spi.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. Serial Peripheral Interface (SPI)
  2. =================================
  3. SPI is the "Serial Peripheral Interface", widely used with embedded
  4. systems because it is a simple and efficient interface: basically a
  5. multiplexed shift register. Its three signal wires hold a clock (SCK,
  6. often in the range of 1-20 MHz), a "Master Out, Slave In" (MOSI) data
  7. line, and a "Master In, Slave Out" (MISO) data line. SPI is a full
  8. duplex protocol; for each bit shifted out the MOSI line (one per clock)
  9. another is shifted in on the MISO line. Those bits are assembled into
  10. words of various sizes on the way to and from system memory. An
  11. additional chipselect line is usually active-low (nCS); four signals are
  12. normally used for each peripheral, plus sometimes an interrupt.
  13. The SPI bus facilities listed here provide a generalized interface to
  14. declare SPI busses and devices, manage them according to the standard
  15. Linux driver model, and perform input/output operations. At this time,
  16. only "master" side interfaces are supported, where Linux talks to SPI
  17. peripherals and does not implement such a peripheral itself. (Interfaces
  18. to support implementing SPI slaves would necessarily look different.)
  19. The programming interface is structured around two kinds of driver, and
  20. two kinds of device. A "Controller Driver" abstracts the controller
  21. hardware, which may be as simple as a set of GPIO pins or as complex as
  22. a pair of FIFOs connected to dual DMA engines on the other side of the
  23. SPI shift register (maximizing throughput). Such drivers bridge between
  24. whatever bus they sit on (often the platform bus) and SPI, and expose
  25. the SPI side of their device as a :c:type:`struct spi_master
  26. <spi_master>`. SPI devices are children of that master,
  27. represented as a :c:type:`struct spi_device <spi_device>` and
  28. manufactured from :c:type:`struct spi_board_info
  29. <spi_board_info>` descriptors which are usually provided by
  30. board-specific initialization code. A :c:type:`struct spi_driver
  31. <spi_driver>` is called a "Protocol Driver", and is bound to a
  32. spi_device using normal driver model calls.
  33. The I/O model is a set of queued messages. Protocol drivers submit one
  34. or more :c:type:`struct spi_message <spi_message>` objects,
  35. which are processed and completed asynchronously. (There are synchronous
  36. wrappers, however.) Messages are built from one or more
  37. :c:type:`struct spi_transfer <spi_transfer>` objects, each of
  38. which wraps a full duplex SPI transfer. A variety of protocol tweaking
  39. options are needed, because different chips adopt very different
  40. policies for how they use the bits transferred with SPI.
  41. .. kernel-doc:: include/linux/spi/spi.h
  42. :internal:
  43. .. kernel-doc:: drivers/spi/spi.c
  44. :functions: spi_register_board_info
  45. .. kernel-doc:: drivers/spi/spi.c
  46. :export: