diff options
Diffstat (limited to 'Documentation/i2c')
-rw-r--r-- | Documentation/i2c/busses/i2c-i810 | 47 | ||||
-rw-r--r-- | Documentation/i2c/busses/i2c-prosavage | 23 | ||||
-rw-r--r-- | Documentation/i2c/busses/i2c-savage4 | 26 | ||||
-rw-r--r-- | Documentation/i2c/chips/max6875 | 2 | ||||
-rw-r--r-- | Documentation/i2c/chips/pca9539 | 10 | ||||
-rw-r--r-- | Documentation/i2c/chips/pcf8574 | 12 | ||||
-rw-r--r-- | Documentation/i2c/chips/pcf8575 | 9 | ||||
-rw-r--r-- | Documentation/i2c/fault-codes | 127 | ||||
-rw-r--r-- | Documentation/i2c/functionality | 95 | ||||
-rw-r--r-- | Documentation/i2c/smbus-protocol | 81 | ||||
-rw-r--r-- | Documentation/i2c/upgrading-clients | 281 | ||||
-rw-r--r-- | Documentation/i2c/writing-clients | 69 |
12 files changed, 578 insertions, 204 deletions
diff --git a/Documentation/i2c/busses/i2c-i810 b/Documentation/i2c/busses/i2c-i810 deleted file mode 100644 index 778210ee1583..000000000000 --- a/Documentation/i2c/busses/i2c-i810 +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | Kernel driver i2c-i810 | ||
2 | |||
3 | Supported adapters: | ||
4 | * Intel 82810, 82810-DC100, 82810E, and 82815 (GMCH) | ||
5 | * Intel 82845G (GMCH) | ||
6 | |||
7 | Authors: | ||
8 | Frodo Looijaard <frodol@dds.nl>, | ||
9 | Philip Edelbrock <phil@netroedge.com>, | ||
10 | Kyösti Mälkki <kmalkki@cc.hut.fi>, | ||
11 | Ralph Metzler <rjkm@thp.uni-koeln.de>, | ||
12 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
13 | |||
14 | Main contact: Mark Studebaker <mdsxyz123@yahoo.com> | ||
15 | |||
16 | Description | ||
17 | ----------- | ||
18 | |||
19 | WARNING: If you have an '810' or '815' motherboard, your standard I2C | ||
20 | temperature sensors are most likely on the 801's I2C bus. You want the | ||
21 | i2c-i801 driver for those, not this driver. | ||
22 | |||
23 | Now for the i2c-i810... | ||
24 | |||
25 | The GMCH chip contains two I2C interfaces. | ||
26 | |||
27 | The first interface is used for DDC (Data Display Channel) which is a | ||
28 | serial channel through the VGA monitor connector to a DDC-compliant | ||
29 | monitor. This interface is defined by the Video Electronics Standards | ||
30 | Association (VESA). The standards are available for purchase at | ||
31 | http://www.vesa.org . | ||
32 | |||
33 | The second interface is a general-purpose I2C bus. It may be connected to a | ||
34 | TV-out chip such as the BT869 or possibly to a digital flat-panel display. | ||
35 | |||
36 | Features | ||
37 | -------- | ||
38 | |||
39 | Both busses use the i2c-algo-bit driver for 'bit banging' | ||
40 | and support for specific transactions is provided by i2c-algo-bit. | ||
41 | |||
42 | Issues | ||
43 | ------ | ||
44 | |||
45 | If you enable bus testing in i2c-algo-bit (insmod i2c-algo-bit bit_test=1), | ||
46 | the test may fail; if so, the i2c-i810 driver won't be inserted. However, | ||
47 | we think this has been fixed. | ||
diff --git a/Documentation/i2c/busses/i2c-prosavage b/Documentation/i2c/busses/i2c-prosavage deleted file mode 100644 index 703687902511..000000000000 --- a/Documentation/i2c/busses/i2c-prosavage +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | Kernel driver i2c-prosavage | ||
2 | |||
3 | Supported adapters: | ||
4 | |||
5 | S3/VIA KM266/VT8375 aka ProSavage8 | ||
6 | S3/VIA KM133/VT8365 aka Savage4 | ||
7 | |||
8 | Author: Henk Vergonet <henk@god.dyndns.org> | ||
9 | |||
10 | Description | ||
11 | ----------- | ||
12 | |||
13 | The Savage4 chips contain two I2C interfaces (aka a I2C 'master' or | ||
14 | 'host'). | ||
15 | |||
16 | The first interface is used for DDC (Data Display Channel) which is a | ||
17 | serial channel through the VGA monitor connector to a DDC-compliant | ||
18 | monitor. This interface is defined by the Video Electronics Standards | ||
19 | Association (VESA). The standards are available for purchase at | ||
20 | http://www.vesa.org . The second interface is a general-purpose I2C bus. | ||
21 | |||
22 | Usefull for gaining access to the TV Encoder chips. | ||
23 | |||
diff --git a/Documentation/i2c/busses/i2c-savage4 b/Documentation/i2c/busses/i2c-savage4 deleted file mode 100644 index 6ecceab618d3..000000000000 --- a/Documentation/i2c/busses/i2c-savage4 +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | Kernel driver i2c-savage4 | ||
2 | |||
3 | Supported adapters: | ||
4 | * Savage4 | ||
5 | * Savage2000 | ||
6 | |||
7 | Authors: | ||
8 | Alexander Wold <awold@bigfoot.com>, | ||
9 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
10 | |||
11 | Description | ||
12 | ----------- | ||
13 | |||
14 | The Savage4 chips contain two I2C interfaces (aka a I2C 'master' | ||
15 | or 'host'). | ||
16 | |||
17 | The first interface is used for DDC (Data Display Channel) which is a | ||
18 | serial channel through the VGA monitor connector to a DDC-compliant | ||
19 | monitor. This interface is defined by the Video Electronics Standards | ||
20 | Association (VESA). The standards are available for purchase at | ||
21 | http://www.vesa.org . The DDC bus is not yet supported because its register | ||
22 | is not directly memory-mapped. | ||
23 | |||
24 | The second interface is a general-purpose I2C bus. This is the only | ||
25 | interface supported by the driver at the moment. | ||
26 | |||
diff --git a/Documentation/i2c/chips/max6875 b/Documentation/i2c/chips/max6875 index a0cd8af2f408..10ca43cd1a72 100644 --- a/Documentation/i2c/chips/max6875 +++ b/Documentation/i2c/chips/max6875 | |||
@@ -49,7 +49,7 @@ $ modprobe max6875 force=0,0x50 | |||
49 | 49 | ||
50 | The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple | 50 | The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple |
51 | addresses. For example, for address 0x50, it also reserves 0x51. | 51 | addresses. For example, for address 0x50, it also reserves 0x51. |
52 | The even-address instance is called 'max6875', the odd one is 'max6875 subclient'. | 52 | The even-address instance is called 'max6875', the odd one is 'dummy'. |
53 | 53 | ||
54 | 54 | ||
55 | Programming the chip using i2c-dev | 55 | Programming the chip using i2c-dev |
diff --git a/Documentation/i2c/chips/pca9539 b/Documentation/i2c/chips/pca9539 index 1d81c530c4a5..6aff890088b1 100644 --- a/Documentation/i2c/chips/pca9539 +++ b/Documentation/i2c/chips/pca9539 | |||
@@ -7,7 +7,7 @@ drivers/gpio/pca9539.c instead. | |||
7 | Supported chips: | 7 | Supported chips: |
8 | * Philips PCA9539 | 8 | * Philips PCA9539 |
9 | Prefix: 'pca9539' | 9 | Prefix: 'pca9539' |
10 | Addresses scanned: 0x74 - 0x77 | 10 | Addresses scanned: none |
11 | Datasheet: | 11 | Datasheet: |
12 | http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf | 12 | http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf |
13 | 13 | ||
@@ -23,6 +23,14 @@ The input sense can also be inverted. | |||
23 | The 16 lines are split between two bytes. | 23 | The 16 lines are split between two bytes. |
24 | 24 | ||
25 | 25 | ||
26 | Detection | ||
27 | --------- | ||
28 | |||
29 | The PCA9539 is difficult to detect and not commonly found in PC machines, | ||
30 | so you have to pass the I2C bus and address of the installed PCA9539 | ||
31 | devices explicitly to the driver at load time via the force=... parameter. | ||
32 | |||
33 | |||
26 | Sysfs entries | 34 | Sysfs entries |
27 | ------------- | 35 | ------------- |
28 | 36 | ||
diff --git a/Documentation/i2c/chips/pcf8574 b/Documentation/i2c/chips/pcf8574 index 5c1ad1376b62..235815c075ff 100644 --- a/Documentation/i2c/chips/pcf8574 +++ b/Documentation/i2c/chips/pcf8574 | |||
@@ -4,13 +4,13 @@ Kernel driver pcf8574 | |||
4 | Supported chips: | 4 | Supported chips: |
5 | * Philips PCF8574 | 5 | * Philips PCF8574 |
6 | Prefix: 'pcf8574' | 6 | Prefix: 'pcf8574' |
7 | Addresses scanned: I2C 0x20 - 0x27 | 7 | Addresses scanned: none |
8 | Datasheet: Publicly available at the Philips Semiconductors website | 8 | Datasheet: Publicly available at the Philips Semiconductors website |
9 | http://www.semiconductors.philips.com/pip/PCF8574P.html | 9 | http://www.semiconductors.philips.com/pip/PCF8574P.html |
10 | 10 | ||
11 | * Philips PCF8574A | 11 | * Philips PCF8574A |
12 | Prefix: 'pcf8574a' | 12 | Prefix: 'pcf8574a' |
13 | Addresses scanned: I2C 0x38 - 0x3f | 13 | Addresses scanned: none |
14 | Datasheet: Publicly available at the Philips Semiconductors website | 14 | Datasheet: Publicly available at the Philips Semiconductors website |
15 | http://www.semiconductors.philips.com/pip/PCF8574P.html | 15 | http://www.semiconductors.philips.com/pip/PCF8574P.html |
16 | 16 | ||
@@ -38,12 +38,10 @@ For more informations see the datasheet. | |||
38 | Accessing PCF8574(A) via /sys interface | 38 | Accessing PCF8574(A) via /sys interface |
39 | ------------------------------------- | 39 | ------------------------------------- |
40 | 40 | ||
41 | ! Be careful ! | ||
42 | The PCF8574(A) is plainly impossible to detect ! Stupid chip. | 41 | The PCF8574(A) is plainly impossible to detect ! Stupid chip. |
43 | So every chip with address in the interval [20..27] and [38..3f] are | 42 | So, you have to pass the I2C bus and address of the installed PCF857A |
44 | detected as PCF8574(A). If you have other chips in this address | 43 | and PCF8574A devices explicitly to the driver at load time via the |
45 | range, the workaround is to load this module after the one | 44 | force=... parameter. |
46 | for your others chips. | ||
47 | 45 | ||
48 | On detection (i.e. insmod, modprobe et al.), directories are being | 46 | On detection (i.e. insmod, modprobe et al.), directories are being |
49 | created for each detected PCF8574(A): | 47 | created for each detected PCF8574(A): |
diff --git a/Documentation/i2c/chips/pcf8575 b/Documentation/i2c/chips/pcf8575 index 25f5698a61cf..40b268eb276f 100644 --- a/Documentation/i2c/chips/pcf8575 +++ b/Documentation/i2c/chips/pcf8575 | |||
@@ -40,12 +40,9 @@ Detection | |||
40 | --------- | 40 | --------- |
41 | 41 | ||
42 | There is no method known to detect whether a chip on a given I2C address is | 42 | There is no method known to detect whether a chip on a given I2C address is |
43 | a PCF8575 or whether it is any other I2C device. So there are two alternatives | 43 | a PCF8575 or whether it is any other I2C device, so you have to pass the I2C |
44 | to let the driver find the installed PCF8575 devices: | 44 | bus and address of the installed PCF8575 devices explicitly to the driver at |
45 | - Load this driver after any other I2C driver for I2C devices with addresses | 45 | load time via the force=... parameter. |
46 | in the range 0x20 .. 0x27. | ||
47 | - Pass the I2C bus and address of the installed PCF8575 devices explicitly to | ||
48 | the driver at load time via the probe=... or force=... parameters. | ||
49 | 46 | ||
50 | /sys interface | 47 | /sys interface |
51 | -------------- | 48 | -------------- |
diff --git a/Documentation/i2c/fault-codes b/Documentation/i2c/fault-codes new file mode 100644 index 000000000000..045765c0b9b5 --- /dev/null +++ b/Documentation/i2c/fault-codes | |||
@@ -0,0 +1,127 @@ | |||
1 | This is a summary of the most important conventions for use of fault | ||
2 | codes in the I2C/SMBus stack. | ||
3 | |||
4 | |||
5 | A "Fault" is not always an "Error" | ||
6 | ---------------------------------- | ||
7 | Not all fault reports imply errors; "page faults" should be a familiar | ||
8 | example. Software often retries idempotent operations after transient | ||
9 | faults. There may be fancier recovery schemes that are appropriate in | ||
10 | some cases, such as re-initializing (and maybe resetting). After such | ||
11 | recovery, triggered by a fault report, there is no error. | ||
12 | |||
13 | In a similar way, sometimes a "fault" code just reports one defined | ||
14 | result for an operation ... it doesn't indicate that anything is wrong | ||
15 | at all, just that the outcome wasn't on the "golden path". | ||
16 | |||
17 | In short, your I2C driver code may need to know these codes in order | ||
18 | to respond correctly. Other code may need to rely on YOUR code reporting | ||
19 | the right fault code, so that it can (in turn) behave correctly. | ||
20 | |||
21 | |||
22 | I2C and SMBus fault codes | ||
23 | ------------------------- | ||
24 | These are returned as negative numbers from most calls, with zero or | ||
25 | some positive number indicating a non-fault return. The specific | ||
26 | numbers associated with these symbols differ between architectures, | ||
27 | though most Linux systems use <asm-generic/errno*.h> numbering. | ||
28 | |||
29 | Note that the descriptions here are not exhaustive. There are other | ||
30 | codes that may be returned, and other cases where these codes should | ||
31 | be returned. However, drivers should not return other codes for these | ||
32 | cases (unless the hardware doesn't provide unique fault reports). | ||
33 | |||
34 | Also, codes returned by adapter probe methods follow rules which are | ||
35 | specific to their host bus (such as PCI, or the platform bus). | ||
36 | |||
37 | |||
38 | EAGAIN | ||
39 | Returned by I2C adapters when they lose arbitration in master | ||
40 | transmit mode: some other master was transmitting different | ||
41 | data at the same time. | ||
42 | |||
43 | Also returned when trying to invoke an I2C operation in an | ||
44 | atomic context, when some task is already using that I2C bus | ||
45 | to execute some other operation. | ||
46 | |||
47 | EBADMSG | ||
48 | Returned by SMBus logic when an invalid Packet Error Code byte | ||
49 | is received. This code is a CRC covering all bytes in the | ||
50 | transaction, and is sent before the terminating STOP. This | ||
51 | fault is only reported on read transactions; the SMBus slave | ||
52 | may have a way to report PEC mismatches on writes from the | ||
53 | host. Note that even if PECs are in use, you should not rely | ||
54 | on these as the only way to detect incorrect data transfers. | ||
55 | |||
56 | EBUSY | ||
57 | Returned by SMBus adapters when the bus was busy for longer | ||
58 | than allowed. This usually indicates some device (maybe the | ||
59 | SMBus adapter) needs some fault recovery (such as resetting), | ||
60 | or that the reset was attempted but failed. | ||
61 | |||
62 | EINVAL | ||
63 | This rather vague error means an invalid parameter has been | ||
64 | detected before any I/O operation was started. Use a more | ||
65 | specific fault code when you can. | ||
66 | |||
67 | One example would be a driver trying an SMBus Block Write | ||
68 | with block size outside the range of 1-32 bytes. | ||
69 | |||
70 | EIO | ||
71 | This rather vague error means something went wrong when | ||
72 | performing an I/O operation. Use a more specific fault | ||
73 | code when you can. | ||
74 | |||
75 | ENODEV | ||
76 | Returned by driver probe() methods. This is a bit more | ||
77 | specific than ENXIO, implying the problem isn't with the | ||
78 | address, but with the device found there. Driver probes | ||
79 | may verify the device returns *correct* responses, and | ||
80 | return this as appropriate. (The driver core will warn | ||
81 | about probe faults other than ENXIO and ENODEV.) | ||
82 | |||
83 | ENOMEM | ||
84 | Returned by any component that can't allocate memory when | ||
85 | it needs to do so. | ||
86 | |||
87 | ENXIO | ||
88 | Returned by I2C adapters to indicate that the address phase | ||
89 | of a transfer didn't get an ACK. While it might just mean | ||
90 | an I2C device was temporarily not responding, usually it | ||
91 | means there's nothing listening at that address. | ||
92 | |||
93 | Returned by driver probe() methods to indicate that they | ||
94 | found no device to bind to. (ENODEV may also be used.) | ||
95 | |||
96 | EOPNOTSUPP | ||
97 | Returned by an adapter when asked to perform an operation | ||
98 | that it doesn't, or can't, support. | ||
99 | |||
100 | For example, this would be returned when an adapter that | ||
101 | doesn't support SMBus block transfers is asked to execute | ||
102 | one. In that case, the driver making that request should | ||
103 | have verified that functionality was supported before it | ||
104 | made that block transfer request. | ||
105 | |||
106 | Similarly, if an I2C adapter can't execute all legal I2C | ||
107 | messages, it should return this when asked to perform a | ||
108 | transaction it can't. (These limitations can't be seen in | ||
109 | the adapter's functionality mask, since the assumption is | ||
110 | that if an adapter supports I2C it supports all of I2C.) | ||
111 | |||
112 | EPROTO | ||
113 | Returned when slave does not conform to the relevant I2C | ||
114 | or SMBus (or chip-specific) protocol specifications. One | ||
115 | case is when the length of an SMBus block data response | ||
116 | (from the SMBus slave) is outside the range 1-32 bytes. | ||
117 | |||
118 | ETIMEDOUT | ||
119 | This is returned by drivers when an operation took too much | ||
120 | time, and was aborted before it completed. | ||
121 | |||
122 | SMBus adapters may return it when an operation took more | ||
123 | time than allowed by the SMBus specification; for example, | ||
124 | when a slave stretches clocks too far. I2C has no such | ||
125 | timeouts, but it's normal for I2C adapters to impose some | ||
126 | arbitrary limits (much longer than SMBus!) too. | ||
127 | |||
diff --git a/Documentation/i2c/functionality b/Documentation/i2c/functionality index 60cca249e452..42c17c1fb3cd 100644 --- a/Documentation/i2c/functionality +++ b/Documentation/i2c/functionality | |||
@@ -51,26 +51,38 @@ A few combinations of the above flags are also defined for your convenience: | |||
51 | the transparent emulation layer) | 51 | the transparent emulation layer) |
52 | 52 | ||
53 | 53 | ||
54 | ALGORITHM/ADAPTER IMPLEMENTATION | 54 | ADAPTER IMPLEMENTATION |
55 | -------------------------------- | 55 | ---------------------- |
56 | 56 | ||
57 | When you write a new algorithm driver, you will have to implement a | 57 | When you write a new adapter driver, you will have to implement a |
58 | function callback `functionality', that gets an i2c_adapter structure | 58 | function callback `functionality'. Typical implementations are given |
59 | pointer as its only parameter: | 59 | below. |
60 | 60 | ||
61 | struct i2c_algorithm { | 61 | A typical SMBus-only adapter would list all the SMBus transactions it |
62 | /* Many other things of course; check <linux/i2c.h>! */ | 62 | supports. This example comes from the i2c-piix4 driver: |
63 | u32 (*functionality) (struct i2c_adapter *); | 63 | |
64 | static u32 piix4_func(struct i2c_adapter *adapter) | ||
65 | { | ||
66 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | ||
67 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | ||
68 | I2C_FUNC_SMBUS_BLOCK_DATA; | ||
64 | } | 69 | } |
65 | 70 | ||
66 | A typically implementation is given below, from i2c-algo-bit.c: | 71 | A typical full-I2C adapter would use the following (from the i2c-pxa |
72 | driver): | ||
67 | 73 | ||
68 | static u32 bit_func(struct i2c_adapter *adap) | 74 | static u32 i2c_pxa_functionality(struct i2c_adapter *adap) |
69 | { | 75 | { |
70 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | | 76 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
71 | I2C_FUNC_PROTOCOL_MANGLING; | ||
72 | } | 77 | } |
73 | 78 | ||
79 | I2C_FUNC_SMBUS_EMUL includes all the SMBus transactions (with the | ||
80 | addition of I2C block transactions) which i2c-core can emulate using | ||
81 | I2C_FUNC_I2C without any help from the adapter driver. The idea is | ||
82 | to let the client drivers check for the support of SMBus functions | ||
83 | without having to care whether the said functions are implemented in | ||
84 | hardware by the adapter, or emulated in software by i2c-core on top | ||
85 | of an I2C adapter. | ||
74 | 86 | ||
75 | 87 | ||
76 | CLIENT CHECKING | 88 | CLIENT CHECKING |
@@ -78,36 +90,33 @@ CLIENT CHECKING | |||
78 | 90 | ||
79 | Before a client tries to attach to an adapter, or even do tests to check | 91 | Before a client tries to attach to an adapter, or even do tests to check |
80 | whether one of the devices it supports is present on an adapter, it should | 92 | whether one of the devices it supports is present on an adapter, it should |
81 | check whether the needed functionality is present. There are two functions | 93 | check whether the needed functionality is present. The typical way to do |
82 | defined which should be used instead of calling the functionality hook | 94 | this is (from the lm75 driver): |
83 | in the algorithm structure directly: | ||
84 | |||
85 | /* Return the functionality mask */ | ||
86 | extern u32 i2c_get_functionality (struct i2c_adapter *adap); | ||
87 | |||
88 | /* Return 1 if adapter supports everything we need, 0 if not. */ | ||
89 | extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func); | ||
90 | 95 | ||
91 | This is a typical way to use these functions (from the writing-clients | 96 | static int lm75_detect(...) |
92 | document): | ||
93 | int foo_detect_client(struct i2c_adapter *adapter, int address, | ||
94 | unsigned short flags, int kind) | ||
95 | { | 97 | { |
96 | /* Define needed variables */ | 98 | (...) |
97 | 99 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | |
98 | /* As the very first action, we check whether the adapter has the | 100 | I2C_FUNC_SMBUS_WORD_DATA)) |
99 | needed functionality: we need the SMBus read_word_data, | 101 | goto exit; |
100 | write_word_data and write_byte functions in this example. */ | 102 | (...) |
101 | if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | | ||
102 | I2C_FUNC_SMBUS_WRITE_BYTE)) | ||
103 | goto ERROR0; | ||
104 | |||
105 | /* Now we can do the real detection */ | ||
106 | |||
107 | ERROR0: | ||
108 | /* Return an error */ | ||
109 | } | 103 | } |
110 | 104 | ||
105 | Here, the lm75 driver checks if the adapter can do both SMBus byte data | ||
106 | and SMBus word data transactions. If not, then the driver won't work on | ||
107 | this adapter and there's no point in going on. If the check above is | ||
108 | successful, then the driver knows that it can call the following | ||
109 | functions: i2c_smbus_read_byte_data(), i2c_smbus_write_byte_data(), | ||
110 | i2c_smbus_read_word_data() and i2c_smbus_write_word_data(). As a rule of | ||
111 | thumb, the functionality constants you test for with | ||
112 | i2c_check_functionality() should match exactly the i2c_smbus_* functions | ||
113 | which you driver is calling. | ||
114 | |||
115 | Note that the check above doesn't tell whether the functionalities are | ||
116 | implemented in hardware by the underlying adapter or emulated in | ||
117 | software by i2c-core. Client drivers don't have to care about this, as | ||
118 | i2c-core will transparently implement SMBus transactions on top of I2C | ||
119 | adapters. | ||
111 | 120 | ||
112 | 121 | ||
113 | CHECKING THROUGH /DEV | 122 | CHECKING THROUGH /DEV |
@@ -116,19 +125,19 @@ CHECKING THROUGH /DEV | |||
116 | If you try to access an adapter from a userspace program, you will have | 125 | If you try to access an adapter from a userspace program, you will have |
117 | to use the /dev interface. You will still have to check whether the | 126 | to use the /dev interface. You will still have to check whether the |
118 | functionality you need is supported, of course. This is done using | 127 | functionality you need is supported, of course. This is done using |
119 | the I2C_FUNCS ioctl. An example, adapted from the lm_sensors i2cdetect | 128 | the I2C_FUNCS ioctl. An example, adapted from the i2cdetect program, is |
120 | program, is below: | 129 | below: |
121 | 130 | ||
122 | int file; | 131 | int file; |
123 | if (file = open("/dev/i2c-0",O_RDWR) < 0) { | 132 | if (file = open("/dev/i2c-0", O_RDWR) < 0) { |
124 | /* Some kind of error handling */ | 133 | /* Some kind of error handling */ |
125 | exit(1); | 134 | exit(1); |
126 | } | 135 | } |
127 | if (ioctl(file,I2C_FUNCS,&funcs) < 0) { | 136 | if (ioctl(file, I2C_FUNCS, &funcs) < 0) { |
128 | /* Some kind of error handling */ | 137 | /* Some kind of error handling */ |
129 | exit(1); | 138 | exit(1); |
130 | } | 139 | } |
131 | if (! (funcs & I2C_FUNC_SMBUS_QUICK)) { | 140 | if (!(funcs & I2C_FUNC_SMBUS_QUICK)) { |
132 | /* Oops, the needed functionality (SMBus write_quick function) is | 141 | /* Oops, the needed functionality (SMBus write_quick function) is |
133 | not available! */ | 142 | not available! */ |
134 | exit(1); | 143 | exit(1); |
diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol index 8a653c60d25a..24bfb65da17d 100644 --- a/Documentation/i2c/smbus-protocol +++ b/Documentation/i2c/smbus-protocol | |||
@@ -1,5 +1,6 @@ | |||
1 | SMBus Protocol Summary | 1 | SMBus Protocol Summary |
2 | ====================== | 2 | ====================== |
3 | |||
3 | The following is a summary of the SMBus protocol. It applies to | 4 | The following is a summary of the SMBus protocol. It applies to |
4 | all revisions of the protocol (1.0, 1.1, and 2.0). | 5 | all revisions of the protocol (1.0, 1.1, and 2.0). |
5 | Certain protocol features which are not supported by | 6 | Certain protocol features which are not supported by |
@@ -8,6 +9,7 @@ this package are briefly described at the end of this document. | |||
8 | Some adapters understand only the SMBus (System Management Bus) protocol, | 9 | Some adapters understand only the SMBus (System Management Bus) protocol, |
9 | which is a subset from the I2C protocol. Fortunately, many devices use | 10 | which is a subset from the I2C protocol. Fortunately, many devices use |
10 | only the same subset, which makes it possible to put them on an SMBus. | 11 | only the same subset, which makes it possible to put them on an SMBus. |
12 | |||
11 | If you write a driver for some I2C device, please try to use the SMBus | 13 | If you write a driver for some I2C device, please try to use the SMBus |
12 | commands if at all possible (if the device uses only that subset of the | 14 | commands if at all possible (if the device uses only that subset of the |
13 | I2C protocol). This makes it possible to use the device driver on both | 15 | I2C protocol). This makes it possible to use the device driver on both |
@@ -15,7 +17,12 @@ SMBus adapters and I2C adapters (the SMBus command set is automatically | |||
15 | translated to I2C on I2C adapters, but plain I2C commands can not be | 17 | translated to I2C on I2C adapters, but plain I2C commands can not be |
16 | handled at all on most pure SMBus adapters). | 18 | handled at all on most pure SMBus adapters). |
17 | 19 | ||
18 | Below is a list of SMBus commands. | 20 | Below is a list of SMBus protocol operations, and the functions executing |
21 | them. Note that the names used in the SMBus protocol specifications usually | ||
22 | don't match these function names. For some of the operations which pass a | ||
23 | single data byte, the functions using SMBus protocol operation names execute | ||
24 | a different protocol operation entirely. | ||
25 | |||
19 | 26 | ||
20 | Key to symbols | 27 | Key to symbols |
21 | ============== | 28 | ============== |
@@ -35,17 +42,16 @@ Count (8 bits): A data byte containing the length of a block operation. | |||
35 | [..]: Data sent by I2C device, as opposed to data sent by the host adapter. | 42 | [..]: Data sent by I2C device, as opposed to data sent by the host adapter. |
36 | 43 | ||
37 | 44 | ||
38 | SMBus Write Quick | 45 | SMBus Quick Command |
39 | ================= | 46 | =================== |
40 | 47 | ||
41 | This sends a single bit to the device, at the place of the Rd/Wr bit. | 48 | This sends a single bit to the device, at the place of the Rd/Wr bit. |
42 | There is no equivalent Read Quick command. | ||
43 | 49 | ||
44 | A Addr Rd/Wr [A] P | 50 | A Addr Rd/Wr [A] P |
45 | 51 | ||
46 | 52 | ||
47 | SMBus Read Byte | 53 | SMBus Receive Byte: i2c_smbus_read_byte() |
48 | =============== | 54 | ========================================== |
49 | 55 | ||
50 | This reads a single byte from a device, without specifying a device | 56 | This reads a single byte from a device, without specifying a device |
51 | register. Some devices are so simple that this interface is enough; for | 57 | register. Some devices are so simple that this interface is enough; for |
@@ -55,17 +61,17 @@ the previous SMBus command. | |||
55 | S Addr Rd [A] [Data] NA P | 61 | S Addr Rd [A] [Data] NA P |
56 | 62 | ||
57 | 63 | ||
58 | SMBus Write Byte | 64 | SMBus Send Byte: i2c_smbus_write_byte() |
59 | ================ | 65 | ======================================== |
60 | 66 | ||
61 | This is the reverse of Read Byte: it sends a single byte to a device. | 67 | This operation is the reverse of Receive Byte: it sends a single byte |
62 | See Read Byte for more information. | 68 | to a device. See Receive Byte for more information. |
63 | 69 | ||
64 | S Addr Wr [A] Data [A] P | 70 | S Addr Wr [A] Data [A] P |
65 | 71 | ||
66 | 72 | ||
67 | SMBus Read Byte Data | 73 | SMBus Read Byte: i2c_smbus_read_byte_data() |
68 | ==================== | 74 | ============================================ |
69 | 75 | ||
70 | This reads a single byte from a device, from a designated register. | 76 | This reads a single byte from a device, from a designated register. |
71 | The register is specified through the Comm byte. | 77 | The register is specified through the Comm byte. |
@@ -73,30 +79,30 @@ The register is specified through the Comm byte. | |||
73 | S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P | 79 | S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P |
74 | 80 | ||
75 | 81 | ||
76 | SMBus Read Word Data | 82 | SMBus Read Word: i2c_smbus_read_word_data() |
77 | ==================== | 83 | ============================================ |
78 | 84 | ||
79 | This command is very like Read Byte Data; again, data is read from a | 85 | This operation is very like Read Byte; again, data is read from a |
80 | device, from a designated register that is specified through the Comm | 86 | device, from a designated register that is specified through the Comm |
81 | byte. But this time, the data is a complete word (16 bits). | 87 | byte. But this time, the data is a complete word (16 bits). |
82 | 88 | ||
83 | S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P | 89 | S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P |
84 | 90 | ||
85 | 91 | ||
86 | SMBus Write Byte Data | 92 | SMBus Write Byte: i2c_smbus_write_byte_data() |
87 | ===================== | 93 | ============================================== |
88 | 94 | ||
89 | This writes a single byte to a device, to a designated register. The | 95 | This writes a single byte to a device, to a designated register. The |
90 | register is specified through the Comm byte. This is the opposite of | 96 | register is specified through the Comm byte. This is the opposite of |
91 | the Read Byte Data command. | 97 | the Read Byte operation. |
92 | 98 | ||
93 | S Addr Wr [A] Comm [A] Data [A] P | 99 | S Addr Wr [A] Comm [A] Data [A] P |
94 | 100 | ||
95 | 101 | ||
96 | SMBus Write Word Data | 102 | SMBus Write Word: i2c_smbus_write_word_data() |
97 | ===================== | 103 | ============================================== |
98 | 104 | ||
99 | This is the opposite operation of the Read Word Data command. 16 bits | 105 | This is the opposite of the Read Word operation. 16 bits |
100 | of data is written to a device, to the designated register that is | 106 | of data is written to a device, to the designated register that is |
101 | specified through the Comm byte. | 107 | specified through the Comm byte. |
102 | 108 | ||
@@ -113,8 +119,8 @@ S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] | |||
113 | S Addr Rd [A] [DataLow] A [DataHigh] NA P | 119 | S Addr Rd [A] [DataLow] A [DataHigh] NA P |
114 | 120 | ||
115 | 121 | ||
116 | SMBus Block Read | 122 | SMBus Block Read: i2c_smbus_read_block_data() |
117 | ================ | 123 | ============================================== |
118 | 124 | ||
119 | This command reads a block of up to 32 bytes from a device, from a | 125 | This command reads a block of up to 32 bytes from a device, from a |
120 | designated register that is specified through the Comm byte. The amount | 126 | designated register that is specified through the Comm byte. The amount |
@@ -124,8 +130,8 @@ S Addr Wr [A] Comm [A] | |||
124 | S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P | 130 | S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P |
125 | 131 | ||
126 | 132 | ||
127 | SMBus Block Write | 133 | SMBus Block Write: i2c_smbus_write_block_data() |
128 | ================= | 134 | ================================================ |
129 | 135 | ||
130 | The opposite of the Block Read command, this writes up to 32 bytes to | 136 | The opposite of the Block Read command, this writes up to 32 bytes to |
131 | a device, to a designated register that is specified through the | 137 | a device, to a designated register that is specified through the |
@@ -134,10 +140,11 @@ Comm byte. The amount of data is specified in the Count byte. | |||
134 | S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P | 140 | S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P |
135 | 141 | ||
136 | 142 | ||
137 | SMBus Block Process Call | 143 | SMBus Block Write - Block Read Process Call |
138 | ======================== | 144 | =========================================== |
139 | 145 | ||
140 | SMBus Block Process Call was introduced in Revision 2.0 of the specification. | 146 | SMBus Block Write - Block Read Process Call was introduced in |
147 | Revision 2.0 of the specification. | ||
141 | 148 | ||
142 | This command selects a device register (through the Comm byte), sends | 149 | This command selects a device register (through the Comm byte), sends |
143 | 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return. | 150 | 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return. |
@@ -159,13 +166,16 @@ alerting device's address. | |||
159 | 166 | ||
160 | Packet Error Checking (PEC) | 167 | Packet Error Checking (PEC) |
161 | =========================== | 168 | =========================== |
169 | |||
162 | Packet Error Checking was introduced in Revision 1.1 of the specification. | 170 | Packet Error Checking was introduced in Revision 1.1 of the specification. |
163 | 171 | ||
164 | PEC adds a CRC-8 error-checking byte to all transfers. | 172 | PEC adds a CRC-8 error-checking byte to transfers using it, immediately |
173 | before the terminating STOP. | ||
165 | 174 | ||
166 | 175 | ||
167 | Address Resolution Protocol (ARP) | 176 | Address Resolution Protocol (ARP) |
168 | ================================= | 177 | ================================= |
178 | |||
169 | The Address Resolution Protocol was introduced in Revision 2.0 of | 179 | The Address Resolution Protocol was introduced in Revision 2.0 of |
170 | the specification. It is a higher-layer protocol which uses the | 180 | the specification. It is a higher-layer protocol which uses the |
171 | messages above. | 181 | messages above. |
@@ -177,14 +187,17 @@ require PEC checksums. | |||
177 | 187 | ||
178 | I2C Block Transactions | 188 | I2C Block Transactions |
179 | ====================== | 189 | ====================== |
190 | |||
180 | The following I2C block transactions are supported by the | 191 | The following I2C block transactions are supported by the |
181 | SMBus layer and are described here for completeness. | 192 | SMBus layer and are described here for completeness. |
193 | They are *NOT* defined by the SMBus specification. | ||
194 | |||
182 | I2C block transactions do not limit the number of bytes transferred | 195 | I2C block transactions do not limit the number of bytes transferred |
183 | but the SMBus layer places a limit of 32 bytes. | 196 | but the SMBus layer places a limit of 32 bytes. |
184 | 197 | ||
185 | 198 | ||
186 | I2C Block Read | 199 | I2C Block Read: i2c_smbus_read_i2c_block_data() |
187 | ============== | 200 | ================================================ |
188 | 201 | ||
189 | This command reads a block of bytes from a device, from a | 202 | This command reads a block of bytes from a device, from a |
190 | designated register that is specified through the Comm byte. | 203 | designated register that is specified through the Comm byte. |
@@ -203,8 +216,8 @@ S Addr Wr [A] Comm1 [A] Comm2 [A] | |||
203 | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P | 216 | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P |
204 | 217 | ||
205 | 218 | ||
206 | I2C Block Write | 219 | I2C Block Write: i2c_smbus_write_i2c_block_data() |
207 | =============== | 220 | ================================================== |
208 | 221 | ||
209 | The opposite of the Block Read command, this writes bytes to | 222 | The opposite of the Block Read command, this writes bytes to |
210 | a device, to a designated register that is specified through the | 223 | a device, to a designated register that is specified through the |
@@ -212,5 +225,3 @@ Comm byte. Note that command lengths of 0, 2, or more bytes are | |||
212 | supported as they are indistinguishable from data. | 225 | supported as they are indistinguishable from data. |
213 | 226 | ||
214 | S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P | 227 | S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P |
215 | |||
216 | |||
diff --git a/Documentation/i2c/upgrading-clients b/Documentation/i2c/upgrading-clients new file mode 100644 index 000000000000..9a45f9bb6a25 --- /dev/null +++ b/Documentation/i2c/upgrading-clients | |||
@@ -0,0 +1,281 @@ | |||
1 | Upgrading I2C Drivers to the new 2.6 Driver Model | ||
2 | ================================================= | ||
3 | |||
4 | Ben Dooks <ben-linux@fluff.org> | ||
5 | |||
6 | Introduction | ||
7 | ------------ | ||
8 | |||
9 | This guide outlines how to alter existing Linux 2.6 client drivers from | ||
10 | the old to the new new binding methods. | ||
11 | |||
12 | |||
13 | Example old-style driver | ||
14 | ------------------------ | ||
15 | |||
16 | |||
17 | struct example_state { | ||
18 | struct i2c_client client; | ||
19 | .... | ||
20 | }; | ||
21 | |||
22 | static struct i2c_driver example_driver; | ||
23 | |||
24 | static unsigned short ignore[] = { I2C_CLIENT_END }; | ||
25 | static unsigned short normal_addr[] = { OUR_ADDR, I2C_CLIENT_END }; | ||
26 | |||
27 | I2C_CLIENT_INSMOD; | ||
28 | |||
29 | static int example_attach(struct i2c_adapter *adap, int addr, int kind) | ||
30 | { | ||
31 | struct example_state *state; | ||
32 | struct device *dev = &adap->dev; /* to use for dev_ reports */ | ||
33 | int ret; | ||
34 | |||
35 | state = kzalloc(sizeof(struct example_state), GFP_KERNEL); | ||
36 | if (state == NULL) { | ||
37 | dev_err(dev, "failed to create our state\n"); | ||
38 | return -ENOMEM; | ||
39 | } | ||
40 | |||
41 | example->client.addr = addr; | ||
42 | example->client.flags = 0; | ||
43 | example->client.adapter = adap; | ||
44 | |||
45 | i2c_set_clientdata(&state->i2c_client, state); | ||
46 | strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE); | ||
47 | |||
48 | ret = i2c_attach_client(&state->i2c_client); | ||
49 | if (ret < 0) { | ||
50 | dev_err(dev, "failed to attach client\n"); | ||
51 | kfree(state); | ||
52 | return ret; | ||
53 | } | ||
54 | |||
55 | dev = &state->i2c_client.dev; | ||
56 | |||
57 | /* rest of the initialisation goes here. */ | ||
58 | |||
59 | dev_info(dev, "example client created\n"); | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int __devexit example_detach(struct i2c_client *client) | ||
65 | { | ||
66 | struct example_state *state = i2c_get_clientdata(client); | ||
67 | |||
68 | i2c_detach_client(client); | ||
69 | kfree(state); | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int example_attach_adapter(struct i2c_adapter *adap) | ||
74 | { | ||
75 | return i2c_probe(adap, &addr_data, example_attach); | ||
76 | } | ||
77 | |||
78 | static struct i2c_driver example_driver = { | ||
79 | .driver = { | ||
80 | .owner = THIS_MODULE, | ||
81 | .name = "example", | ||
82 | }, | ||
83 | .attach_adapter = example_attach_adapter, | ||
84 | .detach_client = __devexit_p(example_detach), | ||
85 | .suspend = example_suspend, | ||
86 | .resume = example_resume, | ||
87 | }; | ||
88 | |||
89 | |||
90 | Updating the client | ||
91 | ------------------- | ||
92 | |||
93 | The new style binding model will check against a list of supported | ||
94 | devices and their associated address supplied by the code registering | ||
95 | the busses. This means that the driver .attach_adapter and | ||
96 | .detach_adapter methods can be removed, along with the addr_data, | ||
97 | as follows: | ||
98 | |||
99 | - static struct i2c_driver example_driver; | ||
100 | |||
101 | - static unsigned short ignore[] = { I2C_CLIENT_END }; | ||
102 | - static unsigned short normal_addr[] = { OUR_ADDR, I2C_CLIENT_END }; | ||
103 | |||
104 | - I2C_CLIENT_INSMOD; | ||
105 | |||
106 | - static int example_attach_adapter(struct i2c_adapter *adap) | ||
107 | - { | ||
108 | - return i2c_probe(adap, &addr_data, example_attach); | ||
109 | - } | ||
110 | |||
111 | static struct i2c_driver example_driver = { | ||
112 | - .attach_adapter = example_attach_adapter, | ||
113 | - .detach_client = __devexit_p(example_detach), | ||
114 | } | ||
115 | |||
116 | Add the probe and remove methods to the i2c_driver, as so: | ||
117 | |||
118 | static struct i2c_driver example_driver = { | ||
119 | + .probe = example_probe, | ||
120 | + .remove = __devexit_p(example_remove), | ||
121 | } | ||
122 | |||
123 | Change the example_attach method to accept the new parameters | ||
124 | which include the i2c_client that it will be working with: | ||
125 | |||
126 | - static int example_attach(struct i2c_adapter *adap, int addr, int kind) | ||
127 | + static int example_probe(struct i2c_client *client, | ||
128 | + const struct i2c_device_id *id) | ||
129 | |||
130 | Change the name of example_attach to example_probe to align it with the | ||
131 | i2c_driver entry names. The rest of the probe routine will now need to be | ||
132 | changed as the i2c_client has already been setup for use. | ||
133 | |||
134 | The necessary client fields have already been setup before | ||
135 | the probe function is called, so the following client setup | ||
136 | can be removed: | ||
137 | |||
138 | - example->client.addr = addr; | ||
139 | - example->client.flags = 0; | ||
140 | - example->client.adapter = adap; | ||
141 | - | ||
142 | - strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE); | ||
143 | |||
144 | The i2c_set_clientdata is now: | ||
145 | |||
146 | - i2c_set_clientdata(&state->client, state); | ||
147 | + i2c_set_clientdata(client, state); | ||
148 | |||
149 | The call to i2c_attach_client is no longer needed, if the probe | ||
150 | routine exits successfully, then the driver will be automatically | ||
151 | attached by the core. Change the probe routine as so: | ||
152 | |||
153 | - ret = i2c_attach_client(&state->i2c_client); | ||
154 | - if (ret < 0) { | ||
155 | - dev_err(dev, "failed to attach client\n"); | ||
156 | - kfree(state); | ||
157 | - return ret; | ||
158 | - } | ||
159 | |||
160 | |||
161 | Remove the storage of 'struct i2c_client' from the 'struct example_state' | ||
162 | as we are provided with the i2c_client in our example_probe. Instead we | ||
163 | store a pointer to it for when it is needed. | ||
164 | |||
165 | struct example_state { | ||
166 | - struct i2c_client client; | ||
167 | + struct i2c_client *client; | ||
168 | |||
169 | the new i2c client as so: | ||
170 | |||
171 | - struct device *dev = &adap->dev; /* to use for dev_ reports */ | ||
172 | + struct device *dev = &i2c_client->dev; /* to use for dev_ reports */ | ||
173 | |||
174 | And remove the change after our client is attached, as the driver no | ||
175 | longer needs to register a new client structure with the core: | ||
176 | |||
177 | - dev = &state->i2c_client.dev; | ||
178 | |||
179 | In the probe routine, ensure that the new state has the client stored | ||
180 | in it: | ||
181 | |||
182 | static int example_probe(struct i2c_client *i2c_client, | ||
183 | const struct i2c_device_id *id) | ||
184 | { | ||
185 | struct example_state *state; | ||
186 | struct device *dev = &i2c_client->dev; | ||
187 | int ret; | ||
188 | |||
189 | state = kzalloc(sizeof(struct example_state), GFP_KERNEL); | ||
190 | if (state == NULL) { | ||
191 | dev_err(dev, "failed to create our state\n"); | ||
192 | return -ENOMEM; | ||
193 | } | ||
194 | |||
195 | + state->client = i2c_client; | ||
196 | |||
197 | Update the detach method, by changing the name to _remove and | ||
198 | to delete the i2c_detach_client call. It is possible that you | ||
199 | can also remove the ret variable as it is not not needed for | ||
200 | any of the core functions. | ||
201 | |||
202 | - static int __devexit example_detach(struct i2c_client *client) | ||
203 | + static int __devexit example_remove(struct i2c_client *client) | ||
204 | { | ||
205 | struct example_state *state = i2c_get_clientdata(client); | ||
206 | |||
207 | - i2c_detach_client(client); | ||
208 | |||
209 | And finally ensure that we have the correct ID table for the i2c-core | ||
210 | and other utilities: | ||
211 | |||
212 | + struct i2c_device_id example_idtable[] = { | ||
213 | + { "example", 0 }, | ||
214 | + { } | ||
215 | +}; | ||
216 | + | ||
217 | +MODULE_DEVICE_TABLE(i2c, example_idtable); | ||
218 | |||
219 | static struct i2c_driver example_driver = { | ||
220 | .driver = { | ||
221 | .owner = THIS_MODULE, | ||
222 | .name = "example", | ||
223 | }, | ||
224 | + .id_table = example_ids, | ||
225 | |||
226 | |||
227 | Our driver should now look like this: | ||
228 | |||
229 | struct example_state { | ||
230 | struct i2c_client *client; | ||
231 | .... | ||
232 | }; | ||
233 | |||
234 | static int example_probe(struct i2c_client *client, | ||
235 | const struct i2c_device_id *id) | ||
236 | { | ||
237 | struct example_state *state; | ||
238 | struct device *dev = &client->dev; | ||
239 | |||
240 | state = kzalloc(sizeof(struct example_state), GFP_KERNEL); | ||
241 | if (state == NULL) { | ||
242 | dev_err(dev, "failed to create our state\n"); | ||
243 | return -ENOMEM; | ||
244 | } | ||
245 | |||
246 | state->client = client; | ||
247 | i2c_set_clientdata(client, state); | ||
248 | |||
249 | /* rest of the initialisation goes here. */ | ||
250 | |||
251 | dev_info(dev, "example client created\n"); | ||
252 | |||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static int __devexit example_remove(struct i2c_client *client) | ||
257 | { | ||
258 | struct example_state *state = i2c_get_clientdata(client); | ||
259 | |||
260 | kfree(state); | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | static struct i2c_device_id example_idtable[] = { | ||
265 | { "example", 0 }, | ||
266 | { } | ||
267 | }; | ||
268 | |||
269 | MODULE_DEVICE_TABLE(i2c, example_idtable); | ||
270 | |||
271 | static struct i2c_driver example_driver = { | ||
272 | .driver = { | ||
273 | .owner = THIS_MODULE, | ||
274 | .name = "example", | ||
275 | }, | ||
276 | .id_table = example_idtable, | ||
277 | .probe = example_probe, | ||
278 | .remove = __devexit_p(example_remove), | ||
279 | .suspend = example_suspend, | ||
280 | .resume = example_resume, | ||
281 | }; | ||
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index ee75cbace28d..6b61b3a2e90b 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -25,14 +25,29 @@ routines, and should be zero-initialized except for fields with data you | |||
25 | provide. A client structure holds device-specific information like the | 25 | provide. A client structure holds device-specific information like the |
26 | driver model device node, and its I2C address. | 26 | driver model device node, and its I2C address. |
27 | 27 | ||
28 | /* iff driver uses driver model ("new style") binding model: */ | ||
29 | |||
30 | static struct i2c_device_id foo_idtable[] = { | ||
31 | { "foo", my_id_for_foo }, | ||
32 | { "bar", my_id_for_bar }, | ||
33 | { } | ||
34 | }; | ||
35 | |||
36 | MODULE_DEVICE_TABLE(i2c, foo_idtable); | ||
37 | |||
28 | static struct i2c_driver foo_driver = { | 38 | static struct i2c_driver foo_driver = { |
29 | .driver = { | 39 | .driver = { |
30 | .name = "foo", | 40 | .name = "foo", |
31 | }, | 41 | }, |
32 | 42 | ||
33 | /* iff driver uses driver model ("new style") binding model: */ | 43 | /* iff driver uses driver model ("new style") binding model: */ |
44 | .id_table = foo_ids, | ||
34 | .probe = foo_probe, | 45 | .probe = foo_probe, |
35 | .remove = foo_remove, | 46 | .remove = foo_remove, |
47 | /* if device autodetection is needed: */ | ||
48 | .class = I2C_CLASS_SOMETHING, | ||
49 | .detect = foo_detect, | ||
50 | .address_data = &addr_data, | ||
36 | 51 | ||
37 | /* else, driver uses "legacy" binding model: */ | 52 | /* else, driver uses "legacy" binding model: */ |
38 | .attach_adapter = foo_attach_adapter, | 53 | .attach_adapter = foo_attach_adapter, |
@@ -173,10 +188,9 @@ handle may be used during foo_probe(). If foo_probe() reports success | |||
173 | (zero not a negative status code) it may save the handle and use it until | 188 | (zero not a negative status code) it may save the handle and use it until |
174 | foo_remove() returns. That binding model is used by most Linux drivers. | 189 | foo_remove() returns. That binding model is used by most Linux drivers. |
175 | 190 | ||
176 | Drivers match devices when i2c_client.driver_name and the driver name are | 191 | The probe function is called when an entry in the id_table name field |
177 | the same; this approach is used in several other busses that don't have | 192 | matches the device's name. It is passed the entry that was matched so |
178 | device typing support in the hardware. The driver and module name should | 193 | the driver knows which one in the table matched. |
179 | match, so hotplug/coldplug mechanisms will modprobe the driver. | ||
180 | 194 | ||
181 | 195 | ||
182 | Device Creation (Standard driver model) | 196 | Device Creation (Standard driver model) |
@@ -207,6 +221,31 @@ in the I2C bus driver. You may want to save the returned i2c_client | |||
207 | reference for later use. | 221 | reference for later use. |
208 | 222 | ||
209 | 223 | ||
224 | Device Detection (Standard driver model) | ||
225 | ---------------------------------------- | ||
226 | |||
227 | Sometimes you do not know in advance which I2C devices are connected to | ||
228 | a given I2C bus. This is for example the case of hardware monitoring | ||
229 | devices on a PC's SMBus. In that case, you may want to let your driver | ||
230 | detect supported devices automatically. This is how the legacy model | ||
231 | was working, and is now available as an extension to the standard | ||
232 | driver model (so that we can finally get rid of the legacy model.) | ||
233 | |||
234 | You simply have to define a detect callback which will attempt to | ||
235 | identify supported devices (returning 0 for supported ones and -ENODEV | ||
236 | for unsupported ones), a list of addresses to probe, and a device type | ||
237 | (or class) so that only I2C buses which may have that type of device | ||
238 | connected (and not otherwise enumerated) will be probed. The i2c | ||
239 | core will then call you back as needed and will instantiate a device | ||
240 | for you for every successful detection. | ||
241 | |||
242 | Note that this mechanism is purely optional and not suitable for all | ||
243 | devices. You need some reliable way to identify the supported devices | ||
244 | (typically using device-specific, dedicated identification registers), | ||
245 | otherwise misdetections are likely to occur and things can get wrong | ||
246 | quickly. | ||
247 | |||
248 | |||
210 | Device Deletion (Standard driver model) | 249 | Device Deletion (Standard driver model) |
211 | --------------------------------------- | 250 | --------------------------------------- |
212 | 251 | ||
@@ -559,7 +598,6 @@ SMBus communication | |||
559 | in terms of it. Never use this function directly! | 598 | in terms of it. Never use this function directly! |
560 | 599 | ||
561 | 600 | ||
562 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); | ||
563 | extern s32 i2c_smbus_read_byte(struct i2c_client * client); | 601 | extern s32 i2c_smbus_read_byte(struct i2c_client * client); |
564 | extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); | 602 | extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); |
565 | extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); | 603 | extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); |
@@ -568,30 +606,31 @@ SMBus communication | |||
568 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); | 606 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); |
569 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, | 607 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, |
570 | u8 command, u16 value); | 608 | u8 command, u16 value); |
609 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, | ||
610 | u8 command, u8 *values); | ||
571 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, | 611 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
572 | u8 command, u8 length, | 612 | u8 command, u8 length, |
573 | u8 *values); | 613 | u8 *values); |
574 | extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, | 614 | extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, |
575 | u8 command, u8 length, u8 *values); | 615 | u8 command, u8 length, u8 *values); |
576 | |||
577 | These ones were removed in Linux 2.6.10 because they had no users, but could | ||
578 | be added back later if needed: | ||
579 | |||
580 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, | ||
581 | u8 command, u8 *values); | ||
582 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, | 616 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, |
583 | u8 command, u8 length, | 617 | u8 command, u8 length, |
584 | u8 *values); | 618 | u8 *values); |
619 | |||
620 | These ones were removed from i2c-core because they had no users, but could | ||
621 | be added back later if needed: | ||
622 | |||
623 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); | ||
585 | extern s32 i2c_smbus_process_call(struct i2c_client * client, | 624 | extern s32 i2c_smbus_process_call(struct i2c_client * client, |
586 | u8 command, u16 value); | 625 | u8 command, u16 value); |
587 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, | 626 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, |
588 | u8 command, u8 length, | 627 | u8 command, u8 length, |
589 | u8 *values) | 628 | u8 *values) |
590 | 629 | ||
591 | All these transactions return -1 on failure. The 'write' transactions | 630 | All these transactions return a negative errno value on failure. The 'write' |
592 | return 0 on success; the 'read' transactions return the read value, except | 631 | transactions return 0 on success; the 'read' transactions return the read |
593 | for read_block, which returns the number of values read. The block buffers | 632 | value, except for block transactions, which return the number of values |
594 | need not be longer than 32 bytes. | 633 | read. The block buffers need not be longer than 32 bytes. |
595 | 634 | ||
596 | You can read the file `smbus-protocol' for more information about the | 635 | You can read the file `smbus-protocol' for more information about the |
597 | actual SMBus protocol. | 636 | actual SMBus protocol. |