Blame view

Documentation/i2c/smbus-protocol.rst 9.64 KB
f6fcefa10   Luca Ceresoli   docs: i2c: rename...
1
2
3
  ==================
  The SMBus Protocol
  ==================
1a31a88f4   David Brownell   i2c: Improve smbu...
4

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
  The following is a summary of the SMBus protocol. It applies to
  all revisions of the protocol (1.0, 1.1, and 2.0).
  Certain protocol features which are not supported by
  this package are briefly described at the end of this document.
  
  Some adapters understand only the SMBus (System Management Bus) protocol,
  which is a subset from the I2C protocol. Fortunately, many devices use
  only the same subset, which makes it possible to put them on an SMBus.
1a31a88f4   David Brownell   i2c: Improve smbu...
13

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
17
18
19
  If you write a driver for some I2C device, please try to use the SMBus
  commands if at all possible (if the device uses only that subset of the
  I2C protocol). This makes it possible to use the device driver on both
  SMBus adapters and I2C adapters (the SMBus command set is automatically
  translated to I2C on I2C adapters, but plain I2C commands can not be
  handled at all on most pure SMBus adapters).
1a31a88f4   David Brownell   i2c: Improve smbu...
20
21
22
23
24
  Below is a list of SMBus protocol operations, and the functions executing
  them.  Note that the names used in the SMBus protocol specifications usually
  don't match these function names.  For some of the operations which pass a
  single data byte, the functions using SMBus protocol operation names execute
  a different protocol operation entirely.
a1681781d   Jean Delvare   i2c: Mention func...
25
26
27
  Each transaction type corresponds to a functionality flag. Before calling a
  transaction function, a device driver should always check (just once) for
  the corresponding functionality flag to ensure that the underlying I2C
924fbb4d2   Luca Ceresoli   docs: i2c: smbus-...
28
29
  adapter supports the transaction in question. See :doc:`functionality` for
  the details.
a1681781d   Jean Delvare   i2c: Mention func...
30

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
  
  Key to symbols
  ==============
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
34
  =============== =============================================================
026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
35
36
37
  S               Start condition
  P               Stop condition
  Rd/Wr (1 bit)   Read/Write bit. Rd equals 1, Wr equals 0.
9e89d6187   Luca Ceresoli   docs: i2c: smbus-...
38
  A, NA (1 bit)   Acknowledge (ACK) and Not Acknowledge (NACK) bit
026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
39
  Addr  (7 bits)  I2C 7 bit address. Note that this can be expanded as usual to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
                  get a 10 bit I2C address.
026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
41
  Comm  (8 bits)  Command byte, a data byte which often selects a register on
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
                  the device.
026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
43
  Data  (8 bits)  A plain data byte. Sometimes, I write DataLow, DataHigh
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
                  for 16 bit data.
026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
45
  Count (8 bits)  A data byte containing the length of a block operation.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46

026c0fe66   Luca Ceresoli   docs: i2c: smbus-...
47
  [..]            Data sent by I2C device, as opposed to data sent by the host
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
48
49
                  adapter.
  =============== =============================================================
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50

67c2e6657   Jean Delvare   i2c: Delete unuse...
51
52
  SMBus Quick Command
  ===================
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
54
  This sends a single bit to the device, at the place of the Rd/Wr bit::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

a5765124e   Daniel Schaefer   Documentation/i2c...
56
    S Addr Rd/Wr [A] P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57

a1681781d   Jean Delvare   i2c: Mention func...
58
  Functionality flag: I2C_FUNC_SMBUS_QUICK
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
60
61
62
63
  SMBus Receive Byte
  ==================
  
  Implemented by i2c_smbus_read_byte()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
67
  
  This reads a single byte from a device, without specifying a device
  register. Some devices are so simple that this interface is enough; for
  others, it is a shorthand if you want to read the same register as in
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
68
  the previous SMBus command::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
70
    S Addr Rd [A] [Data] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71

a1681781d   Jean Delvare   i2c: Mention func...
72
  Functionality flag: I2C_FUNC_SMBUS_READ_BYTE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
74
75
76
77
  SMBus Send Byte
  ===============
  
  Implemented by i2c_smbus_write_byte()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78

1a31a88f4   David Brownell   i2c: Improve smbu...
79
80
  This operation is the reverse of Receive Byte: it sends a single byte
  to a device.  See Receive Byte for more information.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
82
83
84
  ::
  
    S Addr Wr [A] Data [A] P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85

a1681781d   Jean Delvare   i2c: Mention func...
86
  Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
88
89
90
91
  SMBus Read Byte
  ===============
  
  Implemented by i2c_smbus_read_byte_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
  
  This reads a single byte from a device, from a designated register.
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
94
  The register is specified through the Comm byte::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
96
    S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
97

a1681781d   Jean Delvare   i2c: Mention func...
98
  Functionality flag: I2C_FUNC_SMBUS_READ_BYTE_DATA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
100
101
102
103
  SMBus Read Word
  ===============
  
  Implemented by i2c_smbus_read_word_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104

1a31a88f4   David Brownell   i2c: Improve smbu...
105
  This operation is very like Read Byte; again, data is read from a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
  device, from a designated register that is specified through the Comm
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
107
  byte. But this time, the data is a complete word (16 bits)::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
109
    S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110

a1681781d   Jean Delvare   i2c: Mention func...
111
  Functionality flag: I2C_FUNC_SMBUS_READ_WORD_DATA
b36cbb70e   Luca Ceresoli   docs: i2c: smbus-...
112
  Note the convenience function i2c_smbus_read_word_swapped() is
06a67848c   Jonathan Cameron   i2c: Functions fo...
113
114
  available for reads where the two data bytes are the other way
  around (not SMBus compliant, but very popular.)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
116
117
118
119
  SMBus Write Byte
  ================
  
  Implemented by i2c_smbus_write_byte_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
122
  
  This writes a single byte to a device, to a designated register. The
  register is specified through the Comm byte. This is the opposite of
1a31a88f4   David Brownell   i2c: Improve smbu...
123
  the Read Byte operation.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
125
126
127
  ::
  
    S Addr Wr [A] Comm [A] Data [A] P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128

a1681781d   Jean Delvare   i2c: Mention func...
129
  Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE_DATA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
131
132
133
134
  SMBus Write Word
  ================
  
  Implemented by i2c_smbus_write_word_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135

1a31a88f4   David Brownell   i2c: Improve smbu...
136
  This is the opposite of the Read Word operation. 16 bits
414a59645   Luca Ceresoli   docs: i2c: smbus-...
137
  of data are written to a device, to the designated register that is
c7148b059   Luca Ceresoli   docs: i2c: smbus-...
138
  specified through the Comm byte::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
140
    S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141

a1681781d   Jean Delvare   i2c: Mention func...
142
  Functionality flag: I2C_FUNC_SMBUS_WRITE_WORD_DATA
b36cbb70e   Luca Ceresoli   docs: i2c: smbus-...
143
  Note the convenience function i2c_smbus_write_word_swapped() is
06a67848c   Jonathan Cameron   i2c: Functions fo...
144
145
  available for writes where the two data bytes are the other way
  around (not SMBus compliant, but very popular.)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
147
148
  SMBus Process Call
  ==================
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
  
  This command selects a device register (through the Comm byte), sends
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
151
  16 bits of data to it, and reads 16 bits of data in return::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
153
154
    S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
                                 S Addr Rd [A] [DataLow] A [DataHigh] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

a1681781d   Jean Delvare   i2c: Mention func...
156
  Functionality flag: I2C_FUNC_SMBUS_PROC_CALL
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
158
159
160
161
  SMBus Block Read
  ================
  
  Implemented by i2c_smbus_read_block_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
163
  This command reads a block of up to 32 bytes from a device, from a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
  designated register that is specified through the Comm byte. The amount
  of data is specified by the device in the Count byte.
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
166
167
168
169
  ::
  
    S Addr Wr [A] Comm [A]
               S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170

a1681781d   Jean Delvare   i2c: Mention func...
171
  Functionality flag: I2C_FUNC_SMBUS_READ_BLOCK_DATA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
173
174
175
176
  SMBus Block Write
  =================
  
  Implemented by i2c_smbus_write_block_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
178
  The opposite of the Block Read command, this writes up to 32 bytes to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
  a device, to a designated register that is specified through the
  Comm byte. The amount of data is specified in the Count byte.
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
181
182
183
  ::
  
    S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184

a1681781d   Jean Delvare   i2c: Mention func...
185
  Functionality flag: I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186

1a31a88f4   David Brownell   i2c: Improve smbu...
187
188
  SMBus Block Write - Block Read Process Call
  ===========================================
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189

1a31a88f4   David Brownell   i2c: Improve smbu...
190
191
  SMBus Block Write - Block Read Process Call was introduced in
  Revision 2.0 of the specification.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
192
193
  
  This command selects a device register (through the Comm byte), sends
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
194
  1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
196
197
    S Addr Wr [A] Comm [A] Count [A] Data [A] ...
                                 S Addr Rd [A] [Count] A [Data] ... A P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198

a1681781d   Jean Delvare   i2c: Mention func...
199
  Functionality flag: I2C_FUNC_SMBUS_BLOCK_PROC_CALL
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
201
202
203
204
205
206
207
  
  SMBus Host Notify
  =================
  
  This command is sent from a SMBus device acting as a master to the
  SMBus host acting as a slave.
  It is the same form as Write Word, with the command code replaced by the
  alerting device's address.
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
208
209
210
  ::
  
    [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211

e456cd37b   Benjamin Tissoires   i2c: smbus: add S...
212
  This is implemented in the following way in the Linux kernel:
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
213

4d5538f58   Benjamin Tissoires   i2c: use an IRQ t...
214
215
216
217
218
219
220
221
  * I2C bus drivers which support SMBus Host Notify should report
    I2C_FUNC_SMBUS_HOST_NOTIFY.
  * I2C bus drivers trigger SMBus Host Notify by a call to
    i2c_handle_smbus_host_notify().
  * I2C drivers for devices which can trigger SMBus Host Notify will have
    client->irq assigned to a Host Notify IRQ if noone else specified an other.
  
  There is currently no way to retrieve the data parameter from the client.
e456cd37b   Benjamin Tissoires   i2c: smbus: add S...
222

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
  
  Packet Error Checking (PEC)
  ===========================
1a31a88f4   David Brownell   i2c: Improve smbu...
226

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  Packet Error Checking was introduced in Revision 1.1 of the specification.
1a31a88f4   David Brownell   i2c: Improve smbu...
228
229
  PEC adds a CRC-8 error-checking byte to transfers using it, immediately
  before the terminating STOP.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
233
  
  
  Address Resolution Protocol (ARP)
  =================================
1a31a88f4   David Brownell   i2c: Improve smbu...
234

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
238
239
240
241
  The Address Resolution Protocol was introduced in Revision 2.0 of
  the specification. It is a higher-layer protocol which uses the
  messages above.
  
  ARP adds device enumeration and dynamic address assignment to
  the protocol. All ARP communications use slave address 0x61 and
  require PEC checksums.
b5527a776   Jean Delvare   i2c: Add SMBus al...
242
243
244
245
246
247
248
249
250
251
  SMBus Alert
  ===========
  
  SMBus Alert was introduced in Revision 1.0 of the specification.
  
  The SMBus alert protocol allows several SMBus slave devices to share a
  single interrupt pin on the SMBus master, while still allowing the master
  to know which slave triggered the interrupt.
  
  This is implemented the following way in the Linux kernel:
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
252

b5527a776   Jean Delvare   i2c: Add SMBus al...
253
  * I2C bus drivers which support SMBus alert should call
ed6805222   Wolfram Sang   i2c: convert SMBu...
254
    i2c_new_smbus_alert_device() to install SMBus alert support.
b5527a776   Jean Delvare   i2c: Add SMBus al...
255
256
  * I2C drivers for devices which can trigger SMBus alerts should implement
    the optional alert() callback.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
258
  I2C Block Transactions
  ======================
1a31a88f4   David Brownell   i2c: Improve smbu...
259

95b83774e   Luca Ceresoli   docs: i2c: smbus-...
260
261
262
263
  The following I2C block transactions are similar to the SMBus Block Read
  and Write operations, except these do not have a Count byte. They are
  supported by the SMBus layer and are described here for completeness, but
  they are *NOT* defined by the SMBus specification.
1a31a88f4   David Brownell   i2c: Improve smbu...
264

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
  I2C block transactions do not limit the number of bytes transferred
  but the SMBus layer places a limit of 32 bytes.
3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
267
268
269
270
  I2C Block Read
  ==============
  
  Implemented by i2c_smbus_read_i2c_block_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
272
273
  This command reads a block of bytes from a device, from a
  designated register that is specified through the Comm byte::
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
275
276
    S Addr Wr [A] Comm [A]
               S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277

a1681781d   Jean Delvare   i2c: Mention func...
278
  Functionality flag: I2C_FUNC_SMBUS_READ_I2C_BLOCK
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279

3c13f1fbe   Luca Ceresoli   docs: i2c: smbus-...
280
281
282
283
  I2C Block Write
  ===============
  
  Implemented by i2c_smbus_write_i2c_block_data()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284

ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
285
  The opposite of the Block Read command, this writes bytes to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
288
  a device, to a designated register that is specified through the
  Comm byte. Note that command lengths of 0, 2, or more bytes are
  supported as they are indistinguishable from data.
ccf988b66   Mauro Carvalho Chehab   docs: i2c: conver...
289
290
291
  ::
  
    S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
a1681781d   Jean Delvare   i2c: Mention func...
292
293
  
  Functionality flag: I2C_FUNC_SMBUS_WRITE_I2C_BLOCK