From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbcLYG63 (ORCPT ); Sun, 25 Dec 2016 01:58:29 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35330 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862AbcLYG61 (ORCPT ); Sun, 25 Dec 2016 01:58:27 -0500 From: Venkat Prashanth B U To: alexandre.belloni@free-electrons.com Cc: manabian@gmail.com, a.zummo@towertech.it, rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Venkat Prashanth B U Subject: [PATCH] rtc: add support for rtc NXP pca21125 and pca8565 Date: Sat, 24 Dec 2016 22:58:08 -0800 Message-Id: <1482649088-2845-1-git-send-email-venkat.prashanth2498@gmail.com> X-Mailer: git-send-email 1.9.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a patch to support the SPI compatible PCA21125 device with the I2C based rtc-pcf8563 driver using regmap layer. Further this patch adds "pca8565" to the set of i2c ids. Signed-off-by: Venkat Prashanth B U --- change log v3: 1. Add a regmap layer to I2C PCF8563 to support SPI PCA21125. 2. Add pca8565 to the set of i2c ids of rtc-pcf8563. --- --- drivers/rtc/rtc-pcf8563.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 1227cea..26c8b9b 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define PCF8563_REG_ST1 0x00 /* status */ #define PCF8563_REG_ST2 0x01 @@ -59,6 +61,7 @@ #define PCF8563_SC_LV 0x80 /* low voltage */ #define PCF8563_MO_C 0x80 /* century */ +#define PCF8563_REG_SR 0x01 /*control-status register*/ static struct i2c_driver pcf8563_driver; @@ -84,6 +87,9 @@ struct pcf8563 { struct i2c_client *client; #ifdef CONFIG_COMMON_CLK struct clk_hw clkout_hw; +const struct device *dev; +const struct regmap *regmap; + bool suspended; #endif }; @@ -629,6 +635,7 @@ static int pcf8563_probe(struct i2c_client *client, static const struct i2c_device_id pcf8563_id[] = { { "pcf8563", 0 }, { "rtc8564", 0 }, + { "pca8565", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, pcf8563_id); @@ -636,11 +643,86 @@ MODULE_DEVICE_TABLE(i2c, pcf8563_id); #ifdef CONFIG_OF static const struct of_device_id pcf8563_of_match[] = { { .compatible = "nxp,pcf8563" }, + { .compatible = "nxp,pca8565" }, {} }; MODULE_DEVICE_TABLE(of, pcf8563_of_match); #endif +#if IS_ENABLED(CONFIG_SPI_MASTER) + +static int pca21125_probe(const struct spi_device *spi) +{ + int res; + unsigned int tmp; + static const struct regmap_config config = { + .reg_bits = 8, + .val_bits = 8, + .write_flag_mask = 0x80, + }; +const struct regmap *regmap; +const struct pcf8563 *pcf8563; + + 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); + } + + spi->mode = SPI_MODE_3; + spi->bits_per_word = 8; + spi_setup(spi); + + res = regmap_read(regmap, PCF8563_REG_SC, &tmp); + + if (res) + return res; + res = regmap_read(regmap, PCF8563_REG_CLKO, &tmp); + + if (res) + return res; + + res = regmap_write(regmap, PCF8563_REG_CLKO, tmp & 0x1c); + + if (res) + return res; + + res = regmap_read(regmap, PCF8563_REG_SR, &tmp); + + if (res) + return res; + + res = regmap_write(regmap, PCF8563_REG_SR, tmp & 0x88); + + if (res) + return res; + + /* Print our settings */ + res = regmap_read(regmap, PCF8563_REG_CLKO, &tmp); + + if (res) + return res; + + dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp); + res = regmap_read(regmap, PCF8563_REG_SR, &tmp); + + if (res) + return res; + + dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); + + pcf8563->rtc = devm_rtc_device_register(&spi->dev, + "pcf8563", + &pcf8563_rtc_ops, THIS_MODULE); +} + +const struct spi_driver pca21125_driver = { + .driver = { + .name = "pca21125", + }, + static struct i2c_driver pcf8563_driver = { .driver = { .name = "rtc-pcf8563", -- 1.9.2