linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] rtc: r9701: remove leftover comment
@ 2020-10-15 19:11 Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 2/6] rtc: r9701: stop setting a default time Alexandre Belloni
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

Commit 22652ba72453 ("rtc: stop validating rtc_time in .read_time") removed
the code but not the associated comment.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-r9701.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 84f0d25259ae..eb00879f7c9a 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -85,10 +85,6 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
 	dt->tm_mon = bcd2bin(buf[4]) - 1; /* RMONCNT */
 	dt->tm_year = bcd2bin(buf[5]) + 100; /* RYRCNT */
 
-	/* the rtc device may contain illegal values on power up
-	 * according to the data sheet. make sure they are valid.
-	 */
-
 	return 0;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/6] rtc: r9701: stop setting a default time
  2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
@ 2020-10-15 19:11 ` Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 3/6] rtc: r9701: remove useless memset Alexandre Belloni
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

It doesn't make sense to set the RTC to a default value at probe time. Let
the core handle invalid date and time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-r9701.c | 22 ----------------------
 1 file changed, 22 deletions(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index eb00879f7c9a..f8f7044ff808 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -115,7 +115,6 @@ static const struct rtc_class_ops r9701_rtc_ops = {
 static int r9701_probe(struct spi_device *spi)
 {
 	struct rtc_device *rtc;
-	struct rtc_time dt;
 	unsigned char tmp;
 	int res;
 
@@ -126,27 +125,6 @@ static int r9701_probe(struct spi_device *spi)
 		return -ENODEV;
 	}
 
-	/*
-	 * The device seems to be present. Now check if the registers
-	 * contain invalid values. If so, try to write a default date:
-	 * 2000/1/1 00:00:00
-	 */
-	if (r9701_get_datetime(&spi->dev, &dt)) {
-		dev_info(&spi->dev, "trying to repair invalid date/time\n");
-		dt.tm_sec  = 0;
-		dt.tm_min  = 0;
-		dt.tm_hour = 0;
-		dt.tm_mday = 1;
-		dt.tm_mon  = 0;
-		dt.tm_year = 100;
-
-		if (r9701_set_datetime(&spi->dev, &dt) ||
-				r9701_get_datetime(&spi->dev, &dt)) {
-			dev_err(&spi->dev, "cannot repair RTC register\n");
-			return -ENODEV;
-		}
-	}
-
 	rtc = devm_rtc_device_register(&spi->dev, "r9701",
 				&r9701_rtc_ops, THIS_MODULE);
 	if (IS_ERR(rtc))
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/6] rtc: r9701: remove useless memset
  2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 2/6] rtc: r9701: stop setting a default time Alexandre Belloni
@ 2020-10-15 19:11 ` Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 4/6] rtc: r9701: stop setting RWKCNT Alexandre Belloni
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

The RTC core already sets to zero the struct rtc_tie it passes to the
driver, avoid doing it a second time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-r9701.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index f8f7044ff808..4b688e9c4192 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -75,8 +75,6 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
 	if (ret)
 		return ret;
 
-	memset(dt, 0, sizeof(*dt));
-
 	dt->tm_sec = bcd2bin(buf[0]); /* RSECCNT */
 	dt->tm_min = bcd2bin(buf[1]); /* RMINCNT */
 	dt->tm_hour = bcd2bin(buf[2]); /* RHRCNT */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/6] rtc: r9701: stop setting RWKCNT
  2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 2/6] rtc: r9701: stop setting a default time Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 3/6] rtc: r9701: remove useless memset Alexandre Belloni
@ 2020-10-15 19:11 ` Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 5/6] rtc: r9701: convert to devm_rtc_allocate_device Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 6/6] rtc: r9701: set range Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Dan Carpenter, linux-rtc, linux-kernel

tm_wday is never checked for validity and it is not read back in
r9701_get_datetime. Avoid setting it to stop tripping static checkers:

        drivers/rtc/rtc-r9701.c:109 r9701_set_datetime()
        error: undefined (user controlled) shift '1 << dt->tm_wday'

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
Cc: Dan Carpenter <dan.carpenter@oracle.com>

 drivers/rtc/rtc-r9701.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 4b688e9c4192..183c5a0fe78c 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -100,7 +100,6 @@ static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
 	ret = ret ? ret : write_reg(dev, RDAYCNT, bin2bcd(dt->tm_mday));
 	ret = ret ? ret : write_reg(dev, RMONCNT, bin2bcd(dt->tm_mon + 1));
 	ret = ret ? ret : write_reg(dev, RYRCNT, bin2bcd(dt->tm_year - 100));
-	ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday);
 
 	return ret;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/6] rtc: r9701: convert to devm_rtc_allocate_device
  2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
                   ` (2 preceding siblings ...)
  2020-10-15 19:11 ` [PATCH 4/6] rtc: r9701: stop setting RWKCNT Alexandre Belloni
@ 2020-10-15 19:11 ` Alexandre Belloni
  2020-10-15 19:11 ` [PATCH 6/6] rtc: r9701: set range Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

This allows further improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-r9701.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 183c5a0fe78c..9165c180b0e6 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -122,14 +122,14 @@ static int r9701_probe(struct spi_device *spi)
 		return -ENODEV;
 	}
 
-	rtc = devm_rtc_device_register(&spi->dev, "r9701",
-				&r9701_rtc_ops, THIS_MODULE);
+	rtc = devm_rtc_allocate_device(&spi->dev);
 	if (IS_ERR(rtc))
 		return PTR_ERR(rtc);
 
 	spi_set_drvdata(spi, rtc);
+	rtc->ops = &r9701_rtc_ops;
 
-	return 0;
+	return rtc_register_device(rtc);
 }
 
 static struct spi_driver r9701_driver = {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 6/6] rtc: r9701: set range
  2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
                   ` (3 preceding siblings ...)
  2020-10-15 19:11 ` [PATCH 5/6] rtc: r9701: convert to devm_rtc_allocate_device Alexandre Belloni
@ 2020-10-15 19:11 ` Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2020-10-15 19:11 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

Set range and remove the set_time check. This is a classic BCD RTC.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-r9701.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 9165c180b0e6..7ceb968f0e44 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -88,11 +88,7 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
 
 static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
 {
-	int ret, year;
-
-	year = dt->tm_year + 1900;
-	if (year >= 2100 || year < 2000)
-		return -EINVAL;
+	int ret;
 
 	ret = write_reg(dev, RHRCNT, bin2bcd(dt->tm_hour));
 	ret = ret ? ret : write_reg(dev, RMINCNT, bin2bcd(dt->tm_min));
@@ -128,6 +124,8 @@ static int r9701_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, rtc);
 	rtc->ops = &r9701_rtc_ops;
+	rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+	rtc->range_max = RTC_TIMESTAMP_END_2099;
 
 	return rtc_register_device(rtc);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-15 19:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 19:11 [PATCH 1/6] rtc: r9701: remove leftover comment Alexandre Belloni
2020-10-15 19:11 ` [PATCH 2/6] rtc: r9701: stop setting a default time Alexandre Belloni
2020-10-15 19:11 ` [PATCH 3/6] rtc: r9701: remove useless memset Alexandre Belloni
2020-10-15 19:11 ` [PATCH 4/6] rtc: r9701: stop setting RWKCNT Alexandre Belloni
2020-10-15 19:11 ` [PATCH 5/6] rtc: r9701: convert to devm_rtc_allocate_device Alexandre Belloni
2020-10-15 19:11 ` [PATCH 6/6] rtc: r9701: set range Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).