* [PATCH 1/3] rtc: ab8500: use rtc_add_group
@ 2018-09-24 14:49 Alexandre Belloni
2018-09-24 14:49 ` [PATCH 2/3] rtc: ab8500: let the core handle range Alexandre Belloni
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alexandre Belloni @ 2018-09-24 14:49 UTC (permalink / raw)
To: linux-rtc
Cc: Linus Walleij, linux-arm-kernel, linux-kernel, Alexandre Belloni
Use rtc_add_group to add the sysfs group in a race free manner.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-ab8500.c | 41 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index e28f4401fd35..e97015e5c63e 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -360,15 +360,14 @@ static DEVICE_ATTR(rtc_calibration, S_IRUGO | S_IWUSR,
ab8500_sysfs_show_rtc_calibration,
ab8500_sysfs_store_rtc_calibration);
-static int ab8500_sysfs_rtc_register(struct device *dev)
-{
- return device_create_file(dev, &dev_attr_rtc_calibration);
-}
+static struct attribute *ab8500_rtc_attrs[] = {
+ &dev_attr_rtc_calibration.attr,
+ NULL
+};
-static void ab8500_sysfs_rtc_unregister(struct device *dev)
-{
- device_remove_file(dev, &dev_attr_rtc_calibration);
-}
+static const struct attribute_group ab8500_rtc_sysfs_files = {
+ .attrs = ab8500_rtc_attrs,
+};
static irqreturn_t rtc_alarm_handler(int irq, void *data)
{
@@ -429,14 +428,11 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, true);
- rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc",
- (struct rtc_class_ops *)platid->driver_data,
- THIS_MODULE);
- if (IS_ERR(rtc)) {
- dev_err(&pdev->dev, "Registration failed\n");
- err = PTR_ERR(rtc);
- return err;
- }
+ rtc = devm_rtc_allocate_device(&pdev->dev);
+ if (IS_ERR(rtc))
+ return PTR_ERR(rtc);
+
+ rtc->ops = (struct rtc_class_ops *)platid->driver_data;
err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
rtc_alarm_handler, IRQF_ONESHOT,
@@ -447,22 +443,19 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
dev_pm_set_wake_irq(&pdev->dev, irq);
platform_set_drvdata(pdev, rtc);
- err = ab8500_sysfs_rtc_register(&pdev->dev);
- if (err) {
- dev_err(&pdev->dev, "sysfs RTC failed to register\n");
- return err;
- }
-
rtc->uie_unsupported = 1;
- return 0;
+ err = rtc_add_group(rtc, &ab8500_rtc_sysfs_files);
+ if (err)
+ return err;
+
+ return rtc_register_device(rtc);
}
static int ab8500_rtc_remove(struct platform_device *pdev)
{
dev_pm_clear_wake_irq(&pdev->dev);
device_init_wakeup(&pdev->dev, false);
- ab8500_sysfs_rtc_unregister(&pdev->dev);
return 0;
}
--
2.19.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 2/3] rtc: ab8500: let the core handle range 2018-09-24 14:49 [PATCH 1/3] rtc: ab8500: use rtc_add_group Alexandre Belloni @ 2018-09-24 14:49 ` Alexandre Belloni 2018-09-26 7:39 ` Linus Walleij 2018-09-24 14:49 ` [PATCH 3/3] rtc: ab8500: remove useless check Alexandre Belloni 2018-09-26 7:38 ` [PATCH 1/3] rtc: ab8500: use rtc_add_group Linus Walleij 2 siblings, 1 reply; 6+ messages in thread From: Alexandre Belloni @ 2018-09-24 14:49 UTC (permalink / raw) To: linux-rtc Cc: Linus Walleij, linux-arm-kernel, linux-kernel, Alexandre Belloni Let the core handle offsetting and windowing the RTC range. The RTC has a 24 bit counter for minutes plus a seconds counter. Keep the epoch at the beginning of 2000. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> --- drivers/rtc/rtc-ab8500.c | 53 +++------------------------------------- 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c index e97015e5c63e..2e2671b84ab0 100644 --- a/drivers/rtc/rtc-ab8500.c +++ b/drivers/rtc/rtc-ab8500.c @@ -46,7 +46,6 @@ #define RTC_STATUS_DATA 0x01 #define COUNTS_PER_SEC (0xF000 / 60) -#define AB8500_RTC_EPOCH 2000 static const u8 ab8500_rtc_time_regs[] = { AB8500_RTC_WATCH_TMIN_HI_REG, AB8500_RTC_WATCH_TMIN_MID_REG, @@ -59,23 +58,6 @@ static const u8 ab8500_rtc_alarm_regs[] = { AB8500_RTC_ALRM_MIN_LOW_REG }; -/* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */ -static unsigned long get_elapsed_seconds(int year) -{ - unsigned long secs; - struct rtc_time tm = { - .tm_year = year - 1900, - .tm_mday = 1, - }; - - /* - * This function calculates secs from 1970 and not from - * 1900, even if we supply the offset from year 1900. - */ - rtc_tm_to_time(&tm, &secs); - return secs; -} - static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) { unsigned long timeout = jiffies + HZ; @@ -118,9 +100,6 @@ static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) secs = secs / COUNTS_PER_SEC; secs = secs + (mins * 60); - /* Add back the initially subtracted number of seconds */ - secs += get_elapsed_seconds(AB8500_RTC_EPOCH); - rtc_time_to_tm(secs, tm); return 0; } @@ -131,21 +110,8 @@ static int ab8500_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; unsigned long no_secs, no_mins, secs = 0; - if (tm->tm_year < (AB8500_RTC_EPOCH - 1900)) { - dev_dbg(dev, "year should be equal to or greater than %d\n", - AB8500_RTC_EPOCH); - return -EINVAL; - } - - /* Get the number of seconds since 1970 */ rtc_tm_to_time(tm, &secs); - /* - * Convert it to the number of seconds since 01-01-2000 00:00:00, since - * we only have a small counter in the RTC. - */ - secs -= get_elapsed_seconds(AB8500_RTC_EPOCH); - no_mins = secs / 60; no_secs = secs % 60; @@ -202,9 +168,6 @@ static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) mins = (buf[0] << 16) | (buf[1] << 8) | (buf[2]); secs = mins * 60; - /* Add back the initially subtracted number of seconds */ - secs += get_elapsed_seconds(AB8500_RTC_EPOCH); - rtc_time_to_tm(secs, &alarm->time); return rtc_valid_tm(&alarm->time); @@ -224,12 +187,6 @@ static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) unsigned long mins, secs = 0, cursec = 0; struct rtc_time curtm; - if (alarm->time.tm_year < (AB8500_RTC_EPOCH - 1900)) { - dev_dbg(dev, "year should be equal to or greater than %d\n", - AB8500_RTC_EPOCH); - return -EINVAL; - } - /* Get the number of seconds since 1970 */ rtc_tm_to_time(&alarm->time, &secs); @@ -245,12 +202,6 @@ static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) return -EINVAL; } - /* - * Convert it to the number of seconds since 01-01-2000 00:00:00, since - * we only have a small counter in the RTC. - */ - secs -= get_elapsed_seconds(AB8500_RTC_EPOCH); - mins = secs / 60; buf[2] = mins & 0xFF; @@ -445,6 +396,10 @@ static int ab8500_rtc_probe(struct platform_device *pdev) rtc->uie_unsupported = 1; + rtc->range_max = (1ULL << 24) * 60 - 1; // 24-bit minutes + 59 secs + rtc->start_secs = RTC_TIMESTAMP_BEGIN_2000; + rtc->set_start_time = true; + err = rtc_add_group(rtc, &ab8500_rtc_sysfs_files); if (err) return err; -- 2.19.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] rtc: ab8500: let the core handle range 2018-09-24 14:49 ` [PATCH 2/3] rtc: ab8500: let the core handle range Alexandre Belloni @ 2018-09-26 7:39 ` Linus Walleij 0 siblings, 0 replies; 6+ messages in thread From: Linus Walleij @ 2018-09-26 7:39 UTC (permalink / raw) To: Alexandre Belloni; +Cc: linux-rtc, Linux ARM, linux-kernel On Mon, Sep 24, 2018 at 4:49 PM Alexandre Belloni <alexandre.belloni@bootlin.com> wrote: > Let the core handle offsetting and windowing the RTC range. > The RTC has a 24 bit counter for minutes plus a seconds counter. > Keep the epoch at the beginning of 2000. > > Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] rtc: ab8500: remove useless check 2018-09-24 14:49 [PATCH 1/3] rtc: ab8500: use rtc_add_group Alexandre Belloni 2018-09-24 14:49 ` [PATCH 2/3] rtc: ab8500: let the core handle range Alexandre Belloni @ 2018-09-24 14:49 ` Alexandre Belloni 2018-09-26 7:40 ` Linus Walleij 2018-09-26 7:38 ` [PATCH 1/3] rtc: ab8500: use rtc_add_group Linus Walleij 2 siblings, 1 reply; 6+ messages in thread From: Alexandre Belloni @ 2018-09-24 14:49 UTC (permalink / raw) To: linux-rtc Cc: Linus Walleij, linux-arm-kernel, linux-kernel, Alexandre Belloni rtc_time_to_tm always rturns a valid tm, there is no need to validate it. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> --- drivers/rtc/rtc-ab8500.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c index 2e2671b84ab0..1f0cbd51ba06 100644 --- a/drivers/rtc/rtc-ab8500.c +++ b/drivers/rtc/rtc-ab8500.c @@ -170,7 +170,7 @@ static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) rtc_time_to_tm(secs, &alarm->time); - return rtc_valid_tm(&alarm->time); + return 0; } static int ab8500_rtc_irq_enable(struct device *dev, unsigned int enabled) -- 2.19.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] rtc: ab8500: remove useless check 2018-09-24 14:49 ` [PATCH 3/3] rtc: ab8500: remove useless check Alexandre Belloni @ 2018-09-26 7:40 ` Linus Walleij 0 siblings, 0 replies; 6+ messages in thread From: Linus Walleij @ 2018-09-26 7:40 UTC (permalink / raw) To: Alexandre Belloni; +Cc: linux-rtc, Linux ARM, linux-kernel On Mon, Sep 24, 2018 at 4:49 PM Alexandre Belloni <alexandre.belloni@bootlin.com> wrote: > rtc_time_to_tm always rturns a valid tm, there is no need to validate it. > > Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] rtc: ab8500: use rtc_add_group 2018-09-24 14:49 [PATCH 1/3] rtc: ab8500: use rtc_add_group Alexandre Belloni 2018-09-24 14:49 ` [PATCH 2/3] rtc: ab8500: let the core handle range Alexandre Belloni 2018-09-24 14:49 ` [PATCH 3/3] rtc: ab8500: remove useless check Alexandre Belloni @ 2018-09-26 7:38 ` Linus Walleij 2 siblings, 0 replies; 6+ messages in thread From: Linus Walleij @ 2018-09-26 7:38 UTC (permalink / raw) To: Alexandre Belloni; +Cc: linux-rtc, Linux ARM, linux-kernel On Mon, Sep 24, 2018 at 4:49 PM Alexandre Belloni <alexandre.belloni@bootlin.com> wrote: > Use rtc_add_group to add the sysfs group in a race free manner. > > Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-09-26 7:40 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-09-24 14:49 [PATCH 1/3] rtc: ab8500: use rtc_add_group Alexandre Belloni 2018-09-24 14:49 ` [PATCH 2/3] rtc: ab8500: let the core handle range Alexandre Belloni 2018-09-26 7:39 ` Linus Walleij 2018-09-24 14:49 ` [PATCH 3/3] rtc: ab8500: remove useless check Alexandre Belloni 2018-09-26 7:40 ` Linus Walleij 2018-09-26 7:38 ` [PATCH 1/3] rtc: ab8500: use rtc_add_group Linus Walleij
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