rtc: rv3029: Add support of RV3049

Add support of Microcrystal RV3049 RTC (SPI) using regmap on the
RV3029 (I2C) driver.

Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
This commit is contained in:
Mylène Josserand 2016-05-03 11:54:34 +02:00 committed by Alexandre Belloni
parent e6e3808212
commit c2a1c14540
2 changed files with 124 additions and 21 deletions

View File

@ -573,24 +573,6 @@ config RTC_DRV_EM3027
This driver can also be built as a module. If so, the module
will be called rtc-em3027.
config RTC_DRV_RV3029C2
tristate "Micro Crystal RV3029"
help
If you say yes here you get support for the Micro Crystal
RV3029 RTC chips.
This driver can also be built as a module. If so, the module
will be called rtc-rv3029c2.
config RTC_DRV_RV3029_HWMON
bool "HWMON support for RV3029"
depends on RTC_DRV_RV3029C2 && HWMON
depends on !(RTC_DRV_RV3029C2=y && HWMON=m)
default y
help
Say Y here if you want to expose temperature sensor data on
rtc-rv3029.
config RTC_DRV_RV8803
tristate "Micro Crystal RV8803"
help
@ -786,6 +768,25 @@ 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_RV3029C2
tristate "Micro Crystal RV3029/3049"
depends on RTC_I2C_AND_SPI
help
If you say yes here you get support for the Micro Crystal
RV3029 and RV3049 RTC chips.
This driver can also be built as a module. If so, the module
will be called rtc-rv3029c2.
config RTC_DRV_RV3029_HWMON
bool "HWMON support for RV3029/3049"
depends on RTC_DRV_RV3029C2 && HWMON
depends on !(RTC_DRV_RV3029C2=y && HWMON=m)
default y
help
Say Y here if you want to expose temperature sensor data on
rtc-rv3029.
comment "Platform RTC drivers"
# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h>

View File

@ -1,5 +1,5 @@
/*
* Micro Crystal RV-3029 rtc class driver
* Micro Crystal RV-3029 / RV-3049 rtc class driver
*
* Author: Gregory Hermant <gregory.hermant@calao-systems.com>
* Michael Buesch <m@bues.ch>
@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/spi/spi.h>
#include <linux/bcd.h>
#include <linux/rtc.h>
#include <linux/delay.h>
@ -766,6 +767,8 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
return PTR_ERR_OR_ZERO(rv3029->rtc);
}
#if IS_ENABLED(CONFIG_I2C)
static int rv3029_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@ -799,9 +802,108 @@ static struct i2c_driver rv3029_driver = {
.id_table = rv3029_id,
};
module_i2c_driver(rv3029_driver);
static int rv3029_register_driver(void)
{
return i2c_add_driver(&rv3029_driver);
}
static void rv3029_unregister_driver(void)
{
i2c_del_driver(&rv3029_driver);
}
#else
static int rv3029_register_driver(void)
{
return 0;
}
static void rv3029_unregister_driver(void)
{
}
#endif
#if IS_ENABLED(CONFIG_SPI_MASTER)
static int rv3049_probe(struct spi_device *spi)
{
static const struct regmap_config config = {
.reg_bits = 8,
.val_bits = 8,
};
struct regmap *regmap;
regmap = devm_regmap_init_spi(spi, &config);
if (IS_ERR(regmap)) {
dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
__func__, PTR_ERR(regmap));
return PTR_ERR(regmap);
}
return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049");
}
static struct spi_driver rv3049_driver = {
.driver = {
.name = "rv3049",
},
.probe = rv3049_probe,
};
static int rv3049_register_driver(void)
{
return spi_register_driver(&rv3049_driver);
}
static void rv3049_unregister_driver(void)
{
spi_unregister_driver(&rv3049_driver);
}
#else
static int rv3049_register_driver(void)
{
return 0;
}
static void rv3049_unregister_driver(void)
{
}
#endif
static int __init rv30x9_init(void)
{
int ret;
ret = rv3029_register_driver();
if (ret) {
pr_err("Failed to register rv3029 driver: %d\n", ret);
return ret;
}
ret = rv3049_register_driver();
if (ret) {
pr_err("Failed to register rv3049 driver: %d\n", ret);
rv3029_unregister_driver();
}
return ret;
}
module_init(rv30x9_init)
static void __exit rv30x9_exit(void)
{
rv3049_unregister_driver();
rv3029_unregister_driver();
}
module_exit(rv30x9_exit)
MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>");
MODULE_AUTHOR("Michael Buesch <m@bues.ch>");
MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver");
MODULE_DESCRIPTION("Micro Crystal RV3029/RV3049 RTC driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("spi:rv3049");