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

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jump to solution
467 Views
Contributor IV

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
225 Views
Contributor IV

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
15 Replies
350 Views
Contributor IV

@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
317 Views
NXP TechSupport
NXP TechSupport

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
243 Views
Contributor IV

@igorpadykov  

Thank you.

I have submitted my requirement.

if not free,I will do it by myself

0 Kudos
454 Views
NXP TechSupport
NXP TechSupport
0 Kudos
447 Views
Contributor IV

@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
431 Views
Contributor IV

 

 

@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
430 Views
Contributor IV


attched is em-sbc-imx8m.dts file

0 Kudos
405 Views
NXP TechSupport
NXP TechSupport

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
390 Views
Contributor IV

@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
392 Views
Contributor IV

thank you very much.

I am trying to  add it

0 Kudos
383 Views
Contributor IV

@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
369 Views
Contributor IV

@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
246 Views
Contributor IV

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
226 Views
Contributor IV

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
59 Views
Contributor IV

@igorpadykov 

 

Do you know, is there a way to get status of the RTC? for example to know if battery needs to be replaced?
 
I mean how to read RTC Battery low warning in user space app code?
Thank you
 
0 Kudos