aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/i2c/writing-clients
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/i2c/writing-clients')
-rw-r--r--Documentation/i2c/writing-clients114
1 files changed, 30 insertions, 84 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index 91664be91ffc..077275722a7c 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -148,15 +148,15 @@ are defined in i2c.h to help you support them, as well as a generic
148detection algorithm. 148detection algorithm.
149 149
150You do not have to use this parameter interface; but don't try to use 150You do not have to use this parameter interface; but don't try to use
151function i2c_probe() (or i2c_detect()) if you don't. 151function i2c_probe() if you don't.
152 152
153NOTE: If you want to write a `sensors' driver, the interface is slightly 153NOTE: If you want to write a `sensors' driver, the interface is slightly
154 different! See below. 154 different! See below.
155 155
156 156
157 157
158Probing classes (i2c) 158Probing classes
159--------------------- 159---------------
160 160
161All parameters are given as lists of unsigned 16-bit integers. Lists are 161All parameters are given as lists of unsigned 16-bit integers. Lists are
162terminated by I2C_CLIENT_END. 162terminated by I2C_CLIENT_END.
@@ -171,12 +171,18 @@ The following lists are used internally:
171 ignore: insmod parameter. 171 ignore: insmod parameter.
172 A list of pairs. The first value is a bus number (-1 for any I2C bus), 172 A list of pairs. The first value is a bus number (-1 for any I2C bus),
173 the second is the I2C address. These addresses are never probed. 173 the second is the I2C address. These addresses are never probed.
174 This parameter overrules 'normal' and 'probe', but not the 'force' lists. 174 This parameter overrules the 'normal_i2c' list only.
175 force: insmod parameter. 175 force: insmod parameter.
176 A list of pairs. The first value is a bus number (-1 for any I2C bus), 176 A list of pairs. The first value is a bus number (-1 for any I2C bus),
177 the second is the I2C address. A device is blindly assumed to be on 177 the second is the I2C address. A device is blindly assumed to be on
178 the given address, no probing is done. 178 the given address, no probing is done.
179 179
180Additionally, kind-specific force lists may optionally be defined if
181the driver supports several chip kinds. They are grouped in a
182NULL-terminated list of pointers named forces, those first element if the
183generic force list mentioned above. Each additional list correspond to an
184insmod parameter of the form force_<kind>.
185
180Fortunately, as a module writer, you just have to define the `normal_i2c' 186Fortunately, as a module writer, you just have to define the `normal_i2c'
181parameter. The complete declaration could look like this: 187parameter. The complete declaration could look like this:
182 188
@@ -186,66 +192,17 @@ parameter. The complete declaration could look like this:
186 192
187 /* Magic definition of all other variables and things */ 193 /* Magic definition of all other variables and things */
188 I2C_CLIENT_INSMOD; 194 I2C_CLIENT_INSMOD;
195 /* Or, if your driver supports, say, 2 kind of devices: */
196 I2C_CLIENT_INSMOD_2(foo, bar);
197
198If you use the multi-kind form, an enum will be defined for you:
199 enum chips { any_chip, foo, bar, ... }
200You can then (and certainly should) use it in the driver code.
189 201
190Note that you *have* to call the defined variable `normal_i2c', 202Note that you *have* to call the defined variable `normal_i2c',
191without any prefix! 203without any prefix!
192 204
193 205
194Probing classes (sensors)
195-------------------------
196
197If you write a `sensors' driver, you use a slightly different interface.
198As well as I2C addresses, we have to cope with ISA addresses. Also, we
199use a enum of chip types. Don't forget to include `sensors.h'.
200
201The following lists are used internally. They are all lists of integers.
202
203 normal_i2c: filled in by the module writer. Terminated by SENSORS_I2C_END.
204 A list of I2C addresses which should normally be examined.
205 normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END.
206 A list of ISA addresses which should normally be examined.
207 probe: insmod parameter. Initialize this list with SENSORS_I2C_END values.
208 A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
209 the ISA bus, -1 for any I2C bus), the second is the address. These
210 addresses are also probed, as if they were in the 'normal' list.
211 ignore: insmod parameter. Initialize this list with SENSORS_I2C_END values.
212 A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
213 the ISA bus, -1 for any I2C bus), the second is the I2C address. These
214 addresses are never probed. This parameter overrules 'normal' and
215 'probe', but not the 'force' lists.
216
217Also used is a list of pointers to sensors_force_data structures:
218 force_data: insmod parameters. A list, ending with an element of which
219 the force field is NULL.
220 Each element contains the type of chip and a list of pairs.
221 The first value is a bus number (SENSORS_ISA_BUS for the ISA bus,
222 -1 for any I2C bus), the second is the address.
223 These are automatically translated to insmod variables of the form
224 force_foo.
225
226So we have a generic insmod variabled `force', and chip-specific variables
227`force_CHIPNAME'.
228
229Fortunately, as a module writer, you just have to define the `normal_i2c'
230and `normal_isa' parameters, and define what chip names are used.
231The complete declaration could look like this:
232 /* Scan i2c addresses 0x37, and 0x48 to 0x4f */
233 static unsigned short normal_i2c[] = { 0x37, 0x48, 0x49, 0x4a, 0x4b, 0x4c,
234 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
235 /* Scan ISA address 0x290 */
236 static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END};
237
238 /* Define chips foo and bar, as well as all module parameters and things */
239 SENSORS_INSMOD_2(foo,bar);
240
241If you have one chip, you use macro SENSORS_INSMOD_1(chip), if you have 2
242you use macro SENSORS_INSMOD_2(chip1,chip2), etc. If you do not want to
243bother with chip types, you can use SENSORS_INSMOD_0.
244
245A enum is automatically defined as follows:
246 enum chips { any_chip, chip1, chip2, ... }
247
248
249Attaching to an adapter 206Attaching to an adapter
250----------------------- 207-----------------------
251 208
@@ -264,17 +221,10 @@ detected at a specific address, another callback is called.
264 return i2c_probe(adapter,&addr_data,&foo_detect_client); 221 return i2c_probe(adapter,&addr_data,&foo_detect_client);
265 } 222 }
266 223
267For `sensors' drivers, use the i2c_detect function instead:
268
269 int foo_attach_adapter(struct i2c_adapter *adapter)
270 {
271 return i2c_detect(adapter,&addr_data,&foo_detect_client);
272 }
273
274Remember, structure `addr_data' is defined by the macros explained above, 224Remember, structure `addr_data' is defined by the macros explained above,
275so you do not have to define it yourself. 225so you do not have to define it yourself.
276 226
277The i2c_probe or i2c_detect function will call the foo_detect_client 227The i2c_probe function will call the foo_detect_client
278function only for those i2c addresses that actually have a device on 228function only for those i2c addresses that actually have a device on
279them (unless a `force' parameter was used). In addition, addresses that 229them (unless a `force' parameter was used). In addition, addresses that
280are already in use (by some other registered client) are skipped. 230are already in use (by some other registered client) are skipped.
@@ -283,19 +233,18 @@ are already in use (by some other registered client) are skipped.
283The detect client function 233The detect client function
284-------------------------- 234--------------------------
285 235
286The detect client function is called by i2c_probe or i2c_detect. 236The detect client function is called by i2c_probe. The `kind' parameter
287The `kind' parameter contains 0 if this call is due to a `force' 237contains -1 for a probed detection, 0 for a forced detection, or a positive
288parameter, and -1 otherwise (for i2c_detect, it contains 0 if 238number for a forced detection with a chip type forced.
289this call is due to the generic `force' parameter, and the chip type
290number if it is due to a specific `force' parameter).
291 239
292Below, some things are only needed if this is a `sensors' driver. Those 240Below, some things are only needed if this is a `sensors' driver. Those
293parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */ 241parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */
294markers. 242markers.
295 243
296This function should only return an error (any value != 0) if there is 244Returning an error different from -ENODEV in a detect function will cause
297some reason why no more detection should be done anymore. If the 245the detection to stop: other addresses and adapters won't be scanned.
298detection just fails for this address, return 0. 246This should only be done on fatal or internal errors, such as a memory
247shortage or i2c_attach_client failing.
299 248
300For now, you can ignore the `flags' parameter. It is there for future use. 249For now, you can ignore the `flags' parameter. It is there for future use.
301 250
@@ -320,11 +269,10 @@ For now, you can ignore the `flags' parameter. It is there for future use.
320 const char *type_name = ""; 269 const char *type_name = "";
321 int is_isa = i2c_is_isa_adapter(adapter); 270 int is_isa = i2c_is_isa_adapter(adapter);
322 271
323 if (is_isa) { 272 /* Do this only if the chip can additionally be found on the ISA bus
273 (hybrid chip). */
324 274
325 /* If this client can't be on the ISA bus at all, we can stop now 275 if (is_isa) {
326 (call `goto ERROR0'). But for kicks, we will assume it is all
327 right. */
328 276
329 /* Discard immediately if this ISA range is already used */ 277 /* Discard immediately if this ISA range is already used */
330 if (check_region(address,FOO_EXTENT)) 278 if (check_region(address,FOO_EXTENT))
@@ -495,15 +443,13 @@ much simpler than the attachment code, fortunately!
495 /* SENSORS ONLY END */ 443 /* SENSORS ONLY END */
496 444
497 /* Try to detach the client from i2c space */ 445 /* Try to detach the client from i2c space */
498 if ((err = i2c_detach_client(client))) { 446 if ((err = i2c_detach_client(client)))
499 printk("foo.o: Client deregistration failed, client not detached.\n");
500 return err; 447 return err;
501 }
502 448
503 /* SENSORS ONLY START */ 449 /* HYBRID SENSORS CHIP ONLY START */
504 if i2c_is_isa_client(client) 450 if i2c_is_isa_client(client)
505 release_region(client->addr,LM78_EXTENT); 451 release_region(client->addr,LM78_EXTENT);
506 /* SENSORS ONLY END */ 452 /* HYBRID SENSORS CHIP ONLY END */
507 453
508 kfree(client); /* Frees client data too, if allocated at the same time */ 454 kfree(client); /* Frees client data too, if allocated at the same time */
509 return 0; 455 return 0;