How to use SPI on Colibri IMX6ULL

type “dmesg” at command prompt.

Thank you for your replay.
Where can I find the dmesg.log?
Best regards
Matteo

Dear @jaski.tx,
I changed the branch and I rebuilt the 4.9.2.3 with my changed.But I had again the same problem: I don’t found the spi device.
I attached the dmes.log link text
Could you help me?
Best regards
Matteo

hi @Matte

According to your dmesg.log, you have several pin conflict errors. Could you correct them?

[    1.376123] imx6ul-pinctrl 20e0000.iomuxc: pin MX6UL_PAD_GPIO1_IO05 already requested by 21f4000.serial; cannot claim for 2008000.ecspi
[    1.395653] imx6ul-pinctrl 20e0000.iomuxc: pin-28 (2008000.ecspi) status -22
[    1.406431] imx6ul-pinctrl 20e0000.iomuxc: could not request pin 28 (MX6UL_PAD_GPIO1_IO05) from group ecspi1-cs-grp  on device 20e0000.iomuxc
[    1.426214] spi_imx 2008000.ecspi: Error applying setting, reverse things back
[    1.440829] spi_imx: probe of 2008000.ecspi failed with error -22

Best regards,
Jaski

Dear @jaski.tx,
Thank fir your replay.
I understood the problem, the I’m changing the PIN.
Of I have again any problem, I’ll contact you.
Best regards
Matteo

Perfect. Please let us know if you have any other questions.

Dear @jaski.tx,
I want to use the following pins for the SPI:

              MX6UL_PAD_GPIO1_IO05__GPIO05	0x70a0 /* SODIMM 21 */
              MX6UL_PAD_JTAG_TDO__GPIO1_IO12		0x70a0 /* SODIMM 23 */
              MX6UL_PAD_UART1_CTS__GPIO1_IO18	0x70a0	/* SODIMM 25 */

Can I use them?

Because I have again the conflict problem and I don’t understand how I can to solve it.

Do I need to disable the functionality that I don’t use?
I attachs the files imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi. link text

Could you help me?

Best regards

Matteo

Hi @Matte

Can I use them?

Sure, you can use the Pins.

Because I have again the conflict problem and I don’t understand how I can to solve it.

You need to check the Pins you want to use are not defined anywhere else.

Do I need to disable the functionality that I don’t use? I attach the files imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi. link text

Yes. You need to choose which Pins you want to use for which functionality.
By the way, the files you sent me, are they compiling without errors?

Best regards,
Jaski

Dear @jaski.tx,
Thank you for your replay.
I sent you a wrong file, I fixed the file and now they compile correctly. link text
Could you confirm me that the the following Pin name it’s right?

              pinctrl_ecspi1_cs: ecspi1-cs-grp {
	         fsl,pins = <
             `         MX6UL_PAD_GPIO1_IO05__GPIO1_IO05	0x70a0 /* SODIMM 21 */
                       MX6UL_PAD_JTAG_TDO__GPIO1_IO12		0x70a0 /* SODIMM 23 */
                       MX6UL_PAD_UART1_CTS_B__GPIO1_IO18  	0x70a0	/* SODIMM 25 */
        	>;
    	};

On thre tree at the moment:

    PIN 21 It's used on **uart5grp** 
    PIN 23 it's used on  **uart1-ctrlgrp1**
    PIN 25 it's used on **uart1-grp**

Do I need to disable this uart1 and uart5 to use them?
Thank you
Best Regards

Hi @Matte

Thanks for the files. They seems to be correct.

Do I need to disable this uart1 and uart5 to use them?

Yes, you need to disable them or use other pins. You can disable UART5 but disabling UART1 will lead to lose of the console and you need to redirect the console to a different UART Port.

Best regards,
Jaski

Dear @jaski.tx,
Thank for your support.
In order to disable the uart5 do I need to change its status on imx6ull-colibri-eval-v3.dtsi

       &uart5 {
            status = "disable";
         };

Is it right?

Best regards

Matteo

You are welcome.

It should be

status = "disabled";

Please check the existing device-tree files for this.

Thank for your replay.

I have a last question about the choose of PIN.

If I want to use the camera’s PIN because I’m sure that to do not used that feature.
I need to remove the pinctrl_hog_2 from iomuxc of file imx6ull-colibri-nonwifi.dtsi
and the I can add those PIN on SPI section or is there any other way to do it?

Best regards

Matteo

You are welcome.

I need to remove the pinctrl_hog_2 from iomuxc of file imx6ull-colibri-nonwifi.dtsi and the I can add those PIN on SPI section or is there any other way to do it?

Yes, or you just make sure that the pinctrl_hog_2 is not used anywhere in the devicetree.

Best regards,
Jaski

Dear @jaski.tx,
I decided to use the UART2 PINS for SPI, I disabled the UART2 and inserted the PINS on SPI Section I compiled the tree link text.

When I do dmesg on the IMX6ULL I have the following error:

[    1.341373] gpmi-nand 1806000.gpmi-nand: driver registered.
[    1.355765] spi_imx 2008000.ecspi: cs1 >= max 1
[    1.363888] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@1
[    1.381565] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@1
[    1.400095] spi_imx 2008000.ecspi: cs2 >= max 1
[    1.408240] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@2
[    1.426377] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@2
[    1.445284] spi_imx 2008000.ecspi: cs3 >= max 1
[    1.453559] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@3
[    1.471824] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@3
[    1.491079] spi_imx 2008000.ecspi: probed

The configuration of the tree is the following:

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

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

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

spidev3: spidev@3 {
        compatible = "toradex,evalspi";
        reg = <3>;
        spi-max-frequency = <1000000>;
        status = "okay";
};

Could you tell me what I’m wrong?

Hi @Matte

You need to use the num-cs property and not the fsl,spi-num-chipselects since iMX6ULL is using a different spi driver ( drivers/spi/spi-imx.c ) as mentioned in ( arch/arm/boot/dts/imx6ul.dtsi ).

With the patch below you should be able to get the spidev devices you want. The colibri-spi-csx are symbolic links for the spidev0.x devices.

Best regards,
Jaski

diff --git a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
index 96f4438a3569..20084ec7ae0f 100644
--- a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
@@ -94,15 +94,39 @@
 		spi-max-frequency = <10000000>;
 		vdd-supply = <&reg_3v3>;
 		xceiver-supply = <&reg_5v0>;
-		status = "okay";
-	};
-
-	spidev0: spidev@0 {
-		compatible = "toradex,evalspi";
-		reg = <0>;
-		spi-max-frequency = <23000000>;
 		status = "disabled";
 	};
+
+
+        spidev0: spidev@0 {
+                compatible = "toradex,evalspi";
+                reg = <0>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+
+        spidev1: spidev@1 {
+                compatible = "toradex,evalspi";
+                reg = <1>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+
+         spidev2: spidev@2 {
+                compatible = "toradex,evalspi";
+                reg = <2>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+      spidev3: spidev@3 {
+                compatible = "toradex,evalspi";
+                reg = <3>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
 };
 
 &can1 {
@@ -298,7 +322,7 @@
 };
 
 &uart2 {
-	status = "okay";
+	status = "disabled";
 };
 
 &uart5 {
diff --git a/arch/arm/boot/dts/imx6ull-colibri.dtsi b/arch/arm/boot/dts/imx6ull-colibri.dtsi
index 10d3605e0ac4..3ef13ae776f7 100644
--- a/arch/arm/boot/dts/imx6ull-colibri.dtsi
+++ b/arch/arm/boot/dts/imx6ull-colibri.dtsi
@@ -106,7 +106,11 @@
 
 /* Colibri SPI */
 &ecspi1 {
-	cs-gpios = <&gpio3 26 GPIO_ACTIVE_HIGH>;
+	fsl,spi-num-chipselects = <4>;
+	cs-gpios =  <&gpio1 20 GPIO_ACTIVE_LOW>,
+				<&gpio1 21 GPIO_ACTIVE_LOW>,
+				<&gpio1 22 GPIO_ACTIVE_LOW>,
+				<&gpio1 23 GPIO_ACTIVE_LOW>;
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1_cs>;
 };
@@ -319,7 +323,10 @@
 
 	pinctrl_ecspi1_cs: ecspi1-cs-grp {
 		fsl,pins = <
-			MX6UL_PAD_LCD_DATA21__GPIO3_IO26	0x70a0	/* SODIMM 86 */
+			MX6UL_PAD_UART2_CTS_B__GPIO1_IO22	0x70a0 /* SODIMM 32 */
+			MX6UL_PAD_UART2_RTS_B__GPIO1_IO23	0x70a0 /* SODIMM 34 */
+			MX6UL_PAD_UART2_RX_DATA__GPIO1_IO21  	0x70a0	/* SODIMM 38 */
+			MX6UL_PAD_UART2_TX_DATA__GPIO1_IO20  	0x70a0	/* SODIMM 36 */
 		>;
 	};

Thank you,

now I have 4 SPI, and I seem everything right.

Matteo

Perfect that it works. Thanks for that feedback.

Best regards,
Jaski

Dear @jaski.tx,

I need to change the value of SPI output gpio on sometime while the my application is running.
If I use the Toradex GPIO tool the value is changed right.
I saw the change value using the command: cat /sys/kernel/debug/gpio and with the oscilloscope.

Before:
gpiochip0: GPIOs 0-31, parent: platform/209c000.gpio, 209c000.gpio:
gpio-2 ( |VCC_USB[1-4] ) out lo
gpio-11 ( |enable ) out hi
gpio-20 ( |spi_imx ) out hi
gpio-21 ( |spi_imx ) out hi
gpio-22 ( |spi_imx ) out hi
gpio-23 ( |spi_imx ) out hi
After:
gpiochip0: GPIOs 0-31, parent: platform/209c000.gpio, 209c000.gpio:
gpio-2 ( |VCC_USB[1-4] ) out lo
gpio-11 ( |enable ) out hi
gpio-20 ( |spi_imx ) out hi
gpio-21 ( |spi_imx ) out lo
gpio-22 ( |spi_imx ) out hi
gpio-23 ( |spi_imx ) out hi

I tried to use the following lines:

                     // export GPIO
                     fd = open("/sys/class/gpio/export", O_WRONLY);
                    write(fd, "21", 2);
                    close(fd);

                      // configure as output
                      fd = open("/sys/class/gpio/gpio21/direction", O_WRONLY);
                      write(fd, "out", 3);
                      close(fd);

                     fd = open("/sys/class/gpio/gpio21/value", O_WRONLY | O_SYNC);
                     write(fd, "0", 1);

I used these commands on the VF61 and they run right.
Then I tried to export gpio21 on IMX6ULL it’s give me a error message and the folder gpio21 is not created.
I tried the following command line: echo 21 > /sys/class/gpio/export

and obtained this error: write error: Device or resource busy

How could I change the status of SPI GPIO output?

Thank you,

Best regards

Matteo

hi @Matte

Could you ask a new question? This will help us to keep the Community clean.

Thanks and best regards,
Jaski