rtc: pcf2123: convert to devm_rtc_allocate_device
Subsystems (2)
Alexandre Belloni
maintainerPATCH 1/4 rtc: pcf2123: convert to devm_rtc_allocate_device
This allows further improvement of the driver.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-pcf2123.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/rtc/rtc-pcf2123.c +15 -9
@@ -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 ;
Signature · 1 line
2.21.0
Alexandre Belloni
maintainerPATCH 2/4 rtc: pcf2123: let the core handle range offsetting
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 <[email protected]>
--- drivers/rtc/rtc-pcf2123.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/rtc/rtc-pcf2123.c +5 -4
@@ -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)
Signature · 1 line
2.21.0
Alexandre Belloni
maintainerPATCH 3/4 rtc: pcf2123: convert to SPDX identifier
In reply to Alexandre BelloniUse SPDX-License-Identifier instead of a verbose license text.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-pcf2123.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/rtc/rtc-pcf2123.c +1 -4
@@ -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 <[email protected]> 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: *
Signature · 1 line
2.21.0
Alexandre Belloni
maintainerPATCH 4/4 rtc: pcf2123: add proper compatible string
In reply to Alexandre Belloninxp,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 <[email protected]>
--- Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt | 4 ++-- drivers/rtc/rtc-pcf2123.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt +2 -2
@@ -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; };
drivers/rtc/rtc-pcf2123.c +3 -1
@@ -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);
Signature · 1 line
2.21.0
Alexandre Belloni
maintainerQuoted 37 lines · Alexandre Belloni
This allows further improvement of the driver.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/rtc/rtc-pcf2123.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)drivers/rtc/rtc-pcf2123.c +6
-9@@ -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; +
drivers/rtc/rtc-pcf2123.c static int pcf2123_probe(struct spi_device *spi) · line 448
Quoted 10 lines
drivers/rtc/rtc-pcf2123.c +9
-0+ 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...
Quoted 5 lines
drivers/rtc/rtc-pcf2123.c +0
-0return 0 ;Signature · 1 line
2.21.0
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com