mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
	John Whitmore <arigead@gmail.com>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 2/2][RFC] rtc: Rework hctosys so that it is called on RTC registration
Date: Fri, 27 Jun 2014 10:27:11 -0700	[thread overview]
Message-ID: <1403890031-26419-3-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1403890031-26419-1-git-send-email-john.stultz@linaro.org>

Rather then calling hctosys at late_init, when RTC modules may not
yet be loaded, call hctosys on each RTC device registration.

We also change hctosys to usilize do_first_settimeofday() in
order to make sure the time is only initialized once by an RTC
and doesn't overwrite any time changes already made by userspace.

Cc: John Whitmore <arigead@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/rtc/class.c   |  2 ++
 drivers/rtc/hctosys.c | 19 ++++++++-----------
 include/linux/rtc.h   |  6 ++++++
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 589351e..6986529 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -237,6 +237,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 	dev_info(dev, "rtc core: registered %s as %s\n",
 			rtc->name, dev_name(&rtc->dev));
 
+	rtc_hctosys();
+
 	return rtc;
 
 exit_kfree:
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index 4aa60d7..72be031 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -22,7 +22,7 @@
  * the best guess is to add 0.5s.
  */
 
-static int __init rtc_hctosys(void)
+int rtc_hctosys(void)
 {
 	int err = -ENODEV;
 	struct rtc_time tm;
@@ -54,14 +54,13 @@ static int __init rtc_hctosys(void)
 
 	rtc_tm_to_time(&tm, &tv.tv_sec);
 
-	err = do_settimeofday(&tv);
-
-	dev_info(rtc->dev.parent,
-		"setting system clock to "
-		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
-		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-		tm.tm_hour, tm.tm_min, tm.tm_sec,
-		(unsigned int) tv.tv_sec);
+	if (!do_first_settimeofday(&tv))
+		dev_info(rtc->dev.parent,
+			"setting system clock to "
+			"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
+			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+			tm.tm_hour, tm.tm_min, tm.tm_sec,
+			(unsigned int) tv.tv_sec);
 
 err_invalid:
 err_read:
@@ -72,5 +71,3 @@ err_open:
 
 	return err;
 }
-
-late_initcall(rtc_hctosys);
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index c2c2897..a524cc6 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -191,6 +191,12 @@ static inline bool is_leap_year(unsigned int year)
 	return (!(year % 4) && (year % 100)) || !(year % 400);
 }
 
+#ifdef CONFIG_RTC_SYSTOHC
+int rtc_hctosys(void);
+#else
+#define rtc_hctosys() 0
+#endif
+
 #ifdef CONFIG_RTC_HCTOSYS_DEVICE
 extern int rtc_hctosys_ret;
 #else
-- 
1.9.1


  parent reply	other threads:[~2014-06-27 17:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27 17:27 [PATCH 0/2][RFC] Try to handle hctosys w/ rtc modules John Stultz
2014-06-27 17:27 ` [PATCH 1/2][RFC] time: Introduce do_first_settimeofday() John Stultz
2014-06-27 17:27 ` John Stultz [this message]
2014-06-28  7:18 ` [PATCH 0/2][RFC] Try to handle hctosys w/ rtc modules Alexander Holler
2014-06-28  7:32   ` Alexander Holler
2014-06-28 18:54     ` Marc Dietrich
2014-06-28 20:50       ` Alexander Holler
2014-06-30 19:37       ` Alessandro Zummo
2014-07-01 18:42         ` Alexander Holler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403890031-26419-3-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=a.zummo@towertech.it \
    --cc=arigead@gmail.com \
    --cc=holler@ahsoftware.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome