[PATCH 2/3] rtc: pcf85063: add support for RV8063

Antoni Pokusinski posted 3 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH 2/3] rtc: pcf85063: add support for RV8063
Posted by Antoni Pokusinski 10 months, 1 week ago
Microcrystal RV8063 is a real-time clock with SPI interface. Its
functionality is very similar to the RV8263 rtc.

Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
---
 drivers/rtc/Kconfig        | 21 ++++++-----
 drivers/rtc/rtc-pcf85063.c | 74 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 85 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 838bdc138ffe..1b9be96faa13 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-pcf8523.
 
-config RTC_DRV_PCF85063
-	tristate "NXP PCF85063"
-	select REGMAP_I2C
-	help
-	  If you say yes here you get support for the PCF85063 RTC chip
-
-	  This driver can also be built as a module. If so, the module
-	  will be called rtc-pcf85063.
-
 config RTC_DRV_PCF85363
 	tristate "NXP PCF85363"
 	select REGMAP_I2C
@@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-pcf2127.
 
+config RTC_DRV_PCF85063
+	tristate "NXP PCF85063"
+	depends on RTC_I2C_AND_SPI
+	select REGMAP_I2C if I2C
+	select REGMAP_SPI if SPI_MASTER
+	help
+	  If you say yes here you get support for the PCF85063 and RV8063
+	  RTC chips.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-pcf85063.
+
 config RTC_DRV_RV3029C2
 	tristate "Micro Crystal RV3029/3049"
 	depends on RTC_I2C_AND_SPI
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index 03dfc58f4cd7..512933479dd5 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -17,6 +17,7 @@
 #include <linux/of.h>
 #include <linux/pm_wakeirq.h>
 #include <linux/regmap.h>
+#include <linux/spi/spi.h>
 
 /*
  * Information for this driver was pulled from the following datasheets.
@@ -29,6 +30,9 @@
  *
  *  https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf
  *  RV8263 -- Rev. 1.0 — January 2019
+ *
+ *  https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8063-C7_App-Manual.pdf
+ *  RV8063 -- Rev. 1.1 - October 2018
  */
 
 #define PCF85063_REG_CTRL1		0x00 /* status */
@@ -559,6 +563,18 @@ static const struct pcf85063_config config_rv8263 = {
 	.force_cap_7000 = 1,
 };
 
+static const struct pcf85063_config config_rv8063 = {
+	.regmap = {
+		.reg_bits = 8,
+		.val_bits = 8,
+		.max_register = 0x11,
+		.read_flag_mask = BIT(7) | BIT(5),
+		.write_flag_mask = BIT(5),
+	},
+	.has_alarms = 1,
+	.force_cap_7000 = 1,
+};
+
 static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq,
 			  const struct pcf85063_config *config)
 {
@@ -725,14 +741,69 @@ static void pcf85063_unregister_driver(void)
 
 #endif /* IS_ENABLED(CONFIG_I2C) */
 
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+
+static int rv8063_probe(struct spi_device *spi)
+{
+	const struct pcf85063_config *config = &config_rv8063;
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &config->regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return pcf85063_probe(&spi->dev, regmap, spi->irq, config);
+}
+
+static struct spi_driver rv8063_driver = {
+	.driver         = {
+		.name   = "rv8063",
+	},
+	.probe          = rv8063_probe,
+};
+
+static int __init rv8063_register_driver(void)
+{
+	return spi_register_driver(&rv8063_driver);
+}
+
+static void __exit rv8063_unregister_driver(void)
+{
+	spi_unregister_driver(&rv8063_driver);
+}
+
+#else
+
+static int __init rv8063_register_driver(void)
+{
+	return 0;
+}
+
+static void __exit rv8063_unregister_driver(void)
+{
+}
+
+#endif /* IS_ENABLED(CONFIG_SPI_MASTER) */
+
 static int __init pcf85063_init(void)
 {
-	return pcf85063_register_driver();
+	int ret;
+
+	ret = pcf85063_register_driver();
+	if (ret)
+		return ret;
+
+	ret = rv8063_register_driver();
+	if (ret)
+		pcf85063_unregister_driver();
+
+	return ret;
 }
 module_init(pcf85063_init);
 
 static void __exit pcf85063_exit(void)
 {
+	rv8063_unregister_driver();
 	pcf85063_unregister_driver();
 }
 module_exit(pcf85063_exit);
@@ -740,3 +811,4 @@ module_exit(pcf85063_exit);
 MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
 MODULE_DESCRIPTION("PCF85063 RTC driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("spi:rv8063");
-- 
2.25.1

Re: [PATCH 2/3] rtc: pcf85063: add support for RV8063
Posted by Krzysztof Kozlowski 10 months, 1 week ago
On 07/04/2025 21:35, Antoni Pokusinski wrote:
> Microcrystal RV8063 is a real-time clock with SPI interface. Its
> functionality is very similar to the RV8263 rtc.
> 
> Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
> ---
>  drivers/rtc/Kconfig        | 21 ++++++-----
>  drivers/rtc/rtc-pcf85063.c | 74 +++++++++++++++++++++++++++++++++++++-
>  2 files changed, 85 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 838bdc138ffe..1b9be96faa13 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rtc-pcf8523.
>  
> -config RTC_DRV_PCF85063
> -	tristate "NXP PCF85063"
> -	select REGMAP_I2C
> -	help
> -	  If you say yes here you get support for the PCF85063 RTC chip
> -
> -	  This driver can also be built as a module. If so, the module
> -	  will be called rtc-pcf85063.
> -
>  config RTC_DRV_PCF85363
>  	tristate "NXP PCF85363"
>  	select REGMAP_I2C
> @@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rtc-pcf2127.
>  
> +config RTC_DRV_PCF85063

Why? This breaks the order.

> +	tristate "NXP PCF85063"
> +	depends on RTC_I2C_AND_SPI
> +	select REGMAP_I2C if I2C
> +	select REGMAP_SPI if SPI_MASTER
> +	help
> +	  If you say yes here you get support for the PCF85063 and RV8063
> +	  RTC chips.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called rtc-pcf85063.
> +


...

>  module_exit(pcf85063_exit);
> @@ -740,3 +811,4 @@ module_exit(pcf85063_exit);
>  MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
>  MODULE_DESCRIPTION("PCF85063 RTC driver");
>  MODULE_LICENSE("GPL");
> +MODULE_ALIAS("spi:rv8063");

Drop and use proper ID tables.


Best regards,
Krzysztof
Re: [PATCH 2/3] rtc: pcf85063: add support for RV8063
Posted by Antoni Pokusinski 10 months ago
On Tue, Apr 08, 2025 at 08:14:36AM +0200, Krzysztof Kozlowski wrote:
> On 07/04/2025 21:35, Antoni Pokusinski wrote:
> > Microcrystal RV8063 is a real-time clock with SPI interface. Its
> > functionality is very similar to the RV8263 rtc.
> > 
> > Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
> > ---
> >  drivers/rtc/Kconfig        | 21 ++++++-----
> >  drivers/rtc/rtc-pcf85063.c | 74 +++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 85 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> > index 838bdc138ffe..1b9be96faa13 100644
> > --- a/drivers/rtc/Kconfig
> > +++ b/drivers/rtc/Kconfig
> > @@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
> >  	  This driver can also be built as a module. If so, the module
> >  	  will be called rtc-pcf8523.
> >  
> > -config RTC_DRV_PCF85063
> > -	tristate "NXP PCF85063"
> > -	select REGMAP_I2C
> > -	help
> > -	  If you say yes here you get support for the PCF85063 RTC chip
> > -
> > -	  This driver can also be built as a module. If so, the module
> > -	  will be called rtc-pcf85063.
> > -
> >  config RTC_DRV_PCF85363
> >  	tristate "NXP PCF85363"
> >  	select REGMAP_I2C
> > @@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
> >  	  This driver can also be built as a module. If so, the module
> >  	  will be called rtc-pcf2127.
> >  
> > +config RTC_DRV_PCF85063
> 
> Why? This breaks the order.
>
I moved this config entry to the "SPI and I2C RTC drivers" section,
because the driver supports now both I2C and SPI devices.

> > +	tristate "NXP PCF85063"
> > +	depends on RTC_I2C_AND_SPI
> > +	select REGMAP_I2C if I2C
> > +	select REGMAP_SPI if SPI_MASTER
> > +	help
> > +	  If you say yes here you get support for the PCF85063 and RV8063
> > +	  RTC chips.
> > +
> > +	  This driver can also be built as a module. If so, the module
> > +	  will be called rtc-pcf85063.
> > +
> 
> 
> ...
> 
> >  module_exit(pcf85063_exit);
> > @@ -740,3 +811,4 @@ module_exit(pcf85063_exit);
> >  MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
> >  MODULE_DESCRIPTION("PCF85063 RTC driver");
> >  MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("spi:rv8063");
> 
> Drop and use proper ID tables.
> 
Will fix that in v2, thanks.
> 
> Best regards,
> Krzysztof

Kind regards,
Antoni
Re: [PATCH 2/3] rtc: pcf85063: add support for RV8063
Posted by Alexandre Belloni 10 months, 1 week ago
On 08/04/2025 08:14:36+0200, Krzysztof Kozlowski wrote:
> On 07/04/2025 21:35, Antoni Pokusinski wrote:
> > Microcrystal RV8063 is a real-time clock with SPI interface. Its
> > functionality is very similar to the RV8263 rtc.
> > 
> > Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
> > ---
> >  drivers/rtc/Kconfig        | 21 ++++++-----
> >  drivers/rtc/rtc-pcf85063.c | 74 +++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 85 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> > index 838bdc138ffe..1b9be96faa13 100644
> > --- a/drivers/rtc/Kconfig
> > +++ b/drivers/rtc/Kconfig
> > @@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
> >  	  This driver can also be built as a module. If so, the module
> >  	  will be called rtc-pcf8523.
> >  
> > -config RTC_DRV_PCF85063
> > -	tristate "NXP PCF85063"
> > -	select REGMAP_I2C
> > -	help
> > -	  If you say yes here you get support for the PCF85063 RTC chip
> > -
> > -	  This driver can also be built as a module. If so, the module
> > -	  will be called rtc-pcf85063.
> > -
> >  config RTC_DRV_PCF85363
> >  	tristate "NXP PCF85363"
> >  	select REGMAP_I2C
> > @@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
> >  	  This driver can also be built as a module. If so, the module
> >  	  will be called rtc-pcf2127.
> >  
> > +config RTC_DRV_PCF85063
> 
> Why? This breaks the order.
> 

I don't think it does but you can't see it from the diff.

> > +	tristate "NXP PCF85063"
> > +	depends on RTC_I2C_AND_SPI
> > +	select REGMAP_I2C if I2C
> > +	select REGMAP_SPI if SPI_MASTER
> > +	help
> > +	  If you say yes here you get support for the PCF85063 and RV8063
> > +	  RTC chips.
> > +
> > +	  This driver can also be built as a module. If so, the module
> > +	  will be called rtc-pcf85063.
> > +
> 
> 
> ...
> 
> >  module_exit(pcf85063_exit);
> > @@ -740,3 +811,4 @@ module_exit(pcf85063_exit);
> >  MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
> >  MODULE_DESCRIPTION("PCF85063 RTC driver");
> >  MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("spi:rv8063");
> 
> Drop and use proper ID tables.
> 
> 
> Best regards,
> Krzysztof

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