linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device
@ 2019-06-20 18:34 Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 2/4] rtc: pcf2123: let the core handle range offsetting Alexandre Belloni
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alexandre Belloni @ 2019-06-20 18:34 UTC (permalink / raw)
  To: linux-rtc; +Cc: Dylan Howey, linux-kernel, Alexandre Belloni

This allows further improvement of the driver.

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

diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index e8100af789ef..29e09ff57f89 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -411,14 +411,9 @@ static int pcf2123_probe(struct spi_device *spi)
 			(spi->max_speed_hz + 500) / 1000);
 
 	/* Finalize the initialization */
-	rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
-			&pcf2123_rtc_ops, THIS_MODULE);
-
-	if (IS_ERR(rtc)) {
-		dev_err(&spi->dev, "failed to register.\n");
-		ret = PTR_ERR(rtc);
-		goto kfree_exit;
-	}
+	rtc = devm_rtc_allocate_device(&spi->dev);
+	if (IS_ERR(rtc))
+		return PTR_ERR(rtc);
 
 	pdata->rtc = rtc;
 
@@ -438,7 +433,18 @@ static int pcf2123_probe(struct spi_device *spi)
 	 * support to this driver to generate interrupts more than once
 	 * per minute.
 	 */
-	pdata->rtc->uie_unsupported = 1;
+	rtc->uie_unsupported = 1;
+	rtc->ops = &pcf2123_rtc_ops;
+
+	ret = rtc_register_device(rtc);
+	if (ret)
+		return ret;
+
+	if (IS_ERR(rtc)) {
+		dev_err(&spi->dev, "failed to register.\n");
+		ret = PTR_ERR(rtc);
+		goto kfree_exit;
+	}
 
 	return 0;
 
-- 
2.21.0


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

* [PATCH 2/4] rtc: pcf2123: let the core handle range offsetting
  2019-06-20 18:34 [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
@ 2019-06-20 18:34 ` Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 3/4] rtc: pcf2123: convert to SPDX identifier Alexandre Belloni
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2019-06-20 18:34 UTC (permalink / raw)
  To: linux-rtc; +Cc: Dylan Howey, linux-kernel, Alexandre Belloni

Set the RTC range properly and use the core windowing and offsetting to
(unfortunately) map back to a 1970-2069 range.

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

diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 29e09ff57f89..d263c8bab62a 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -198,9 +198,7 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F);
 	tm->tm_wday = rxbuf[4] & 0x07;
 	tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */
-	tm->tm_year = bcd2bin(rxbuf[6]);
-	if (tm->tm_year < 70)
-		tm->tm_year += 100;	/* assume we are in 1970...2069 */
+	tm->tm_year = bcd2bin(rxbuf[6]) + 100;
 
 	dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm);
 
@@ -227,7 +225,7 @@ static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	txbuf[3] = bin2bcd(tm->tm_mday & 0x3F);
 	txbuf[4] = tm->tm_wday & 0x07;
 	txbuf[5] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */
-	txbuf[6] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100);
+	txbuf[6] = bin2bcd(tm->tm_year - 100);
 
 	ret = regmap_bulk_write(pdata->map, PCF2123_REG_SC, txbuf,
 				sizeof(txbuf));
@@ -435,6 +433,9 @@ static int pcf2123_probe(struct spi_device *spi)
 	 */
 	rtc->uie_unsupported = 1;
 	rtc->ops = &pcf2123_rtc_ops;
+	rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+	rtc->range_max = RTC_TIMESTAMP_END_2099;
+	rtc->set_start_time = true;
 
 	ret = rtc_register_device(rtc);
 	if (ret)
-- 
2.21.0


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

* [PATCH 3/4] rtc: pcf2123: convert to SPDX identifier
  2019-06-20 18:34 [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 2/4] rtc: pcf2123: let the core handle range offsetting Alexandre Belloni
@ 2019-06-20 18:34 ` Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 4/4] rtc: pcf2123: add proper compatible string Alexandre Belloni
  2019-06-20 19:43 ` [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2019-06-20 18:34 UTC (permalink / raw)
  To: linux-rtc; +Cc: Dylan Howey, linux-kernel, Alexandre Belloni

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

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

diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index d263c8bab62a..f31feffed2d2 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * An SPI driver for the Philips PCF2123 RTC
  * Copyright 2009 Cyber Switching, Inc.
@@ -10,10 +11,6 @@
  * Thanks to Christian Pellegrin <chripell@fsfe.org> for
  * the sysfs contributions to this driver.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
  * Please note that the CS is active high, so platform data
  * should look something like:
  *
-- 
2.21.0


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

* [PATCH 4/4] rtc: pcf2123: add proper compatible string
  2019-06-20 18:34 [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 2/4] rtc: pcf2123: let the core handle range offsetting Alexandre Belloni
  2019-06-20 18:34 ` [PATCH 3/4] rtc: pcf2123: convert to SPDX identifier Alexandre Belloni
@ 2019-06-20 18:34 ` Alexandre Belloni
  2019-06-20 19:43 ` [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2019-06-20 18:34 UTC (permalink / raw)
  To: linux-rtc; +Cc: Dylan Howey, linux-kernel, Alexandre Belloni

nxp,rtc-pcf2123 is not a proper compatible strong for this RTC. The part
name is only pcf2123 and is less confusing.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt | 4 ++--
 drivers/rtc/rtc-pcf2123.c                              | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
index 1994f601800a..7371f525a687 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
+++ b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
@@ -1,7 +1,7 @@
 NXP PCF2123 SPI Real Time Clock
 
 Required properties:
-- compatible: should be: "nxp,rtc-pcf2123"
+- compatible: should be: "nxp,pcf2123"
                       or "microcrystal,rv2123"
 - reg: should be the SPI slave chipselect address
 
@@ -11,7 +11,7 @@ Optional properties:
 Example:
 
 pcf2123: rtc@3 {
-	compatible = "nxp,rtc-pcf2123"
+	compatible = "nxp,pcf2123"
 	reg = <3>
 	spi-cs-high;
 };
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index f31feffed2d2..2ac016cb2af6 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -453,8 +453,10 @@ static int pcf2123_probe(struct spi_device *spi)
 
 #ifdef CONFIG_OF
 static const struct of_device_id pcf2123_dt_ids[] = {
-	{ .compatible = "nxp,rtc-pcf2123", },
+	{ .compatible = "nxp,pcf2123", },
 	{ .compatible = "microcrystal,rv2123", },
+	/* Deprecated, do not use */
+	{ .compatible = "nxp,rtc-pcf2123", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, pcf2123_dt_ids);
-- 
2.21.0


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

* Re: [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device
  2019-06-20 18:34 [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
                   ` (2 preceding siblings ...)
  2019-06-20 18:34 ` [PATCH 4/4] rtc: pcf2123: add proper compatible string Alexandre Belloni
@ 2019-06-20 19:43 ` Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2019-06-20 19:43 UTC (permalink / raw)
  To: linux-rtc; +Cc: Dylan Howey, linux-kernel

On 20/06/2019 20:34:30+0200, Alexandre Belloni wrote:
> This allows further improvement of the driver.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-pcf2123.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
> index e8100af789ef..29e09ff57f89 100644
> --- a/drivers/rtc/rtc-pcf2123.c
> +++ b/drivers/rtc/rtc-pcf2123.c
> @@ -411,14 +411,9 @@ static int pcf2123_probe(struct spi_device *spi)
>  			(spi->max_speed_hz + 500) / 1000);
>  
>  	/* Finalize the initialization */
> -	rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
> -			&pcf2123_rtc_ops, THIS_MODULE);
> -
> -	if (IS_ERR(rtc)) {
> -		dev_err(&spi->dev, "failed to register.\n");
> -		ret = PTR_ERR(rtc);
> -		goto kfree_exit;
> -	}
> +	rtc = devm_rtc_allocate_device(&spi->dev);
> +	if (IS_ERR(rtc))
> +		return PTR_ERR(rtc);
>  
>  	pdata->rtc = rtc;
>  
> @@ -438,7 +433,18 @@ static int pcf2123_probe(struct spi_device *spi)
>  	 * support to this driver to generate interrupts more than once
>  	 * per minute.
>  	 */
> -	pdata->rtc->uie_unsupported = 1;
> +	rtc->uie_unsupported = 1;
> +	rtc->ops = &pcf2123_rtc_ops;
> +
> +	ret = rtc_register_device(rtc);
> +	if (ret)
> +		return ret;
> +
> +	if (IS_ERR(rtc)) {
> +		dev_err(&spi->dev, "failed to register.\n");
> +		ret = PTR_ERR(rtc);
> +		goto kfree_exit;
> +	}
>  

I need to rework that part, I'll resend...

>  	return 0;
>  
> -- 
> 2.21.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-06-20 19:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 18:34 [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device Alexandre Belloni
2019-06-20 18:34 ` [PATCH 2/4] rtc: pcf2123: let the core handle range offsetting Alexandre Belloni
2019-06-20 18:34 ` [PATCH 3/4] rtc: pcf2123: convert to SPDX identifier Alexandre Belloni
2019-06-20 18:34 ` [PATCH 4/4] rtc: pcf2123: add proper compatible string Alexandre Belloni
2019-06-20 19:43 ` [PATCH 1/4] rtc: pcf2123: convert to devm_rtc_allocate_device 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).