How to enable internal RTC on Colibri iMX7 1GB

The external RTC module m41t0 is enabled by default in imx7-colibri-eval-v3.dtsi:

/* M41T0M6 real time clock on carrier board */
rtc: m41t0m6@68 {
    compatible = "st,m41t0";
    reg = <0x68>;
};

How can I enable the internal RTC module instead (besides removing the above lines)?
I cannot find any examples of enabling RTC in other iMX7 dtb files and what should be added in DTB.

I have found a solution but I am not sure if that’s correct.

By looking at the commit history of imx7d.dtsi, it seems the support for internal RTC of iMX7 was added around 2015 in this commit:

ARM: dts: imx7d: enable snvs rtc, onoffkey and power off,

but later in 2016 somehow removed in the process of refactoring imx7d.dtsi into imx7s.dtsi and imx7d.dtsi in these two commits:

ARM: dts: imx7d: use imx7s.dtsi as base device tree

ARM: dts: imx7d: recreate imx7d.dtsi with i.MX 7Dual specifics

I copied the relevant node from the old imx7d.dtsi into imx7s.dtsi just to see how things would play.

I am not sure if this the correct way of enabling RTC. For instance, does it have any effect on caam-snvs which is already present in the DTS?

--- a/arch/arm/boot/dts/imx7s.dtsi
+++ b/arch/arm/boot/dts/imx7s.dtsi
@@ -643,6 +643,34 @@
 				reg = <0x30370000 0x10000>;
 			};
 
+			snvs: snvs@30370000 {
+				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>;
+				};
+
+				snvs_poweroff: snvs-poweroff {
+					compatible = "syscon-poweroff";
+					regmap = <&snvs>;
+					offset = <0x38>;
+					mask = <0x60>;
+				};
+
+				snvs_pwrkey: snvs-powerkey {
+					compatible = "fsl,sec-v4.0-pwrkey";
+					regmap = <&snvs>;
+					interrupts = <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>;
+					linux,keycode = <KEY_POWER>;
+					wakeup-source;
+				};
+			};
+

Now the rtc device shows up in the dmesg logs (I haven’t tested if rtc would actually preserve time as the battery is not wired on our board yet):

root@colibri-imx7-emmc:~# dmesg | grep -i rtc
[    1.361285] snvs_rtc 30370000.snvs:snvs-rtc-lp: rtc core: registered 30370000.snvs:snvs- as rtc0
[    1.900347] snvs_rtc 30370000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01 00:00:00 UTC (0)
  1. Is this the correct way of enabling internal RTC?
  2. I suppose I can remove snvs_poweroff and snvs_pwrkey nodes. Is that correct?
  3. Is there any consideration/side-effect for this configuration?
  1. You are right, those nodes should have been copied to the imx7s.dtsi device tree. They used to be present in the 4.1 kernel as well
  2. You can but it seems not to be necessary as we did leave them also in the 4.1 kernel
  3. Since we used the same nodes also in the 4.1 kernel I would not expect any side effects.

Thanks for clarification.

We did some tests and I can confirm the internal RTC is now working as expected.

FWIW, I also pushed a fix onto our -next branch:
http://git.toradex.com/cgit/linux-toradex.git/log/?h=toradex_4.9-1.0.x-imx-next

hi @isaac @stefan.tx

I’m using the toradex_4.9-1.0.x-imx-next branch.

i’m getting error on rtc . Not able to get logs like you , shown above.

root@colibri-imx7-emmc:~# dmesg | grep -i rtc

[ 1.101602] rtc-ds1307: probe of 3-0068 failed with error -5

[ 1.107913] snvs_rtc 30370000.snvs:snvs-rtc-lp: rtc core: registered 30370000.snvs:snvs- as rtc1

[ 1.697822] hctosys: unable to open rtc device (rtc0)

Help me .

regards,
nikunj

hi @nikunjp26: Could you ask a new question, please? Thanks.