Skip to content

Commit a3c7f7e

Browse files
panantoni01alexandrebelloni
authored andcommitted
rtc: pcf85063: add support for RV8063
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> Link: https://lore.kernel.org/r/20250413130755.159373-4-apokusinski01@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 29ac4ce commit a3c7f7e

2 files changed

Lines changed: 98 additions & 10 deletions

File tree

drivers/rtc/Kconfig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
483483
This driver can also be built as a module. If so, the module
484484
will be called rtc-pcf8523.
485485

486-
config RTC_DRV_PCF85063
487-
tristate "NXP PCF85063"
488-
select REGMAP_I2C
489-
help
490-
If you say yes here you get support for the PCF85063 RTC chip
491-
492-
This driver can also be built as a module. If so, the module
493-
will be called rtc-pcf85063.
494-
495486
config RTC_DRV_PCF85363
496487
tristate "NXP PCF85363"
497488
select REGMAP_I2C
@@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
971962
This driver can also be built as a module. If so, the module
972963
will be called rtc-pcf2127.
973964

965+
config RTC_DRV_PCF85063
966+
tristate "NXP PCF85063"
967+
depends on RTC_I2C_AND_SPI
968+
select REGMAP_I2C if I2C
969+
select REGMAP_SPI if SPI_MASTER
970+
help
971+
If you say yes here you get support for the PCF85063 and RV8063
972+
RTC chips.
973+
974+
This driver can also be built as a module. If so, the module
975+
will be called rtc-pcf85063.
976+
974977
config RTC_DRV_RV3029C2
975978
tristate "Micro Crystal RV3029/3049"
976979
depends on RTC_I2C_AND_SPI

drivers/rtc/rtc-pcf85063.c

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/of.h>
1818
#include <linux/pm_wakeirq.h>
1919
#include <linux/regmap.h>
20+
#include <linux/spi/spi.h>
2021

2122
/*
2223
* Information for this driver was pulled from the following datasheets.
@@ -29,6 +30,9 @@
2930
*
3031
* https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf
3132
* RV8263 -- Rev. 1.0 — January 2019
33+
*
34+
* https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8063-C7_App-Manual.pdf
35+
* RV8063 -- Rev. 1.1 - October 2018
3236
*/
3337

3438
#define PCF85063_REG_CTRL1 0x00 /* status */
@@ -559,6 +563,18 @@ static const struct pcf85063_config config_rv8263 = {
559563
.force_cap_7000 = 1,
560564
};
561565

566+
static const struct pcf85063_config config_rv8063 = {
567+
.regmap = {
568+
.reg_bits = 8,
569+
.val_bits = 8,
570+
.max_register = 0x11,
571+
.read_flag_mask = BIT(7) | BIT(5),
572+
.write_flag_mask = BIT(5),
573+
},
574+
.has_alarms = 1,
575+
.force_cap_7000 = 1,
576+
};
577+
562578
static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq,
563579
const struct pcf85063_config *config)
564580
{
@@ -725,14 +741,83 @@ static void pcf85063_unregister_driver(void)
725741

726742
#endif /* IS_ENABLED(CONFIG_I2C) */
727743

744+
#if IS_ENABLED(CONFIG_SPI_MASTER)
745+
746+
static const struct spi_device_id rv8063_id[] = {
747+
{ "rv8063" },
748+
{}
749+
};
750+
MODULE_DEVICE_TABLE(spi, rv8063_id);
751+
752+
static const struct of_device_id rv8063_of_match[] = {
753+
{ .compatible = "microcrystal,rv8063" },
754+
{}
755+
};
756+
MODULE_DEVICE_TABLE(of, rv8063_of_match);
757+
758+
static int rv8063_probe(struct spi_device *spi)
759+
{
760+
const struct pcf85063_config *config = &config_rv8063;
761+
struct regmap *regmap;
762+
763+
regmap = devm_regmap_init_spi(spi, &config->regmap);
764+
if (IS_ERR(regmap))
765+
return PTR_ERR(regmap);
766+
767+
return pcf85063_probe(&spi->dev, regmap, spi->irq, config);
768+
}
769+
770+
static struct spi_driver rv8063_driver = {
771+
.driver = {
772+
.name = "rv8063",
773+
.of_match_table = rv8063_of_match,
774+
},
775+
.probe = rv8063_probe,
776+
.id_table = rv8063_id,
777+
};
778+
779+
static int __init rv8063_register_driver(void)
780+
{
781+
return spi_register_driver(&rv8063_driver);
782+
}
783+
784+
static void __exit rv8063_unregister_driver(void)
785+
{
786+
spi_unregister_driver(&rv8063_driver);
787+
}
788+
789+
#else
790+
791+
static int __init rv8063_register_driver(void)
792+
{
793+
return 0;
794+
}
795+
796+
static void __exit rv8063_unregister_driver(void)
797+
{
798+
}
799+
800+
#endif /* IS_ENABLED(CONFIG_SPI_MASTER) */
801+
728802
static int __init pcf85063_init(void)
729803
{
730-
return pcf85063_register_driver();
804+
int ret;
805+
806+
ret = pcf85063_register_driver();
807+
if (ret)
808+
return ret;
809+
810+
ret = rv8063_register_driver();
811+
if (ret)
812+
pcf85063_unregister_driver();
813+
814+
return ret;
731815
}
732816
module_init(pcf85063_init);
733817

734818
static void __exit pcf85063_exit(void)
735819
{
820+
rv8063_unregister_driver();
736821
pcf85063_unregister_driver();
737822
}
738823
module_exit(pcf85063_exit);

0 commit comments

Comments
 (0)