SPI: Device API Besides the transfer, we need an abstraction for the device We may rely on the fact that read-only memory is cheaper We must support various pin configurations #define SPI_CS(x) (-1 - (x)) /* arg is 0.., value is negative */ #define __SPI_IS_HW_CS(x) ((x) < 0) #define __SPI_GET_HW_CS(x) (-(x) - 1) /* This is an interface for SPI, master and slave */ struct spi_cfg { int gpio_cs; /* Either GPIO number or SPI_CS(x) */ int freq; /* Suggested frequency */ int timeout; /* Jiffies */ unsigned long flags; uint8_t pol, phase, bits, devn; /* devn selects spi0 or spi1 or more */ }; /* This would be opaque if we had malloc */ struct spi_dev { const struct spi_cfg *cfg; unsigned long base; int current_freq; }; extern struct spi_dev *spi_create(struct spi_dev *cfg); extern void spi_destroy(struct spi_dev *dev);