How to enable spidev on i.MX6 using kernel 3.10.9?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to enable spidev on i.MX6 using kernel 3.10.9?

Jump to solution
24,414 Views
rathben
Contributor III

Hi,

I'm moving my i.MX6 based project from LTIB to Yocto and trying to reproduce the steps I used in LTIB to enable spidev on a particular SPI. This is described well in a number of places including here https://community.freescale.com/thread/302612

This mostly amounts to modifying some files in /arch/arm/mach-mx6, however this directory and the applicable sources don't exist in the 3.10.9 kernel. I have successfully done this with Yocto+3.0.35, but have an interest in using a newer kernel.

Is there a new way to perform this sort of hardware configuration? If so, can someone provide me with a pointer to some information?

Thanks! -Ben

Labels (2)
1 Solution
5,460 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Ben

     New kernel of L3.10 uses device tree, all those hardware related config will be passed from dtb to kernel, you can refer to arch/arm/boot/dts/imx6q.dtsi, arch/arm/boot/dts/imx6qdl.dtsi and arch/arm/boot/dts/imx6qdl-sabresd.dtsi's ecspi node. grep spi in these three files to see how device tree works.

View solution in original post

15 Replies
5,460 Views
niklasmolin
Senior Contributor I

Hi Ben.

Did you manage to solve this problem?

Did you manage to figure out how the GPIO works for the SS pins?

I'm still a little bit confused how the pin is configured to be that specific GPIO (I couldn't find the GPIO in any of the IOMUX settings)?

Also when I try to enable multiple spi busses, I only get one spi device driver in my /dev directory.

Have you managed to do this?

Thanks,

Niklas

0 Kudos
5,460 Views
rathben
Contributor III

Hi Niklas,

Yes, I did get multiple busses working. I added something like this to my .dts file:

&ecspi2 {

  fsl,spi-num-chipselects = <2>;

  cs-gpios = <&gpio3 19 0>,<0>;

  pinctrl-names = "default";

  pinctrl-0 = <&pinctrl_ecspi2_1>;

  status = "okay";

    spidev@0x00 {

        compatible = "spidev";

        spi-max-frequency = <20000000>;

        reg = <0>;

    };

    spidev@0x01 {

        compatible = "spidev";

        spi-max-frequency = <20000000>;

        reg = <1>;

    };

};

&iomuxc {

...

...

    ecspi2 {

      pinctrl_ecspi2_1: ecspi2grp-1 {

            fsl,pins = <

                MX6SL_PAD_LCD_DAT10__ECSPI2_MISO 0x100b1

                MX6SL_PAD_LCD_DAT9__ECSPI2_MOSI 0x100b1

                MX6SL_PAD_LCD_DAT8__ECSPI2_SCLK 0x100b1

                MX6SL_PAD_HSIC_STROBE__GPIO3_IO20 0x100b1

                MX6SL_PAD_LCD_DAT11__ECSPI2_SS1 0x100b1

            >;

      };

    };


If you have still have problems getting GPIOs working, try the patch mentioned in this thread: Problems modifying device tree to blink an LED



0 Kudos
5,460 Views
carlosgallegos
Contributor III

Hi,


I have already modified the imx6sl-evk.dts file and I added the following code:


&ecspi2 {

  fsl,spi-num-chipselects = <2>;

  cs-gpios = <0>,<&gpio3 31 0>;

  pinctrl-names = "default";

  pinctrl-0 = <&pinctrl_ecspi2_1>;

  status = "okay";

   spidev@0x00 {

   compatible = "spidev";

   spi-max-frequency = <20000000>;

   reg = <0>;

   };

   spidev@0x01 {

   compatible = "spidev";

   spi-max-frequency = <20000000>;

   reg = <1>;

   };

};

&iomuxc {

...

...

   ecspi2 {

   pinctrl_ecspi2_1: ecspi2grp-1 {

   fsl,pins = <

   MX6SL_PAD_ECSPI2_MISO__ECSPI2_MISO 0x100b1

   MX6SL_PAD_ECSPI2_MOSI__ECSPI2_MOSI 0x100b1

   MX6SL_PAD_ECSPI2_SCLK__ECSPI2_SCLK 0x100b1

   MX6SL_PAD_ECSPI2_SS0__ECSPI2_SS0 0x100b1

   MX6SL_PAD_KEY_ROW3__GPIO3_IO31 0x100b1

   >;

   };

   };

And I can see /dev/spidev32765. 0 and /dev/spidev32765.1. With this I hope I can use the SPI2 that is in the LCD port (I have an adapter for this), but I cannot even see the clock when something is sent (or at least I assume that). The test I am doing is based on a program from the kernel files and you can find it in the reference [1].
0 Kudos
5,460 Views
carlosgallegos
Contributor III

Hi Ben,

I have started working with the SPI of the imx6slevk, so i'm extremely new at this. I have already modified the file imx6sl-evk.dts and I was expecting that after the reboot the device would appear under /dev/. Can you give me some advice at what should I do next, I am so lost at this. (sorry for my english).

0 Kudos
5,460 Views
saurabh206
Senior Contributor III

Hi,

Jose

Have you enabled CONFIG_SPI_SPIDEV=y in defconfig file?

Best Regards,

Saurabh

0 Kudos
5,460 Views
carlosgallegos
Contributor III

Hi Saurabh,

I went and edit the file /usr/src/kernel/arch/arm/configs/imx_v7_defconfig and added the line that you show me. Then I reboot the imx6 and still nothing in /dev. I forgot to mention and I don't know if it is important but I am working in L3.10.17.

Greetings,

JC.

0 Kudos
5,460 Views
saurabh206
Senior Contributor III

Hi,

JC

L3.10.17 process is same.

just make sure that your CONFIG_SPI_SPIDEV=7 is there in .config file.

Saurabh

0 Kudos
5,460 Views
carlosgallegos
Contributor III

Hi Saurabh,

I already modify my .config under /usr/src/kernel, but I still can see any spider under /dev. I don't know if i'm editing the wrong file under ../dts, I modified the file called imx6sl-evk.dts and added the code that was posted before. Also were can I find the pin nomenclature for the imx6slevk, maybe I am not writing the correct pin name.

0 Kudos
5,460 Views
niklasmolin
Senior Contributor I

Hi Ben.

Thanks for your response.

I managed to enable 2 chip selects on one SPI bus.

But when I add another SPI bus, then it won't show up in my /dev.

&ecspi1 {

  fsl,spi-num-chipselects = <2>;

  cs-gpios = <&gpio4 9 0>, <&gpio5 9 0>;

  pinctrl-names = "default";

  pinctrl-0 = <&pinctrl_ecspi1_2>;

  status = "okay";

        chip1: spidev@0 {

               compatible = "spidev";

               spi-max-frequency = <20000000>;

               reg = <0>;

        };

        chip2: spidev@1 {

               compatible = "spidev";

               spi-max-frequency = <20000000>;

               reg = <1>;

        };

};

&ecspi3 {

  fsl,spi-num-chipselects = <1>;

  cs-gpios = <&gpio4 24 0>;

  pinctrl-names = "default";

  pinctrl-0 = <&pinctrl_ecspi3_1>;

  status = "okay";

        chip3: spidev@0 {

               compatible = "spidev";

               spi-max-frequency = <20000000>;

               reg = <0>;

        };

};

All I see in my /dev are from ecspi1.

/Niklas

0 Kudos
5,460 Views
rathben
Contributor III

No, sorry I didn't try that yet.

0 Kudos
5,460 Views
niklasmolin
Senior Contributor I

Hi Ben.

I'm still working on this problem.

Another quick question.

I'm a little bit confused how to know which GPIO that should be sued for the select?

I saw in your example that to iomuxed:

                MX6SL_PAD_HSIC_STROBE__GPIO3_IO20 0x100b1

                MX6SL_PAD_LCD_DAT11__ECSPI2_SS1 0x100b1

and then for cs used, gpio3 19


Best regards,

Niklas

0 Kudos
5,460 Views
rathben
Contributor III

I use both. The <0> in cs-gpios definition means select the "native" chip select

0 Kudos
5,460 Views
niklasmolin
Senior Contributor I

Hi Ben.

Managed to get it to work.

Seems like I already had the right GPIO pin, but but connected to the wrong SS (first SS should be unconnected).

What I suspect with the multiple SPI busses, is that it gives them the same name.

For instance I have ecspi1 and ecspi3 and using spidev.

When I look in the /dev directory I get /dev/spi32766.0 (and spi32766.1 if I use multiple SS)

But it seems like it doesn't include the spi bus number in the name.

When I look at www.kernel.org/doc/Documentation/spi/spidev it should include B.C in the name, which it doesn't do in this case.

So I think that's why I "only" see one SPI bus (meaning ecspi interface number).

I'll continue to investigate this thing.

/Niklas

0 Kudos
5,460 Views
rathben
Contributor III

this topic is discussed a little here: https://community.freescale.com/thread/319336

0 Kudos
5,461 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Ben

     New kernel of L3.10 uses device tree, all those hardware related config will be passed from dtb to kernel, you can refer to arch/arm/boot/dts/imx6q.dtsi, arch/arm/boot/dts/imx6qdl.dtsi and arch/arm/boot/dts/imx6qdl-sabresd.dtsi's ecspi node. grep spi in these three files to see how device tree works.