]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtc: rzn1: Disable controller before initialization
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Mon, 26 May 2025 09:58:03 +0000 (11:58 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Sun, 1 Jun 2025 21:53:02 +0000 (23:53 +0200)
Datasheet says that the controller must be disabled before setting up
either SUBU or SCMP. This did not matter so far because the driver only
supported SUBU which was the default, too. It is good practice to follow
datasheet recommendations, though. It will also be needed because SCMP
mode will be added in a later patch.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20250526095801.35781-7-wsa+renesas@sang-engineering.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-rzn1.c

index 3c2861983ff1e2de35f0027d5441e503b5f79f40..7777df1e34266432eb82ffc2fc0299ba7ae42689 100644 (file)
@@ -25,6 +25,7 @@
 #define   RZN1_RTC_CTL0_SLSB_SUBU 0
 #define   RZN1_RTC_CTL0_SLSB_SCMP BIT(4)
 #define   RZN1_RTC_CTL0_AMPM BIT(5)
+#define   RZN1_RTC_CTL0_CEST BIT(6)
 #define   RZN1_RTC_CTL0_CE BIT(7)
 
 #define RZN1_RTC_CTL1 0x04
@@ -369,6 +370,7 @@ static const struct rtc_class_ops rzn1_rtc_ops = {
 static int rzn1_rtc_probe(struct platform_device *pdev)
 {
        struct rzn1_rtc *rtc;
+       u32 val;
        int irq;
        int ret;
 
@@ -406,6 +408,14 @@ static int rzn1_rtc_probe(struct platform_device *pdev)
         * Ensure the clock counter is enabled.
         * Set 24-hour mode and possible oscillator offset compensation in SUBU mode.
         */
+       val = readl(rtc->base + RZN1_RTC_CTL0) & ~RZN1_RTC_CTL0_CE;
+       writel(val, rtc->base + RZN1_RTC_CTL0);
+       /* Wait 2-4 32k clock cycles for the disabled controller */
+       ret = readl_poll_timeout(rtc->base + RZN1_RTC_CTL0, val,
+                                !(val & RZN1_RTC_CTL0_CEST), 62, 123);
+       if (ret)
+               goto dis_runtime_pm;
+
        writel(RZN1_RTC_CTL0_CE | RZN1_RTC_CTL0_AMPM | RZN1_RTC_CTL0_SLSB_SUBU,
               rtc->base + RZN1_RTC_CTL0);