This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM3354: Multiple CS support for SPI

Part Number: AM3354

Hi,

I would like to add multiple CS (Chip Select) support in the device tree to handle multiple SPI devices with help of /dev/spidev1.x (x is a number of CS) nodes. Please find below snippet of my device tree.

   spi1_pins: pinmux_spi1_pins {
      pinctrl-single,pins = <
         0x190 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_aclkx.spi1_sclk */
         0x194 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_fsx.spi1_d0 */
         0x198 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_axr0.spi1_d1 */
         0x19C (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_ahclkr.spi1_cs0 */
         0x108 (MUX_MODE7)  /* mii1_col.gpio3_0 */
      >;
   };

&spi1 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi1_pins>;
   ti,pindir-d0-out-d1-in = <1>;
 
   spidev@0 {
      compatible = "linux,spidev";
      spi-max-frequency = <20000000>;
      reg = <0>;
   };

   spidev@1 {
      compatible = "linux,spidev";
      spi-max-frequency = <20000000>;
      reg = <1>;
   };
};

With the mentioned device tree information, I am only able to handle spidev1.0 with the CS0 pin. I am not able to handle spidev1.1 with the CS1 pin. Kindly help me to resolve this issue.

Best Regards,

Neel

  • Hi Neel,

    Seems that spi1_cs1 pinmux is missing from your DTS file. You also need to add #address-cells and #size-cells in spidev nodes. Also "rohm,dh2228fv" should be used instead of "linux,spidev".  Please refer pointers for reference:

    linux-4.19.38/arch/arm/boot/dts/am335x-boneblack-spi0.dtsi

    linux-4.19.38/arch/arm/boot/dts/am335x-icev2-common.dtsi

    Regards,
    Pavel

  • Hi Pavel,

    Thank you for your response. But I was not able to solve this issue with the below device tree. Here, I am using gpio3_0 for CS with MUX_MODE7 (I/O). I am not using an internal CS pin with MUX_MODE3. Please let me know what I have done wrong.

    spi1_pins: pinmux_spi1_pins {
       pinctrl-single,pins = <
          0x190 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_aclkx.spi1_sclk */
          0x194 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_fsx.spi1_d0 */
          0x198 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_axr0.spi1_d1 */
          0x19C (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_ahclkr.spi1_cs0 */
          0x108 (MUX_MODE7)  /* mii1_col.gpio3_0 */
       >;
    };
    
    &spi1 {
       status = "okay";
       pinctrl-names = "default";
       pinctrl-0 = <&spi1_pins>;
       ti,pindir-d0-out-d1-in = <1>;
       ti,spi-num-cs = <2>;
    
       spidev@0 {
          compatible = "rohm,dh2228fv";
          spi-max-frequency = <20000000>;
          reg = <0>;
          status = "okay";
          #address-cells = <1>;
          #size-cells = <0>;
       };
    
       spidev@1 {
          compatible = "rohm,dh2228fv";
          spi-max-frequency = <20000000>;
          reg = <1>;
          status = "okay";
          #address-cells = <1>;
          #size-cells = <0>;
       };
    };
    

    I have made some corrections in my device-tree and able to resolve my issue with the below device tree.

    spi1_pins: pinmux_spi1_pins {
       pinctrl-single,pins = <
          0x190 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_aclkx.spi1_sclk */
          0x194 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_fsx.spi1_d0 */
          0x198 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_axr0.spi1_d1 */
       >;
    };
    
    &spi1 {
       status = "okay";
       pinctrl-names = "default";
       pinctrl-0 = <&spi1_pins>;
       ti,pindir-d0-out-d1-in = <1>;
       num_cs = <2>;
       cs-gpios = <&gpio3 17 0>,<&gpio3 0 0>;
    
       spidev@0 {
          compatible = "rohm,dh2228fv";
          spi-max-frequency = <20000000>;
          reg = <0>;
       };
    
       spidev@1 {
          compatible = "rohm,dh2228fv";
          spi-max-frequency = <20000000>;
          reg = <1>;
       };
    };

  • Neel Oza said:
    &spi1 {
       status = "okay";
       pinctrl-names = "default";
       pinctrl-0 = <&spi1_pins>;
       ti,pindir-d0-out-d1-in = <1>;
       ti,spi-num-cs = <2>;

    ti,spi-num-cs entry is NOT needed, as already defined in the base AM33xx DTS file, that you need to include in your main DTS file.

    linux-kernel/arch/arm/boot/dts/am33xx.dtsi

    Neel Oza said:
    spi1_pins: pinmux_spi1_pins {
       pinctrl-single,pins = <
          0x190 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_aclkx.spi1_sclk */
          0x194 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_fsx.spi1_d0 */
          0x198 (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_axr0.spi1_d1 */
          0x19C (PIN_INPUT_PULLUP | MUX_MODE3) /* mcasp0_ahclkr.spi1_cs0 */
          0x108 (MUX_MODE7)  /* mii1_col.gpio3_0 */
       >;
    };

    One CS is McSPI pin, other is GPIO pin. That might be the main issue. In your working setup, you have CS both GPIO pins.