diff options
-rw-r--r-- | Documentation/i2c/summary | 29 | ||||
-rw-r--r-- | Documentation/i2c/writing-clients | 82 |
2 files changed, 92 insertions, 19 deletions
diff --git a/Documentation/i2c/summary b/Documentation/i2c/summary index 41dde8776791..aea60bf7e8f0 100644 --- a/Documentation/i2c/summary +++ b/Documentation/i2c/summary | |||
@@ -4,17 +4,23 @@ I2C and SMBus | |||
4 | ============= | 4 | ============= |
5 | 5 | ||
6 | I2C (pronounce: I squared C) is a protocol developed by Philips. It is a | 6 | I2C (pronounce: I squared C) is a protocol developed by Philips. It is a |
7 | slow two-wire protocol (10-400 kHz), but it suffices for many types of | 7 | slow two-wire protocol (variable speed, up to 400 kHz), with a high speed |
8 | devices. | 8 | extension (3.4 MHz). It provides an inexpensive bus for connecting many |
9 | types of devices with infrequent or low bandwidth communications needs. | ||
10 | I2C is widely used with embedded systems. Some systems use variants that | ||
11 | don't meet branding requirements, and so are not advertised as being I2C. | ||
9 | 12 | ||
10 | SMBus (System Management Bus) is a subset of the I2C protocol. Many | 13 | SMBus (System Management Bus) is based on the I2C protocol, and is mostly |
11 | modern mainboards have a System Management Bus. There are a lot of | 14 | a subset of I2C protocols and signaling. Many I2C devices will work on an |
12 | devices which can be connected to a SMBus; the most notable are modern | 15 | SMBus, but some SMBus protocols add semantics beyond what is required to |
13 | memory chips with EEPROM memories and chips for hardware monitoring. | 16 | achieve I2C branding. Modern PC mainboards rely on SMBus. The most common |
17 | devices connected through SMBus are RAM modules configured using I2C EEPROMs, | ||
18 | and hardware monitoring chips. | ||
14 | 19 | ||
15 | Because the SMBus is just a special case of the generalized I2C bus, we | 20 | Because the SMBus is mostly a subset of the generalized I2C bus, we can |
16 | can simulate the SMBus protocol on plain I2C busses. The reverse is | 21 | use its protocols on many I2C systems. However, there are systems that don't |
17 | regretfully impossible. | 22 | meet both SMBus and I2C electrical constraints; and others which can't |
23 | implement all the common SMBus protocol semantics or messages. | ||
18 | 24 | ||
19 | 25 | ||
20 | Terminology | 26 | Terminology |
@@ -29,6 +35,7 @@ When we talk about I2C, we use the following terms: | |||
29 | An Algorithm driver contains general code that can be used for a whole class | 35 | An Algorithm driver contains general code that can be used for a whole class |
30 | of I2C adapters. Each specific adapter driver depends on one algorithm | 36 | of I2C adapters. Each specific adapter driver depends on one algorithm |
31 | driver. | 37 | driver. |
38 | |||
32 | A Driver driver (yes, this sounds ridiculous, sorry) contains the general | 39 | A Driver driver (yes, this sounds ridiculous, sorry) contains the general |
33 | code to access some type of device. Each detected device gets its own | 40 | code to access some type of device. Each detected device gets its own |
34 | data in the Client structure. Usually, Driver and Client are more closely | 41 | data in the Client structure. Usually, Driver and Client are more closely |
@@ -40,6 +47,10 @@ a separate Adapter and Algorithm driver), and drivers for your I2C devices | |||
40 | in this package. See the lm_sensors project http://www.lm-sensors.nu | 47 | in this package. See the lm_sensors project http://www.lm-sensors.nu |
41 | for device drivers. | 48 | for device drivers. |
42 | 49 | ||
50 | At this time, Linux only operates I2C (or SMBus) in master mode; you can't | ||
51 | use these APIs to make a Linux system behave as a slave/device, either to | ||
52 | speak a custom protocol or to emulate some other device. | ||
53 | |||
43 | 54 | ||
44 | Included Bus Drivers | 55 | Included Bus Drivers |
45 | ==================== | 56 | ==================== |
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 @@ | |||
1 | This is a small guide for those who want to write kernel drivers for I2C | 1 | This is a small guide for those who want to write kernel drivers for I2C |
2 | or SMBus devices. | 2 | or SMBus devices, using Linux as the protocol host/master (not slave). |
3 | 3 | ||
4 | To set up a driver, you need to do several things. Some are optional, and | 4 | To set up a driver, you need to do several things. Some are optional, and |
5 | some things can be done slightly or completely different. Use this as a | 5 | some 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 = { | |||
40 | The name field is the driver name, and must not contain spaces. It | 48 | The name field is the driver name, and must not contain spaces. It |
41 | should match the module name (if the driver can be compiled as a module), | 49 | should match the module name (if the driver can be compiled as a module), |
42 | although you can use MODULE_ALIAS (passing "foo" in this example) to add | 50 | although you can use MODULE_ALIAS (passing "foo" in this example) to add |
43 | another name for the module. | 51 | another name for the module. If the driver name doesn't match the module |
52 | name, the module won't be automatically loaded (hotplug/coldplug). | ||
44 | 53 | ||
45 | All other fields are for call-back functions which will be explained | 54 | All other fields are for call-back functions which will be explained |
46 | below. | 55 | below. |
@@ -141,6 +150,59 @@ Writing is done the same way. | |||
141 | Probing and attaching | 150 | Probing and attaching |
142 | ===================== | 151 | ===================== |
143 | 152 | ||
153 | The Linux I2C stack was originally written to support access to hardware | ||
154 | monitoring chips on PC motherboards, and thus it embeds some assumptions | ||
155 | that are more appropriate to SMBus (and PCs) than to I2C. One of these | ||
156 | assumptions is that most adapters and devices drivers support the SMBUS_QUICK | ||
157 | protocol to probe device presence. Another is that devices and their drivers | ||
158 | can be sufficiently configured using only such probe primitives. | ||
159 | |||
160 | As Linux and its I2C stack became more widely used in embedded systems | ||
161 | and complex components such as DVB adapters, those assumptions became more | ||
162 | problematic. Drivers for I2C devices that issue interrupts need more (and | ||
163 | different) configuration information, as do drivers handling chip variants | ||
164 | that can't be distinguished by protocol probing, or which need some board | ||
165 | specific information to operate correctly. | ||
166 | |||
167 | Accordingly, the I2C stack now has two models for associating I2C devices | ||
168 | with their drivers: the original "legacy" model, and a newer one that's | ||
169 | fully compatible with the Linux 2.6 driver model. These models do not mix, | ||
170 | since the "legacy" model requires drivers to create "i2c_client" device | ||
171 | objects after SMBus style probing, while the Linux driver model expects | ||
172 | drivers to be given such device objects in their probe() routines. | ||
173 | |||
174 | |||
175 | Standard Driver Model Binding ("New Style") | ||
176 | ------------------------------------------- | ||
177 | |||
178 | System infrastructure, typically board-specific initialization code or | ||
179 | boot firmware, reports what I2C devices exist. For example, there may be | ||
180 | a table, in the kernel or from the boot loader, identifying I2C devices | ||
181 | and linking them to board-specific configuration information about IRQs | ||
182 | and other wiring artifacts, chip type, and so on. That could be used to | ||
183 | create i2c_client objects for each I2C device. | ||
184 | |||
185 | I2C device drivers using this binding model work just like any other | ||
186 | kind of driver in Linux: they provide a probe() method to bind to | ||
187 | those 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 | |||
192 | Remember that the i2c_driver does not create those client handles. The | ||
193 | handle 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 | ||
195 | foo_remove() returns. That binding model is used by most Linux drivers. | ||
196 | |||
197 | Drivers match devices when i2c_client.driver_name and the driver name are | ||
198 | the same; this approach is used in several other busses that don't have | ||
199 | device typing support in the hardware. The driver and module name should | ||
200 | match, so hotplug/coldplug mechanisms will modprobe the driver. | ||
201 | |||
202 | |||
203 | Legacy Driver Binding Model | ||
204 | --------------------------- | ||
205 | |||
144 | Most i2c devices can be present on several i2c addresses; for some this | 206 | Most i2c devices can be present on several i2c addresses; for some this |
145 | is determined in hardware (by soldering some chip pins to Vcc or Ground), | 207 | is determined in hardware (by soldering some chip pins to Vcc or Ground), |
146 | for others this can be changed in software (by writing to specific client | 208 | for 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 | ||
165 | Probing classes | 227 | Probing classes (Legacy model) |
166 | --------------- | 228 | ------------------------------ |
167 | 229 | ||
168 | All parameters are given as lists of unsigned 16-bit integers. Lists are | 230 | All parameters are given as lists of unsigned 16-bit integers. Lists are |
169 | terminated by I2C_CLIENT_END. | 231 | terminated by I2C_CLIENT_END. |
@@ -210,8 +272,8 @@ Note that you *have* to call the defined variable `normal_i2c', | |||
210 | without any prefix! | 272 | without any prefix! |
211 | 273 | ||
212 | 274 | ||
213 | Attaching to an adapter | 275 | Attaching to an adapter (Legacy model) |
214 | ----------------------- | 276 | -------------------------------------- |
215 | 277 | ||
216 | Whenever a new adapter is inserted, or for all adapters if the driver is | 278 | Whenever a new adapter is inserted, or for all adapters if the driver is |
217 | being registered, the callback attach_adapter() is called. Now is the | 279 | being 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 | |||
237 | are already in use (by some other registered client) are skipped. | 299 | are already in use (by some other registered client) are skipped. |
238 | 300 | ||
239 | 301 | ||
240 | The detect client function | 302 | The detect client function (Legacy model) |
241 | -------------------------- | 303 | ----------------------------------------- |
242 | 304 | ||
243 | The detect client function is called by i2c_probe. The `kind' parameter | 305 | The detect client function is called by i2c_probe. The `kind' parameter |
244 | contains -1 for a probed detection, 0 for a forced detection, or a positive | 306 | contains -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 | ||
430 | Removing the client | 492 | Removing the client (Legacy model) |
431 | =================== | 493 | ================================== |
432 | 494 | ||
433 | The detach_client call back function is called when a client should be | 495 | The detach_client call back function is called when a client should be |
434 | removed. It may actually fail, but only when panicking. This code is | 496 | removed. It may actually fail, but only when panicking. This code is |