* [rtc-linux] [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 9:54 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-08 9:54 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
devicetree, rtc-linux, kernel, Steffen Trumtrar
Add the binding documentation for the Epson RX6110 RTC.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Changes since v2:
- removed the size field in i2c binding
.../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
new file mode 100644
index 000000000000..71353542a59d
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
@@ -0,0 +1,39 @@
+Epson RX6110 Real Time Clock
+============================
+
+The Epson RX6110 can be used with SPI or I2C busses. The kind of
+bus depends on the SPISEL pin and can not be configured via software.
+
+I2C mode
+--------
+
+Required properties:
+ - compatible: should be: "epson,rx6110"
+ - reg : offset of the register set of the device
+
+Example:
+
+ rtc: rtc@32 {
+ compatible = "epson,rx6110"
+ reg = <0x32>;
+ };
+
+SPI mode
+--------
+
+Required properties:
+ - compatible: should be: "epson,rx6110"
+ - reg: chip select number
+ - spi-cs-high: RX6110 needs chipselect high
+ - spi-cpha: RX6110 works with SPI shifted clock phase
+ - spi-cpol: RX6110 works with SPI inverse clock polarity
+
+Example:
+
+ rtc: rtc@3 {
+ compatible = "epson,rx6110"
+ reg = <3>
+ spi-cs-high;
+ spi-cpha;
+ spi-cpol;
+ };
--
2.6.2
--
--
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] 14+ messages in thread
* [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 9:54 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-08 9:54 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
Steffen Trumtrar
Add the binding documentation for the Epson RX6110 RTC.
Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
Changes since v2:
- removed the size field in i2c binding
.../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
new file mode 100644
index 000000000000..71353542a59d
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
@@ -0,0 +1,39 @@
+Epson RX6110 Real Time Clock
+============================
+
+The Epson RX6110 can be used with SPI or I2C busses. The kind of
+bus depends on the SPISEL pin and can not be configured via software.
+
+I2C mode
+--------
+
+Required properties:
+ - compatible: should be: "epson,rx6110"
+ - reg : offset of the register set of the device
+
+Example:
+
+ rtc: rtc@32 {
+ compatible = "epson,rx6110"
+ reg = <0x32>;
+ };
+
+SPI mode
+--------
+
+Required properties:
+ - compatible: should be: "epson,rx6110"
+ - reg: chip select number
+ - spi-cs-high: RX6110 needs chipselect high
+ - spi-cpha: RX6110 works with SPI shifted clock phase
+ - spi-cpol: RX6110 works with SPI inverse clock polarity
+
+Example:
+
+ rtc: rtc@3 {
+ compatible = "epson,rx6110"
+ reg = <3>
+ spi-cs-high;
+ spi-cpha;
+ spi-cpol;
+ };
--
2.6.2
--
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] 14+ messages in thread
* [rtc-linux] [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-08 9:54 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-08 9:54 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
devicetree, rtc-linux, kernel, Steffen Trumtrar
The RX6110 comes in two different variants: SPI and I2C.
This driver only supports the SPI variant.
If the need ever arises to also support the I2C variant, this driver
could easily be refactored to support both cases.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Changes since v2:
- remove old copyright infos
- use the BIT() macro
- replace rx6110_get_week_day() with ffs()
- replace hardcoded offsets with enum
- fix copy-and-paste error in rx6110_init
- use regmap_bulk_write in set_time
- return -EINVAL instead of "fixing" time in the rtc
drivers/rtc/Kconfig | 9 +
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-rx6110.c | 438 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 448 insertions(+)
create mode 100644 drivers/rtc/rtc-rx6110.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2a524244afec..fbb26ccd512c 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -734,6 +734,15 @@ config RTC_DRV_RX4581
This driver can also be built as a module. If so the module
will be called rtc-rx4581.
+config RTC_DRV_RX6110
+ tristate "Epson RX-6110"
+ select REGMAP_SPI
+ help
+ If you say yes here you will get support for the Epson RX-6610.
+
+ This driver can also be built as a module. If so the module
+ will be called rtc-rx6110.
+
config RTC_DRV_MCP795
tristate "Microchip MCP795"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 231f76451615..1e8dfc6bbe82 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -128,6 +128,7 @@ obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o
obj-$(CONFIG_RTC_DRV_RV8803) += rtc-rv8803.o
obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o
+obj-$(CONFIG_RTC_DRV_RX6110) += rtc-rx6110.o
obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o
obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
new file mode 100644
index 000000000000..aa9d89d5d2de
--- /dev/null
+++ b/drivers/rtc/rtc-rx6110.c
@@ -0,0 +1,438 @@
+/*
+ * Driver for the Epson RTC module RX-6110 SA
+ *
+ * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel@pengutronix.de>
+ * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
+ *
+ * This driver software is distributed as is, without any warranty of any kind,
+ * either express or implied as further specified in the GNU Public License.
+ * This software may be used and distributed according to the terms of the GNU
+ * Public License, version 2 as published by the Free Software Foundation.
+ * See the file COPYING in the main directory of this archive for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/bcd.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+#include <linux/spi/spi.h>
+
+/* RX-6110 Register definitions */
+#define RX6110_REG_SEC 0x10
+#define RX6110_REG_MIN 0x11
+#define RX6110_REG_HOUR 0x12
+#define RX6110_REG_WDAY 0x13
+#define RX6110_REG_MDAY 0x14
+#define RX6110_REG_MONTH 0x15
+#define RX6110_REG_YEAR 0x16
+#define RX6110_REG_RES1 0x17
+#define RX6110_REG_ALMIN 0x18
+#define RX6110_REG_ALHOUR 0x19
+#define RX6110_REG_ALWDAY 0x1A
+#define RX6110_REG_TCOUNT0 0x1B
+#define RX6110_REG_TCOUNT1 0x1C
+#define RX6110_REG_EXT 0x1D
+#define RX6110_REG_FLAG 0x1E
+#define RX6110_REG_CTRL 0x1F
+#define RX6110_REG_USER0 0x20
+#define RX6110_REG_USER1 0x21
+#define RX6110_REG_USER2 0x22
+#define RX6110_REG_USER3 0x23
+#define RX6110_REG_USER4 0x24
+#define RX6110_REG_USER5 0x25
+#define RX6110_REG_USER6 0x26
+#define RX6110_REG_USER7 0x27
+#define RX6110_REG_USER8 0x28
+#define RX6110_REG_USER9 0x29
+#define RX6110_REG_USERA 0x2A
+#define RX6110_REG_USERB 0x2B
+#define RX6110_REG_USERC 0x2C
+#define RX6110_REG_USERD 0x2D
+#define RX6110_REG_USERE 0x2E
+#define RX6110_REG_USERF 0x2F
+#define RX6110_REG_RES2 0x30
+#define RX6110_REG_RES3 0x31
+#define RX6110_REG_IRQ 0x32
+
+#define RX6110_BIT_ALARM_EN BIT(7)
+
+/* Extension Register (1Dh) bit positions */
+#define RX6110_BIT_EXT_TSEL0 BIT(0)
+#define RX6110_BIT_EXT_TSEL1 BIT(1)
+#define RX6110_BIT_EXT_TSEL2 BIT(2)
+#define RX6110_BIT_EXT_WADA BIT(3)
+#define RX6110_BIT_EXT_TE BIT(4)
+#define RX6110_BIT_EXT_USEL BIT(5)
+#define RX6110_BIT_EXT_FSEL0 BIT(6)
+#define RX6110_BIT_EXT_FSEL1 BIT(7)
+
+/* Flag Register (1Eh) bit positions */
+#define RX6110_BIT_FLAG_VLF BIT(1)
+#define RX6110_BIT_FLAG_AF BIT(3)
+#define RX6110_BIT_FLAG_TF BIT(4)
+#define RX6110_BIT_FLAG_UF BIT(5)
+
+/* Control Register (1Fh) bit positions */
+#define RX6110_BIT_CTRL_TBKE BIT(0)
+#define RX6110_BIT_CTRL_TBKON BIT(1)
+#define RX6110_BIT_CTRL_TSTP BIT(2)
+#define RX6110_BIT_CTRL_AIE BIT(3)
+#define RX6110_BIT_CTRL_TIE BIT(4)
+#define RX6110_BIT_CTRL_UIE BIT(5)
+#define RX6110_BIT_CTRL_STOP BIT(6)
+#define RX6110_BIT_CTRL_TEST BIT(7)
+
+enum {
+ RTC_SEC = 0,
+ RTC_MIN,
+ RTC_HOUR,
+ RTC_WDAY,
+ RTC_MDAY,
+ RTC_MONTH,
+ RTC_YEAR,
+ RTC_NR_TIME
+};
+
+static struct spi_driver rx6110_driver;
+
+struct rx6110_data {
+ struct rtc_device *rtc;
+ struct regmap *regmap;
+};
+
+/**
+ * rx6110_rtc_tm_to_data - convert rtc_time to native time encoding
+ *
+ * @tm: holds date and time
+ * @data: holds the encoding in rx6110 native form
+ */
+static int rx6110_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+ pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ /*
+ * The year in the RTC is a value between 0 and 99.
+ * Assume that this represents the current century
+ * and disregard all other values.
+ */
+ if (tm->tm_year < 100 || tm->tm_year >= 200)
+ return -EINVAL;
+
+ data[RTC_SEC] = bin2bcd(tm->tm_sec);
+ data[RTC_MIN] = bin2bcd(tm->tm_min);
+ data[RTC_HOUR] = bin2bcd(tm->tm_hour);
+ data[RTC_WDAY] = 1 << bin2bcd(tm->tm_wday);
+ data[RTC_MDAY] = bin2bcd(tm->tm_mday);
+ data[RTC_MONTH] = bin2bcd(tm->tm_mon + 1);
+ data[RTC_YEAR] = bin2bcd(tm->tm_year % 100);
+
+ return 0;
+}
+
+/**
+ * rx6110_data_to_rtc_tm - convert native time encoding to rtc_time
+ *
+ * @data: holds the encoding in rx6110 native form
+ * @tm: holds date and time
+ */
+static int rx6110_data_to_rtc_tm(u8 *data, struct rtc_time *tm)
+{
+ tm->tm_sec = bcd2bin(data[RTC_SEC] & 0x7f);
+ tm->tm_min = bcd2bin(data[RTC_MIN] & 0x7f);
+ /* only 24-hour clock */
+ tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
+ tm->tm_wday = ffs(data[RTC_WDAY] & 0x7f);
+ tm->tm_mday = bcd2bin(data[RTC_MDAY] & 0x3f);
+ tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1;
+ tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100;
+
+ pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ /*
+ * The year in the RTC is a value between 0 and 99.
+ * Assume that this represents the current century
+ * and disregard all other values.
+ */
+ if (tm->tm_year < 100 || tm->tm_year >= 200)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * rx6110_set_time - set the current time in the rx6110 registers
+ *
+ * @dev: the rtc device in use
+ * @tm: holds date and time
+ *
+ * BUG: The HW assumes every year that is a multiple of 4 to be a leap
+ * year. Next time this is wrong is 2100, which will not be a leap year
+ *
+ * Note: If STOP is not set/cleared, the clock will start when the seconds
+ * register is written
+ *
+ */
+static int rx6110_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct rx6110_data *rx6110 = dev_get_drvdata(dev);
+ u8 data[RTC_NR_TIME];
+ int ret;
+
+ ret = rx6110_rtc_tm_to_data(tm, data);
+ if (ret < 0)
+ return ret;
+
+ /* set STOP bit before changing clock/calendar */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL,
+ RX6110_BIT_CTRL_STOP, RX6110_BIT_CTRL_STOP);
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_write(rx6110->regmap, RX6110_REG_SEC, data,
+ RTC_NR_TIME);
+ if (ret)
+ return ret;
+
+ /* The time in the RTC is valid. Be sure to have VLF cleared. */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
+ RX6110_BIT_FLAG_VLF, 0);
+ if (ret)
+ return ret;
+
+ /* clear STOP bit after changing clock/calendar */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL,
+ RX6110_BIT_CTRL_STOP, 0);
+
+ return ret;
+}
+
+/**
+ * rx6110_get_time - get the current time from the rx6110 registers
+ * @dev: the rtc device in use
+ * @tm: holds date and time
+ */
+static int rx6110_get_time(struct device *dev, struct rtc_time *tm)
+{
+ struct rx6110_data *rx6110 = dev_get_drvdata(dev);
+ u8 data[RTC_NR_TIME];
+ int flags;
+ int ret;
+
+ ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
+ if (ret)
+ return -EINVAL;
+
+ /* check for VLF Flag (set at power-on) */
+ if ((flags & RX6110_BIT_FLAG_VLF)) {
+ dev_warn(dev, "Voltage low, data is invalid.\n");
+ return -EINVAL;
+ }
+
+ /* read registers to date */
+ ret = regmap_bulk_read(rx6110->regmap, RX6110_REG_SEC, data,
+ RTC_NR_TIME);
+ if (ret)
+ return ret;
+
+ ret = rx6110_data_to_rtc_tm(data, tm);
+ if (ret)
+ return ret;
+
+ dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ return rtc_valid_tm(tm);
+}
+
+/**
+ * rx6110_init - initialize the rx6110 registers
+ *
+ * @rx6110: pointer to the rx6110 struct in use
+ *
+ */
+static int rx6110_init(struct rx6110_data *rx6110)
+{
+ struct rtc_device *rtc = rx6110->rtc;
+ int ext;
+ int flags;
+ int ctrl;
+ int ret;
+
+ /* set reserved register 0x17 with specified value of 0xB8 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
+ if (ret)
+ return ret;
+
+ /* set reserved register 0x30 with specified value of 0x00 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
+ if (ret)
+ return ret;
+
+ /* set reserved register 0x31 with specified value of 0x10 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
+ if (ret)
+ return ret;
+
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT,
+ RX6110_BIT_EXT_TE, 0);
+ if (ret)
+ return ret;
+
+ /* get current extension, flag, control register values */
+ ret = regmap_read(rx6110->regmap, RX6110_REG_EXT, &ext);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
+ if (ret)
+ return ret;
+
+ /* clear ctrl register */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_CTRL, 0);
+ if (ret)
+ return ret;
+
+ ctrl = 0;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALMIN, 0);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALHOUR, 0);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALWDAY, 0);
+ if (ret)
+ return ret;
+
+ dev_dbg(&rtc->dev, "ext: %x, flag: %x, ctrl: %x\n", ext, flags, ctrl);
+
+ /* check for VLF Flag (set at power-on) */
+ if ((flags & RX6110_BIT_FLAG_VLF))
+ dev_warn(&rtc->dev, "Voltage low, data loss detected.\n");
+
+ /* check for Alarm Flag */
+ if (flags & RX6110_BIT_FLAG_AF)
+ dev_warn(&rtc->dev, "An alarm may have been missed.\n");
+
+ /* check for Periodic Timer Flag */
+ if (flags & RX6110_BIT_FLAG_TF)
+ dev_warn(&rtc->dev, "Periodic timer was detected\n");
+
+ /* check for Update Timer Flag */
+ if (flags & RX6110_BIT_FLAG_UF)
+ dev_warn(&rtc->dev, "Update timer was detected\n");
+
+ /* clear all flags BUT VLF */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
+ RX6110_BIT_FLAG_AF |
+ RX6110_BIT_FLAG_UF |
+ RX6110_BIT_FLAG_TF,
+ 0);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static struct rtc_class_ops rx6110_rtc_ops = {
+ .read_time = rx6110_get_time,
+ .set_time = rx6110_set_time,
+};
+
+static struct regmap_config regmap_spi_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = RX6110_REG_IRQ,
+ .read_flag_mask = 0x80,
+};
+
+/**
+ * rx6110_probe - initialize rtc driver
+ * @spi: pointer to spi device
+ */
+static int rx6110_probe(struct spi_device *spi)
+{
+ struct rx6110_data *rx6110;
+ int err;
+
+ if ((spi->bits_per_word && spi->bits_per_word != 8)
+ || (spi->max_speed_hz > 2000000)
+ || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
+ dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
+ spi->bits_per_word, spi->max_speed_hz, spi->mode);
+ dev_warn(&spi->dev, "driving device in an unsupported mode");
+ }
+
+ rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
+ if (!rx6110)
+ return -ENOMEM;
+
+ rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
+ if (IS_ERR(rx6110->regmap)) {
+ dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
+ return PTR_ERR(rx6110->regmap);
+ }
+
+ spi_set_drvdata(spi, rx6110);
+
+ rx6110->rtc = devm_rtc_device_register(&spi->dev,
+ rx6110_driver.driver.name,
+ &rx6110_rtc_ops, THIS_MODULE);
+
+ if (IS_ERR(rx6110->rtc))
+ return PTR_ERR(rx6110->rtc);
+
+ err = rx6110_init(rx6110);
+ if (err)
+ return err;
+
+ rx6110->rtc->max_user_freq = 1;
+
+ return 0;
+}
+
+static int rx6110_remove(struct spi_device *spi)
+{
+ return 0;
+}
+
+static const struct spi_device_id rx6110_id[] = {
+ { "rx6110", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, rx6110_id);
+
+static struct spi_driver rx6110_driver = {
+ .driver = {
+ .name = "rx6110-rtc",
+ .owner = THIS_MODULE,
+ },
+ .probe = rx6110_probe,
+ .remove = rx6110_remove,
+ .id_table = rx6110_id,
+};
+
+module_spi_driver(rx6110_driver);
+
+MODULE_AUTHOR("Val Krutov <val.krutov@erd.epson.com>");
+MODULE_DESCRIPTION("RX-6110 SA RTC driver");
+MODULE_LICENSE("GPL");
--
2.6.2
--
--
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] 14+ messages in thread
* [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-08 9:54 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-08 9:54 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
Steffen Trumtrar
The RX6110 comes in two different variants: SPI and I2C.
This driver only supports the SPI variant.
If the need ever arises to also support the I2C variant, this driver
could easily be refactored to support both cases.
Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
Changes since v2:
- remove old copyright infos
- use the BIT() macro
- replace rx6110_get_week_day() with ffs()
- replace hardcoded offsets with enum
- fix copy-and-paste error in rx6110_init
- use regmap_bulk_write in set_time
- return -EINVAL instead of "fixing" time in the rtc
drivers/rtc/Kconfig | 9 +
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-rx6110.c | 438 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 448 insertions(+)
create mode 100644 drivers/rtc/rtc-rx6110.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2a524244afec..fbb26ccd512c 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -734,6 +734,15 @@ config RTC_DRV_RX4581
This driver can also be built as a module. If so the module
will be called rtc-rx4581.
+config RTC_DRV_RX6110
+ tristate "Epson RX-6110"
+ select REGMAP_SPI
+ help
+ If you say yes here you will get support for the Epson RX-6610.
+
+ This driver can also be built as a module. If so the module
+ will be called rtc-rx6110.
+
config RTC_DRV_MCP795
tristate "Microchip MCP795"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 231f76451615..1e8dfc6bbe82 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -128,6 +128,7 @@ obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o
obj-$(CONFIG_RTC_DRV_RV8803) += rtc-rv8803.o
obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o
+obj-$(CONFIG_RTC_DRV_RX6110) += rtc-rx6110.o
obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o
obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
new file mode 100644
index 000000000000..aa9d89d5d2de
--- /dev/null
+++ b/drivers/rtc/rtc-rx6110.c
@@ -0,0 +1,438 @@
+/*
+ * Driver for the Epson RTC module RX-6110 SA
+ *
+ * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
+ * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
+ *
+ * This driver software is distributed as is, without any warranty of any kind,
+ * either express or implied as further specified in the GNU Public License.
+ * This software may be used and distributed according to the terms of the GNU
+ * Public License, version 2 as published by the Free Software Foundation.
+ * See the file COPYING in the main directory of this archive for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/bcd.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+#include <linux/spi/spi.h>
+
+/* RX-6110 Register definitions */
+#define RX6110_REG_SEC 0x10
+#define RX6110_REG_MIN 0x11
+#define RX6110_REG_HOUR 0x12
+#define RX6110_REG_WDAY 0x13
+#define RX6110_REG_MDAY 0x14
+#define RX6110_REG_MONTH 0x15
+#define RX6110_REG_YEAR 0x16
+#define RX6110_REG_RES1 0x17
+#define RX6110_REG_ALMIN 0x18
+#define RX6110_REG_ALHOUR 0x19
+#define RX6110_REG_ALWDAY 0x1A
+#define RX6110_REG_TCOUNT0 0x1B
+#define RX6110_REG_TCOUNT1 0x1C
+#define RX6110_REG_EXT 0x1D
+#define RX6110_REG_FLAG 0x1E
+#define RX6110_REG_CTRL 0x1F
+#define RX6110_REG_USER0 0x20
+#define RX6110_REG_USER1 0x21
+#define RX6110_REG_USER2 0x22
+#define RX6110_REG_USER3 0x23
+#define RX6110_REG_USER4 0x24
+#define RX6110_REG_USER5 0x25
+#define RX6110_REG_USER6 0x26
+#define RX6110_REG_USER7 0x27
+#define RX6110_REG_USER8 0x28
+#define RX6110_REG_USER9 0x29
+#define RX6110_REG_USERA 0x2A
+#define RX6110_REG_USERB 0x2B
+#define RX6110_REG_USERC 0x2C
+#define RX6110_REG_USERD 0x2D
+#define RX6110_REG_USERE 0x2E
+#define RX6110_REG_USERF 0x2F
+#define RX6110_REG_RES2 0x30
+#define RX6110_REG_RES3 0x31
+#define RX6110_REG_IRQ 0x32
+
+#define RX6110_BIT_ALARM_EN BIT(7)
+
+/* Extension Register (1Dh) bit positions */
+#define RX6110_BIT_EXT_TSEL0 BIT(0)
+#define RX6110_BIT_EXT_TSEL1 BIT(1)
+#define RX6110_BIT_EXT_TSEL2 BIT(2)
+#define RX6110_BIT_EXT_WADA BIT(3)
+#define RX6110_BIT_EXT_TE BIT(4)
+#define RX6110_BIT_EXT_USEL BIT(5)
+#define RX6110_BIT_EXT_FSEL0 BIT(6)
+#define RX6110_BIT_EXT_FSEL1 BIT(7)
+
+/* Flag Register (1Eh) bit positions */
+#define RX6110_BIT_FLAG_VLF BIT(1)
+#define RX6110_BIT_FLAG_AF BIT(3)
+#define RX6110_BIT_FLAG_TF BIT(4)
+#define RX6110_BIT_FLAG_UF BIT(5)
+
+/* Control Register (1Fh) bit positions */
+#define RX6110_BIT_CTRL_TBKE BIT(0)
+#define RX6110_BIT_CTRL_TBKON BIT(1)
+#define RX6110_BIT_CTRL_TSTP BIT(2)
+#define RX6110_BIT_CTRL_AIE BIT(3)
+#define RX6110_BIT_CTRL_TIE BIT(4)
+#define RX6110_BIT_CTRL_UIE BIT(5)
+#define RX6110_BIT_CTRL_STOP BIT(6)
+#define RX6110_BIT_CTRL_TEST BIT(7)
+
+enum {
+ RTC_SEC = 0,
+ RTC_MIN,
+ RTC_HOUR,
+ RTC_WDAY,
+ RTC_MDAY,
+ RTC_MONTH,
+ RTC_YEAR,
+ RTC_NR_TIME
+};
+
+static struct spi_driver rx6110_driver;
+
+struct rx6110_data {
+ struct rtc_device *rtc;
+ struct regmap *regmap;
+};
+
+/**
+ * rx6110_rtc_tm_to_data - convert rtc_time to native time encoding
+ *
+ * @tm: holds date and time
+ * @data: holds the encoding in rx6110 native form
+ */
+static int rx6110_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+ pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ /*
+ * The year in the RTC is a value between 0 and 99.
+ * Assume that this represents the current century
+ * and disregard all other values.
+ */
+ if (tm->tm_year < 100 || tm->tm_year >= 200)
+ return -EINVAL;
+
+ data[RTC_SEC] = bin2bcd(tm->tm_sec);
+ data[RTC_MIN] = bin2bcd(tm->tm_min);
+ data[RTC_HOUR] = bin2bcd(tm->tm_hour);
+ data[RTC_WDAY] = 1 << bin2bcd(tm->tm_wday);
+ data[RTC_MDAY] = bin2bcd(tm->tm_mday);
+ data[RTC_MONTH] = bin2bcd(tm->tm_mon + 1);
+ data[RTC_YEAR] = bin2bcd(tm->tm_year % 100);
+
+ return 0;
+}
+
+/**
+ * rx6110_data_to_rtc_tm - convert native time encoding to rtc_time
+ *
+ * @data: holds the encoding in rx6110 native form
+ * @tm: holds date and time
+ */
+static int rx6110_data_to_rtc_tm(u8 *data, struct rtc_time *tm)
+{
+ tm->tm_sec = bcd2bin(data[RTC_SEC] & 0x7f);
+ tm->tm_min = bcd2bin(data[RTC_MIN] & 0x7f);
+ /* only 24-hour clock */
+ tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
+ tm->tm_wday = ffs(data[RTC_WDAY] & 0x7f);
+ tm->tm_mday = bcd2bin(data[RTC_MDAY] & 0x3f);
+ tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1;
+ tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100;
+
+ pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ /*
+ * The year in the RTC is a value between 0 and 99.
+ * Assume that this represents the current century
+ * and disregard all other values.
+ */
+ if (tm->tm_year < 100 || tm->tm_year >= 200)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * rx6110_set_time - set the current time in the rx6110 registers
+ *
+ * @dev: the rtc device in use
+ * @tm: holds date and time
+ *
+ * BUG: The HW assumes every year that is a multiple of 4 to be a leap
+ * year. Next time this is wrong is 2100, which will not be a leap year
+ *
+ * Note: If STOP is not set/cleared, the clock will start when the seconds
+ * register is written
+ *
+ */
+static int rx6110_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct rx6110_data *rx6110 = dev_get_drvdata(dev);
+ u8 data[RTC_NR_TIME];
+ int ret;
+
+ ret = rx6110_rtc_tm_to_data(tm, data);
+ if (ret < 0)
+ return ret;
+
+ /* set STOP bit before changing clock/calendar */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL,
+ RX6110_BIT_CTRL_STOP, RX6110_BIT_CTRL_STOP);
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_write(rx6110->regmap, RX6110_REG_SEC, data,
+ RTC_NR_TIME);
+ if (ret)
+ return ret;
+
+ /* The time in the RTC is valid. Be sure to have VLF cleared. */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
+ RX6110_BIT_FLAG_VLF, 0);
+ if (ret)
+ return ret;
+
+ /* clear STOP bit after changing clock/calendar */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL,
+ RX6110_BIT_CTRL_STOP, 0);
+
+ return ret;
+}
+
+/**
+ * rx6110_get_time - get the current time from the rx6110 registers
+ * @dev: the rtc device in use
+ * @tm: holds date and time
+ */
+static int rx6110_get_time(struct device *dev, struct rtc_time *tm)
+{
+ struct rx6110_data *rx6110 = dev_get_drvdata(dev);
+ u8 data[RTC_NR_TIME];
+ int flags;
+ int ret;
+
+ ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
+ if (ret)
+ return -EINVAL;
+
+ /* check for VLF Flag (set at power-on) */
+ if ((flags & RX6110_BIT_FLAG_VLF)) {
+ dev_warn(dev, "Voltage low, data is invalid.\n");
+ return -EINVAL;
+ }
+
+ /* read registers to date */
+ ret = regmap_bulk_read(rx6110->regmap, RX6110_REG_SEC, data,
+ RTC_NR_TIME);
+ if (ret)
+ return ret;
+
+ ret = rx6110_data_to_rtc_tm(data, tm);
+ if (ret)
+ return ret;
+
+ dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
+ tm->tm_sec, tm->tm_min, tm->tm_hour,
+ tm->tm_mday, tm->tm_mon, tm->tm_year);
+
+ return rtc_valid_tm(tm);
+}
+
+/**
+ * rx6110_init - initialize the rx6110 registers
+ *
+ * @rx6110: pointer to the rx6110 struct in use
+ *
+ */
+static int rx6110_init(struct rx6110_data *rx6110)
+{
+ struct rtc_device *rtc = rx6110->rtc;
+ int ext;
+ int flags;
+ int ctrl;
+ int ret;
+
+ /* set reserved register 0x17 with specified value of 0xB8 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
+ if (ret)
+ return ret;
+
+ /* set reserved register 0x30 with specified value of 0x00 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
+ if (ret)
+ return ret;
+
+ /* set reserved register 0x31 with specified value of 0x10 */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
+ if (ret)
+ return ret;
+
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT,
+ RX6110_BIT_EXT_TE, 0);
+ if (ret)
+ return ret;
+
+ /* get current extension, flag, control register values */
+ ret = regmap_read(rx6110->regmap, RX6110_REG_EXT, &ext);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
+ if (ret)
+ return ret;
+
+ /* clear ctrl register */
+ ret = regmap_write(rx6110->regmap, RX6110_REG_CTRL, 0);
+ if (ret)
+ return ret;
+
+ ctrl = 0;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALMIN, 0);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALHOUR, 0);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(rx6110->regmap, RX6110_REG_ALWDAY, 0);
+ if (ret)
+ return ret;
+
+ dev_dbg(&rtc->dev, "ext: %x, flag: %x, ctrl: %x\n", ext, flags, ctrl);
+
+ /* check for VLF Flag (set at power-on) */
+ if ((flags & RX6110_BIT_FLAG_VLF))
+ dev_warn(&rtc->dev, "Voltage low, data loss detected.\n");
+
+ /* check for Alarm Flag */
+ if (flags & RX6110_BIT_FLAG_AF)
+ dev_warn(&rtc->dev, "An alarm may have been missed.\n");
+
+ /* check for Periodic Timer Flag */
+ if (flags & RX6110_BIT_FLAG_TF)
+ dev_warn(&rtc->dev, "Periodic timer was detected\n");
+
+ /* check for Update Timer Flag */
+ if (flags & RX6110_BIT_FLAG_UF)
+ dev_warn(&rtc->dev, "Update timer was detected\n");
+
+ /* clear all flags BUT VLF */
+ ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
+ RX6110_BIT_FLAG_AF |
+ RX6110_BIT_FLAG_UF |
+ RX6110_BIT_FLAG_TF,
+ 0);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static struct rtc_class_ops rx6110_rtc_ops = {
+ .read_time = rx6110_get_time,
+ .set_time = rx6110_set_time,
+};
+
+static struct regmap_config regmap_spi_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = RX6110_REG_IRQ,
+ .read_flag_mask = 0x80,
+};
+
+/**
+ * rx6110_probe - initialize rtc driver
+ * @spi: pointer to spi device
+ */
+static int rx6110_probe(struct spi_device *spi)
+{
+ struct rx6110_data *rx6110;
+ int err;
+
+ if ((spi->bits_per_word && spi->bits_per_word != 8)
+ || (spi->max_speed_hz > 2000000)
+ || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
+ dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
+ spi->bits_per_word, spi->max_speed_hz, spi->mode);
+ dev_warn(&spi->dev, "driving device in an unsupported mode");
+ }
+
+ rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
+ if (!rx6110)
+ return -ENOMEM;
+
+ rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
+ if (IS_ERR(rx6110->regmap)) {
+ dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
+ return PTR_ERR(rx6110->regmap);
+ }
+
+ spi_set_drvdata(spi, rx6110);
+
+ rx6110->rtc = devm_rtc_device_register(&spi->dev,
+ rx6110_driver.driver.name,
+ &rx6110_rtc_ops, THIS_MODULE);
+
+ if (IS_ERR(rx6110->rtc))
+ return PTR_ERR(rx6110->rtc);
+
+ err = rx6110_init(rx6110);
+ if (err)
+ return err;
+
+ rx6110->rtc->max_user_freq = 1;
+
+ return 0;
+}
+
+static int rx6110_remove(struct spi_device *spi)
+{
+ return 0;
+}
+
+static const struct spi_device_id rx6110_id[] = {
+ { "rx6110", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, rx6110_id);
+
+static struct spi_driver rx6110_driver = {
+ .driver = {
+ .name = "rx6110-rtc",
+ .owner = THIS_MODULE,
+ },
+ .probe = rx6110_probe,
+ .remove = rx6110_remove,
+ .id_table = rx6110_id,
+};
+
+module_spi_driver(rx6110_driver);
+
+MODULE_AUTHOR("Val Krutov <val.krutov-vVP6MZSVwm2aMJb+Lgu22Q@public.gmane.org>");
+MODULE_DESCRIPTION("RX-6110 SA RTC driver");
+MODULE_LICENSE("GPL");
--
2.6.2
--
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] 14+ messages in thread
* [rtc-linux] Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 10:29 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:29 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree,
rtc-linux, Pawel Moll, Ian Campbell, Rob Herring, kernel,
Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> Add the binding documentation for the Epson RX6110 RTC.
>
> Acked-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
although I'd like a small change to be made below:
> ---
> Changes since v2:
> - removed the size field in i2c binding
>
> .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
>
> diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> new file mode 100644
> index 000000000000..71353542a59d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> @@ -0,0 +1,39 @@
> +Epson RX6110 Real Time Clock
> +============================
> +
> +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> +bus depends on the SPISEL pin and can not be configured via software.
> +
> +I2C mode
> +--------
> +
> +Required properties:
> + - compatible: should be: "epson,rx6110"
> + - reg : offset of the register set of the device
That should be the I2C address of the device, as in:
git grep "reg.*I2C address" Documentation/
regards
Philipp
--
--
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] 14+ messages in thread
* Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 10:29 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:29 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Pawel Moll, Ian Campbell,
Rob Herring, kernel-bIcnvbaLZ9MEGnE8C9+IrQ, Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> Add the binding documentation for the Epson RX6110 RTC.
>
> Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Reviewed-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
although I'd like a small change to be made below:
> ---
> Changes since v2:
> - removed the size field in i2c binding
>
> .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
>
> diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> new file mode 100644
> index 000000000000..71353542a59d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> @@ -0,0 +1,39 @@
> +Epson RX6110 Real Time Clock
> +============================
> +
> +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> +bus depends on the SPISEL pin and can not be configured via software.
> +
> +I2C mode
> +--------
> +
> +Required properties:
> + - compatible: should be: "epson,rx6110"
> + - reg : offset of the register set of the device
That should be the I2C address of the device, as in:
git grep "reg.*I2C address" Documentation/
regards
Philipp
--
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] 14+ messages in thread
* [rtc-linux] Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 10:29 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:29 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree,
rtc-linux, Pawel Moll, Ian Campbell, Rob Herring, kernel,
Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> Add the binding documentation for the Epson RX6110 RTC.
>
> Acked-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
although I'd like a small change to be made below:
> ---
> Changes since v2:
> - removed the size field in i2c binding
>
> .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
>
> diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> new file mode 100644
> index 000000000000..71353542a59d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> @@ -0,0 +1,39 @@
> +Epson RX6110 Real Time Clock
> +============================
> +
> +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> +bus depends on the SPISEL pin and can not be configured via software.
> +
> +I2C mode
> +--------
> +
> +Required properties:
> + - compatible: should be: "epson,rx6110"
> + - reg : offset of the register set of the device
That should be the I2C address of the device:
git grep "reg.*I2C address" Documentation/
regards
Philipp
--
--
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] 14+ messages in thread
* Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-08 10:29 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:29 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Pawel Moll, Ian Campbell,
Rob Herring, kernel-bIcnvbaLZ9MEGnE8C9+IrQ, Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> Add the binding documentation for the Epson RX6110 RTC.
>
> Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Reviewed-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
although I'd like a small change to be made below:
> ---
> Changes since v2:
> - removed the size field in i2c binding
>
> .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
>
> diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> new file mode 100644
> index 000000000000..71353542a59d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> @@ -0,0 +1,39 @@
> +Epson RX6110 Real Time Clock
> +============================
> +
> +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> +bus depends on the SPISEL pin and can not be configured via software.
> +
> +I2C mode
> +--------
> +
> +Required properties:
> + - compatible: should be: "epson,rx6110"
> + - reg : offset of the register set of the device
That should be the I2C address of the device:
git grep "reg.*I2C address" Documentation/
regards
Philipp
--
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] 14+ messages in thread
* [rtc-linux] Re: [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-08 10:30 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:30 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree,
rtc-linux, Pawel Moll, Ian Campbell, Rob Herring, kernel,
Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> The RX6110 comes in two different variants: SPI and I2C.
> This driver only supports the SPI variant.
>
> If the need ever arises to also support the I2C variant, this driver
> could easily be refactored to support both cases.
>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
I have a few suggestions:
[...]
> diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
> new file mode 100644
> index 000000000000..aa9d89d5d2de
> --- /dev/null
> +++ b/drivers/rtc/rtc-rx6110.c
> @@ -0,0 +1,438 @@
> +/*
> + * Driver for the Epson RTC module RX-6110 SA
> + *
> + * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel@pengutronix.de>
> + * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
> + *
> + * This driver software is distributed as is, without any warranty of any kind,
> + * either express or implied as further specified in the GNU Public License.
> + * This software may be used and distributed according to the terms of the GNU
> + * Public License, version 2 as published by the Free Software Foundation.
> + * See the file COPYING in the main directory of this archive for more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/bcd.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
I think these three can be dropped.
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +#include <linux/spi/spi.h>
> +
> +/* RX-6110 Register definitions */
[...]
> +
> +static struct spi_driver rx6110_driver;
Several drivers do this. Instead of the forward declaration and using
rx6110_driver.driver.name in devm_rtc_device_register below, why not
just have a #define RX6110_DRIVER_NAME "rx6110-rtc" and reuse that?
Actually, I think the "-rtc" suffix is superfluous in the rtc name.
I'd just use "rx6110" as a parameter to devm_rtc_device_register.
> +struct rx6110_data {
> + struct rtc_device *rtc;
> + struct regmap *regmap;
> +};
[...]
> +/**
> + * rx6110_init - initialize the rx6110 registers
> + *
> + * @rx6110: pointer to the rx6110 struct in use
> + *
> + */
> +static int rx6110_init(struct rx6110_data *rx6110)
> +{
> + struct rtc_device *rtc = rx6110->rtc;
> + int ext;
> + int flags;
> + int ctrl;
ctrl is unused, except in the dev_dbg to print 0 below.
> + int ret;
> +
> + /* set reserved register 0x17 with specified value of 0xB8 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
> + if (ret)
> + return ret;
> +
> + /* set reserved register 0x30 with specified value of 0x00 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
> + if (ret)
> + return ret;
> +
> + /* set reserved register 0x31 with specified value of 0x10 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
> + if (ret)
> + return ret;
Maybe combine those using regmap_multi_reg_write? Not sure if the
sequence can be reordered to also include the writes below.
> + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT,
> + RX6110_BIT_EXT_TE, 0);
> + if (ret)
> + return ret;
> +
> + /* get current extension, flag, control register values */
> + ret = regmap_read(rx6110->regmap, RX6110_REG_EXT, &ext);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
> + if (ret)
> + return ret;
> +
> + /* clear ctrl register */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_CTRL, 0);
> + if (ret)
> + return ret;
> +
> + ctrl = 0;
This is unused ...
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALMIN, 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALHOUR, 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALWDAY, 0);
> + if (ret)
> + return ret;
> +
> + dev_dbg(&rtc->dev, "ext: %x, flag: %x, ctrl: %x\n", ext, flags, ctrl);
... except here.
> +
> + /* check for VLF Flag (set at power-on) */
> + if ((flags & RX6110_BIT_FLAG_VLF))
> + dev_warn(&rtc->dev, "Voltage low, data loss detected.\n");
> +
> + /* check for Alarm Flag */
> + if (flags & RX6110_BIT_FLAG_AF)
> + dev_warn(&rtc->dev, "An alarm may have been missed.\n");
> +
> + /* check for Periodic Timer Flag */
> + if (flags & RX6110_BIT_FLAG_TF)
> + dev_warn(&rtc->dev, "Periodic timer was detected\n");
> +
> + /* check for Update Timer Flag */
> + if (flags & RX6110_BIT_FLAG_UF)
> + dev_warn(&rtc->dev, "Update timer was detected\n");
> +
> + /* clear all flags BUT VLF */
> + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
> + RX6110_BIT_FLAG_AF |
> + RX6110_BIT_FLAG_UF |
> + RX6110_BIT_FLAG_TF,
> + 0);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
[...]
> +/**
> + * rx6110_probe - initialize rtc driver
> + * @spi: pointer to spi device
> + */
> +static int rx6110_probe(struct spi_device *spi)
> +{
> + struct rx6110_data *rx6110;
> + int err;
> +
> + if ((spi->bits_per_word && spi->bits_per_word != 8)
> + || (spi->max_speed_hz > 2000000)
> + || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
> + dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
> + spi->bits_per_word, spi->max_speed_hz, spi->mode);
> + dev_warn(&spi->dev, "driving device in an unsupported mode");
> + }
> +
> + rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
> + if (!rx6110)
> + return -ENOMEM;
> +
> + rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
> + if (IS_ERR(rx6110->regmap)) {
> + dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
Maybe print the error code.
> + return PTR_ERR(rx6110->regmap);
> + }
> +
> + spi_set_drvdata(spi, rx6110);
> +
> + rx6110->rtc = devm_rtc_device_register(&spi->dev,
> + rx6110_driver.driver.name,
That could be just "rx6110" instead of "rx6110-rtc" in my opinion.
> + &rx6110_rtc_ops, THIS_MODULE);
> +
> + if (IS_ERR(rx6110->rtc))
> + return PTR_ERR(rx6110->rtc);
> +
> + err = rx6110_init(rx6110);
> + if (err)
> + return err;
> +
> + rx6110->rtc->max_user_freq = 1;
> +
> + return 0;
> +}
regards
Philipp
--
--
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] 14+ messages in thread
* Re: [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-08 10:30 ` Philipp Zabel
0 siblings, 0 replies; 14+ messages in thread
From: Philipp Zabel @ 2015-12-08 10:30 UTC (permalink / raw)
To: Steffen Trumtrar
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Pawel Moll, Ian Campbell,
Rob Herring, kernel-bIcnvbaLZ9MEGnE8C9+IrQ, Kumar Gala
Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> The RX6110 comes in two different variants: SPI and I2C.
> This driver only supports the SPI variant.
>
> If the need ever arises to also support the I2C variant, this driver
> could easily be refactored to support both cases.
>
> Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Reviewed-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
I have a few suggestions:
[...]
> diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
> new file mode 100644
> index 000000000000..aa9d89d5d2de
> --- /dev/null
> +++ b/drivers/rtc/rtc-rx6110.c
> @@ -0,0 +1,438 @@
> +/*
> + * Driver for the Epson RTC module RX-6110 SA
> + *
> + * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> + * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
> + *
> + * This driver software is distributed as is, without any warranty of any kind,
> + * either express or implied as further specified in the GNU Public License.
> + * This software may be used and distributed according to the terms of the GNU
> + * Public License, version 2 as published by the Free Software Foundation.
> + * See the file COPYING in the main directory of this archive for more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/bcd.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
I think these three can be dropped.
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +#include <linux/spi/spi.h>
> +
> +/* RX-6110 Register definitions */
[...]
> +
> +static struct spi_driver rx6110_driver;
Several drivers do this. Instead of the forward declaration and using
rx6110_driver.driver.name in devm_rtc_device_register below, why not
just have a #define RX6110_DRIVER_NAME "rx6110-rtc" and reuse that?
Actually, I think the "-rtc" suffix is superfluous in the rtc name.
I'd just use "rx6110" as a parameter to devm_rtc_device_register.
> +struct rx6110_data {
> + struct rtc_device *rtc;
> + struct regmap *regmap;
> +};
[...]
> +/**
> + * rx6110_init - initialize the rx6110 registers
> + *
> + * @rx6110: pointer to the rx6110 struct in use
> + *
> + */
> +static int rx6110_init(struct rx6110_data *rx6110)
> +{
> + struct rtc_device *rtc = rx6110->rtc;
> + int ext;
> + int flags;
> + int ctrl;
ctrl is unused, except in the dev_dbg to print 0 below.
> + int ret;
> +
> + /* set reserved register 0x17 with specified value of 0xB8 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
> + if (ret)
> + return ret;
> +
> + /* set reserved register 0x30 with specified value of 0x00 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
> + if (ret)
> + return ret;
> +
> + /* set reserved register 0x31 with specified value of 0x10 */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
> + if (ret)
> + return ret;
Maybe combine those using regmap_multi_reg_write? Not sure if the
sequence can be reordered to also include the writes below.
> + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT,
> + RX6110_BIT_EXT_TE, 0);
> + if (ret)
> + return ret;
> +
> + /* get current extension, flag, control register values */
> + ret = regmap_read(rx6110->regmap, RX6110_REG_EXT, &ext);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags);
> + if (ret)
> + return ret;
> +
> + /* clear ctrl register */
> + ret = regmap_write(rx6110->regmap, RX6110_REG_CTRL, 0);
> + if (ret)
> + return ret;
> +
> + ctrl = 0;
This is unused ...
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALMIN, 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALHOUR, 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(rx6110->regmap, RX6110_REG_ALWDAY, 0);
> + if (ret)
> + return ret;
> +
> + dev_dbg(&rtc->dev, "ext: %x, flag: %x, ctrl: %x\n", ext, flags, ctrl);
... except here.
> +
> + /* check for VLF Flag (set at power-on) */
> + if ((flags & RX6110_BIT_FLAG_VLF))
> + dev_warn(&rtc->dev, "Voltage low, data loss detected.\n");
> +
> + /* check for Alarm Flag */
> + if (flags & RX6110_BIT_FLAG_AF)
> + dev_warn(&rtc->dev, "An alarm may have been missed.\n");
> +
> + /* check for Periodic Timer Flag */
> + if (flags & RX6110_BIT_FLAG_TF)
> + dev_warn(&rtc->dev, "Periodic timer was detected\n");
> +
> + /* check for Update Timer Flag */
> + if (flags & RX6110_BIT_FLAG_UF)
> + dev_warn(&rtc->dev, "Update timer was detected\n");
> +
> + /* clear all flags BUT VLF */
> + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG,
> + RX6110_BIT_FLAG_AF |
> + RX6110_BIT_FLAG_UF |
> + RX6110_BIT_FLAG_TF,
> + 0);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
[...]
> +/**
> + * rx6110_probe - initialize rtc driver
> + * @spi: pointer to spi device
> + */
> +static int rx6110_probe(struct spi_device *spi)
> +{
> + struct rx6110_data *rx6110;
> + int err;
> +
> + if ((spi->bits_per_word && spi->bits_per_word != 8)
> + || (spi->max_speed_hz > 2000000)
> + || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
> + dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
> + spi->bits_per_word, spi->max_speed_hz, spi->mode);
> + dev_warn(&spi->dev, "driving device in an unsupported mode");
> + }
> +
> + rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
> + if (!rx6110)
> + return -ENOMEM;
> +
> + rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
> + if (IS_ERR(rx6110->regmap)) {
> + dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
Maybe print the error code.
> + return PTR_ERR(rx6110->regmap);
> + }
> +
> + spi_set_drvdata(spi, rx6110);
> +
> + rx6110->rtc = devm_rtc_device_register(&spi->dev,
> + rx6110_driver.driver.name,
That could be just "rx6110" instead of "rx6110-rtc" in my opinion.
> + &rx6110_rtc_ops, THIS_MODULE);
> +
> + if (IS_ERR(rx6110->rtc))
> + return PTR_ERR(rx6110->rtc);
> +
> + err = rx6110_init(rx6110);
> + if (err)
> + return err;
> +
> + rx6110->rtc->max_user_freq = 1;
> +
> + return 0;
> +}
regards
Philipp
--
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] 14+ messages in thread
* [rtc-linux] Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-10 10:56 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-10 10:56 UTC (permalink / raw)
To: Philipp Zabel
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree,
rtc-linux, Pawel Moll, Ian Campbell, Rob Herring, kernel,
Kumar Gala
Hi!
On Tue, Dec 08, 2015 at 11:29:26AM +0100, Philipp Zabel wrote:
> Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> > Add the binding documentation for the Epson RX6110 RTC.
> >
> > Acked-by: Rob Herring <robh@kernel.org>
> > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
>
> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
>
> although I'd like a small change to be made below:
>
> > ---
> > Changes since v2:
> > - removed the size field in i2c binding
> >
> > .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> > 1 file changed, 39 insertions(+)
> > create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> >
> > diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> > new file mode 100644
> > index 000000000000..71353542a59d
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> > @@ -0,0 +1,39 @@
> > +Epson RX6110 Real Time Clock
> > +============================
> > +
> > +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> > +bus depends on the SPISEL pin and can not be configured via software.
> > +
> > +I2C mode
> > +--------
> > +
> > +Required properties:
> > + - compatible: should be: "epson,rx6110"
> > + - reg : offset of the register set of the device
>
> That should be the I2C address of the device, as in:
> git grep "reg.*I2C address" Documentation/
>
Sounds reasonable. Changed.
Thanks,
Steffen Trumtrar
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
--
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] 14+ messages in thread
* Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding
@ 2015-12-10 10:56 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-10 10:56 UTC (permalink / raw)
To: Philipp Zabel
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Pawel Moll, Ian Campbell,
Rob Herring, kernel-bIcnvbaLZ9MEGnE8C9+IrQ, Kumar Gala
Hi!
On Tue, Dec 08, 2015 at 11:29:26AM +0100, Philipp Zabel wrote:
> Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> > Add the binding documentation for the Epson RX6110 RTC.
> >
> > Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
>
> Reviewed-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
>
> although I'd like a small change to be made below:
>
> > ---
> > Changes since v2:
> > - removed the size field in i2c binding
> >
> > .../devicetree/bindings/rtc/epson,rx6110.txt | 39 ++++++++++++++++++++++
> > 1 file changed, 39 insertions(+)
> > create mode 100644 Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> >
> > diff --git a/Documentation/devicetree/bindings/rtc/epson,rx6110.txt b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> > new file mode 100644
> > index 000000000000..71353542a59d
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/rtc/epson,rx6110.txt
> > @@ -0,0 +1,39 @@
> > +Epson RX6110 Real Time Clock
> > +============================
> > +
> > +The Epson RX6110 can be used with SPI or I2C busses. The kind of
> > +bus depends on the SPISEL pin and can not be configured via software.
> > +
> > +I2C mode
> > +--------
> > +
> > +Required properties:
> > + - compatible: should be: "epson,rx6110"
> > + - reg : offset of the register set of the device
>
> That should be the I2C address of the device, as in:
> git grep "reg.*I2C address" Documentation/
>
Sounds reasonable. Changed.
Thanks,
Steffen Trumtrar
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
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] 14+ messages in thread
* [rtc-linux] Re: [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-10 11:01 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-10 11:01 UTC (permalink / raw)
To: Philipp Zabel
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland, devicetree,
rtc-linux, Pawel Moll, Ian Campbell, Rob Herring, kernel,
Kumar Gala
Hi!
On Tue, Dec 08, 2015 at 11:30:21AM +0100, Philipp Zabel wrote:
> Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> > The RX6110 comes in two different variants: SPI and I2C.
> > This driver only supports the SPI variant.
> >
> > If the need ever arises to also support the I2C variant, this driver
> > could easily be refactored to support both cases.
> >
> > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
>
> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
>
> I have a few suggestions:
>
> [...]
> > diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
> > new file mode 100644
> > index 000000000000..aa9d89d5d2de
> > --- /dev/null
> > +++ b/drivers/rtc/rtc-rx6110.c
> > @@ -0,0 +1,438 @@
> > +/*
> > + * Driver for the Epson RTC module RX-6110 SA
> > + *
> > + * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel@pengutronix.de>
> > + * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
> > + *
> > + * This driver software is distributed as is, without any warranty of any kind,
> > + * either express or implied as further specified in the GNU Public License.
> > + * This software may be used and distributed according to the terms of the GNU
> > + * Public License, version 2 as published by the Free Software Foundation.
> > + * See the file COPYING in the main directory of this archive for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along with
> > + * this program. If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include <linux/bcd.h>
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
>
> > +#include <linux/of.h>
> > +#include <linux/of_device.h>
> > +#include <linux/of_gpio.h>
>
> I think these three can be dropped.
>
Okay.
> > +#include <linux/regmap.h>
> > +#include <linux/rtc.h>
> > +#include <linux/spi/spi.h>
> > +
> > +/* RX-6110 Register definitions */
> [...]
> > +
> > +static struct spi_driver rx6110_driver;
>
> Several drivers do this. Instead of the forward declaration and using
> rx6110_driver.driver.name in devm_rtc_device_register below, why not
> just have a #define RX6110_DRIVER_NAME "rx6110-rtc" and reuse that?
> Actually, I think the "-rtc" suffix is superfluous in the rtc name.
> I'd just use "rx6110" as a parameter to devm_rtc_device_register.
>
Yeah, why not. The define seems to be a cleaner solution than the
forward declaration. Changed.
> > +struct rx6110_data {
> > + struct rtc_device *rtc;
> > + struct regmap *regmap;
> > +};
> [...]
> > +/**
> > + * rx6110_init - initialize the rx6110 registers
> > + *
> > + * @rx6110: pointer to the rx6110 struct in use
> > + *
> > + */
> > +static int rx6110_init(struct rx6110_data *rx6110)
> > +{
> > + struct rtc_device *rtc = rx6110->rtc;
> > + int ext;
> > + int flags;
> > + int ctrl;
>
> ctrl is unused, except in the dev_dbg to print 0 below.
>
> > + int ret;
> > +
> > + /* set reserved register 0x17 with specified value of 0xB8 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
> > + if (ret)
> > + return ret;
> > +
> > + /* set reserved register 0x30 with specified value of 0x00 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
> > + if (ret)
> > + return ret;
> > +
> > + /* set reserved register 0x31 with specified value of 0x10 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
> > + if (ret)
> > + return ret;
>
> Maybe combine those using regmap_multi_reg_write? Not sure if the
> sequence can be reordered to also include the writes below.
>
Never heard of it, but it sounds like a good idea.
(...)
> > +/**
> > + * rx6110_probe - initialize rtc driver
> > + * @spi: pointer to spi device
> > + */
> > +static int rx6110_probe(struct spi_device *spi)
> > +{
> > + struct rx6110_data *rx6110;
> > + int err;
> > +
> > + if ((spi->bits_per_word && spi->bits_per_word != 8)
> > + || (spi->max_speed_hz > 2000000)
> > + || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
> > + dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
> > + spi->bits_per_word, spi->max_speed_hz, spi->mode);
> > + dev_warn(&spi->dev, "driving device in an unsupported mode");
> > + }
> > +
> > + rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
> > + if (!rx6110)
> > + return -ENOMEM;
> > +
> > + rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
> > + if (IS_ERR(rx6110->regmap)) {
> > + dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
>
> Maybe print the error code.
>
Done.
Thanks,
Steffen
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
--
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] 14+ messages in thread
* Re: [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock
@ 2015-12-10 11:01 ` Steffen Trumtrar
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Trumtrar @ 2015-12-10 11:01 UTC (permalink / raw)
To: Philipp Zabel
Cc: Alessandro Zummo, Alexandre Belloni, Mark Rutland,
devicetree-u79uwXL29TY76Z2rM5mHXA,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Pawel Moll, Ian Campbell,
Rob Herring, kernel-bIcnvbaLZ9MEGnE8C9+IrQ, Kumar Gala
Hi!
On Tue, Dec 08, 2015 at 11:30:21AM +0100, Philipp Zabel wrote:
> Am Dienstag, den 08.12.2015, 10:54 +0100 schrieb Steffen Trumtrar:
> > The RX6110 comes in two different variants: SPI and I2C.
> > This driver only supports the SPI variant.
> >
> > If the need ever arises to also support the I2C variant, this driver
> > could easily be refactored to support both cases.
> >
> > Signed-off-by: Steffen Trumtrar <s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
>
> Reviewed-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
>
> I have a few suggestions:
>
> [...]
> > diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
> > new file mode 100644
> > index 000000000000..aa9d89d5d2de
> > --- /dev/null
> > +++ b/drivers/rtc/rtc-rx6110.c
> > @@ -0,0 +1,438 @@
> > +/*
> > + * Driver for the Epson RTC module RX-6110 SA
> > + *
> > + * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > + * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved.
> > + *
> > + * This driver software is distributed as is, without any warranty of any kind,
> > + * either express or implied as further specified in the GNU Public License.
> > + * This software may be used and distributed according to the terms of the GNU
> > + * Public License, version 2 as published by the Free Software Foundation.
> > + * See the file COPYING in the main directory of this archive for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along with
> > + * this program. If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include <linux/bcd.h>
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
>
> > +#include <linux/of.h>
> > +#include <linux/of_device.h>
> > +#include <linux/of_gpio.h>
>
> I think these three can be dropped.
>
Okay.
> > +#include <linux/regmap.h>
> > +#include <linux/rtc.h>
> > +#include <linux/spi/spi.h>
> > +
> > +/* RX-6110 Register definitions */
> [...]
> > +
> > +static struct spi_driver rx6110_driver;
>
> Several drivers do this. Instead of the forward declaration and using
> rx6110_driver.driver.name in devm_rtc_device_register below, why not
> just have a #define RX6110_DRIVER_NAME "rx6110-rtc" and reuse that?
> Actually, I think the "-rtc" suffix is superfluous in the rtc name.
> I'd just use "rx6110" as a parameter to devm_rtc_device_register.
>
Yeah, why not. The define seems to be a cleaner solution than the
forward declaration. Changed.
> > +struct rx6110_data {
> > + struct rtc_device *rtc;
> > + struct regmap *regmap;
> > +};
> [...]
> > +/**
> > + * rx6110_init - initialize the rx6110 registers
> > + *
> > + * @rx6110: pointer to the rx6110 struct in use
> > + *
> > + */
> > +static int rx6110_init(struct rx6110_data *rx6110)
> > +{
> > + struct rtc_device *rtc = rx6110->rtc;
> > + int ext;
> > + int flags;
> > + int ctrl;
>
> ctrl is unused, except in the dev_dbg to print 0 below.
>
> > + int ret;
> > +
> > + /* set reserved register 0x17 with specified value of 0xB8 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES1, 0xB8);
> > + if (ret)
> > + return ret;
> > +
> > + /* set reserved register 0x30 with specified value of 0x00 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES2, 0x00);
> > + if (ret)
> > + return ret;
> > +
> > + /* set reserved register 0x31 with specified value of 0x10 */
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_RES3, 0x10);
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_write(rx6110->regmap, RX6110_REG_IRQ, 0x0);
> > + if (ret)
> > + return ret;
>
> Maybe combine those using regmap_multi_reg_write? Not sure if the
> sequence can be reordered to also include the writes below.
>
Never heard of it, but it sounds like a good idea.
(...)
> > +/**
> > + * rx6110_probe - initialize rtc driver
> > + * @spi: pointer to spi device
> > + */
> > +static int rx6110_probe(struct spi_device *spi)
> > +{
> > + struct rx6110_data *rx6110;
> > + int err;
> > +
> > + if ((spi->bits_per_word && spi->bits_per_word != 8)
> > + || (spi->max_speed_hz > 2000000)
> > + || (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) {
> > + dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n",
> > + spi->bits_per_word, spi->max_speed_hz, spi->mode);
> > + dev_warn(&spi->dev, "driving device in an unsupported mode");
> > + }
> > +
> > + rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL);
> > + if (!rx6110)
> > + return -ENOMEM;
> > +
> > + rx6110->regmap = devm_regmap_init_spi(spi, ®map_spi_config);
> > + if (IS_ERR(rx6110->regmap)) {
> > + dev_err(&spi->dev, "regmap init failed for rtc rx6110\n");
>
> Maybe print the error code.
>
Done.
Thanks,
Steffen
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
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] 14+ messages in thread
end of thread, other threads:[~2015-12-10 11:01 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-08 9:54 [rtc-linux] [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding Steffen Trumtrar
2015-12-08 9:54 ` Steffen Trumtrar
2015-12-08 9:54 ` [rtc-linux] [PATCH v3 2/2] rtc: add driver for RX6110SA real time clock Steffen Trumtrar
2015-12-08 9:54 ` Steffen Trumtrar
2015-12-08 10:30 ` [rtc-linux] " Philipp Zabel
2015-12-08 10:30 ` Philipp Zabel
2015-12-10 11:01 ` [rtc-linux] " Steffen Trumtrar
2015-12-10 11:01 ` Steffen Trumtrar
2015-12-08 10:29 ` [rtc-linux] Re: [PATCH v3 1/2] Documentation: devicetree: add epson rx6110 binding Philipp Zabel
2015-12-08 10:29 ` Philipp Zabel
2015-12-10 10:56 ` [rtc-linux] " Steffen Trumtrar
2015-12-10 10:56 ` Steffen Trumtrar
2015-12-08 10:29 ` [rtc-linux] " Philipp Zabel
2015-12-08 10:29 ` Philipp Zabel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.