how to make spi interface rtc function work for imx8mq maaxboard ?

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

how to make spi interface rtc function work for imx8mq maaxboard ?

Jump to solution
6,178 Views
gonewithwind-peter
Senior Contributor I

Hello everyone,

I want to add RTC function to imx8 maaxboard,

We used another board with SPI interface and rtc chip M41T93RMY6F on the motherboard.

I found that there is a kernel driver file for the chip M41T93RMY6F.

and so

problem:

1.

I need to configure the kernel to select spi rtc M41T93RMY6F support, right?

So after the kernel is configured, should spi rtc work properly?

2. After the kernel is started, how to configure or read/set the time or date in the user space?

3. Or directly use hwclock command to set/read rtc? No other settings or configurations are needed after the kernel is started?

4. Any user space application source code?

 

 

thank you very much.

Labels (1)
0 Kudos
1 Solution
5,936 Views
gonewithwind-peter
Senior Contributor I

hi

@igorpadykov 

step 1

I have  successfully added the rtc spi m41t39 in maaxbaord.

I have fixed the issue,
 
the spi cs pin is wrong in dts file
it should change to cs-gpios = <&gpio5 9 0 > ; from  cs-gpios = <&gpio5 13 0 > ;
 
I checked the imx8mq processor hardware datasheet
 
the ecsp1_ss0 is gpio5.io9 not io13
 
the gpio5.io13 is ecsp2_ss0 , wrong at here.
 
correct:
 

237                 pinctrl_ecspi1: ecspi1grp {

238                                 fsl,pins = <

239                                 MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9               0x16

240                                 MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI    0x16

241                                 MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO    0x16

242                                 MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK    0x1816

243                         >;

244                 };

 
 

&ecspi1{

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

    cs-gpios = <&gpio5 9 0 > ;

    pinctrl-names = "default";

    pinctrl-0 = <&pinctrl_ecspi1 >;

    status = "okay";

    #address-cells=<1>;

    #size-cells=<0>;

    rtc@0x00{

        #address-cellss=<1>;

        #size-cells=<1>;

        compatible = "rtc-m41t93";

        spi-max-frequency = <5000000>;

        reg = <0>;

    };

};

 

step 2. config m41t39  in kernel config.

NOT use module, need to build in  kernel. because if use module. every time after kernel start up, the module should insert and the time should reset again so that it seems does not work.

 

 

 

 

View solution in original post

0 Kudos
22 Replies
5,846 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

I got some doc from technical supporter:

and changed dts as below:

 

237                 pinctrl_ecspi1: ecspi1grp {

238                                 fsl,pins = <

239                                 MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9               0x16

240                                 MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI    0x16

241                                 MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO    0x16

242                                 MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK    0x1816

243                         >;

244                 };

&ecspi1{

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

    cs-gpios = <&gpio5 13 0 > ;

    pinctrl-names = "default";

    pinctrl-0 = <&pinctrl_ecspi1 >;

    status = "okay";

    #address-cells=<1>;

    #size-cells=<0>;

    rtc@0x00{

        #address-cellss=<1>;

        #size-cells=<1>;

        compatible = "rtc-m41t93";

        spi-max-frequency = <20000000>;

        reg = <0>;

    };

};

 

but error:

dmesg | grep rtc
[ 1.038658] imx-drm display-subsystem: bound imx-dcss-crtc.0 (ops dcss_crtc_ops)
[ 2.414482] rtc-m41t93 spi0.0: rtc core: registered rtc-m41t93 as rtc0
[ 2.422484] snvs_rtc 30370000.snvs:snvs-rtc-lp: rtc core: registered 30370000.snvs:snvs-rtc-lp as rtc1
[ 2.894506] rtc-m41t93 spi0.0: hctosys: unable to read the hardware clock

 

---

 

I am at sure how to register SPI rtc driver, in the driver file : the .name =rtc-m41t93.  but there is not "compatible"

any suggestions?

Thank you.

 

attached file is reference file from maxxbaord

 

 

 

0 Kudos
5,814 Views
igorpadykov
NXP Employee
NXP Employee

Hi jin1

 

nxp has special service for helping customers with software porting :

https://contact.nxp.com/new-prof-svcs-sw-tech

 

Best regards
igor

0 Kudos
5,739 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov  

Thank you.

I have submitted my requirement.

if not free,I will do it by myself

0 Kudos
5,950 Views
igorpadykov
NXP Employee
NXP Employee
0 Kudos
5,943 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

thank you very much.

 

another thing:

the new forum is not convenient than before. after you replied, I can not received in my email  new. before I could received replying every time.

0 Kudos
5,927 Views
gonewithwind-peter
Senior Contributor I

 

 

@igorpadykov 

I read your posted help doc.

it's not for Imx8mq.

I do not find simliar RTC node in imx8qm device tree in  maaxboard(em-sbc-imx8m.dts) or imx8mq-evk board(fsl-imx8mq-evk.dts)

I asked the technical supporter ,and get the  pin

J10 in board in maaxboard

      original GPIO   processor ball                      SPI  function                            (another ball No. from different Doc, maybe wrong)
19 GPIO3_IO06     G20                                    ECSSPI1_MOSI.                        A4
21 GPIO3_IO07.   J20                                      ECSSPI1_MISO                         B4
23 GPIO3_IO00    G19                                     ECSSPI1_SCLK                         D5
24 GPIO3_IO01    H19                                     ECS SPI1_SS0                            D4


I am another sure how to add SPI node in device tree.

any more help?


----
attched is em-sbc-imx8m.dts file

0 Kudos
5,926 Views
gonewithwind-peter
Senior Contributor I


attched is em-sbc-imx8m.dts file

0 Kudos
5,901 Views
igorpadykov
NXP Employee
NXP Employee

Hi jin1

 

i.MX8MQ has ecspi, i2c modules similar to i.MX6 series. So modifications

can be performed in the same way.

 

Best regards
igor

0 Kudos
5,886 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

I find a patch at here:

 

should be work for SPI? please have a look.

I am going to try.

Thank you 

 

https://patchwork.kernel.org/patch/10782611/

 

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 892063a7c26c..45b9d4a8b0da 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -26,6 +26,9 @@
serial1 = &uart2;
serial2 = &uart3;
serial3 = &uart4;
+ spi0 = &ecspi1;
+ spi1 = &ecspi2;
+ spi2 = &ecspi3;
};

ckil: clock-ckil {
@@ -381,6 +384,42 @@
#size-cells = <1>;
ranges = <0x30800000 0x30800000 0x400000>;

+ ecspi1: spi@30820000 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
+ reg = <0x0 0x30820000 0x0 0x10000>;
+ interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&clk IMX8MQ_CLK_ECSPI1_ROOT>,
+ <&clk IMX8MQ_CLK_ECSPI1_ROOT>;
+ clock-names = "ipg", "per";
+ status = "disabled";
+ };
+
+ ecspi2: spi@30830000 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
+ reg = <0x0 0x30830000 0x0 0x10000>;
+ interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&clk IMX8MQ_CLK_ECSPI2_ROOT>,
+ <&clk IMX8MQ_CLK_ECSPI2_ROOT>;
+ clock-names = "ipg", "per";
+ status = "disabled";
+ };
+
+ ecspi3: spi@30840000 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
+ reg = <0x0 0x30840000 0x0 0x10000>;
+ interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&clk IMX8MQ_CLK_ECSPI3_ROOT>,
+ <&clk IMX8MQ_CLK_ECSPI3_ROOT>;
+ clock-names = "ipg", "per";
+ status = "disabled";
+ };
+
uart1: serial@30860000 {
compatible = "fsl,imx8mq-uart",
"fsl,imx6q-uart";

0 Kudos
5,888 Views
gonewithwind-peter
Senior Contributor I

thank you very much.

I am trying to  add it

0 Kudos
5,879 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

 

add something like this: in fsl-imx8mq.dtsi

 

right?

 

784         ecspi1: ecspi@30820000 {

785                 compatible = "fsl,imx6ul-ecspi", "fsl,imx51-ecspi";

786                 reg = <0x0 0x30820000 0x0 0x10000>;

787                 interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;

788                 clocks = <&clk IMX8MQ_CLK_ECSPI1_ROOT>,

789                         <&clk IMX8MQ_CLK_ECSPI1_ROOT>;

790                 clock-names = "ipg", "per";

791                 status = "okay";

792                 rtc@68 {

793                                 compatible = "rtc-m41t93";

794                                                 reg = <0x68>;

795                         };      

796

797         };   

0 Kudos
5,865 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

test results using the rtc node as upper

 

-sh-4.4# dmesg | grep rtc
[ 1.043095] imx-drm display-subsystem: bound imx-dcss-crtc.0 (ops dcss_crtc_ops)
[ 2.045533] spi_master spi0: /ecspi@30820000/rtc@68 has no valid 'spi-max-frequency' property (-22)
[ 2.054696] spi_master spi0: Failed to create SPI device for /ecspi@30820000/rtc@68
[ 2.435732] snvs_rtc 30370000.snvs:snvs-rtc-lp: rtc core: registered 30370000.snvs:snvs-rtc-lp as rtc0
[ 2.883123] snvs_rtc 30370000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01 00:00:00 UTC (0)

0 Kudos
5,742 Views
gonewithwind-peter
Senior Contributor I

my dts for spi rtc

 

I used your reference file and  changed(add) dts  in em-sbc-imx8m.dts
as below:

 

237                 pinctrl_ecspi1: ecspi1grp {

238                                 fsl,pins = <

239                                 MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9               0x16

240                                 MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI    0x16

241                                 MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO    0x16

242                                 MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK    0x1816

243                         >;

244                 };

&ecspi1{

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

    cs-gpios = <&gpio5 13 0 > ;

    pinctrl-names = "default";

    pinctrl-0 = <&pinctrl_ecspi1 >;

    status = "okay";

    #address-cells=<1>;

    #size-cells=<0>;

    rtc@0x00{

        #address-cellss=<1>;

        #size-cells=<1>;

        compatible = "rtc-m41t93";

        spi-max-frequency = <20000000>;

        reg = <0>;

    };

};

 

but error:

dmesg | grep rtc
[ 1.038658] imx-drm display-subsystem: bound imx-dcss-crtc.0 (ops dcss_crtc_ops)
[ 2.414482] rtc-m41t93 spi0.0: rtc core: registered rtc-m41t93 as rtc0
[ 2.422484] snvs_rtc 30370000.snvs:snvs-rtc-lp: rtc core: registered 30370000.snvs:snvs-rtc-lp as rtc1
[ 2.894506] rtc-m41t93 spi0.0: hctosys: unable to read the hardware clock

 

I added some debug info in driver rtc-m41t93.c, the below is the debug ingo output.
I looks like the driver works. when it writes the data, it seems no error. but after writing, the reading is wrong.
when I  use hwclock -r     ,the error is hwclock: RTC_RD_TIME: Invalid argument 
 
I worry about the pins for spi1 in   pinctrl_ecspi1: ecspi1grp are wrong, 
are you make sure the pins are correct?
 
when I ckeck cat /proc/interrupts | grep spi
I find the interrups counts are increasing,please see below. it seems the driver  works but data is wrong
 
 
any suggestions?
thank you.
 
-----
 
-sh-4.4# insmod rtc-m41t93.ko                                                                                                                            
[ 3447.986508] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=0, hours=0, mday=0, mon=-1, year=100, wday=-1                                              
[ 3447.996096] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
[ 3448.000948] rtc-m41t93 spi0.0: rtc core: registered rtc-m41t93 as rtc0                                                                                
[ 3448.007772] rtc-m41t93 spi0.0: jin  test3 probe                                                                                                      
-sh-4.4# date --set="20201015 14:32"                                                                                                                    
Thu Oct 15 14:32:00 -05 2020                                                                                                                            
-sh-4.4# hwclock --systohc --utc                                                                                                                        
[ 3600.903392] rtc-m41t93 spi0.0: jin test1 write secs=17, mins=32, hours=19, mday=15, mon=9, year=120, wday=4                                          
-sh-4.4# [ 3600.959304] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=0, hours=0, mday=0, mon=-1, year=100, wday=-1                                    
[ 3600.973839] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
                                                                                                                                                         
-sh-4.4# hwclock --systohc --utc                                                                                                                        
[ 3613.852979] rtc-m41t93 spi0.0: jin test1 write secs=30, mins=32, hours=19, mday=15, mon=9, year=120, wday=4                                          
[ 3613.864034] rtc-m41t93 spi0.0: jin test2 read secs=3, mins=0, hours=10, mday=0, mon=-1, year=100, wday=-1                                            
[ 3613.873731] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
-sh-4.4# hwclock --systohc --utc                                                                                                                        
[ 3616.232812] rtc-m41t93 spi0.0: jin test1 write secs=32, mins=32, hours=19, mday=15, mon=9, year=120, wday=4                                          
-sh-4.4# [ 3616.244620] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=40, hours=0, mday=0, mon=-1, year=104, wday=-1                                    
[ 3616.254458] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
hwclock --systohc --utc                                                                                                                                  
[ 3625.690010] rtc-m41t93 spi0.0: jin test1 write secs=41, mins=32, hours=19, mday=15, mon=9, year=120, wday=4                                          
-sh-4.4# [ 3625.700937] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=0, hours=0, mday=0, mon=-1, year=100, wday=-1                                    
[ 3625.711095] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
                                                                                                                                                         
-sh-4.4# hwclock -r                                                                                                                                      
[ 3660.309908] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=4, hours=0, mday=0, mon=9, year=100, wday=2                                                
[ 3660.319503] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
hwclock: RTC_RD_TIME: Invalid argument                                                                                                                  
-sh-4.4# hwclock --systohc --utc                                                                                                                        
[ 3868.465926] rtc-m41t93 spi0.0: jin test1 write secs=44, mins=36, hours=19, mday=15, mon=9, year=120, wday=4                                          
-sh-4.4# [ 3868.477142] rtc-m41t93 spi0.0: jin test2 read secs=0, mins=0, hours=0, mday=40, mon=-1, year=340, wday=-1                                    
[ 3868.487247] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
                                                                                                                                                         
-sh-4.4# date                                                                                                                                            
Thu Oct 15 14:36:49 -05 2020  
 
 
----
 
 
 cat /proc/interrupts | grep spi                                                                                                                
 39:         51          0          0          0  GPC-PSCI  31 Edge      30820000.ecspi                                                                  
-sh-4.4# hwclock -w                                                                                                                                      
[  431.303151] rtc-m41t93 spi0.0: jin test write secs=40, mins=13, hours=13, mday=28, mon=8, year=120, wday=1                                            
-sh-4.4# [  431.314511] rtc-m41t93 spi0.0: jin test read secs=0, mins=0, hours=0, mday=0, mon=-1, year=100, wday=-1                                      
[  431.324597] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
                                                                                                                                                         
-sh-4.4# cat /proc/interrupts | grep spi                                                                                                                
 39:         84          0          0          0  GPC-PSCI  31 Edge      30820000.ecspi                                                                  
-sh-4.4# hwclock -r                                                                                                                                      
[  442.794300] rtc-m41t93 spi0.0: jin test read secs=80, mins=0, hours=0, mday=40, mon=-1, year=200, wday=-1                                            
[  442.803954] rtc-m41t93 spi0.0: jin test ret=0                                                                                                        
hwclock: RTC_RD_TIME: Invalid argument                                                                                                                  
-sh-4.4#                                                                                                                                                
-sh-4.4# cat /proc/interrupts | grep spi                                                                                                                
 39:         96          0          0          0  GPC-PSCI  31 Edge      30820000.ecspi    

 

 

0 Kudos
5,937 Views
gonewithwind-peter
Senior Contributor I

hi

@igorpadykov 

step 1

I have  successfully added the rtc spi m41t39 in maaxbaord.

I have fixed the issue,
 
the spi cs pin is wrong in dts file
it should change to cs-gpios = <&gpio5 9 0 > ; from  cs-gpios = <&gpio5 13 0 > ;
 
I checked the imx8mq processor hardware datasheet
 
the ecsp1_ss0 is gpio5.io9 not io13
 
the gpio5.io13 is ecsp2_ss0 , wrong at here.
 
correct:
 

237                 pinctrl_ecspi1: ecspi1grp {

238                                 fsl,pins = <

239                                 MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9               0x16

240                                 MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI    0x16

241                                 MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO    0x16

242                                 MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK    0x1816

243                         >;

244                 };

 
 

&ecspi1{

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

    cs-gpios = <&gpio5 9 0 > ;

    pinctrl-names = "default";

    pinctrl-0 = <&pinctrl_ecspi1 >;

    status = "okay";

    #address-cells=<1>;

    #size-cells=<0>;

    rtc@0x00{

        #address-cellss=<1>;

        #size-cells=<1>;

        compatible = "rtc-m41t93";

        spi-max-frequency = <5000000>;

        reg = <0>;

    };

};

 

step 2. config m41t39  in kernel config.

NOT use module, need to build in  kernel. because if use module. every time after kernel start up, the module should insert and the time should reset again so that it seems does not work.

 

 

 

 

0 Kudos
3,487 Views
sijinahi
Contributor I

Can you explain how to edit the the DTS file

0 Kudos
3,477 Views
gonewithwind-peter
Senior Contributor I

@sijinahi 

see attached  001-spi-real-time-M41T93.patch  patch file or following,you can compare with the original kernel file. you will get it how to edit the the DTS file.

the original kernel file is here https://github.com/Avnet/meta-maaxboard   zeus branch(master branch) for maaxboard. after you bitbake building, you can get the kernel source code. 

or here ,the kernel source code (just the default branch) https://github.com/Avnet/linux-imx

 

001-spi-real-time-M41T93.patch

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 5943d2ed653d..239271911429 100755
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -826,7 +826,7 @@
ecspi1: spi@30820000 {
#address-cells = <1>;
#size-cells = <0>;
- compatible = "fsl,imx8mq-ecspi", "fsl,imx6ul-ecspi";
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
reg = <0x30820000 0x10000>;
interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk IMX8MQ_CLK_ECSPI1_ROOT>,
@@ -838,7 +838,7 @@
ecspi2: spi@30830000 {
#address-cells = <1>;
#size-cells = <0>;
- compatible = "fsl,imx8mq-ecspi", "fsl,imx6ul-ecspi";
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
reg = <0x30830000 0x10000>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk IMX8MQ_CLK_ECSPI2_ROOT>,
@@ -850,7 +850,7 @@
ecspi3: spi@30840000 {
#address-cells = <1>;
#size-cells = <0>;
- compatible = "fsl,imx8mq-ecspi", "fsl,imx6ul-ecspi";
+ compatible = "fsl,imx8mq-ecspi", "fsl,imx51-ecspi";
reg = <0x30840000 0x10000>;
interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk IMX8MQ_CLK_ECSPI3_ROOT>,
diff --git a/arch/arm64/boot/dts/freescale/maaxboard-extended-gpio.dtsi b/arch/arm64/boot/dts/freescale/maaxboard-extended-gpio.dtsi
index 25c84d58bf74..61202110b358 100755
--- a/arch/arm64/boot/dts/freescale/maaxboard-extended-gpio.dtsi
+++ b/arch/arm64/boot/dts/freescale/maaxboard-extended-gpio.dtsi
@@ -37,10 +37,10 @@

pinctrl_ecspi1: ecspi1grp {
fsl,pins = <
- MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9 0x16
- MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI 0x16
- MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO 0x16
- MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK 0x1816
+ MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9 0x19
+ MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI 0x19
+ MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO 0x19
+ MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK 0x19
>;
};

@@ -89,11 +89,23 @@
};

&ecspi1{
- fsl,spi-num-chipselects = < 1 >;
- cs-gpios = <&gpio5 13 0 > ;
pinctrl-names = "default";
- pinctrl-0 = <&pinctrl_ecspi1 >;
+ pinctrl-0 = <&pinctrl_ecspi1>;
+ fsl,spi-num-chipselects = <1>;
+ cs-gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>;
status = "okay";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ rtc@0 {
+ compatible = "rtc-m41t93";
+ reg = <0>;
+ spi-max-frequency = <5000000>;
+ };
+};
+
+&snvs_rtc {
+ status = "disabled";
};

&i2c2 {
diff --git a/arch/arm64/configs/maaxboard_defconfig b/arch/arm64/configs/maaxboard_defconfig
index a89ebacf02f7..0a796e196774 100755
--- a/arch/arm64/configs/maaxboard_defconfig
+++ b/arch/arm64/configs/maaxboard_defconfig
@@ -659,6 +659,7 @@ CONFIG_EDAC=y
CONFIG_EDAC_GHES=y
CONFIG_EDAC_SYNOPSYS=y
CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_M41T93=y
CONFIG_RTC_DRV_DS1307=y
CONFIG_RTC_DRV_MAX77686=y
CONFIG_RTC_DRV_RK808=m
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 09ae4282ad56..a145004f649b 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -639,7 +639,6 @@ static struct sdma_driver_data sdma_imx8mq = {
.num_events = 48,
.script_addrs = &sdma_script_imx7d,
.check_ratio = 1,
- .ecspi_fixed = true,
};

static struct sdma_driver_data sdma_imx8mp = {
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 39870bc38e40..f608f89f45cd 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -888,12 +888,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
controller->bus_num = pdev->id;
controller->slave_abort = fsl_lpspi_slave_abort;

- ret = devm_spi_register_controller(&pdev->dev, controller);
- if (ret < 0) {
- dev_err(&pdev->dev, "spi_register_controller error.\n");
- goto out_controller_put;
- }
-
if (!fsl_lpspi->is_slave) {
controller->cs_gpios = devm_kzalloc(&controller->dev,
sizeof(int) * controller->num_chipselect, GFP_KERNEL);
@@ -901,6 +895,11 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
for (i = 0; i < controller->num_chipselect; i++) {
int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);

+ if (cs_gpio == -EPROBE_DEFER) {
+ ret = -EPROBE_DEFER;
+ goto out_controller_put;
+ }
+
if (!gpio_is_valid(cs_gpio) && lpspi_platform_info)
cs_gpio = lpspi_platform_info->chipselect[i];

@@ -971,13 +970,30 @@ static int fsl_lpspi_probe(struct platform_device *pdev)

ret = fsl_lpspi_dma_init(&pdev->dev, fsl_lpspi, controller);
if (ret == -EPROBE_DEFER)
- goto out_controller_put;
-
+ goto err_disable_runtime_pm;
if (ret < 0)
dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret);
+ else
+ /* disable LPSPI module IRQ when enable DMA mode successfully,
+ * to prevent the unexpected LPSPI module IRQ events*/
+ disable_irq(irq);
+
+ ret = devm_spi_register_controller(&pdev->dev, controller);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "spi_register_controller error.\n");
+ goto err_disable_runtime_pm;
+ }
+
+ pm_runtime_mark_last_busy(fsl_lpspi->dev);
+ pm_runtime_put_autosuspend(fsl_lpspi->dev);

return 0;

+err_disable_runtime_pm:
+ pm_runtime_dont_use_autosuspend(fsl_lpspi->dev);
+ pm_runtime_put_sync(fsl_lpspi->dev);
+ pm_runtime_disable(fsl_lpspi->dev);
+
out_controller_put:
spi_controller_put(controller);

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 91e32291c44e..0128e33eb5bc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1775,8 +1775,13 @@ static int spi_imx_probe(struct platform_device *pdev)
/* Request GPIO CS lines, if any */
if (!spi_imx->slave_mode && master->cs_gpios) {
for (i = 0; i < master->num_chipselect; i++) {
- if (!gpio_is_valid(master->cs_gpios[i]))
+ if (!gpio_is_valid(master->cs_gpios[i])) {
+ if (master->cs_gpios[i] == -EPROBE_DEFER) {
+ ret = -EPROBE_DEFER;
+ goto out_spi_bitbang;
+ }
continue;
+ }

ret = devm_gpio_request(&pdev->dev,
master->cs_gpios[i],

3,018 Views
sijinahi
Contributor I

Hi 
I in my case i am trying to just access the spi module that is connected to maaxboard mini. 

sijinahi_0-1679549832922.png

spidev is not getting listed in /dev
i have added the device tree for it as follows
&ecspi1 {
fsl,spi-num-chipselects = <4>;
cs-gpios = <&gpio5 9 0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_ecspi1>;
status = "okay";
};
after this 
dmesg |grep spi 

[ 1.392663] spi_imx 30820000.spi: probed

Kernel configuration:
CONFIG_SPI_IMX=y
CONFIG_SPI=y compiled into the kernel,
CONFIG_SPI=m compile as a loadable module

both tried
CONFIG_SPI=y  nothing was visual but spi is expected to be supported from kernel

in the second case spidev.ko was found in the 
cd /lib/modules/5.4.24-2.1.0+gb8e6bda2e31d/kernel/drivers/spi path

still /dev/ doesnot list spidev0.0... or any spidev

i tried to manually mknod the spidev1.0 and spidev1.1 and try to open the file.. this gave cant open error.

what is it that i am missing

@gonewithwind-peter 
@igorpadykov 

0 Kudos
3,003 Views
gonewithwind-peter
Senior Contributor I

@sijinahi 

I checked my maaxboard mini zeus branch (linux 5.4), I think spi should work well ,do not need to patch it. for my rtc spi chip ,I only add my rtc chip there, I think the default spi  with default kernel config should work.  what chip do you want to connect the spi1 ? 

I see you patched something at  & ecspi 1, but I see my patch for my rtc chip, I never modified there. I keep there as default.

----

 i have added the device tree for it as follows
&ecspi1 {
fsl,spi-num-chipselects = <4>;
cs-gpios = <&gpio5 9 0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_ecspi1>;
status = "okay";
};

-----

 

see my attached file as  below:

 

cat 002-rtc-m41t93.patch
diff -Naur ori/arch/arm64/boot/dts/freescale/imx8mm.dtsi patch-2/arch/arm64/boot/dts/freescale/imx8mm.dtsi
--- ori/arch/arm64/boot/dts/freescale/imx8mm.dtsi 2021-09-03 10:47:15.651358472 -0400
+++ patch-2/arch/arm64/boot/dts/freescale/imx8mm.dtsi 2021-09-03 14:25:44.549574600 -0400
@@ -704,15 +704,6 @@
compatible = "fsl,sec-v4.0-mon","syscon", "simple-mfd";
reg = <0x30370000 0x10000>;

- snvs_rtc: snvs-rtc-lp {
- compatible = "fsl,sec-v4.0-mon-rtc-lp";
- regmap = <&snvs>;
- offset = <0x34>;
- interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>,
- <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
- clocks = <&clk IMX8MM_CLK_SNVS_ROOT>;
- clock-names = "snvs-rtc";
- };

snvs_pwrkey: snvs-powerkey {
compatible = "fsl,sec-v4.0-pwrkey";
@@ -850,7 +841,7 @@
clock-names = "ipg", "per";
dmas = <&sdma1 0 7 1>, <&sdma1 1 7 2>;
dma-names = "rx", "tx";
- status = "disabled";
+ status = "enabled";
};

ecspi2: spi@30830000 {
diff -Naur ori/arch/arm64/boot/dts/freescale/maaxboard-mini-extended-gpio.dtsi patch-2/arch/arm64/boot/dts/freescale/maaxboard-mini-extended-gpio.dtsi
--- ori/arch/arm64/boot/dts/freescale/maaxboard-mini-extended-gpio.dtsi 2021-09-03 10:46:33.255550169 -0400
+++ patch-2/arch/arm64/boot/dts/freescale/maaxboard-mini-extended-gpio.dtsi 2021-09-03 14:28:33.752814424 -0400
@@ -101,6 +101,13 @@
pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1_cs>;
cs-gpios = <&gpio5 9 0 > ;
status = "okay";
+rtc@0{
+ #address-cellss=<1>;
+ #size-cells=<1>;
+ compatible = "rtc-m41t93";
+ spi-max-frequency = <5000000>;
+ reg = <0>;
+ };
};

0 Kudos
2,981 Views
sijinahi
Contributor I

@igorpadykov 

@gonewithwind-peter 

Maaxboard mini is connected to TMC429 via spi.

 

0 Kudos
2,961 Views
gonewithwind-peter
Senior Contributor I

@sijinahi 

I used bitbake -c menuconfig linux-imx    to check the kernel config  , I can not find the keyword "TMC429" . that means there is no TMC429 (motor chip) driver in  the kernel  to support it.

it is not like my rtc chip rtc-m41t93  , I can find it and can find  rtc-m41t93.c driver so that I enabled it in kernel and then add my patch in dtb,after that my rtc can work .

 

so you can not use my solution to connect the TMC429 to spi .that means you can not patch like mine: 

+rtc@0{
+ #address-cellss=<1>;
+ #size-cells=<1>;
+ compatible = "rtc-m41t93";
+ spi-max-frequency = <5000000>;
+ reg = <0>;
+ };
};

so that you can not use the layer driver (like my rtc) to operate your  TMC429. you need to use more lower spi driver (generic driver) to operate it. 

so I suggest ,you keep all the spi as default in DTB (device tree) because my rtc chip works well with the default lower spi driver  and I never modified(patched) it. so try to find how to directly operate the lower spi driver.

sorry, I have no more experience to operate it, please search online  or some one else can help you here.

Maybe you can user  space driver (normal  linux C code) not kernel driver to operate spi  . because it seems  there is no kernel driver  after checking with   bitbake -c menuconfig linux-imx 

 

I searched online with "how to directly read /write spi in linux user space"

results:

The most popular way for SPI read/write in user space is through character device /dev/spidev but this way gives you only half-duplex access. An other way for SPI read/write in user space is through ioctl SPI_IOC_MESSAGE(N) request that gives you full-duplex access.

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/680213/linux-am3352-spi-co...

https://stackoverflow.com/questions/36626214/can-i-select-on-a-dev-spidev-file-descriptor

 

Maybe it can hep you

Tags (1)
0 Kudos