rtc: s5m: switch to devm_rtc_allocate_device
Alexandre Belloni
maintainerPATCH 1/4 rtc: s5m: switch to devm_rtc_allocate_device
Switch to devm_rtc_allocate_device/devm_rtc_register_device, this allows for further improvement of the driver.
--- drivers/rtc/rtc-s5m.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/rtc/rtc-s5m.c +7 -3
@@ -788,12 +788,16 @@ static int s5m_rtc_probe(struct platform_device *pdev)device_init_wakeup (&pdev->dev,1 ); - info->rtc_dev =devm_rtc_device_register (&pdev->dev,"s5m-rtc" , - &s5m_rtc_ops,THIS_MODULE ); - + info->rtc_dev =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (info->rtc_dev))return PTR_ERR (info->rtc_dev); + info->rtc_dev->ops = &s5m_rtc_ops; + + err =devm_rtc_register_device (info->rtc_dev); +if (err) +return err; +if (!info->irq) {dev_info (&pdev->dev,"Alarm IRQ not available\n" );return 0 ;
Signature · 1 line
2.31.1
Alexandre Belloni
maintainerPATCH 2/4 rtc: s5m: signal the core when alarm are not available
Clear the RTC_FEATURE_ALARM bit to signal to the core when alarms are not available to ensure the alarm callbacks are never called and userspace is aware alarms are not supported.
--- drivers/rtc/rtc-s5m.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
drivers/rtc/rtc-s5m.c +11 -16
@@ -794,25 +794,20 @@ static int s5m_rtc_probe(struct platform_device *pdev) info->rtc_dev->ops = &s5m_rtc_ops; - err =devm_rtc_register_device (info->rtc_dev); -if (err) -return err; -if (!info->irq) { -dev_info (&pdev->dev,"Alarm IRQ not available\n" ); -return 0 ; - } - - ret =devm_request_threaded_irq (&pdev->dev, info->irq,NULL , - s5m_rtc_alarm_irq,0 ,"rtc-alarm0" , - info); -if (ret <0 ) { -dev_err (&pdev->dev,"Failed to request alarm IRQ: %d: %d\n" , - info->irq, ret); -return ret; +clear_bit (RTC_FEATURE_ALARM , info->rtc_dev->features); + }else { + ret =devm_request_threaded_irq (&pdev->dev, info->irq,NULL , + s5m_rtc_alarm_irq,0 ,"rtc-alarm0" , + info); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to request alarm IRQ: %d: %d\n" , + info->irq, ret); +return ret; + } } -return 0 ; +return devm_rtc_register_device (info->rtc_dev); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.31.1
Re: [PATCH 2/4] rtc: s5m: signal the core when alarm are not available
Quoted 9 lines · Alexandre Belloni
Clear the
RTC_FEATURE_ALARMbit to signal to the core when alarms are not available to ensure the alarm callbacks are never called and userspace is aware alarms are not supported.Signed-off-by Alexandre Belloni <[email protected]>--- drivers/rtc/rtc-s5m.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
Best regards,
Krzysztof
Alexandre Belloni
maintainerPATCH 3/4 rtc: s5m: enable wakeup only when available
In reply to Alexandre BelloniCall device_init_wakeup() only when alarms are available and the RTC is actually able to wake up the system.
--- drivers/rtc/rtc-s5m.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/rtc/rtc-s5m.c +1 -2
@@ -786,8 +786,6 @@ static int s5m_rtc_probe(struct platform_device *pdev)if (ret)return ret; -device_init_wakeup (&pdev->dev,1 ); - info->rtc_dev =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (info->rtc_dev))return PTR_ERR (info->rtc_dev);
@@ -805,6 +803,7 @@ static int s5m_rtc_probe(struct platform_device *pdev) info->irq, ret);return ret; } +device_init_wakeup (&pdev->dev,1 ); }return devm_rtc_register_device (info->rtc_dev);
Signature · 1 line
2.31.1
Re: [PATCH 3/4] rtc: s5m: enable wakeup only when available
Quoted 7 lines · Alexandre Belloni
Call
device_init_wakeup()only when alarms are available and the RTC is actually able to wake up the system.Signed-off-by Alexandre Belloni <[email protected]>--- drivers/rtc/rtc-s5m.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Best regards,
Krzysztof
Alexandre Belloni
maintainerPATCH 4/4 rtc: s5m: set range
In reply to Alexandre BelloniThe S5M8763X type seems to handles dates from year 0000 to 9999, there is no info on leap year handling after 2099. The other models handles dates from 2000 to 2099.
--- drivers/rtc/rtc-s5m.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/rtc/rtc-s5m.c +10 -8
@@ -204,15 +204,9 @@ static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data) data[RTC_WEEKDAY ] =1 << tm->tm_wday; data[RTC_DATE ] = tm->tm_mday; data[RTC_MONTH ] = tm->tm_mon +1 ; - data[RTC_YEAR1 ] = tm->tm_year >100 ? (tm->tm_year -100 ) :0 ; + data[RTC_YEAR1 ] = tm->tm_year -100 ; -if (tm->tm_year <100 ) { -pr_err ("RTC cannot handle the year %d\n" , -1900 + tm->tm_year); -return -EINVAL ; - }else { -return 0 ; - } +return 0 ; }/*
@@ -792,6 +786,14 @@ static int s5m_rtc_probe(struct platform_device *pdev) info->rtc_dev->ops = &s5m_rtc_ops; +if (info->device_type ==S5M8763X ) { + info->rtc_dev->range_min =RTC_TIMESTAMP_BEGIN_0000 ; + info->rtc_dev->range_max =RTC_TIMESTAMP_END_9999 ; + }else { + info->rtc_dev->range_min =RTC_TIMESTAMP_BEGIN_2000 ; + info->rtc_dev->range_max =RTC_TIMESTAMP_END_2099 ; + } +if (!info->irq) {clear_bit (RTC_FEATURE_ALARM , info->rtc_dev->features); }else {
Signature · 1 line
2.31.1
Re: [PATCH 4/4] rtc: s5m: set range
Quoted 9 lines · Alexandre Belloni
The S5M8763X type seems to handles dates from year 0000 to 9999, there is no info on leap year handling after 2099. The other models handles dates from 2000 to 2099.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/rtc/rtc-s5m.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
Seems correct:
Best regards,
Krzysztof
Quoted 8 lines · Alexandre Belloni
Switch to devm_rtc_allocate_device/devm_rtc_register_device, this allows for further improvement of the driver.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/rtc/rtc-s5m.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Best regards,
Krzysztof