18c2ecf20Sopenharmony_ci==================
28c2ecf20Sopenharmony_ciThe SMBus Protocol
38c2ecf20Sopenharmony_ci==================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThe following is a summary of the SMBus protocol. It applies to
68c2ecf20Sopenharmony_ciall revisions of the protocol (1.0, 1.1, and 2.0).
78c2ecf20Sopenharmony_ciCertain protocol features which are not supported by
88c2ecf20Sopenharmony_cithis package are briefly described at the end of this document.
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciSome adapters understand only the SMBus (System Management Bus) protocol,
118c2ecf20Sopenharmony_ciwhich is a subset from the I2C protocol. Fortunately, many devices use
128c2ecf20Sopenharmony_cionly the same subset, which makes it possible to put them on an SMBus.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciIf you write a driver for some I2C device, please try to use the SMBus
158c2ecf20Sopenharmony_cicommands if at all possible (if the device uses only that subset of the
168c2ecf20Sopenharmony_ciI2C protocol). This makes it possible to use the device driver on both
178c2ecf20Sopenharmony_ciSMBus adapters and I2C adapters (the SMBus command set is automatically
188c2ecf20Sopenharmony_citranslated to I2C on I2C adapters, but plain I2C commands can not be
198c2ecf20Sopenharmony_cihandled at all on most pure SMBus adapters).
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciBelow is a list of SMBus protocol operations, and the functions executing
228c2ecf20Sopenharmony_cithem.  Note that the names used in the SMBus protocol specifications usually
238c2ecf20Sopenharmony_cidon't match these function names.  For some of the operations which pass a
248c2ecf20Sopenharmony_cisingle data byte, the functions using SMBus protocol operation names execute
258c2ecf20Sopenharmony_cia different protocol operation entirely.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciEach transaction type corresponds to a functionality flag. Before calling a
288c2ecf20Sopenharmony_citransaction function, a device driver should always check (just once) for
298c2ecf20Sopenharmony_cithe corresponding functionality flag to ensure that the underlying I2C
308c2ecf20Sopenharmony_ciadapter supports the transaction in question. See :doc:`functionality` for
318c2ecf20Sopenharmony_cithe details.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciKey to symbols
358c2ecf20Sopenharmony_ci==============
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci=============== =============================================================
388c2ecf20Sopenharmony_ciS               Start condition
398c2ecf20Sopenharmony_ciP               Stop condition
408c2ecf20Sopenharmony_ciRd/Wr (1 bit)   Read/Write bit. Rd equals 1, Wr equals 0.
418c2ecf20Sopenharmony_ciA, NA (1 bit)   Acknowledge (ACK) and Not Acknowledge (NACK) bit
428c2ecf20Sopenharmony_ciAddr  (7 bits)  I2C 7 bit address. Note that this can be expanded as usual to
438c2ecf20Sopenharmony_ci                get a 10 bit I2C address.
448c2ecf20Sopenharmony_ciComm  (8 bits)  Command byte, a data byte which often selects a register on
458c2ecf20Sopenharmony_ci                the device.
468c2ecf20Sopenharmony_ciData  (8 bits)  A plain data byte. Sometimes, I write DataLow, DataHigh
478c2ecf20Sopenharmony_ci                for 16 bit data.
488c2ecf20Sopenharmony_ciCount (8 bits)  A data byte containing the length of a block operation.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci[..]            Data sent by I2C device, as opposed to data sent by the host
518c2ecf20Sopenharmony_ci                adapter.
528c2ecf20Sopenharmony_ci=============== =============================================================
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciSMBus Quick Command
568c2ecf20Sopenharmony_ci===================
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciThis sends a single bit to the device, at the place of the Rd/Wr bit::
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci  S Addr Rd/Wr [A] P
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_QUICK
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciSMBus Receive Byte
668c2ecf20Sopenharmony_ci==================
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciImplemented by i2c_smbus_read_byte()
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciThis reads a single byte from a device, without specifying a device
718c2ecf20Sopenharmony_ciregister. Some devices are so simple that this interface is enough; for
728c2ecf20Sopenharmony_ciothers, it is a shorthand if you want to read the same register as in
738c2ecf20Sopenharmony_cithe previous SMBus command::
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci  S Addr Rd [A] [Data] NA P
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_READ_BYTE
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciSMBus Send Byte
818c2ecf20Sopenharmony_ci===============
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciImplemented by i2c_smbus_write_byte()
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciThis operation is the reverse of Receive Byte: it sends a single byte
868c2ecf20Sopenharmony_cito a device.  See Receive Byte for more information.
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci::
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci  S Addr Wr [A] Data [A] P
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_WRITE_BYTE
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciSMBus Read Byte
968c2ecf20Sopenharmony_ci===============
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ciImplemented by i2c_smbus_read_byte_data()
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ciThis reads a single byte from a device, from a designated register.
1018c2ecf20Sopenharmony_ciThe register is specified through the Comm byte::
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_READ_BYTE_DATA
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciSMBus Read Word
1098c2ecf20Sopenharmony_ci===============
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ciImplemented by i2c_smbus_read_word_data()
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciThis operation is very like Read Byte; again, data is read from a
1148c2ecf20Sopenharmony_cidevice, from a designated register that is specified through the Comm
1158c2ecf20Sopenharmony_cibyte. But this time, the data is a complete word (16 bits)::
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_READ_WORD_DATA
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ciNote the convenience function i2c_smbus_read_word_swapped() is
1228c2ecf20Sopenharmony_ciavailable for reads where the two data bytes are the other way
1238c2ecf20Sopenharmony_ciaround (not SMBus compliant, but very popular.)
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciSMBus Write Byte
1278c2ecf20Sopenharmony_ci================
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciImplemented by i2c_smbus_write_byte_data()
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ciThis writes a single byte to a device, to a designated register. The
1328c2ecf20Sopenharmony_ciregister is specified through the Comm byte. This is the opposite of
1338c2ecf20Sopenharmony_cithe Read Byte operation.
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci::
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] Data [A] P
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_WRITE_BYTE_DATA
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciSMBus Write Word
1438c2ecf20Sopenharmony_ci================
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ciImplemented by i2c_smbus_write_word_data()
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciThis is the opposite of the Read Word operation. 16 bits
1488c2ecf20Sopenharmony_ciof data are written to a device, to the designated register that is
1498c2ecf20Sopenharmony_cispecified through the Comm byte::
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_WRITE_WORD_DATA
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciNote the convenience function i2c_smbus_write_word_swapped() is
1568c2ecf20Sopenharmony_ciavailable for writes where the two data bytes are the other way
1578c2ecf20Sopenharmony_ciaround (not SMBus compliant, but very popular.)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ciSMBus Process Call
1618c2ecf20Sopenharmony_ci==================
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciThis command selects a device register (through the Comm byte), sends
1648c2ecf20Sopenharmony_ci16 bits of data to it, and reads 16 bits of data in return::
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
1678c2ecf20Sopenharmony_ci                               S Addr Rd [A] [DataLow] A [DataHigh] NA P
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_PROC_CALL
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ciSMBus Block Read
1738c2ecf20Sopenharmony_ci================
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ciImplemented by i2c_smbus_read_block_data()
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ciThis command reads a block of up to 32 bytes from a device, from a
1788c2ecf20Sopenharmony_cidesignated register that is specified through the Comm byte. The amount
1798c2ecf20Sopenharmony_ciof data is specified by the device in the Count byte.
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci::
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A]
1848c2ecf20Sopenharmony_ci             S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_READ_BLOCK_DATA
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ciSMBus Block Write
1908c2ecf20Sopenharmony_ci=================
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ciImplemented by i2c_smbus_write_block_data()
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciThe opposite of the Block Read command, this writes up to 32 bytes to
1958c2ecf20Sopenharmony_cia device, to a designated register that is specified through the
1968c2ecf20Sopenharmony_ciComm byte. The amount of data is specified in the Count byte.
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci::
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ciSMBus Block Write - Block Read Process Call
2068c2ecf20Sopenharmony_ci===========================================
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciSMBus Block Write - Block Read Process Call was introduced in
2098c2ecf20Sopenharmony_ciRevision 2.0 of the specification.
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ciThis command selects a device register (through the Comm byte), sends
2128c2ecf20Sopenharmony_ci1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return::
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] Count [A] Data [A] ...
2158c2ecf20Sopenharmony_ci                               S Addr Rd [A] [Count] A [Data] ... A P
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_BLOCK_PROC_CALL
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ciSMBus Host Notify
2218c2ecf20Sopenharmony_ci=================
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciThis command is sent from a SMBus device acting as a master to the
2248c2ecf20Sopenharmony_ciSMBus host acting as a slave.
2258c2ecf20Sopenharmony_ciIt is the same form as Write Word, with the command code replaced by the
2268c2ecf20Sopenharmony_cialerting device's address.
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci::
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci  [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ciThis is implemented in the following way in the Linux kernel:
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci* I2C bus drivers which support SMBus Host Notify should report
2358c2ecf20Sopenharmony_ci  I2C_FUNC_SMBUS_HOST_NOTIFY.
2368c2ecf20Sopenharmony_ci* I2C bus drivers trigger SMBus Host Notify by a call to
2378c2ecf20Sopenharmony_ci  i2c_handle_smbus_host_notify().
2388c2ecf20Sopenharmony_ci* I2C drivers for devices which can trigger SMBus Host Notify will have
2398c2ecf20Sopenharmony_ci  client->irq assigned to a Host Notify IRQ if noone else specified an other.
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ciThere is currently no way to retrieve the data parameter from the client.
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciPacket Error Checking (PEC)
2458c2ecf20Sopenharmony_ci===========================
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ciPacket Error Checking was introduced in Revision 1.1 of the specification.
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ciPEC adds a CRC-8 error-checking byte to transfers using it, immediately
2508c2ecf20Sopenharmony_cibefore the terminating STOP.
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ciAddress Resolution Protocol (ARP)
2548c2ecf20Sopenharmony_ci=================================
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ciThe Address Resolution Protocol was introduced in Revision 2.0 of
2578c2ecf20Sopenharmony_cithe specification. It is a higher-layer protocol which uses the
2588c2ecf20Sopenharmony_cimessages above.
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ciARP adds device enumeration and dynamic address assignment to
2618c2ecf20Sopenharmony_cithe protocol. All ARP communications use slave address 0x61 and
2628c2ecf20Sopenharmony_cirequire PEC checksums.
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ciSMBus Alert
2668c2ecf20Sopenharmony_ci===========
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ciSMBus Alert was introduced in Revision 1.0 of the specification.
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ciThe SMBus alert protocol allows several SMBus slave devices to share a
2718c2ecf20Sopenharmony_cisingle interrupt pin on the SMBus master, while still allowing the master
2728c2ecf20Sopenharmony_cito know which slave triggered the interrupt.
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ciThis is implemented the following way in the Linux kernel:
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci* I2C bus drivers which support SMBus alert should call
2778c2ecf20Sopenharmony_ci  i2c_new_smbus_alert_device() to install SMBus alert support.
2788c2ecf20Sopenharmony_ci* I2C drivers for devices which can trigger SMBus alerts should implement
2798c2ecf20Sopenharmony_ci  the optional alert() callback.
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ciI2C Block Transactions
2838c2ecf20Sopenharmony_ci======================
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ciThe following I2C block transactions are similar to the SMBus Block Read
2868c2ecf20Sopenharmony_ciand Write operations, except these do not have a Count byte. They are
2878c2ecf20Sopenharmony_cisupported by the SMBus layer and are described here for completeness, but
2888c2ecf20Sopenharmony_cithey are *NOT* defined by the SMBus specification.
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ciI2C block transactions do not limit the number of bytes transferred
2918c2ecf20Sopenharmony_cibut the SMBus layer places a limit of 32 bytes.
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ciI2C Block Read
2958c2ecf20Sopenharmony_ci==============
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ciImplemented by i2c_smbus_read_i2c_block_data()
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ciThis command reads a block of bytes from a device, from a
3008c2ecf20Sopenharmony_cidesignated register that is specified through the Comm byte::
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A]
3038c2ecf20Sopenharmony_ci             S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_READ_I2C_BLOCK
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ciI2C Block Write
3098c2ecf20Sopenharmony_ci===============
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ciImplemented by i2c_smbus_write_i2c_block_data()
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ciThe opposite of the Block Read command, this writes bytes to
3148c2ecf20Sopenharmony_cia device, to a designated register that is specified through the
3158c2ecf20Sopenharmony_ciComm byte. Note that command lengths of 0, 2, or more bytes are
3168c2ecf20Sopenharmony_cisupported as they are indistinguishable from data.
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci::
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci  S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ciFunctionality flag: I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
323