1. Add a SPI device (Actual SPI device driver), in my case it is altera spi
static struct resource spi_master_resource = {
= {
.start = SPI_MASTER_BASE,
.end = SPI_MASTER_END,
.flags = IORESOURCE_MEM,
},
= {
.start = SPI_MASTER_IRQ,
.end = SPI_MASTER_IRQ,
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device spi_master_device = {
.name = "spi_altera",
.id = 0, /* Bus number */
.num_resources = ARRAY_SIZE(spi_master_resource),
.resource = spi_master_resource,
};
2. Add spi board info. The id in SPI device and bus_num in spi board info shall match. you can add multiple entries if you have many.
static struct spi_board_info nios2_spi_devices = {
/* the modalias must be the same as spi device driver name */
.modalias = "spidev", /* Name of spi_driver for this device */
.max_speed_hz = 4000000, /* max spi clock (SCK) speed in HZ */
.bus_num = 0, /* bus number */
.chip_select = 4,
.mode = SPI_CPOL | SPI_CPHA,
},
3. Add a device in device table
/dev/spimas c 640 0 0 153 0 0 0 -
4. If all these things are done, still spi does show up, debug your spi device probe (not spidev), it may be returning due to not supported mode bits