How to use SPI on Colibri iMX7d 1GB

Hi Guys,
I want to use all 4 SPI channels and configure SPI data as interrupt.
I modified below code and can see:

&ecspi3 {
    status = "okay";

mcp2515: can@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";
};
};

root@colibri-imx7-emmc:/tmp# dmesg | grep spi
[    1.115033] spi_imx 30840000.ecspi: dma setup error -19, use pio
[    1.124327] spi_imx 30840000.ecspi: probed
root@colibri-imx7-emmc:/tmp# ls /dev/spi*
/dev/spidev2.0

I want to know:

  1. How to enable other 3 SPI drivers
  2. Where to find details on HW pins or which pins shall I use to connect slave device

HI @neeraj.verma

I want to use all 4 SPI channels and configure SPI data as interrupt

What exactly do you mean with configure SPI data as interrupt? You can enable the interrupt on the chip select line.

  1. How to enable other 3 SPI drivers

You just to do the create the SPI nodes and do the correct muxing of the Pins as described here.

Where to find details on HW pins or which pins shall I use to connect slave device

Please check the datasheet of the module.

Best regards,
Jaski

Hi @jaski.tx
Thanks for the reply. Can I use CS as interrupt as well (one pin having two functions output and interrupt)?

I only see one instance of spi3, how do I create another:
Ex: spidev1: spidev@1

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

I really don’t see which pins I should use for another SPI node.

Hi @neeraj.verma

Thanks for the reply.

You are welcome.

Can I use CS as interrupt as well (one pin having two functions output and interrupt)?

CS is an output and interrupt an output. So I don’t think, this will be possible, but you can connect the chip select to another SODIMM Pin over the carrier board and the other SODIMM Pin can be defined as Interrupt.

For having more spi Node, first you need to change in the escpi3 node the following parameters in the devicetree on the module layer:

  • number of chipselects,

  • Gpios to use for chipselect

  • change pinctrl-0 referencing node to do the correct pinmuxing of the chip select pins

    /* Colibri SPI */
    &ecspi3 {
    fsl,spi-num-chipselects = <1>;
    cs-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>;
    pinctrl-names = “default”;
    pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs>;
    On carrier board layer, you need to define the differents spidev3.x under ecspi3 and change the property reg = , where x comes from the chipselect used.

Best regards,
Jaski

Hi Jaski (@jaski.tx ),
I just probed SODIMM_86 pin on board while reading SPI, I don’t see CS is LOW. (first step). Could you please help me on this to understand what is wrong?

&ecspi3 {
status = "okay";

mcp2515: can@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";
};

};
&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: ecspi3-grp {
    fsl,pins = <
        MX7D_PAD_I2C1_SCL__ECSPI3_MISO      0x2
        MX7D_PAD_I2C1_SDA__ECSPI3_MOSI      0x2
        MX7D_PAD_I2C2_SCL__ECSPI3_SCLK      0x2
    >;
};

pinctrl_ecspi3_cs: ecspi3-cs-grp {
    fsl,pins = <
        MX7D_PAD_I2C2_SDA__GPIO4_IO11       0x14
    >;
};

Attaching dmesg log and SPI code for you to have a quick look.
link text

hi @neeraj.verma

You are having IoMux errors in the dmesg log. Could you correct them and check again, if SPI is working.

Thanks @jaski.tx for pointing out.
actually that pin is used for UARTxx, I used another pin for CS and my code works now.
Sharing correct code for users:
&ecspi3 {

mcp2515: can@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 = <10000000>;
    /*spi-max-frequency = <23000000>;*/
    status = "okay";
};

};

&ecspi3 {
status = “okay”;
fsl,spi-num-chipselects = <2>;
cs-gpios = <&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_SD1_DATA3__GPIO5_IO8       0x14
    >;
};

pinctrl_ecspi3: ecspi3-grp {
    fsl,pins = <
        MX7D_PAD_I2C1_SCL__ECSPI3_MISO      0x2
        MX7D_PAD_I2C1_SDA__ECSPI3_MOSI      0x2
        MX7D_PAD_I2C2_SCL__ECSPI3_SCLK      0x2
    >;
};

Perfect that it works. Thanks for the feedback.