All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/3] arm64: Realtek RTD1295 RTC
@ 2017-08-20  1:36 ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel
  Cc: linux-kernel, Roc He, 蒋丽琴,
	Andreas Färber, devicetree

Hello,

This series adds the RTC for the Realtek RTD1295 SoC.
Based on my RTD1295 clk series.

There being no public source code for RTD1295, the implementation is based on
register offsets seen in the vendor DT, as well as older mach-rtk119x code
published by QNAP.

The base year is hardcoded - probably should be a DT property like downstream?

The DT node depends on the clk series for clock index and header.

More experimental patches at:
https://github.com/afaerber/linux/commits/rtd1295-next

Have a lot of fun!

Cheers,
Andreas

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: linux-rtc@vger.kernel.org
Cc: Roc He <hepeng@zidoo.tv>
Cc: 蒋丽琴 <jiang.liqin@geniatech.com>
Cc: devicetree@vger.kernel.org

Andreas Färber (3):
  dt-bindings: rtc: Add Realtek RTD1295
  rtc: Add Realtek RTD1295
  arm64: dts: realtek: Add RTD1295 RTC node

 .../devicetree/bindings/rtc/realtek,rtd119x.txt    |  16 ++
 arch/arm64/boot/dts/realtek/rtd1295.dtsi           |   6 +
 drivers/rtc/Kconfig                                |   8 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-rtd119x.c                          | 175 +++++++++++++++++++++
 5 files changed, 206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
 create mode 100644 drivers/rtc/rtc-rtd119x.c

-- 
2.12.3

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

* [RFC 0/3] arm64: Realtek RTD1295 RTC
@ 2017-08-20  1:36 ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni,
	linux-rtc-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Roc He,
	蒋丽琴,
	Andreas Färber, devicetree-u79uwXL29TY76Z2rM5mHXA

Hello,

This series adds the RTC for the Realtek RTD1295 SoC.
Based on my RTD1295 clk series.

There being no public source code for RTD1295, the implementation is based on
register offsets seen in the vendor DT, as well as older mach-rtk119x code
published by QNAP.

The base year is hardcoded - probably should be a DT property like downstream?

The DT node depends on the clk series for clock index and header.

More experimental patches at:
https://github.com/afaerber/linux/commits/rtd1295-next

Have a lot of fun!

Cheers,
Andreas

Cc: Alessandro Zummo <a.zummo-BfzFCNDTiLLj+vYz1yj4TQ@public.gmane.org>
Cc: Alexandre Belloni <alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
Cc: linux-rtc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Roc He <hepeng-qoVzM6YEWSw@public.gmane.org>
Cc: 蒋丽琴 <jiang.liqin-31gW8twSeR21Z/+hSey0Gg@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

Andreas Färber (3):
  dt-bindings: rtc: Add Realtek RTD1295
  rtc: Add Realtek RTD1295
  arm64: dts: realtek: Add RTD1295 RTC node

 .../devicetree/bindings/rtc/realtek,rtd119x.txt    |  16 ++
 arch/arm64/boot/dts/realtek/rtd1295.dtsi           |   6 +
 drivers/rtc/Kconfig                                |   8 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-rtd119x.c                          | 175 +++++++++++++++++++++
 5 files changed, 206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
 create mode 100644 drivers/rtc/rtc-rtd119x.c

-- 
2.12.3

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

* [RFC 0/3] arm64: Realtek RTD1295 RTC
@ 2017-08-20  1:36 ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

This series adds the RTC for the Realtek RTD1295 SoC.
Based on my RTD1295 clk series.

There being no public source code for RTD1295, the implementation is based on
register offsets seen in the vendor DT, as well as older mach-rtk119x code
published by QNAP.

The base year is hardcoded - probably should be a DT property like downstream?

The DT node depends on the clk series for clock index and header.

More experimental patches at:
https://github.com/afaerber/linux/commits/rtd1295-next

Have a lot of fun!

Cheers,
Andreas

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: linux-rtc at vger.kernel.org
Cc: Roc He <hepeng@zidoo.tv>
Cc: ??? <jiang.liqin@geniatech.com>
Cc: devicetree at vger.kernel.org

Andreas F?rber (3):
  dt-bindings: rtc: Add Realtek RTD1295
  rtc: Add Realtek RTD1295
  arm64: dts: realtek: Add RTD1295 RTC node

 .../devicetree/bindings/rtc/realtek,rtd119x.txt    |  16 ++
 arch/arm64/boot/dts/realtek/rtd1295.dtsi           |   6 +
 drivers/rtc/Kconfig                                |   8 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-rtd119x.c                          | 175 +++++++++++++++++++++
 5 files changed, 206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
 create mode 100644 drivers/rtc/rtc-rtd119x.c

-- 
2.12.3

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
  2017-08-20  1:36 ` Andreas Färber
@ 2017-08-20  1:36   ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel
  Cc: linux-kernel, Roc He, 蒋丽琴,
	Andreas Färber, Rob Herring, Mark Rutland, devicetree

Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt

diff --git a/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
new file mode 100644
index 000000000000..bbf1ccb5df31
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
@@ -0,0 +1,16 @@
+Realtek RTD129x Real-Time Clock
+===============================
+
+Required properties:
+- compatible :  Should be "realtek,rtd1295-rtc"
+- reg        :  Specifies the physical base address and size
+- clocks     :  Specifies the clock gate
+
+
+Example:
+
+	rtc@9801b600 {
+		compatible = "realtek,rtd1295-clk";
+		reg = <0x9801b600 0x100>;
+		clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>;
+	};
-- 
2.12.3

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-20  1:36   ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: linux-arm-kernel

Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.

Signed-off-by: Andreas F?rber <afaerber@suse.de>
---
 .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt

diff --git a/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
new file mode 100644
index 000000000000..bbf1ccb5df31
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
@@ -0,0 +1,16 @@
+Realtek RTD129x Real-Time Clock
+===============================
+
+Required properties:
+- compatible :  Should be "realtek,rtd1295-rtc"
+- reg        :  Specifies the physical base address and size
+- clocks     :  Specifies the clock gate
+
+
+Example:
+
+	rtc at 9801b600 {
+		compatible = "realtek,rtd1295-clk";
+		reg = <0x9801b600 0x100>;
+		clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>;
+	};
-- 
2.12.3

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

* [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20  1:36 ` Andreas Färber
@ 2017-08-20  1:36   ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel
  Cc: linux-kernel, Roc He, 蒋丽琴, Andreas Färber

Based on QNAP's mach-rtk119x/driver/rtk_rtc_drv.c code.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 drivers/rtc/Kconfig       |   8 +++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-rtd119x.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+)
 create mode 100644 drivers/rtc/rtc-rtd119x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 72419ac2c52a..882828b1b351 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1765,6 +1765,14 @@ config RTC_DRV_CPCAP
 	   Say y here for CPCAP rtc found on some Motorola phones
 	   and tablets such as Droid 4.
 
+config RTC_DRV_RTD119X
+	bool "Realtek RTD129x RTC"
+	depends on ARCH_REALTEK || COMPILE_TEST
+	default ARCH_REALTEK
+	help
+	  If you say yes here, you get support for the RTD1295 SoC
+	  Real Time Clock.
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index acd366b41c85..55a0a5ca45b0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -131,6 +131,7 @@ obj-$(CONFIG_RTC_DRV_RP5C01)	+= rtc-rp5c01.o
 obj-$(CONFIG_RTC_DRV_RS5C313)	+= rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)	+= rtc-rs5c348.o
 obj-$(CONFIG_RTC_DRV_RS5C372)	+= rtc-rs5c372.o
+obj-$(CONFIG_RTC_DRV_RTD119X)	+= rtc-rtd119x.o
 obj-$(CONFIG_RTC_DRV_RV3029C2)	+= rtc-rv3029c2.o
 obj-$(CONFIG_RTC_DRV_RV8803)	+= rtc-rv8803.o
 obj-$(CONFIG_RTC_DRV_RX4581)	+= rtc-rx4581.o
diff --git a/drivers/rtc/rtc-rtd119x.c b/drivers/rtc/rtc-rtd119x.c
new file mode 100644
index 000000000000..b532e127b56e
--- /dev/null
+++ b/drivers/rtc/rtc-rtd119x.c
@@ -0,0 +1,175 @@
+/*
+ * Realtek RTD129x RTC
+ *
+ * Copyright (c) 2017 Andreas Färber
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+#define RTD_RTCSEC		0x00
+#define RTD_RTCMIN		0x04
+#define RTD_RTCHR		0x08
+#define RTD_RTCDATE_LOW		0x0c
+#define RTD_RTCDATE_HIGH	0x10
+#define RTD_RTCACR		0x28
+#define RTD_RTCEN		0x2c
+
+struct rtd119x_rtc {
+	void __iomem *base;
+	struct clk *clk;
+	struct rtc_device *rtcdev;
+	unsigned base_year;
+};
+
+static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	u32 val;
+
+	val = readl_relaxed(data->base + RTD_RTCEN);
+	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);
+	if (enable) {
+		if ((val & 0xff) == 0x5a)
+			return;
+		writel_relaxed(0x5a, data->base + RTD_RTCEN);
+	} else {
+		writel_relaxed(0, data->base + RTD_RTCEN);
+	}
+}
+
+static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	time64_t t;
+	u32 day;
+
+	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
+	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;
+	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
+	t += day * 24 * 60 * 60;
+	rtc_time64_to_tm(t, tm);
+	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
+	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
+	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
+
+	return rtc_valid_tm(tm);
+}
+
+static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	time64_t time_base, new_time, time_delta;
+	unsigned long day;
+
+	if (tm->tm_year < data->base_year)
+		return -EINVAL;
+
+	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
+	new_time = rtc_tm_to_time64(tm);
+	time_delta = new_time - time_base;
+	day = time_delta / (24 * 60 * 60);
+	if (day > 0x7fff)
+		return -EINVAL;
+
+	rtd119x_rtc_set_enabled(dev, false);
+
+	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
+	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
+	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
+	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
+	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
+
+	rtd119x_rtc_set_enabled(dev, true);
+
+	return 0;
+}
+
+static int rtd119x_rtc_open(struct device *dev)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	u32 val;
+	int ret;
+
+	ret = clk_prepare_enable(data->clk);
+	if (ret)
+		return ret;
+
+	val = readl_relaxed(data->base + RTD_RTCACR);
+	dev_info(dev, "rtcacr = 0x%08x\n", val);
+	if (!(val & BIT(7))) {
+	}
+
+	rtd119x_rtc_set_enabled(dev, true);
+
+	return 0;
+}
+
+static void rtd119x_rtc_release(struct device *dev)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+
+	rtd119x_rtc_set_enabled(dev, false);
+
+	clk_disable_unprepare(data->clk);
+}
+
+static const struct rtc_class_ops rtd119x_rtc_ops = {
+	.open		= rtd119x_rtc_open,
+	.release	= rtd119x_rtc_release,
+	.read_time	= rtd119x_rtc_read_time,
+	.set_time	= rtd119x_rtc_set_time,
+};
+
+static const struct of_device_id rtd119x_rtc_dt_ids[] = {
+	 { .compatible = "realtek,rtd1295-rtc" },
+	 { }
+};
+
+static int rtd119x_rtc_probe(struct platform_device *pdev)
+{
+	struct rtd119x_rtc *data;
+	struct resource *res;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, data);
+	data->base_year = 2014;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	data->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(data->base))
+		return PTR_ERR(data->base);
+
+	data->clk = of_clk_get(pdev->dev.of_node, 0);
+	if (IS_ERR(data->clk))
+		return PTR_ERR(data->clk);
+
+	data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc",
+				&rtd119x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(data->rtcdev)) {
+		dev_err(&pdev->dev, "failed to register rtc device");
+		clk_put(data->clk);
+		return PTR_ERR(data->rtcdev);
+	}
+
+	return 0;
+}
+
+static struct platform_driver rtd119x_rtc_driver = {
+	.probe = rtd119x_rtc_probe,
+	.driver = {
+		.name = "rtd1295-rtc",
+		.of_match_table	= rtd119x_rtc_dt_ids,
+	},
+};
+builtin_platform_driver(rtd119x_rtc_driver);
-- 
2.12.3

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-20  1:36   ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: linux-arm-kernel

Based on QNAP's mach-rtk119x/driver/rtk_rtc_drv.c code.

Signed-off-by: Andreas F?rber <afaerber@suse.de>
---
 drivers/rtc/Kconfig       |   8 +++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-rtd119x.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+)
 create mode 100644 drivers/rtc/rtc-rtd119x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 72419ac2c52a..882828b1b351 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1765,6 +1765,14 @@ config RTC_DRV_CPCAP
 	   Say y here for CPCAP rtc found on some Motorola phones
 	   and tablets such as Droid 4.
 
+config RTC_DRV_RTD119X
+	bool "Realtek RTD129x RTC"
+	depends on ARCH_REALTEK || COMPILE_TEST
+	default ARCH_REALTEK
+	help
+	  If you say yes here, you get support for the RTD1295 SoC
+	  Real Time Clock.
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index acd366b41c85..55a0a5ca45b0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -131,6 +131,7 @@ obj-$(CONFIG_RTC_DRV_RP5C01)	+= rtc-rp5c01.o
 obj-$(CONFIG_RTC_DRV_RS5C313)	+= rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)	+= rtc-rs5c348.o
 obj-$(CONFIG_RTC_DRV_RS5C372)	+= rtc-rs5c372.o
+obj-$(CONFIG_RTC_DRV_RTD119X)	+= rtc-rtd119x.o
 obj-$(CONFIG_RTC_DRV_RV3029C2)	+= rtc-rv3029c2.o
 obj-$(CONFIG_RTC_DRV_RV8803)	+= rtc-rv8803.o
 obj-$(CONFIG_RTC_DRV_RX4581)	+= rtc-rx4581.o
diff --git a/drivers/rtc/rtc-rtd119x.c b/drivers/rtc/rtc-rtd119x.c
new file mode 100644
index 000000000000..b532e127b56e
--- /dev/null
+++ b/drivers/rtc/rtc-rtd119x.c
@@ -0,0 +1,175 @@
+/*
+ * Realtek RTD129x RTC
+ *
+ * Copyright (c) 2017 Andreas F?rber
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+#define RTD_RTCSEC		0x00
+#define RTD_RTCMIN		0x04
+#define RTD_RTCHR		0x08
+#define RTD_RTCDATE_LOW		0x0c
+#define RTD_RTCDATE_HIGH	0x10
+#define RTD_RTCACR		0x28
+#define RTD_RTCEN		0x2c
+
+struct rtd119x_rtc {
+	void __iomem *base;
+	struct clk *clk;
+	struct rtc_device *rtcdev;
+	unsigned base_year;
+};
+
+static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	u32 val;
+
+	val = readl_relaxed(data->base + RTD_RTCEN);
+	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);
+	if (enable) {
+		if ((val & 0xff) == 0x5a)
+			return;
+		writel_relaxed(0x5a, data->base + RTD_RTCEN);
+	} else {
+		writel_relaxed(0, data->base + RTD_RTCEN);
+	}
+}
+
+static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	time64_t t;
+	u32 day;
+
+	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
+	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;
+	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
+	t += day * 24 * 60 * 60;
+	rtc_time64_to_tm(t, tm);
+	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
+	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
+	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
+
+	return rtc_valid_tm(tm);
+}
+
+static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	time64_t time_base, new_time, time_delta;
+	unsigned long day;
+
+	if (tm->tm_year < data->base_year)
+		return -EINVAL;
+
+	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
+	new_time = rtc_tm_to_time64(tm);
+	time_delta = new_time - time_base;
+	day = time_delta / (24 * 60 * 60);
+	if (day > 0x7fff)
+		return -EINVAL;
+
+	rtd119x_rtc_set_enabled(dev, false);
+
+	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
+	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
+	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
+	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
+	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
+
+	rtd119x_rtc_set_enabled(dev, true);
+
+	return 0;
+}
+
+static int rtd119x_rtc_open(struct device *dev)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+	u32 val;
+	int ret;
+
+	ret = clk_prepare_enable(data->clk);
+	if (ret)
+		return ret;
+
+	val = readl_relaxed(data->base + RTD_RTCACR);
+	dev_info(dev, "rtcacr = 0x%08x\n", val);
+	if (!(val & BIT(7))) {
+	}
+
+	rtd119x_rtc_set_enabled(dev, true);
+
+	return 0;
+}
+
+static void rtd119x_rtc_release(struct device *dev)
+{
+	struct rtd119x_rtc *data = dev_get_drvdata(dev);
+
+	rtd119x_rtc_set_enabled(dev, false);
+
+	clk_disable_unprepare(data->clk);
+}
+
+static const struct rtc_class_ops rtd119x_rtc_ops = {
+	.open		= rtd119x_rtc_open,
+	.release	= rtd119x_rtc_release,
+	.read_time	= rtd119x_rtc_read_time,
+	.set_time	= rtd119x_rtc_set_time,
+};
+
+static const struct of_device_id rtd119x_rtc_dt_ids[] = {
+	 { .compatible = "realtek,rtd1295-rtc" },
+	 { }
+};
+
+static int rtd119x_rtc_probe(struct platform_device *pdev)
+{
+	struct rtd119x_rtc *data;
+	struct resource *res;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, data);
+	data->base_year = 2014;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	data->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(data->base))
+		return PTR_ERR(data->base);
+
+	data->clk = of_clk_get(pdev->dev.of_node, 0);
+	if (IS_ERR(data->clk))
+		return PTR_ERR(data->clk);
+
+	data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc",
+				&rtd119x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(data->rtcdev)) {
+		dev_err(&pdev->dev, "failed to register rtc device");
+		clk_put(data->clk);
+		return PTR_ERR(data->rtcdev);
+	}
+
+	return 0;
+}
+
+static struct platform_driver rtd119x_rtc_driver = {
+	.probe = rtd119x_rtc_probe,
+	.driver = {
+		.name = "rtd1295-rtc",
+		.of_match_table	= rtd119x_rtc_dt_ids,
+	},
+};
+builtin_platform_driver(rtd119x_rtc_driver);
-- 
2.12.3

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

* [RFC 3/3] arm64: dts: realtek: Add RTD1295 RTC node
@ 2017-08-20  1:36   ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel
  Cc: linux-kernel, Roc He, 蒋丽琴,
	Andreas Färber, Rob Herring, Mark Rutland, Catalin Marinas,
	Will Deacon, devicetree

Add RTC node to the Realtek RTD1295 Device Tree.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 arch/arm64/boot/dts/realtek/rtd1295.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/realtek/rtd1295.dtsi b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
index 503e2d5fc334..8ae0949ad89e 100644
--- a/arch/arm64/boot/dts/realtek/rtd1295.dtsi
+++ b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
@@ -192,6 +192,12 @@
 			status = "disabled";
 		};
 
+		rtc@9801b600 {
+			compatible = "realtek,rtd1295-rtc";
+			reg = <0x9801b600 0x100>;
+			clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>;
+		};
+
 		gic: interrupt-controller@ff011000 {
 			compatible = "arm,gic-400";
 			reg = <0xff011000 0x1000>,
-- 
2.12.3

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

* [RFC 3/3] arm64: dts: realtek: Add RTD1295 RTC node
@ 2017-08-20  1:36   ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni,
	linux-rtc-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Roc He,
	蒋丽琴,
	Andreas Färber, Rob Herring, Mark Rutland, Catalin Marinas,
	Will Deacon, devicetree-u79uwXL29TY76Z2rM5mHXA

Add RTC node to the Realtek RTD1295 Device Tree.

Signed-off-by: Andreas Färber <afaerber-l3A5Bk7waGM@public.gmane.org>
---
 arch/arm64/boot/dts/realtek/rtd1295.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/realtek/rtd1295.dtsi b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
index 503e2d5fc334..8ae0949ad89e 100644
--- a/arch/arm64/boot/dts/realtek/rtd1295.dtsi
+++ b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
@@ -192,6 +192,12 @@
 			status = "disabled";
 		};
 
+		rtc@9801b600 {
+			compatible = "realtek,rtd1295-rtc";
+			reg = <0x9801b600 0x100>;
+			clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>;
+		};
+
 		gic: interrupt-controller@ff011000 {
 			compatible = "arm,gic-400";
 			reg = <0xff011000 0x1000>,
-- 
2.12.3

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

* [RFC 3/3] arm64: dts: realtek: Add RTD1295 RTC node
@ 2017-08-20  1:36   ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20  1:36 UTC (permalink / raw)
  To: linux-arm-kernel

Add RTC node to the Realtek RTD1295 Device Tree.

Signed-off-by: Andreas F?rber <afaerber@suse.de>
---
 arch/arm64/boot/dts/realtek/rtd1295.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/realtek/rtd1295.dtsi b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
index 503e2d5fc334..8ae0949ad89e 100644
--- a/arch/arm64/boot/dts/realtek/rtd1295.dtsi
+++ b/arch/arm64/boot/dts/realtek/rtd1295.dtsi
@@ -192,6 +192,12 @@
 			status = "disabled";
 		};
 
+		rtc at 9801b600 {
+			compatible = "realtek,rtd1295-rtc";
+			reg = <0x9801b600 0x100>;
+			clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>;
+		};
+
 		gic: interrupt-controller at ff011000 {
 			compatible = "arm,gic-400";
 			reg = <0xff011000 0x1000>,
-- 
2.12.3

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

* Re: [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20  1:36   ` Andreas Färber
@ 2017-08-20  8:32     ` Alexandre Belloni
  -1 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-20  8:32 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Alessandro Zummo, linux-rtc, linux-arm-kernel, linux-kernel,
	Roc He, 蒋丽琴

Hi,

On 20/08/2017 at 03:36:30 +0200, Andreas Färber wrote:
> +static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	time64_t t;
> +	u32 day;
> +
> +	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
> +	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;

Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read? If this is not
the case, you probably want to handle a possible update between both
readl_relaxed.

> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
> +	t += day * 24 * 60 * 60;
> +	rtc_time64_to_tm(t, tm);
> +	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
> +	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
> +	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
> +
> +	return rtc_valid_tm(tm);
> +}
> +
> +static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	time64_t time_base, new_time, time_delta;
> +	unsigned long day;
> +
> +	if (tm->tm_year < data->base_year)
> +		return -EINVAL;
> +
> +	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
> +	new_time = rtc_tm_to_time64(tm);
> +	time_delta = new_time - time_base;
> +	day = time_delta / (24 * 60 * 60);
> +	if (day > 0x7fff)
> +		return -EINVAL;
> +
> +	rtd119x_rtc_set_enabled(dev, false);
> +
> +	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
> +	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
> +	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
> +	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
> +	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
> +
> +	rtd119x_rtc_set_enabled(dev, true);
> +
> +	return 0;
> +}
> +
> +static int rtd119x_rtc_open(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +	int ret;
> +
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret)
> +		return ret;
> +
> +	val = readl_relaxed(data->base + RTD_RTCACR);
> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
> +	if (!(val & BIT(7))) {
> +	}

I don't see the point of reading that register, and not doing anything
with it.

> +
> +	rtd119x_rtc_set_enabled(dev, true);
> +

This is certainly not what you want. The RTC device is usually not
opened so enabling the RTC when open and disabling it when closed will
not work on most systems. This is probably true for the clock too. i.e
what you do here should be done in probe.

> +	return 0;
> +}
> +
> +static void rtd119x_rtc_release(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +
> +	rtd119x_rtc_set_enabled(dev, false);
> +
> +	clk_disable_unprepare(data->clk);
> +}
> +
> +static const struct rtc_class_ops rtd119x_rtc_ops = {
> +	.open		= rtd119x_rtc_open,
> +	.release	= rtd119x_rtc_release,
> +	.read_time	= rtd119x_rtc_read_time,
> +	.set_time	= rtd119x_rtc_set_time,
> +};
> +
> +static const struct of_device_id rtd119x_rtc_dt_ids[] = {
> +	 { .compatible = "realtek,rtd1295-rtc" },
> +	 { }
> +};
> +
> +static int rtd119x_rtc_probe(struct platform_device *pdev)
> +{
> +	struct rtd119x_rtc *data;
> +	struct resource *res;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, data);
> +	data->base_year = 2014;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	data->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(data->base))
> +		return PTR_ERR(data->base);
> +
> +	data->clk = of_clk_get(pdev->dev.of_node, 0);
> +	if (IS_ERR(data->clk))
> +		return PTR_ERR(data->clk);
> +
> +	data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc",
> +				&rtd119x_rtc_ops, THIS_MODULE);
> +	if (IS_ERR(data->rtcdev)) {
> +		dev_err(&pdev->dev, "failed to register rtc device");
> +		clk_put(data->clk);
> +		return PTR_ERR(data->rtcdev);
> +	}
> +
> +	return 0;
> +}
> +
> +static struct platform_driver rtd119x_rtc_driver = {
> +	.probe = rtd119x_rtc_probe,
> +	.driver = {
> +		.name = "rtd1295-rtc",
> +		.of_match_table	= rtd119x_rtc_dt_ids,
> +	},
> +};
> +builtin_platform_driver(rtd119x_rtc_driver);
> -- 
> 2.12.3
> 

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

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-20  8:32     ` Alexandre Belloni
  0 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-20  8:32 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 20/08/2017 at 03:36:30 +0200, Andreas F?rber wrote:
> +static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	time64_t t;
> +	u32 day;
> +
> +	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
> +	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;

Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read? If this is not
the case, you probably want to handle a possible update between both
readl_relaxed.

> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
> +	t += day * 24 * 60 * 60;
> +	rtc_time64_to_tm(t, tm);
> +	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
> +	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
> +	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
> +
> +	return rtc_valid_tm(tm);
> +}
> +
> +static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	time64_t time_base, new_time, time_delta;
> +	unsigned long day;
> +
> +	if (tm->tm_year < data->base_year)
> +		return -EINVAL;
> +
> +	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
> +	new_time = rtc_tm_to_time64(tm);
> +	time_delta = new_time - time_base;
> +	day = time_delta / (24 * 60 * 60);
> +	if (day > 0x7fff)
> +		return -EINVAL;
> +
> +	rtd119x_rtc_set_enabled(dev, false);
> +
> +	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
> +	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
> +	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
> +	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
> +	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
> +
> +	rtd119x_rtc_set_enabled(dev, true);
> +
> +	return 0;
> +}
> +
> +static int rtd119x_rtc_open(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +	int ret;
> +
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret)
> +		return ret;
> +
> +	val = readl_relaxed(data->base + RTD_RTCACR);
> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
> +	if (!(val & BIT(7))) {
> +	}

I don't see the point of reading that register, and not doing anything
with it.

> +
> +	rtd119x_rtc_set_enabled(dev, true);
> +

This is certainly not what you want. The RTC device is usually not
opened so enabling the RTC when open and disabling it when closed will
not work on most systems. This is probably true for the clock too. i.e
what you do here should be done in probe.

> +	return 0;
> +}
> +
> +static void rtd119x_rtc_release(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +
> +	rtd119x_rtc_set_enabled(dev, false);
> +
> +	clk_disable_unprepare(data->clk);
> +}
> +
> +static const struct rtc_class_ops rtd119x_rtc_ops = {
> +	.open		= rtd119x_rtc_open,
> +	.release	= rtd119x_rtc_release,
> +	.read_time	= rtd119x_rtc_read_time,
> +	.set_time	= rtd119x_rtc_set_time,
> +};
> +
> +static const struct of_device_id rtd119x_rtc_dt_ids[] = {
> +	 { .compatible = "realtek,rtd1295-rtc" },
> +	 { }
> +};
> +
> +static int rtd119x_rtc_probe(struct platform_device *pdev)
> +{
> +	struct rtd119x_rtc *data;
> +	struct resource *res;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, data);
> +	data->base_year = 2014;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	data->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(data->base))
> +		return PTR_ERR(data->base);
> +
> +	data->clk = of_clk_get(pdev->dev.of_node, 0);
> +	if (IS_ERR(data->clk))
> +		return PTR_ERR(data->clk);
> +
> +	data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc",
> +				&rtd119x_rtc_ops, THIS_MODULE);
> +	if (IS_ERR(data->rtcdev)) {
> +		dev_err(&pdev->dev, "failed to register rtc device");
> +		clk_put(data->clk);
> +		return PTR_ERR(data->rtcdev);
> +	}
> +
> +	return 0;
> +}
> +
> +static struct platform_driver rtd119x_rtc_driver = {
> +	.probe = rtd119x_rtc_probe,
> +	.driver = {
> +		.name = "rtd1295-rtc",
> +		.of_match_table	= rtd119x_rtc_dt_ids,
> +	},
> +};
> +builtin_platform_driver(rtd119x_rtc_driver);
> -- 
> 2.12.3
> 

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

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

* Re: [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20  1:36   ` Andreas Färber
@ 2017-08-20 15:40     ` Andrew Lunn
  -1 siblings, 0 replies; 32+ messages in thread
From: Andrew Lunn @ 2017-08-20 15:40 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel,
	?????????,
	linux-kernel, Roc He

> +static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +
> +	val = readl_relaxed(data->base + RTD_RTCEN);
> +	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);

dev_dbg()?

> +static int rtd119x_rtc_open(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +	int ret;
> +
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret)
> +		return ret;
> +
> +	val = readl_relaxed(data->base + RTD_RTCACR);
> +	dev_info(dev, "rtcacr = 0x%08x\n", val);

dev_dbg()?

	Andrew

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-20 15:40     ` Andrew Lunn
  0 siblings, 0 replies; 32+ messages in thread
From: Andrew Lunn @ 2017-08-20 15:40 UTC (permalink / raw)
  To: linux-arm-kernel

> +static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +
> +	val = readl_relaxed(data->base + RTD_RTCEN);
> +	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);

dev_dbg()?

> +static int rtd119x_rtc_open(struct device *dev)
> +{
> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
> +	u32 val;
> +	int ret;
> +
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret)
> +		return ret;
> +
> +	val = readl_relaxed(data->base + RTD_RTCACR);
> +	dev_info(dev, "rtcacr = 0x%08x\n", val);

dev_dbg()?

	Andrew

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

* Re: [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20  8:32     ` Alexandre Belloni
@ 2017-08-20 21:10       ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20 21:10 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, linux-rtc, linux-arm-kernel, linux-kernel,
	Roc He, 蒋丽琴

Hi Alexandre,

Am 20.08.2017 um 10:32 schrieb Alexandre Belloni:
> On 20/08/2017 at 03:36:30 +0200, Andreas Färber wrote:
>> +static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	time64_t t;
>> +	u32 day;
>> +
>> +	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
>> +	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;
> 
> Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read?

I do not have an answer to that.

> If this is not
> the case, you probably want to handle a possible update between both
> readl_relaxed.

Are you proposing to disable the RTC while reading the registers, or
something related to my choice of _relaxed? (it follows an explanation
by Marc Zyngier on the irq mux series) Inconsistencies might not be
limited to the date.

>> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
>> +	t += day * 24 * 60 * 60;
>> +	rtc_time64_to_tm(t, tm);

BTW is there any more efficient way to get from year+days to
day/month/year without going via seconds?

>> +	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
>> +	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
>> +	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
>> +
>> +	return rtc_valid_tm(tm);
>> +}
>> +
>> +static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	time64_t time_base, new_time, time_delta;
>> +	unsigned long day;
>> +
>> +	if (tm->tm_year < data->base_year)
>> +		return -EINVAL;
>> +
>> +	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
>> +	new_time = rtc_tm_to_time64(tm);
>> +	time_delta = new_time - time_base;
>> +	day = time_delta / (24 * 60 * 60);
>> +	if (day > 0x7fff)
>> +		return -EINVAL;
>> +
>> +	rtd119x_rtc_set_enabled(dev, false);
>> +
>> +	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
>> +	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
>> +	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
>> +	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
>> +	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
>> +
>> +	rtd119x_rtc_set_enabled(dev, true);
>> +
>> +	return 0;
>> +}
>> +
>> +static int rtd119x_rtc_open(struct device *dev)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(data->clk);
>> +	if (ret)
>> +		return ret;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCACR);
>> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
>> +	if (!(val & BIT(7))) {
>> +	}
> 
> I don't see the point of reading that register, and not doing anything
> with it.

Thanks for spotting this. The story is that the old downstream has code
for this case, but in my testing I didn't run into that path and forgot.
Explanations are largely missing in the vendor code. That code should
probably be added here in v2 and the dev_info() dropped, rather than
dropping the current no-op expression.

>> +
>> +	rtd119x_rtc_set_enabled(dev, true);
>> +
> 
> This is certainly not what you want. The RTC device is usually not
> opened so enabling the RTC when open and disabling it when closed will
> not work on most systems. This is probably true for the clock too. i.e
> what you do here should be done in probe.

I did test the probe path to work, but I can change it again. The
downstream code had it in probe, but looking at rtc_class_ops I saw
those hooks and thought they'd serve a purpose - what are they for then?
(Any chance you can improve the documentation comments to avoid such
misunderstandings? :))

>> +	return 0;
>> +}
[snip]

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-20 21:10       ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20 21:10 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Alexandre,

Am 20.08.2017 um 10:32 schrieb Alexandre Belloni:
> On 20/08/2017 at 03:36:30 +0200, Andreas F?rber wrote:
>> +static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	time64_t t;
>> +	u32 day;
>> +
>> +	day = readl_relaxed(data->base + RTD_RTCDATE_LOW);
>> +	day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8;
> 
> Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read?

I do not have an answer to that.

> If this is not
> the case, you probably want to handle a possible update between both
> readl_relaxed.

Are you proposing to disable the RTC while reading the registers, or
something related to my choice of _relaxed? (it follows an explanation
by Marc Zyngier on the irq mux series) Inconsistencies might not be
limited to the date.

>> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
>> +	t += day * 24 * 60 * 60;
>> +	rtc_time64_to_tm(t, tm);

BTW is there any more efficient way to get from year+days to
day/month/year without going via seconds?

>> +	tm->tm_sec  = readl_relaxed(data->base + RTD_RTCSEC) >> 1;
>> +	tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN);
>> +	tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR);
>> +
>> +	return rtc_valid_tm(tm);
>> +}
>> +
>> +static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	time64_t time_base, new_time, time_delta;
>> +	unsigned long day;
>> +
>> +	if (tm->tm_year < data->base_year)
>> +		return -EINVAL;
>> +
>> +	time_base = mktime64(data->base_year, 1, 1, 0, 0, 0);
>> +	new_time = rtc_tm_to_time64(tm);
>> +	time_delta = new_time - time_base;
>> +	day = time_delta / (24 * 60 * 60);
>> +	if (day > 0x7fff)
>> +		return -EINVAL;
>> +
>> +	rtd119x_rtc_set_enabled(dev, false);
>> +
>> +	writel_relaxed(tm->tm_sec,  data->base + RTD_RTCSEC);
>> +	writel_relaxed(tm->tm_min,  data->base + RTD_RTCMIN);
>> +	writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR);
>> +	writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW);
>> +	writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH);
>> +
>> +	rtd119x_rtc_set_enabled(dev, true);
>> +
>> +	return 0;
>> +}
>> +
>> +static int rtd119x_rtc_open(struct device *dev)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(data->clk);
>> +	if (ret)
>> +		return ret;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCACR);
>> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
>> +	if (!(val & BIT(7))) {
>> +	}
> 
> I don't see the point of reading that register, and not doing anything
> with it.

Thanks for spotting this. The story is that the old downstream has code
for this case, but in my testing I didn't run into that path and forgot.
Explanations are largely missing in the vendor code. That code should
probably be added here in v2 and the dev_info() dropped, rather than
dropping the current no-op expression.

>> +
>> +	rtd119x_rtc_set_enabled(dev, true);
>> +
> 
> This is certainly not what you want. The RTC device is usually not
> opened so enabling the RTC when open and disabling it when closed will
> not work on most systems. This is probably true for the clock too. i.e
> what you do here should be done in probe.

I did test the probe path to work, but I can change it again. The
downstream code had it in probe, but looking at rtc_class_ops I saw
those hooks and thought they'd serve a purpose - what are they for then?
(Any chance you can improve the documentation comments to avoid such
misunderstandings? :))

>> +	return 0;
>> +}
[snip]

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

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

* Re: [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20 15:40     ` Andrew Lunn
@ 2017-08-20 21:12       ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20 21:12 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel,
	?????????,
	linux-kernel, Roc He

Am 20.08.2017 um 17:40 schrieb Andrew Lunn:
>> +static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCEN);
>> +	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);
> 
> dev_dbg()?
> 
>> +static int rtd119x_rtc_open(struct device *dev)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(data->clk);
>> +	if (ret)
>> +		return ret;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCACR);
>> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
> 
> dev_dbg()?

Yeah, either that or dropping them altogether.

Thanks,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-20 21:12       ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-20 21:12 UTC (permalink / raw)
  To: linux-arm-kernel

Am 20.08.2017 um 17:40 schrieb Andrew Lunn:
>> +static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCEN);
>> +	dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val);
> 
> dev_dbg()?
> 
>> +static int rtd119x_rtc_open(struct device *dev)
>> +{
>> +	struct rtd119x_rtc *data = dev_get_drvdata(dev);
>> +	u32 val;
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(data->clk);
>> +	if (ret)
>> +		return ret;
>> +
>> +	val = readl_relaxed(data->base + RTD_RTCACR);
>> +	dev_info(dev, "rtcacr = 0x%08x\n", val);
> 
> dev_dbg()?

Yeah, either that or dropping them altogether.

Thanks,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
  2017-08-20  1:36   ` Andreas Färber
@ 2017-08-23  0:29     ` Rob Herring
  -1 siblings, 0 replies; 32+ messages in thread
From: Rob Herring @ 2017-08-23  0:29 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel,
	linux-kernel, Roc He, 蒋丽琴,
	Mark Rutland, devicetree

On Sun, Aug 20, 2017 at 03:36:29AM +0200, Andreas Färber wrote:
> Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt

Acked-by: Rob Herring <robh@kernel.org>

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-23  0:29     ` Rob Herring
  0 siblings, 0 replies; 32+ messages in thread
From: Rob Herring @ 2017-08-23  0:29 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Aug 20, 2017 at 03:36:29AM +0200, Andreas F?rber wrote:
> Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.
> 
> Signed-off-by: Andreas F?rber <afaerber@suse.de>
> ---
>  .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [RFC 2/3] rtc: Add Realtek RTD1295
  2017-08-20 21:10       ` Andreas Färber
@ 2017-08-23  1:18         ` Alexandre Belloni
  -1 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-23  1:18 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Alessandro Zummo, linux-rtc, linux-arm-kernel, linux-kernel,
	Roc He, 蒋丽琴

On 20/08/2017 at 23:10:16 +0200, Andreas Färber wrote:
> > Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read?
> 
> I do not have an answer to that.
> 
> > If this is not
> > the case, you probably want to handle a possible update between both
> > readl_relaxed.
> 
> Are you proposing to disable the RTC while reading the registers, or
> something related to my choice of _relaxed? (it follows an explanation
> by Marc Zyngier on the irq mux series) Inconsistencies might not be
> limited to the date.
> 

A simple way to be sure would be to read RTD_RTCSEC first, then the
other registers and check RTD_RTCSEC didn't change. This will ensure the
other registers have not be updated in the meantime (unless it takes
one minute but I doubt this is the case). if RTD_RTCSEC changed, then
you can start over.

> >> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
> >> +	t += day * 24 * 60 * 60;
> >> +	rtc_time64_to_tm(t, tm);
> 
> BTW is there any more efficient way to get from year+days to
> day/month/year without going via seconds?
> 

Completely untested:

for (y = data->base_year; (day - (365 + is_leap_year(y))) > 0; y++)
	day -= (365 + is_leap_year(y));

for (m = 0; (day - rtc_month_days(m, y)) > 0; m++)
	day -= rtc_month_days(m, y);


> >> +
> >> +	rtd119x_rtc_set_enabled(dev, true);
> >> +
> > 
> > This is certainly not what you want. The RTC device is usually not
> > opened so enabling the RTC when open and disabling it when closed will
> > not work on most systems. This is probably true for the clock too. i.e
> > what you do here should be done in probe.
> 
> I did test the probe path to work, but I can change it again. The
> downstream code had it in probe, but looking at rtc_class_ops I saw
> those hooks and thought they'd serve a purpose - what are they for then?
> (Any chance you can improve the documentation comments to avoid such
> misunderstandings? :))
> 

They are (were) used only when the rtc character device (/dev/rtcx) is
opened/released but the cdev interface is one of many interfaces to the
RTC sod it doesn't make sense to do something only in that case
(especially requesting IRQs).

To solve your concern, this is what I'm going to apply after fixing the
two remaining uses of .release:

http://patchwork.ozlabs.org/patch/804707/


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

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

* [RFC 2/3] rtc: Add Realtek RTD1295
@ 2017-08-23  1:18         ` Alexandre Belloni
  0 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-23  1:18 UTC (permalink / raw)
  To: linux-arm-kernel

On 20/08/2017 at 23:10:16 +0200, Andreas F?rber wrote:
> > Is RTD_RTCDATE_HIGH latched when RTD_RTCDATE_LOW is read?
> 
> I do not have an answer to that.
> 
> > If this is not
> > the case, you probably want to handle a possible update between both
> > readl_relaxed.
> 
> Are you proposing to disable the RTC while reading the registers, or
> something related to my choice of _relaxed? (it follows an explanation
> by Marc Zyngier on the irq mux series) Inconsistencies might not be
> limited to the date.
> 

A simple way to be sure would be to read RTD_RTCSEC first, then the
other registers and check RTD_RTCSEC didn't change. This will ensure the
other registers have not be updated in the meantime (unless it takes
one minute but I doubt this is the case). if RTD_RTCSEC changed, then
you can start over.

> >> +	t = mktime64(data->base_year, 1, 1, 0, 0, 0);
> >> +	t += day * 24 * 60 * 60;
> >> +	rtc_time64_to_tm(t, tm);
> 
> BTW is there any more efficient way to get from year+days to
> day/month/year without going via seconds?
> 

Completely untested:

for (y = data->base_year; (day - (365 + is_leap_year(y))) > 0; y++)
	day -= (365 + is_leap_year(y));

for (m = 0; (day - rtc_month_days(m, y)) > 0; m++)
	day -= rtc_month_days(m, y);


> >> +
> >> +	rtd119x_rtc_set_enabled(dev, true);
> >> +
> > 
> > This is certainly not what you want. The RTC device is usually not
> > opened so enabling the RTC when open and disabling it when closed will
> > not work on most systems. This is probably true for the clock too. i.e
> > what you do here should be done in probe.
> 
> I did test the probe path to work, but I can change it again. The
> downstream code had it in probe, but looking at rtc_class_ops I saw
> those hooks and thought they'd serve a purpose - what are they for then?
> (Any chance you can improve the documentation comments to avoid such
> misunderstandings? :))
> 

They are (were) used only when the rtc character device (/dev/rtcx) is
opened/released but the cdev interface is one of many interfaces to the
RTC sod it doesn't make sense to do something only in that case
(especially requesting IRQs).

To solve your concern, this is what I'm going to apply after fixing the
two remaining uses of .release:

http://patchwork.ozlabs.org/patch/804707/


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

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
  2017-08-23  0:29     ` Rob Herring
  (?)
@ 2017-08-27 10:41       ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-27 10:41 UTC (permalink / raw)
  To: Rob Herring
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-arm-kernel,
	linux-kernel, Roc He, 蒋丽琴,
	Mark Rutland, devicetree

Hi Rob,

Am 23.08.2017 um 02:29 schrieb Rob Herring:
> On Sun, Aug 20, 2017 at 03:36:29AM +0200, Andreas Färber wrote:
>> Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
>>  .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
> 
> Acked-by: Rob Herring <robh@kernel.org>

Thanks. Did you read the RFC question in the cover letter as well and
have any comments? Downstream has an rtc-base-year = <2014>; property
that I had left out in this RFC and due to your ack not included in v2.

Should we default to 2014 in the driver and add an optional base-year
property once we encounter a diverging device, or should we make it
required from the beginning? I did not spot any other rtc binding with
such a property and would appreciate a clarification.

Thanks in advance,

Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 10:41       ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-27 10:41 UTC (permalink / raw)
  To: Rob Herring
  Cc: Alessandro Zummo, Alexandre Belloni,
	linux-rtc-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Roc He,
	蒋丽琴,
	Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA

Hi Rob,

Am 23.08.2017 um 02:29 schrieb Rob Herring:
> On Sun, Aug 20, 2017 at 03:36:29AM +0200, Andreas Färber wrote:
>> Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.
>>
>> Signed-off-by: Andreas Färber <afaerber-l3A5Bk7waGM@public.gmane.org>
>> ---
>>  .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
> 
> Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

Thanks. Did you read the RFC question in the cover letter as well and
have any comments? Downstream has an rtc-base-year = <2014>; property
that I had left out in this RFC and due to your ack not included in v2.

Should we default to 2014 in the driver and add an optional base-year
property once we encounter a diverging device, or should we make it
required from the beginning? I did not spot any other rtc binding with
such a property and would appreciate a clarification.

Thanks in advance,

Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
--
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] 32+ messages in thread

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 10:41       ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-27 10:41 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Rob,

Am 23.08.2017 um 02:29 schrieb Rob Herring:
> On Sun, Aug 20, 2017 at 03:36:29AM +0200, Andreas F?rber wrote:
>> Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families.
>>
>> Signed-off-by: Andreas F?rber <afaerber@suse.de>
>> ---
>>  .../devicetree/bindings/rtc/realtek,rtd119x.txt          | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt
> 
> Acked-by: Rob Herring <robh@kernel.org>

Thanks. Did you read the RFC question in the cover letter as well and
have any comments? Downstream has an rtc-base-year = <2014>; property
that I had left out in this RFC and due to your ack not included in v2.

Should we default to 2014 in the driver and add an optional base-year
property once we encounter a diverging device, or should we make it
required from the beginning? I did not spot any other rtc binding with
such a property and would appreciate a clarification.

Thanks in advance,

Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 13:47         ` Andrew Lunn
  0 siblings, 0 replies; 32+ messages in thread
From: Andrew Lunn @ 2017-08-27 13:47 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Rob Herring, linux-rtc, Alessandro Zummo, Roc He, devicetree,
	?????????,
	linux-kernel, Alexandre Belloni, Mark Rutland, linux-arm-kernel

> Thanks. Did you read the RFC question in the cover letter as well and
> have any comments? Downstream has an rtc-base-year = <2014>; property
> that I had left out in this RFC and due to your ack not included in v2.
> 
> Should we default to 2014 in the driver and add an optional base-year
> property once we encounter a diverging device, or should we make it
> required from the beginning? I did not spot any other rtc binding with
> such a property and would appreciate a clarification.

Hi Andreas

>From the perspective of the hardware, does it care what the base is?

A device using a different base will initially return the wrong
time. But once the correct time has been written back, it will be O.K.

This only becomes an issue if a device is used with different OSs,
which have different bases. Swapping back and forth between OSs then
becomes an issue.

KISS suggests not having a base in DT until it is actually
required. Since it is an additional property, it does not break
backwards compatibility when added.

	  Andrew

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 13:47         ` Andrew Lunn
  0 siblings, 0 replies; 32+ messages in thread
From: Andrew Lunn @ 2017-08-27 13:47 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Rob Herring, linux-rtc-u79uwXL29TY76Z2rM5mHXA, Alessandro Zummo,
	Roc He, devicetree-u79uwXL29TY76Z2rM5mHXA, ?????????,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Alexandre Belloni,
	Mark Rutland, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

> Thanks. Did you read the RFC question in the cover letter as well and
> have any comments? Downstream has an rtc-base-year = <2014>; property
> that I had left out in this RFC and due to your ack not included in v2.
> 
> Should we default to 2014 in the driver and add an optional base-year
> property once we encounter a diverging device, or should we make it
> required from the beginning? I did not spot any other rtc binding with
> such a property and would appreciate a clarification.

Hi Andreas

>From the perspective of the hardware, does it care what the base is?

A device using a different base will initially return the wrong
time. But once the correct time has been written back, it will be O.K.

This only becomes an issue if a device is used with different OSs,
which have different bases. Swapping back and forth between OSs then
becomes an issue.

KISS suggests not having a base in DT until it is actually
required. Since it is an additional property, it does not break
backwards compatibility when added.

	  Andrew

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 13:47         ` Andrew Lunn
  0 siblings, 0 replies; 32+ messages in thread
From: Andrew Lunn @ 2017-08-27 13:47 UTC (permalink / raw)
  To: linux-arm-kernel

> Thanks. Did you read the RFC question in the cover letter as well and
> have any comments? Downstream has an rtc-base-year = <2014>; property
> that I had left out in this RFC and due to your ack not included in v2.
> 
> Should we default to 2014 in the driver and add an optional base-year
> property once we encounter a diverging device, or should we make it
> required from the beginning? I did not spot any other rtc binding with
> such a property and would appreciate a clarification.

Hi Andreas

>From the perspective of the hardware, does it care what the base is?

A device using a different base will initially return the wrong
time. But once the correct time has been written back, it will be O.K.

This only becomes an issue if a device is used with different OSs,
which have different bases. Swapping back and forth between OSs then
becomes an issue.

KISS suggests not having a base in DT until it is actually
required. Since it is an additional property, it does not break
backwards compatibility when added.

	  Andrew

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
  2017-08-27 13:47         ` Andrew Lunn
@ 2017-08-27 17:26           ` Andreas Färber
  -1 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-27 17:26 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Rob Herring, linux-rtc, Alessandro Zummo, Roc He, devicetree,
	?????????,
	linux-kernel, Alexandre Belloni, Mark Rutland, linux-arm-kernel

Hi Andrew,

Am 27.08.2017 um 15:47 schrieb Andrew Lunn:
>> Thanks. Did you read the RFC question in the cover letter as well and
>> have any comments? Downstream has an rtc-base-year = <2014>; property
>> that I had left out in this RFC and due to your ack not included in v2.
>>
>> Should we default to 2014 in the driver and add an optional base-year
>> property once we encounter a diverging device, or should we make it
>> required from the beginning? I did not spot any other rtc binding with
>> such a property and would appreciate a clarification.
> 
> From the perspective of the hardware, does it care what the base is?

The hardware stores a 15-bit number of days since Jan 1st of that base
year. It does not store the base year.

The datasheet does not name such a base year. No manual is available.

The driver needs to get it from somewhere for calculating day/month/year
in read_time and days in set_time.

The read_offset/set_offset API appeared to be something different.

> A device using a different base will initially return the wrong
> time. But once the correct time has been written back, it will be O.K.
> 
> This only becomes an issue if a device is used with different OSs,
> which have different bases. Swapping back and forth between OSs then
> becomes an issue.

These are TV boxes, so yes, I'm dual-booting into Android with a vendor
4.1 kernel and would like to keep date compatibility.

https://en.opensuse.org/HCL:Zidoo_X9S
https://en.opensuse.org/HCL:ProBox2_Ava
https://en.opensuse.org/HCL:Lake1

As stated in the v2 rtc commit message, 2014 is the base year
encountered on all three devices that I've had access to.
@Jiang, if you're using a different base year, please speak up!

> KISS suggests not having a base in DT until it is actually
> required. Since it is an additional property, it does not break
> backwards compatibility when added.

That's what I've attempted here - but for RDA8810PL serial Rob said he
did not want future changes to my binding, therefore I am asking for his
confirmation here.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 17:26           ` Andreas Färber
  0 siblings, 0 replies; 32+ messages in thread
From: Andreas Färber @ 2017-08-27 17:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Andrew,

Am 27.08.2017 um 15:47 schrieb Andrew Lunn:
>> Thanks. Did you read the RFC question in the cover letter as well and
>> have any comments? Downstream has an rtc-base-year = <2014>; property
>> that I had left out in this RFC and due to your ack not included in v2.
>>
>> Should we default to 2014 in the driver and add an optional base-year
>> property once we encounter a diverging device, or should we make it
>> required from the beginning? I did not spot any other rtc binding with
>> such a property and would appreciate a clarification.
> 
> From the perspective of the hardware, does it care what the base is?

The hardware stores a 15-bit number of days since Jan 1st of that base
year. It does not store the base year.

The datasheet does not name such a base year. No manual is available.

The driver needs to get it from somewhere for calculating day/month/year
in read_time and days in set_time.

The read_offset/set_offset API appeared to be something different.

> A device using a different base will initially return the wrong
> time. But once the correct time has been written back, it will be O.K.
> 
> This only becomes an issue if a device is used with different OSs,
> which have different bases. Swapping back and forth between OSs then
> becomes an issue.

These are TV boxes, so yes, I'm dual-booting into Android with a vendor
4.1 kernel and would like to keep date compatibility.

https://en.opensuse.org/HCL:Zidoo_X9S
https://en.opensuse.org/HCL:ProBox2_Ava
https://en.opensuse.org/HCL:Lake1

As stated in the v2 rtc commit message, 2014 is the base year
encountered on all three devices that I've had access to.
@Jiang, if you're using a different base year, please speak up!

> KISS suggests not having a base in DT until it is actually
> required. Since it is an additional property, it does not break
> backwards compatibility when added.

That's what I've attempted here - but for RDA8810PL serial Rob said he
did not want future changes to my binding, therefore I am asking for his
confirmation here.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

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

* Re: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
  2017-08-27 17:26           ` Andreas Färber
@ 2017-08-27 19:07             ` Alexandre Belloni
  -1 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-27 19:07 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Andrew Lunn, Rob Herring, linux-rtc, Alessandro Zummo, Roc He,
	devicetree, ?????????,
	linux-kernel, Mark Rutland, linux-arm-kernel

On 27/08/2017 at 19:26:11 +0200, Andreas Färber wrote:
> Hi Andrew,
> 
> Am 27.08.2017 um 15:47 schrieb Andrew Lunn:
> >> Thanks. Did you read the RFC question in the cover letter as well and
> >> have any comments? Downstream has an rtc-base-year = <2014>; property
> >> that I had left out in this RFC and due to your ack not included in v2.
> >>
> >> Should we default to 2014 in the driver and add an optional base-year
> >> property once we encounter a diverging device, or should we make it
> >> required from the beginning? I did not spot any other rtc binding with
> >> such a property and would appreciate a clarification.
> > 
> > From the perspective of the hardware, does it care what the base is?
> 
> The hardware stores a 15-bit number of days since Jan 1st of that base
> year. It does not store the base year.
> 
> The datasheet does not name such a base year. No manual is available.
> 
> The driver needs to get it from somewhere for calculating day/month/year
> in read_time and days in set_time.
> 
> The read_offset/set_offset API appeared to be something different.
> 

There is no api to change the epoch of an RTC because it is difficult to
do in a race free way. This has to be worked on.

Anyway, you don't really care for now as it goes up to 2093 and
hopefully, you will never have a product with a different epoch.

> > A device using a different base will initially return the wrong
> > time. But once the correct time has been written back, it will be O.K.
> > 

The other issue being that you don't have any way to know whether the
base is correct or not until the date is set.

> > This only becomes an issue if a device is used with different OSs,
> > which have different bases. Swapping back and forth between OSs then
> > becomes an issue.
> 
> These are TV boxes, so yes, I'm dual-booting into Android with a vendor
> 4.1 kernel and would like to keep date compatibility.
> 
> https://en.opensuse.org/HCL:Zidoo_X9S
> https://en.opensuse.org/HCL:ProBox2_Ava
> https://en.opensuse.org/HCL:Lake1
> 
> As stated in the v2 rtc commit message, 2014 is the base year
> encountered on all three devices that I've had access to.
> @Jiang, if you're using a different base year, please speak up!
> 
> > KISS suggests not having a base in DT until it is actually
> > required. Since it is an additional property, it does not break
> > backwards compatibility when added.
> 
> That's what I've attempted here - but for RDA8810PL serial Rob said he
> did not want future changes to my binding, therefore I am asking for his
> confirmation here.

It would be a change that is easy enough to do in a backward compatible
way so that is probably fine.

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

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

* [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295
@ 2017-08-27 19:07             ` Alexandre Belloni
  0 siblings, 0 replies; 32+ messages in thread
From: Alexandre Belloni @ 2017-08-27 19:07 UTC (permalink / raw)
  To: linux-arm-kernel

On 27/08/2017 at 19:26:11 +0200, Andreas F?rber wrote:
> Hi Andrew,
> 
> Am 27.08.2017 um 15:47 schrieb Andrew Lunn:
> >> Thanks. Did you read the RFC question in the cover letter as well and
> >> have any comments? Downstream has an rtc-base-year = <2014>; property
> >> that I had left out in this RFC and due to your ack not included in v2.
> >>
> >> Should we default to 2014 in the driver and add an optional base-year
> >> property once we encounter a diverging device, or should we make it
> >> required from the beginning? I did not spot any other rtc binding with
> >> such a property and would appreciate a clarification.
> > 
> > From the perspective of the hardware, does it care what the base is?
> 
> The hardware stores a 15-bit number of days since Jan 1st of that base
> year. It does not store the base year.
> 
> The datasheet does not name such a base year. No manual is available.
> 
> The driver needs to get it from somewhere for calculating day/month/year
> in read_time and days in set_time.
> 
> The read_offset/set_offset API appeared to be something different.
> 

There is no api to change the epoch of an RTC because it is difficult to
do in a race free way. This has to be worked on.

Anyway, you don't really care for now as it goes up to 2093 and
hopefully, you will never have a product with a different epoch.

> > A device using a different base will initially return the wrong
> > time. But once the correct time has been written back, it will be O.K.
> > 

The other issue being that you don't have any way to know whether the
base is correct or not until the date is set.

> > This only becomes an issue if a device is used with different OSs,
> > which have different bases. Swapping back and forth between OSs then
> > becomes an issue.
> 
> These are TV boxes, so yes, I'm dual-booting into Android with a vendor
> 4.1 kernel and would like to keep date compatibility.
> 
> https://en.opensuse.org/HCL:Zidoo_X9S
> https://en.opensuse.org/HCL:ProBox2_Ava
> https://en.opensuse.org/HCL:Lake1
> 
> As stated in the v2 rtc commit message, 2014 is the base year
> encountered on all three devices that I've had access to.
> @Jiang, if you're using a different base year, please speak up!
> 
> > KISS suggests not having a base in DT until it is actually
> > required. Since it is an additional property, it does not break
> > backwards compatibility when added.
> 
> That's what I've attempted here - but for RDA8810PL serial Rob said he
> did not want future changes to my binding, therefore I am asking for his
> confirmation here.

It would be a change that is easy enough to do in a backward compatible
way so that is probably fine.

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

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

end of thread, other threads:[~2017-08-27 19:07 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-20  1:36 [RFC 0/3] arm64: Realtek RTD1295 RTC Andreas Färber
2017-08-20  1:36 ` Andreas Färber
2017-08-20  1:36 ` Andreas Färber
2017-08-20  1:36 ` [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295 Andreas Färber
2017-08-20  1:36   ` Andreas Färber
2017-08-23  0:29   ` Rob Herring
2017-08-23  0:29     ` Rob Herring
2017-08-27 10:41     ` Andreas Färber
2017-08-27 10:41       ` Andreas Färber
2017-08-27 10:41       ` Andreas Färber
2017-08-27 13:47       ` Andrew Lunn
2017-08-27 13:47         ` Andrew Lunn
2017-08-27 13:47         ` Andrew Lunn
2017-08-27 17:26         ` Andreas Färber
2017-08-27 17:26           ` Andreas Färber
2017-08-27 19:07           ` Alexandre Belloni
2017-08-27 19:07             ` Alexandre Belloni
2017-08-20  1:36 ` [RFC 2/3] " Andreas Färber
2017-08-20  1:36   ` Andreas Färber
2017-08-20  8:32   ` Alexandre Belloni
2017-08-20  8:32     ` Alexandre Belloni
2017-08-20 21:10     ` Andreas Färber
2017-08-20 21:10       ` Andreas Färber
2017-08-23  1:18       ` Alexandre Belloni
2017-08-23  1:18         ` Alexandre Belloni
2017-08-20 15:40   ` Andrew Lunn
2017-08-20 15:40     ` Andrew Lunn
2017-08-20 21:12     ` Andreas Färber
2017-08-20 21:12       ` Andreas Färber
2017-08-20  1:36 ` [RFC 3/3] arm64: dts: realtek: Add RTD1295 RTC node Andreas Färber
2017-08-20  1:36   ` Andreas Färber
2017-08-20  1:36   ` Andreas Färber

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.