Skip to contentSkip to conversation

rtc: wm831x: set range

PATCH New Alexandre Belloni 1 participant 4 messages Mar 22, 2019

Subsystems (2)
lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/4 rtc: wm831x: set range

The wm831x has a 32bit second counter.

---
 drivers/rtc/rtc-wm831x.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/rtc/rtc-wm831x.c +10 -6
index 7b824dabf104..deaffe0eaf2f 100644
@@ -436,12 +436,16 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
-					      &wm831x_rtc_ops, THIS_MODULE);
-	if (IS_ERR(wm831x_rtc->rtc)) {
-		ret = PTR_ERR(wm831x_rtc->rtc);
-		goto err;
-	}
+	wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(wm831x_rtc->rtc))
+		return PTR_ERR(wm831x_rtc->rtc);
+
+	wm831x_rtc->rtc->ops = &wm831x_rtc_ops;
+	wm831x_rtc->rtc->range_max = U32_MAX;
+
+	ret = rtc_register_device(wm831x_rtc->rtc);
+	if (ret)
+		return ret;
 
 	ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
 				wm831x_alm_irq,
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/4 rtc: wm831x: remove unnecessary goto

There is no specific handling in the error path of wm831x_rtc_probe, remove the unnecessary goto and label.

---
 drivers/rtc/rtc-wm831x.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/rtc/rtc-wm831x.c +1 -4
index deaffe0eaf2f..1b0c3b3f63e8 100644
@@ -429,7 +429,7 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
 	ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
-		goto err;
+		return ret;
 	}
 	if (ret & WM831X_RTC_ALM_ENA)
 		wm831x_rtc->alarm_enabled = 1;
@@ -459,9 +459,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
 	wm831x_rtc_add_randomness(wm831x);
 
 	return 0;
-
-err:
-	return ret;
 }
 
 static const struct dev_pm_ops wm831x_rtc_pm_ops = {
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 3/4 rtc: wm831x: switch to rtc_time64_to_tm/rtc_tm_to_time64

In reply to Alexandre Belloni

Call the 64bit versions of rtc_tm time conversion now that the range is enforced by the core.

---
 drivers/rtc/rtc-wm831x.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/rtc/rtc-wm831x.c +4 -12
index 1b0c3b3f63e8..d286dd1dfcf9 100644
@@ -155,7 +155,7 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
 		if (memcmp(time1, time2, sizeof(time1)) == 0) {
 			u32 time = (time1[0] << 16) | time1[1];
 
-			rtc_time_to_tm(time, tm);
+			rtc_time64_to_tm(time, tm);
 			return 0;
 		}
 
@@ -215,11 +215,7 @@ static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time)
 	if (ret < 0)
 		return ret;
 
-	ret = rtc_tm_to_time(&new_tm, &new_time);
-	if (ret < 0) {
-		dev_err(dev, "Failed to convert time: %d\n", ret);
-		return ret;
-	}
+	new_time = rtc_tm_to_time64(&new_tm);
 
 	/* Allow a second of change in case of tick */
 	if (new_time - time > 1) {
@@ -249,7 +245,7 @@ static int wm831x_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 	time = (data[0] << 16) | data[1];
 
-	rtc_time_to_tm(time, &alrm->time);
+	rtc_time64_to_tm(time, &alrm->time);
 
 	ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL);
 	if (ret < 0) {
@@ -288,11 +284,7 @@ static int wm831x_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	int ret;
 	unsigned long time;
 
-	ret = rtc_tm_to_time(&alrm->time, &time);
-	if (ret < 0) {
-		dev_err(dev, "Failed to convert time: %d\n", ret);
-		return ret;
-	}
+	time = rtc_tm_to_time64(&alrm->time);
 
 	ret = wm831x_rtc_stop_alarm(wm831x_rtc);
 	if (ret < 0) {
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 4/4 rtc: wm831x: convert to SPDX identifier

In reply to Alexandre Belloni

Use SPDX-License-Identifier instead of a verbose license text.

---
 drivers/rtc/rtc-wm831x.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/rtc/rtc-wm831x.c +1 -5
index d286dd1dfcf9..6a0defd16088 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  *	Real Time Clock driver for Wolfson Microelectronics WM831x
  *
@@ -5,11 +6,6 @@
  *
  *  Author: Mark Brown <[email protected]>
  *
- *  This program is free software; you can redistribute  it and/or modify it
- *  under  the terms of  the GNU General  Public License as published by the
- *  Free Software Foundation;  either version 2 of the  License, or (at your
- *  option) any later version.
- *
  */
 
 #include <linux/module.h>
Signature · 1 line
2.20.1