protocol.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ============
  3. I3C protocol
  4. ============
  5. Disclaimer
  6. ==========
  7. This chapter will focus on aspects that matter to software developers. For
  8. everything hardware related (like how things are transmitted on the bus, how
  9. collisions are prevented, ...) please have a look at the I3C specification.
  10. This document is just a brief introduction to the I3C protocol and the concepts
  11. it brings to the table. If you need more information, please refer to the MIPI
  12. I3C specification (can be downloaded here
  13. https://resources.mipi.org/mipi-i3c-v1-download).
  14. Introduction
  15. ============
  16. The I3C (pronounced 'eye-three-see') is a MIPI standardized protocol designed
  17. to overcome I2C limitations (limited speed, external signals needed for
  18. interrupts, no automatic detection of the devices connected to the bus, ...)
  19. while remaining power-efficient.
  20. I3C Bus
  21. =======
  22. An I3C bus is made of several I3C devices and possibly some I2C devices as
  23. well, but let's focus on I3C devices for now.
  24. An I3C device on the I3C bus can have one of the following roles:
  25. * Master: the device is driving the bus. It's the one in charge of initiating
  26. transactions or deciding who is allowed to talk on the bus (slave generated
  27. events are possible in I3C, see below).
  28. * Slave: the device acts as a slave, and is not able to send frames to another
  29. slave on the bus. The device can still send events to the master on
  30. its own initiative if the master allowed it.
  31. I3C is a multi-master protocol, so there might be several masters on a bus,
  32. though only one device can act as a master at a given time. In order to gain
  33. bus ownership, a master has to follow a specific procedure.
  34. Each device on the I3C bus has to be assigned a dynamic address to be able to
  35. communicate. Until this is done, the device should only respond to a limited
  36. set of commands. If it has a static address (also called legacy I2C address),
  37. the device can reply to I2C transfers.
  38. In addition to these per-device addresses, the protocol defines a broadcast
  39. address in order to address all devices on the bus.
  40. Once a dynamic address has been assigned to a device, this address will be used
  41. for any direct communication with the device. Note that even after being
  42. assigned a dynamic address, the device should still process broadcast messages.
  43. I3C Device discovery
  44. ====================
  45. The I3C protocol defines a mechanism to automatically discover devices present
  46. on the bus, their capabilities and the functionalities they provide. In this
  47. regard I3C is closer to a discoverable bus like USB than it is to I2C or SPI.
  48. The discovery mechanism is called DAA (Dynamic Address Assignment), because it
  49. not only discovers devices but also assigns them a dynamic address.
  50. During DAA, each I3C device reports 3 important things:
  51. * BCR: Bus Characteristic Register. This 8-bit register describes the device bus
  52. related capabilities
  53. * DCR: Device Characteristic Register. This 8-bit register describes the
  54. functionalities provided by the device
  55. * Provisional ID: A 48-bit unique identifier. On a given bus there should be no
  56. Provisional ID collision, otherwise the discovery mechanism may fail.
  57. I3C slave events
  58. ================
  59. The I3C protocol allows slaves to generate events on their own, and thus allows
  60. them to take temporary control of the bus.
  61. This mechanism is called IBI for In Band Interrupts, and as stated in the name,
  62. it allows devices to generate interrupts without requiring an external signal.
  63. During DAA, each device on the bus has been assigned an address, and this
  64. address will serve as a priority identifier to determine who wins if 2 different
  65. devices are generating an interrupt at the same moment on the bus (the lower the
  66. dynamic address the higher the priority).
  67. Masters are allowed to inhibit interrupts if they want to. This inhibition
  68. request can be broadcast (applies to all devices) or sent to a specific
  69. device.
  70. I3C Hot-Join
  71. ============
  72. The Hot-Join mechanism is similar to USB hotplug. This mechanism allows
  73. slaves to join the bus after it has been initialized by the master.
  74. This covers the following use cases:
  75. * the device is not powered when the bus is probed
  76. * the device is hotplugged on the bus through an extension board
  77. This mechanism is relying on slave events to inform the master that a new
  78. device joined the bus and is waiting for a dynamic address.
  79. The master is then free to address the request as it wishes: ignore it or
  80. assign a dynamic address to the slave.
  81. I3C transfer types
  82. ==================
  83. If you omit SMBus (which is just a standardization on how to access registers
  84. exposed by I2C devices), I2C has only one transfer type.
  85. I3C defines 3 different classes of transfer in addition to I2C transfers which
  86. are here for backward compatibility with I2C devices.
  87. I3C CCC commands
  88. ----------------
  89. CCC (Common Command Code) commands are meant to be used for anything that is
  90. related to bus management and all features that are common to a set of devices.
  91. CCC commands contain an 8-bit CCC ID describing the command that is executed.
  92. The MSB of this ID specifies whether this is a broadcast command (bit7 = 0) or a
  93. unicast one (bit7 = 1).
  94. The command ID can be followed by a payload. Depending on the command, this
  95. payload is either sent by the master sending the command (write CCC command),
  96. or sent by the slave receiving the command (read CCC command). Of course, read
  97. accesses only apply to unicast commands.
  98. Note that, when sending a CCC command to a specific device, the device address
  99. is passed in the first byte of the payload.
  100. The payload length is not explicitly passed on the bus, and should be extracted
  101. from the CCC ID.
  102. Note that vendors can use a dedicated range of CCC IDs for their own commands
  103. (0x61-0x7f and 0xe0-0xef).
  104. I3C Private SDR transfers
  105. -------------------------
  106. Private SDR (Single Data Rate) transfers should be used for anything that is
  107. device specific and does not require high transfer speed.
  108. It is the equivalent of I2C transfers but in the I3C world. Each transfer is
  109. passed the device address (dynamic address assigned during DAA), a payload
  110. and a direction.
  111. The only difference with I2C is that the transfer is much faster (typical clock
  112. frequency is 12.5MHz).
  113. I3C HDR commands
  114. ----------------
  115. HDR commands should be used for anything that is device specific and requires
  116. high transfer speed.
  117. The first thing attached to an HDR command is the HDR mode. There are currently
  118. 3 different modes defined by the I3C specification (refer to the specification
  119. for more details):
  120. * HDR-DDR: Double Data Rate mode
  121. * HDR-TSP: Ternary Symbol Pure. Only usable on busses with no I2C devices
  122. * HDR-TSL: Ternary Symbol Legacy. Usable on busses with I2C devices
  123. When sending an HDR command, the whole bus has to enter HDR mode, which is done
  124. using a broadcast CCC command.
  125. Once the bus has entered a specific HDR mode, the master sends the HDR command.
  126. An HDR command is made of:
  127. * one 16-bits command word in big endian
  128. * N 16-bits data words in big endian
  129. Those words may be wrapped with specific preambles/post-ambles which depend on
  130. the chosen HDR mode and are detailed here (see the specification for more
  131. details).
  132. The 16-bits command word is made of:
  133. * bit[15]: direction bit, read is 1, write is 0
  134. * bit[14:8]: command code. Identifies the command being executed, the amount of
  135. data words and their meaning
  136. * bit[7:1]: I3C address of the device this command is addressed to
  137. * bit[0]: reserved/parity-bit
  138. Backward compatibility with I2C devices
  139. =======================================
  140. The I3C protocol has been designed to be backward compatible with I2C devices.
  141. This backward compatibility allows one to connect a mix of I2C and I3C devices
  142. on the same bus, though, in order to be really efficient, I2C devices should
  143. be equipped with 50 ns spike filters.
  144. I2C devices can't be discovered like I3C ones and have to be statically
  145. declared. In order to let the master know what these devices are capable of
  146. (both in terms of bus related limitations and functionalities), the software
  147. has to provide some information, which is done through the LVR (Legacy I2C
  148. Virtual Register).