All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Chris Brandt <chris.brandt@renesas.com>,
	linux-renesas-soc@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 3/3] rtc: sh: set range
Date: Wed, 20 Mar 2019 12:30:10 +0100	[thread overview]
Message-ID: <20190320113010.8955-3-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20190320113010.8955-1-alexandre.belloni@bootlin.com>

The SH RTC is a BCD RTC with some version having 4 digits for the year.

The range for the RTCs with only 2 digits for the year was unfortunately
shifted to handle 1999 to 2098.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-sh.c | 8 ++++++++
 include/linux/rtc.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index b582af10ddb5..37964a867de7 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -601,6 +601,14 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
 	rtc->rtc_dev->ops = &sh_rtc_ops;
 	rtc->rtc_dev->max_user_freq = 256;
 
+	if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
+		rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+		rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
+	} else {
+		rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
+		rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
+	}
+
 	ret = rtc_register_device(rtc->rtc_dev);
 	if (ret)
 		goto err_unmap;
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f89bfbb54902..588120ba372c 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -165,6 +165,7 @@ struct rtc_device {
 #define RTC_TIMESTAMP_BEGIN_1900	-2208989361LL /* 1900-01-01 00:00:00 */
 #define RTC_TIMESTAMP_BEGIN_2000	946684800LL /* 2000-01-01 00:00:00 */
 #define RTC_TIMESTAMP_END_2099		4102444799LL /* 2099-12-31 23:59:59 */
+#define RTC_TIMESTAMP_END_9999		253402300799LL /* 9999-12-31 23:59:59 */
 
 extern struct rtc_device *devm_rtc_device_register(struct device *dev,
 					const char *name,
-- 
2.20.1


WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Chris Brandt <chris.brandt@renesas.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] rtc: sh: set range
Date: Wed, 20 Mar 2019 12:30:10 +0100	[thread overview]
Message-ID: <20190320113010.8955-3-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20190320113010.8955-1-alexandre.belloni@bootlin.com>

The SH RTC is a BCD RTC with some version having 4 digits for the year.

The range for the RTCs with only 2 digits for the year was unfortunately
shifted to handle 1999 to 2098.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-sh.c | 8 ++++++++
 include/linux/rtc.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index b582af10ddb5..37964a867de7 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -601,6 +601,14 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
 	rtc->rtc_dev->ops = &sh_rtc_ops;
 	rtc->rtc_dev->max_user_freq = 256;
 
+	if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
+		rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+		rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
+	} else {
+		rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
+		rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
+	}
+
 	ret = rtc_register_device(rtc->rtc_dev);
 	if (ret)
 		goto err_unmap;
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f89bfbb54902..588120ba372c 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -165,6 +165,7 @@ struct rtc_device {
 #define RTC_TIMESTAMP_BEGIN_1900	-2208989361LL /* 1900-01-01 00:00:00 */
 #define RTC_TIMESTAMP_BEGIN_2000	946684800LL /* 2000-01-01 00:00:00 */
 #define RTC_TIMESTAMP_END_2099		4102444799LL /* 2099-12-31 23:59:59 */
+#define RTC_TIMESTAMP_END_9999		253402300799LL /* 9999-12-31 23:59:59 */
 
 extern struct rtc_device *devm_rtc_device_register(struct device *dev,
 					const char *name,
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-03-20 11:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 11:30 [PATCH 1/3] rtc: sh: stop resetting time to epoch Alexandre Belloni
2019-03-20 11:30 ` Alexandre Belloni
2019-03-20 11:30 ` [PATCH 2/3] rtc: sh: fix possible race condition Alexandre Belloni
2019-03-20 11:30   ` Alexandre Belloni
2019-03-21  9:51   ` Geert Uytterhoeven
2019-03-21  9:51     ` Geert Uytterhoeven
2019-03-20 11:30 ` Alexandre Belloni [this message]
2019-03-20 11:30   ` [PATCH 3/3] rtc: sh: set range Alexandre Belloni
2019-03-21 10:22   ` Geert Uytterhoeven
2019-03-21 10:22     ` Geert Uytterhoeven
2019-03-22  6:12     ` Alexandre Belloni
2019-03-22  6:12       ` Alexandre Belloni
2019-03-22  7:26       ` Geert Uytterhoeven
2019-03-22  7:26         ` Geert Uytterhoeven
2019-03-21  9:46 ` [PATCH 1/3] rtc: sh: stop resetting time to epoch Geert Uytterhoeven
2019-03-21  9:46   ` Geert Uytterhoeven

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=20190320113010.8955-3-alexandre.belloni@bootlin.com \
    --to=alexandre.belloni@bootlin.com \
    --cc=chris.brandt@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-rtc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.