Linux RTC
 help / color / mirror / Atom feed
* [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support
@ 2026-11-23 20:27 Fil Dunsky via B4 Relay
  2026-11-23 20:27 ` [PATCH v2 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC Fil Dunsky via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 20:27 UTC (permalink / raw)
  To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-rtc, devicetree, linux-arm-kernel, linux-kernel

Add the memory-mapped calendar clock of the CS7542, based on the GPL
vendor and OpenWrt implementation. Use an independent OF/HAS_IOMEM
Kconfig option so the driver can be reviewed without the pending
platform series.

The initial driver supports calendar reads and setting the clock in
the 2000-2099 range. It decodes the four-digit BCD year, bounds retries
across second changes and retains RTCEN after programming. The alarm
and suspend-wakeup features are deliberately not advertised.

An alarm prototype was investigated on the board, but the expected
alarm IRQ did not arrive. Time-of-day and calendar comparisons and
interrupt-mode experiments have not yet established the missing
hardware behaviour. Those experiments are retained locally and are not
included as working functionality in this series. This is a calendar
support submission, not a claim that alarms have been fixed.

The three patches are the binding, the driver/Kconfig/Makefile and a
MAINTAINERS entry. They apply to Linux v7.4-rc4 without the pending
CS75xx platform or clock/pinctrl series. 

Validation:
- binding schema, example compilation and style checks passed
- strict source checkpatch with --no-signoff: no errors/warnings/checks
- complete minimal ARM vmlinux and modules builds with both new
  drivers built in and modular, COMPILE_TEST=n, without the platform
- actual driver functions tested with mocked MMIO/regmap and UBSAN
- exact sources booted in a Linux 7.4-rc4 RAM integration kernel on
  Almond+, with platform v9, clock/pinctrl and the accepted watchdog

RTC opened, read a valid date, advanced over two seconds, accepted
setting the current time and kept counting afterwards. The alarm ioctl
was rejected, matching the advertised support scope.
The final combined RAM test recorded 16 checks with no failures and
returned to installed OpenWrt 6.18.64 through the watchdog. Both CPUs
were online. The firmware was not flashed. Earlier incomplete or
experimental alarm runs are not counted as this successful test.

---
Changes in v2:
- Place RTC_DRV_CS75XX in the on-CPU RTC section, outside the HID section.
- Keep the Makefile entry alphabetical. Driver C code is unchanged.
- Link to v1: https://patch.msgid.link/20261123-b4-cs7542-rtc-v1-0-6c53761ffa03@gmail.com

To: Fil Dunsky <filipp.dunsky@gmail.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
Cc: linux-rtc@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Fil Dunsky (3):
      dt-bindings: rtc: Add Cortina Systems CS7542 RTC
      rtc: Add Cortina Systems CS7542 RTC driver
      MAINTAINERS: Add Cortina Systems CS7542 RTC support

 .../bindings/rtc/cortina,cs7542-rtc.yaml           |  48 ++++++
 MAINTAINERS                                        |   7 +
 drivers/rtc/Kconfig                                |   9 ++
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-cs75xx.c                           | 174 +++++++++++++++++++++
 5 files changed, 239 insertions(+)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-rtc-f0818d77fda2

Best regards,
--  
Fil Dunsky <filipp.dunsky@gmail.com>



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

* [PATCH v2 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC
  2026-11-23 20:27 [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
@ 2026-11-23 20:27 ` Fil Dunsky via B4 Relay
  2026-11-23 20:27 ` [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver Fil Dunsky via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 20:27 UTC (permalink / raw)
  To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-rtc, devicetree, linux-arm-kernel, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Describe the RTC register block and its optional alarm and periodic
interrupt lines. The initial driver supports the calendar without
requiring those interrupts.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 .../bindings/rtc/cortina,cs7542-rtc.yaml           | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/Documentation/devicetree/bindings/rtc/cortina,cs7542-rtc.yaml b/Documentation/devicetree/bindings/rtc/cortina,cs7542-rtc.yaml
new file mode 100644
index 000000000..8c2cc7ec9
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/cortina,cs7542-rtc.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/cortina,cs7542-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 real-time clock
+
+maintainers:
+  - Fil Dunsky <filipp.dunsky@gmail.com>
+
+allOf:
+  - $ref: rtc.yaml#
+
+properties:
+  compatible:
+    const: cortina,cs7542-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Alarm interrupt
+      - description: Periodic interrupt
+
+  interrupt-names:
+    items:
+      - const: alarm
+      - const: periodic
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    rtc@f4920000 {
+        compatible = "cortina,cs7542-rtc";
+        reg = <0xf4920000 0x50>;
+        interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "alarm", "periodic";
+    };

-- 
2.53.0



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

* [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
  2026-11-23 20:27 [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
  2026-11-23 20:27 ` [PATCH v2 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC Fil Dunsky via B4 Relay
@ 2026-11-23 20:27 ` Fil Dunsky via B4 Relay
  2026-11-23 20:56   ` Alexandre Belloni
  2026-11-23 20:27 ` [PATCH v2 3/3] MAINTAINERS: Add Cortina Systems CS7542 RTC support Fil Dunsky via B4 Relay
  2026-11-23 20:33 ` [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support sashiko-bot
  3 siblings, 1 reply; 8+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 20:27 UTC (permalink / raw)
  To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-rtc, devicetree, linux-arm-kernel, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Adapt the vendor-derived OpenWrt calendar implementation to an OF driver
without a platform Kconfig dependency. Decode the four-digit BCD year,
retry reads across second changes and preserve RTCEN after programming.
Expose the verified 2000-2099 calendar read/set operations. Do not
advertise alarm interrupts or suspend wake until their hardware
behaviour has been established.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/rtc/Kconfig      |   9 +++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-cs75xx.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 73ec9230e..2937f637a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1463,6 +1463,15 @@ config RTC_DRV_ASM9260
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-asm9260.
 
+config RTC_DRV_CS75XX
+	tristate "Cortina Systems CS7542 RTC"
+	depends on OF && HAS_IOMEM
+	help
+	  Support the calendar clock of the Cortina Systems CS7542 SoC.
+	  Read and set dates in the 2000-2099 range.
+	  Alarm interrupts are not supported.
+	  The module will be named rtc-cs75xx.
+
 config RTC_DRV_CV1800
 	tristate "Sophgo CV1800 RTC"
 	depends on SOPHGO_CV1800_RTCSYS || COMPILE_TEST
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 46f1a0fc2..516cc6c9c 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_CADENCE)	+= rtc-cadence.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_CPCAP)	+= rtc-cpcap.o
 obj-$(CONFIG_RTC_DRV_CROS_EC)	+= rtc-cros-ec.o
+obj-$(CONFIG_RTC_DRV_CS75XX)	+= rtc-cs75xx.o
 obj-$(CONFIG_RTC_DRV_CV1800)	+= rtc-cv1800.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)	+= rtc-da9055.o
diff --git a/drivers/rtc/rtc-cs75xx.c b/drivers/rtc/rtc-cs75xx.c
new file mode 100644
index 000000000..2ba25ac04
--- /dev/null
+++ b/drivers/rtc/rtc-cs75xx.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/module.h>
+#include <linux/bits.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/io.h>
+#include <linux/of.h>
+
+#define DRV_NAME	"cs75xx-rtc"
+
+#define G2_RTC_RTCCON		0x00
+#define G2_RTC_RTCCON_STARTB	BIT(0)
+#define G2_RTC_RTCCON_RTCEN	BIT(1)
+#define G2_RTC_RTCCON_CLKRST	BIT(2)
+#define G2_RTC_RTCCON_OSCEN	BIT(3)
+
+#define G2_RTC_RTCSEC		0x24
+#define G2_RTC_RTCMIN		0x28
+#define G2_RTC_RTCHOUR		0x2c
+#define G2_RTC_RTCDATE		0x30
+#define G2_RTC_RTCDAY		0x34
+#define G2_RTC_RTCMON		0x38
+#define G2_RTC_RTCYEAR		0x3c
+struct g2_rtc {
+	void __iomem		*base;
+	struct rtc_device	*rtc;
+};
+
+static u32 g2_rtc_readl(struct g2_rtc *p, unsigned int addr)
+{
+	return readl(p->base + addr);
+}
+
+static u8 g2_rtc_readb(struct g2_rtc *p, unsigned int addr)
+{
+	return readl(p->base + addr) & 0xff;
+}
+
+static void g2_rtc_writel(struct g2_rtc *p, unsigned int addr, u32 val, u32 mask)
+{
+	u32 reg = (readl(p->base + addr) & ~mask) | (val & mask);
+
+	writel(reg, p->base + addr);
+}
+
+static void g2_rtc_write_enable(struct g2_rtc *p)
+{
+	u32 tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
+
+	g2_rtc_writel(p, G2_RTC_RTCCON,
+		      tmp | G2_RTC_RTCCON_RTCEN | G2_RTC_RTCCON_STARTB, 0xff);
+}
+
+static void g2_rtc_write_disable(struct g2_rtc *p)
+{
+	u32 tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
+
+	g2_rtc_writel(p, G2_RTC_RTCCON,
+		      tmp & ~G2_RTC_RTCCON_STARTB, 0xff);
+}
+
+static int g2_rtc_gettime(struct device *dev, struct rtc_time *tm)
+{
+	struct g2_rtc *p = dev_get_drvdata(dev);
+	u32 year, sec;
+	int retry;
+
+	for (retry = 0; retry < 3; retry++) {
+		sec = g2_rtc_readb(p, G2_RTC_RTCSEC);
+		tm->tm_min = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCMIN));
+		tm->tm_hour = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCHOUR));
+		tm->tm_mday = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCDATE));
+		tm->tm_mon = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCMON)) - 1;
+		year = g2_rtc_readl(p, G2_RTC_RTCYEAR) & 0xffff;
+		if (sec == g2_rtc_readb(p, G2_RTC_RTCSEC)) {
+			tm->tm_sec = bcd2bin(sec);
+			tm->tm_year = bcd2bin(year & 0xff) +
+				      bcd2bin(year >> 8) * 100 - 1900;
+			return rtc_valid_tm(tm);
+		}
+	}
+
+	return -EAGAIN;
+}
+
+static int g2_rtc_settime(struct device *dev, struct rtc_time *tm)
+{
+	struct g2_rtc *p = dev_get_drvdata(dev);
+	int year = tm->tm_year + 1900;
+
+	g2_rtc_write_enable(p);
+	g2_rtc_writel(p, G2_RTC_RTCSEC,  bin2bcd(tm->tm_sec), 0xffffffff);
+	g2_rtc_writel(p, G2_RTC_RTCMIN,  bin2bcd(tm->tm_min), 0xffffffff);
+	g2_rtc_writel(p, G2_RTC_RTCHOUR, bin2bcd(tm->tm_hour), 0xffffffff);
+	g2_rtc_writel(p, G2_RTC_RTCDATE, bin2bcd(tm->tm_mday), 0xffffffff);
+	g2_rtc_writel(p, G2_RTC_RTCMON,  bin2bcd(tm->tm_mon + 1), 0xffffffff);
+	g2_rtc_writel(p, G2_RTC_RTCYEAR,
+		      (bin2bcd(year / 100) << 8) | bin2bcd(year % 100), 0xffff);
+	g2_rtc_write_disable(p);
+
+	return 0;
+}
+
+static const struct rtc_class_ops g2_rtcops = {
+	.read_time		= g2_rtc_gettime,
+	.set_time		= g2_rtc_settime,
+};
+
+static void g2_rtc_enable(struct device *dev, struct g2_rtc *p)
+{
+	u32 tmp;
+
+	if ((g2_rtc_readb(p, G2_RTC_RTCCON) & G2_RTC_RTCCON_RTCEN) == 0) {
+		dev_info(dev, "rtc disabled, re-enabling\n");
+		tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
+		g2_rtc_writel(p, G2_RTC_RTCCON, tmp | G2_RTC_RTCCON_RTCEN, 0xff);
+	}
+	if (g2_rtc_readb(p, G2_RTC_RTCCON) & G2_RTC_RTCCON_CLKRST) {
+		dev_info(dev, "removing RTCCON_CLKRST\n");
+		tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
+		g2_rtc_writel(p, G2_RTC_RTCCON, tmp & ~G2_RTC_RTCCON_CLKRST, 0xff);
+	}
+}
+
+static int g2_rtc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct g2_rtc *p;
+
+	p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	p->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(p->base))
+		return PTR_ERR(p->base);
+
+	platform_set_drvdata(pdev, p);
+
+	g2_rtc_enable(dev, p);
+
+	p->rtc = devm_rtc_allocate_device(dev);
+	if (IS_ERR(p->rtc))
+		return PTR_ERR(p->rtc);
+	p->rtc->ops = &g2_rtcops;
+	p->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+	p->rtc->range_max = RTC_TIMESTAMP_END_2099;
+	/* Alarm interrupt generation has not yet been verified. */
+	clear_bit(RTC_FEATURE_ALARM, p->rtc->features);
+
+	return devm_rtc_register_device(p->rtc);
+}
+
+static const struct of_device_id cs75xx_rtc_of_match_table[] = {
+	{ .compatible = "cortina,cs7542-rtc" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, cs75xx_rtc_of_match_table);
+
+static struct platform_driver g2_rtc_driver = {
+	.probe		= g2_rtc_probe,
+	.driver		= {
+		.name	= DRV_NAME,
+		.of_match_table = cs75xx_rtc_of_match_table,
+	},
+};
+module_platform_driver(g2_rtc_driver);
+
+MODULE_DESCRIPTION("Cortina CS75xx RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:cs75xx-rtc");

-- 
2.53.0



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

* [PATCH v2 3/3] MAINTAINERS: Add Cortina Systems CS7542 RTC support
  2026-11-23 20:27 [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
  2026-11-23 20:27 ` [PATCH v2 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC Fil Dunsky via B4 Relay
  2026-11-23 20:27 ` [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver Fil Dunsky via B4 Relay
@ 2026-11-23 20:27 ` Fil Dunsky via B4 Relay
  2026-11-23 20:33 ` [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support sashiko-bot
  3 siblings, 0 replies; 8+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 20:27 UTC (permalink / raw)
  To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-rtc, devicetree, linux-arm-kernel, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Route changes to the CS7542 calendar clock driver and binding
to their subsystem mailing list and the platform maintainer.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb..e7f97fb96 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2949,6 +2949,13 @@ F:	tools/perf/tests/shell/coresight/*
 F:	tools/perf/util/cs-etm-decoder/*
 F:	tools/perf/util/cs-etm.*
 
+ARM/CORTINA SYSTEMS CS7542 RTC
+M:	Fil Dunsky <filipp.dunsky@gmail.com>
+L:	linux-rtc@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/rtc/cortina,cs7542-rtc.yaml
+F:	drivers/rtc/rtc-cs75xx.c
+
 ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
 M:	Hans Ulli Kroll <ulli.kroll@googlemail.com>
 M:	Linus Walleij <linusw@kernel.org>

-- 
2.53.0



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

* Re: [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support
  2026-11-23 20:27 [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-23 20:27 ` [PATCH v2 3/3] MAINTAINERS: Add Cortina Systems CS7542 RTC support Fil Dunsky via B4 Relay
@ 2026-11-23 20:33 ` sashiko-bot
  3 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Fil Dunsky; +Cc: linux-rtc, Alexandre Belloni

Sashiko has finished reviewing this 3-patch series:

- Patches 1 and 2: no issues found.
- Patch 3: skipped (not reviewed).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-rtc-v2-0-31ab43f2cc8e@gmail.com

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

* Re: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
  2026-11-23 20:27 ` [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver Fil Dunsky via B4 Relay
@ 2026-11-23 20:56   ` Alexandre Belloni
  2026-11-23 22:00     ` Fil Dunsky
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre Belloni @ 2026-11-23 20:56 UTC (permalink / raw)
  To: filipp.dunsky
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-rtc,
	devicetree, linux-arm-kernel, linux-kernel

On 23/11/2026 23:27:02+0300, Fil Dunsky via B4 Relay wrote:
> From: Fil Dunsky <filipp.dunsky@gmail.com>
> 
> Adapt the vendor-derived OpenWrt calendar implementation to an OF driver
> without a platform Kconfig dependency. Decode the four-digit BCD year,
> retry reads across second changes and preserve RTCEN after programming.
> Expose the verified 2000-2099 calendar read/set operations. Do not
> advertise alarm interrupts or suspend wake until their hardware
> behaviour has been established.
> 
> Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
> ---
>  drivers/rtc/Kconfig      |   9 +++
>  drivers/rtc/Makefile     |   1 +
>  drivers/rtc/rtc-cs75xx.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 184 insertions(+)
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 73ec9230e..2937f637a 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -1463,6 +1463,15 @@ config RTC_DRV_ASM9260
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rtc-asm9260.
>  
> +config RTC_DRV_CS75XX
> +	tristate "Cortina Systems CS7542 RTC"
> +	depends on OF && HAS_IOMEM
> +	help
> +	  Support the calendar clock of the Cortina Systems CS7542 SoC.
> +	  Read and set dates in the 2000-2099 range.
> +	  Alarm interrupts are not supported.
> +	  The module will be named rtc-cs75xx.
> +
>  config RTC_DRV_CV1800
>  	tristate "Sophgo CV1800 RTC"
>  	depends on SOPHGO_CV1800_RTCSYS || COMPILE_TEST
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 46f1a0fc2..516cc6c9c 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_CADENCE)	+= rtc-cadence.o
>  obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
>  obj-$(CONFIG_RTC_DRV_CPCAP)	+= rtc-cpcap.o
>  obj-$(CONFIG_RTC_DRV_CROS_EC)	+= rtc-cros-ec.o
> +obj-$(CONFIG_RTC_DRV_CS75XX)	+= rtc-cs75xx.o
>  obj-$(CONFIG_RTC_DRV_CV1800)	+= rtc-cv1800.o
>  obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
>  obj-$(CONFIG_RTC_DRV_DA9055)	+= rtc-da9055.o
> diff --git a/drivers/rtc/rtc-cs75xx.c b/drivers/rtc/rtc-cs75xx.c
> new file mode 100644
> index 000000000..2ba25ac04
> --- /dev/null
> +++ b/drivers/rtc/rtc-cs75xx.c
> @@ -0,0 +1,174 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <linux/module.h>
> +#include <linux/bits.h>
> +#include <linux/err.h>
> +#include <linux/slab.h>
> +#include <linux/platform_device.h>
> +#include <linux/rtc.h>
> +#include <linux/bcd.h>
> +#include <linux/io.h>
> +#include <linux/of.h>
> +
> +#define DRV_NAME	"cs75xx-rtc"
> +
> +#define G2_RTC_RTCCON		0x00
> +#define G2_RTC_RTCCON_STARTB	BIT(0)
> +#define G2_RTC_RTCCON_RTCEN	BIT(1)
> +#define G2_RTC_RTCCON_CLKRST	BIT(2)
> +#define G2_RTC_RTCCON_OSCEN	BIT(3)
> +
> +#define G2_RTC_RTCSEC		0x24
> +#define G2_RTC_RTCMIN		0x28
> +#define G2_RTC_RTCHOUR		0x2c
> +#define G2_RTC_RTCDATE		0x30
> +#define G2_RTC_RTCDAY		0x34
> +#define G2_RTC_RTCMON		0x38
> +#define G2_RTC_RTCYEAR		0x3c
> +struct g2_rtc {
> +	void __iomem		*base;
> +	struct rtc_device	*rtc;
> +};
> +
> +static u32 g2_rtc_readl(struct g2_rtc *p, unsigned int addr)
> +{
> +	return readl(p->base + addr);
> +}
> +
> +static u8 g2_rtc_readb(struct g2_rtc *p, unsigned int addr)
> +{
> +	return readl(p->base + addr) & 0xff;
> +}
> +
> +static void g2_rtc_writel(struct g2_rtc *p, unsigned int addr, u32 val, u32 mask)
> +{
> +	u32 reg = (readl(p->base + addr) & ~mask) | (val & mask);
> +
> +	writel(reg, p->base + addr);
> +}
> +
> +static void g2_rtc_write_enable(struct g2_rtc *p)
> +{
> +	u32 tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
> +
> +	g2_rtc_writel(p, G2_RTC_RTCCON,
> +		      tmp | G2_RTC_RTCCON_RTCEN | G2_RTC_RTCCON_STARTB, 0xff);
> +}
> +
> +static void g2_rtc_write_disable(struct g2_rtc *p)
> +{
> +	u32 tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
> +
> +	g2_rtc_writel(p, G2_RTC_RTCCON,
> +		      tmp & ~G2_RTC_RTCCON_STARTB, 0xff);
> +}
> +
> +static int g2_rtc_gettime(struct device *dev, struct rtc_time *tm)
> +{
> +	struct g2_rtc *p = dev_get_drvdata(dev);
> +	u32 year, sec;
> +	int retry;
> +
> +	for (retry = 0; retry < 3; retry++) {
> +		sec = g2_rtc_readb(p, G2_RTC_RTCSEC);
> +		tm->tm_min = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCMIN));
> +		tm->tm_hour = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCHOUR));
> +		tm->tm_mday = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCDATE));
> +		tm->tm_mon = bcd2bin(g2_rtc_readb(p, G2_RTC_RTCMON)) - 1;
> +		year = g2_rtc_readl(p, G2_RTC_RTCYEAR) & 0xffff;
> +		if (sec == g2_rtc_readb(p, G2_RTC_RTCSEC)) {
> +			tm->tm_sec = bcd2bin(sec);
> +			tm->tm_year = bcd2bin(year & 0xff) +
> +				      bcd2bin(year >> 8) * 100 - 1900;
> +			return rtc_valid_tm(tm);

Calling rtc_valid_tm() is not necessary because the core is validating
the tm later on.

> +		}
> +	}
> +
> +	return -EAGAIN;
> +}
> +
> +static int g2_rtc_settime(struct device *dev, struct rtc_time *tm)
> +{
> +	struct g2_rtc *p = dev_get_drvdata(dev);
> +	int year = tm->tm_year + 1900;
> +
> +	g2_rtc_write_enable(p);
> +	g2_rtc_writel(p, G2_RTC_RTCSEC,  bin2bcd(tm->tm_sec), 0xffffffff);
> +	g2_rtc_writel(p, G2_RTC_RTCMIN,  bin2bcd(tm->tm_min), 0xffffffff);
> +	g2_rtc_writel(p, G2_RTC_RTCHOUR, bin2bcd(tm->tm_hour), 0xffffffff);
> +	g2_rtc_writel(p, G2_RTC_RTCDATE, bin2bcd(tm->tm_mday), 0xffffffff);
> +	g2_rtc_writel(p, G2_RTC_RTCMON,  bin2bcd(tm->tm_mon + 1), 0xffffffff);
> +	g2_rtc_writel(p, G2_RTC_RTCYEAR,
> +		      (bin2bcd(year / 100) << 8) | bin2bcd(year % 100), 0xffff);
> +	g2_rtc_write_disable(p);
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops g2_rtcops = {
> +	.read_time		= g2_rtc_gettime,
> +	.set_time		= g2_rtc_settime,
> +};
> +
> +static void g2_rtc_enable(struct device *dev, struct g2_rtc *p)
> +{
> +	u32 tmp;
> +
> +	if ((g2_rtc_readb(p, G2_RTC_RTCCON) & G2_RTC_RTCCON_RTCEN) == 0) {
> +		dev_info(dev, "rtc disabled, re-enabling\n");

This is too verbose.

> +		tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
> +		g2_rtc_writel(p, G2_RTC_RTCCON, tmp | G2_RTC_RTCCON_RTCEN, 0xff);
> +	}
> +	if (g2_rtc_readb(p, G2_RTC_RTCCON) & G2_RTC_RTCCON_CLKRST) {
> +		dev_info(dev, "removing RTCCON_CLKRST\n");

Ditto.

> +		tmp = g2_rtc_readb(p, G2_RTC_RTCCON);
> +		g2_rtc_writel(p, G2_RTC_RTCCON, tmp & ~G2_RTC_RTCCON_CLKRST, 0xff);
> +	}
> +}
> +
> +static int g2_rtc_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct g2_rtc *p;
> +
> +	p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
> +	if (!p)
> +		return -ENOMEM;
> +
> +	p->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(p->base))
> +		return PTR_ERR(p->base);
> +
> +	platform_set_drvdata(pdev, p);
> +
> +	g2_rtc_enable(dev, p);
> +

No, don't unconditionally enable the RTC, you have to enable it once you
know the time is know (that is, in .set_time). You then need to return
-EINVAL from .read_time when the time is know to be invalid.

> +	p->rtc = devm_rtc_allocate_device(dev);
> +	if (IS_ERR(p->rtc))
> +		return PTR_ERR(p->rtc);
> +	p->rtc->ops = &g2_rtcops;
> +	p->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> +	p->rtc->range_max = RTC_TIMESTAMP_END_2099;

Doesn't the RTC support a larger range, there are century bits. Does it
consider 2100 to be a leap year?

This can be checked with
https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c


> +	/* Alarm interrupt generation has not yet been verified. */
> +	clear_bit(RTC_FEATURE_ALARM, p->rtc->features);

Not necessary as the alarm callbacks are not implemented.


-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
  2026-11-23 20:56   ` Alexandre Belloni
@ 2026-11-23 22:00     ` Fil Dunsky
  2026-11-23 22:08       ` Alexandre Belloni
  0 siblings, 1 reply; 8+ messages in thread
From: Fil Dunsky @ 2026-11-23 22:00 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-rtc,
	devicetree, linux-arm-kernel, linux-kernel

Thanks for the review. I have sent v3:

https://lore.kernel.org/all/20261124-b4-cs7542-rtc-v3-0-53902bfbe0ae@gmail.com/

Probe now leaves the enable/reset state alone. read_time returns EINVAL
when RTCEN is clear or CLKRST is set, and only set_time enables the clock
and clears its reset state after programming a known time. I removed
the redundant rtc_valid_tm call, the two probe messages and the ALARM
feature clearing.

I also checked the year field and the calendar on Almond+. The vendor
register definition gives BCDYEAR bits 15:0 to year data, with bits 31:16
reserved. Using a separate RAM-only range fixture, the hardware passed
2099 to 2100, February 28 to March 1 in both 2100 and 2200, and February
28 to February 29 in 2400. Century carries into 2200 and 2400 passed too.
The 1970 and 2038 first-second/boundary checks, year 2000 leap day, and
9999-12-31 23:59:58 to 23:59:59 also passed. I therefore changed the
advertised range to 1970-9999. These are specific boundary tests, not a
hardware sweep of every year.

An exact-driver RAM run separately checked reprobe with RTCEN disabled
and CLKRST set: probe preserved control, reads returned EINVAL, and
setting current UTC enabled the RTC and resumed counting. Each run
restored current UTC before returning to installed OpenWrt, then I
verified restoration again from fresh host UTC. Firmware was not flashed.
Full independent ARM built-in/module builds and source tests passed.

Thanks,
Fil

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

* Re: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
  2026-11-23 22:00     ` Fil Dunsky
@ 2026-11-23 22:08       ` Alexandre Belloni
  0 siblings, 0 replies; 8+ messages in thread
From: Alexandre Belloni @ 2026-11-23 22:08 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-rtc,
	devicetree, linux-arm-kernel, linux-kernel

On 24/11/2026 01:00:59+0300, Fil Dunsky wrote:
> Thanks for the review. I have sent v3:
> 
> https://lore.kernel.org/all/20261124-b4-cs7542-rtc-v3-0-53902bfbe0ae@gmail.com/
> 
> Probe now leaves the enable/reset state alone. read_time returns EINVAL
> when RTCEN is clear or CLKRST is set, and only set_time enables the clock
> and clears its reset state after programming a known time. I removed
> the redundant rtc_valid_tm call, the two probe messages and the ALARM
> feature clearing.
> 
> I also checked the year field and the calendar on Almond+. The vendor
> register definition gives BCDYEAR bits 15:0 to year data, with bits 31:16
> reserved. Using a separate RAM-only range fixture, the hardware passed
> 2099 to 2100, February 28 to March 1 in both 2100 and 2200, and February
> 28 to February 29 in 2400. Century carries into 2200 and 2400 passed too.
> The 1970 and 2038 first-second/boundary checks, year 2000 leap day, and
> 9999-12-31 23:59:58 to 23:59:59 also passed. I therefore changed the
> advertised range to 1970-9999. These are specific boundary tests, not a
> hardware sweep of every year.

So why not 0 to 9999?

> 
> An exact-driver RAM run separately checked reprobe with RTCEN disabled
> and CLKRST set: probe preserved control, reads returned EINVAL, and
> setting current UTC enabled the RTC and resumed counting. Each run
> restored current UTC before returning to installed OpenWrt, then I
> verified restoration again from fresh host UTC. Firmware was not flashed.
> Full independent ARM built-in/module builds and source tests passed.
> 
> Thanks,
> Fil

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2026-11-23 22:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 20:27 [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
2026-11-23 20:27 ` [PATCH v2 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC Fil Dunsky via B4 Relay
2026-11-23 20:27 ` [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver Fil Dunsky via B4 Relay
2026-11-23 20:56   ` Alexandre Belloni
2026-11-23 22:00     ` Fil Dunsky
2026-11-23 22:08       ` Alexandre Belloni
2026-11-23 20:27 ` [PATCH v2 3/3] MAINTAINERS: Add Cortina Systems CS7542 RTC support Fil Dunsky via B4 Relay
2026-11-23 20:33 ` [PATCH v2 0/3] rtc: Add Cortina Systems CS7542 calendar clock support sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox