mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Venkat Prashanth B U <venkat.prashanth2498@gmail.com>
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 <venkat.prashanth2498@gmail.com>
Subject: [PATCH] rtc: add support for rtc NXP pca21125 and pca8565
Date: Sat, 24 Dec 2016 22:58:08 -0800	[thread overview]
Message-ID: <1482649088-2845-1-git-send-email-venkat.prashanth2498@gmail.com> (raw)

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 <venkat.prashanth2498@gmail.com>
---
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 <linux/module.h>
 #include <linux/of.h>
 #include <linux/err.h>
+#include <linux/spi/spi.h>
+#include <linux/regmap.h>
 
 #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

             reply	other threads:[~2016-12-25  6:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-25  6:58 Venkat Prashanth B U [this message]
2016-12-25  7:36 ` kbuild test robot
2016-12-25  7:51 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482649088-2845-1-git-send-email-venkat.prashanth2498@gmail.com \
    --to=venkat.prashanth2498@gmail.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manabian@gmail.com \
    --cc=rtc-linux@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®