Skip to contentSkip to conversation

rtc: zynqmp: Enable crystal oscillator in initialization

PATCH In review Daniel Viaño 3 participants 3 messages Sep 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: zynqmp: Enable crystal oscillator in initialization

Enable the RTC crystal oscillator bit in the control register (RTC_CTRL, offset 0x40) during driver initialization.

Although the RTC_OSC_EN macro was defined when the driver was originally introduced, it was never asserted in xlnx_init_rtc(). On cold boots, after battery exhaustion, or on platforms where firmware does not pre-initialize RTC_CTRL, the oscillator remains disabled and the counter never ticks.

Asserting RTC_OSC_EN alongside RTC_BATT_EN ensures the oscillator starts without relying on bootloader initialization. Per the Zynq UltraScale+ TRM (UG1085), bit 24 (OSC_CNTRL) is a static level enable for the crystal inverter rather than an edge-triggered reset; re-asserting it when the oscillator is already running is a non-destructive no-op that does not glitch or reset the ticking counters.

Tested on Zynq UltraScale+ hardware, confirming that the counter freezes when RTC_OSC_EN is cleared, advances reliably once enabled, and is unaffected when re-asserted while running.

Fixes 11143c19eb57 ("rtc: add xilinx zynqmp rtc driver")
---
 drivers/rtc/rtc-zynqmp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/rtc/rtc-zynqmp.c +5 -2
index 5bcb7536e973..278705ec09f5 100644
@@ -167,9 +167,12 @@ static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev)
 {
 	u32 rtc_ctrl;
 
-	/* Enable RTC switch to battery when VCC_PSAUX is not available */
+	/*
+	 * Enable crystal oscillator, and enable RTC switch to battery
+	 * when VCC_PSAUX is not available.
+	 */
 	rtc_ctrl = readl(xrtcdev->reg_base + RTC_CTRL);
-	rtc_ctrl |= RTC_BATT_EN;
+	rtc_ctrl |= RTC_BATT_EN | RTC_OSC_EN;
 	writel(rtc_ctrl, xrtcdev->reg_base + RTC_CTRL);
 }
 
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines

Enable the RTC crystal oscillator bit in the control register (RTC_CTRL, offset 0x40) during driver initialization.

Although the RTC_OSC_EN macro was defined when the driver was originally introduced, it was never asserted in xlnx_init_rtc(). On cold boots, after battery exhaustion, or on platforms where firmware does not pre-initialize RTC_CTRL, the oscillator remains disabled and the counter never ticks.

Asserting RTC_OSC_EN alongside RTC_BATT_EN ensures the oscillator starts without relying on bootloader initialization. Per the Zynq UltraScale+ TRM (UG1085), bit 24 (OSC_CNTRL) is a static level enable for the crystal inverter rather than an edge-triggered reset; re-asserting it when the oscillator is already running is a non-destructive no-op that does not glitch or reset the ticking counters.

Quoted 7 lines

Tested on Zynq UltraScale+ hardware, confirming that the counter freezes when RTC_OSC_EN is cleared, advances reliably once enabled, and is unaffected when re-asserted while running.

Fixes 11143c19eb57 ("rtc: add xilinx zynqmp rtc driver")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Daniel Viaño
Quoted 32 lines · Daniel Viaño

Enable the RTC crystal oscillator bit in the control register (RTC_CTRL, offset 0x40) during driver initialization.

Although the RTC_OSC_EN macro was defined when the driver was originally introduced, it was never asserted in xlnx_init_rtc(). On cold boots, after battery exhaustion, or on platforms where firmware does not pre-initialize RTC_CTRL, the oscillator remains disabled and the counter never ticks.

Asserting RTC_OSC_EN alongside RTC_BATT_EN ensures the oscillator starts without relying on bootloader initialization. Per the Zynq UltraScale+ TRM (UG1085), bit 24 (OSC_CNTRL) is a static level enable for the crystal inverter rather than an edge-triggered reset; re-asserting it when the oscillator is already running is a non-destructive no-op that does not glitch or reset the ticking counters.

Tested on Zynq UltraScale+ hardware, confirming that the counter freezes when RTC_OSC_EN is cleared, advances reliably once enabled, and is unaffected when re-asserted while running.

Fixes 11143c19eb57 ("rtc: add xilinx zynqmp rtc driver")
---
 drivers/rtc/rtc-zynqmp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/rtc/rtc-zynqmp.c +0 -0
index 5bcb7536e973..278705ec09f5 100644
@@ -167,9 +167,12 @@ static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev)
 {

drivers/rtc/rtc-zynqmp.c static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev) · line 175

Quoted 10 lines
drivers/rtc/rtc-zynqmp.c +5 -2
 	u32 rtc_ctrl;
 
-	/* Enable RTC switch to battery when VCC_PSAUX is not available */
+	/*
+	 * Enable crystal oscillator, and enable RTC switch to battery
+	 * when VCC_PSAUX is not available.
+	 */
 	rtc_ctrl = readl(xrtcdev->reg_base + RTC_CTRL);
-	rtc_ctrl |= RTC_BATT_EN;
+	rtc_ctrl |= RTC_BATT_EN | RTC_OSC_EN;

No, you need to keep it disabled until you now the time is correct, that is in set_time and you need to test for it in read_time and return -EINVAL when it is not set.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com