blob: 00d8e17d0acabca6e68e86ad7d8a182b821a0887 [file] [log] [blame]
Luca Ceresolif6fcefa2020-01-29 16:19:51 +01001==================
2The SMBus Protocol
3==================
David Brownell1a31a882008-05-11 20:37:05 +02004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005The following is a summary of the SMBus protocol. It applies to
6all revisions of the protocol (1.0, 1.1, and 2.0).
7Certain protocol features which are not supported by
8this package are briefly described at the end of this document.
9
10Some adapters understand only the SMBus (System Management Bus) protocol,
11which is a subset from the I2C protocol. Fortunately, many devices use
12only the same subset, which makes it possible to put them on an SMBus.
David Brownell1a31a882008-05-11 20:37:05 +020013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014If you write a driver for some I2C device, please try to use the SMBus
15commands if at all possible (if the device uses only that subset of the
16I2C protocol). This makes it possible to use the device driver on both
17SMBus adapters and I2C adapters (the SMBus command set is automatically
18translated to I2C on I2C adapters, but plain I2C commands can not be
19handled at all on most pure SMBus adapters).
20
David Brownell1a31a882008-05-11 20:37:05 +020021Below is a list of SMBus protocol operations, and the functions executing
22them. Note that the names used in the SMBus protocol specifications usually
23don't match these function names. For some of the operations which pass a
24single data byte, the functions using SMBus protocol operation names execute
25a different protocol operation entirely.
26
Jean Delvarea1681782012-12-16 21:11:55 +010027Each transaction type corresponds to a functionality flag. Before calling a
28transaction function, a device driver should always check (just once) for
29the corresponding functionality flag to ensure that the underlying I2C
Mauro Carvalho Chehab25edd3a2021-06-16 08:27:33 +020030adapter supports the transaction in question. See
31Documentation/i2c/functionality.rst for the details.
Jean Delvarea1681782012-12-16 21:11:55 +010032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34Key to symbols
35==============
36
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030037=============== =============================================================
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010038S Start condition
Miquel Raynalbed68f42021-11-15 12:08:18 +010039Sr Repeated start condition, used to switch from write to
40 read mode.
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010041P Stop condition
42Rd/Wr (1 bit) Read/Write bit. Rd equals 1, Wr equals 0.
Luca Ceresoli9e89d612020-01-29 16:19:39 +010043A, NA (1 bit) Acknowledge (ACK) and Not Acknowledge (NACK) bit
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010044Addr (7 bits) I2C 7 bit address. Note that this can be expanded as usual to
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 get a 10 bit I2C address.
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010046Comm (8 bits) Command byte, a data byte which often selects a register on
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 the device.
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010048Data (8 bits) A plain data byte. Sometimes, I write DataLow, DataHigh
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 for 16 bit data.
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010050Count (8 bits) A data byte containing the length of a block operation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Luca Ceresoli026c0fe2020-01-29 16:19:38 +010052[..] Data sent by I2C device, as opposed to data sent by the host
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030053 adapter.
54=============== =============================================================
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56
Jean Delvare67c2e662008-07-14 22:38:23 +020057SMBus Quick Command
58===================
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030060This sends a single bit to the device, at the place of the Rd/Wr bit::
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Daniel Schaefera5765122020-06-14 20:23:55 +020062 S Addr Rd/Wr [A] P
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Jean Delvarea1681782012-12-16 21:11:55 +010064Functionality flag: I2C_FUNC_SMBUS_QUICK
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +010067SMBus Receive Byte
68==================
69
70Implemented by i2c_smbus_read_byte()
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72This reads a single byte from a device, without specifying a device
73register. Some devices are so simple that this interface is enough; for
74others, it is a shorthand if you want to read the same register as in
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030075the previous SMBus command::
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030077 S Addr Rd [A] [Data] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Jean Delvarea1681782012-12-16 21:11:55 +010079Functionality flag: I2C_FUNC_SMBUS_READ_BYTE
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +010082SMBus Send Byte
83===============
84
85Implemented by i2c_smbus_write_byte()
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
David Brownell1a31a882008-05-11 20:37:05 +020087This operation is the reverse of Receive Byte: it sends a single byte
88to a device. See Receive Byte for more information.
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030090::
91
92 S Addr Wr [A] Data [A] P
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Jean Delvarea1681782012-12-16 21:11:55 +010094Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +010097SMBus Read Byte
98===============
99
100Implemented by i2c_smbus_read_byte_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102This reads a single byte from a device, from a designated register.
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300103The register is specified through the Comm byte::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Miquel Raynalbed68f42021-11-15 12:08:18 +0100105 S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Jean Delvarea1681782012-12-16 21:11:55 +0100107Functionality flag: I2C_FUNC_SMBUS_READ_BYTE_DATA
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100110SMBus Read Word
111===============
112
113Implemented by i2c_smbus_read_word_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
David Brownell1a31a882008-05-11 20:37:05 +0200115This operation is very like Read Byte; again, data is read from a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116device, from a designated register that is specified through the Comm
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300117byte. But this time, the data is a complete word (16 bits)::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Miquel Raynalbed68f42021-11-15 12:08:18 +0100119 S Addr Wr [A] Comm [A] Sr Addr Rd [A] [DataLow] A [DataHigh] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Jean Delvarea1681782012-12-16 21:11:55 +0100121Functionality flag: I2C_FUNC_SMBUS_READ_WORD_DATA
122
Luca Ceresolib36cbb72020-01-29 16:19:41 +0100123Note the convenience function i2c_smbus_read_word_swapped() is
Jonathan Cameron06a67842011-10-30 13:47:25 +0100124available for reads where the two data bytes are the other way
125around (not SMBus compliant, but very popular.)
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100128SMBus Write Byte
129================
130
131Implemented by i2c_smbus_write_byte_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133This writes a single byte to a device, to a designated register. The
134register is specified through the Comm byte. This is the opposite of
David Brownell1a31a882008-05-11 20:37:05 +0200135the Read Byte operation.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300137::
138
139 S Addr Wr [A] Comm [A] Data [A] P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Jean Delvarea1681782012-12-16 21:11:55 +0100141Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE_DATA
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100144SMBus Write Word
145================
146
147Implemented by i2c_smbus_write_word_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
David Brownell1a31a882008-05-11 20:37:05 +0200149This is the opposite of the Read Word operation. 16 bits
Luca Ceresoli414a5962020-01-29 16:19:42 +0100150of data are written to a device, to the designated register that is
Luca Ceresolic7148b052020-01-29 16:19:43 +0100151specified through the Comm byte::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300153 S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Jean Delvarea1681782012-12-16 21:11:55 +0100155Functionality flag: I2C_FUNC_SMBUS_WRITE_WORD_DATA
156
Luca Ceresolib36cbb72020-01-29 16:19:41 +0100157Note the convenience function i2c_smbus_write_word_swapped() is
Jonathan Cameron06a67842011-10-30 13:47:25 +0100158available for writes where the two data bytes are the other way
159around (not SMBus compliant, but very popular.)
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100162SMBus Process Call
163==================
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165This command selects a device register (through the Comm byte), sends
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030016616 bits of data to it, and reads 16 bits of data in return::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300168 S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
Miquel Raynalbed68f42021-11-15 12:08:18 +0100169 Sr Addr Rd [A] [DataLow] A [DataHigh] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Jean Delvarea1681782012-12-16 21:11:55 +0100171Functionality flag: I2C_FUNC_SMBUS_PROC_CALL
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100174SMBus Block Read
175================
176
177Implemented by i2c_smbus_read_block_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300179This command reads a block of up to 32 bytes from a device, from a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180designated register that is specified through the Comm byte. The amount
181of data is specified by the device in the Count byte.
182
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300183::
184
185 S Addr Wr [A] Comm [A]
Miquel Raynalbed68f42021-11-15 12:08:18 +0100186 Sr Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Jean Delvarea1681782012-12-16 21:11:55 +0100188Functionality flag: I2C_FUNC_SMBUS_READ_BLOCK_DATA
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100191SMBus Block Write
192=================
193
194Implemented by i2c_smbus_write_block_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300196The opposite of the Block Read command, this writes up to 32 bytes to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197a device, to a designated register that is specified through the
198Comm byte. The amount of data is specified in the Count byte.
199
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300200::
201
202 S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Jean Delvarea1681782012-12-16 21:11:55 +0100204Functionality flag: I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
David Brownell1a31a882008-05-11 20:37:05 +0200207SMBus Block Write - Block Read Process Call
208===========================================
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
David Brownell1a31a882008-05-11 20:37:05 +0200210SMBus Block Write - Block Read Process Call was introduced in
211Revision 2.0 of the specification.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213This command selects a device register (through the Comm byte), sends
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -03002141 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300216 S Addr Wr [A] Comm [A] Count [A] Data [A] ...
Miquel Raynalbed68f42021-11-15 12:08:18 +0100217 Sr Addr Rd [A] [Count] A [Data] ... A P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Jean Delvarea1681782012-12-16 21:11:55 +0100219Functionality flag: I2C_FUNC_SMBUS_BLOCK_PROC_CALL
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222SMBus Host Notify
223=================
224
225This command is sent from a SMBus device acting as a master to the
226SMBus host acting as a slave.
227It is the same form as Write Word, with the command code replaced by the
228alerting device's address.
229
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300230::
231
232 [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Benjamin Tissoirese456cd32016-06-09 16:53:48 +0200234This is implemented in the following way in the Linux kernel:
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300235
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +0200236* I2C bus drivers which support SMBus Host Notify should report
237 I2C_FUNC_SMBUS_HOST_NOTIFY.
238* I2C bus drivers trigger SMBus Host Notify by a call to
239 i2c_handle_smbus_host_notify().
240* I2C drivers for devices which can trigger SMBus Host Notify will have
241 client->irq assigned to a Host Notify IRQ if noone else specified an other.
242
243There is currently no way to retrieve the data parameter from the client.
Benjamin Tissoirese456cd32016-06-09 16:53:48 +0200244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246Packet Error Checking (PEC)
247===========================
David Brownell1a31a882008-05-11 20:37:05 +0200248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249Packet Error Checking was introduced in Revision 1.1 of the specification.
250
David Brownell1a31a882008-05-11 20:37:05 +0200251PEC adds a CRC-8 error-checking byte to transfers using it, immediately
252before the terminating STOP.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254
255Address Resolution Protocol (ARP)
256=================================
David Brownell1a31a882008-05-11 20:37:05 +0200257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258The Address Resolution Protocol was introduced in Revision 2.0 of
259the specification. It is a higher-layer protocol which uses the
260messages above.
261
262ARP adds device enumeration and dynamic address assignment to
263the protocol. All ARP communications use slave address 0x61 and
264require PEC checksums.
265
266
Jean Delvareb5527a72010-03-02 12:23:42 +0100267SMBus Alert
268===========
269
270SMBus Alert was introduced in Revision 1.0 of the specification.
271
272The SMBus alert protocol allows several SMBus slave devices to share a
273single interrupt pin on the SMBus master, while still allowing the master
274to know which slave triggered the interrupt.
275
276This is implemented the following way in the Linux kernel:
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300277
Jean Delvareb5527a72010-03-02 12:23:42 +0100278* I2C bus drivers which support SMBus alert should call
Wolfram Sanged680522020-02-28 18:12:20 +0100279 i2c_new_smbus_alert_device() to install SMBus alert support.
Jean Delvareb5527a72010-03-02 12:23:42 +0100280* I2C drivers for devices which can trigger SMBus alerts should implement
281 the optional alert() callback.
282
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284I2C Block Transactions
285======================
David Brownell1a31a882008-05-11 20:37:05 +0200286
Luca Ceresoli95b83772020-01-29 16:19:44 +0100287The following I2C block transactions are similar to the SMBus Block Read
288and Write operations, except these do not have a Count byte. They are
289supported by the SMBus layer and are described here for completeness, but
290they are *NOT* defined by the SMBus specification.
David Brownell1a31a882008-05-11 20:37:05 +0200291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292I2C block transactions do not limit the number of bytes transferred
293but the SMBus layer places a limit of 32 bytes.
294
295
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100296I2C Block Read
297==============
298
299Implemented by i2c_smbus_read_i2c_block_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300301This command reads a block of bytes from a device, from a
302designated register that is specified through the Comm byte::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300304 S Addr Wr [A] Comm [A]
Miquel Raynalbed68f42021-11-15 12:08:18 +0100305 Sr Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Jean Delvarea1681782012-12-16 21:11:55 +0100307Functionality flag: I2C_FUNC_SMBUS_READ_I2C_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309
Luca Ceresoli3c13f1f2020-01-29 16:19:40 +0100310I2C Block Write
311===============
312
313Implemented by i2c_smbus_write_i2c_block_data()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300315The opposite of the Block Read command, this writes bytes to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316a device, to a designated register that is specified through the
317Comm byte. Note that command lengths of 0, 2, or more bytes are
318supported as they are indistinguishable from data.
319
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -0300320::
321
322 S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
Jean Delvarea1681782012-12-16 21:11:55 +0100323
324Functionality flag: I2C_FUNC_SMBUS_WRITE_I2C_BLOCK