IMXRT1050 SPI and Linux Device Tree

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

IMXRT1050 SPI and Linux Device Tree

1,805 Views
wre
Contributor III

Hello,

I am new to the device tree aspect of linux (4.5.0).  We are using an imxrt1050 on a board similar to the IMXRT105X_NXPEVK and trying to add an external RTC via SPI.  My Kinetis experience suggests that there are clock gating registers that need to be set, pin mux modes, chip select identification, etc. that needs to be done. 

- What are the proper device tree entries that need to be added for this part to complete the device tree? 

- What goes in the clock section to get the LPSPI_CLK_ROOT going? Or does the spi-fsl-lpspi driver take care of that?

- What goes in the SOC section (iomuxc? gpio? lpspi?)?

- What about pinctrl for the iomuxc?  How are the chip selects handled versus the SDI, SDO and SCK pins?

- What else am I missing?

Here are snippets of the DT as I have it so far:

/ {
   model = "NXP IMXRT1050 board";
   compatible = "nxp,imxrt1050-evk", "nxp,imxrt105x";

   (other stuff)

   soc {
      aips0: aips-bus@40000000 {
         compatible = "fsl,aips-bus", "simple-bus";
         #address-cells = <1>;
         size-cells = <1>;
         ranges;

     (some gpiox stuff I don't fully understand)

     (other stuff)

      lpspi3: lpspi@4039c000 {
         compatible = "fsl,imx7ulp-spi";
         reg = <0x4039c000 0x4000>;
         interrupts = <34>;
         clocks = <&ipg_clk>;
         clock-names = "ipg";
      };

   };

};

#define MXRT105X_PAD_CFG_SPI_CS    0xA0B0
#define MXRT105X_PAD_CFG_SPI      0xB0    

&iomuxc {

   (other stuff)

   pinctrl_lpspi3_cs: lpspi3_cs_grp {
      fsl,pins = <
         MXRT105X_PAD_AD_B1_12_LPSPI3_PCS0 MXRT105X_PAD_CFG_SPI_CS
      >;
   };

   pinctrl_lpspi3: lpspi3grp {
      fsl,pins = <
         MXRT105X_PAD_AD_B1_13_LPSPI3_SDI MXRT105X_PAD_CFG_SPI
         MXRT105X_PAD_AD_B1_14_LPSPI3_SDO MXRT105X_PAD_CFG_SPI
         MXRT105X_PAD_AD_B1_15_LPSPI3_SCK MXRT105X_PAD_CFG_SPI
      >;
   };

};

&lpspi3 {
        fsl,spi-num-chipselects = <1>;
         pinctrl-names = "default";
         pinctrl-0 = <&pinctrl_lpspi3 &pinctrl_lpspi3_cs>;
         status = "okay";
         #address-cells = <1>;
         #size-cells = <0>;
   mcp795: rtc@0 {
      compatible = "maxim,mcp795";
      spi-max-frequency = <500000>;
      #address-cells = <1>;
      #size-cells = <0>;
      reg = <0>;
   };
};

The SPI master is found and loaded.  The RTC driver is also found and loaded but the RTC does not yet respond to the SPI requests.  By faking the data returned by the RTC driver, from a system point of view, everything looks correct.  /dev/rtc0 exists it just doesn't talk.  I am in the process of trying to get scope probes on some of the lines to see if they are wiggling but I expect there is more to be done in the device tree than I presently understand.  Any help would be appreciated and hopefully answers here will help many more people climbing the learning curve of the imxrt1050 and linux device trees.

Labels (1)
0 Kudos
3 Replies

601 Views
nicolasmuratore
Contributor III

Hi wre, hope you are doing well, did you solve your problem with DT and SPI interface?

I'm using imxrt1060 with Linux and I'm facing some problems trying to configure and use an SPI interface using a DT.

My DT SPI interface configuration is almost identical to the yours, with the diference that I'm trying to use the LPSPI4 intead of LPSPI3, but the registers and parameters are the same for imxrt1050 or 1060:

Aliases:
{
.
.
spi4=&lpspi4
 
}
.
.
.
 
lpspi4: lpspi@403a0000 {
compatible = "fsl,imx7ulp-spi";
reg = <0x403a0000 0x4000>;
interrupts = <35>;
clocks = <&ipg_clk>;
clocks-names = "ipg";
status = "disabled";
};
.
.
.
pinctrl_lpspi4_cs: lpspi4_cs_grp {
      fsl,pins = <
          MXRT105X_PAD_B0_00_LPSPI4_PCS0 MXRT105X_PAD_CFG_SPI_CS
      >;
    };
 
    pinctrl_lpspi4: lpspi4grp {
      fsl,pins = <
          MXRT105X_PAD_B0_01_LPSPI4_SDI MXRT105X_PAD_CFG_SPI
          MXRT105X_PAD_B0_02_LPSPI4_SDO MXRT105X_PAD_CFG_SPI
          MXRT105X_PAD_B0_03_LPSPI4_SCK MXRT105X_PAD_CFG_SPI
      >;
    };
 
 
};
 
&lpspi4 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lpspi4 &pinctrl_lpspi4_cs>;
status = "okay";
 
flash: m25p80@0 {      
status = "okay";
compatible = "spansion,m25p80"; /*spansion, spi-nor,.... not working*/
spi-max-frequency = <25000000>;
reg = <0>;
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "spi_flash_part0";
reg = <0x0 0x100000>;
};
 
parition@1 {
label = "spi_flash_part1";
reg = <0x100000 0x300000>;
};
};

But in my case, I can't get even that the kernel recognize the SPI master controller, I always get the same error on startup:   "fsl_lpspi: probe of 403a0000.lpspi failed with error -2" 

Maybe you have found a solution for your proyect that could help me.

Many thanks. 

0 Kudos

1,465 Views
wre
Contributor III

@fangfang, thank you, I have seen that document.  I can understand what needs to be set up from the processor point of view but what is not clear is how to properly accomplish those things through the device tree nodes.

0 Kudos

1,465 Views
fangfang
NXP TechSupport
NXP TechSupport

Hello,

 I'd recommend to the document(How to configure LPSPI clock) as the link. URL:

https://community.nxp.com/docs/DOC-342717.

Hope it help you.

Best regrads

0 Kudos