Skip to contentSkip to conversation

Add RTC support

PATCH New Biju Das 2 participants 10 messages Jul 15, 2019 – Jul 17, 2019

Subsystems (3)
lore
Share & tools
lore

Biju Das

author
#0 lore raw

cover Add RTC support

This patch series add RTC support for EK874 platform.

This patch series is based on linux-4.19.y-cip and all the patches in this series are cherry-picked from linux rc tree.

This patch series is depend on the below patch series
https://patchwork.kernel.org/project/cip-dev/list/?series=145931

Alexandre Belloni (2):
rtc: nvmem: use devm_nvmem_register()
rtc: nvmem: remove nvmem from struct rtc_device

Biju Das (4):
dt-bindings: rtc: add rx8571 compatible
rtc: rx8581: Add support for Epson rx8571 RTC
arm64: defconfig: enable RX-8581 config option
arm64: dts: renesas: r8a774c0-cat874: add RTC support

 .../devicetree/bindings/trivial-devices.txt        |   1 +
 arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts    |  19 ++++
 arch/arm64/configs/defconfig                       |   1 +
 drivers/rtc/Kconfig                                |   5 +-
 drivers/rtc/nvmem.c                                |  29 ++----
 drivers/rtc/rtc-rx8581.c                           | 114 +++++++++++++++++++--
 include/linux/rtc.h                                |   1 -
 7 files changed, 139 insertions(+), 31 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/6 rtc: nvmem: use devm_nvmem_register()

From: Alexandre Belloni <[email protected]>

commit 461e557b97277b693cd8008c32a9d01c7f8f453b upstream.

Use the resource managed variant of nvmem_register().

---
 drivers/rtc/nvmem.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/rtc/nvmem.c +1 -6
index 36ab183..2a7220d 100644
@@ -93,7 +93,7 @@ int rtc_nvmem_register(struct rtc_device *rtc,
 
 	nvmem_config->dev = rtc->dev.parent;
 	nvmem_config->owner = rtc->owner;
-	rtc->nvmem = nvmem_register(nvmem_config);
+	rtc->nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
 	if (IS_ERR(rtc->nvmem))
 		return PTR_ERR(rtc->nvmem);
 
@@ -107,12 +107,7 @@ EXPORT_SYMBOL_GPL(rtc_nvmem_register);
 
 void rtc_nvmem_unregister(struct rtc_device *rtc)
 {
-	if (IS_ERR_OR_NULL(rtc->nvmem))
-		return;
-
 	/* unregister the old ABI */
 	if (rtc->nvram)
 		rtc_nvram_unregister(rtc);
-
-	nvmem_unregister(rtc->nvmem);
 }
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH 2/6 rtc: nvmem: remove nvmem from struct rtc_device

In reply to Biju Das

From: Alexandre Belloni <[email protected]>

commit 41c9e132c5cc3e5f28cf44032ff82f7614a42989 upstream.

Using devm_nvmem_register allows to avoid tracking the nvmem pointer in the rtc_device structure.
This ultimately allows to register multiple nvmem devices from an RTC driver.

---
 drivers/rtc/nvmem.c | 24 ++++++++++--------------
 include/linux/rtc.h |  1 -
 2 files changed, 10 insertions(+), 15 deletions(-)
drivers/rtc/nvmem.c +10 -14
index 2a7220d..ebdfe8e 100644
@@ -25,11 +25,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj,
 	       struct bin_attribute *attr,
 	       char *buf, loff_t off, size_t count)
 {
-	struct rtc_device *rtc = attr->private;
-
 	dev_warn_once(kobj_to_dev(kobj), nvram_warning);
 
-	return nvmem_device_read(rtc->nvmem, off, count, buf);
+	return nvmem_device_read(attr->private, off, count, buf);
 }
 
 static ssize_t
@@ -37,14 +35,13 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
 		struct bin_attribute *attr,
 		char *buf, loff_t off, size_t count)
 {
-	struct rtc_device *rtc = attr->private;
-
 	dev_warn_once(kobj_to_dev(kobj), nvram_warning);
 
-	return nvmem_device_write(rtc->nvmem, off, count, buf);
+	return nvmem_device_write(attr->private, off, count, buf);
 }
 
-static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
+static int rtc_nvram_register(struct rtc_device *rtc,
+			      struct nvmem_device *nvmem, size_t size)
 {
 	int err;
 
@@ -56,7 +53,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
 
 	rtc->nvram->attr.name = "nvram";
 	rtc->nvram->attr.mode = 0644;
-	rtc->nvram->private = rtc;
+	rtc->nvram->private = nvmem;
 
 	sysfs_bin_attr_init(rtc->nvram);
 
@@ -85,21 +82,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
 int rtc_nvmem_register(struct rtc_device *rtc,
 		       struct nvmem_config *nvmem_config)
 {
-	if (!IS_ERR_OR_NULL(rtc->nvmem))
-		return -EBUSY;
+	struct nvmem_device *nvmem;
 
 	if (!nvmem_config)
 		return -ENODEV;
 
 	nvmem_config->dev = rtc->dev.parent;
 	nvmem_config->owner = rtc->owner;
-	rtc->nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
-	if (IS_ERR(rtc->nvmem))
-		return PTR_ERR(rtc->nvmem);
+	nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
 
 	/* Register the old ABI */
 	if (rtc->nvram_old_abi)
-		rtc_nvram_register(rtc, nvmem_config->size);
+		rtc_nvram_register(rtc, nvmem, nvmem_config->size);
 
 	return 0;
 }
include/linux/rtc.h +0 -1
index 6aedc30..6e9cb05 100644
@@ -138,7 +138,6 @@ struct rtc_device {
 
 	bool registered;
 
-	struct nvmem_device *nvmem;
 	/* Old ABI support */
 	bool nvram_old_abi;
 	struct bin_attribute *nvram;
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH 3/6 dt-bindings: rtc: add rx8571 compatible

In reply to Biju Das

commit 57e883b576dc056f59a5612713b679432db36bfa upstream.

The Epson rx8571 is compatible with the Epson rx8581 RTC.

The difference between the rx8571 and rx8581 RTC is that the former has 16 bytes more RAM. This renders them incompatible from a DT point of view.

[Backported to 4.19-cip]
---
 Documentation/devicetree/bindings/trivial-devices.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/trivial-devices.txt +1 -0
index 763a280..8a7e937 100644
@@ -52,6 +52,7 @@ dlg,da9063		DA9063: system PMIC for quad-core application processors
 domintech,dmard09	DMARD09: 3-axis Accelerometer
 domintech,dmard10	DMARD10: 3-axis Accelerometer
 epson,rx8010		I2C-BUS INTERFACE REAL TIME CLOCK MODULE
+epson,rx8571		I2C-BUS INTERFACE REAL TIME CLOCK MODULE with Battery Backed RAM
 epson,rx8581		I2C-BUS INTERFACE REAL TIME CLOCK MODULE
 emmicro,em3027		EM Microelectronic EM3027 Real-time Clock
 fsl,mag3110		MAG3110: Xtrinsic High Accuracy, 3D Magnetometer
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH 4/6 rtc: rx8581: Add support for Epson rx8571 RTC

In reply to Biju Das

commit 51f896ffd1a5aacbda82ed82552c4077e3cc3b68 upstream.

Add support for Epson rx8571 real-time clock. rx8571 rtc is compatible with rx8581,except that rx8571 has additional 16 bytes of RAM.

16 bytes of nvmem is supported and exposed in sysfs (# is the instance number,starting with 0): /sys/bus/nvmem/devices/rx8571-#/nvmem

---
 drivers/rtc/Kconfig      |   5 ++-
 drivers/rtc/rtc-rx8581.c | 114 +++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 108 insertions(+), 11 deletions(-)
drivers/rtc/Kconfig +3 -2
index 7d7be60..ec2cba4 100644
@@ -600,9 +600,10 @@ config RTC_DRV_RX8010
 	  will be called rtc-rx8010.
 
 config RTC_DRV_RX8581
-	tristate "Epson RX-8581"
+	tristate "Epson RX-8571/RX-8581"
 	help
-	  If you say yes here you will get support for the Epson RX-8581.
+	  If you say yes here you will get support for the Epson RX-8571/
+	  RX-8581.
 
 	  This driver can also be built as a module. If so the module
 	  will be called rtc-rx8581.
drivers/rtc/rtc-rx8581.c +105 -9

167 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH 4/6 rtc: rx8581: Add support for Epson rx8571 RTC

Hi!

Quoted 13 lines
drivers/rtc/rtc-rx8581.c +13 -0
+static int rx85x1_nvram_read(void *priv, unsigned int offset, void *val,
+			     size_t bytes)
+{
+	struct rx8581 *rx8581 = priv;
+	unsigned int tmp_val;
+	int ret;
+
+	ret = regmap_read(rx8581->regmap, RX8581_REG_RAM, &tmp_val);
+	(*(unsigned char *)val) = (unsigned char) tmp_val;
+
+	return ret;
+}
+

drivers/rtc/rtc-rx8581.c static const struct rtc_class_ops rx8581_rtc_ops = { · line 234

Quoted 10 lines
drivers/rtc/rtc-rx8581.c +10 -0
+static int rx85x1_nvram_write(void *priv, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	struct rx8581 *rx8581 = priv;
+	unsigned char tmp_val;
+
+	tmp_val = *((unsigned char *)val);
+	return regmap_write(rx8581->regmap, RX8581_REG_RAM,
+				(unsigned int)tmp_val);
+}

I see that 85x1 has single byte of RAM. I'd still expect return of error in case of offset != 0 or bytes != 1.

Probably best done in mainline first...

Best regards,
Pavel

Signature · 9 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/22b19a6e/attachment.sig>
author
#6 lore raw

PATCH 4/6 rtc: rx8581: Add support for Epson rx8571 RTC

Hi Pavel,

Thanks for the feedback.

Quoted 23 lines

Subject: Re: [cip-dev] [PATCH 4.19.y-cip 4/6] rtc: rx8581: Add support for Epson rx8571 RTC

Hi!

Quoted 18 lines
drivers/rtc/rtc-rx8581.c +18 -0
+static int rx85x1_nvram_read(void *priv, unsigned int offset, void *val,
+			     size_t bytes)
+{
+	struct rx8581 *rx8581 = priv;
+	unsigned int tmp_val;
+	int ret;
+
+	ret = regmap_read(rx8581->regmap, RX8581_REG_RAM, &tmp_val);
+	(*(unsigned char *)val) = (unsigned char) tmp_val;
+
+	return ret;
+}
+
+static int rx85x1_nvram_write(void *priv, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	struct rx8581 *rx8581 = priv;
+	unsigned char tmp_val;
Quoted 8 lines

drivers/rtc/rtc-rx8581.c static const struct rtc_class_ops rx8581_rtc_ops = { · line 234

Quoted 5 lines
drivers/rtc/rtc-rx8581.c +5 -0
+
+	tmp_val = *((unsigned char *)val);
+	return regmap_write(rx8581->regmap, RX8581_REG_RAM,
+				(unsigned int)tmp_val);
+}

I see that 85x1 has single byte of RAM. I'd still expect return of error in case of offset != 0 or bytes != 1.

As per the discussion we had in ML. Any validation to be done at nvmem framework level.

Quoted 1 line

Probably best done in mainline first...

We need to fix this issue at nvmem frame work level. Which involves API changes. Please see the mail discussion related to this.

https://patchwork.kernel.org/patch/10723299/

May be at some point, we will have a fix for this issues.

regards,
Biju

author
#7 lore raw

PATCH 5/6 arm64: defconfig: enable RX-8581 config option

In reply to Biju Das

commit 940d1a288a598ee18afa25ee74f4ca124bddd364 upstream.

Enable support for RX-8571/RX-8581 RTC by turning on CONFIG_RTC_DRV_RX8581 as module.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 11f9f0d..8561bef 100644
@@ -546,6 +546,7 @@ CONFIG_EDAC_GHES=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MAX77686=y
 CONFIG_RTC_DRV_RK808=m
+CONFIG_RTC_DRV_RX8581=m
 CONFIG_RTC_DRV_S5M=y
 CONFIG_RTC_DRV_DS3232=y
 CONFIG_RTC_DRV_EFI=y
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH 6/6 arm64: dts: renesas: r8a774c0-cat874: add RTC support

In reply to Biju Das

commit 07e72397f722d3a522991dcba82ce2ddb8c3c6e1 upstream.

This patch adds Epson RX-8571 real time clock support.

---
 arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts +19 -0
index 4333af8..f08778e 100644
@@ -61,6 +61,19 @@
 	clock-frequency = <48000000>;
 };
 
+&i2c1 {
+	pinctrl-0 = <&i2c1_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	rtc at 32 {
+		compatible = "epson,rx8571";
+		reg = <0x32>;
+	};
+};
+
 &ohci0 {
 	dr_mode = "host";
 	status = "okay";
@@ -76,6 +89,12 @@
 };
 
 &pfc {
+
+	i2c1_pins: i2c1 {
+		groups = "i2c1_b";
+		function = "i2c1";
+	};
+
 	scif2_pins: scif2 {
 		groups = "scif2_data_a";
 		function = "scif2";
Signature · 1 line
2.7.4
#9 lore raw

cover Add RTC support

In reply to Biju Das
Quoted 7 lines · Biju Das

This patch series add RTC support for EK874 platform.

This patch series is based on linux-4.19.y-cip and all the patches in this series are cherry-picked from linux rc tree.

This patch series is depend on the below patch series
https://patchwork.kernel.org/project/cip-dev/list/?series=145931

Thanks for the series, applied, and pushed out.

Best regards,
Pavel

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/5503864b/attachment.sig>