xref: /OK3568_Linux_fs/kernel/Documentation/i2c/writing-clients.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===============================
2*4882a593SmuzhiyunImplementing I2C device drivers
3*4882a593Smuzhiyun===============================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThis is a small guide for those who want to write kernel drivers for I2C
6*4882a593Smuzhiyunor SMBus devices, using Linux as the protocol host/master (not slave).
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunTo set up a driver, you need to do several things. Some are optional, and
9*4882a593Smuzhiyunsome things can be done slightly or completely different. Use this as a
10*4882a593Smuzhiyunguide, not as a rule book!
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunGeneral remarks
14*4882a593Smuzhiyun===============
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunTry to keep the kernel namespace as clean as possible. The best way to
17*4882a593Smuzhiyundo this is to use a unique prefix for all global symbols. This is
18*4882a593Smuzhiyunespecially important for exported symbols, but it is a good idea to do
19*4882a593Smuzhiyunit for non-exported symbols too. We will use the prefix ``foo_`` in this
20*4882a593Smuzhiyuntutorial.
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunThe driver structure
24*4882a593Smuzhiyun====================
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunUsually, you will implement a single driver structure, and instantiate
27*4882a593Smuzhiyunall clients from it. Remember, a driver structure contains general access
28*4882a593Smuzhiyunroutines, and should be zero-initialized except for fields with data you
29*4882a593Smuzhiyunprovide.  A client structure holds device-specific information like the
30*4882a593Smuzhiyundriver model device node, and its I2C address.
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun::
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun  static struct i2c_device_id foo_idtable[] = {
35*4882a593Smuzhiyun	{ "foo", my_id_for_foo },
36*4882a593Smuzhiyun	{ "bar", my_id_for_bar },
37*4882a593Smuzhiyun	{ }
38*4882a593Smuzhiyun  };
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun  MODULE_DEVICE_TABLE(i2c, foo_idtable);
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun  static struct i2c_driver foo_driver = {
43*4882a593Smuzhiyun	.driver = {
44*4882a593Smuzhiyun		.name	= "foo",
45*4882a593Smuzhiyun		.pm	= &foo_pm_ops,	/* optional */
46*4882a593Smuzhiyun	},
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun	.id_table	= foo_idtable,
49*4882a593Smuzhiyun	.probe		= foo_probe,
50*4882a593Smuzhiyun	.remove		= foo_remove,
51*4882a593Smuzhiyun	/* if device autodetection is needed: */
52*4882a593Smuzhiyun	.class		= I2C_CLASS_SOMETHING,
53*4882a593Smuzhiyun	.detect		= foo_detect,
54*4882a593Smuzhiyun	.address_list	= normal_i2c,
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun	.shutdown	= foo_shutdown,	/* optional */
57*4882a593Smuzhiyun	.command	= foo_command,	/* optional, deprecated */
58*4882a593Smuzhiyun  }
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunThe name field is the driver name, and must not contain spaces.  It
61*4882a593Smuzhiyunshould match the module name (if the driver can be compiled as a module),
62*4882a593Smuzhiyunalthough you can use MODULE_ALIAS (passing "foo" in this example) to add
63*4882a593Smuzhiyunanother name for the module.  If the driver name doesn't match the module
64*4882a593Smuzhiyunname, the module won't be automatically loaded (hotplug/coldplug).
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunAll other fields are for call-back functions which will be explained
67*4882a593Smuzhiyunbelow.
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun
70*4882a593SmuzhiyunExtra client data
71*4882a593Smuzhiyun=================
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunEach client structure has a special ``data`` field that can point to any
74*4882a593Smuzhiyunstructure at all.  You should use this to keep device-specific data.
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun::
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun	/* store the value */
79*4882a593Smuzhiyun	void i2c_set_clientdata(struct i2c_client *client, void *data);
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun	/* retrieve the value */
82*4882a593Smuzhiyun	void *i2c_get_clientdata(const struct i2c_client *client);
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunNote that starting with kernel 2.6.34, you don't have to set the ``data`` field
85*4882a593Smuzhiyunto NULL in remove() or if probe() failed anymore. The i2c-core does this
86*4882a593Smuzhiyunautomatically on these occasions. Those are also the only times the core will
87*4882a593Smuzhiyuntouch this field.
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunAccessing the client
91*4882a593Smuzhiyun====================
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunLet's say we have a valid client structure. At some time, we will need
94*4882a593Smuzhiyunto gather information from the client, or write new information to the
95*4882a593Smuzhiyunclient.
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunI have found it useful to define foo_read and foo_write functions for this.
98*4882a593SmuzhiyunFor some cases, it will be easier to call the I2C functions directly,
99*4882a593Smuzhiyunbut many chips have some kind of register-value idea that can easily
100*4882a593Smuzhiyunbe encapsulated.
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunThe below functions are simple examples, and should not be copied
103*4882a593Smuzhiyunliterally::
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun  int foo_read_value(struct i2c_client *client, u8 reg)
106*4882a593Smuzhiyun  {
107*4882a593Smuzhiyun	if (reg < 0x10)	/* byte-sized register */
108*4882a593Smuzhiyun		return i2c_smbus_read_byte_data(client, reg);
109*4882a593Smuzhiyun	else		/* word-sized register */
110*4882a593Smuzhiyun		return i2c_smbus_read_word_data(client, reg);
111*4882a593Smuzhiyun  }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun  int foo_write_value(struct i2c_client *client, u8 reg, u16 value)
114*4882a593Smuzhiyun  {
115*4882a593Smuzhiyun	if (reg == 0x10)	/* Impossible to write - driver error! */
116*4882a593Smuzhiyun		return -EINVAL;
117*4882a593Smuzhiyun	else if (reg < 0x10)	/* byte-sized register */
118*4882a593Smuzhiyun		return i2c_smbus_write_byte_data(client, reg, value);
119*4882a593Smuzhiyun	else			/* word-sized register */
120*4882a593Smuzhiyun		return i2c_smbus_write_word_data(client, reg, value);
121*4882a593Smuzhiyun  }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun
124*4882a593SmuzhiyunProbing and attaching
125*4882a593Smuzhiyun=====================
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunThe Linux I2C stack was originally written to support access to hardware
128*4882a593Smuzhiyunmonitoring chips on PC motherboards, and thus used to embed some assumptions
129*4882a593Smuzhiyunthat were more appropriate to SMBus (and PCs) than to I2C.  One of these
130*4882a593Smuzhiyunassumptions was that most adapters and devices drivers support the SMBUS_QUICK
131*4882a593Smuzhiyunprotocol to probe device presence.  Another was that devices and their drivers
132*4882a593Smuzhiyuncan be sufficiently configured using only such probe primitives.
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunAs Linux and its I2C stack became more widely used in embedded systems
135*4882a593Smuzhiyunand complex components such as DVB adapters, those assumptions became more
136*4882a593Smuzhiyunproblematic.  Drivers for I2C devices that issue interrupts need more (and
137*4882a593Smuzhiyundifferent) configuration information, as do drivers handling chip variants
138*4882a593Smuzhiyunthat can't be distinguished by protocol probing, or which need some board
139*4882a593Smuzhiyunspecific information to operate correctly.
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunDevice/Driver Binding
143*4882a593Smuzhiyun---------------------
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunSystem infrastructure, typically board-specific initialization code or
146*4882a593Smuzhiyunboot firmware, reports what I2C devices exist.  For example, there may be
147*4882a593Smuzhiyuna table, in the kernel or from the boot loader, identifying I2C devices
148*4882a593Smuzhiyunand linking them to board-specific configuration information about IRQs
149*4882a593Smuzhiyunand other wiring artifacts, chip type, and so on.  That could be used to
150*4882a593Smuzhiyuncreate i2c_client objects for each I2C device.
151*4882a593Smuzhiyun
152*4882a593SmuzhiyunI2C device drivers using this binding model work just like any other
153*4882a593Smuzhiyunkind of driver in Linux:  they provide a probe() method to bind to
154*4882a593Smuzhiyunthose devices, and a remove() method to unbind.
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun::
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun	static int foo_probe(struct i2c_client *client,
159*4882a593Smuzhiyun			     const struct i2c_device_id *id);
160*4882a593Smuzhiyun	static int foo_remove(struct i2c_client *client);
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunRemember that the i2c_driver does not create those client handles.  The
163*4882a593Smuzhiyunhandle may be used during foo_probe().  If foo_probe() reports success
164*4882a593Smuzhiyun(zero not a negative status code) it may save the handle and use it until
165*4882a593Smuzhiyunfoo_remove() returns.  That binding model is used by most Linux drivers.
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunThe probe function is called when an entry in the id_table name field
168*4882a593Smuzhiyunmatches the device's name. It is passed the entry that was matched so
169*4882a593Smuzhiyunthe driver knows which one in the table matched.
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun
172*4882a593SmuzhiyunDevice Creation
173*4882a593Smuzhiyun---------------
174*4882a593Smuzhiyun
175*4882a593SmuzhiyunIf you know for a fact that an I2C device is connected to a given I2C bus,
176*4882a593Smuzhiyunyou can instantiate that device by simply filling an i2c_board_info
177*4882a593Smuzhiyunstructure with the device address and driver name, and calling
178*4882a593Smuzhiyuni2c_new_client_device().  This will create the device, then the driver core
179*4882a593Smuzhiyunwill take care of finding the right driver and will call its probe() method.
180*4882a593SmuzhiyunIf a driver supports different device types, you can specify the type you
181*4882a593Smuzhiyunwant using the type field.  You can also specify an IRQ and platform data
182*4882a593Smuzhiyunif needed.
183*4882a593Smuzhiyun
184*4882a593SmuzhiyunSometimes you know that a device is connected to a given I2C bus, but you
185*4882a593Smuzhiyundon't know the exact address it uses.  This happens on TV adapters for
186*4882a593Smuzhiyunexample, where the same driver supports dozens of slightly different
187*4882a593Smuzhiyunmodels, and I2C device addresses change from one model to the next.  In
188*4882a593Smuzhiyunthat case, you can use the i2c_new_scanned_device() variant, which is
189*4882a593Smuzhiyunsimilar to i2c_new_client_device(), except that it takes an additional list
190*4882a593Smuzhiyunof possible I2C addresses to probe.  A device is created for the first
191*4882a593Smuzhiyunresponsive address in the list.  If you expect more than one device to be
192*4882a593Smuzhiyunpresent in the address range, simply call i2c_new_scanned_device() that
193*4882a593Smuzhiyunmany times.
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunThe call to i2c_new_client_device() or i2c_new_scanned_device() typically
196*4882a593Smuzhiyunhappens in the I2C bus driver. You may want to save the returned i2c_client
197*4882a593Smuzhiyunreference for later use.
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunDevice Detection
201*4882a593Smuzhiyun----------------
202*4882a593Smuzhiyun
203*4882a593SmuzhiyunSometimes you do not know in advance which I2C devices are connected to
204*4882a593Smuzhiyuna given I2C bus.  This is for example the case of hardware monitoring
205*4882a593Smuzhiyundevices on a PC's SMBus.  In that case, you may want to let your driver
206*4882a593Smuzhiyundetect supported devices automatically.  This is how the legacy model
207*4882a593Smuzhiyunwas working, and is now available as an extension to the standard
208*4882a593Smuzhiyundriver model.
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunYou simply have to define a detect callback which will attempt to
211*4882a593Smuzhiyunidentify supported devices (returning 0 for supported ones and -ENODEV
212*4882a593Smuzhiyunfor unsupported ones), a list of addresses to probe, and a device type
213*4882a593Smuzhiyun(or class) so that only I2C buses which may have that type of device
214*4882a593Smuzhiyunconnected (and not otherwise enumerated) will be probed.  For example,
215*4882a593Smuzhiyuna driver for a hardware monitoring chip for which auto-detection is
216*4882a593Smuzhiyunneeded would set its class to I2C_CLASS_HWMON, and only I2C adapters
217*4882a593Smuzhiyunwith a class including I2C_CLASS_HWMON would be probed by this driver.
218*4882a593SmuzhiyunNote that the absence of matching classes does not prevent the use of
219*4882a593Smuzhiyuna device of that type on the given I2C adapter.  All it prevents is
220*4882a593Smuzhiyunauto-detection; explicit instantiation of devices is still possible.
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunNote that this mechanism is purely optional and not suitable for all
223*4882a593Smuzhiyundevices.  You need some reliable way to identify the supported devices
224*4882a593Smuzhiyun(typically using device-specific, dedicated identification registers),
225*4882a593Smuzhiyunotherwise misdetections are likely to occur and things can get wrong
226*4882a593Smuzhiyunquickly.  Keep in mind that the I2C protocol doesn't include any
227*4882a593Smuzhiyunstandard way to detect the presence of a chip at a given address, let
228*4882a593Smuzhiyunalone a standard way to identify devices.  Even worse is the lack of
229*4882a593Smuzhiyunsemantics associated to bus transfers, which means that the same
230*4882a593Smuzhiyuntransfer can be seen as a read operation by a chip and as a write
231*4882a593Smuzhiyunoperation by another chip.  For these reasons, explicit device
232*4882a593Smuzhiyuninstantiation should always be preferred to auto-detection where
233*4882a593Smuzhiyunpossible.
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunDevice Deletion
237*4882a593Smuzhiyun---------------
238*4882a593Smuzhiyun
239*4882a593SmuzhiyunEach I2C device which has been created using i2c_new_client_device()
240*4882a593Smuzhiyunor i2c_new_scanned_device() can be unregistered by calling
241*4882a593Smuzhiyuni2c_unregister_device().  If you don't call it explicitly, it will be
242*4882a593Smuzhiyuncalled automatically before the underlying I2C bus itself is removed,
243*4882a593Smuzhiyunas a device can't survive its parent in the device driver model.
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun
246*4882a593SmuzhiyunInitializing the driver
247*4882a593Smuzhiyun=======================
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunWhen the kernel is booted, or when your foo driver module is inserted,
250*4882a593Smuzhiyunyou have to do some initializing. Fortunately, just registering the
251*4882a593Smuzhiyundriver module is usually enough.
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun::
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun  static int __init foo_init(void)
256*4882a593Smuzhiyun  {
257*4882a593Smuzhiyun	return i2c_add_driver(&foo_driver);
258*4882a593Smuzhiyun  }
259*4882a593Smuzhiyun  module_init(foo_init);
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun  static void __exit foo_cleanup(void)
262*4882a593Smuzhiyun  {
263*4882a593Smuzhiyun	i2c_del_driver(&foo_driver);
264*4882a593Smuzhiyun  }
265*4882a593Smuzhiyun  module_exit(foo_cleanup);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun  The module_i2c_driver() macro can be used to reduce above code.
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun  module_i2c_driver(foo_driver);
270*4882a593Smuzhiyun
271*4882a593SmuzhiyunNote that some functions are marked by ``__init``.  These functions can
272*4882a593Smuzhiyunbe removed after kernel booting (or module loading) is completed.
273*4882a593SmuzhiyunLikewise, functions marked by ``__exit`` are dropped by the compiler when
274*4882a593Smuzhiyunthe code is built into the kernel, as they would never be called.
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun
277*4882a593SmuzhiyunDriver Information
278*4882a593Smuzhiyun==================
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun::
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun  /* Substitute your own name and email address */
283*4882a593Smuzhiyun  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"
284*4882a593Smuzhiyun  MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices");
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun  /* a few non-GPL license types are also allowed */
287*4882a593Smuzhiyun  MODULE_LICENSE("GPL");
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun
290*4882a593SmuzhiyunPower Management
291*4882a593Smuzhiyun================
292*4882a593Smuzhiyun
293*4882a593SmuzhiyunIf your I2C device needs special handling when entering a system low
294*4882a593Smuzhiyunpower state -- like putting a transceiver into a low power mode, or
295*4882a593Smuzhiyunactivating a system wakeup mechanism -- do that by implementing the
296*4882a593Smuzhiyunappropriate callbacks for the dev_pm_ops of the driver (like suspend
297*4882a593Smuzhiyunand resume).
298*4882a593Smuzhiyun
299*4882a593SmuzhiyunThese are standard driver model calls, and they work just like they
300*4882a593Smuzhiyunwould for any other driver stack.  The calls can sleep, and can use
301*4882a593SmuzhiyunI2C messaging to the device being suspended or resumed (since their
302*4882a593Smuzhiyunparent I2C adapter is active when these calls are issued, and IRQs
303*4882a593Smuzhiyunare still enabled).
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun
306*4882a593SmuzhiyunSystem Shutdown
307*4882a593Smuzhiyun===============
308*4882a593Smuzhiyun
309*4882a593SmuzhiyunIf your I2C device needs special handling when the system shuts down
310*4882a593Smuzhiyunor reboots (including kexec) -- like turning something off -- use a
311*4882a593Smuzhiyunshutdown() method.
312*4882a593Smuzhiyun
313*4882a593SmuzhiyunAgain, this is a standard driver model call, working just like it
314*4882a593Smuzhiyunwould for any other driver stack:  the calls can sleep, and can use
315*4882a593SmuzhiyunI2C messaging.
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun
318*4882a593SmuzhiyunCommand function
319*4882a593Smuzhiyun================
320*4882a593Smuzhiyun
321*4882a593SmuzhiyunA generic ioctl-like function call back is supported. You will seldom
322*4882a593Smuzhiyunneed this, and its use is deprecated anyway, so newer design should not
323*4882a593Smuzhiyunuse it.
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun
326*4882a593SmuzhiyunSending and receiving
327*4882a593Smuzhiyun=====================
328*4882a593Smuzhiyun
329*4882a593SmuzhiyunIf you want to communicate with your device, there are several functions
330*4882a593Smuzhiyunto do this. You can find all of them in <linux/i2c.h>.
331*4882a593Smuzhiyun
332*4882a593SmuzhiyunIf you can choose between plain I2C communication and SMBus level
333*4882a593Smuzhiyuncommunication, please use the latter. All adapters understand SMBus level
334*4882a593Smuzhiyuncommands, but only some of them understand plain I2C!
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun
337*4882a593SmuzhiyunPlain I2C communication
338*4882a593Smuzhiyun-----------------------
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun::
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun	int i2c_master_send(struct i2c_client *client, const char *buf,
343*4882a593Smuzhiyun			    int count);
344*4882a593Smuzhiyun	int i2c_master_recv(struct i2c_client *client, char *buf, int count);
345*4882a593Smuzhiyun
346*4882a593SmuzhiyunThese routines read and write some bytes from/to a client. The client
347*4882a593Smuzhiyuncontains the I2C address, so you do not have to include it. The second
348*4882a593Smuzhiyunparameter contains the bytes to read/write, the third the number of bytes
349*4882a593Smuzhiyunto read/write (must be less than the length of the buffer, also should be
350*4882a593Smuzhiyunless than 64k since msg.len is u16.) Returned is the actual number of bytes
351*4882a593Smuzhiyunread/written.
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun::
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun	int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msg,
356*4882a593Smuzhiyun			 int num);
357*4882a593Smuzhiyun
358*4882a593SmuzhiyunThis sends a series of messages. Each message can be a read or write,
359*4882a593Smuzhiyunand they can be mixed in any way. The transactions are combined: no
360*4882a593Smuzhiyunstop condition is issued between transaction. The i2c_msg structure
361*4882a593Smuzhiyuncontains for each message the client address, the number of bytes of the
362*4882a593Smuzhiyunmessage and the message data itself.
363*4882a593Smuzhiyun
364*4882a593SmuzhiyunYou can read the file ``i2c-protocol`` for more information about the
365*4882a593Smuzhiyunactual I2C protocol.
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun
368*4882a593SmuzhiyunSMBus communication
369*4882a593Smuzhiyun-------------------
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun::
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun	s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
374*4882a593Smuzhiyun			   unsigned short flags, char read_write, u8 command,
375*4882a593Smuzhiyun			   int size, union i2c_smbus_data *data);
376*4882a593Smuzhiyun
377*4882a593SmuzhiyunThis is the generic SMBus function. All functions below are implemented
378*4882a593Smuzhiyunin terms of it. Never use this function directly!
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun::
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun	s32 i2c_smbus_read_byte(struct i2c_client *client);
383*4882a593Smuzhiyun	s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value);
384*4882a593Smuzhiyun	s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command);
385*4882a593Smuzhiyun	s32 i2c_smbus_write_byte_data(struct i2c_client *client,
386*4882a593Smuzhiyun				      u8 command, u8 value);
387*4882a593Smuzhiyun	s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command);
388*4882a593Smuzhiyun	s32 i2c_smbus_write_word_data(struct i2c_client *client,
389*4882a593Smuzhiyun				      u8 command, u16 value);
390*4882a593Smuzhiyun	s32 i2c_smbus_read_block_data(struct i2c_client *client,
391*4882a593Smuzhiyun				      u8 command, u8 *values);
392*4882a593Smuzhiyun	s32 i2c_smbus_write_block_data(struct i2c_client *client,
393*4882a593Smuzhiyun				       u8 command, u8 length, const u8 *values);
394*4882a593Smuzhiyun	s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client,
395*4882a593Smuzhiyun					  u8 command, u8 length, u8 *values);
396*4882a593Smuzhiyun	s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
397*4882a593Smuzhiyun					   u8 command, u8 length,
398*4882a593Smuzhiyun					   const u8 *values);
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunThese ones were removed from i2c-core because they had no users, but could
401*4882a593Smuzhiyunbe added back later if needed::
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun	s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value);
404*4882a593Smuzhiyun	s32 i2c_smbus_process_call(struct i2c_client *client,
405*4882a593Smuzhiyun				   u8 command, u16 value);
406*4882a593Smuzhiyun	s32 i2c_smbus_block_process_call(struct i2c_client *client,
407*4882a593Smuzhiyun					 u8 command, u8 length, u8 *values);
408*4882a593Smuzhiyun
409*4882a593SmuzhiyunAll these transactions return a negative errno value on failure. The 'write'
410*4882a593Smuzhiyuntransactions return 0 on success; the 'read' transactions return the read
411*4882a593Smuzhiyunvalue, except for block transactions, which return the number of values
412*4882a593Smuzhiyunread. The block buffers need not be longer than 32 bytes.
413*4882a593Smuzhiyun
414*4882a593SmuzhiyunYou can read the file ``smbus-protocol`` for more information about the
415*4882a593Smuzhiyunactual SMBus protocol.
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun
418*4882a593SmuzhiyunGeneral purpose routines
419*4882a593Smuzhiyun========================
420*4882a593Smuzhiyun
421*4882a593SmuzhiyunBelow all general purpose routines are listed, that were not mentioned
422*4882a593Smuzhiyunbefore::
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun	/* Return the adapter number for a specific adapter */
425*4882a593Smuzhiyun	int i2c_adapter_id(struct i2c_adapter *adap);
426