rtc: davinci: convert to devm_rtc_allocate_device
Alexandre Belloni
maintainerPATCH 1/4 rtc: davinci: convert to devm_rtc_allocate_device
This allows further improvement of the driver. Also remove the unnecessary error string as the core will already display error messages.
--- drivers/rtc/rtc-davinci.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/rtc/rtc-davinci.c +5 -7
@@ -485,13 +485,11 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, davinci_rtc); - davinci_rtc->rtc =devm_rtc_device_register (&pdev->dev, pdev->name, - &davinci_rtc_ops,THIS_MODULE ); -if (IS_ERR (davinci_rtc->rtc)) { -dev_err (dev,"unable to register RTC device, err %d\n" , - ret); + davinci_rtc->rtc =devm_rtc_allocate_device (&pdev->dev); +if (IS_ERR (davinci_rtc->rtc))return PTR_ERR (davinci_rtc->rtc); - } + + davinci_rtc->rtc->ops = &davinci_rtc_ops;rtcif_write (davinci_rtc,PRTCIF_INTFLG_RTCSS ,PRTCIF_INTFLG );rtcif_write (davinci_rtc,0 ,PRTCIF_INTEN );
@@ -516,7 +514,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)device_init_wakeup (&pdev->dev,0 ); -return 0 ; +return rtc_register_device (davinci_rtc->rtc); } static int __exit davinci_rtc_remove(struct platform_device *pdev)
Signature · 1 line
2.24.1
Alexandre Belloni
maintainerPATCH 2/4 rtc: davinci: remove useless 24h alarm handling
The code handling invalid alarms meaning the alarm is in the next 24 hours is not necessary since commit f8245c26886c ("rtc: remove "RTC_ALM_SET mode" bugs") which actually predates this driver. Since then, .set_alarm is never called with an invalid alarm and this handling is not necessary in the driver.
--- drivers/rtc/rtc-davinci.c | 21 --------------------- 1 file changed, 21 deletions(-)
drivers/rtc/rtc-davinci.c +0 -21
@@ -413,27 +413,6 @@ static int davinci_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)unsigned long flags;u16 days; -if (alm->time.tm_mday <=0 && alm->time.tm_mon <0 - && alm->time.tm_year <0 ) { -struct rtc_time tm; -unsigned long now, then; - -davinci_rtc_read_time (dev, &tm); -rtc_tm_to_time (&tm, &now); - - alm->time.tm_mday = tm.tm_mday; - alm->time.tm_mon = tm.tm_mon; - alm->time.tm_year = tm.tm_year; -rtc_tm_to_time (&alm->time, &then); - -if (then < now) { -rtc_time_to_tm (now +24 *60 *60 , &tm); - alm->time.tm_mday = tm.tm_mday; - alm->time.tm_mon = tm.tm_mon; - alm->time.tm_year = tm.tm_year; - } - } -if (convert2days (&days, &alm->time) <0 )return -EINVAL ;
Signature · 1 line
2.24.1
Alexandre Belloni
maintainerPATCH 3/4 rtc: davinci: let the core handle rtc range
In reply to Alexandre BelloniLet the core handle offsetting and windowing the RTC range.
This rtc has hours, minutes, seconds and 16bit days. As the driver has the RTC epoch set to year 2000, this means that the end of the range is 2^16 days minus one second later. This is Sun Jun 6 23:59:59 UTC 2179. This is better than the currently set year 2099.
--- drivers/rtc/rtc-davinci.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/rtc/rtc-davinci.c +4 -8
@@ -258,10 +258,6 @@ static int convert2days(u16 *days, struct rtc_time *tm)int i; *days =0 ; -/* epoch == 1900 */ -if (tm->tm_year <100 || tm->tm_year >199 ) -return -EINVAL ; -for (i =2000 ; i <1900 + tm->tm_year; i++) *days +=rtc_year_days (1 ,12 , i);
@@ -313,8 +309,7 @@ static int davinci_rtc_set_time(struct device *dev, struct rtc_time *tm)u8 rtc_cctrl;unsigned long flags; -if (convert2days (&days, tm) <0 ) -return -EINVAL ; +convert2days (&days, tm);spin_lock_irqsave (&davinci_rtc_lock, flags);
@@ -413,8 +408,7 @@ static int davinci_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)unsigned long flags;u16 days; -if (convert2days (&days, &alm->time) <0 ) -return -EINVAL ; +convert2days (&days, &alm->time);spin_lock_irqsave (&davinci_rtc_lock, flags);
@@ -469,6 +463,8 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)return PTR_ERR (davinci_rtc->rtc); davinci_rtc->rtc->ops = &davinci_rtc_ops; + davinci_rtc->rtc->range_min =RTC_TIMESTAMP_BEGIN_2000 ; + davinci_rtc->rtc->range_max =RTC_TIMESTAMP_BEGIN_2000 + (1 <<16 ) *86400ULL -1 ;rtcif_write (davinci_rtc,PRTCIF_INTFLG_RTCSS ,PRTCIF_INTFLG );rtcif_write (davinci_rtc,0 ,PRTCIF_INTEN );
Signature · 1 line
2.24.1
Alexandre Belloni
maintainerPATCH 4/4 rtc: davinci: remove useless error handling
In reply to Alexandre Belloniconvertfromdays and convert2days never return errors, stop handling non existent errors.
--- drivers/rtc/rtc-davinci.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/rtc/rtc-davinci.c +4 -9
@@ -227,7 +227,7 @@ davinci_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)return ret; } -static int convertfromdays (u16 days,struct rtc_time *tm) +static void convertfromdays (u16 days,struct rtc_time *tm) {int tmp_days, year, mon;
@@ -250,10 +250,9 @@ static int convertfromdays(u16 days, struct rtc_time *tm)break ; } } -return 0 ; } -static int convert2days (u16 *days,struct rtc_time *tm) +static void convert2days (u16 *days,struct rtc_time *tm) {int i; *days =0 ;
@@ -262,8 +261,6 @@ static int convert2days(u16 *days, struct rtc_time *tm) *days +=rtc_year_days (1 ,12 , i); *days +=rtc_year_days (tm->tm_mday, tm->tm_mon,1900 + tm->tm_year); - -return 0 ; }static int davinci_rtc_read_time (struct device *dev,struct rtc_time *tm)
@@ -296,8 +293,7 @@ static int davinci_rtc_read_time(struct device *dev, struct rtc_time *tm) days <<=8 ; days |= day0; -if (convertfromdays (days, tm) <0 ) -return -EINVAL ; +convertfromdays (days, tm);return 0 ; }
@@ -391,8 +387,7 @@ static int davinci_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) days <<=8 ; days |= day0; -if (convertfromdays (days, &alm->time) <0 ) -return -EINVAL ; +convertfromdays (days, &alm->time); alm->pending = !!(rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL) &
Signature · 1 line
2.24.1