The driver architecture
The required header for SPI stuff in the Linux kernel is <linux/spi/spi.h>
. Before talking about the driver structure, let's see how SPI devices are defined in the kernel. An SPI device is represented in the kernel as an instance of spi_device
. The instance of the driver that manages them is the struct spi_driver
structure.
The device structure
The struct spi_device
structure represents an SPI device, and is defined in include/linux/spi/spi.h
:
struct spi_device { struct devicedev; struct spi_master*master; u32 max_speed_hz; u8 chip_select; u8 bits_per_word; u16 mode; int irq; [...] int cs_gpio; /* chip select gpio */ };
Some fields that are not meaningful for us have been removed. The following are the meanings of the elements in the structure:
master
: This represents the SPI controller (bus) on which the device is connected.max_speed_hz
: This is the maximum clock rate to be used with this chip (on the current...