diff options
Diffstat (limited to 'Documentation/i2c')
-rw-r--r-- | Documentation/i2c/functionality | 95 | ||||
-rw-r--r-- | Documentation/i2c/smbus-protocol | 81 |
2 files changed, 98 insertions, 78 deletions
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..03f08fb491cc 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: i2c_smbus_write_quick() |
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 | |||