Skip to contentSkip to conversation

rtc: au1xxx: convert to devm_rtc_allocate_device

PATCH New Alexandre Belloni 1 participant 4 messages Mar 6, 2020 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/4 rtc: au1xxx: convert to devm_rtc_allocate_device

This allows further improvement of the driver.

---
 drivers/rtc/rtc-au1xxx.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/rtc/rtc-au1xxx.c +6 -7
index 7c5530c71285..a13ac73aa2b7 100644
@@ -99,16 +99,15 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
 	while (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C0S)
 		msleep(1);
 
-	rtcdev = devm_rtc_device_register(&pdev->dev, "rtc-au1xxx",
-				     &au1xtoy_rtc_ops, THIS_MODULE);
-	if (IS_ERR(rtcdev)) {
-		ret = PTR_ERR(rtcdev);
-		goto out_err;
-	}
+	rtcdev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtcdev))
+		return PTR_ERR(rtcdev);
+
+	rtcdev->ops = &au1xtoy_rtc_ops;
 
 	platform_set_drvdata(pdev, rtcdev);
 
-	return 0;
+	return rtc_register_device(rtcdev);
 
 out_err:
 	return ret;
Signature · 1 line
2.24.1
author maintainer
#1 lore raw

PATCH 2/4 rtc: au1xxx: remove goto label

Simplify the driver by removing the goto label as it only does return ret.

---
 drivers/rtc/rtc-au1xxx.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/rtc/rtc-au1xxx.c +2 -9
index a13ac73aa2b7..73aeb15f9491 100644
@@ -65,17 +65,13 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
 {
 	struct rtc_device *rtcdev;
 	unsigned long t;
-	int ret;
 
 	t = alchemy_rdsys(AU1000_SYS_CNTRCTRL);
 	if (!(t & CNTR_OK)) {
 		dev_err(&pdev->dev, "counters not working; aborting.\n");
-		ret = -ENODEV;
-		goto out_err;
+		return -ENODEV;
 	}
 
-	ret = -ETIMEDOUT;
-
 	/* set counter0 tickrate to 1Hz if necessary */
 	if (alchemy_rdsys(AU1000_SYS_TOYTRIM) != 32767) {
 		/* wait until hardware gives access to TRIM register */
@@ -88,7 +84,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
 			 * counters are unusable.
 			 */
 			dev_err(&pdev->dev, "timeout waiting for access\n");
-			goto out_err;
+			return -ETIMEDOUT;
 		}
 
 		/* set 1Hz TOY tick rate */
@@ -108,9 +104,6 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, rtcdev);
 
 	return rtc_register_device(rtcdev);
-
-out_err:
-	return ret;
 }
 
 static struct platform_driver au1xrtc_driver = {
Signature · 1 line
2.24.1
author maintainer
#2 lore raw

PATCH 3/4 rtc: au1xxx: set range

In reply to Alexandre Belloni

The Alchemy counter0 is a 32bit seconds counter.

---
 drivers/rtc/rtc-au1xxx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/rtc/rtc-au1xxx.c +1 -0
index 73aeb15f9491..e186fb5cfffd 100644
@@ -100,6 +100,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(rtcdev);
 
 	rtcdev->ops = &au1xtoy_rtc_ops;
+	rtcdev->range_max = U32_MAX;
 
 	platform_set_drvdata(pdev, rtcdev);
 
Signature · 1 line
2.24.1
author maintainer
#3 lore raw

PATCH 4/4 rtc: au1xxx: switch to rtc_time64_to_tm/rtc_tm_to_time64

In reply to Alexandre Belloni

Call the 64bit versions of rtc_tm time conversion.

---
 drivers/rtc/rtc-au1xxx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-au1xxx.c +2 -2
index e186fb5cfffd..791bebcb6f47 100644
@@ -34,7 +34,7 @@ static int au1xtoy_rtc_read_time(struct device *dev, struct rtc_time *tm)
 
 	t = alchemy_rdsys(AU1000_SYS_TOYREAD);
 
-	rtc_time_to_tm(t, tm);
+	rtc_time64_to_tm(t, tm);
 
 	return 0;
 }
@@ -43,7 +43,7 @@ static int au1xtoy_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
 	unsigned long t;
 
-	rtc_tm_to_time(tm, &t);
+	t = rtc_tm_to_time64(tm);
 
 	alchemy_wrsys(t, AU1000_SYS_TOYWRITE);
 
Signature · 1 line
2.24.1