pxa2xx.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. ==============================
  2. PXA2xx SPI on SSP driver HOWTO
  3. ==============================
  4. This a mini HOWTO on the pxa2xx_spi driver. The driver turns a PXA2xx
  5. synchronous serial port into an SPI master controller
  6. (see Documentation/spi/spi-summary.rst). The driver has the following features
  7. - Support for any PXA2xx and compatible SSP.
  8. - SSP PIO and SSP DMA data transfers.
  9. - External and Internal (SSPFRM) chip selects.
  10. - Per slave device (chip) configuration.
  11. - Full suspend, freeze, resume support.
  12. The driver is built around a &struct spi_message FIFO serviced by kernel
  13. thread. The kernel thread, spi_pump_messages(), drives message FIFO and
  14. is responsible for queuing SPI transactions and setting up and launching
  15. the DMA or interrupt driven transfers.
  16. Declaring PXA2xx Master Controllers
  17. -----------------------------------
  18. Typically, for a legacy platform, an SPI master is defined in the
  19. arch/.../mach-*/board-*.c as a "platform device". The master configuration
  20. is passed to the driver via a table found in include/linux/spi/pxa2xx_spi.h::
  21. struct pxa2xx_spi_controller {
  22. u16 num_chipselect;
  23. u8 enable_dma;
  24. ...
  25. };
  26. The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of
  27. slave device (chips) attached to this SPI master.
  28. The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should
  29. be used. This caused the driver to acquire two DMA channels: Rx channel and
  30. Tx channel. The Rx channel has a higher DMA service priority than the Tx channel.
  31. See the "PXA2xx Developer Manual" section "DMA Controller".
  32. For the new platforms the description of the controller and peripheral devices
  33. comes from Device Tree or ACPI.
  34. NSSP MASTER SAMPLE
  35. ------------------
  36. Below is a sample configuration using the PXA255 NSSP for a legacy platform::
  37. static struct resource pxa_spi_nssp_resources[] = {
  38. [0] = {
  39. .start = __PREG(SSCR0_P(2)), /* Start address of NSSP */
  40. .end = __PREG(SSCR0_P(2)) + 0x2c, /* Range of registers */
  41. .flags = IORESOURCE_MEM,
  42. },
  43. [1] = {
  44. .start = IRQ_NSSP, /* NSSP IRQ */
  45. .end = IRQ_NSSP,
  46. .flags = IORESOURCE_IRQ,
  47. },
  48. };
  49. static struct pxa2xx_spi_controller pxa_nssp_master_info = {
  50. .num_chipselect = 1, /* Matches the number of chips attached to NSSP */
  51. .enable_dma = 1, /* Enables NSSP DMA */
  52. };
  53. static struct platform_device pxa_spi_nssp = {
  54. .name = "pxa2xx-spi", /* MUST BE THIS VALUE, so device match driver */
  55. .id = 2, /* Bus number, MUST MATCH SSP number 1..n */
  56. .resource = pxa_spi_nssp_resources,
  57. .num_resources = ARRAY_SIZE(pxa_spi_nssp_resources),
  58. .dev = {
  59. .platform_data = &pxa_nssp_master_info, /* Passed to driver */
  60. },
  61. };
  62. static struct platform_device *devices[] __initdata = {
  63. &pxa_spi_nssp,
  64. };
  65. static void __init board_init(void)
  66. {
  67. (void)platform_add_device(devices, ARRAY_SIZE(devices));
  68. }
  69. Declaring Slave Devices
  70. -----------------------
  71. Typically, for a legacy platform, each SPI slave (chip) is defined in the
  72. arch/.../mach-*/board-*.c using the "spi_board_info" structure found in
  73. "linux/spi/spi.h". See "Documentation/spi/spi-summary.rst" for additional
  74. information.
  75. Each slave device attached to the PXA must provide slave specific configuration
  76. information via the structure "pxa2xx_spi_chip" found in
  77. "include/linux/spi/pxa2xx_spi.h". The pxa2xx_spi master controller driver
  78. will uses the configuration whenever the driver communicates with the slave
  79. device. All fields are optional.
  80. ::
  81. struct pxa2xx_spi_chip {
  82. u8 tx_threshold;
  83. u8 rx_threshold;
  84. u8 dma_burst_size;
  85. u32 timeout;
  86. };
  87. The "pxa2xx_spi_chip.tx_threshold" and "pxa2xx_spi_chip.rx_threshold" fields are
  88. used to configure the SSP hardware FIFO. These fields are critical to the
  89. performance of pxa2xx_spi driver and misconfiguration will result in rx
  90. FIFO overruns (especially in PIO mode transfers). Good default values are::
  91. .tx_threshold = 8,
  92. .rx_threshold = 8,
  93. The range is 1 to 16 where zero indicates "use default".
  94. The "pxa2xx_spi_chip.dma_burst_size" field is used to configure PXA2xx DMA
  95. engine and is related the "spi_device.bits_per_word" field. Read and understand
  96. the PXA2xx "Developer Manual" sections on the DMA controller and SSP Controllers
  97. to determine the correct value. An SSP configured for byte-wide transfers would
  98. use a value of 8. The driver will determine a reasonable default if
  99. dma_burst_size == 0.
  100. The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle
  101. trailing bytes in the SSP receiver FIFO. The correct value for this field is
  102. dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific
  103. slave device. Please note that the PXA2xx SSP 1 does not support trailing byte
  104. timeouts and must busy-wait any trailing bytes.
  105. NOTE: the SPI driver cannot control the chip select if SSPFRM is used, so the
  106. chipselect is dropped after each spi_transfer. Most devices need chip select
  107. asserted around the complete message. Use SSPFRM as a GPIO (through a descriptor)
  108. to accommodate these chips.
  109. NSSP SLAVE SAMPLE
  110. -----------------
  111. For a legacy platform or in some other cases, the pxa2xx_spi_chip structure
  112. is passed to the pxa2xx_spi driver in the "spi_board_info.controller_data"
  113. field. Below is a sample configuration using the PXA255 NSSP.
  114. ::
  115. static struct pxa2xx_spi_chip cs8415a_chip_info = {
  116. .tx_threshold = 8, /* SSP hardward FIFO threshold */
  117. .rx_threshold = 8, /* SSP hardward FIFO threshold */
  118. .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */
  119. .timeout = 235, /* See Intel documentation */
  120. };
  121. static struct pxa2xx_spi_chip cs8405a_chip_info = {
  122. .tx_threshold = 8, /* SSP hardward FIFO threshold */
  123. .rx_threshold = 8, /* SSP hardward FIFO threshold */
  124. .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */
  125. .timeout = 235, /* See Intel documentation */
  126. };
  127. static struct spi_board_info streetracer_spi_board_info[] __initdata = {
  128. {
  129. .modalias = "cs8415a", /* Name of spi_driver for this device */
  130. .max_speed_hz = 3686400, /* Run SSP as fast a possbile */
  131. .bus_num = 2, /* Framework bus number */
  132. .chip_select = 0, /* Framework chip select */
  133. .platform_data = NULL; /* No spi_driver specific config */
  134. .controller_data = &cs8415a_chip_info, /* Master chip config */
  135. .irq = STREETRACER_APCI_IRQ, /* Slave device interrupt */
  136. },
  137. {
  138. .modalias = "cs8405a", /* Name of spi_driver for this device */
  139. .max_speed_hz = 3686400, /* Run SSP as fast a possbile */
  140. .bus_num = 2, /* Framework bus number */
  141. .chip_select = 1, /* Framework chip select */
  142. .controller_data = &cs8405a_chip_info, /* Master chip config */
  143. .irq = STREETRACER_APCI_IRQ, /* Slave device interrupt */
  144. },
  145. };
  146. static void __init streetracer_init(void)
  147. {
  148. spi_register_board_info(streetracer_spi_board_info,
  149. ARRAY_SIZE(streetracer_spi_board_info));
  150. }
  151. DMA and PIO I/O Support
  152. -----------------------
  153. The pxa2xx_spi driver supports both DMA and interrupt driven PIO message
  154. transfers. The driver defaults to PIO mode and DMA transfers must be enabled
  155. by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure.
  156. For the newer platforms, that are known to support DMA, the driver will enable
  157. it automatically and try it first with a possible fallback to PIO. The DMA
  158. mode supports both coherent and stream based DMA mappings.
  159. The following logic is used to determine the type of I/O to be used on
  160. a per "spi_transfer" basis::
  161. if !enable_dma then
  162. always use PIO transfers
  163. if spi_message.len > 8191 then
  164. print "rate limited" warning
  165. use PIO transfers
  166. if spi_message.is_dma_mapped and rx_dma_buf != 0 and tx_dma_buf != 0 then
  167. use coherent DMA mode
  168. if rx_buf and tx_buf are aligned on 8 byte boundary then
  169. use streaming DMA mode
  170. otherwise
  171. use PIO transfer
  172. THANKS TO
  173. ---------
  174. David Brownell and others for mentoring the development of this driver.