All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH v2 0/2] RTC support for NXP LPC18xx family
@ 2015-05-15 13:25 ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm, a.zummo
  Cc: Joachim Eastwood, wellsk40, rtc-linux, devicetree,
	linux-arm-kernel, alexandre.belloni, joshc

This patch set adds support for the RTC found on many NXP devices
including LPC24xx/178x/18xx/43xx. The RTC provides calendar and
clock functionality together with periodic tick and alarm interrupt
support.

The driver is a rework of an old driver by Kevin Wells. It has been
modified to support modern resource allocation, device tree and
generally cleaned up.

This version address the comments from Josh Cartwright and Alexandre
Belloni.

changes since v1:
 - s/lpc2k/lpc24xx for better consistency
 - fix Kconfig entry
 - drop support for old versions for the ip block

Patch set is based on Linux v4.1-rc1.

Base support for the NXP LPC18xx family can be found here:
http://marc.info/?l=linux-arm-kernel&m=143016894704253&w=2


Joachim Eastwood (2):
  rtc: add rtc-lpc24xx driver
  doc: dt: add documentation for nxp,lpc1788-rtc

 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt    |  21 ++
 drivers/rtc/Kconfig                                |  13 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-lpc24xx.c                          | 341 +++++++++++++++++++++
 4 files changed, 376 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

-- 
1.8.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 0/2] RTC support for NXP LPC18xx family
@ 2015-05-15 13:25 ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ
  Cc: Joachim Eastwood, wellsk40-Re5JQEeQqe8AvxtiuMwx3w,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	joshc-acOepvfBmUk

This patch set adds support for the RTC found on many NXP devices
including LPC24xx/178x/18xx/43xx. The RTC provides calendar and
clock functionality together with periodic tick and alarm interrupt
support.

The driver is a rework of an old driver by Kevin Wells. It has been
modified to support modern resource allocation, device tree and
generally cleaned up.

This version address the comments from Josh Cartwright and Alexandre
Belloni.

changes since v1:
 - s/lpc2k/lpc24xx for better consistency
 - fix Kconfig entry
 - drop support for old versions for the ip block

Patch set is based on Linux v4.1-rc1.

Base support for the NXP LPC18xx family can be found here:
http://marc.info/?l=linux-arm-kernel&m=143016894704253&w=2


Joachim Eastwood (2):
  rtc: add rtc-lpc24xx driver
  doc: dt: add documentation for nxp,lpc1788-rtc

 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt    |  21 ++
 drivers/rtc/Kconfig                                |  13 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-lpc24xx.c                          | 341 +++++++++++++++++++++
 4 files changed, 376 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

-- 
1.8.0

--
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] 24+ messages in thread

* [PATCH v2 0/2] RTC support for NXP LPC18xx family
@ 2015-05-15 13:25 ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: linux-arm-kernel

This patch set adds support for the RTC found on many NXP devices
including LPC24xx/178x/18xx/43xx. The RTC provides calendar and
clock functionality together with periodic tick and alarm interrupt
support.

The driver is a rework of an old driver by Kevin Wells. It has been
modified to support modern resource allocation, device tree and
generally cleaned up.

This version address the comments from Josh Cartwright and Alexandre
Belloni.

changes since v1:
 - s/lpc2k/lpc24xx for better consistency
 - fix Kconfig entry
 - drop support for old versions for the ip block

Patch set is based on Linux v4.1-rc1.

Base support for the NXP LPC18xx family can be found here:
http://marc.info/?l=linux-arm-kernel&m=143016894704253&w=2


Joachim Eastwood (2):
  rtc: add rtc-lpc24xx driver
  doc: dt: add documentation for nxp,lpc1788-rtc

 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt    |  21 ++
 drivers/rtc/Kconfig                                |  13 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-lpc24xx.c                          | 341 +++++++++++++++++++++
 4 files changed, 376 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

-- 
1.8.0

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [rtc-linux] [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm, a.zummo
  Cc: Joachim Eastwood, wellsk40, rtc-linux, devicetree,
	linux-arm-kernel, alexandre.belloni, joshc

Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
The RTC provides calendar and clock functionality together with
periodic tick and alarm interrupt support.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/rtc/Kconfig       |  13 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-lpc24xx.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 355 insertions(+)
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6149ae01e11f..279342e8168b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
 	  This driver can also be buillt as a module. If so, the module
 	  will be called rtc-jz4740.
 
+config RTC_DRV_LPC24XX
+	depends on ARCH_LPC18XX || COMPILE_TEST
+	depends on HAS_IOMEM
+	depends on OF
+	tristate "NXP LPC24xx RTC"
+	help
+	  This enables support for the NXP RTC found which can be found on
+	  LPC24xx/178x/18xx/43xx devices.
+
+	  If you have one of the devices above enable this driver to use
+	  the hardware RTC. This driver can also be buillt as a module. If
+	  so, the module will be called rtc-lpc24xx.
+
 config RTC_DRV_LPC32XX
 	depends on ARCH_LPC32XX
 	tristate "NXP LPC32XX RTC"
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c31731c29762..8687a2e13247 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
 obj-$(CONFIG_RTC_DRV_ISL12057)	+= rtc-isl12057.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
+obj-$(CONFIG_RTC_DRV_LPC24XX)	+= rtc-lpc24xx.o
 obj-$(CONFIG_RTC_DRV_LPC32XX)	+= rtc-lpc32xx.o
 obj-$(CONFIG_RTC_DRV_LOONGSON1)	+= rtc-ls1x.o
 obj-$(CONFIG_RTC_DRV_M41T80)	+= rtc-m41t80.o
diff --git a/drivers/rtc/rtc-lpc24xx.c b/drivers/rtc/rtc-lpc24xx.c
new file mode 100644
index 000000000000..33caa00fd44f
--- /dev/null
+++ b/drivers/rtc/rtc-lpc24xx.c
@@ -0,0 +1,341 @@
+/*
+ * Driver for NXP LPC24xx/178x/18xx/43xx Real-Time Clock (RTC)
+ *
+ * Copyright (C) 2011 NXP Semiconductors
+ * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+/* LPC24xx RTC register offsets */
+#define LPC24XX_ILR		0x00
+#define LPC24XX_CTC		0x04
+#define LPC24XX_CCR		0x08
+#define LPC24XX_CIIR		0x0c
+#define LPC24XX_AMR		0x10
+#define LPC24XX_CTIME0		0x14
+#define LPC24XX_CTIME1		0x18
+#define LPC24XX_CTIME2		0x1c
+#define LPC24XX_SEC		0x20
+#define LPC24XX_MIN		0x24
+#define LPC24XX_HOUR		0x28
+#define LPC24XX_DOM		0x2c
+#define LPC24XX_DOW		0x30
+#define LPC24XX_DOY		0x34
+#define LPC24XX_MONTH		0x38
+#define LPC24XX_YEAR		0x3c
+#define LPC24XX_ALSEC		0x60
+#define LPC24XX_ALMIN		0x64
+#define LPC24XX_ALHOUR		0x68
+#define LPC24XX_ALDOM		0x6c
+#define LPC24XX_ALDOW		0x70
+#define LPC24XX_ALDOY		0x74
+#define LPC24XX_ALMON		0x78
+#define LPC24XX_ALYEAR		0x7c
+
+#define LPC24XX_RTCCIF		BIT(0)
+#define LPC24XX_RTCALF		BIT(1)
+
+#define LPC24XX_CLKEN		BIT(0)
+#define LPC24XX_CTCRST		BIT(1)
+
+#define LPC24XX_IMSEC		BIT(0)
+#define LPC24XX_IMMIN		BIT(1)
+#define LPC24XX_IMHOUR		BIT(2)
+#define LPC24XX_IMDOM		BIT(3)
+#define LPC24XX_IMDOW		BIT(4)
+#define LPC24XX_IMDOY		BIT(5)
+#define LPC24XX_IMMON		BIT(6)
+#define LPC24XX_IMYEAR		BIT(7)
+
+#define LPC24XX_ALARM_DISABLE	0xff
+
+#define CT0_SECS(x)		(((x) >> 0)  & 0x3f)
+#define CT0_MINS(x)		(((x) >> 8)  & 0x3f)
+#define CT0_HOURS(x)		(((x) >> 16) & 0x1f)
+#define CT0_DOW(x)		(((x) >> 24) & 0x07)
+#define CT1_DOM(x)		(((x) >> 0)  & 0x1f)
+#define CT1_MONTH(x)		(((x) >> 8)  & 0x0f)
+#define CT1_YEAR(x)		(((x) >> 16) & 0xfff)
+#define CT2_DOY(x)		(((x) >> 0)  & 0xfff)
+
+#define rtc_readl(dev, reg)		readl((dev)->rtc_base + (reg))
+#define rtc_writel(dev, reg, val)	writel((val), (dev)->rtc_base + (reg))
+
+struct lpc24xx_rtc {
+	void __iomem *rtc_base;
+	struct rtc_device *rtc;
+	struct clk *clk_rtc;
+	struct clk *clk_reg;
+};
+
+static int lpc24xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 rtc_ctrl;
+
+	/* Disable RTC during update */
+	rtc_ctrl = rtc_readl(rtc, LPC24XX_CCR);
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl & ~LPC24XX_CLKEN);
+
+	rtc_writel(rtc, LPC24XX_SEC,	tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_MIN,	tm->tm_min);
+	rtc_writel(rtc, LPC24XX_HOUR,	tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_DOW,	tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_DOM,	tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_DOY,	tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_MONTH,	tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_YEAR,	tm->tm_year);
+
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl | LPC24XX_CLKEN);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 ct0, ct1, ct2;
+
+	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
+	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
+	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
+
+	tm->tm_sec  = CT0_SECS(ct0);
+	tm->tm_min  = CT0_MINS(ct0);
+	tm->tm_hour = CT0_HOURS(ct0);
+	tm->tm_wday = CT0_DOW(ct0);
+	tm->tm_mon  = CT1_MONTH(ct1);
+	tm->tm_mday = CT1_DOM(ct1);
+	tm->tm_year = CT1_YEAR(ct1);
+	tm->tm_yday = CT2_DOY(ct2);
+
+	if (rtc_valid_tm(tm) < 0) {
+		dev_warn(dev, "retrieved date and time is invalid\n");
+		rtc_time64_to_tm(0, tm);
+		lpc24xx_rtc_set_time(dev, tm);
+	}
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	tm->tm_sec  = rtc_readl(rtc, LPC24XX_ALSEC);
+	tm->tm_min  = rtc_readl(rtc, LPC24XX_ALMIN);
+	tm->tm_hour = rtc_readl(rtc, LPC24XX_ALHOUR);
+	tm->tm_mday = rtc_readl(rtc, LPC24XX_ALDOM);
+	tm->tm_wday = rtc_readl(rtc, LPC24XX_ALDOW);
+	tm->tm_yday = rtc_readl(rtc, LPC24XX_ALDOY);
+	tm->tm_mon  = rtc_readl(rtc, LPC24XX_ALMON);
+	tm->tm_year = rtc_readl(rtc, LPC24XX_ALYEAR);
+
+	wkalrm->enabled = rtc_readl(rtc, LPC24XX_AMR) == 0;
+	wkalrm->pending = !!(rtc_readl(rtc, LPC24XX_ILR) & LPC24XX_RTCCIF);
+
+	return rtc_valid_tm(&wkalrm->time);
+}
+
+static int lpc24xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	/* Disable alarm IRQs during update */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	rtc_writel(rtc, LPC24XX_ALSEC,  tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_ALMIN,  tm->tm_min);
+	rtc_writel(rtc, LPC24XX_ALHOUR, tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_ALDOM,  tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_ALDOW,  tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_ALDOY,  tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_ALMON,  tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_ALYEAR, tm->tm_year);
+
+	if (wkalrm->enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_alarm_irq_enable(struct device *dev,
+					unsigned int enabled)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+
+	if (enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+	else
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	return 0;
+}
+
+static irqreturn_t lpc24xx_rtc_interrupt(int irq, void *dev)
+{
+	unsigned long events = RTC_IRQF;
+	struct lpc24xx_rtc *rtc = dev;
+	u32 rtc_iir;
+
+	/* Check interrupt cause */
+	rtc_iir = rtc_readl(rtc, LPC24XX_ILR);
+
+	/* 1s tick */
+	if (rtc_iir & LPC24XX_RTCCIF)
+		events |= RTC_UF;
+
+	/* Alarm */
+	if (rtc_iir & LPC24XX_RTCALF) {
+		events |= RTC_AF;
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	}
+
+	/* Clear interrupt status and report event */
+	rtc_writel(rtc, LPC24XX_ILR, rtc_iir);
+	rtc_update_irq(rtc->rtc, 1, events);
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops lpc24xx_rtc_ops = {
+	.read_time		= lpc24xx_rtc_read_time,
+	.set_time		= lpc24xx_rtc_set_time,
+	.read_alarm		= lpc24xx_rtc_read_alarm,
+	.set_alarm		= lpc24xx_rtc_set_alarm,
+	.alarm_irq_enable	= lpc24xx_rtc_alarm_irq_enable,
+};
+
+static const struct of_device_id lpc24xx_rtc_match[] = {
+	{ .compatible = "nxp,lpc1788-rtc" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc24xx_rtc_match);
+
+static int lpc24xx_rtc_probe(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc;
+	struct resource *res;
+	int irq, ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->rtc_base))
+		return PTR_ERR(rtc->rtc_base);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_warn(&pdev->dev, "can't get interrupt resource\n");
+		return irq;
+	}
+
+	rtc->clk_rtc = devm_clk_get(&pdev->dev, "rtc");
+	if (IS_ERR(rtc->clk_rtc)) {
+		dev_err(&pdev->dev, "error getting rtc clock\n");
+		return PTR_ERR(rtc->clk_rtc);
+	}
+
+	rtc->clk_reg = devm_clk_get(&pdev->dev, "reg");
+	if (IS_ERR(rtc->clk_reg)) {
+		dev_err(&pdev->dev, "error getting reg clock\n");
+		return PTR_ERR(rtc->clk_reg);
+	}
+
+	ret = clk_prepare_enable(rtc->clk_rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable rtc clock\n");
+		return ret;
+	}
+
+	ret = clk_prepare_enable(rtc->clk_reg);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable reg clock\n");
+		goto disable_rtc_clk;
+	}
+
+	platform_set_drvdata(pdev, rtc);
+
+	/* Clear the counter increment state */
+	rtc_writel(rtc, LPC24XX_ILR, LPC24XX_RTCCIF);
+
+	/* Only 1-second interrupt will generate interrupt */
+	rtc_writel(rtc, LPC24XX_CIIR, LPC24XX_IMSEC);
+
+	/* Enable RTC count */
+	rtc_writel(rtc, LPC24XX_CCR, LPC24XX_CLKEN);
+
+	ret = devm_request_irq(&pdev->dev, irq, lpc24xx_rtc_interrupt, 0,
+			       pdev->name, rtc);
+	if (ret < 0) {
+		dev_warn(&pdev->dev, "can't request interrupt\n");
+		goto disable_clks;
+	}
+
+	rtc->rtc = devm_rtc_device_register(&pdev->dev, "lpc24xx-rtc",
+					    &lpc24xx_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc)) {
+		dev_err(&pdev->dev, "can't register rtc device\n");
+		ret = PTR_ERR(rtc->rtc);
+		goto disable_clks;
+	}
+
+	return 0;
+
+disable_clks:
+	clk_disable_unprepare(rtc->clk_reg);
+disable_rtc_clk:
+	clk_disable_unprepare(rtc->clk_rtc);
+	return ret;
+}
+
+static int lpc24xx_rtc_remove(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc = platform_get_drvdata(pdev);
+
+	/*
+	 * Disable alarm, but leave RTC enabled so it
+	 * remains valid across reset cycles.
+	 */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	rtc_writel(rtc, LPC24XX_CCR, 0);
+
+	clk_disable_unprepare(rtc->clk_rtc);
+	clk_disable_unprepare(rtc->clk_reg);
+
+	return 0;
+}
+
+static struct platform_driver lpc24xx_rtc_driver = {
+	.probe	= lpc24xx_rtc_probe,
+	.remove	= lpc24xx_rtc_remove,
+	.driver	= {
+		.name = "lpc24xx-rtc",
+		.of_match_table	= lpc24xx_rtc_match,
+	},
+};
+module_platform_driver(lpc24xx_rtc_driver);
+
+MODULE_AUTHOR("Kevin Wells <wellsk40@gmail.com");
+MODULE_DESCRIPTION("RTC driver for the LPC24xx SoC");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:lpc24xx-rtc");
-- 
1.8.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ
  Cc: Joachim Eastwood, wellsk40-Re5JQEeQqe8AvxtiuMwx3w,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	joshc-acOepvfBmUk

Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
The RTC provides calendar and clock functionality together with
periodic tick and alarm interrupt support.

Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/rtc/Kconfig       |  13 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-lpc24xx.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 355 insertions(+)
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6149ae01e11f..279342e8168b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
 	  This driver can also be buillt as a module. If so, the module
 	  will be called rtc-jz4740.
 
+config RTC_DRV_LPC24XX
+	depends on ARCH_LPC18XX || COMPILE_TEST
+	depends on HAS_IOMEM
+	depends on OF
+	tristate "NXP LPC24xx RTC"
+	help
+	  This enables support for the NXP RTC found which can be found on
+	  LPC24xx/178x/18xx/43xx devices.
+
+	  If you have one of the devices above enable this driver to use
+	  the hardware RTC. This driver can also be buillt as a module. If
+	  so, the module will be called rtc-lpc24xx.
+
 config RTC_DRV_LPC32XX
 	depends on ARCH_LPC32XX
 	tristate "NXP LPC32XX RTC"
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c31731c29762..8687a2e13247 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
 obj-$(CONFIG_RTC_DRV_ISL12057)	+= rtc-isl12057.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
+obj-$(CONFIG_RTC_DRV_LPC24XX)	+= rtc-lpc24xx.o
 obj-$(CONFIG_RTC_DRV_LPC32XX)	+= rtc-lpc32xx.o
 obj-$(CONFIG_RTC_DRV_LOONGSON1)	+= rtc-ls1x.o
 obj-$(CONFIG_RTC_DRV_M41T80)	+= rtc-m41t80.o
diff --git a/drivers/rtc/rtc-lpc24xx.c b/drivers/rtc/rtc-lpc24xx.c
new file mode 100644
index 000000000000..33caa00fd44f
--- /dev/null
+++ b/drivers/rtc/rtc-lpc24xx.c
@@ -0,0 +1,341 @@
+/*
+ * Driver for NXP LPC24xx/178x/18xx/43xx Real-Time Clock (RTC)
+ *
+ * Copyright (C) 2011 NXP Semiconductors
+ * Copyright (C) 2015 Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+/* LPC24xx RTC register offsets */
+#define LPC24XX_ILR		0x00
+#define LPC24XX_CTC		0x04
+#define LPC24XX_CCR		0x08
+#define LPC24XX_CIIR		0x0c
+#define LPC24XX_AMR		0x10
+#define LPC24XX_CTIME0		0x14
+#define LPC24XX_CTIME1		0x18
+#define LPC24XX_CTIME2		0x1c
+#define LPC24XX_SEC		0x20
+#define LPC24XX_MIN		0x24
+#define LPC24XX_HOUR		0x28
+#define LPC24XX_DOM		0x2c
+#define LPC24XX_DOW		0x30
+#define LPC24XX_DOY		0x34
+#define LPC24XX_MONTH		0x38
+#define LPC24XX_YEAR		0x3c
+#define LPC24XX_ALSEC		0x60
+#define LPC24XX_ALMIN		0x64
+#define LPC24XX_ALHOUR		0x68
+#define LPC24XX_ALDOM		0x6c
+#define LPC24XX_ALDOW		0x70
+#define LPC24XX_ALDOY		0x74
+#define LPC24XX_ALMON		0x78
+#define LPC24XX_ALYEAR		0x7c
+
+#define LPC24XX_RTCCIF		BIT(0)
+#define LPC24XX_RTCALF		BIT(1)
+
+#define LPC24XX_CLKEN		BIT(0)
+#define LPC24XX_CTCRST		BIT(1)
+
+#define LPC24XX_IMSEC		BIT(0)
+#define LPC24XX_IMMIN		BIT(1)
+#define LPC24XX_IMHOUR		BIT(2)
+#define LPC24XX_IMDOM		BIT(3)
+#define LPC24XX_IMDOW		BIT(4)
+#define LPC24XX_IMDOY		BIT(5)
+#define LPC24XX_IMMON		BIT(6)
+#define LPC24XX_IMYEAR		BIT(7)
+
+#define LPC24XX_ALARM_DISABLE	0xff
+
+#define CT0_SECS(x)		(((x) >> 0)  & 0x3f)
+#define CT0_MINS(x)		(((x) >> 8)  & 0x3f)
+#define CT0_HOURS(x)		(((x) >> 16) & 0x1f)
+#define CT0_DOW(x)		(((x) >> 24) & 0x07)
+#define CT1_DOM(x)		(((x) >> 0)  & 0x1f)
+#define CT1_MONTH(x)		(((x) >> 8)  & 0x0f)
+#define CT1_YEAR(x)		(((x) >> 16) & 0xfff)
+#define CT2_DOY(x)		(((x) >> 0)  & 0xfff)
+
+#define rtc_readl(dev, reg)		readl((dev)->rtc_base + (reg))
+#define rtc_writel(dev, reg, val)	writel((val), (dev)->rtc_base + (reg))
+
+struct lpc24xx_rtc {
+	void __iomem *rtc_base;
+	struct rtc_device *rtc;
+	struct clk *clk_rtc;
+	struct clk *clk_reg;
+};
+
+static int lpc24xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 rtc_ctrl;
+
+	/* Disable RTC during update */
+	rtc_ctrl = rtc_readl(rtc, LPC24XX_CCR);
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl & ~LPC24XX_CLKEN);
+
+	rtc_writel(rtc, LPC24XX_SEC,	tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_MIN,	tm->tm_min);
+	rtc_writel(rtc, LPC24XX_HOUR,	tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_DOW,	tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_DOM,	tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_DOY,	tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_MONTH,	tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_YEAR,	tm->tm_year);
+
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl | LPC24XX_CLKEN);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 ct0, ct1, ct2;
+
+	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
+	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
+	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
+
+	tm->tm_sec  = CT0_SECS(ct0);
+	tm->tm_min  = CT0_MINS(ct0);
+	tm->tm_hour = CT0_HOURS(ct0);
+	tm->tm_wday = CT0_DOW(ct0);
+	tm->tm_mon  = CT1_MONTH(ct1);
+	tm->tm_mday = CT1_DOM(ct1);
+	tm->tm_year = CT1_YEAR(ct1);
+	tm->tm_yday = CT2_DOY(ct2);
+
+	if (rtc_valid_tm(tm) < 0) {
+		dev_warn(dev, "retrieved date and time is invalid\n");
+		rtc_time64_to_tm(0, tm);
+		lpc24xx_rtc_set_time(dev, tm);
+	}
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	tm->tm_sec  = rtc_readl(rtc, LPC24XX_ALSEC);
+	tm->tm_min  = rtc_readl(rtc, LPC24XX_ALMIN);
+	tm->tm_hour = rtc_readl(rtc, LPC24XX_ALHOUR);
+	tm->tm_mday = rtc_readl(rtc, LPC24XX_ALDOM);
+	tm->tm_wday = rtc_readl(rtc, LPC24XX_ALDOW);
+	tm->tm_yday = rtc_readl(rtc, LPC24XX_ALDOY);
+	tm->tm_mon  = rtc_readl(rtc, LPC24XX_ALMON);
+	tm->tm_year = rtc_readl(rtc, LPC24XX_ALYEAR);
+
+	wkalrm->enabled = rtc_readl(rtc, LPC24XX_AMR) == 0;
+	wkalrm->pending = !!(rtc_readl(rtc, LPC24XX_ILR) & LPC24XX_RTCCIF);
+
+	return rtc_valid_tm(&wkalrm->time);
+}
+
+static int lpc24xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	/* Disable alarm IRQs during update */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	rtc_writel(rtc, LPC24XX_ALSEC,  tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_ALMIN,  tm->tm_min);
+	rtc_writel(rtc, LPC24XX_ALHOUR, tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_ALDOM,  tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_ALDOW,  tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_ALDOY,  tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_ALMON,  tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_ALYEAR, tm->tm_year);
+
+	if (wkalrm->enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_alarm_irq_enable(struct device *dev,
+					unsigned int enabled)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+
+	if (enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+	else
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	return 0;
+}
+
+static irqreturn_t lpc24xx_rtc_interrupt(int irq, void *dev)
+{
+	unsigned long events = RTC_IRQF;
+	struct lpc24xx_rtc *rtc = dev;
+	u32 rtc_iir;
+
+	/* Check interrupt cause */
+	rtc_iir = rtc_readl(rtc, LPC24XX_ILR);
+
+	/* 1s tick */
+	if (rtc_iir & LPC24XX_RTCCIF)
+		events |= RTC_UF;
+
+	/* Alarm */
+	if (rtc_iir & LPC24XX_RTCALF) {
+		events |= RTC_AF;
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	}
+
+	/* Clear interrupt status and report event */
+	rtc_writel(rtc, LPC24XX_ILR, rtc_iir);
+	rtc_update_irq(rtc->rtc, 1, events);
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops lpc24xx_rtc_ops = {
+	.read_time		= lpc24xx_rtc_read_time,
+	.set_time		= lpc24xx_rtc_set_time,
+	.read_alarm		= lpc24xx_rtc_read_alarm,
+	.set_alarm		= lpc24xx_rtc_set_alarm,
+	.alarm_irq_enable	= lpc24xx_rtc_alarm_irq_enable,
+};
+
+static const struct of_device_id lpc24xx_rtc_match[] = {
+	{ .compatible = "nxp,lpc1788-rtc" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc24xx_rtc_match);
+
+static int lpc24xx_rtc_probe(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc;
+	struct resource *res;
+	int irq, ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->rtc_base))
+		return PTR_ERR(rtc->rtc_base);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_warn(&pdev->dev, "can't get interrupt resource\n");
+		return irq;
+	}
+
+	rtc->clk_rtc = devm_clk_get(&pdev->dev, "rtc");
+	if (IS_ERR(rtc->clk_rtc)) {
+		dev_err(&pdev->dev, "error getting rtc clock\n");
+		return PTR_ERR(rtc->clk_rtc);
+	}
+
+	rtc->clk_reg = devm_clk_get(&pdev->dev, "reg");
+	if (IS_ERR(rtc->clk_reg)) {
+		dev_err(&pdev->dev, "error getting reg clock\n");
+		return PTR_ERR(rtc->clk_reg);
+	}
+
+	ret = clk_prepare_enable(rtc->clk_rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable rtc clock\n");
+		return ret;
+	}
+
+	ret = clk_prepare_enable(rtc->clk_reg);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable reg clock\n");
+		goto disable_rtc_clk;
+	}
+
+	platform_set_drvdata(pdev, rtc);
+
+	/* Clear the counter increment state */
+	rtc_writel(rtc, LPC24XX_ILR, LPC24XX_RTCCIF);
+
+	/* Only 1-second interrupt will generate interrupt */
+	rtc_writel(rtc, LPC24XX_CIIR, LPC24XX_IMSEC);
+
+	/* Enable RTC count */
+	rtc_writel(rtc, LPC24XX_CCR, LPC24XX_CLKEN);
+
+	ret = devm_request_irq(&pdev->dev, irq, lpc24xx_rtc_interrupt, 0,
+			       pdev->name, rtc);
+	if (ret < 0) {
+		dev_warn(&pdev->dev, "can't request interrupt\n");
+		goto disable_clks;
+	}
+
+	rtc->rtc = devm_rtc_device_register(&pdev->dev, "lpc24xx-rtc",
+					    &lpc24xx_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc)) {
+		dev_err(&pdev->dev, "can't register rtc device\n");
+		ret = PTR_ERR(rtc->rtc);
+		goto disable_clks;
+	}
+
+	return 0;
+
+disable_clks:
+	clk_disable_unprepare(rtc->clk_reg);
+disable_rtc_clk:
+	clk_disable_unprepare(rtc->clk_rtc);
+	return ret;
+}
+
+static int lpc24xx_rtc_remove(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc = platform_get_drvdata(pdev);
+
+	/*
+	 * Disable alarm, but leave RTC enabled so it
+	 * remains valid across reset cycles.
+	 */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	rtc_writel(rtc, LPC24XX_CCR, 0);
+
+	clk_disable_unprepare(rtc->clk_rtc);
+	clk_disable_unprepare(rtc->clk_reg);
+
+	return 0;
+}
+
+static struct platform_driver lpc24xx_rtc_driver = {
+	.probe	= lpc24xx_rtc_probe,
+	.remove	= lpc24xx_rtc_remove,
+	.driver	= {
+		.name = "lpc24xx-rtc",
+		.of_match_table	= lpc24xx_rtc_match,
+	},
+};
+module_platform_driver(lpc24xx_rtc_driver);
+
+MODULE_AUTHOR("Kevin Wells <wellsk40-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org");
+MODULE_DESCRIPTION("RTC driver for the LPC24xx SoC");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:lpc24xx-rtc");
-- 
1.8.0

--
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] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
The RTC provides calendar and clock functionality together with
periodic tick and alarm interrupt support.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/rtc/Kconfig       |  13 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-lpc24xx.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 355 insertions(+)
 create mode 100644 drivers/rtc/rtc-lpc24xx.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6149ae01e11f..279342e8168b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
 	  This driver can also be buillt as a module. If so, the module
 	  will be called rtc-jz4740.
 
+config RTC_DRV_LPC24XX
+	depends on ARCH_LPC18XX || COMPILE_TEST
+	depends on HAS_IOMEM
+	depends on OF
+	tristate "NXP LPC24xx RTC"
+	help
+	  This enables support for the NXP RTC found which can be found on
+	  LPC24xx/178x/18xx/43xx devices.
+
+	  If you have one of the devices above enable this driver to use
+	  the hardware RTC. This driver can also be buillt as a module. If
+	  so, the module will be called rtc-lpc24xx.
+
 config RTC_DRV_LPC32XX
 	depends on ARCH_LPC32XX
 	tristate "NXP LPC32XX RTC"
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c31731c29762..8687a2e13247 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
 obj-$(CONFIG_RTC_DRV_ISL12057)	+= rtc-isl12057.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
+obj-$(CONFIG_RTC_DRV_LPC24XX)	+= rtc-lpc24xx.o
 obj-$(CONFIG_RTC_DRV_LPC32XX)	+= rtc-lpc32xx.o
 obj-$(CONFIG_RTC_DRV_LOONGSON1)	+= rtc-ls1x.o
 obj-$(CONFIG_RTC_DRV_M41T80)	+= rtc-m41t80.o
diff --git a/drivers/rtc/rtc-lpc24xx.c b/drivers/rtc/rtc-lpc24xx.c
new file mode 100644
index 000000000000..33caa00fd44f
--- /dev/null
+++ b/drivers/rtc/rtc-lpc24xx.c
@@ -0,0 +1,341 @@
+/*
+ * Driver for NXP LPC24xx/178x/18xx/43xx Real-Time Clock (RTC)
+ *
+ * Copyright (C) 2011 NXP Semiconductors
+ * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+/* LPC24xx RTC register offsets */
+#define LPC24XX_ILR		0x00
+#define LPC24XX_CTC		0x04
+#define LPC24XX_CCR		0x08
+#define LPC24XX_CIIR		0x0c
+#define LPC24XX_AMR		0x10
+#define LPC24XX_CTIME0		0x14
+#define LPC24XX_CTIME1		0x18
+#define LPC24XX_CTIME2		0x1c
+#define LPC24XX_SEC		0x20
+#define LPC24XX_MIN		0x24
+#define LPC24XX_HOUR		0x28
+#define LPC24XX_DOM		0x2c
+#define LPC24XX_DOW		0x30
+#define LPC24XX_DOY		0x34
+#define LPC24XX_MONTH		0x38
+#define LPC24XX_YEAR		0x3c
+#define LPC24XX_ALSEC		0x60
+#define LPC24XX_ALMIN		0x64
+#define LPC24XX_ALHOUR		0x68
+#define LPC24XX_ALDOM		0x6c
+#define LPC24XX_ALDOW		0x70
+#define LPC24XX_ALDOY		0x74
+#define LPC24XX_ALMON		0x78
+#define LPC24XX_ALYEAR		0x7c
+
+#define LPC24XX_RTCCIF		BIT(0)
+#define LPC24XX_RTCALF		BIT(1)
+
+#define LPC24XX_CLKEN		BIT(0)
+#define LPC24XX_CTCRST		BIT(1)
+
+#define LPC24XX_IMSEC		BIT(0)
+#define LPC24XX_IMMIN		BIT(1)
+#define LPC24XX_IMHOUR		BIT(2)
+#define LPC24XX_IMDOM		BIT(3)
+#define LPC24XX_IMDOW		BIT(4)
+#define LPC24XX_IMDOY		BIT(5)
+#define LPC24XX_IMMON		BIT(6)
+#define LPC24XX_IMYEAR		BIT(7)
+
+#define LPC24XX_ALARM_DISABLE	0xff
+
+#define CT0_SECS(x)		(((x) >> 0)  & 0x3f)
+#define CT0_MINS(x)		(((x) >> 8)  & 0x3f)
+#define CT0_HOURS(x)		(((x) >> 16) & 0x1f)
+#define CT0_DOW(x)		(((x) >> 24) & 0x07)
+#define CT1_DOM(x)		(((x) >> 0)  & 0x1f)
+#define CT1_MONTH(x)		(((x) >> 8)  & 0x0f)
+#define CT1_YEAR(x)		(((x) >> 16) & 0xfff)
+#define CT2_DOY(x)		(((x) >> 0)  & 0xfff)
+
+#define rtc_readl(dev, reg)		readl((dev)->rtc_base + (reg))
+#define rtc_writel(dev, reg, val)	writel((val), (dev)->rtc_base + (reg))
+
+struct lpc24xx_rtc {
+	void __iomem *rtc_base;
+	struct rtc_device *rtc;
+	struct clk *clk_rtc;
+	struct clk *clk_reg;
+};
+
+static int lpc24xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 rtc_ctrl;
+
+	/* Disable RTC during update */
+	rtc_ctrl = rtc_readl(rtc, LPC24XX_CCR);
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl & ~LPC24XX_CLKEN);
+
+	rtc_writel(rtc, LPC24XX_SEC,	tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_MIN,	tm->tm_min);
+	rtc_writel(rtc, LPC24XX_HOUR,	tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_DOW,	tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_DOM,	tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_DOY,	tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_MONTH,	tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_YEAR,	tm->tm_year);
+
+	rtc_writel(rtc, LPC24XX_CCR, rtc_ctrl | LPC24XX_CLKEN);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	u32 ct0, ct1, ct2;
+
+	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
+	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
+	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
+
+	tm->tm_sec  = CT0_SECS(ct0);
+	tm->tm_min  = CT0_MINS(ct0);
+	tm->tm_hour = CT0_HOURS(ct0);
+	tm->tm_wday = CT0_DOW(ct0);
+	tm->tm_mon  = CT1_MONTH(ct1);
+	tm->tm_mday = CT1_DOM(ct1);
+	tm->tm_year = CT1_YEAR(ct1);
+	tm->tm_yday = CT2_DOY(ct2);
+
+	if (rtc_valid_tm(tm) < 0) {
+		dev_warn(dev, "retrieved date and time is invalid\n");
+		rtc_time64_to_tm(0, tm);
+		lpc24xx_rtc_set_time(dev, tm);
+	}
+
+	return 0;
+}
+
+static int lpc24xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	tm->tm_sec  = rtc_readl(rtc, LPC24XX_ALSEC);
+	tm->tm_min  = rtc_readl(rtc, LPC24XX_ALMIN);
+	tm->tm_hour = rtc_readl(rtc, LPC24XX_ALHOUR);
+	tm->tm_mday = rtc_readl(rtc, LPC24XX_ALDOM);
+	tm->tm_wday = rtc_readl(rtc, LPC24XX_ALDOW);
+	tm->tm_yday = rtc_readl(rtc, LPC24XX_ALDOY);
+	tm->tm_mon  = rtc_readl(rtc, LPC24XX_ALMON);
+	tm->tm_year = rtc_readl(rtc, LPC24XX_ALYEAR);
+
+	wkalrm->enabled = rtc_readl(rtc, LPC24XX_AMR) == 0;
+	wkalrm->pending = !!(rtc_readl(rtc, LPC24XX_ILR) & LPC24XX_RTCCIF);
+
+	return rtc_valid_tm(&wkalrm->time);
+}
+
+static int lpc24xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_time *tm = &wkalrm->time;
+
+	/* Disable alarm IRQs during update */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	rtc_writel(rtc, LPC24XX_ALSEC,  tm->tm_sec);
+	rtc_writel(rtc, LPC24XX_ALMIN,  tm->tm_min);
+	rtc_writel(rtc, LPC24XX_ALHOUR, tm->tm_hour);
+	rtc_writel(rtc, LPC24XX_ALDOM,  tm->tm_mday);
+	rtc_writel(rtc, LPC24XX_ALDOW,  tm->tm_wday);
+	rtc_writel(rtc, LPC24XX_ALDOY,  tm->tm_yday);
+	rtc_writel(rtc, LPC24XX_ALMON,  tm->tm_mon);
+	rtc_writel(rtc, LPC24XX_ALYEAR, tm->tm_year);
+
+	if (wkalrm->enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+
+	return 0;
+}
+
+static int lpc24xx_rtc_alarm_irq_enable(struct device *dev,
+					unsigned int enabled)
+{
+	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
+
+	if (enabled)
+		rtc_writel(rtc, LPC24XX_AMR, 0);
+	else
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+
+	return 0;
+}
+
+static irqreturn_t lpc24xx_rtc_interrupt(int irq, void *dev)
+{
+	unsigned long events = RTC_IRQF;
+	struct lpc24xx_rtc *rtc = dev;
+	u32 rtc_iir;
+
+	/* Check interrupt cause */
+	rtc_iir = rtc_readl(rtc, LPC24XX_ILR);
+
+	/* 1s tick */
+	if (rtc_iir & LPC24XX_RTCCIF)
+		events |= RTC_UF;
+
+	/* Alarm */
+	if (rtc_iir & LPC24XX_RTCALF) {
+		events |= RTC_AF;
+		rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	}
+
+	/* Clear interrupt status and report event */
+	rtc_writel(rtc, LPC24XX_ILR, rtc_iir);
+	rtc_update_irq(rtc->rtc, 1, events);
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops lpc24xx_rtc_ops = {
+	.read_time		= lpc24xx_rtc_read_time,
+	.set_time		= lpc24xx_rtc_set_time,
+	.read_alarm		= lpc24xx_rtc_read_alarm,
+	.set_alarm		= lpc24xx_rtc_set_alarm,
+	.alarm_irq_enable	= lpc24xx_rtc_alarm_irq_enable,
+};
+
+static const struct of_device_id lpc24xx_rtc_match[] = {
+	{ .compatible = "nxp,lpc1788-rtc" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc24xx_rtc_match);
+
+static int lpc24xx_rtc_probe(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc;
+	struct resource *res;
+	int irq, ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->rtc_base))
+		return PTR_ERR(rtc->rtc_base);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_warn(&pdev->dev, "can't get interrupt resource\n");
+		return irq;
+	}
+
+	rtc->clk_rtc = devm_clk_get(&pdev->dev, "rtc");
+	if (IS_ERR(rtc->clk_rtc)) {
+		dev_err(&pdev->dev, "error getting rtc clock\n");
+		return PTR_ERR(rtc->clk_rtc);
+	}
+
+	rtc->clk_reg = devm_clk_get(&pdev->dev, "reg");
+	if (IS_ERR(rtc->clk_reg)) {
+		dev_err(&pdev->dev, "error getting reg clock\n");
+		return PTR_ERR(rtc->clk_reg);
+	}
+
+	ret = clk_prepare_enable(rtc->clk_rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable rtc clock\n");
+		return ret;
+	}
+
+	ret = clk_prepare_enable(rtc->clk_reg);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to enable reg clock\n");
+		goto disable_rtc_clk;
+	}
+
+	platform_set_drvdata(pdev, rtc);
+
+	/* Clear the counter increment state */
+	rtc_writel(rtc, LPC24XX_ILR, LPC24XX_RTCCIF);
+
+	/* Only 1-second interrupt will generate interrupt */
+	rtc_writel(rtc, LPC24XX_CIIR, LPC24XX_IMSEC);
+
+	/* Enable RTC count */
+	rtc_writel(rtc, LPC24XX_CCR, LPC24XX_CLKEN);
+
+	ret = devm_request_irq(&pdev->dev, irq, lpc24xx_rtc_interrupt, 0,
+			       pdev->name, rtc);
+	if (ret < 0) {
+		dev_warn(&pdev->dev, "can't request interrupt\n");
+		goto disable_clks;
+	}
+
+	rtc->rtc = devm_rtc_device_register(&pdev->dev, "lpc24xx-rtc",
+					    &lpc24xx_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc)) {
+		dev_err(&pdev->dev, "can't register rtc device\n");
+		ret = PTR_ERR(rtc->rtc);
+		goto disable_clks;
+	}
+
+	return 0;
+
+disable_clks:
+	clk_disable_unprepare(rtc->clk_reg);
+disable_rtc_clk:
+	clk_disable_unprepare(rtc->clk_rtc);
+	return ret;
+}
+
+static int lpc24xx_rtc_remove(struct platform_device *pdev)
+{
+	struct lpc24xx_rtc *rtc = platform_get_drvdata(pdev);
+
+	/*
+	 * Disable alarm, but leave RTC enabled so it
+	 * remains valid across reset cycles.
+	 */
+	rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE);
+	rtc_writel(rtc, LPC24XX_CCR, 0);
+
+	clk_disable_unprepare(rtc->clk_rtc);
+	clk_disable_unprepare(rtc->clk_reg);
+
+	return 0;
+}
+
+static struct platform_driver lpc24xx_rtc_driver = {
+	.probe	= lpc24xx_rtc_probe,
+	.remove	= lpc24xx_rtc_remove,
+	.driver	= {
+		.name = "lpc24xx-rtc",
+		.of_match_table	= lpc24xx_rtc_match,
+	},
+};
+module_platform_driver(lpc24xx_rtc_driver);
+
+MODULE_AUTHOR("Kevin Wells <wellsk40@gmail.com");
+MODULE_DESCRIPTION("RTC driver for the LPC24xx SoC");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:lpc24xx-rtc");
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [rtc-linux] [PATCH v2 2/2] doc: dt: add documentation for nxp,lpc1788-rtc
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm, a.zummo
  Cc: Joachim Eastwood, wellsk40, rtc-linux, devicetree,
	linux-arm-kernel, alexandre.belloni, joshc

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
new file mode 100644
index 000000000000..ad41a040432c
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
@@ -0,0 +1,21 @@
+NXP LPC1788 real-time clock
+
+The LPC1788 RTC provides calendar and clock functionality
+together with periodic tick and alarm interrupt support.
+
+Required properties:
+- compatible	: must contain "nxp,lpc1788-rtc"
+- reg		: Specifies base physical address and size of the registers.
+- interrupts	: A single interrupt specifier.
+- clocks	: Must contain entries for rtc and register clock
+- clock-names	: Must contain "rtc" and "reg"
+  See ../clocks/clock-bindings.txt for details.
+
+Example:
+rtc: rtc@40046000 {
+	compatible = "nxp,lpc1788-rtc";
+	reg = <0x40046000 0x1000>;
+	interrupts = <47>;
+	clocks = <&creg_clk 0>, <&ccu1 CLK_CPU_BUS>;
+	clock-names = "rtc", "reg";
+};
-- 
1.8.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/2] doc: dt: add documentation for nxp,lpc1788-rtc
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, a.zummo-BfzFCNDTiLLj+vYz1yj4TQ
  Cc: Joachim Eastwood, wellsk40-Re5JQEeQqe8AvxtiuMwx3w,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	joshc-acOepvfBmUk

Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
new file mode 100644
index 000000000000..ad41a040432c
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
@@ -0,0 +1,21 @@
+NXP LPC1788 real-time clock
+
+The LPC1788 RTC provides calendar and clock functionality
+together with periodic tick and alarm interrupt support.
+
+Required properties:
+- compatible	: must contain "nxp,lpc1788-rtc"
+- reg		: Specifies base physical address and size of the registers.
+- interrupts	: A single interrupt specifier.
+- clocks	: Must contain entries for rtc and register clock
+- clock-names	: Must contain "rtc" and "reg"
+  See ../clocks/clock-bindings.txt for details.
+
+Example:
+rtc: rtc@40046000 {
+	compatible = "nxp,lpc1788-rtc";
+	reg = <0x40046000 0x1000>;
+	interrupts = <47>;
+	clocks = <&creg_clk 0>, <&ccu1 CLK_CPU_BUS>;
+	clock-names = "rtc", "reg";
+};
-- 
1.8.0

--
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] 24+ messages in thread

* [PATCH v2 2/2] doc: dt: add documentation for nxp,lpc1788-rtc
@ 2015-05-15 13:25   ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 13:25 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 .../devicetree/bindings/rtc/nxp,lpc1788-rtc.txt     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
new file mode 100644
index 000000000000..ad41a040432c
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
@@ -0,0 +1,21 @@
+NXP LPC1788 real-time clock
+
+The LPC1788 RTC provides calendar and clock functionality
+together with periodic tick and alarm interrupt support.
+
+Required properties:
+- compatible	: must contain "nxp,lpc1788-rtc"
+- reg		: Specifies base physical address and size of the registers.
+- interrupts	: A single interrupt specifier.
+- clocks	: Must contain entries for rtc and register clock
+- clock-names	: Must contain "rtc" and "reg"
+  See ../clocks/clock-bindings.txt for details.
+
+Example:
+rtc: rtc at 40046000 {
+	compatible = "nxp,lpc1788-rtc";
+	reg = <0x40046000 0x1000>;
+	interrupts = <47>;
+	clocks = <&creg_clk 0>, <&ccu1 CLK_CPU_BUS>;
+	clock-names = "rtc", "reg";
+};
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [rtc-linux] Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 15:23     ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 15:23 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: akpm, a.zummo, wellsk40, rtc-linux, devicetree, linux-arm-kernel,
	alexandre.belloni

[-- Attachment #1: Type: text/plain, Size: 2889 bytes --]

Hello again,

On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> The RTC provides calendar and clock functionality together with
> periodic tick and alarm interrupt support.
> 
> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> ---
[..]
> +++ b/drivers/rtc/Kconfig
> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>  	  This driver can also be buillt as a module. If so, the module
>  	  will be called rtc-jz4740.
>  
> +config RTC_DRV_LPC24XX
> +	depends on ARCH_LPC18XX || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	depends on OF
> +	tristate "NXP LPC24xx RTC"
> +	help
> +	  This enables support for the NXP RTC found which can be found on
> +	  LPC24xx/178x/18xx/43xx devices.

Is this still true?

> +
> +	  If you have one of the devices above enable this driver to use
> +	  the hardware RTC. This driver can also be buillt as a module. If
> +	  so, the module will be called rtc-lpc24xx.
> +
>  config RTC_DRV_LPC32XX
>  	depends on ARCH_LPC32XX
>  	tristate "NXP LPC32XX RTC"
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index c31731c29762..8687a2e13247 100644
> --- a/drivers/rtc/Makefile
[..]
> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> +	u32 ct0, ct1, ct2;
> +
> +	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> +	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> +	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> +
> +	tm->tm_sec  = CT0_SECS(ct0);
> +	tm->tm_min  = CT0_MINS(ct0);
> +	tm->tm_hour = CT0_HOURS(ct0);
> +	tm->tm_wday = CT0_DOW(ct0);
> +	tm->tm_mon  = CT1_MONTH(ct1);
> +	tm->tm_mday = CT1_DOM(ct1);
> +	tm->tm_year = CT1_YEAR(ct1);
> +	tm->tm_yday = CT2_DOY(ct2);
> +
> +	if (rtc_valid_tm(tm) < 0) {
> +		dev_warn(dev, "retrieved date and time is invalid\n");
> +		rtc_time64_to_tm(0, tm);
> +		lpc24xx_rtc_set_time(dev, tm);
> +	}
> +
> +	return 0;

Forcing the read time to be the epoch on failure seems like a pretty
poor way to handle errors, in my opinion.

Why not trickle an error up to the rtc class driver?

Actually, the class driver is already doing a rtc_valid_tm() check, so
that shouldn't even be necessary.  Just read your time here, and let the
upper layer take care of handling an invalid time (and properly
propagating an error up the stack).

  Josh

-- 
-- 
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.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 15:23     ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 15:23 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, wellsk40-Re5JQEeQqe8AvxtiuMwx3w,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8

[-- Attachment #1: Type: text/plain, Size: 2475 bytes --]

Hello again,

On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> The RTC provides calendar and clock functionality together with
> periodic tick and alarm interrupt support.
> 
> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
[..]
> +++ b/drivers/rtc/Kconfig
> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>  	  This driver can also be buillt as a module. If so, the module
>  	  will be called rtc-jz4740.
>  
> +config RTC_DRV_LPC24XX
> +	depends on ARCH_LPC18XX || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	depends on OF
> +	tristate "NXP LPC24xx RTC"
> +	help
> +	  This enables support for the NXP RTC found which can be found on
> +	  LPC24xx/178x/18xx/43xx devices.

Is this still true?

> +
> +	  If you have one of the devices above enable this driver to use
> +	  the hardware RTC. This driver can also be buillt as a module. If
> +	  so, the module will be called rtc-lpc24xx.
> +
>  config RTC_DRV_LPC32XX
>  	depends on ARCH_LPC32XX
>  	tristate "NXP LPC32XX RTC"
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index c31731c29762..8687a2e13247 100644
> --- a/drivers/rtc/Makefile
[..]
> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> +	u32 ct0, ct1, ct2;
> +
> +	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> +	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> +	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> +
> +	tm->tm_sec  = CT0_SECS(ct0);
> +	tm->tm_min  = CT0_MINS(ct0);
> +	tm->tm_hour = CT0_HOURS(ct0);
> +	tm->tm_wday = CT0_DOW(ct0);
> +	tm->tm_mon  = CT1_MONTH(ct1);
> +	tm->tm_mday = CT1_DOM(ct1);
> +	tm->tm_year = CT1_YEAR(ct1);
> +	tm->tm_yday = CT2_DOY(ct2);
> +
> +	if (rtc_valid_tm(tm) < 0) {
> +		dev_warn(dev, "retrieved date and time is invalid\n");
> +		rtc_time64_to_tm(0, tm);
> +		lpc24xx_rtc_set_time(dev, tm);
> +	}
> +
> +	return 0;

Forcing the read time to be the epoch on failure seems like a pretty
poor way to handle errors, in my opinion.

Why not trickle an error up to the rtc class driver?

Actually, the class driver is already doing a rtc_valid_tm() check, so
that shouldn't even be necessary.  Just read your time here, and let the
upper layer take care of handling an invalid time (and properly
propagating an error up the stack).

  Josh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 15:23     ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 15:23 UTC (permalink / raw)
  To: linux-arm-kernel

Hello again,

On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> The RTC provides calendar and clock functionality together with
> periodic tick and alarm interrupt support.
> 
> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> ---
[..]
> +++ b/drivers/rtc/Kconfig
> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>  	  This driver can also be buillt as a module. If so, the module
>  	  will be called rtc-jz4740.
>  
> +config RTC_DRV_LPC24XX
> +	depends on ARCH_LPC18XX || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	depends on OF
> +	tristate "NXP LPC24xx RTC"
> +	help
> +	  This enables support for the NXP RTC found which can be found on
> +	  LPC24xx/178x/18xx/43xx devices.

Is this still true?

> +
> +	  If you have one of the devices above enable this driver to use
> +	  the hardware RTC. This driver can also be buillt as a module. If
> +	  so, the module will be called rtc-lpc24xx.
> +
>  config RTC_DRV_LPC32XX
>  	depends on ARCH_LPC32XX
>  	tristate "NXP LPC32XX RTC"
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index c31731c29762..8687a2e13247 100644
> --- a/drivers/rtc/Makefile
[..]
> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> +	u32 ct0, ct1, ct2;
> +
> +	ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> +	ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> +	ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> +
> +	tm->tm_sec  = CT0_SECS(ct0);
> +	tm->tm_min  = CT0_MINS(ct0);
> +	tm->tm_hour = CT0_HOURS(ct0);
> +	tm->tm_wday = CT0_DOW(ct0);
> +	tm->tm_mon  = CT1_MONTH(ct1);
> +	tm->tm_mday = CT1_DOM(ct1);
> +	tm->tm_year = CT1_YEAR(ct1);
> +	tm->tm_yday = CT2_DOY(ct2);
> +
> +	if (rtc_valid_tm(tm) < 0) {
> +		dev_warn(dev, "retrieved date and time is invalid\n");
> +		rtc_time64_to_tm(0, tm);
> +		lpc24xx_rtc_set_time(dev, tm);
> +	}
> +
> +	return 0;

Forcing the read time to be the epoch on failure seems like a pretty
poor way to handle errors, in my opinion.

Why not trickle an error up to the rtc class driver?

Actually, the class driver is already doing a rtc_valid_tm() check, so
that shouldn't even be necessary.  Just read your time here, and let the
upper layer take care of handling an invalid time (and properly
propagating an error up the stack).

  Josh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150515/7f3b602d/attachment.sig>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [rtc-linux] Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 16:31       ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 16:31 UTC (permalink / raw)
  To: Josh Cartwright
  Cc: akpm, Alessandro Zummo, Kevin Wells, rtc-linux, devicetree,
	linux-arm-kernel, alexandre.belloni

On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> Hello again,
>
> On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> The RTC provides calendar and clock functionality together with
>> periodic tick and alarm interrupt support.
>>
>> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
>> ---
> [..]
>> +++ b/drivers/rtc/Kconfig
>> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>>         This driver can also be buillt as a module. If so, the module
>>         will be called rtc-jz4740.
>>
>> +config RTC_DRV_LPC24XX
>> +     depends on ARCH_LPC18XX || COMPILE_TEST
>> +     depends on HAS_IOMEM
>> +     depends on OF
>> +     tristate "NXP LPC24xx RTC"
>> +     help
>> +       This enables support for the NXP RTC found which can be found on
>> +       LPC24xx/178x/18xx/43xx devices.
>
> Is this still true?

I guess I should have updated the Kconfig text when I removed the LPC24xx bits.

I'll put something this in the next version:
tristate "NXP LPC178x/18xx/43xx RTC"
...
help
  This enables support for the NXP RTC found which can be found on
  LPC178x/18xx/43xx devices.


>> +
>> +       If you have one of the devices above enable this driver to use
>> +       the hardware RTC. This driver can also be buillt as a module. If
>> +       so, the module will be called rtc-lpc24xx.
>> +
>>  config RTC_DRV_LPC32XX
>>       depends on ARCH_LPC32XX
>>       tristate "NXP LPC32XX RTC"
>> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> index c31731c29762..8687a2e13247 100644
>> --- a/drivers/rtc/Makefile
> [..]
>> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> +     u32 ct0, ct1, ct2;
>> +
>> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> +
>> +     tm->tm_sec  = CT0_SECS(ct0);
>> +     tm->tm_min  = CT0_MINS(ct0);
>> +     tm->tm_hour = CT0_HOURS(ct0);
>> +     tm->tm_wday = CT0_DOW(ct0);
>> +     tm->tm_mon  = CT1_MONTH(ct1);
>> +     tm->tm_mday = CT1_DOM(ct1);
>> +     tm->tm_year = CT1_YEAR(ct1);
>> +     tm->tm_yday = CT2_DOY(ct2);
>> +
>> +     if (rtc_valid_tm(tm) < 0) {
>> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> +             rtc_time64_to_tm(0, tm);
>> +             lpc24xx_rtc_set_time(dev, tm);
>> +     }
>> +
>> +     return 0;
>
> Forcing the read time to be the epoch on failure seems like a pretty
> poor way to handle errors, in my opinion.

When the device doesn't have battery the CTIME registers contains an
invalid value. So if you don't set them to something valid you will
get a warning each time you try to read the RTC. To "fix" that problem
I set the time at epoch which make the CTIME registers to contain a
valid value. Since the value is already useless I think setting it to
epoch is an improvement in this case.

I guess it deserves a comment in the driver.

> Why not trickle an error up to the rtc class driver?

Because the rtc class will never correct the CTIME register values and
will complain each time lpc24xx_rtc_read_time() is called. Of course
if a user set the time from user space the register value is also
corrected.

> Actually, the class driver is already doing a rtc_valid_tm() check, so
> that shouldn't even be necessary.  Just read your time here, and let the
> upper layer take care of handling an invalid time (and properly
> propagating an error up the stack).


Thanks for taking the time to look at the patch again.

regards,
Joachim Eastwood

-- 
-- 
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] 24+ messages in thread

* Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 16:31       ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 16:31 UTC (permalink / raw)
  To: Josh Cartwright
  Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, Alessandro Zummo,
	Kevin Wells, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8

On 15 May 2015 at 17:23, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
> Hello again,
>
> On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> The RTC provides calendar and clock functionality together with
>> periodic tick and alarm interrupt support.
>>
>> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
> [..]
>> +++ b/drivers/rtc/Kconfig
>> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>>         This driver can also be buillt as a module. If so, the module
>>         will be called rtc-jz4740.
>>
>> +config RTC_DRV_LPC24XX
>> +     depends on ARCH_LPC18XX || COMPILE_TEST
>> +     depends on HAS_IOMEM
>> +     depends on OF
>> +     tristate "NXP LPC24xx RTC"
>> +     help
>> +       This enables support for the NXP RTC found which can be found on
>> +       LPC24xx/178x/18xx/43xx devices.
>
> Is this still true?

I guess I should have updated the Kconfig text when I removed the LPC24xx bits.

I'll put something this in the next version:
tristate "NXP LPC178x/18xx/43xx RTC"
...
help
  This enables support for the NXP RTC found which can be found on
  LPC178x/18xx/43xx devices.


>> +
>> +       If you have one of the devices above enable this driver to use
>> +       the hardware RTC. This driver can also be buillt as a module. If
>> +       so, the module will be called rtc-lpc24xx.
>> +
>>  config RTC_DRV_LPC32XX
>>       depends on ARCH_LPC32XX
>>       tristate "NXP LPC32XX RTC"
>> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> index c31731c29762..8687a2e13247 100644
>> --- a/drivers/rtc/Makefile
> [..]
>> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> +     u32 ct0, ct1, ct2;
>> +
>> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> +
>> +     tm->tm_sec  = CT0_SECS(ct0);
>> +     tm->tm_min  = CT0_MINS(ct0);
>> +     tm->tm_hour = CT0_HOURS(ct0);
>> +     tm->tm_wday = CT0_DOW(ct0);
>> +     tm->tm_mon  = CT1_MONTH(ct1);
>> +     tm->tm_mday = CT1_DOM(ct1);
>> +     tm->tm_year = CT1_YEAR(ct1);
>> +     tm->tm_yday = CT2_DOY(ct2);
>> +
>> +     if (rtc_valid_tm(tm) < 0) {
>> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> +             rtc_time64_to_tm(0, tm);
>> +             lpc24xx_rtc_set_time(dev, tm);
>> +     }
>> +
>> +     return 0;
>
> Forcing the read time to be the epoch on failure seems like a pretty
> poor way to handle errors, in my opinion.

When the device doesn't have battery the CTIME registers contains an
invalid value. So if you don't set them to something valid you will
get a warning each time you try to read the RTC. To "fix" that problem
I set the time at epoch which make the CTIME registers to contain a
valid value. Since the value is already useless I think setting it to
epoch is an improvement in this case.

I guess it deserves a comment in the driver.

> Why not trickle an error up to the rtc class driver?

Because the rtc class will never correct the CTIME register values and
will complain each time lpc24xx_rtc_read_time() is called. Of course
if a user set the time from user space the register value is also
corrected.

> Actually, the class driver is already doing a rtc_valid_tm() check, so
> that shouldn't even be necessary.  Just read your time here, and let the
> upper layer take care of handling an invalid time (and properly
> propagating an error up the stack).


Thanks for taking the time to look at the patch again.

regards,
Joachim Eastwood
--
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] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 16:31       ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 16:31 UTC (permalink / raw)
  To: linux-arm-kernel

On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> Hello again,
>
> On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> The RTC provides calendar and clock functionality together with
>> periodic tick and alarm interrupt support.
>>
>> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
>> ---
> [..]
>> +++ b/drivers/rtc/Kconfig
>> @@ -1427,6 +1427,19 @@ config RTC_DRV_JZ4740
>>         This driver can also be buillt as a module. If so, the module
>>         will be called rtc-jz4740.
>>
>> +config RTC_DRV_LPC24XX
>> +     depends on ARCH_LPC18XX || COMPILE_TEST
>> +     depends on HAS_IOMEM
>> +     depends on OF
>> +     tristate "NXP LPC24xx RTC"
>> +     help
>> +       This enables support for the NXP RTC found which can be found on
>> +       LPC24xx/178x/18xx/43xx devices.
>
> Is this still true?

I guess I should have updated the Kconfig text when I removed the LPC24xx bits.

I'll put something this in the next version:
tristate "NXP LPC178x/18xx/43xx RTC"
...
help
  This enables support for the NXP RTC found which can be found on
  LPC178x/18xx/43xx devices.


>> +
>> +       If you have one of the devices above enable this driver to use
>> +       the hardware RTC. This driver can also be buillt as a module. If
>> +       so, the module will be called rtc-lpc24xx.
>> +
>>  config RTC_DRV_LPC32XX
>>       depends on ARCH_LPC32XX
>>       tristate "NXP LPC32XX RTC"
>> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> index c31731c29762..8687a2e13247 100644
>> --- a/drivers/rtc/Makefile
> [..]
>> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> +     u32 ct0, ct1, ct2;
>> +
>> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> +
>> +     tm->tm_sec  = CT0_SECS(ct0);
>> +     tm->tm_min  = CT0_MINS(ct0);
>> +     tm->tm_hour = CT0_HOURS(ct0);
>> +     tm->tm_wday = CT0_DOW(ct0);
>> +     tm->tm_mon  = CT1_MONTH(ct1);
>> +     tm->tm_mday = CT1_DOM(ct1);
>> +     tm->tm_year = CT1_YEAR(ct1);
>> +     tm->tm_yday = CT2_DOY(ct2);
>> +
>> +     if (rtc_valid_tm(tm) < 0) {
>> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> +             rtc_time64_to_tm(0, tm);
>> +             lpc24xx_rtc_set_time(dev, tm);
>> +     }
>> +
>> +     return 0;
>
> Forcing the read time to be the epoch on failure seems like a pretty
> poor way to handle errors, in my opinion.

When the device doesn't have battery the CTIME registers contains an
invalid value. So if you don't set them to something valid you will
get a warning each time you try to read the RTC. To "fix" that problem
I set the time at epoch which make the CTIME registers to contain a
valid value. Since the value is already useless I think setting it to
epoch is an improvement in this case.

I guess it deserves a comment in the driver.

> Why not trickle an error up to the rtc class driver?

Because the rtc class will never correct the CTIME register values and
will complain each time lpc24xx_rtc_read_time() is called. Of course
if a user set the time from user space the register value is also
corrected.

> Actually, the class driver is already doing a rtc_valid_tm() check, so
> that shouldn't even be necessary.  Just read your time here, and let the
> upper layer take care of handling an invalid time (and properly
> propagating an error up the stack).


Thanks for taking the time to look at the patch again.

regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [rtc-linux] Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 17:53         ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 17:53 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: akpm, Alessandro Zummo, Kevin Wells, rtc-linux, devicetree,
	linux-arm-kernel, alexandre.belloni

[-- Attachment #1: Type: text/plain, Size: 2684 bytes --]

On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> > Hello again,
> >
> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> The RTC provides calendar and clock functionality together with
> >> periodic tick and alarm interrupt support.
> >>
> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> >> ---
[..]
> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> +{
> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> +     u32 ct0, ct1, ct2;
> >> +
> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> +
> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> +
> >> +     if (rtc_valid_tm(tm) < 0) {
> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> +             rtc_time64_to_tm(0, tm);
> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> +     }
> >> +
> >> +     return 0;
> >
> > Forcing the read time to be the epoch on failure seems like a pretty
> > poor way to handle errors, in my opinion.
> 
> When the device doesn't have battery the CTIME registers contains an
> invalid value. So if you don't set them to something valid you will
> get a warning each time you try to read the RTC. To "fix" that problem
> I set the time at epoch which make the CTIME registers to contain a
> valid value. Since the value is already useless I think setting it to
> epoch is an improvement in this case.

I see.  I think doing this setting in your read_time callback is the
wrong place to do this check.  I'm thinking a better place for it would
be in your driver's probe().

> I guess it deserves a comment in the driver.

Yes, I agree.

  Josh

-- 
-- 
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.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 17:53         ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 17:53 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, Alessandro Zummo,
	Kevin Wells, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8

[-- Attachment #1: Type: text/plain, Size: 2274 bytes --]

On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> On 15 May 2015 at 17:23, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
> > Hello again,
> >
> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> The RTC provides calendar and clock functionality together with
> >> periodic tick and alarm interrupt support.
> >>
> >> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >> ---
[..]
> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> +{
> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> +     u32 ct0, ct1, ct2;
> >> +
> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> +
> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> +
> >> +     if (rtc_valid_tm(tm) < 0) {
> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> +             rtc_time64_to_tm(0, tm);
> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> +     }
> >> +
> >> +     return 0;
> >
> > Forcing the read time to be the epoch on failure seems like a pretty
> > poor way to handle errors, in my opinion.
> 
> When the device doesn't have battery the CTIME registers contains an
> invalid value. So if you don't set them to something valid you will
> get a warning each time you try to read the RTC. To "fix" that problem
> I set the time at epoch which make the CTIME registers to contain a
> valid value. Since the value is already useless I think setting it to
> epoch is an improvement in this case.

I see.  I think doing this setting in your read_time callback is the
wrong place to do this check.  I'm thinking a better place for it would
be in your driver's probe().

> I guess it deserves a comment in the driver.

Yes, I agree.

  Josh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 17:53         ` Josh Cartwright
  0 siblings, 0 replies; 24+ messages in thread
From: Josh Cartwright @ 2015-05-15 17:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> > Hello again,
> >
> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> The RTC provides calendar and clock functionality together with
> >> periodic tick and alarm interrupt support.
> >>
> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> >> ---
[..]
> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> +{
> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> +     u32 ct0, ct1, ct2;
> >> +
> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> +
> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> +
> >> +     if (rtc_valid_tm(tm) < 0) {
> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> +             rtc_time64_to_tm(0, tm);
> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> +     }
> >> +
> >> +     return 0;
> >
> > Forcing the read time to be the epoch on failure seems like a pretty
> > poor way to handle errors, in my opinion.
> 
> When the device doesn't have battery the CTIME registers contains an
> invalid value. So if you don't set them to something valid you will
> get a warning each time you try to read the RTC. To "fix" that problem
> I set the time at epoch which make the CTIME registers to contain a
> valid value. Since the value is already useless I think setting it to
> epoch is an improvement in this case.

I see.  I think doing this setting in your read_time callback is the
wrong place to do this check.  I'm thinking a better place for it would
be in your driver's probe().

> I guess it deserves a comment in the driver.

Yes, I agree.

  Josh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150515/ab41cd33/attachment.sig>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [rtc-linux] Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 18:04           ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 18:04 UTC (permalink / raw)
  To: Josh Cartwright
  Cc: akpm, Alessandro Zummo, Kevin Wells, rtc-linux, devicetree,
	linux-arm-kernel, Alexandre Belloni

On 15 May 2015 at 19:53, Josh Cartwright <joshc@ni.com> wrote:
> On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
>> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
>> > Hello again,
>> >
>> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> >> The RTC provides calendar and clock functionality together with
>> >> periodic tick and alarm interrupt support.
>> >>
>> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
>> >> ---
> [..]
>> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> >> +{
>> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> >> +     u32 ct0, ct1, ct2;
>> >> +
>> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> >> +
>> >> +     tm->tm_sec  = CT0_SECS(ct0);
>> >> +     tm->tm_min  = CT0_MINS(ct0);
>> >> +     tm->tm_hour = CT0_HOURS(ct0);
>> >> +     tm->tm_wday = CT0_DOW(ct0);
>> >> +     tm->tm_mon  = CT1_MONTH(ct1);
>> >> +     tm->tm_mday = CT1_DOM(ct1);
>> >> +     tm->tm_year = CT1_YEAR(ct1);
>> >> +     tm->tm_yday = CT2_DOY(ct2);
>> >> +
>> >> +     if (rtc_valid_tm(tm) < 0) {
>> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> >> +             rtc_time64_to_tm(0, tm);
>> >> +             lpc24xx_rtc_set_time(dev, tm);
>> >> +     }
>> >> +
>> >> +     return 0;
>> >
>> > Forcing the read time to be the epoch on failure seems like a pretty
>> > poor way to handle errors, in my opinion.
>>
>> When the device doesn't have battery the CTIME registers contains an
>> invalid value. So if you don't set them to something valid you will
>> get a warning each time you try to read the RTC. To "fix" that problem
>> I set the time at epoch which make the CTIME registers to contain a
>> valid value. Since the value is already useless I think setting it to
>> epoch is an improvement in this case.
>
> I see.  I think doing this setting in your read_time callback is the
> wrong place to do this check.  I'm thinking a better place for it would
> be in your driver's probe().

That is a good idea. I'll move the check to probe instead.

>> I guess it deserves a comment in the driver.
>
> Yes, I agree.

I'll add it in the next version.


regards,
Joachim Eastwood

-- 
-- 
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] 24+ messages in thread

* Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 18:04           ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 18:04 UTC (permalink / raw)
  To: Josh Cartwright
  Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, Alessandro Zummo,
	Kevin Wells, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Alexandre Belloni

On 15 May 2015 at 19:53, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
> On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
>> On 15 May 2015 at 17:23, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
>> > Hello again,
>> >
>> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> >> The RTC provides calendar and clock functionality together with
>> >> periodic tick and alarm interrupt support.
>> >>
>> >> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> >> ---
> [..]
>> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> >> +{
>> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> >> +     u32 ct0, ct1, ct2;
>> >> +
>> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> >> +
>> >> +     tm->tm_sec  = CT0_SECS(ct0);
>> >> +     tm->tm_min  = CT0_MINS(ct0);
>> >> +     tm->tm_hour = CT0_HOURS(ct0);
>> >> +     tm->tm_wday = CT0_DOW(ct0);
>> >> +     tm->tm_mon  = CT1_MONTH(ct1);
>> >> +     tm->tm_mday = CT1_DOM(ct1);
>> >> +     tm->tm_year = CT1_YEAR(ct1);
>> >> +     tm->tm_yday = CT2_DOY(ct2);
>> >> +
>> >> +     if (rtc_valid_tm(tm) < 0) {
>> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> >> +             rtc_time64_to_tm(0, tm);
>> >> +             lpc24xx_rtc_set_time(dev, tm);
>> >> +     }
>> >> +
>> >> +     return 0;
>> >
>> > Forcing the read time to be the epoch on failure seems like a pretty
>> > poor way to handle errors, in my opinion.
>>
>> When the device doesn't have battery the CTIME registers contains an
>> invalid value. So if you don't set them to something valid you will
>> get a warning each time you try to read the RTC. To "fix" that problem
>> I set the time at epoch which make the CTIME registers to contain a
>> valid value. Since the value is already useless I think setting it to
>> epoch is an improvement in this case.
>
> I see.  I think doing this setting in your read_time callback is the
> wrong place to do this check.  I'm thinking a better place for it would
> be in your driver's probe().

That is a good idea. I'll move the check to probe instead.

>> I guess it deserves a comment in the driver.
>
> Yes, I agree.

I'll add it in the next version.


regards,
Joachim Eastwood
--
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] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-15 18:04           ` Joachim Eastwood
  0 siblings, 0 replies; 24+ messages in thread
From: Joachim Eastwood @ 2015-05-15 18:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 15 May 2015 at 19:53, Josh Cartwright <joshc@ni.com> wrote:
> On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
>> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
>> > Hello again,
>> >
>> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
>> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
>> >> The RTC provides calendar and clock functionality together with
>> >> periodic tick and alarm interrupt support.
>> >>
>> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
>> >> ---
> [..]
>> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> >> +{
>> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
>> >> +     u32 ct0, ct1, ct2;
>> >> +
>> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
>> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
>> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
>> >> +
>> >> +     tm->tm_sec  = CT0_SECS(ct0);
>> >> +     tm->tm_min  = CT0_MINS(ct0);
>> >> +     tm->tm_hour = CT0_HOURS(ct0);
>> >> +     tm->tm_wday = CT0_DOW(ct0);
>> >> +     tm->tm_mon  = CT1_MONTH(ct1);
>> >> +     tm->tm_mday = CT1_DOM(ct1);
>> >> +     tm->tm_year = CT1_YEAR(ct1);
>> >> +     tm->tm_yday = CT2_DOY(ct2);
>> >> +
>> >> +     if (rtc_valid_tm(tm) < 0) {
>> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
>> >> +             rtc_time64_to_tm(0, tm);
>> >> +             lpc24xx_rtc_set_time(dev, tm);
>> >> +     }
>> >> +
>> >> +     return 0;
>> >
>> > Forcing the read time to be the epoch on failure seems like a pretty
>> > poor way to handle errors, in my opinion.
>>
>> When the device doesn't have battery the CTIME registers contains an
>> invalid value. So if you don't set them to something valid you will
>> get a warning each time you try to read the RTC. To "fix" that problem
>> I set the time at epoch which make the CTIME registers to contain a
>> valid value. Since the value is already useless I think setting it to
>> epoch is an improvement in this case.
>
> I see.  I think doing this setting in your read_time callback is the
> wrong place to do this check.  I'm thinking a better place for it would
> be in your driver's probe().

That is a good idea. I'll move the check to probe instead.

>> I guess it deserves a comment in the driver.
>
> Yes, I agree.

I'll add it in the next version.


regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [rtc-linux] Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-16 16:53             ` Alexandre Belloni
  0 siblings, 0 replies; 24+ messages in thread
From: Alexandre Belloni @ 2015-05-16 16:53 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: Josh Cartwright, akpm, Alessandro Zummo, Kevin Wells, rtc-linux,
	devicetree, linux-arm-kernel

On 15/05/2015 at 20:04:16 +0200, Joachim Eastwood wrote :
> On 15 May 2015 at 19:53, Josh Cartwright <joshc@ni.com> wrote:
> > On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> >> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> >> > Hello again,
> >> >
> >> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> >> The RTC provides calendar and clock functionality together with
> >> >> periodic tick and alarm interrupt support.
> >> >>
> >> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> >> >> ---
> > [..]
> >> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> >> +{
> >> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> >> +     u32 ct0, ct1, ct2;
> >> >> +
> >> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> >> +
> >> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> >> +
> >> >> +     if (rtc_valid_tm(tm) < 0) {
> >> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> >> +             rtc_time64_to_tm(0, tm);
> >> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> >> +     }
> >> >> +
> >> >> +     return 0;
> >> >
> >> > Forcing the read time to be the epoch on failure seems like a pretty
> >> > poor way to handle errors, in my opinion.
> >>
> >> When the device doesn't have battery the CTIME registers contains an
> >> invalid value. So if you don't set them to something valid you will
> >> get a warning each time you try to read the RTC. To "fix" that problem
> >> I set the time at epoch which make the CTIME registers to contain a
> >> valid value. Since the value is already useless I think setting it to
> >> epoch is an improvement in this case.
> >
> > I see.  I think doing this setting in your read_time callback is the
> > wrong place to do this check.  I'm thinking a better place for it would
> > be in your driver's probe().
> 
> That is a good idea. I'll move the check to probe instead.
> 

Actually, it is never a good idea to set the time to epoch at all because
then userspace, will assume that the time is valid. You should return
an error until userspace sets the time. You can drop the dev_warn and
simply return rtc_valid_tm(tm);

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-16 16:53             ` Alexandre Belloni
  0 siblings, 0 replies; 24+ messages in thread
From: Alexandre Belloni @ 2015-05-16 16:53 UTC (permalink / raw)
  To: Joachim Eastwood
  Cc: Josh Cartwright, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	Alessandro Zummo, Kevin Wells, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 15/05/2015 at 20:04:16 +0200, Joachim Eastwood wrote :
> On 15 May 2015 at 19:53, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
> > On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> >> On 15 May 2015 at 17:23, Josh Cartwright <joshc-acOepvfBmUk@public.gmane.org> wrote:
> >> > Hello again,
> >> >
> >> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> >> The RTC provides calendar and clock functionality together with
> >> >> periodic tick and alarm interrupt support.
> >> >>
> >> >> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >> >> ---
> > [..]
> >> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> >> +{
> >> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> >> +     u32 ct0, ct1, ct2;
> >> >> +
> >> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> >> +
> >> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> >> +
> >> >> +     if (rtc_valid_tm(tm) < 0) {
> >> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> >> +             rtc_time64_to_tm(0, tm);
> >> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> >> +     }
> >> >> +
> >> >> +     return 0;
> >> >
> >> > Forcing the read time to be the epoch on failure seems like a pretty
> >> > poor way to handle errors, in my opinion.
> >>
> >> When the device doesn't have battery the CTIME registers contains an
> >> invalid value. So if you don't set them to something valid you will
> >> get a warning each time you try to read the RTC. To "fix" that problem
> >> I set the time at epoch which make the CTIME registers to contain a
> >> valid value. Since the value is already useless I think setting it to
> >> epoch is an improvement in this case.
> >
> > I see.  I think doing this setting in your read_time callback is the
> > wrong place to do this check.  I'm thinking a better place for it would
> > be in your driver's probe().
> 
> That is a good idea. I'll move the check to probe instead.
> 

Actually, it is never a good idea to set the time to epoch at all because
then userspace, will assume that the time is valid. You should return
an error until userspace sets the time. You can drop the dev_warn and
simply return rtc_valid_tm(tm);

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android 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] 24+ messages in thread

* [PATCH v2 1/2] rtc: add rtc-lpc24xx driver
@ 2015-05-16 16:53             ` Alexandre Belloni
  0 siblings, 0 replies; 24+ messages in thread
From: Alexandre Belloni @ 2015-05-16 16:53 UTC (permalink / raw)
  To: linux-arm-kernel

On 15/05/2015 at 20:04:16 +0200, Joachim Eastwood wrote :
> On 15 May 2015 at 19:53, Josh Cartwright <joshc@ni.com> wrote:
> > On Fri, May 15, 2015 at 06:31:53PM +0200, Joachim Eastwood wrote:
> >> On 15 May 2015 at 17:23, Josh Cartwright <joshc@ni.com> wrote:
> >> > Hello again,
> >> >
> >> > On Fri, May 15, 2015 at 03:25:05PM +0200, Joachim Eastwood wrote:
> >> >> Add driver for the RTC found on NXP LPC24xx/178x/18xx/43xx devices.
> >> >> The RTC provides calendar and clock functionality together with
> >> >> periodic tick and alarm interrupt support.
> >> >>
> >> >> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> >> >> ---
> > [..]
> >> >> +static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >> >> +{
> >> >> +     struct lpc24xx_rtc *rtc = dev_get_drvdata(dev);
> >> >> +     u32 ct0, ct1, ct2;
> >> >> +
> >> >> +     ct0 = rtc_readl(rtc, LPC24XX_CTIME0);
> >> >> +     ct1 = rtc_readl(rtc, LPC24XX_CTIME1);
> >> >> +     ct2 = rtc_readl(rtc, LPC24XX_CTIME2);
> >> >> +
> >> >> +     tm->tm_sec  = CT0_SECS(ct0);
> >> >> +     tm->tm_min  = CT0_MINS(ct0);
> >> >> +     tm->tm_hour = CT0_HOURS(ct0);
> >> >> +     tm->tm_wday = CT0_DOW(ct0);
> >> >> +     tm->tm_mon  = CT1_MONTH(ct1);
> >> >> +     tm->tm_mday = CT1_DOM(ct1);
> >> >> +     tm->tm_year = CT1_YEAR(ct1);
> >> >> +     tm->tm_yday = CT2_DOY(ct2);
> >> >> +
> >> >> +     if (rtc_valid_tm(tm) < 0) {
> >> >> +             dev_warn(dev, "retrieved date and time is invalid\n");
> >> >> +             rtc_time64_to_tm(0, tm);
> >> >> +             lpc24xx_rtc_set_time(dev, tm);
> >> >> +     }
> >> >> +
> >> >> +     return 0;
> >> >
> >> > Forcing the read time to be the epoch on failure seems like a pretty
> >> > poor way to handle errors, in my opinion.
> >>
> >> When the device doesn't have battery the CTIME registers contains an
> >> invalid value. So if you don't set them to something valid you will
> >> get a warning each time you try to read the RTC. To "fix" that problem
> >> I set the time at epoch which make the CTIME registers to contain a
> >> valid value. Since the value is already useless I think setting it to
> >> epoch is an improvement in this case.
> >
> > I see.  I think doing this setting in your read_time callback is the
> > wrong place to do this check.  I'm thinking a better place for it would
> > be in your driver's probe().
> 
> That is a good idea. I'll move the check to probe instead.
> 

Actually, it is never a good idea to set the time to epoch at all because
then userspace, will assume that the time is valid. You should return
an error until userspace sets the time. You can drop the dev_warn and
simply return rtc_valid_tm(tm);

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-05-16 16:53 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 13:25 [rtc-linux] [PATCH v2 0/2] RTC support for NXP LPC18xx family Joachim Eastwood
2015-05-15 13:25 ` Joachim Eastwood
2015-05-15 13:25 ` Joachim Eastwood
2015-05-15 13:25 ` [rtc-linux] [PATCH v2 1/2] rtc: add rtc-lpc24xx driver Joachim Eastwood
2015-05-15 13:25   ` Joachim Eastwood
2015-05-15 13:25   ` Joachim Eastwood
2015-05-15 15:23   ` [rtc-linux] " Josh Cartwright
2015-05-15 15:23     ` Josh Cartwright
2015-05-15 15:23     ` Josh Cartwright
2015-05-15 16:31     ` [rtc-linux] " Joachim Eastwood
2015-05-15 16:31       ` Joachim Eastwood
2015-05-15 16:31       ` Joachim Eastwood
2015-05-15 17:53       ` [rtc-linux] " Josh Cartwright
2015-05-15 17:53         ` Josh Cartwright
2015-05-15 17:53         ` Josh Cartwright
2015-05-15 18:04         ` [rtc-linux] " Joachim Eastwood
2015-05-15 18:04           ` Joachim Eastwood
2015-05-15 18:04           ` Joachim Eastwood
2015-05-16 16:53           ` [rtc-linux] " Alexandre Belloni
2015-05-16 16:53             ` Alexandre Belloni
2015-05-16 16:53             ` Alexandre Belloni
2015-05-15 13:25 ` [rtc-linux] [PATCH v2 2/2] doc: dt: add documentation for nxp,lpc1788-rtc Joachim Eastwood
2015-05-15 13:25   ` Joachim Eastwood
2015-05-15 13:25   ` Joachim Eastwood

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.