0

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.

Amiy
  • 1
  • 3
  • I don't see a way to do that without replacing the device drivers that talk directly to the SPI for ones that are aware of your MUXing. And these, you'll probably have to write yourself, based on the originals. Do you really need SPI on those devices? This would be a lot easier with I2C... – Fabio Ceconello Feb 28 '13 at 20:56
  • See: http://stackoverflow.com/questions/14053535/more-than-two-spi-devices-on-an-arm-board-that-supports-only-two which is similar. – artless noise Mar 01 '13 at 22:23
  • Most drivers support a `GPIO` chip select; via a negative chip select value. They will call Linux `GPIO` functions. Write a `GPIO` handler that accesses the `CPLD` and hits the multiplexor. No need to alter the `SPI` drivers. – artless noise Mar 01 '13 at 23:57

0 Answers0