linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Xunlei Pang <pang.xunlei@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	John Stultz <john.stultz@linaro.org>
Subject: [PATCH 09/21] rtc/ab3100: Update driver to address y2038/y2106 issues
Date: Wed,  1 Apr 2015 20:34:29 -0700	[thread overview]
Message-ID: <1427945681-29972-10-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1427945681-29972-1-git-send-email-john.stultz@linaro.org>

From: Xunlei Pang <pang.xunlei@linaro.org>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_tm_to_time() with rtc_tm_to_time64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change ab3100_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining
y2038/y2106 issues.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/rtc/rtc-ab3100.c | 55 ++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index 1d0340f..9b725c5 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -43,21 +43,21 @@
 /*
  * RTC clock functions and device struct declaration
  */
-static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs)
 {
 	u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2,
 		     AB3100_TI3, AB3100_TI4, AB3100_TI5};
 	unsigned char buf[6];
-	u64 fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2;
+	u64 hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2;
 	int err = 0;
 	int i;
 
-	buf[0] = (fat_time) & 0xFF;
-	buf[1] = (fat_time >> 8) & 0xFF;
-	buf[2] = (fat_time >> 16) & 0xFF;
-	buf[3] = (fat_time >> 24) & 0xFF;
-	buf[4] = (fat_time >> 32) & 0xFF;
-	buf[5] = (fat_time >> 40) & 0xFF;
+	buf[0] = (hw_counter) & 0xFF;
+	buf[1] = (hw_counter >> 8) & 0xFF;
+	buf[2] = (hw_counter >> 16) & 0xFF;
+	buf[3] = (hw_counter >> 24) & 0xFF;
+	buf[4] = (hw_counter >> 32) & 0xFF;
+	buf[5] = (hw_counter >> 40) & 0xFF;
 
 	for (i = 0; i < 6; i++) {
 		err = abx500_set_register_interruptible(dev, 0,
@@ -75,7 +75,7 @@ static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs)
 
 static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	unsigned long time;
+	time64_t time;
 	u8 rtcval;
 	int err;
 
@@ -88,7 +88,7 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		dev_info(dev, "clock not set (lost power)");
 		return -EINVAL;
 	} else {
-		u64 fat_time;
+		u64 hw_counter;
 		u8 buf[6];
 
 		/* Read out time registers */
@@ -98,22 +98,21 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		if (err != 0)
 			return err;
 
-		fat_time = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) |
+		hw_counter = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) |
 			((u64) buf[3] << 24) | ((u64) buf[2] << 16) |
 			((u64) buf[1] << 8) | (u64) buf[0];
-		time = (unsigned long) (fat_time /
-					(u64) (AB3100_RTC_CLOCK_RATE * 2));
+		time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2);
 	}
 
-	rtc_time_to_tm(time, tm);
+	rtc_time64_to_tm(time, tm);
 
 	return rtc_valid_tm(tm);
 }
 
 static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
-	unsigned long time;
-	u64 fat_time;
+	time64_t time;
+	u64 hw_counter;
 	u8 buf[6];
 	u8 rtcval;
 	int err;
@@ -134,11 +133,11 @@ static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 						     AB3100_AL0, buf, 4);
 	if (err)
 		return err;
-	fat_time = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) |
+	hw_counter = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) |
 		((u64) buf[1] << 24) | ((u64) buf[0] << 16);
-	time = (unsigned long) (fat_time / (u64) (AB3100_RTC_CLOCK_RATE * 2));
+	time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2);
 
-	rtc_time_to_tm(time, &alarm->time);
+	rtc_time64_to_tm(time, &alarm->time);
 
 	return rtc_valid_tm(&alarm->time);
 }
@@ -147,17 +146,17 @@ static int ab3100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
 	u8 regs[] = {AB3100_AL0, AB3100_AL1, AB3100_AL2, AB3100_AL3};
 	unsigned char buf[4];
-	unsigned long secs;
-	u64 fat_time;
+	time64_t secs;
+	u64 hw_counter;
 	int err;
 	int i;
 
-	rtc_tm_to_time(&alarm->time, &secs);
-	fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2;
-	buf[0] = (fat_time >> 16) & 0xFF;
-	buf[1] = (fat_time >> 24) & 0xFF;
-	buf[2] = (fat_time >> 32) & 0xFF;
-	buf[3] = (fat_time >> 40) & 0xFF;
+	secs = rtc_tm_to_time64(&alarm->time);
+	hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2;
+	buf[0] = (hw_counter >> 16) & 0xFF;
+	buf[1] = (hw_counter >> 24) & 0xFF;
+	buf[2] = (hw_counter >> 32) & 0xFF;
+	buf[3] = (hw_counter >> 40) & 0xFF;
 
 	/* Set the alarm */
 	for (i = 0; i < 4; i++) {
@@ -193,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled)
 
 static const struct rtc_class_ops ab3100_rtc_ops = {
 	.read_time	= ab3100_rtc_read_time,
-	.set_mmss	= ab3100_rtc_set_mmss,
+	.set_mmss64	= ab3100_rtc_set_mmss,
 	.read_alarm	= ab3100_rtc_read_alarm,
 	.set_alarm	= ab3100_rtc_set_alarm,
 	.alarm_irq_enable = ab3100_rtc_irq_enable,
-- 
1.9.1


  parent reply	other threads:[~2015-04-02  3:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02  3:34 [PATCH 00/21] 4.1 time and rtc changes for tip/timers/core John Stultz
2015-04-02  3:34 ` [PATCH 01/21] time: Add y2038 safe read_boot_clock64() John Stultz
2015-04-03  8:15   ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 02/21] time: Add y2038 safe read_persistent_clock64() John Stultz
2015-04-03  8:15   ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 03/21] time: Add y2038 safe update_persistent_clock64() John Stultz
2015-04-03  8:16   ` [tip:timers/core] time: Add y2038 safe update_persistent_clock64( ) tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 04/21] ARM: OMAP: 32k counter: Provide y2038-safe omap_read_persistent_clock() replacement John Stultz
2015-04-03  8:16   ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 05/21] ARM: tegra: clock: Provide y2038-safe tegra_read_persistent_clock() replacement John Stultz
2015-04-03  8:16   ` [tip:timers/core] clocksource/drivers/tegra: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 06/21] ARM: time: Provide read_boot_clock64() and read_persistent_clock64() John Stultz
2015-04-03  8:17   ` [tip:timers/core] ARM, clocksource/drivers: Provide read_boot_clock64() and read_persistent_clock64() and use them tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 07/21] rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement John Stultz
2015-04-03  8:17   ` [tip:timers/core] drivers/rtc: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 08/21] rtc/test: Update driver to address y2038/y2106 issues John Stultz
2015-04-03  8:17   ` [tip:timers/core] drivers/rtc/test: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` John Stultz [this message]
2015-04-03  8:17   ` [tip:timers/core] drivers/rtc/ab3100: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 10/21] rtc/mc13xxx: " John Stultz
2015-04-03  8:18   ` [tip:timers/core] drivers/rtc/mc13xxx: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 11/21] rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time John Stultz
2015-04-03  8:18   ` [tip:timers/core] drivers/rtc/mxc: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 12/21] rtc/mxc: Convert get_alarm_or_time()/set_alarm_or_time() to use time64_t John Stultz
2015-04-03  8:18   ` [tip:timers/core] drivers/rtc/mxc: Convert get_alarm_or_time()/ set_alarm_or_time() " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 13/21] rtc/mxc: Update driver to address y2038/y2106 issues John Stultz
2015-04-03  8:19   ` [tip:timers/core] drivers/rtc/mxc: Update driver to address y2038 /y2106 issues tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 14/21] alpha: rtc: Change to use rtc_class_ops's set_mmss64() John Stultz
2015-04-03  8:19   ` [tip:timers/core] alpha, rtc: Change to use rtc_class_ops' s set_mmss64() tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 15/21] time: Don't build timekeeping_inject_sleeptime64() if no one uses it John Stultz
2015-04-03  8:19   ` [tip:timers/core] time: Don' t " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 16/21] rtc: Remove redundant rtc_valid_tm() from rtc_resume() John Stultz
2015-04-03  8:19   ` [tip:timers/core] drivers/rtc: " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 17/21] time: Fix a bug in timekeeping_suspend() with no persistent clock John Stultz
2015-04-03  6:16   ` Ingo Molnar
2015-04-03  8:20   ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 18/21] time: rtc: Don't bother into rtc_resume() for the nonstop clocksource John Stultz
2015-04-03  8:20   ` [tip:timers/core] time, drivers/rtc: Don't bother with rtc_resume () " tip-bot for Xunlei Pang
2015-04-02  3:34 ` [PATCH 19/21] clocksource: Improve comment explaining clocks_calc_max_nsecs()'s 50% safety margin John Stultz
2015-04-02  8:50   ` Peter Zijlstra
2015-04-02 17:30     ` John Stultz
2015-04-02 18:34       ` Peter Zijlstra
2015-04-02 18:41         ` John Stultz
2015-04-02 18:43           ` Peter Zijlstra
2015-04-02 18:50             ` John Stultz
2015-04-02 19:04               ` Peter Zijlstra
2015-04-03  8:20   ` [tip:timers/core] " tip-bot for John Stultz
2015-04-02  3:34 ` [PATCH 20/21] timekeeping: Change timekeeping_check_update() to take a tk_read_base John Stultz
2015-04-02  3:34 ` [PATCH 21/21] time: Rework debugging variables so they aren't global John Stultz
2015-04-02  7:47   ` Peter Zijlstra
2015-04-02  7:51     ` Ingo Molnar
2015-04-02  8:36       ` Peter Zijlstra
2015-04-02  8:41         ` Peter Zijlstra
2015-04-02 17:32       ` John Stultz
2015-04-03  6:21         ` Ingo Molnar

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=1427945681-29972-10-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pang.xunlei@linaro.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).