Add spidev with other CS to imx7D

Hello,

I’m working on imx7D, with a Colibri Evaluation Board v3.2B. I’m building a Kernel with Toradex Repository V2.7 (Linux Kernel Version is 4.1.35-v2.7b1+gc117783)

I have a working SPI Device on ecspi3, working with default Chip Select:

cs-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>;

I would like to add another /dev/spidev that would use the same signals exept for CS.

I followed information here: Add an SPI device to colibri imx6 - Toradex Community

But I could not get new spidev… So, here is what I have done:

  • Using pin configurator, I found that CS1 for ecspi3 is pin 53. In imx7d-pinfunc.h I figured out that is was GPIO05 IO8.
  • I modified imx7-colibri.dtsi:

Original:

&ecspi3 {
	fsl,spi-num-chipselects = <1>;
	cs-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs>;
};

pinctrl_ecspi3_cs: ecspi3_cs_grp {
    fsl,pins = <
        MX7D_PAD_I2C2_SDA__GPIO4_IO11		0x14
    >;
};

Became:

&ecspi3 {
    fsl,spi-num-chipselects = <2>;
    cs-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>, <&gpio5 8 GPIO_ACTIVE_HIGH>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs>;
};


pinctrl_ecspi3_cs: ecspi3_cs_grp {
    fsl,pins = <
        MX7D_PAD_I2C2_SDA__GPIO4_IO11		0x14
        MX7D_PAD_SD1_DATA3__GPIO5_IO8       0x14
    >;
};
  • I also modified imx7-colibri-eval-v3.dtsi:

After spidev0: spidev@1 in &ecspi3 node, I added:

    spidev1: spidev@2 {
		compatible = "toradex,evalspi";
		reg = <1>;
        spi-max-frequency = <23000000>;
        status = "okay";
	};

During boot, the only trace refering to spi is the following:

[    1.138252] spi_imx 30840000.ecspi: probed

Is there something wrong or missing? (It must as I do not get the second spidev :frowning: )

The number after the @ in the node name needs to match the reg property, e.g.

 spidev1: spidev@2 {
     compatible = "toradex,evalspi";
     reg = <2>;
     spi-max-frequency = <23000000>;
     status = "okay";
 };

In https://www.toradex.com/community/questions/3068/add-an-spi-device-to-colibri-imx6.html they use reg 1 for spidev@2 and it seems to work.
And base spidev@1 use reg 0 in the imx7-colibri-eval-v3.dtsi http://git.toradex.com/cgit/linux-toradex.git/tree/arch/arm/boot/dts/imx7-colibri-eval-v3.dtsi?h=toradex_4.1-2.0.x-imx

Anyway I tried like you said and I still only have 1 spidev2.0…

You are right, and that is actually wrong in our standard device tree, thanks for pointing out. Let me reproduce your issue here to figure out what is going wrong in your case.

Note that the MX7D_PAD_SD1_DATA3 pad is used by the SD-card controller (usdhc1). You need to disable that node in order to make sure that you don’t have pin conflicts. Altough, in my case ecspi actually managed to acquire the pin before usdhc1, but the SD-card driver could not really handle that situation:

[   11.936468] imx7d-pinctrl 30330000.iomuxc: pin MX7D_PAD_SD1_DATA3 already requested by 30840000.ecspi; cannot claim for 30b40000.usdhc
[   11.952997] imx7d-pinctrl 30330000.iomuxc: pin-106 (30b40000.usdhc) status -22

But after disabling usdhc1, the two spidev devices showed up successfully. Note that I changed the Carrier board device tree exclusively by just appending pinctrls/overwriting nodes (see also Device Tree Customization):

&ecspi3 {
    status = "okay";
    fsl,spi-num-chipselects = <2>;
    cs-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>, <&gpio5 8 GPIO_ACTIVE_HIGH>;
    pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs &pinctrl_ecspi3_cs2>;

    mcp258x0: mcp258x@0 {
	    compatible = "microchip,mcp2515";
	    pinctrl-names = "default";
	    pinctrl-0 = <&pinctrl_can_int>;
	    reg = <0>;
	    clocks = <&clk16m>;
	    interrupt-parent = <&gpio5>;
	    interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
	    spi-max-frequency = <10000000>;
	    status = "disabled";
    };

    spidev0: spidev@0 {
	    compatible = "toradex,evalspi";
	    reg = <0>;
	    spi-max-frequency = <23000000>;
	    status = "okay";
    };

    spidev1: spidev@1 {
	    compatible = "toradex,evalspi";
	    reg = <1>;
	    spi-max-frequency = <23000000>;
	    status = "okay";
    };
};

&usdhc1 {
    ...
    status = "disabled";
};

&iomuxc {
    imx7d-eval-v3 {
    ...
	    pinctrl_ecspi3_cs2: ecspi3_cs_grp2 {
		    fsl,pins = <
			    MX7D_PAD_SD1_DATA3__GPIO5_IO8		0x14
		    >;
	    };
    };
};

With that, I got both spidev devices:

root@colibri-imx7:~# dmesg | grep spi
[    1.171273] spi_imx 30840000.ecspi: probed
root@colibri-imx7:~# ls -l /dev/spidev*
crw-------    1 root     root      153,   0 Mar 15 19:58 /dev/spidev2.0
crw-------    1 root     root      153,   1 Mar 15 19:58 /dev/spidev2.1
root@colibri-imx7:~#

Yeah!! It works!! I mean, I do not yet test the signal driving of signals, but I manage to get spidev2.0 and spidev2.1!
Many many thanks Stephan!