Configuring Second SPI Port in DTS for i.MX7D

In the device tree I’m trying to configure a second SPI port for use from user space.

We have ecspi3 working and it is available as spidev2.0 in user space. It works when called, and I can see that bytes are read from or written to the ecspi3 SPI port using a logic analyzer.

We’re also trying to configure a second SPI port, ecspi2, for use. I’m using similar node names, to ecspi3 for setting up ecspi2 in the device tree. Here are the device tree nodes:

&ecspi2 {
	status = "okay";

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

/* Colibri SPI */
&ecspi2 {
	fsl,spi-num-chipselects = <1>;
	cs-gpios = <&gpio7 9 GPIO_ACTIVE_HIGH>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_ecspi2 &pinctrl_ecspi2_cs>;
};

// 5/26/20167 KJC - Setup i2c3 port lines used for communicating with the 
//	            FPGA.
&iomuxc {
	imx7d-p1100 {
		pinctrl_ecspi2_cs: ecspi2_cs_grp {
			fsl,pins = <
				MX7D_PAD_ENET1_RGMII_TD3__GPIO7_IO9	0x14 // 194  
			>;
		};

		pinctrl_ecspi2: ecspi2grp {
			fsl,pins = <
				MX7D_PAD_ENET1_RGMII_TD2__ECSPI2_MISO	0x2  // 196
				MX7D_PAD_ENET1_RGMII_RD3__ECSPI2_MOSI	0x2  // 55
				MX7D_PAD_ENET1_RGMII_RD2__ECSPI2_SCLK	0x2  // 63
			>;
		};
	};
};

After adding the above lines to our carrier board dts file, building, and then copying the dtb file to our device I can see two spi ports available from userspace: spidev1.0, and spidev2.0. spidev1.0 corresponds to escpi2, and spidev2.0 corresponds to ecspi3.

When I make the call to escpi3 using: open( "/dev/spidev2.0", O_RDWR) it works and I can read data from and write data to the spi port. I can see the activity on the spi lines using our logic port analyzer.

When I make the call to escpi2 using: open( "/dev/spidev1.0", O_RDWR) the only activity I see on the logic analyzer is that chip select (SSO) goes low, as it should, but there is no clock, MOSI, or MISO activity.

I did discover that one of the GPIO lines we are using for ecspi2: MX7D_PAD_ENET1_RGMII_TD2__ECSPI2_MISO is also used for i2c4 in the Colibri evaluation board as: MX7D_PAD_ENET1_RGMII_TD2__I2C4_SCL.

I have commented out those lines in the imx7-colibri.dtsi file that setup i2c4 and use the GPIO line that we need for ecspi2 (spidev1.0), but ecspi2 is still not woirking. Only the chip select line (SS0) seems to behave the way that it should.

I’ve also tried disabling ecspi3 by setting it’s status property to disabled. When I do this only spidev1.0 appears in /dev as I would expect, but it still doesn’t work.

What do I need to do to get escpi2 (spidev1.0) working properly?

Thank You

MX7D_PAD_ENET1_RGMII_TD3__GPIO7_IO9 and MX7D_PAD_ENET1_RGMII_TD2__ECSPI2_MISO are used by I2C4. I2C4 would have to be disabled if you want to use those pins for SPI. Also the ECSPI2 MOSI and SCLK pins are configured as GPIO by default. While I did not test, the below would be the expected set of changes to get ECSPI2 to work along with ECSPI3.

diff --git a/arch/arm/boot/dts/imx7-colibri-eval-v3.dtsi b/arch/arm/boot/dts/imx7-colibri-eval-v3.dtsi
index 1db5aa5365b2..b8e72d9a9aee 100644
--- a/arch/arm/boot/dts/imx7-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/imx7-colibri-eval-v3.dtsi
@@ -89,6 +89,20 @@
        status = "okay";
 };
 
+&ecspi2 {
+       fsl,spi-num-chipselects = <1>;
+       cs-gpios = <&gpio7 9 GPIO_ACTIVE_HIGH>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_ecspi2 &pinctrl_ecspi2_cs>;
+       status = "okay";
+
+       spidev1: spidev@1 {
+               compatible = "toradex,evalspi";
+               reg = <0>;
+               spi-max-frequency = <23000000>;
+       };
+};
+
 &ecspi3 {
        status = "okay";
 
@@ -101,14 +115,14 @@
                interrupt-parent = <&gpio5>;
                interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
                spi-max-frequency = <10000000>;
-               status = "okay";
+               status = "disabled";
        };
 
        spidev0: spidev@0 {
                compatible = "toradex,evalspi";
                reg = <0>;
                spi-max-frequency = <23000000>;
-               status = "disabled";
+               status = "okay";
        };
 };
 
@@ -117,7 +131,7 @@
 };
 
 &i2c4 {
-       status = "okay";
+       status = "disabled";
 
        touch: touchrevf0710a@10 {
                compatible = "touchrevolution,fusion-f0710a";
@@ -327,5 +341,19 @@
                                MX7D_PAD_GPIO1_IO10__GPIO1_IO10         0x14
                        >;
                };
+
+               pinctrl_ecspi2_cs: ecspi2_cs_grp {
+                       fsl,pins = <
+                               MX7D_PAD_ENET1_RGMII_TD3__GPIO7_IO9     0x14
+                       >;
+               };
+
+               pinctrl_ecspi2: ecspi2grp {
+                       fsl,pins = <
+                               MX7D_PAD_ENET1_RGMII_TD2__ECSPI2_MISO    0x2
+                               MX7D_PAD_ENET1_RGMII_RD3__ECSPI2_MOSI    0x2
+                               MX7D_PAD_ENET1_RGMII_RD2__ECSPI2_SCLK    0x2
+                       >;
+               };
        };
 };
diff --git a/arch/arm/boot/dts/imx7-colibri.dtsi b/arch/arm/boot/dts/imx7-colibri.dtsi
index 0d0a31e74784..44fee1383d9d 100644
--- a/arch/arm/boot/dts/imx7-colibri.dtsi
+++ b/arch/arm/boot/dts/imx7-colibri.dtsi
@@ -288,8 +288,6 @@
                pinctrl_hog_1: hoggrp-1 {
                        fsl,pins = <
                                MX7D_PAD_UART3_RTS_B__GPIO4_IO6         0x14 /* SODIMM 131 USBH OC */
-                               MX7D_PAD_ENET1_RGMII_RD3__GPIO7_IO3     0x74 /* SODIMM 55 */
-                               MX7D_PAD_ENET1_RGMII_RD2__GPIO7_IO2     0x74 /* SODIMM 63 */
                                MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16       0X14 /* SODIMM 77 */
                                MX7D_PAD_EPDC_DATA09__GPIO2_IO9         0x14 /* SODIMM 89 */
                                MX7D_PAD_EPDC_DATA08__GPIO2_IO8         0x74 /* SODIMM 91 */

Hello sanchayan.tx,

Thanks for your response. I actually got this working shortly after I sent my question, so everything is cool now. I just didn’t have time to respond until now.

Thanks for the information. :).

" I actually got this working shortly after I sent my question"

please share the updated DTS folder (or the files with changes) with working ecspi2 and ecspi3 from user-space spidevs.

Moreover, if you can share the corresponding user-space code to use these spidevs together.

Thanks in advance.

The changes shown by @sanchayan.tx should give you the two spidev device files /dev/spidev1.0 and /dev/spidev2.0. If not, did compiling the device tree and transferring it to the device succeeded? Can you share the complete kernel log (dmesg)?

You can find example code how to use the spidev devices in the Linux kernel source Documentation/spi/ folder.