Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753958AbcDUSYm (ORCPT ); Thu, 21 Apr 2016 14:24:42 -0400 Received: from down.free-electrons.com ([37.187.137.238]:43034 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751756AbcDUSYg (ORCPT ); Thu, 21 Apr 2016 14:24:36 -0400 From: =?UTF-8?q?Myl=C3=A8ne=20Josserand?= To: alexandre.belloni@free-electrons.com, rtc-linux@googlegroups.com Cc: Alessandro Zummo , linux-kernel@vger.kernel.org, mylene.josserand@free-electrons.com Subject: [PATCH 3/6] rtc: rv3029: Add support of RV3049 Date: Thu, 21 Apr 2016 20:24:16 +0200 Message-Id: <74271423784bda552ef2a0789c8a6958ee072d7d.1461250479.git.mylene.josserand@free-electrons.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4998 Lines: 207 Add support of Microcrystal RV3049 RTC (SPI) using regmap on the RV3029 (I2C) driver. Signed-off-by: Mylène Josserand --- drivers/rtc/Kconfig | 37 +++++++-------- drivers/rtc/rtc-rv3029c2.c | 110 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 21 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index f1e1f50..18639e0 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -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 diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c index 96dd166..470cc1e 100644 --- a/drivers/rtc/rtc-rv3029c2.c +++ b/drivers/rtc/rtc-rv3029c2.c @@ -1,5 +1,5 @@ /* - * Micro Crystal RV-3029 rtc class driver + * Micro Crystal RV-3029 / RV-3049 rtc class driver * * Author: Gregory Hermant * Michael Buesch @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -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,110 @@ 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) +{ + int res; + unsigned int tmp; + 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 "); MODULE_AUTHOR("Michael Buesch "); -MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver"); +MODULE_DESCRIPTION("Micro Crystal RV3029/RV3049 RTC driver"); MODULE_LICENSE("GPL"); +MODULE_ALIAS("spi:rv3049"); -- 2.8.0.rc3