smbus-protocol.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. ==================
  2. The SMBus Protocol
  3. ==================
  4. The following is a summary of the SMBus protocol. It applies to
  5. all revisions of the protocol (1.0, 1.1, and 2.0).
  6. Certain protocol features which are not supported by
  7. this package are briefly described at the end of this document.
  8. Some adapters understand only the SMBus (System Management Bus) protocol,
  9. 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. 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
  13. I2C protocol). This makes it possible to use the device driver on both
  14. 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
  16. handled at all on most pure SMBus adapters).
  17. Below is a list of SMBus protocol operations, and the functions executing
  18. them. Note that the names used in the SMBus protocol specifications usually
  19. don't match these function names. For some of the operations which pass a
  20. single data byte, the functions using SMBus protocol operation names execute
  21. a different protocol operation entirely.
  22. Each transaction type corresponds to a functionality flag. Before calling a
  23. transaction function, a device driver should always check (just once) for
  24. the corresponding functionality flag to ensure that the underlying I2C
  25. adapter supports the transaction in question. See
  26. Documentation/i2c/functionality.rst for the details.
  27. Key to symbols
  28. ==============
  29. =============== =============================================================
  30. S Start condition
  31. Sr Repeated start condition, used to switch from write to
  32. read mode.
  33. P Stop condition
  34. Rd/Wr (1 bit) Read/Write bit. Rd equals 1, Wr equals 0.
  35. A, NA (1 bit) Acknowledge (ACK) and Not Acknowledge (NACK) bit
  36. Addr (7 bits) I2C 7 bit address. Note that this can be expanded to
  37. get a 10 bit I2C address.
  38. Comm (8 bits) Command byte, a data byte which often selects a register on
  39. the device.
  40. Data (8 bits) A plain data byte. DataLow and DataHigh represent the low and
  41. high byte of a 16 bit word.
  42. Count (8 bits) A data byte containing the length of a block operation.
  43. [..] Data sent by I2C device, as opposed to data sent by the host
  44. adapter.
  45. =============== =============================================================
  46. SMBus Quick Command
  47. ===================
  48. This sends a single bit to the device, at the place of the Rd/Wr bit::
  49. S Addr Rd/Wr [A] P
  50. Functionality flag: I2C_FUNC_SMBUS_QUICK
  51. SMBus Receive Byte
  52. ==================
  53. Implemented by i2c_smbus_read_byte()
  54. This reads a single byte from a device, without specifying a device
  55. register. Some devices are so simple that this interface is enough; for
  56. others, it is a shorthand if you want to read the same register as in
  57. the previous SMBus command::
  58. S Addr Rd [A] [Data] NA P
  59. Functionality flag: I2C_FUNC_SMBUS_READ_BYTE
  60. SMBus Send Byte
  61. ===============
  62. Implemented by i2c_smbus_write_byte()
  63. This operation is the reverse of Receive Byte: it sends a single byte
  64. to a device. See Receive Byte for more information.
  65. ::
  66. S Addr Wr [A] Data [A] P
  67. Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE
  68. SMBus Read Byte
  69. ===============
  70. Implemented by i2c_smbus_read_byte_data()
  71. This reads a single byte from a device, from a designated register.
  72. The register is specified through the Comm byte::
  73. S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] NA P
  74. Functionality flag: I2C_FUNC_SMBUS_READ_BYTE_DATA
  75. SMBus Read Word
  76. ===============
  77. Implemented by i2c_smbus_read_word_data()
  78. This operation is very like Read Byte; again, data is read from a
  79. device, from a designated register that is specified through the Comm
  80. byte. But this time, the data is a complete word (16 bits)::
  81. S Addr Wr [A] Comm [A] Sr Addr Rd [A] [DataLow] A [DataHigh] NA P
  82. Functionality flag: I2C_FUNC_SMBUS_READ_WORD_DATA
  83. Note the convenience function i2c_smbus_read_word_swapped() is
  84. available for reads where the two data bytes are the other way
  85. around (not SMBus compliant, but very popular.)
  86. SMBus Write Byte
  87. ================
  88. Implemented by i2c_smbus_write_byte_data()
  89. 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
  91. the Read Byte operation.
  92. ::
  93. S Addr Wr [A] Comm [A] Data [A] P
  94. Functionality flag: I2C_FUNC_SMBUS_WRITE_BYTE_DATA
  95. SMBus Write Word
  96. ================
  97. Implemented by i2c_smbus_write_word_data()
  98. This is the opposite of the Read Word operation. 16 bits
  99. of data are written to a device, to the designated register that is
  100. specified through the Comm byte::
  101. S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
  102. Functionality flag: I2C_FUNC_SMBUS_WRITE_WORD_DATA
  103. Note the convenience function i2c_smbus_write_word_swapped() is
  104. available for writes where the two data bytes are the other way
  105. around (not SMBus compliant, but very popular.)
  106. SMBus Process Call
  107. ==================
  108. This command selects a device register (through the Comm byte), sends
  109. 16 bits of data to it, and reads 16 bits of data in return::
  110. S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
  111. Sr Addr Rd [A] [DataLow] A [DataHigh] NA P
  112. Functionality flag: I2C_FUNC_SMBUS_PROC_CALL
  113. SMBus Block Read
  114. ================
  115. Implemented by i2c_smbus_read_block_data()
  116. This command reads a block of up to 32 bytes from a device, from a
  117. designated register that is specified through the Comm byte. The amount
  118. of data is specified by the device in the Count byte.
  119. ::
  120. S Addr Wr [A] Comm [A]
  121. Sr Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
  122. Functionality flag: I2C_FUNC_SMBUS_READ_BLOCK_DATA
  123. SMBus Block Write
  124. =================
  125. Implemented by i2c_smbus_write_block_data()
  126. The opposite of the Block Read command, this writes up to 32 bytes to
  127. a device, to a designated register that is specified through the
  128. Comm byte. The amount of data is specified in the Count byte.
  129. ::
  130. S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
  131. Functionality flag: I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
  132. SMBus Block Write - Block Read Process Call
  133. ===========================================
  134. SMBus Block Write - Block Read Process Call was introduced in
  135. Revision 2.0 of the specification.
  136. This command selects a device register (through the Comm byte), sends
  137. 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return::
  138. S Addr Wr [A] Comm [A] Count [A] Data [A] ...
  139. Sr Addr Rd [A] [Count] A [Data] ... A P
  140. Functionality flag: I2C_FUNC_SMBUS_BLOCK_PROC_CALL
  141. SMBus Host Notify
  142. =================
  143. This command is sent from a SMBus device acting as a master to the
  144. SMBus host acting as a slave.
  145. It is the same form as Write Word, with the command code replaced by the
  146. alerting device's address.
  147. ::
  148. [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
  149. This is implemented in the following way in the Linux kernel:
  150. * I2C bus drivers which support SMBus Host Notify should report
  151. I2C_FUNC_SMBUS_HOST_NOTIFY.
  152. * I2C bus drivers trigger SMBus Host Notify by a call to
  153. i2c_handle_smbus_host_notify().
  154. * I2C drivers for devices which can trigger SMBus Host Notify will have
  155. client->irq assigned to a Host Notify IRQ if no one else specified another.
  156. There is currently no way to retrieve the data parameter from the client.
  157. Packet Error Checking (PEC)
  158. ===========================
  159. Packet Error Checking was introduced in Revision 1.1 of the specification.
  160. PEC adds a CRC-8 error-checking byte to transfers using it, immediately
  161. before the terminating STOP.
  162. Address Resolution Protocol (ARP)
  163. =================================
  164. The Address Resolution Protocol was introduced in Revision 2.0 of
  165. the specification. It is a higher-layer protocol which uses the
  166. messages above.
  167. ARP adds device enumeration and dynamic address assignment to
  168. the protocol. All ARP communications use slave address 0x61 and
  169. require PEC checksums.
  170. SMBus Alert
  171. ===========
  172. SMBus Alert was introduced in Revision 1.0 of the specification.
  173. The SMBus alert protocol allows several SMBus slave devices to share a
  174. single interrupt pin on the SMBus master, while still allowing the master
  175. to know which slave triggered the interrupt.
  176. This is implemented the following way in the Linux kernel:
  177. * I2C bus drivers which support SMBus alert should call
  178. i2c_new_smbus_alert_device() to install SMBus alert support.
  179. * I2C drivers for devices which can trigger SMBus alerts should implement
  180. the optional alert() callback.
  181. I2C Block Transactions
  182. ======================
  183. The following I2C block transactions are similar to the SMBus Block Read
  184. and Write operations, except these do not have a Count byte. They are
  185. supported by the SMBus layer and are described here for completeness, but
  186. they are *NOT* defined by the SMBus specification.
  187. I2C block transactions do not limit the number of bytes transferred
  188. but the SMBus layer places a limit of 32 bytes.
  189. I2C Block Read
  190. ==============
  191. Implemented by i2c_smbus_read_i2c_block_data()
  192. This command reads a block of bytes from a device, from a
  193. designated register that is specified through the Comm byte::
  194. S Addr Wr [A] Comm [A]
  195. Sr Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
  196. Functionality flag: I2C_FUNC_SMBUS_READ_I2C_BLOCK
  197. I2C Block Write
  198. ===============
  199. Implemented by i2c_smbus_write_i2c_block_data()
  200. The opposite of the Block Read command, this writes bytes to
  201. a device, to a designated register that is specified through the
  202. Comm byte. Note that command lengths of 0, 2, or more bytes are
  203. supported as they are indistinguishable from data.
  204. ::
  205. S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
  206. Functionality flag: I2C_FUNC_SMBUS_WRITE_I2C_BLOCK