Skip to contentSkip to conversation

rtc: ls1x: switch to rtc_register_device

PATCH New Alexandre Belloni 1 participant 3 messages May 17, 2018 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/3 rtc: ls1x: switch to rtc_register_device

This allows for future improvement of the driver.

---
 drivers/rtc/rtc-ls1x.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/rtc/rtc-ls1x.c +7 -7
index de86f9fabc11..609bd1d013f0 100644
@@ -173,15 +173,15 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
 	while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS)
 		usleep_range(1000, 3000);
 
-	rtcdev = devm_rtc_device_register(&pdev->dev, "ls1x-rtc",
-					&ls1x_rtc_ops , THIS_MODULE);
-	if (IS_ERR(rtcdev)) {
-		ret = PTR_ERR(rtcdev);
-		goto err;
-	}
+	rtcdev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtcdev))
+		return PTR_ERR(rtcdev);
 
 	platform_set_drvdata(pdev, rtcdev);
-	return 0;
+	rtcdev->ops = &ls1x_rtc_ops;
+
+	return rtc_register_device(rtcdev);
+
 err:
 	return ret;
 }
Signature · 1 line
2.17.0
author maintainer
#1 lore raw

PATCH 2/3 rtc: ls1x: remove useless label and goto

The error handling in ls1x_rtc_probe used to release resources but since it is using devm functions, it only returns a value. Make the code clearer by returning directly instead of using goto.

---
 drivers/rtc/rtc-ls1x.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/rtc/rtc-ls1x.c +3 -8
index 609bd1d013f0..8aa3f223621c 100644
@@ -148,15 +148,13 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
 {
 	struct rtc_device *rtcdev;
 	unsigned long v;
-	int ret;
 
 	v = readl(SYS_COUNTER_CNTRL);
 	if (!(v & RTC_CNTR_OK)) {
 		dev_err(&pdev->dev, "rtc counters not working\n");
-		ret = -ENODEV;
-		goto err;
+		return -ENODEV;
 	}
-	ret = -ETIMEDOUT;
+
 	/* set to 1 HZ if needed */
 	if (readl(SYS_TOYTRIM) != 32767) {
 		v = 0x100000;
@@ -165,7 +163,7 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
 
 		if (!v) {
 			dev_err(&pdev->dev, "time out\n");
-			goto err;
+			return -ETIMEDOUT;
 		}
 		writel(32767, SYS_TOYTRIM);
 	}
@@ -181,9 +179,6 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
 	rtcdev->ops = &ls1x_rtc_ops;
 
 	return rtc_register_device(rtcdev);
-
-err:
-	return ret;
 }
 
 static struct platform_driver  ls1x_rtc_driver = {
Signature · 1 line
2.17.0
author maintainer
#2 lore raw

PATCH 3/3 rtc: ls1x: add range

In reply to Alexandre Belloni

While the year in encoded on 32 bits in SYS_TOYWRITE1i/SYS_TOYREAD1. The Loongson 1c datasheet states that the range is from 0 to 99.

The current code exceeds this range and seems to be working, I deduce that the leap year algorithm will fail in 2100.

Anyway, alarm registers only encode the year on 14 bits so with alarm support, the range will always be limited to 0 to 16383.

---
 drivers/rtc/rtc-ls1x.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/rtc/rtc-ls1x.c +2 -0
index 8aa3f223621c..f4c248655edd 100644
@@ -177,6 +177,8 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, rtcdev);
 	rtcdev->ops = &ls1x_rtc_ops;
+	rtcdev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+	rtcdev->range_max = RTC_TIMESTAMP_END_2099;
 
 	return rtc_register_device(rtcdev);
 }
Signature · 1 line
2.17.0