* [PATCH 1/2] rtc: sun6i: let the core handle rtc range
@ 2020-03-30 20:12 Alexandre Belloni
2020-03-30 20:12 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
2020-04-02 13:57 ` [PATCH 1/2] rtc: sun6i: let the core handle rtc range Paul Kocialkowski
0 siblings, 2 replies; 5+ messages in thread
From: Alexandre Belloni @ 2020-03-30 20:12 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, Maxime Ripard, Chen-Yu Tsai
Cc: linux-rtc, linux-arm-kernel, linux-kernel
Let the rtc core check the date/time against the RTC range.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-sun6i.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index 415a20a936e4..446ce38c1592 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -108,7 +108,6 @@
* driver, even though it is somewhat limited.
*/
#define SUN6I_YEAR_MIN 1970
-#define SUN6I_YEAR_MAX 2033
#define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900)
/*
@@ -569,14 +568,6 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
struct sun6i_rtc_dev *chip = dev_get_drvdata(dev);
u32 date = 0;
u32 time = 0;
- int year;
-
- year = rtc_tm->tm_year + 1900;
- if (year < SUN6I_YEAR_MIN || year > SUN6I_YEAR_MAX) {
- dev_err(dev, "rtc only supports year in range %d - %d\n",
- SUN6I_YEAR_MIN, SUN6I_YEAR_MAX);
- return -EINVAL;
- }
rtc_tm->tm_year -= SUN6I_YEAR_OFF;
rtc_tm->tm_mon += 1;
@@ -585,7 +576,7 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
SUN6I_DATE_SET_MON_VALUE(rtc_tm->tm_mon) |
SUN6I_DATE_SET_YEAR_VALUE(rtc_tm->tm_year);
- if (is_leap_year(year))
+ if (is_leap_year(rtc_tm->tm_year + SUN6I_YEAR_MIN))
date |= SUN6I_LEAP_SET_VALUE(1);
time = SUN6I_TIME_SET_SEC_VALUE(rtc_tm->tm_sec) |
@@ -726,12 +717,16 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1);
- chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i",
- &sun6i_rtc_ops, THIS_MODULE);
- if (IS_ERR(chip->rtc)) {
- dev_err(&pdev->dev, "unable to register device\n");
+ chip->rtc = devm_rtc_allocate_device(&pdev->dev);
+ if (IS_ERR(chip->rtc))
return PTR_ERR(chip->rtc);
- }
+
+ chip->rtc->ops = &sun6i_rtc_ops;
+ chip->rtc->range_max = 2019686399LL; /* 2033-12-31 23:59:59 */
+
+ ret = rtc_register_device(chip->rtc);
+ if (ret)
+ return ret;
dev_info(&pdev->dev, "RTC enabled\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64
2020-03-30 20:12 [PATCH 1/2] rtc: sun6i: let the core handle rtc range Alexandre Belloni
@ 2020-03-30 20:12 ` Alexandre Belloni
2020-04-02 13:57 ` [PATCH 1/2] rtc: sun6i: let the core handle rtc range Paul Kocialkowski
1 sibling, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2020-03-30 20:12 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, Maxime Ripard, Chen-Yu Tsai
Cc: linux-rtc, linux-arm-kernel, linux-kernel
Call the 64bit versions of rtc_tm time conversion.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-sun6i.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index 446ce38c1592..e2b8b150bcb4 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -498,7 +498,7 @@ static int sun6i_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
wkalrm->enabled = !!(alrm_en & SUN6I_ALRM_EN_CNT_EN);
wkalrm->pending = !!(alrm_st & SUN6I_ALRM_EN_CNT_EN);
- rtc_time_to_tm(chip->alarm, &wkalrm->time);
+ rtc_time64_to_tm(chip->alarm, &wkalrm->time);
return 0;
}
@@ -519,8 +519,8 @@ static int sun6i_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
return -EINVAL;
}
- rtc_tm_to_time(alrm_tm, &time_set);
- rtc_tm_to_time(&tm_now, &time_now);
+ time_set = rtc_tm_to_time64(alrm_tm);
+ time_now = rtc_tm_to_time64(&tm_now);
if (time_set <= time_now) {
dev_err(dev, "Date to set in the past\n");
return -EINVAL;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] rtc: sun6i: let the core handle rtc range
2020-03-30 20:12 [PATCH 1/2] rtc: sun6i: let the core handle rtc range Alexandre Belloni
2020-03-30 20:12 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
@ 2020-04-02 13:57 ` Paul Kocialkowski
1 sibling, 0 replies; 5+ messages in thread
From: Paul Kocialkowski @ 2020-04-02 13:57 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Alessandro Zummo, Maxime Ripard, Chen-Yu Tsai, linux-rtc,
linux-kernel, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 2725 bytes --]
Hi,
On Mon 30 Mar 20, 22:12, Alexandre Belloni wrote:
> Let the rtc core check the date/time against the RTC range.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This was successfully:
Tested-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Cheers,
Paul
> ---
> drivers/rtc/rtc-sun6i.c | 25 ++++++++++---------------
> 1 file changed, 10 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
> index 415a20a936e4..446ce38c1592 100644
> --- a/drivers/rtc/rtc-sun6i.c
> +++ b/drivers/rtc/rtc-sun6i.c
> @@ -108,7 +108,6 @@
> * driver, even though it is somewhat limited.
> */
> #define SUN6I_YEAR_MIN 1970
> -#define SUN6I_YEAR_MAX 2033
> #define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900)
>
> /*
> @@ -569,14 +568,6 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
> struct sun6i_rtc_dev *chip = dev_get_drvdata(dev);
> u32 date = 0;
> u32 time = 0;
> - int year;
> -
> - year = rtc_tm->tm_year + 1900;
> - if (year < SUN6I_YEAR_MIN || year > SUN6I_YEAR_MAX) {
> - dev_err(dev, "rtc only supports year in range %d - %d\n",
> - SUN6I_YEAR_MIN, SUN6I_YEAR_MAX);
> - return -EINVAL;
> - }
>
> rtc_tm->tm_year -= SUN6I_YEAR_OFF;
> rtc_tm->tm_mon += 1;
> @@ -585,7 +576,7 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
> SUN6I_DATE_SET_MON_VALUE(rtc_tm->tm_mon) |
> SUN6I_DATE_SET_YEAR_VALUE(rtc_tm->tm_year);
>
> - if (is_leap_year(year))
> + if (is_leap_year(rtc_tm->tm_year + SUN6I_YEAR_MIN))
> date |= SUN6I_LEAP_SET_VALUE(1);
>
> time = SUN6I_TIME_SET_SEC_VALUE(rtc_tm->tm_sec) |
> @@ -726,12 +717,16 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
>
> device_init_wakeup(&pdev->dev, 1);
>
> - chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i",
> - &sun6i_rtc_ops, THIS_MODULE);
> - if (IS_ERR(chip->rtc)) {
> - dev_err(&pdev->dev, "unable to register device\n");
> + chip->rtc = devm_rtc_allocate_device(&pdev->dev);
> + if (IS_ERR(chip->rtc))
> return PTR_ERR(chip->rtc);
> - }
> +
> + chip->rtc->ops = &sun6i_rtc_ops;
> + chip->rtc->range_max = 2019686399LL; /* 2033-12-31 23:59:59 */
> +
> + ret = rtc_register_device(chip->rtc);
> + if (ret)
> + return ret;
>
> dev_info(&pdev->dev, "RTC enabled\n");
>
> --
> 2.25.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] rtc: remove rtc_time_to_tm and rtc_tm_to_time
@ 2020-03-30 20:15 Alexandre Belloni
2020-03-30 20:15 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Belloni @ 2020-03-30 20:15 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel
There are no callers of the 32bit versions of rtc_time conversion
functions, drop them.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
include/linux/rtc.h | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 23990bd29040..bba3db3f7efa 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -34,18 +34,6 @@ static inline time64_t rtc_tm_sub(struct rtc_time *lhs, struct rtc_time *rhs)
return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs);
}
-static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
-{
- rtc_time64_to_tm(time, tm);
-}
-
-static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
-{
- *time = rtc_tm_to_time64(tm);
-
- return 0;
-}
-
#include <linux/device.h>
#include <linux/seq_file.h>
#include <linux/cdev.h>
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64
2020-03-30 20:15 [PATCH] rtc: remove rtc_time_to_tm and rtc_tm_to_time Alexandre Belloni
@ 2020-03-30 20:15 ` Alexandre Belloni
2020-04-02 13:57 ` Paul Kocialkowski
0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Belloni @ 2020-03-30 20:15 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, Maxime Ripard, Chen-Yu Tsai
Cc: linux-rtc, linux-arm-kernel, linux-kernel
Call the 64bit versions of rtc_tm time conversion.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-sun6i.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index 446ce38c1592..e2b8b150bcb4 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -498,7 +498,7 @@ static int sun6i_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
wkalrm->enabled = !!(alrm_en & SUN6I_ALRM_EN_CNT_EN);
wkalrm->pending = !!(alrm_st & SUN6I_ALRM_EN_CNT_EN);
- rtc_time_to_tm(chip->alarm, &wkalrm->time);
+ rtc_time64_to_tm(chip->alarm, &wkalrm->time);
return 0;
}
@@ -519,8 +519,8 @@ static int sun6i_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
return -EINVAL;
}
- rtc_tm_to_time(alrm_tm, &time_set);
- rtc_tm_to_time(&tm_now, &time_now);
+ time_set = rtc_tm_to_time64(alrm_tm);
+ time_now = rtc_tm_to_time64(&tm_now);
if (time_set <= time_now) {
dev_err(dev, "Date to set in the past\n");
return -EINVAL;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64
2020-03-30 20:15 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
@ 2020-04-02 13:57 ` Paul Kocialkowski
0 siblings, 0 replies; 5+ messages in thread
From: Paul Kocialkowski @ 2020-04-02 13:57 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Alessandro Zummo, Maxime Ripard, Chen-Yu Tsai, linux-rtc,
linux-kernel, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]
Hi,
On Mon 30 Mar 20, 22:15, Alexandre Belloni wrote:
> Call the 64bit versions of rtc_tm time conversion.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This was successfully:
Tested-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Cheers,
Paul
> ---
> drivers/rtc/rtc-sun6i.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
> index 446ce38c1592..e2b8b150bcb4 100644
> --- a/drivers/rtc/rtc-sun6i.c
> +++ b/drivers/rtc/rtc-sun6i.c
> @@ -498,7 +498,7 @@ static int sun6i_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
>
> wkalrm->enabled = !!(alrm_en & SUN6I_ALRM_EN_CNT_EN);
> wkalrm->pending = !!(alrm_st & SUN6I_ALRM_EN_CNT_EN);
> - rtc_time_to_tm(chip->alarm, &wkalrm->time);
> + rtc_time64_to_tm(chip->alarm, &wkalrm->time);
>
> return 0;
> }
> @@ -519,8 +519,8 @@ static int sun6i_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
> return -EINVAL;
> }
>
> - rtc_tm_to_time(alrm_tm, &time_set);
> - rtc_tm_to_time(&tm_now, &time_now);
> + time_set = rtc_tm_to_time64(alrm_tm);
> + time_now = rtc_tm_to_time64(&tm_now);
> if (time_set <= time_now) {
> dev_err(dev, "Date to set in the past\n");
> return -EINVAL;
> --
> 2.25.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-02 13:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 20:12 [PATCH 1/2] rtc: sun6i: let the core handle rtc range Alexandre Belloni
2020-03-30 20:12 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
2020-04-02 13:57 ` [PATCH 1/2] rtc: sun6i: let the core handle rtc range Paul Kocialkowski
2020-03-30 20:15 [PATCH] rtc: remove rtc_time_to_tm and rtc_tm_to_time Alexandre Belloni
2020-03-30 20:15 ` [PATCH 2/2] rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
2020-04-02 13:57 ` Paul Kocialkowski
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).