multiple-data-lanes.rst 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. ====================================
  2. SPI devices with multiple data lanes
  3. ====================================
  4. Some specialized SPI controllers and peripherals support multiple data lanes
  5. that allow reading more than one word at a time in parallel. This is different
  6. from dual/quad/octal SPI where multiple bits of a single word are transferred
  7. simultaneously.
  8. For example, controllers that support parallel flash memories have this feature
  9. as do some simultaneous-sampling ADCs where each channel has its own data lane.
  10. ---------------------
  11. Describing the wiring
  12. ---------------------
  13. The ``spi-tx-bus-width`` and ``spi-rx-bus-width`` properties in the devicetree
  14. are used to describe how many data lanes are connected between the controller
  15. and how wide each lane is. The number of items in the array indicates how many
  16. lanes there are, and the value of each item indicates how many bits wide that
  17. lane is.
  18. For example, a dual-simultaneous-sampling ADC with two 4-bit lanes might be
  19. wired up like this::
  20. +--------------+ +----------+
  21. | SPI | | AD4630 |
  22. | Controller | | ADC |
  23. | | | |
  24. | CS0 |--->| CS |
  25. | SCK |--->| SCK |
  26. | SDO |--->| SDI |
  27. | | | |
  28. | SDIA0 |<---| SDOA0 |
  29. | SDIA1 |<---| SDOA1 |
  30. | SDIA2 |<---| SDOA2 |
  31. | SDIA3 |<---| SDOA3 |
  32. | | | |
  33. | SDIB0 |<---| SDOB0 |
  34. | SDIB1 |<---| SDOB1 |
  35. | SDIB2 |<---| SDOB2 |
  36. | SDIB3 |<---| SDOB3 |
  37. | | | |
  38. +--------------+ +----------+
  39. It is described in a devicetree like this::
  40. spi {
  41. compatible = "my,spi-controller";
  42. ...
  43. adc@0 {
  44. compatible = "adi,ad4630";
  45. reg = <0>;
  46. ...
  47. spi-rx-bus-width = <4>, <4>; /* 2 lanes of 4 bits each */
  48. ...
  49. };
  50. };
  51. In most cases, lanes will be wired up symmetrically (A to A, B to B, etc). If
  52. this isn't the case, extra ``spi-rx-lane-map`` and ``spi-tx-lane-map``
  53. properties are needed to provide a mapping between controller lanes and the
  54. physical lane wires.
  55. Here is an example where a multi-lane SPI controller has each lane wired to
  56. separate single-lane peripherals::
  57. +--------------+ +----------+
  58. | SPI | | Thing 1 |
  59. | Controller | | |
  60. | | | |
  61. | CS0 |--->| CS |
  62. | SDO0 |--->| SDI |
  63. | SDI0 |<---| SDO |
  64. | SCLK0 |--->| SCLK |
  65. | | | |
  66. | | +----------+
  67. | |
  68. | | +----------+
  69. | | | Thing 2 |
  70. | | | |
  71. | CS1 |--->| CS |
  72. | SDO1 |--->| SDI |
  73. | SDI1 |<---| SDO |
  74. | SCLK1 |--->| SCLK |
  75. | | | |
  76. +--------------+ +----------+
  77. This is described in a devicetree like this::
  78. spi {
  79. compatible = "my,spi-controller";
  80. ...
  81. thing1@0 {
  82. compatible = "my,thing1";
  83. reg = <0>;
  84. ...
  85. };
  86. thing2@1 {
  87. compatible = "my,thing2";
  88. reg = <1>;
  89. ...
  90. spi-tx-lane-map = <1>; /* lane 0 is not used, lane 1 is used for tx wire */
  91. spi-rx-lane-map = <1>; /* lane 0 is not used, lane 1 is used for rx wire */
  92. ...
  93. };
  94. };
  95. The default values of ``spi-rx-bus-width`` and ``spi-tx-bus-width`` are ``<1>``,
  96. so these properties can still be omitted even when ``spi-rx-lane-map`` and
  97. ``spi-tx-lane-map`` are used.
  98. ----------------------------
  99. Usage in a peripheral driver
  100. ----------------------------
  101. These types of SPI controllers generally do not support arbitrary use of the
  102. multiple lanes. Instead, they operate in one of a few defined modes. Peripheral
  103. drivers should set the :c:type:`struct spi_transfer.multi_lane_mode <spi_transfer>`
  104. field to indicate which mode they want to use for a given transfer.
  105. The possible values for this field have the following semantics:
  106. - :c:macro:`SPI_MULTI_BUS_MODE_SINGLE`: Only use the first lane. Other lanes are
  107. ignored. This means that it is operating just like a conventional SPI
  108. peripheral. This is the default, so it does not need to be explicitly set.
  109. Example::
  110. tx_buf[0] = 0x88;
  111. struct spi_transfer xfer = {
  112. .tx_buf = tx_buf,
  113. .len = 1,
  114. };
  115. spi_sync_transfer(spi, &xfer, 1);
  116. Assuming the controller is sending the MSB first, the sequence of bits
  117. sent over the tx wire would be (right-most bit is sent first)::
  118. controller > data bits > peripheral
  119. ---------- ---------------- ----------
  120. SDO 0 0-0-0-1-0-0-0-1 SDI 0
  121. - :c:macro:`SPI_MULTI_BUS_MODE_MIRROR`: Send a single data word over all of the
  122. lanes at the same time. This only makes sense for writes and not
  123. for reads.
  124. Example::
  125. tx_buf[0] = 0x88;
  126. struct spi_transfer xfer = {
  127. .tx_buf = tx_buf,
  128. .len = 1,
  129. .multi_lane_mode = SPI_MULTI_BUS_MODE_MIRROR,
  130. };
  131. spi_sync_transfer(spi, &xfer, 1);
  132. The data is mirrored on each tx wire::
  133. controller > data bits > peripheral
  134. ---------- ---------------- ----------
  135. SDO 0 0-0-0-1-0-0-0-1 SDI 0
  136. SDO 1 0-0-0-1-0-0-0-1 SDI 1
  137. - :c:macro:`SPI_MULTI_BUS_MODE_STRIPE`: Send or receive two different data words
  138. at the same time, one on each lane. This means that the buffer needs to be
  139. sized to hold data for all lanes. Data is interleaved in the buffer, with
  140. the first word corresponding to lane 0, the second to lane 1, and so on.
  141. Once the last lane is used, the next word in the buffer corresponds to lane
  142. 0 again. Accordingly, the buffer size must be a multiple of the number of
  143. lanes. This mode works for both reads and writes.
  144. Example::
  145. struct spi_transfer xfer = {
  146. .rx_buf = rx_buf,
  147. .len = 2,
  148. .multi_lane_mode = SPI_MULTI_BUS_MODE_STRIPE,
  149. };
  150. spi_sync_transfer(spi, &xfer, 1);
  151. Each rx wire has a different data word sent simultaneously::
  152. controller < data bits < peripheral
  153. ---------- ---------------- ----------
  154. SDI 0 0-0-0-1-0-0-0-1 SDO 0
  155. SDI 1 1-0-0-0-1-0-0-0 SDO 1
  156. After the transfer, ``rx_buf[0] == 0x11`` (word from SDO 0) and
  157. ``rx_buf[1] == 0x88`` (word from SDO 1).
  158. -----------------------------
  159. SPI controller driver support
  160. -----------------------------
  161. To support multiple data lanes, SPI controller drivers need to set
  162. :c:type:`struct spi_controller.num_data_lanes <spi_controller>` to a value
  163. greater than 1.
  164. Then the part of the driver that handles SPI transfers needs to check the
  165. :c:type:`struct spi_transfer.multi_lane_mode <spi_transfer>` field and implement
  166. the appropriate behavior for each supported mode and return an error for
  167. unsupported modes.
  168. The core SPI code should handle the rest.