diff options
Diffstat (limited to 'Documentation/i2c/writing-clients')
-rw-r--r-- | Documentation/i2c/writing-clients | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index 3a057c8e5507..fbcff96f4ca1 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -21,20 +21,26 @@ The driver structure | |||
21 | 21 | ||
22 | Usually, you will implement a single driver structure, and instantiate | 22 | Usually, you will implement a single driver structure, and instantiate |
23 | all clients from it. Remember, a driver structure contains general access | 23 | all clients from it. Remember, a driver structure contains general access |
24 | routines, a client structure specific information like the actual I2C | 24 | routines, and should be zero-initialized except for fields with data you |
25 | address. | 25 | provide. A client structure holds device-specific information like the |
26 | driver model device node, and its I2C address. | ||
26 | 27 | ||
27 | static struct i2c_driver foo_driver = { | 28 | static struct i2c_driver foo_driver = { |
28 | .driver = { | 29 | .driver = { |
29 | .name = "foo", | 30 | .name = "foo", |
30 | }, | 31 | }, |
31 | .attach_adapter = &foo_attach_adapter, | 32 | .attach_adapter = foo_attach_adapter, |
32 | .detach_client = &foo_detach_client, | 33 | .detach_client = foo_detach_client, |
33 | .command = &foo_command /* may be NULL */ | 34 | .shutdown = foo_shutdown, /* optional */ |
35 | .suspend = foo_suspend, /* optional */ | ||
36 | .resume = foo_resume, /* optional */ | ||
37 | .command = foo_command, /* optional */ | ||
34 | } | 38 | } |
35 | 39 | ||
36 | The name field must match the driver name, including the case. It must not | 40 | The name field is the driver name, and must not contain spaces. It |
37 | contain spaces, and may be up to 31 characters long. | 41 | 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 | ||
43 | another name for the module. | ||
38 | 44 | ||
39 | All other fields are for call-back functions which will be explained | 45 | All other fields are for call-back functions which will be explained |
40 | below. | 46 | below. |
@@ -43,11 +49,18 @@ below. | |||
43 | Extra client data | 49 | Extra client data |
44 | ================= | 50 | ================= |
45 | 51 | ||
46 | The client structure has a special `data' field that can point to any | 52 | Each client structure has a special `data' field that can point to any |
47 | structure at all. You can use this to keep client-specific data. You | 53 | structure at all. You should use this to keep device-specific data, |
54 | especially in drivers that handle multiple I2C or SMBUS devices. You | ||
48 | do not always need this, but especially for `sensors' drivers, it can | 55 | do not always need this, but especially for `sensors' drivers, it can |
49 | be very useful. | 56 | be very useful. |
50 | 57 | ||
58 | /* store the value */ | ||
59 | void i2c_set_clientdata(struct i2c_client *client, void *data); | ||
60 | |||
61 | /* retrieve the value */ | ||
62 | void *i2c_get_clientdata(struct i2c_client *client); | ||
63 | |||
51 | An example structure is below. | 64 | An example structure is below. |
52 | 65 | ||
53 | struct foo_data { | 66 | struct foo_data { |
@@ -493,6 +506,33 @@ by `__init_data'. Hose functions and structures can be removed after | |||
493 | kernel booting (or module loading) is completed. | 506 | kernel booting (or module loading) is completed. |
494 | 507 | ||
495 | 508 | ||
509 | Power Management | ||
510 | ================ | ||
511 | |||
512 | If your I2C device needs special handling when entering a system low | ||
513 | power state -- like putting a transceiver into a low power mode, or | ||
514 | activating a system wakeup mechanism -- do that in the suspend() method. | ||
515 | The resume() method should reverse what the suspend() method does. | ||
516 | |||
517 | These are standard driver model calls, and they work just like they | ||
518 | would for any other driver stack. The calls can sleep, and can use | ||
519 | I2C messaging to the device being suspended or resumed (since their | ||
520 | parent I2C adapter is active when these calls are issued, and IRQs | ||
521 | are still enabled). | ||
522 | |||
523 | |||
524 | System Shutdown | ||
525 | =============== | ||
526 | |||
527 | If your I2C device needs special handling when the system shuts down | ||
528 | or reboots (including kexec) -- like turning something off -- use a | ||
529 | shutdown() method. | ||
530 | |||
531 | Again, this is a standard driver model call, working just like it | ||
532 | would for any other driver stack: the calls can sleep, and can use | ||
533 | I2C messaging. | ||
534 | |||
535 | |||
496 | Command function | 536 | Command function |
497 | ================ | 537 | ================ |
498 | 538 | ||