In normal scenario a spi device driver talks to the SPI controller to be able to read/write to/from the real SPI device, which is connected to the SPI controller with Clk, MOSI.MISO and CS(chip select).
if SPI controller does not have enough CS lines, we have a CPLD device connected over SPI to have 16 more CS line. AS every device has one driver for it, I would like to implement a SPI Mux so that devices connected over the CPLD are accesecible.
CPLD has two CS lines, one to select the CPLD device itself and other to route it to further devices connected to it. the other CLK,MOSI,MISO are comming from SPI Controller. as standard the info about the device could be added intp spi_board_info
static struct spi_board_info spi_board_cpld_main_mux_info[] =
{
{ /* main board cpld cs */
.modalias = "cpld_gpio", //device driver for CPLD
.platform_data = &cpld_gpio_main_pdata,
.controller_data = (void *)GPIO59_SPI2_FRM,
.max_speed_hz = 13000000,
.bus_num =2,
.chip_select = 0,
.mode = SPI_MODE_0,
},
{
/* Suzuka connected over CPLD main card */
.modalias = "suzuka",
//.platform_data = &main_cpld_gpio_pdata,
.controller_data = (void *)25,
.max_speed_hz = 1000000,
.bus_num = 2,
.chip_select = 1, /* chip select line denoting the gpio_cs on CPLD */
.mode = SPI_MODE_0,
},
{
/* some SPI device connected over CPLD main card */
.modalias = "spidevice1",//or some another driver
//.platform_data = &aux_cpld_gpio_pdata,
.controller_data = (void *)25,
.max_speed_hz = 1000000,
.bus_num = 2,
.chip_select = 2, /* chip select line denoting the gpio_cs on CPLD */
.mode = SPI_MODE_0,
}
};
But the driver hooked to these elements cannot write to the real devices as the CS has to berouted to the intended device over the CPLD which is another SPI device.
My Dillema is how to realize such a SPI MUX which would do the routing of CS every time decive driver wants to access the devices connected over the CPLD. and also how to hook this SPI MUX driver to the individual drivers.
I tried to find some help in kernel code, but found only device drivers which could directly call the SPI Master functionality. Could any one give any pointer for this.