162306a36Sopenharmony_ciSerial Peripheral Interface (SPI) 262306a36Sopenharmony_ci================================= 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciSPI is the "Serial Peripheral Interface", widely used with embedded 562306a36Sopenharmony_cisystems because it is a simple and efficient interface: basically a 662306a36Sopenharmony_cimultiplexed shift register. Its three signal wires hold a clock (SCK, 762306a36Sopenharmony_cioften in the range of 1-20 MHz), a "Master Out, Slave In" (MOSI) data 862306a36Sopenharmony_ciline, and a "Master In, Slave Out" (MISO) data line. SPI is a full 962306a36Sopenharmony_ciduplex protocol; for each bit shifted out the MOSI line (one per clock) 1062306a36Sopenharmony_cianother is shifted in on the MISO line. Those bits are assembled into 1162306a36Sopenharmony_ciwords of various sizes on the way to and from system memory. An 1262306a36Sopenharmony_ciadditional chipselect line is usually active-low (nCS); four signals are 1362306a36Sopenharmony_cinormally used for each peripheral, plus sometimes an interrupt. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciThe SPI bus facilities listed here provide a generalized interface to 1662306a36Sopenharmony_cideclare SPI busses and devices, manage them according to the standard 1762306a36Sopenharmony_ciLinux driver model, and perform input/output operations. At this time, 1862306a36Sopenharmony_cionly "master" side interfaces are supported, where Linux talks to SPI 1962306a36Sopenharmony_ciperipherals and does not implement such a peripheral itself. (Interfaces 2062306a36Sopenharmony_cito support implementing SPI slaves would necessarily look different.) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciThe programming interface is structured around two kinds of driver, and 2362306a36Sopenharmony_citwo kinds of device. A "Controller Driver" abstracts the controller 2462306a36Sopenharmony_cihardware, which may be as simple as a set of GPIO pins or as complex as 2562306a36Sopenharmony_cia pair of FIFOs connected to dual DMA engines on the other side of the 2662306a36Sopenharmony_ciSPI shift register (maximizing throughput). Such drivers bridge between 2762306a36Sopenharmony_ciwhatever bus they sit on (often the platform bus) and SPI, and expose 2862306a36Sopenharmony_cithe SPI side of their device as a :c:type:`struct spi_controller 2962306a36Sopenharmony_ci<spi_controller>`. SPI devices are children of that master, 3062306a36Sopenharmony_cirepresented as a :c:type:`struct spi_device <spi_device>` and 3162306a36Sopenharmony_cimanufactured from :c:type:`struct spi_board_info 3262306a36Sopenharmony_ci<spi_board_info>` descriptors which are usually provided by 3362306a36Sopenharmony_ciboard-specific initialization code. A :c:type:`struct spi_driver 3462306a36Sopenharmony_ci<spi_driver>` is called a "Protocol Driver", and is bound to a 3562306a36Sopenharmony_cispi_device using normal driver model calls. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciThe I/O model is a set of queued messages. Protocol drivers submit one 3862306a36Sopenharmony_cior more :c:type:`struct spi_message <spi_message>` objects, 3962306a36Sopenharmony_ciwhich are processed and completed asynchronously. (There are synchronous 4062306a36Sopenharmony_ciwrappers, however.) Messages are built from one or more 4162306a36Sopenharmony_ci:c:type:`struct spi_transfer <spi_transfer>` objects, each of 4262306a36Sopenharmony_ciwhich wraps a full duplex SPI transfer. A variety of protocol tweaking 4362306a36Sopenharmony_cioptions are needed, because different chips adopt very different 4462306a36Sopenharmony_cipolicies for how they use the bits transferred with SPI. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci.. kernel-doc:: include/linux/spi/spi.h 4762306a36Sopenharmony_ci :internal: 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci.. kernel-doc:: drivers/spi/spi.c 5062306a36Sopenharmony_ci :functions: spi_register_board_info 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci.. kernel-doc:: drivers/spi/spi.c 5362306a36Sopenharmony_ci :export: 54