diff mbox series

[1/3] rtc: sh: stop resetting time to epoch

Message ID 20190320113010.8955-1-alexandre.belloni@bootlin.com (mailing list archive)
State New, archived
Headers show
Series [1/3] rtc: sh: stop resetting time to epoch | expand

Commit Message

Alexandre Belloni March 20, 2019, 11:30 a.m. UTC
There is no point in resetting the time to epoch as this means that
userspace will never get the valuable information that time is actually
invalid.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-sh.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Geert Uytterhoeven March 21, 2019, 9:46 a.m. UTC | #1
Hi Alexandre,

On Wed, Mar 20, 2019 at 12:30 PM Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:
> There is no point in resetting the time to epoch as this means that
> userspace will never get the valuable information that time is actually
> invalid.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

Thanks for your patch!

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Impact before/after (cold boot):

    -sh-rtc fcff1000.rtc: setting system clock to 1970-01-01T00:00:00 UTC (0)
    +sh-rtc fcff1000.rtc: hctosys: unable to read the hardware clock

After warm boot (Linux reboot command):

    sh-rtc fcff1000.rtc: setting system clock to 2019-03-21T08:47:54
UTC (1553158074)

After reset (reset switch):

    sh-rtc fcff1000.rtc: hctosys: unable to read the hardware clock

Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index d417b203cbc5..f4ac9ec8fbb6 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -276,6 +276,9 @@  static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	struct sh_rtc *rtc = dev_get_drvdata(dev);
 	unsigned int sec128, sec2, yr, yr100, cf_bit;
 
+	if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
+		return -EINVAL;
+
 	do {
 		unsigned int tmp;
 
@@ -600,12 +603,6 @@  static int __init sh_rtc_probe(struct platform_device *pdev)
 
 	rtc->rtc_dev->max_user_freq = 256;
 
-	/* reset rtc to epoch 0 if time is invalid */
-	if (rtc_read_time(rtc->rtc_dev, &r) < 0) {
-		rtc_time_to_tm(0, &r);
-		rtc_set_time(rtc->rtc_dev, &r);
-	}
-
 	device_init_wakeup(&pdev->dev, 1);
 	return 0;