rtc: ab8500: use rtc_add_group
Subsystems (2)
Alexandre Belloni
maintainerPATCH 1/3 rtc: ab8500: use rtc_add_group
Use rtc_add_group to add the sysfs group in a race free manner.
--- drivers/rtc/rtc-ab8500.c | 41 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 24 deletions(-)
drivers/rtc/rtc-ab8500.c +17 -24
@@ -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 ; }
Signature · 1 line
2.19.0
Alexandre Belloni
maintainerPATCH 2/3 rtc: ab8500: let the core handle range
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.
--- drivers/rtc/rtc-ab8500.c | 53 +++------------------------------------- 1 file changed, 4 insertions(+), 49 deletions(-)
drivers/rtc/rtc-ab8500.c +4 -49
@@ -46,7 +46,6 @@#define RTC_STATUS_DATA 0x01#define COUNTS_PER_SEC (0xF000 / 60) -#define AB8500_RTC_EPOCH 2000static 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;
Signature · 1 line
2.19.0
Re: [PATCH 2/3] rtc: ab8500: let the core handle range
Quoted 5 lines · 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 <[email protected]>
Yours,
Linus Walleij
Alexandre Belloni
maintainerPATCH 3/3 rtc: ab8500: remove useless check
In reply to Alexandre Bellonirtc_time_to_tm always rturns a valid tm, there is no need to validate it.
--- drivers/rtc/rtc-ab8500.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-ab8500.c +1 -1
@@ -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)
Signature · 1 line
2.19.0
Re: [PATCH 3/3] rtc: ab8500: remove useless check
Quoted 3 lines · Alexandre Belloni
rtc_time_to_tmalways rturns a valid tm, there is no need to validate it.Signed-off-by Alexandre Belloni <[email protected]>
Yours,
Linus Walleij
Quoted 3 lines · Alexandre Belloni
Use
rtc_add_groupto add the sysfs group in a race free manner.Signed-off-by Alexandre Belloni <[email protected]>
Yours,
Linus Walleij