* [rtc-linux] [PATCH 1/3] rtc: pcf2127: conver to use regmap
@ 2016-03-11 16:22 Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 2/3] rtc: pcf2127: add support for spi interface Akinobu Mita
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Akinobu Mita @ 2016-03-11 16:22 UTC (permalink / raw)
To: rtc-linux
Cc: Akinobu Mita, Alessandro Zummo, Alexandre Belloni, Renaud Cerrato
pcf2127 has selectable I2C-bus and SPI-bus interface support.
Currently rtc-pcf2127 driver only supports I2C.
This is preparation for support for SPI interface.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Renaud Cerrato <r.cerrato@til-technologies.fr>
---
drivers/rtc/rtc-pcf2127.c | 209 ++++++++++++++++++++++++++++++----------------
1 file changed, 139 insertions(+), 70 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 629bfdf..8f269e3 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -19,6 +19,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/regmap.h>
#define PCF2127_REG_CTRL1 (0x00) /* Control Register 1 */
#define PCF2127_REG_CTRL2 (0x01) /* Control Register 2 */
@@ -36,29 +37,30 @@
#define PCF2127_OSF BIT(7) /* Oscillator Fail flag */
-static struct i2c_driver pcf2127_driver;
-
struct pcf2127 {
struct rtc_device *rtc;
+ struct regmap *regmap;
};
/*
* In the routines that deal directly with the pcf2127 hardware, we use
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
*/
-static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm)
+static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
- unsigned char buf[10] = { PCF2127_REG_CTRL1 };
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+ unsigned char buf[10];
+ int ret;
- /* read registers */
- if (i2c_master_send(client, buf, 1) != 1 ||
- i2c_master_recv(client, buf, sizeof(buf)) != sizeof(buf)) {
- dev_err(&client->dev, "%s: read error\n", __func__);
- return -EIO;
+ ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL1, buf,
+ sizeof(buf));
+ if (ret) {
+ dev_err(dev, "%s: read error\n", __func__);
+ return ret;
}
if (buf[PCF2127_REG_CTRL3] & PCF2127_REG_CTRL3_BLF)
- dev_info(&client->dev,
+ dev_info(dev,
"low voltage detected, check/replace RTC battery.\n");
if (buf[PCF2127_REG_SC] & PCF2127_OSF) {
@@ -66,12 +68,12 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm)
* no need clear the flag here,
* it will be cleared once the new date is saved
*/
- dev_warn(&client->dev,
+ dev_warn(dev,
"oscillator stop detected, date/time is not reliable\n");
return -EINVAL;
}
- dev_dbg(&client->dev,
+ dev_dbg(dev,
"%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, "
"sec=%02x, min=%02x, hr=%02x, "
"mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
@@ -91,7 +93,7 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm)
if (tm->tm_year < 70)
tm->tm_year += 100; /* assume we are in 1970...2069 */
- dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
+ dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
"mday=%d, mon=%d, year=%d, wday=%d\n",
__func__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
@@ -100,20 +102,18 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm)
return rtc_valid_tm(tm);
}
-static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm)
+static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
- unsigned char buf[8];
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+ unsigned char buf[7];
int i = 0, err;
- dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
+ dev_dbg(dev, "%s: secs=%d, mins=%d, hours=%d, "
"mday=%d, mon=%d, year=%d, wday=%d\n",
__func__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
- /* start register address */
- buf[i++] = PCF2127_REG_SC;
-
/* hours, minutes and seconds */
buf[i++] = bin2bcd(tm->tm_sec); /* this will also clear OSF flag */
buf[i++] = bin2bcd(tm->tm_min);
@@ -128,11 +128,11 @@ static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm)
buf[i++] = bin2bcd(tm->tm_year % 100);
/* write register's data */
- err = i2c_master_send(client, buf, i);
- if (err != i) {
- dev_err(&client->dev,
+ err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i);
+ if (err) {
+ dev_err(dev,
"%s: err=%d", __func__, err);
- return -EIO;
+ return err;
}
return 0;
@@ -142,26 +142,17 @@ static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm)
static int pcf2127_rtc_ioctl(struct device *dev,
unsigned int cmd, unsigned long arg)
{
- struct i2c_client *client = to_i2c_client(dev);
- unsigned char buf = PCF2127_REG_CTRL3;
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
int touser;
int ret;
switch (cmd) {
case RTC_VL_READ:
- ret = i2c_master_send(client, &buf, 1);
- if (!ret)
- ret = -EIO;
- if (ret < 0)
- return ret;
-
- ret = i2c_master_recv(client, &buf, 1);
- if (!ret)
- ret = -EIO;
- if (ret < 0)
+ ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser);
+ if (ret)
return ret;
- touser = buf & PCF2127_REG_CTRL3_BLF ? 1 : 0;
+ touser = touser & PCF2127_REG_CTRL3_BLF ? 1 : 0;
if (copy_to_user((void __user *)arg, &touser, sizeof(int)))
return -EFAULT;
@@ -174,52 +165,33 @@ static int pcf2127_rtc_ioctl(struct device *dev,
#define pcf2127_rtc_ioctl NULL
#endif
-static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
-{
- return pcf2127_get_datetime(to_i2c_client(dev), tm);
-}
-
-static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
-{
- return pcf2127_set_datetime(to_i2c_client(dev), tm);
-}
-
static const struct rtc_class_ops pcf2127_rtc_ops = {
.ioctl = pcf2127_rtc_ioctl,
.read_time = pcf2127_rtc_read_time,
.set_time = pcf2127_rtc_set_time,
};
-static int pcf2127_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+static int pcf2127_probe(struct device *dev, struct regmap *regmap,
+ const char *name)
{
struct pcf2127 *pcf2127;
- dev_dbg(&client->dev, "%s\n", __func__);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
- return -ENODEV;
+ dev_dbg(dev, "%s\n", __func__);
- pcf2127 = devm_kzalloc(&client->dev, sizeof(struct pcf2127),
- GFP_KERNEL);
+ pcf2127 = devm_kzalloc(dev, sizeof(*pcf2127), GFP_KERNEL);
if (!pcf2127)
return -ENOMEM;
- i2c_set_clientdata(client, pcf2127);
+ pcf2127->regmap = regmap;
+
+ dev_set_drvdata(dev, pcf2127);
- pcf2127->rtc = devm_rtc_device_register(&client->dev,
- pcf2127_driver.driver.name,
- &pcf2127_rtc_ops, THIS_MODULE);
+ pcf2127->rtc = devm_rtc_device_register(dev, name, &pcf2127_rtc_ops,
+ THIS_MODULE);
return PTR_ERR_OR_ZERO(pcf2127->rtc);
}
-static const struct i2c_device_id pcf2127_id[] = {
- { "pcf2127", 0 },
- { }
-};
-MODULE_DEVICE_TABLE(i2c, pcf2127_id);
-
#ifdef CONFIG_OF
static const struct of_device_id pcf2127_of_match[] = {
{ .compatible = "nxp,pcf2127" },
@@ -228,16 +200,113 @@ static const struct of_device_id pcf2127_of_match[] = {
MODULE_DEVICE_TABLE(of, pcf2127_of_match);
#endif
-static struct i2c_driver pcf2127_driver = {
+static int pcf2127_i2c_write(void *context, const void *data, size_t count)
+{
+ struct device *dev = context;
+ struct i2c_client *client = to_i2c_client(dev);
+ int ret;
+
+ ret = i2c_master_send(client, data, count);
+ if (ret != count)
+ return ret < 0 ? ret : -EIO;
+
+ return 0;
+}
+
+static int pcf2127_i2c_gather_write(void *context,
+ const void *reg, size_t reg_size,
+ const void *val, size_t val_size)
+{
+ struct device *dev = context;
+ struct i2c_client *client = to_i2c_client(dev);
+ int ret;
+ void *buf;
+
+ if (WARN_ON(reg_size != 1))
+ return -EINVAL;
+
+ buf = kmalloc(val_size + 1, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ memcpy(buf, reg, 1);
+ memcpy(buf + 1, val, val_size);
+
+ ret = i2c_master_send(client, buf, val_size + 1);
+ if (ret != val_size + 1)
+ return ret < 0 ? ret : -EIO;
+
+ return 0;
+}
+
+static int pcf2127_i2c_read(void *context, const void *reg, size_t reg_size,
+ void *val, size_t val_size)
+{
+ struct device *dev = context;
+ struct i2c_client *client = to_i2c_client(dev);
+ int ret;
+
+ if (WARN_ON(reg_size != 1))
+ return -EINVAL;
+
+ ret = i2c_master_send(client, reg, 1);
+ if (ret != 1)
+ return ret < 0 ? ret : -EIO;
+
+ ret = i2c_master_recv(client, val, val_size);
+ if (ret != val_size)
+ return ret < 0 ? ret : -EIO;
+
+ return 0;
+}
+
+static const struct regmap_bus pcf2127_i2c_regmap = {
+ .write = pcf2127_i2c_write,
+ .gather_write = pcf2127_i2c_gather_write,
+ .read = pcf2127_i2c_read,
+};
+
+static struct i2c_driver pcf2127_i2c_driver;
+
+static int pcf2127_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct regmap *regmap;
+ static const struct regmap_config config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ };
+
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ return -ENODEV;
+
+ regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap,
+ &client->dev, &config);
+ if (IS_ERR(regmap)) {
+ dev_err(&client->dev, "%s: regmap allocation failed: %ld\n",
+ __func__, PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
+ return pcf2127_probe(&client->dev, regmap,
+ pcf2127_i2c_driver.driver.name);
+}
+
+static const struct i2c_device_id pcf2127_i2c_id[] = {
+ { "pcf2127", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
+
+static struct i2c_driver pcf2127_i2c_driver = {
.driver = {
- .name = "rtc-pcf2127",
+ .name = "rtc-pcf2127-i2c",
.of_match_table = of_match_ptr(pcf2127_of_match),
},
- .probe = pcf2127_probe,
- .id_table = pcf2127_id,
+ .probe = pcf2127_i2c_probe,
+ .id_table = pcf2127_i2c_id,
};
-
-module_i2c_driver(pcf2127_driver);
+module_i2c_driver(pcf2127_i2c_driver);
MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>");
MODULE_DESCRIPTION("NXP PCF2127 RTC driver");
--
2.5.0
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 6+ messages in thread* [rtc-linux] [PATCH 2/3] rtc: pcf2127: add support for spi interface
2016-03-11 16:22 [rtc-linux] [PATCH 1/3] rtc: pcf2127: conver to use regmap Akinobu Mita
@ 2016-03-11 16:22 ` Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 3/3] rtc: pcf2127: add pcf2129 device id Akinobu Mita
2016-03-11 18:11 ` [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap Alexandre Belloni
2 siblings, 0 replies; 6+ messages in thread
From: Akinobu Mita @ 2016-03-11 16:22 UTC (permalink / raw)
To: rtc-linux
Cc: Akinobu Mita, Alessandro Zummo, Alexandre Belloni, Renaud Cerrato
pcf2127 has selectable I2C-bus and SPI-bus interface support.
This adds support for SPI interface.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Renaud Cerrato <r.cerrato@til-technologies.fr>
---
drivers/rtc/Kconfig | 19 ++++----
drivers/rtc/rtc-pcf2127.c | 118 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 126 insertions(+), 11 deletions(-)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 777fa2d..9d0f4da 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -400,15 +400,6 @@ config RTC_DRV_PALMAS
This driver can also be built as a module. If so, the module
will be called rtc-palma.
-config RTC_DRV_PCF2127
- tristate "NXP PCF2127"
- help
- If you say yes here you get support for the NXP PCF2127/29 RTC
- chips.
-
- This driver can also be built as a module. If so, the module
- will be called rtc-pcf2127.
-
config RTC_DRV_PCF8523
tristate "NXP PCF8523"
help
@@ -767,6 +758,16 @@ config RTC_DRV_DS3232
This driver can also be built as a module. If so, the module
will be called rtc-ds3232.
+config RTC_DRV_PCF2127
+ tristate "NXP PCF2127"
+ depends on RTC_I2C_AND_SPI
+ help
+ If you say yes here you get support for the NXP PCF2127/29 RTC
+ chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-pcf2127.
+
comment "Platform RTC drivers"
# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h>
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 8f269e3..5729ee9 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -1,5 +1,5 @@
/*
- * An I2C driver for the NXP PCF2127 RTC
+ * An I2C and SPI driver for the NXP PCF2127 RTC
* Copyright 2013 Til-Technologies
*
* Author: Renaud Cerrato <r.cerrato@til-technologies.fr>
@@ -14,6 +14,7 @@
*/
#include <linux/i2c.h>
+#include <linux/spi/spi.h>
#include <linux/bcd.h>
#include <linux/rtc.h>
#include <linux/slab.h>
@@ -200,6 +201,8 @@ static const struct of_device_id pcf2127_of_match[] = {
MODULE_DEVICE_TABLE(of, pcf2127_of_match);
#endif
+#if IS_ENABLED(CONFIG_I2C)
+
static int pcf2127_i2c_write(void *context, const void *data, size_t count)
{
struct device *dev = context;
@@ -306,7 +309,118 @@ static struct i2c_driver pcf2127_i2c_driver = {
.probe = pcf2127_i2c_probe,
.id_table = pcf2127_i2c_id,
};
-module_i2c_driver(pcf2127_i2c_driver);
+
+static int pcf2127_i2c_register_driver(void)
+{
+ return i2c_add_driver(&pcf2127_i2c_driver);
+}
+
+static void pcf2127_i2c_unregister_driver(void)
+{
+ i2c_del_driver(&pcf2127_i2c_driver);
+}
+
+#else
+
+static int pcf2127_i2c_register_driver(void)
+{
+ return 0;
+}
+
+static void pcf2127_i2c_unregister_driver(void)
+{
+}
+
+#endif
+
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+
+static struct spi_driver pcf2127_spi_driver;
+
+static int pcf2127_spi_probe(struct spi_device *spi)
+{
+ static const struct regmap_config config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .read_flag_mask = 0xa0,
+ .write_flag_mask = 0x20,
+ };
+ 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 pcf2127_probe(&spi->dev, regmap, pcf2127_spi_driver.driver.name);
+}
+
+static const struct spi_device_id pcf2127_spi_id[] = {
+ { "pcf2127", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, pcf2127_spi_id);
+
+static struct spi_driver pcf2127_spi_driver = {
+ .driver = {
+ .name = "rtc-pcf2127-spi",
+ .of_match_table = of_match_ptr(pcf2127_of_match),
+ },
+ .probe = pcf2127_spi_probe,
+ .id_table = pcf2127_spi_id,
+};
+
+static int pcf2127_spi_register_driver(void)
+{
+ return spi_register_driver(&pcf2127_spi_driver);
+}
+
+static void pcf2127_spi_unregister_driver(void)
+{
+ spi_unregister_driver(&pcf2127_spi_driver);
+}
+
+#else
+
+static int pcf2127_spi_register_driver(void)
+{
+ return 0;
+}
+
+static void pcf2127_spi_unregister_driver(void)
+{
+}
+
+#endif
+
+static int __init pcf2127_init(void)
+{
+ int ret;
+
+ ret = pcf2127_i2c_register_driver();
+ if (ret) {
+ pr_err("Failed to register pcf2127 i2c driver: %d\n", ret);
+ return ret;
+ }
+
+ ret = pcf2127_spi_register_driver();
+ if (ret) {
+ pr_err("Failed to register pcf2127 spi driver: %d\n", ret);
+ pcf2127_i2c_unregister_driver();
+ }
+
+ return ret;
+}
+module_init(pcf2127_init)
+
+static void __exit pcf2127_exit(void)
+{
+ pcf2127_spi_unregister_driver();
+ pcf2127_i2c_unregister_driver();
+}
+module_exit(pcf2127_exit)
MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>");
MODULE_DESCRIPTION("NXP PCF2127 RTC driver");
--
2.5.0
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 6+ messages in thread* [rtc-linux] [PATCH 3/3] rtc: pcf2127: add pcf2129 device id
2016-03-11 16:22 [rtc-linux] [PATCH 1/3] rtc: pcf2127: conver to use regmap Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 2/3] rtc: pcf2127: add support for spi interface Akinobu Mita
@ 2016-03-11 16:22 ` Akinobu Mita
2016-03-11 18:11 ` [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap Alexandre Belloni
2 siblings, 0 replies; 6+ messages in thread
From: Akinobu Mita @ 2016-03-11 16:22 UTC (permalink / raw)
To: rtc-linux
Cc: Akinobu Mita, Alessandro Zummo, Alexandre Belloni, Renaud Cerrato
There are only a few differences between PCF2127 and PCF2129 (PCF2127
has 512 bytes of general purpose SRAM and count-down timer).
The rtc-pcf2127 driver currently doesn't use the PCF2127 specific
functionality and Kconfig help text already says this driver supports
PCF2127/29, so we can simply add pcf2129 to device id list.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Renaud Cerrato <r.cerrato@til-technologies.fr>
---
drivers/rtc/rtc-pcf2127.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 5729ee9..2dc1690 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -1,12 +1,12 @@
/*
- * An I2C and SPI driver for the NXP PCF2127 RTC
+ * An I2C and SPI driver for the NXP PCF2127/29 RTC
* Copyright 2013 Til-Technologies
*
* Author: Renaud Cerrato <r.cerrato@til-technologies.fr>
*
* based on the other drivers in this same directory.
*
- * http://www.nxp.com/documents/data_sheet/PCF2127AT.pdf
+ * Datasheet: http://cache.nxp.com/documents/data_sheet/PCF2127.pdf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -196,6 +196,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
#ifdef CONFIG_OF
static const struct of_device_id pcf2127_of_match[] = {
{ .compatible = "nxp,pcf2127" },
+ { .compatible = "nxp,pcf2129" },
{}
};
MODULE_DEVICE_TABLE(of, pcf2127_of_match);
@@ -297,6 +298,7 @@ static int pcf2127_i2c_probe(struct i2c_client *client,
static const struct i2c_device_id pcf2127_i2c_id[] = {
{ "pcf2127", 0 },
+ { "pcf2129", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
@@ -359,6 +361,7 @@ static int pcf2127_spi_probe(struct spi_device *spi)
static const struct spi_device_id pcf2127_spi_id[] = {
{ "pcf2127", 0 },
+ { "pcf2129", 0 },
{ }
};
MODULE_DEVICE_TABLE(spi, pcf2127_spi_id);
@@ -423,5 +426,5 @@ static void __exit pcf2127_exit(void)
module_exit(pcf2127_exit)
MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>");
-MODULE_DESCRIPTION("NXP PCF2127 RTC driver");
+MODULE_DESCRIPTION("NXP PCF2127/29 RTC driver");
MODULE_LICENSE("GPL v2");
--
2.5.0
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 6+ messages in thread* [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap
2016-03-11 16:22 [rtc-linux] [PATCH 1/3] rtc: pcf2127: conver to use regmap Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 2/3] rtc: pcf2127: add support for spi interface Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 3/3] rtc: pcf2127: add pcf2129 device id Akinobu Mita
@ 2016-03-11 18:11 ` Alexandre Belloni
2016-03-12 15:39 ` Akinobu Mita
2 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2016-03-11 18:11 UTC (permalink / raw)
To: Akinobu Mita; +Cc: rtc-linux, Alessandro Zummo, Renaud Cerrato
Hi,
That is nice to see interest in those RTCs. Do you plan to submit more
RTC drivers? How many do you have? :)
One small comment as I didn't have time to read the datasheet.
On 12/03/2016 at 01:22:14 +0900, Akinobu Mita wrote :
> @@ -228,16 +200,113 @@ static const struct of_device_id pcf2127_of_match[] = {
> MODULE_DEVICE_TABLE(of, pcf2127_of_match);
> #endif
>
> -static struct i2c_driver pcf2127_driver = {
> +static int pcf2127_i2c_write(void *context, const void *data, size_t count)
> +{
> + struct device *dev = context;
> + struct i2c_client *client = to_i2c_client(dev);
> + int ret;
> +
> + ret = i2c_master_send(client, data, count);
> + if (ret != count)
> + return ret < 0 ? ret : -EIO;
> +
> + return 0;
> +}
> +
> +static int pcf2127_i2c_gather_write(void *context,
> + const void *reg, size_t reg_size,
> + const void *val, size_t val_size)
> +{
> + struct device *dev = context;
> + struct i2c_client *client = to_i2c_client(dev);
> + int ret;
> + void *buf;
> +
> + if (WARN_ON(reg_size != 1))
> + return -EINVAL;
> +
> + buf = kmalloc(val_size + 1, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + memcpy(buf, reg, 1);
> + memcpy(buf + 1, val, val_size);
> +
> + ret = i2c_master_send(client, buf, val_size + 1);
> + if (ret != val_size + 1)
> + return ret < 0 ? ret : -EIO;
> +
> + return 0;
> +}
> +
> +static int pcf2127_i2c_read(void *context, const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct device *dev = context;
> + struct i2c_client *client = to_i2c_client(dev);
> + int ret;
> +
> + if (WARN_ON(reg_size != 1))
> + return -EINVAL;
> +
> + ret = i2c_master_send(client, reg, 1);
> + if (ret != 1)
> + return ret < 0 ? ret : -EIO;
> +
> + ret = i2c_master_recv(client, val, val_size);
> + if (ret != val_size)
> + return ret < 0 ? ret : -EIO;
> +
> + return 0;
> +}
> +
> +static const struct regmap_bus pcf2127_i2c_regmap = {
> + .write = pcf2127_i2c_write,
> + .gather_write = pcf2127_i2c_gather_write,
> + .read = pcf2127_i2c_read,
> +};
Do I understand correctly that you have to define that because
regmap_i2c_gather_write doesn't do the right thing for this device?
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 6+ messages in thread* [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap
2016-03-11 18:11 ` [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap Alexandre Belloni
@ 2016-03-12 15:39 ` Akinobu Mita
2016-03-12 15:43 ` Alexandre Belloni
0 siblings, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2016-03-12 15:39 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: rtc-linux, Alessandro Zummo, Renaud Cerrato
2016-03-12 3:11 GMT+09:00 Alexandre Belloni
<alexandre.belloni@free-electrons.com>:
> Hi,
>
> That is nice to see interest in those RTCs. Do you plan to submit more
> RTC drivers? How many do you have? :)
I have DS1302, DS1307, DS3231, DS3232, DS3234, PCF2129, RX8025.
I plan to submit patches for rtc-ds1302 to support controlling with
using GPIO lines like rtc-moxart. PCF2127/29 has some interesting
features like timestamp and watchdog, so I'll try to integrate these
into rtc-pcf2127 driver.
> One small comment as I didn't have time to read the datasheet.
>
> On 12/03/2016 at 01:22:14 +0900, Akinobu Mita wrote :
>> @@ -228,16 +200,113 @@ static const struct of_device_id pcf2127_of_match[] = {
>> MODULE_DEVICE_TABLE(of, pcf2127_of_match);
>> #endif
>>
>> -static struct i2c_driver pcf2127_driver = {
>> +static int pcf2127_i2c_write(void *context, const void *data, size_t count)
>> +{
>> + struct device *dev = context;
>> + struct i2c_client *client = to_i2c_client(dev);
>> + int ret;
>> +
>> + ret = i2c_master_send(client, data, count);
>> + if (ret != count)
>> + return ret < 0 ? ret : -EIO;
>> +
>> + return 0;
>> +}
>> +
>> +static int pcf2127_i2c_gather_write(void *context,
>> + const void *reg, size_t reg_size,
>> + const void *val, size_t val_size)
>> +{
>> + struct device *dev = context;
>> + struct i2c_client *client = to_i2c_client(dev);
>> + int ret;
>> + void *buf;
>> +
>> + if (WARN_ON(reg_size != 1))
>> + return -EINVAL;
>> +
>> + buf = kmalloc(val_size + 1, GFP_KERNEL);
>> + if (!buf)
>> + return -ENOMEM;
>> +
>> + memcpy(buf, reg, 1);
>> + memcpy(buf + 1, val, val_size);
>> +
>> + ret = i2c_master_send(client, buf, val_size + 1);
>> + if (ret != val_size + 1)
>> + return ret < 0 ? ret : -EIO;
>> +
>> + return 0;
>> +}
>> +
>> +static int pcf2127_i2c_read(void *context, const void *reg, size_t reg_size,
>> + void *val, size_t val_size)
>> +{
>> + struct device *dev = context;
>> + struct i2c_client *client = to_i2c_client(dev);
>> + int ret;
>> +
>> + if (WARN_ON(reg_size != 1))
>> + return -EINVAL;
>> +
>> + ret = i2c_master_send(client, reg, 1);
>> + if (ret != 1)
>> + return ret < 0 ? ret : -EIO;
>> +
>> + ret = i2c_master_recv(client, val, val_size);
>> + if (ret != val_size)
>> + return ret < 0 ? ret : -EIO;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct regmap_bus pcf2127_i2c_regmap = {
>> + .write = pcf2127_i2c_write,
>> + .gather_write = pcf2127_i2c_gather_write,
>> + .read = pcf2127_i2c_read,
>> +};
>
> Do I understand correctly that you have to define that because
> regmap_i2c_gather_write doesn't do the right thing for this device?
The reason is regmap_i2c_read() doesn't work for this device because the
STOP condition is required between set register address and read register
data. (Fig 45. Bus protocol, reading from registers in PCF2127.pdf)
I'll update this patch by adding that comment.
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 6+ messages in thread* [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap
2016-03-12 15:39 ` Akinobu Mita
@ 2016-03-12 15:43 ` Alexandre Belloni
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2016-03-12 15:43 UTC (permalink / raw)
To: Akinobu Mita; +Cc: rtc-linux, Alessandro Zummo, Renaud Cerrato
On 13/03/2016 at 00:39:34 +0900, Akinobu Mita wrote :
> The reason is regmap_i2c_read() doesn't work for this device because the
> STOP condition is required between set register address and read register
> data. (Fig 45. Bus protocol, reading from registers in PCF2127.pdf)
>
> I'll update this patch by adding that comment.
That would be great. You also have a small typo in the subject line.
Apart from that, I'm ready to take the patches.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-03-12 15:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-11 16:22 [rtc-linux] [PATCH 1/3] rtc: pcf2127: conver to use regmap Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 2/3] rtc: pcf2127: add support for spi interface Akinobu Mita
2016-03-11 16:22 ` [rtc-linux] [PATCH 3/3] rtc: pcf2127: add pcf2129 device id Akinobu Mita
2016-03-11 18:11 ` [rtc-linux] Re: [PATCH 1/3] rtc: pcf2127: conver to use regmap Alexandre Belloni
2016-03-12 15:39 ` Akinobu Mita
2016-03-12 15:43 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox