aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/i2c/writing-clients
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-05-01 17:26:31 -0400
committerJean Delvare <khali@hyperion.delvare>2007-05-01 17:26:31 -0400
commit4298cfc3eb6110df989f784be516c6340c597a66 (patch)
treeb542354286cef08dffb7f3f8a129e00b035db559 /Documentation/i2c/writing-clients
parenta1d9e6e49f4b473a6945a6b553f5070e8c793e0a (diff)
i2c: i2c probe() and remove() documented
Update Documentation/i2c to match previous patches updating probe() and remove() logic. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'Documentation/i2c/writing-clients')
-rw-r--r--Documentation/i2c/writing-clients82
1 files changed, 72 insertions, 10 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index fbcff96f4ca1..54255fd68ec7 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -1,5 +1,5 @@
1This is a small guide for those who want to write kernel drivers for I2C 1This is a small guide for those who want to write kernel drivers for I2C
2or SMBus devices. 2or SMBus devices, using Linux as the protocol host/master (not slave).
3 3
4To set up a driver, you need to do several things. Some are optional, and 4To set up a driver, you need to do several things. Some are optional, and
5some things can be done slightly or completely different. Use this as a 5some things can be done slightly or completely different. Use this as a
@@ -29,8 +29,16 @@ static struct i2c_driver foo_driver = {
29 .driver = { 29 .driver = {
30 .name = "foo", 30 .name = "foo",
31 }, 31 },
32
33 /* iff driver uses driver model ("new style") binding model: */
34 .probe = foo_probe,
35 .remove = foo_remove,
36
37 /* else, driver uses "legacy" binding model: */
32 .attach_adapter = foo_attach_adapter, 38 .attach_adapter = foo_attach_adapter,
33 .detach_client = foo_detach_client, 39 .detach_client = foo_detach_client,
40
41 /* these may be used regardless of the driver binding model */
34 .shutdown = foo_shutdown, /* optional */ 42 .shutdown = foo_shutdown, /* optional */
35 .suspend = foo_suspend, /* optional */ 43 .suspend = foo_suspend, /* optional */
36 .resume = foo_resume, /* optional */ 44 .resume = foo_resume, /* optional */
@@ -40,7 +48,8 @@ static struct i2c_driver foo_driver = {
40The name field is the driver name, and must not contain spaces. It 48The name field is the driver name, and must not contain spaces. It
41should match the module name (if the driver can be compiled as a module), 49should match the module name (if the driver can be compiled as a module),
42although you can use MODULE_ALIAS (passing "foo" in this example) to add 50although you can use MODULE_ALIAS (passing "foo" in this example) to add
43another name for the module. 51another name for the module. If the driver name doesn't match the module
52name, the module won't be automatically loaded (hotplug/coldplug).
44 53
45All other fields are for call-back functions which will be explained 54All other fields are for call-back functions which will be explained
46below. 55below.
@@ -141,6 +150,59 @@ Writing is done the same way.
141Probing and attaching 150Probing and attaching
142===================== 151=====================
143 152
153The Linux I2C stack was originally written to support access to hardware
154monitoring chips on PC motherboards, and thus it embeds some assumptions
155that are more appropriate to SMBus (and PCs) than to I2C. One of these
156assumptions is that most adapters and devices drivers support the SMBUS_QUICK
157protocol to probe device presence. Another is that devices and their drivers
158can be sufficiently configured using only such probe primitives.
159
160As Linux and its I2C stack became more widely used in embedded systems
161and complex components such as DVB adapters, those assumptions became more
162problematic. Drivers for I2C devices that issue interrupts need more (and
163different) configuration information, as do drivers handling chip variants
164that can't be distinguished by protocol probing, or which need some board
165specific information to operate correctly.
166
167Accordingly, the I2C stack now has two models for associating I2C devices
168with their drivers: the original "legacy" model, and a newer one that's
169fully compatible with the Linux 2.6 driver model. These models do not mix,
170since the "legacy" model requires drivers to create "i2c_client" device
171objects after SMBus style probing, while the Linux driver model expects
172drivers to be given such device objects in their probe() routines.
173
174
175Standard Driver Model Binding ("New Style")
176-------------------------------------------
177
178System infrastructure, typically board-specific initialization code or
179boot firmware, reports what I2C devices exist. For example, there may be
180a table, in the kernel or from the boot loader, identifying I2C devices
181and linking them to board-specific configuration information about IRQs
182and other wiring artifacts, chip type, and so on. That could be used to
183create i2c_client objects for each I2C device.
184
185I2C device drivers using this binding model work just like any other
186kind of driver in Linux: they provide a probe() method to bind to
187those devices, and a remove() method to unbind.
188
189 static int foo_probe(struct i2c_client *client);
190 static int foo_remove(struct i2c_client *client);
191
192Remember that the i2c_driver does not create those client handles. The
193handle may be used during foo_probe(). If foo_probe() reports success
194(zero not a negative status code) it may save the handle and use it until
195foo_remove() returns. That binding model is used by most Linux drivers.
196
197Drivers match devices when i2c_client.driver_name and the driver name are
198the same; this approach is used in several other busses that don't have
199device typing support in the hardware. The driver and module name should
200match, so hotplug/coldplug mechanisms will modprobe the driver.
201
202
203Legacy Driver Binding Model
204---------------------------
205
144Most i2c devices can be present on several i2c addresses; for some this 206Most i2c devices can be present on several i2c addresses; for some this
145is determined in hardware (by soldering some chip pins to Vcc or Ground), 207is determined in hardware (by soldering some chip pins to Vcc or Ground),
146for others this can be changed in software (by writing to specific client 208for others this can be changed in software (by writing to specific client
@@ -162,8 +224,8 @@ NOTE: If you want to write a `sensors' driver, the interface is slightly
162 224
163 225
164 226
165Probing classes 227Probing classes (Legacy model)
166--------------- 228------------------------------
167 229
168All parameters are given as lists of unsigned 16-bit integers. Lists are 230All parameters are given as lists of unsigned 16-bit integers. Lists are
169terminated by I2C_CLIENT_END. 231terminated by I2C_CLIENT_END.
@@ -210,8 +272,8 @@ Note that you *have* to call the defined variable `normal_i2c',
210without any prefix! 272without any prefix!
211 273
212 274
213Attaching to an adapter 275Attaching to an adapter (Legacy model)
214----------------------- 276--------------------------------------
215 277
216Whenever a new adapter is inserted, or for all adapters if the driver is 278Whenever a new adapter is inserted, or for all adapters if the driver is
217being registered, the callback attach_adapter() is called. Now is the 279being registered, the callback attach_adapter() is called. Now is the
@@ -237,8 +299,8 @@ them (unless a `force' parameter was used). In addition, addresses that
237are already in use (by some other registered client) are skipped. 299are already in use (by some other registered client) are skipped.
238 300
239 301
240The detect client function 302The detect client function (Legacy model)
241-------------------------- 303-----------------------------------------
242 304
243The detect client function is called by i2c_probe. The `kind' parameter 305The detect client function is called by i2c_probe. The `kind' parameter
244contains -1 for a probed detection, 0 for a forced detection, or a positive 306contains -1 for a probed detection, 0 for a forced detection, or a positive
@@ -427,8 +489,8 @@ For now, you can ignore the `flags' parameter. It is there for future use.
427 } 489 }
428 490
429 491
430Removing the client 492Removing the client (Legacy model)
431=================== 493==================================
432 494
433The detach_client call back function is called when a client should be 495The detach_client call back function is called when a client should be
434removed. It may actually fail, but only when panicking. This code is 496removed. It may actually fail, but only when panicking. This code is