How to add new spi device as spidev0.2?



  • Hello all, i am trying to add a new device over spi on omega2s+.

    SPI device will be on spidev0 and currently, spidev0.0 is used for internal flash on omega2s+. And I used spidev0.1 for another device, and I have another device to communicate over spi, then I need spidev0.2 as using a gpio for Chip select.

    Could you help me how I can do this?



  • The hardware SPI can only drive 2 devices, as there is only CS0 (already used by internal flash) and CS1 (which you already use).

    So you'd need to resort to software (GPIO based) SPI if you need more SPI devices. So just load the spi-gpio-custom kernel module:

    # configure software GPIO SPI
    # bus<Y>=<devid>,<SCK>,<MOSI>,<MISO>,<mode>,<speedInHz>,<CS>
    insmod spi-gpio-custom bus0=1,11,5,4,0,100000,18
    

    Where

    • Y just numbers the software SPI "buses" controlled by spi-gpio-custom. If you need multiple software SPI, you need to specify all of them on the same insmod command line, and specify parameters like bus0=... bus1=... bus2=...
    • devid is the number X you'll have in the /dev/spidevX.0 name
    • SCK, MOSI, MISO, CS are GPIO numbers for the respective signals
    • mode is the SPI mode, usually 0
    • speedinHz is the speed. Note that software SPI speed is limited, you'll not get the HW SPI top speed with it

    The example above will get you a /dev/spidev1.0 on pins 11,5,4 and 18, in mode 0 and with 100kHz speed.

    Note: if you have full control over when you access your devices, you could also multiplex the HW SPI from CS1 to more than one device (eg. with a 74HC138,139 or similar), and use some GPIOs to switch devices before you access them.



  • @luz Thank you for detailed explanation. I probably will use soft spi because of parallel usage needs of two devices. it will be too slow but there is no other chance. I will need to make some hardware design changes.

    But i couldnt understand why hardware spi count is limited in openwrt side. i know MT7688 has two hardware supported spi cs pin but it could be increased by openwrt side as adding gpios as cs with hardware spi.

    Thanks again @luz



Looks like your connection to Community was lost, please wait while we try to reconnect.