2020-03-06 07:36:29

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 1/3] rtc: da9052: convert to devm_rtc_allocate_device

This allows further improvement of the driver.

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/rtc/rtc-da9052.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 204eb7cf1aa4..e159c5911122 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -298,12 +298,12 @@ static int da9052_rtc_probe(struct platform_device *pdev)
rtc_err(rtc, "Failed to disable TICKS: %d\n", ret);

device_init_wakeup(&pdev->dev, true);
- rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
- &da9052_rtc_ops, THIS_MODULE);
-
+ rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc))
return PTR_ERR(rtc->rtc);

+ rtc->rtc->ops = &da9052_rtc_ops;
+
ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM",
da9052_rtc_irq, rtc);
if (ret != 0) {
@@ -311,7 +311,7 @@ static int da9052_rtc_probe(struct platform_device *pdev)
return ret;
}

- return 0;
+ return rtc_register_device(rtc->rtc);
}

static struct platform_driver da9052_rtc_driver = {
--
2.24.1


2020-03-06 07:36:33

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 2/3] rtc: da9052: set range

The da9052 is an rtc valid from 2000 to 2063 (max year is 63).

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/rtc/rtc-da9052.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index e159c5911122..27cde834a1b8 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -303,6 +303,8 @@ static int da9052_rtc_probe(struct platform_device *pdev)
return PTR_ERR(rtc->rtc);

rtc->rtc->ops = &da9052_rtc_ops;
+ rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+ rtc->rtc->range_max = RTC_TIMESTAMP_END_2063;

ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM",
da9052_rtc_irq, rtc);
--
2.24.1

2020-03-06 07:37:30

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 3/3] rtc: da9052: switch to rtc_time64_to_tm/rtc_tm_to_time64

Call the 64bit versions of rtc_tm time conversion.

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/rtc/rtc-da9052.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 27cde834a1b8..1c567f86ee30 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -103,13 +103,11 @@ static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm)
int ret;
uint8_t v[3];

- ret = rtc_tm_to_time(rtc_tm, &alm_time);
- if (ret != 0)
- return ret;
+ alm_time = rtc_tm_to_time64(rtc_tm);

if (rtc_tm->tm_sec > 0) {
alm_time += 60 - rtc_tm->tm_sec;
- rtc_time_to_tm(alm_time, rtc_tm);
+ rtc_time64_to_tm(alm_time, rtc_tm);
}
BUG_ON(rtc_tm->tm_sec); /* it will cause repeated irqs if not zero */

--
2.24.1

2020-03-12 17:14:22

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH 1/3] rtc: da9052: convert to devm_rtc_allocate_device

On 06 March 2020 07:36, Alexandre Belloni wrote:

> This allows further improvement of the driver.
>
> Signed-off-by: Alexandre Belloni <[email protected]>
> ---
> drivers/rtc/rtc-da9052.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
> index 204eb7cf1aa4..e159c5911122 100644
> --- a/drivers/rtc/rtc-da9052.c
> +++ b/drivers/rtc/rtc-da9052.c
> @@ -298,12 +298,12 @@ static int da9052_rtc_probe(struct platform_device
> *pdev)
> rtc_err(rtc, "Failed to disable TICKS: %d\n", ret);
>
> device_init_wakeup(&pdev->dev, true);
> - rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> - &da9052_rtc_ops, THIS_MODULE);
> -
> + rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
> if (IS_ERR(rtc->rtc))
> return PTR_ERR(rtc->rtc);
>
> + rtc->rtc->ops = &da9052_rtc_ops;
> +
> ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM",
> da9052_rtc_irq, rtc);
> if (ret != 0) {
> @@ -311,7 +311,7 @@ static int da9052_rtc_probe(struct platform_device
> *pdev)
> return ret;
> }
>
> - return 0;
> + return rtc_register_device(rtc->rtc);

It seems with this change there's no tidy up around the IRQ.
da9052_request_irq() isn't calling a devm_* function so I'm not sure how the
IRQ is being freed on failure. In actual fact it looks like there's no _remove()
function for this driver which, although that's a separate topic.

> }
>
> static struct platform_driver da9052_rtc_driver = {
> --
> 2.24.1

2020-03-12 17:17:23

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH 2/3] rtc: da9052: set range

On 06 March 2020 07:36, Alexandre Belloni wrote:

> The da9052 is an rtc valid from 2000 to 2063 (max year is 63).
>
> Signed-off-by: Alexandre Belloni <[email protected]>

Acked-by: Adam Thomson <[email protected]>

> ---
> drivers/rtc/rtc-da9052.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
> index e159c5911122..27cde834a1b8 100644
> --- a/drivers/rtc/rtc-da9052.c
> +++ b/drivers/rtc/rtc-da9052.c
> @@ -303,6 +303,8 @@ static int da9052_rtc_probe(struct platform_device
> *pdev)
> return PTR_ERR(rtc->rtc);
>
> rtc->rtc->ops = &da9052_rtc_ops;
> + rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> + rtc->rtc->range_max = RTC_TIMESTAMP_END_2063;
>
> ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM",
> da9052_rtc_irq, rtc);
> --
> 2.24.1

2020-03-12 17:27:16

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH 3/3] rtc: da9052: switch to rtc_time64_to_tm/rtc_tm_to_time64

On 06 March 2020 07:36, Alexandre Belloni wrote:

> Call the 64bit versions of rtc_tm time conversion.
>
> Signed-off-by: Alexandre Belloni <[email protected]>

Acked-by: Adam Thomson <[email protected]>

> ---
> drivers/rtc/rtc-da9052.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
> index 27cde834a1b8..1c567f86ee30 100644
> --- a/drivers/rtc/rtc-da9052.c
> +++ b/drivers/rtc/rtc-da9052.c
> @@ -103,13 +103,11 @@ static int da9052_set_alarm(struct da9052_rtc *rtc,
> struct rtc_time *rtc_tm)
> int ret;
> uint8_t v[3];
>
> - ret = rtc_tm_to_time(rtc_tm, &alm_time);
> - if (ret != 0)
> - return ret;
> + alm_time = rtc_tm_to_time64(rtc_tm);
>
> if (rtc_tm->tm_sec > 0) {
> alm_time += 60 - rtc_tm->tm_sec;
> - rtc_time_to_tm(alm_time, rtc_tm);
> + rtc_time64_to_tm(alm_time, rtc_tm);
> }
> BUG_ON(rtc_tm->tm_sec); /* it will cause repeated irqs if not zero */
>
> --
> 2.24.1