* [PATCH] rtc: add support for NXP PCF85363 real-time clock @ 2017-10-09 19:41 Eric Nelson [not found] ` <1507578100-2148-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Eric Nelson @ 2017-10-09 19:41 UTC (permalink / raw) To: linux-rtc-u79uwXL29TY76Z2rM5mHXA Cc: a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA, Eric Nelson Note that alarms are not currently implemented. 64 bytes of nvmem is supported and exposed in sysfs (# is the instance number, starting with 0): /sys/bus/nvmem/devices/pcf85363-#/nvmem Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> --- Documentation/devicetree/bindings/rtc/pcf85363.txt | 16 ++ drivers/rtc/Kconfig | 12 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pcf85363.c | 219 +++++++++++++++++++++ 4 files changed, 248 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt create mode 100644 drivers/rtc/rtc-pcf85363.c diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt new file mode 100644 index 0000000..5fddb9f --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt @@ -0,0 +1,16 @@ +NXP PCF85363 Real Time Clock +============================ + +Required properties: +- compatible: Should contain "nxp,pcf85363". +- reg: I2C address for chip. + +Example: + +pcf85363: pcf85363@51 { + compatible = "nxp,pcf85363"; + reg = <0x51>; +}; + +Note that alarms are not yet supported, so a specifier for +"interrupts" will be ignored. diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e0e58f3..62a13d9 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -433,6 +433,18 @@ config RTC_DRV_PCF85063 This driver can also be built as a module. If so, the module will be called rtc-pcf85063. +config RTC_DRV_PCF85363 + tristate "NXP PCF85363" + depends on I2C + help + If you say yes here you get support for the PCF85363 RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-pcf85363. + + The nvmem interface will be named pcf85363-#, where # is the + zero-based instance number. + config RTC_DRV_PCF8563 tristate "Philips PCF8563/Epson RTC8564" help diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 7230014..934a9dd 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -113,6 +113,7 @@ obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o obj-$(CONFIG_RTC_DRV_PCF85063) += rtc-pcf85063.o +obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c new file mode 100644 index 0000000..877b2eb --- /dev/null +++ b/drivers/rtc/rtc-pcf85363.c @@ -0,0 +1,219 @@ +/* + * drivers/rtc/rtc-pcf85363.c + * + * Driver for NXP PCF85363 real-time clock. + * + * Copyright (C) 2017 Eric Nelson + * + * 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 + * published by the Free Software Foundation. + * + * Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert + */ +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/bcd.h> +#include <linux/regmap.h> + +/* + * Date/Time registers + */ +#define DT_100THS 0x00 +#define DT_SECS 0x01 +#define DT_MINUTES 0x02 +#define DT_HOURS 0x03 +#define DT_DAYS 0x04 +#define DT_WEEKDAYS 0x05 +#define DT_MONTHS 0x06 +#define DT_YEARS 0x07 + +/* + * Alarm registers + */ +#define DT_SECOND_ALM1 0x08 +#define DT_MINUTE_ALM1 0x09 +#define DT_HOUR_ALM1 0x0a +#define DT_DAY_ALM1 0x0b +#define DT_MONTH_ALM1 0x0c +#define DT_MINUTE_ALM2 0x0d +#define DT_HOUR_ALM2 0x0e +#define DT_WEEKDAY_ALM2 0x0f +#define DT_ALARM_EN 0x10 + +/* + * Time stamp registers + */ +#define DT_TIMESTAMP1 0x11 +#define DT_TIMESTAMP2 0x17 +#define DT_TIMESTAMP3 0x1d +#define DT_TS_MODE 0x23 + +/* + * control registers + */ +#define CTRL_OFFSET 0x24 +#define CTRL_OSCILLATOR 0x25 +#define CTRL_BATTERY 0x26 +#define CTRL_PIN_IO 0x27 +#define CTRL_FUNCTION 0x28 +#define CTRL_INTA_EN 0x29 +#define CTRL_INTB_EN 0x2a +#define CTRL_FLAGS 0x2b +#define CTRL_RAMBYTE 0x2c +#define CTRL_WDOG 0x2d +#define CTRL_STOP_EN 0x2e +#define CTRL_RESETS 0x2f +#define CTRL_RAM 0x40 + +#define NVRAM_SIZE 0x40 + +static struct i2c_driver pcf85363_driver; + +struct pcf85363 { + struct device *dev; + struct rtc_device *rtc; + struct nvmem_config nvmem_cfg; + struct regmap *regmap; +}; + +static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int ret, len = sizeof(buf); + + /* read the RTC date and time registers all at once */ + ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len); + if (ret) { + dev_err(dev, "%s: error %d\n", __func__, ret); + return ret; + } + + tm->tm_year = bcd2bin(buf[DT_YEARS]); + /* adjust for 1900 base of rtc_time */ + tm->tm_year += 100; + + tm->tm_wday = buf[DT_WEEKDAYS] & 7; + buf[DT_SECS] &= 0x7F; + tm->tm_sec = bcd2bin(buf[DT_SECS]); + buf[DT_MINUTES] &= 0x7F; + tm->tm_min = bcd2bin(buf[DT_MINUTES]); + tm->tm_hour = bcd2bin(buf[DT_HOURS]); + tm->tm_mday = bcd2bin(buf[DT_DAYS]); + tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1; + + return 0; +} + +static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int len = sizeof(buf); + + buf[DT_100THS] = 0; + buf[DT_SECS] = bin2bcd(tm->tm_sec); + buf[DT_MINUTES] = bin2bcd(tm->tm_min); + buf[DT_HOURS] = bin2bcd(tm->tm_hour); + buf[DT_DAYS] = bin2bcd(tm->tm_mday); + buf[DT_WEEKDAYS] = tm->tm_wday; + buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); + buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); + + return regmap_bulk_write(pcf85363->regmap, DT_100THS, + buf, len); +} + +static const struct rtc_class_ops rtc_ops = { + .read_time = pcf85363_rtc_read_time, + .set_time = pcf85363_rtc_set_time, +}; + +static int pcf85363_nvram_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_read(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static int pcf85363_nvram_write(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_write(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static const struct regmap_config regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int pcf85363_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pcf85363 *pcf85363; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), + GFP_KERNEL); + if (!pcf85363) + return -ENOMEM; + + pcf85363->regmap = devm_regmap_init_i2c(client, ®map_config); + if (IS_ERR(pcf85363->regmap)) { + dev_err(&client->dev, "regmap allocation failed\n"); + return PTR_ERR(pcf85363->regmap); + } + + pcf85363->dev = &client->dev; + i2c_set_clientdata(client, pcf85363); + + pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); + if (IS_ERR(pcf85363->rtc)) + return PTR_ERR(pcf85363->rtc); + + pcf85363->nvmem_cfg.name = "pcf85363-"; + pcf85363->nvmem_cfg.word_size = 1; + pcf85363->nvmem_cfg.stride = 1; + pcf85363->nvmem_cfg.size = NVRAM_SIZE; + pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; + pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; + pcf85363->nvmem_cfg.priv = pcf85363; + pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; + pcf85363->rtc->nvram_old_abi = true; + pcf85363->rtc->ops = &rtc_ops; + + return rtc_register_device(pcf85363->rtc); +} + +static const struct i2c_device_id pcf85363_id[] = { + { "pcf85363", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, pcf85363_id); + +static struct i2c_driver pcf85363_driver = { + .driver = { + .name = "pcf85363", + }, + .probe = pcf85363_probe, + .id_table = pcf85363_id, +}; + +module_i2c_driver(pcf85363_driver); + +MODULE_AUTHOR("Eric Nelson"); +MODULE_DESCRIPTION("pcf85363 I2C RTC driver"); +MODULE_LICENSE("GPL"); -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 12+ messages in thread
[parent not found: <1507578100-2148-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH] rtc: add support for NXP PCF85363 real-time clock [not found] ` <1507578100-2148-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> @ 2017-10-10 13:31 ` Fabio Estevam [not found] ` <CAOMZO5C_boginn88C7zgXSBaikx==5FHJrgaE1ewYUyUgGfnFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Fabio Estevam @ 2017-10-10 13:31 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo, Alexandre Belloni, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Otavio Salvador Hi Eric, On Mon, Oct 9, 2017 at 4:41 PM, Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> wrote: > +config RTC_DRV_PCF85363 > + tristate "NXP PCF85363" > + depends on I2C It seems you missed a dependency on REGMAP_I2C. > +static const struct i2c_device_id pcf85363_id[] = { > + { "pcf85363", 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, pcf85363_id); Even though the driver can probe via the i2c device id, it is recommended to explicitly pass the compatible string: static const struct of_device_id pcf85363_dt_match[] = { { .compatible = "nxp,pcf85363" }, { }, See this previous discussion: https://www.spinics.net/lists/devicetree/msg195176.html -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <CAOMZO5C_boginn88C7zgXSBaikx==5FHJrgaE1ewYUyUgGfnFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] rtc: add support for NXP PCF85363 real-time clock [not found] ` <CAOMZO5C_boginn88C7zgXSBaikx==5FHJrgaE1ewYUyUgGfnFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2017-10-11 15:08 ` Eric Nelson 2017-10-11 15:56 ` [PATCH V2] " Eric Nelson 1 sibling, 0 replies; 12+ messages in thread From: Eric Nelson @ 2017-10-11 15:08 UTC (permalink / raw) To: Fabio Estevam Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo, Alexandre Belloni, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Otavio Salvador Hi Fabio, On 10/10/2017 06:31 AM, Fabio Estevam wrote: > Hi Eric, > > On Mon, Oct 9, 2017 at 4:41 PM, Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> wrote: > >> +config RTC_DRV_PCF85363 >> + tristate "NXP PCF85363" >> + depends on I2C > > It seems you missed a dependency on REGMAP_I2C. > Nice catch. Thanks. >> +static const struct i2c_device_id pcf85363_id[] = { >> + { "pcf85363", 0 }, >> + { } >> +}; >> +MODULE_DEVICE_TABLE(i2c, pcf85363_id); > > Even though the driver can probe via the i2c device id, it is > recommended to explicitly pass the compatible string: > > static const struct of_device_id pcf85363_dt_match[] = { > { .compatible = "nxp,pcf85363" }, > { }, > > See this previous discussion: > https://www.spinics.net/lists/devicetree/msg195176.html > Thanks for that, too. I'll fix this up in V2. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH V2] rtc: add support for NXP PCF85363 real-time clock [not found] ` <CAOMZO5C_boginn88C7zgXSBaikx==5FHJrgaE1ewYUyUgGfnFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2017-10-11 15:08 ` Eric Nelson @ 2017-10-11 15:56 ` Eric Nelson [not found] ` <1507737390-27818-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 1 sibling, 1 reply; 12+ messages in thread From: Eric Nelson @ 2017-10-11 15:56 UTC (permalink / raw) To: linux-rtc-u79uwXL29TY76Z2rM5mHXA Cc: a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA, festevam-Re5JQEeQqe8AvxtiuMwx3w, Eric Nelson Note that alarms are not currently implemented. 64 bytes of nvmem is supported and exposed in sysfs (# is the instance number, starting with 0): /sys/bus/nvmem/devices/pcf85363-#/nvmem Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> --- V2 addresses a couple of issues highlighted by Fabio Estevam 1. Kconfig updated to select REGMAP_I2C 2. Switch to of_device_id from i2c_device_id for driver matching Documentation/devicetree/bindings/rtc/pcf85363.txt | 16 ++ drivers/rtc/Kconfig | 13 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ 4 files changed, 251 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt create mode 100644 drivers/rtc/rtc-pcf85363.c diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt new file mode 100644 index 0000000..5fddb9f --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt @@ -0,0 +1,16 @@ +NXP PCF85363 Real Time Clock +============================ + +Required properties: +- compatible: Should contain "nxp,pcf85363". +- reg: I2C address for chip. + +Example: + +pcf85363: pcf85363@51 { + compatible = "nxp,pcf85363"; + reg = <0x51>; +}; + +Note that alarms are not yet supported, so a specifier for +"interrupts" will be ignored. diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e0e58f3..15306ed 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -433,6 +433,19 @@ config RTC_DRV_PCF85063 This driver can also be built as a module. If so, the module will be called rtc-pcf85063. +config RTC_DRV_PCF85363 + tristate "NXP PCF85363" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the PCF85363 RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-pcf85363. + + The nvmem interface will be named pcf85363-#, where # is the + zero-based instance number. + config RTC_DRV_PCF8563 tristate "Philips PCF8563/Epson RTC8564" help diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 7230014..934a9dd 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -113,6 +113,7 @@ obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o obj-$(CONFIG_RTC_DRV_PCF85063) += rtc-pcf85063.o +obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c new file mode 100644 index 0000000..cf1e70c --- /dev/null +++ b/drivers/rtc/rtc-pcf85363.c @@ -0,0 +1,221 @@ +/* + * drivers/rtc/rtc-pcf85363.c + * + * Driver for NXP PCF85363 real-time clock. + * + * Copyright (C) 2017 Eric Nelson + * + * 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 + * published by the Free Software Foundation. + * + * Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert + */ +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/bcd.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/regmap.h> + +/* + * Date/Time registers + */ +#define DT_100THS 0x00 +#define DT_SECS 0x01 +#define DT_MINUTES 0x02 +#define DT_HOURS 0x03 +#define DT_DAYS 0x04 +#define DT_WEEKDAYS 0x05 +#define DT_MONTHS 0x06 +#define DT_YEARS 0x07 + +/* + * Alarm registers + */ +#define DT_SECOND_ALM1 0x08 +#define DT_MINUTE_ALM1 0x09 +#define DT_HOUR_ALM1 0x0a +#define DT_DAY_ALM1 0x0b +#define DT_MONTH_ALM1 0x0c +#define DT_MINUTE_ALM2 0x0d +#define DT_HOUR_ALM2 0x0e +#define DT_WEEKDAY_ALM2 0x0f +#define DT_ALARM_EN 0x10 + +/* + * Time stamp registers + */ +#define DT_TIMESTAMP1 0x11 +#define DT_TIMESTAMP2 0x17 +#define DT_TIMESTAMP3 0x1d +#define DT_TS_MODE 0x23 + +/* + * control registers + */ +#define CTRL_OFFSET 0x24 +#define CTRL_OSCILLATOR 0x25 +#define CTRL_BATTERY 0x26 +#define CTRL_PIN_IO 0x27 +#define CTRL_FUNCTION 0x28 +#define CTRL_INTA_EN 0x29 +#define CTRL_INTB_EN 0x2a +#define CTRL_FLAGS 0x2b +#define CTRL_RAMBYTE 0x2c +#define CTRL_WDOG 0x2d +#define CTRL_STOP_EN 0x2e +#define CTRL_RESETS 0x2f +#define CTRL_RAM 0x40 + +#define NVRAM_SIZE 0x40 + +static struct i2c_driver pcf85363_driver; + +struct pcf85363 { + struct device *dev; + struct rtc_device *rtc; + struct nvmem_config nvmem_cfg; + struct regmap *regmap; +}; + +static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int ret, len = sizeof(buf); + + /* read the RTC date and time registers all at once */ + ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len); + if (ret) { + dev_err(dev, "%s: error %d\n", __func__, ret); + return ret; + } + + tm->tm_year = bcd2bin(buf[DT_YEARS]); + /* adjust for 1900 base of rtc_time */ + tm->tm_year += 100; + + tm->tm_wday = buf[DT_WEEKDAYS] & 7; + buf[DT_SECS] &= 0x7F; + tm->tm_sec = bcd2bin(buf[DT_SECS]); + buf[DT_MINUTES] &= 0x7F; + tm->tm_min = bcd2bin(buf[DT_MINUTES]); + tm->tm_hour = bcd2bin(buf[DT_HOURS]); + tm->tm_mday = bcd2bin(buf[DT_DAYS]); + tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1; + + return 0; +} + +static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int len = sizeof(buf); + + buf[DT_100THS] = 0; + buf[DT_SECS] = bin2bcd(tm->tm_sec); + buf[DT_MINUTES] = bin2bcd(tm->tm_min); + buf[DT_HOURS] = bin2bcd(tm->tm_hour); + buf[DT_DAYS] = bin2bcd(tm->tm_mday); + buf[DT_WEEKDAYS] = tm->tm_wday; + buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); + buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); + + return regmap_bulk_write(pcf85363->regmap, DT_100THS, + buf, len); +} + +static const struct rtc_class_ops rtc_ops = { + .read_time = pcf85363_rtc_read_time, + .set_time = pcf85363_rtc_set_time, +}; + +static int pcf85363_nvram_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_read(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static int pcf85363_nvram_write(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_write(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static const struct regmap_config regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int pcf85363_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pcf85363 *pcf85363; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), + GFP_KERNEL); + if (!pcf85363) + return -ENOMEM; + + pcf85363->regmap = devm_regmap_init_i2c(client, ®map_config); + if (IS_ERR(pcf85363->regmap)) { + dev_err(&client->dev, "regmap allocation failed\n"); + return PTR_ERR(pcf85363->regmap); + } + + pcf85363->dev = &client->dev; + i2c_set_clientdata(client, pcf85363); + + pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); + if (IS_ERR(pcf85363->rtc)) + return PTR_ERR(pcf85363->rtc); + + pcf85363->nvmem_cfg.name = "pcf85363-"; + pcf85363->nvmem_cfg.word_size = 1; + pcf85363->nvmem_cfg.stride = 1; + pcf85363->nvmem_cfg.size = NVRAM_SIZE; + pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; + pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; + pcf85363->nvmem_cfg.priv = pcf85363; + pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; + pcf85363->rtc->nvram_old_abi = true; + pcf85363->rtc->ops = &rtc_ops; + + return rtc_register_device(pcf85363->rtc); +} + +static const struct of_device_id dev_ids[] = { + { .compatible = "nxp,pcf85363" }, + {} +}; +MODULE_DEVICE_TABLE(of, dev_ids); + +static struct i2c_driver pcf85363_driver = { + .driver = { + .name = "pcf85363", + .of_match_table = of_match_ptr(dev_ids), + }, + .probe = pcf85363_probe, +}; + +module_i2c_driver(pcf85363_driver); + +MODULE_AUTHOR("Eric Nelson"); +MODULE_DESCRIPTION("pcf85363 I2C RTC driver"); +MODULE_LICENSE("GPL"); -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 12+ messages in thread
[parent not found: <1507737390-27818-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH V2] rtc: add support for NXP PCF85363 real-time clock [not found] ` <1507737390-27818-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> @ 2017-10-12 21:55 ` Fabio Estevam 2017-10-17 20:06 ` Rob Herring 1 sibling, 0 replies; 12+ messages in thread From: Fabio Estevam @ 2017-10-12 21:55 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo, Alexandre Belloni, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Otavio Salvador On Wed, Oct 11, 2017 at 12:56 PM, Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> wrote: > Note that alarms are not currently implemented. > > 64 bytes of nvmem is supported and exposed in > sysfs (# is the instance number, starting with 0): > > /sys/bus/nvmem/devices/pcf85363-#/nvmem > > Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> Reviewed-by: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org> -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH V2] rtc: add support for NXP PCF85363 real-time clock [not found] ` <1507737390-27818-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-10-12 21:55 ` Fabio Estevam @ 2017-10-17 20:06 ` Rob Herring 2017-10-17 22:24 ` Eric Nelson 1 sibling, 1 reply; 12+ messages in thread From: Rob Herring @ 2017-10-17 20:06 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA, festevam-Re5JQEeQqe8AvxtiuMwx3w On Wed, Oct 11, 2017 at 08:56:30AM -0700, Eric Nelson wrote: > Note that alarms are not currently implemented. > > 64 bytes of nvmem is supported and exposed in > sysfs (# is the instance number, starting with 0): > > /sys/bus/nvmem/devices/pcf85363-#/nvmem > > Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> > --- > V2 addresses a couple of issues highlighted by Fabio Estevam > 1. Kconfig updated to select REGMAP_I2C > 2. Switch to of_device_id from i2c_device_id for driver matching > > Documentation/devicetree/bindings/rtc/pcf85363.txt | 16 ++ > drivers/rtc/Kconfig | 13 ++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ > 4 files changed, 251 insertions(+) > create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt > create mode 100644 drivers/rtc/rtc-pcf85363.c > > diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt > new file mode 100644 > index 0000000..5fddb9f > --- /dev/null > +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt > @@ -0,0 +1,16 @@ > +NXP PCF85363 Real Time Clock > +============================ > + > +Required properties: > +- compatible: Should contain "nxp,pcf85363". > +- reg: I2C address for chip. > + > +Example: > + > +pcf85363: pcf85363@51 { > + compatible = "nxp,pcf85363"; > + reg = <0x51>; > +}; > + > +Note that alarms are not yet supported, so a specifier for > +"interrupts" will be ignored. Irrelevant to the binding. That's a driver feature (or lack of). If the device has an interrupt line, you should document it. It can be optional though. Rob -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH V2] rtc: add support for NXP PCF85363 real-time clock 2017-10-17 20:06 ` Rob Herring @ 2017-10-17 22:24 ` Eric Nelson [not found] ` <20602538-2164-e85c-33b6-31c99dfa8a5e-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Eric Nelson @ 2017-10-17 22:24 UTC (permalink / raw) To: Rob Herring Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA, festevam-Re5JQEeQqe8AvxtiuMwx3w Hi Rob, On 10/17/2017 01:06 PM, Rob Herring wrote: > On Wed, Oct 11, 2017 at 08:56:30AM -0700, Eric Nelson wrote: >> Note that alarms are not currently implemented. >> >> 64 bytes of nvmem is supported and exposed in >> sysfs (# is the instance number, starting with 0): >> >> /sys/bus/nvmem/devices/pcf85363-#/nvmem >> >> Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> >> --- >> V2 addresses a couple of issues highlighted by Fabio Estevam >> 1. Kconfig updated to select REGMAP_I2C >> 2. Switch to of_device_id from i2c_device_id for driver matching >> >> Documentation/devicetree/bindings/rtc/pcf85363.txt | 16 ++ >> drivers/rtc/Kconfig | 13 ++ >> drivers/rtc/Makefile | 1 + >> drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ >> 4 files changed, 251 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt >> create mode 100644 drivers/rtc/rtc-pcf85363.c >> >> diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt >> new file mode 100644 >> index 0000000..5fddb9f >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt >> @@ -0,0 +1,16 @@ >> +NXP PCF85363 Real Time Clock >> +============================ >> + >> +Required properties: >> +- compatible: Should contain "nxp,pcf85363". >> +- reg: I2C address for chip. >> + >> +Example: >> + >> +pcf85363: pcf85363@51 { >> + compatible = "nxp,pcf85363"; >> + reg = <0x51>; >> +}; >> + >> +Note that alarms are not yet supported, so a specifier for >> +"interrupts" will be ignored. > > Irrelevant to the binding. That's a driver feature (or lack of). If the > device has an interrupt line, you should document it. It can be optional > though. > That's what I was attempting do do in an awkward way. Since the driver doesn't support interrupts or alarms at the moment, I'll remove this note. The chip does have an interrupt pin, but the board I have doesn't have it connected. Regards, Eric -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <20602538-2164-e85c-33b6-31c99dfa8a5e-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH V2] rtc: add support for NXP PCF85363 real-time clock [not found] ` <20602538-2164-e85c-33b6-31c99dfa8a5e-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> @ 2017-10-19 21:24 ` Rob Herring [not found] ` <CAL_Jsq+QQK=NTMBwk=h0uszLW0uSiEd1fmF09USRNFM-2VgiSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Rob Herring @ 2017-10-19 21:24 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Otavio Salvador, Fabio Estevam On Tue, Oct 17, 2017 at 5:24 PM, Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> wrote: > Hi Rob, > > > On 10/17/2017 01:06 PM, Rob Herring wrote: >> >> On Wed, Oct 11, 2017 at 08:56:30AM -0700, Eric Nelson wrote: >>> >>> Note that alarms are not currently implemented. >>> >>> 64 bytes of nvmem is supported and exposed in >>> sysfs (# is the instance number, starting with 0): >>> >>> /sys/bus/nvmem/devices/pcf85363-#/nvmem >>> >>> Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> >>> --- >>> V2 addresses a couple of issues highlighted by Fabio Estevam >>> 1. Kconfig updated to select REGMAP_I2C >>> 2. Switch to of_device_id from i2c_device_id for driver matching >>> >>> Documentation/devicetree/bindings/rtc/pcf85363.txt | 16 ++ >>> drivers/rtc/Kconfig | 13 ++ >>> drivers/rtc/Makefile | 1 + >>> drivers/rtc/rtc-pcf85363.c | 221 >>> +++++++++++++++++++++ >>> 4 files changed, 251 insertions(+) >>> create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt >>> create mode 100644 drivers/rtc/rtc-pcf85363.c >>> >>> diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt >>> b/Documentation/devicetree/bindings/rtc/pcf85363.txt >>> new file mode 100644 >>> index 0000000..5fddb9f >>> --- /dev/null >>> +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt >>> @@ -0,0 +1,16 @@ >>> +NXP PCF85363 Real Time Clock >>> +============================ >>> + >>> +Required properties: >>> +- compatible: Should contain "nxp,pcf85363". >>> +- reg: I2C address for chip. >>> + >>> +Example: >>> + >>> +pcf85363: pcf85363@51 { >>> + compatible = "nxp,pcf85363"; >>> + reg = <0x51>; >>> +}; >>> + >>> +Note that alarms are not yet supported, so a specifier for >>> +"interrupts" will be ignored. >> >> >> Irrelevant to the binding. That's a driver feature (or lack of). If the >> device has an interrupt line, you should document it. It can be optional >> though. >> > > That's what I was attempting do do in an awkward way. > > Since the driver doesn't support interrupts or alarms at the moment, > I'll remove this note. > > The chip does have an interrupt pin, but the board I have doesn't > have it connected. Then just document "interrupts" as optional. Rob -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <CAL_Jsq+QQK=NTMBwk=h0uszLW0uSiEd1fmF09USRNFM-2VgiSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* [PATCH V3] rtc: add support for NXP PCF85363 real-time clock [not found] ` <CAL_Jsq+QQK=NTMBwk=h0uszLW0uSiEd1fmF09USRNFM-2VgiSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2017-11-01 15:01 ` Eric Nelson [not found] ` <1509548480-29472-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Eric Nelson @ 2017-11-01 15:01 UTC (permalink / raw) To: linux-rtc-u79uwXL29TY76Z2rM5mHXA Cc: robh-DgEjT+Ai2ygdnm+yROfE0A, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA, Eric Nelson Note that alarms are not currently implemented. 64 bytes of nvmem is supported and exposed in sysfs (# is the instance number, starting with 0): /sys/bus/nvmem/devices/pcf85363-#/nvmem Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> Reviewed-by: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org> --- V2 addresses a couple of issues highlighted by Fabio Estevam 1. Kconfig updated to select REGMAP_I2C 2. Switch to of_device_id from i2c_device_id for driver matching V3 adds interrupts as an optional property in device tree bindings drivers/rtc/Kconfig | 13 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt create mode 100644 drivers/rtc/rtc-pcf85363.c diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt new file mode 100644 index 0000000..76fdabc --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt @@ -0,0 +1,17 @@ +NXP PCF85363 Real Time Clock +============================ + +Required properties: +- compatible: Should contain "nxp,pcf85363". +- reg: I2C address for chip. + +Optional properties: +- interrupts: IRQ line for the RTC (not implemented). + +Example: + +pcf85363: pcf85363@51 { + compatible = "nxp,pcf85363"; + reg = <0x51>; +}; + diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e0e58f3..15306ed 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -433,6 +433,19 @@ config RTC_DRV_PCF85063 This driver can also be built as a module. If so, the module will be called rtc-pcf85063. +config RTC_DRV_PCF85363 + tristate "NXP PCF85363" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the PCF85363 RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-pcf85363. + + The nvmem interface will be named pcf85363-#, where # is the + zero-based instance number. + config RTC_DRV_PCF8563 tristate "Philips PCF8563/Epson RTC8564" help diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 7230014..934a9dd 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -113,6 +113,7 @@ obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o obj-$(CONFIG_RTC_DRV_PCF85063) += rtc-pcf85063.o +obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c new file mode 100644 index 0000000..cf1e70c --- /dev/null +++ b/drivers/rtc/rtc-pcf85363.c @@ -0,0 +1,221 @@ +/* + * drivers/rtc/rtc-pcf85363.c + * + * Driver for NXP PCF85363 real-time clock. + * + * Copyright (C) 2017 Eric Nelson + * + * 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 + * published by the Free Software Foundation. + * + * Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert + */ +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/bcd.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/regmap.h> + +/* + * Date/Time registers + */ +#define DT_100THS 0x00 +#define DT_SECS 0x01 +#define DT_MINUTES 0x02 +#define DT_HOURS 0x03 +#define DT_DAYS 0x04 +#define DT_WEEKDAYS 0x05 +#define DT_MONTHS 0x06 +#define DT_YEARS 0x07 + +/* + * Alarm registers + */ +#define DT_SECOND_ALM1 0x08 +#define DT_MINUTE_ALM1 0x09 +#define DT_HOUR_ALM1 0x0a +#define DT_DAY_ALM1 0x0b +#define DT_MONTH_ALM1 0x0c +#define DT_MINUTE_ALM2 0x0d +#define DT_HOUR_ALM2 0x0e +#define DT_WEEKDAY_ALM2 0x0f +#define DT_ALARM_EN 0x10 + +/* + * Time stamp registers + */ +#define DT_TIMESTAMP1 0x11 +#define DT_TIMESTAMP2 0x17 +#define DT_TIMESTAMP3 0x1d +#define DT_TS_MODE 0x23 + +/* + * control registers + */ +#define CTRL_OFFSET 0x24 +#define CTRL_OSCILLATOR 0x25 +#define CTRL_BATTERY 0x26 +#define CTRL_PIN_IO 0x27 +#define CTRL_FUNCTION 0x28 +#define CTRL_INTA_EN 0x29 +#define CTRL_INTB_EN 0x2a +#define CTRL_FLAGS 0x2b +#define CTRL_RAMBYTE 0x2c +#define CTRL_WDOG 0x2d +#define CTRL_STOP_EN 0x2e +#define CTRL_RESETS 0x2f +#define CTRL_RAM 0x40 + +#define NVRAM_SIZE 0x40 + +static struct i2c_driver pcf85363_driver; + +struct pcf85363 { + struct device *dev; + struct rtc_device *rtc; + struct nvmem_config nvmem_cfg; + struct regmap *regmap; +}; + +static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int ret, len = sizeof(buf); + + /* read the RTC date and time registers all at once */ + ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len); + if (ret) { + dev_err(dev, "%s: error %d\n", __func__, ret); + return ret; + } + + tm->tm_year = bcd2bin(buf[DT_YEARS]); + /* adjust for 1900 base of rtc_time */ + tm->tm_year += 100; + + tm->tm_wday = buf[DT_WEEKDAYS] & 7; + buf[DT_SECS] &= 0x7F; + tm->tm_sec = bcd2bin(buf[DT_SECS]); + buf[DT_MINUTES] &= 0x7F; + tm->tm_min = bcd2bin(buf[DT_MINUTES]); + tm->tm_hour = bcd2bin(buf[DT_HOURS]); + tm->tm_mday = bcd2bin(buf[DT_DAYS]); + tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1; + + return 0; +} + +static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + unsigned char buf[DT_YEARS + 1]; + int len = sizeof(buf); + + buf[DT_100THS] = 0; + buf[DT_SECS] = bin2bcd(tm->tm_sec); + buf[DT_MINUTES] = bin2bcd(tm->tm_min); + buf[DT_HOURS] = bin2bcd(tm->tm_hour); + buf[DT_DAYS] = bin2bcd(tm->tm_mday); + buf[DT_WEEKDAYS] = tm->tm_wday; + buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); + buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); + + return regmap_bulk_write(pcf85363->regmap, DT_100THS, + buf, len); +} + +static const struct rtc_class_ops rtc_ops = { + .read_time = pcf85363_rtc_read_time, + .set_time = pcf85363_rtc_set_time, +}; + +static int pcf85363_nvram_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_read(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static int pcf85363_nvram_write(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct pcf85363 *pcf85363 = priv; + + return regmap_bulk_write(pcf85363->regmap, CTRL_RAM + offset, + val, bytes); +} + +static const struct regmap_config regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int pcf85363_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pcf85363 *pcf85363; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), + GFP_KERNEL); + if (!pcf85363) + return -ENOMEM; + + pcf85363->regmap = devm_regmap_init_i2c(client, ®map_config); + if (IS_ERR(pcf85363->regmap)) { + dev_err(&client->dev, "regmap allocation failed\n"); + return PTR_ERR(pcf85363->regmap); + } + + pcf85363->dev = &client->dev; + i2c_set_clientdata(client, pcf85363); + + pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); + if (IS_ERR(pcf85363->rtc)) + return PTR_ERR(pcf85363->rtc); + + pcf85363->nvmem_cfg.name = "pcf85363-"; + pcf85363->nvmem_cfg.word_size = 1; + pcf85363->nvmem_cfg.stride = 1; + pcf85363->nvmem_cfg.size = NVRAM_SIZE; + pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; + pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; + pcf85363->nvmem_cfg.priv = pcf85363; + pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; + pcf85363->rtc->nvram_old_abi = true; + pcf85363->rtc->ops = &rtc_ops; + + return rtc_register_device(pcf85363->rtc); +} + +static const struct of_device_id dev_ids[] = { + { .compatible = "nxp,pcf85363" }, + {} +}; +MODULE_DEVICE_TABLE(of, dev_ids); + +static struct i2c_driver pcf85363_driver = { + .driver = { + .name = "pcf85363", + .of_match_table = of_match_ptr(dev_ids), + }, + .probe = pcf85363_probe, +}; + +module_i2c_driver(pcf85363_driver); + +MODULE_AUTHOR("Eric Nelson"); +MODULE_DESCRIPTION("pcf85363 I2C RTC driver"); +MODULE_LICENSE("GPL"); -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 12+ messages in thread
[parent not found: <1509548480-29472-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH V3] rtc: add support for NXP PCF85363 real-time clock [not found] ` <1509548480-29472-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> @ 2017-11-01 17:45 ` Rob Herring 2017-11-04 16:08 ` Alexandre Belloni 1 sibling, 0 replies; 12+ messages in thread From: Rob Herring @ 2017-11-01 17:45 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Otavio Salvador On Wed, Nov 1, 2017 at 10:01 AM, Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> wrote: > Note that alarms are not currently implemented. > > 64 bytes of nvmem is supported and exposed in > sysfs (# is the instance number, starting with 0): > > /sys/bus/nvmem/devices/pcf85363-#/nvmem > > Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> > Reviewed-by: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org> > --- > V2 addresses a couple of issues highlighted by Fabio Estevam > 1. Kconfig updated to select REGMAP_I2C > 2. Switch to of_device_id from i2c_device_id for driver matching > > V3 adds interrupts as an optional property in device tree bindings > > drivers/rtc/Kconfig | 13 ++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ > 4 files changed, 252 insertions(+) > create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt > create mode 100644 drivers/rtc/rtc-pcf85363.c For the binding: Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH V3] rtc: add support for NXP PCF85363 real-time clock [not found] ` <1509548480-29472-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-11-01 17:45 ` Rob Herring @ 2017-11-04 16:08 ` Alexandre Belloni [not found] ` <20171104160836.bah5su2ld5ckycr3-m++hUPXGwpdeoWH0uzbU5w@public.gmane.org> 1 sibling, 1 reply; 12+ messages in thread From: Alexandre Belloni @ 2017-11-04 16:08 UTC (permalink / raw) To: Eric Nelson Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, robh-DgEjT+Ai2ygdnm+yROfE0A, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA Hi, On 01/11/2017 at 08:01:20 -0700, Eric Nelson wrote: > Note that alarms are not currently implemented. > > 64 bytes of nvmem is supported and exposed in > sysfs (# is the instance number, starting with 0): > > /sys/bus/nvmem/devices/pcf85363-#/nvmem > > Signed-off-by: Eric Nelson <eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> > Reviewed-by: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org> > --- > V2 addresses a couple of issues highlighted by Fabio Estevam > 1. Kconfig updated to select REGMAP_I2C > 2. Switch to of_device_id from i2c_device_id for driver matching > > V3 adds interrupts as an optional property in device tree bindings > > drivers/rtc/Kconfig | 13 ++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ > 4 files changed, 252 insertions(+) > create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt > create mode 100644 drivers/rtc/rtc-pcf85363.c > I've tested it (thanks to Fabio, I received one a few weeks ago) Applied with the following change: --- a/drivers/rtc/rtc-pcf85363.c +++ b/drivers/rtc/rtc-pcf85363.c @@ -194,7 +194,6 @@ static int pcf85363_probe(struct i2c_client *client, pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; pcf85363->nvmem_cfg.priv = pcf85363; pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; - pcf85363->rtc->nvram_old_abi = true; pcf85363->rtc->ops = &rtc_ops; return rtc_register_device(pcf85363->rtc); nvram_old_abi must not be used for new drivers and will generate warning when the (undocumented) ABI is used anyway. -- Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <20171104160836.bah5su2ld5ckycr3-m++hUPXGwpdeoWH0uzbU5w@public.gmane.org>]
* Re: [PATCH V3] rtc: add support for NXP PCF85363 real-time clock [not found] ` <20171104160836.bah5su2ld5ckycr3-m++hUPXGwpdeoWH0uzbU5w@public.gmane.org> @ 2017-11-06 14:32 ` Eric Nelson 0 siblings, 0 replies; 12+ messages in thread From: Eric Nelson @ 2017-11-06 14:32 UTC (permalink / raw) To: Alexandre Belloni Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA, robh-DgEjT+Ai2ygdnm+yROfE0A, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, mark.rutland-5wv7dgnIgG8, devicetree-u79uwXL29TY76Z2rM5mHXA, otavio.salvador-fKevB0iiKLMBZ+LybsDmbA On 11/04/2017 09:08 AM, Alexandre Belloni wrote: > On 01/11/2017 at 08:01:20 -0700, Eric Nelson wrote: <snip> >> >> V3 adds interrupts as an optional property in device tree bindings >> >> drivers/rtc/Kconfig | 13 ++ >> drivers/rtc/Makefile | 1 + >> drivers/rtc/rtc-pcf85363.c | 221 +++++++++++++++++++++ >> 4 files changed, 252 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/rtc/pcf85363.txt >> create mode 100644 drivers/rtc/rtc-pcf85363.c >> > > I've tested it (thanks to Fabio, I received one a few weeks ago) > > Applied with the following change: > > --- a/drivers/rtc/rtc-pcf85363.c > +++ b/drivers/rtc/rtc-pcf85363.c > @@ -194,7 +194,6 @@ static int pcf85363_probe(struct i2c_client *client, > pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; > pcf85363->nvmem_cfg.priv = pcf85363; > pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; > - pcf85363->rtc->nvram_old_abi = true; > pcf85363->rtc->ops = &rtc_ops; > > return rtc_register_device(pcf85363->rtc); > > nvram_old_abi must not be used for new drivers and will generate warning > when the (undocumented) ABI is used anyway. > Thanks Alexandre (and Fabio). -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-11-06 14:32 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-10-09 19:41 [PATCH] rtc: add support for NXP PCF85363 real-time clock Eric Nelson [not found] ` <1507578100-2148-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-10-10 13:31 ` Fabio Estevam [not found] ` <CAOMZO5C_boginn88C7zgXSBaikx==5FHJrgaE1ewYUyUgGfnFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2017-10-11 15:08 ` Eric Nelson 2017-10-11 15:56 ` [PATCH V2] " Eric Nelson [not found] ` <1507737390-27818-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-10-12 21:55 ` Fabio Estevam 2017-10-17 20:06 ` Rob Herring 2017-10-17 22:24 ` Eric Nelson [not found] ` <20602538-2164-e85c-33b6-31c99dfa8a5e-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-10-19 21:24 ` Rob Herring [not found] ` <CAL_Jsq+QQK=NTMBwk=h0uszLW0uSiEd1fmF09USRNFM-2VgiSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2017-11-01 15:01 ` [PATCH V3] " Eric Nelson [not found] ` <1509548480-29472-1-git-send-email-eric-SeqgQ6RdavfQT0dZR+AlfA@public.gmane.org> 2017-11-01 17:45 ` Rob Herring 2017-11-04 16:08 ` Alexandre Belloni [not found] ` <20171104160836.bah5su2ld5ckycr3-m++hUPXGwpdeoWH0uzbU5w@public.gmane.org> 2017-11-06 14:32 ` Eric Nelson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).