rtc: Add Cortina Systems CS7542 calendar clock support
Subsystems (2)
v2 cover rtc: Add Cortina Systems CS7542 calendar clock support
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/[email protected]
To: Fil Dunsky <[email protected]>
To: Alexandre Belloni <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
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,
Signature · 1 line
Fil Dunsky <[email protected]>
PATCH v2 1/3 dt-bindings: rtc: Add Cortina Systems CS7542 RTC
Describe the RTC register block and its optional alarm and periodic interrupt lines. The initial driver supports the calendar without requiring those interrupts.
--- .../bindings/rtc/cortina,cs7542-rtc.yaml | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+)
Documentation/devicetree/bindings/rtc/cortina,cs7542-rtc.yaml new file +48 -0
@@ -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 <[email protected]> + +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"; + };
Signature · 1 line
2.53.0
PATCH v2 2/3 rtc: Add Cortina Systems CS7542 RTC driver
In reply to Fil DunskyAdapt 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.
--- drivers/rtc/Kconfig | 9 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-cs75xx.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+)
drivers/rtc/Kconfig +9 -0
@@ -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
drivers/rtc/Makefile +1 -0
@@ -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
drivers/rtc/rtc-cs75xx.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.53.0
Alexandre Belloni
maintainerRe: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
Quoted 126 lines · On 23/11/2026 23:27:02+0300, Fil Dunsky via B4 Relay wrote:
From: Fil Dunsky <[email protected]>
Adapt the vendor-derived OpenWrt calendar implementation to an OF driver without a platform
Kconfigdependency. 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 <[email protected]>--- drivers/rtc/Kconfig | 9 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-cs75xx.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+)drivers/rtc/Kconfig +9
-0@@ -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_TESTdrivers/rtc/Makefile +1
-0@@ -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.odrivers/rtc/rtc-cs75xx.c new file +72
-0@@ -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 );
drivers/rtc/rtc-cs75xx.c line 82
Quoted 10 lines
drivers/rtc/rtc-cs75xx.c new file +10
-0+ 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.
Quoted 25 lines
drivers/rtc/rtc-cs75xx.c new file +25
-0+ } + } + +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 = {
drivers/rtc/rtc-cs75xx.c line 117
Quoted 10 lines
drivers/rtc/rtc-cs75xx.c new file +10
-0+ .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.
drivers/rtc/rtc-cs75xx.c line 122
Quoted 5 lines
drivers/rtc/rtc-cs75xx.c new file +5
-0+ 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.
Quoted 12 lines
drivers/rtc/rtc-cs75xx.c new file +12
-0+ 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)
drivers/rtc/rtc-cs75xx.c line 144
Quoted 10 lines
drivers/rtc/rtc-cs75xx.c new file +10
-0+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.
drivers/rtc/rtc-cs75xx.c line 150
Quoted 6 lines
drivers/rtc/rtc-cs75xx.c new file +6
-0+ 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
drivers/rtc/rtc-cs75xx.c line 152
Quoted 2 lines
drivers/rtc/rtc-cs75xx.c new file +2
-0+/* 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.
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
Thanks for the review. I have sent v3:
https://lore.kernel.org/all/[email protected]/
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
Alexandre Belloni
maintainerRe: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
Quoted 16 lines · Fil Dunsky
Thanks for the review. I have sent v3:
https://lore.kernel.org/all/[email protected]/
Probe now leaves the enable/reset state alone.
read_timereturns EINVAL when RTCEN is clear or CLKRST is set, and onlyset_timeenables the clock and clears its reset state after programming a known time. I removed the redundantrtc_valid_tmcall, 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
Quoted 3 lines
9999-12-31 23:59:58 to 23:59:59 also passed. I therefore changed theadvertised range to 1970-9999. These are specific boundary tests, not a hardware sweep of every year.
So why not 0 to 9999?
Quoted 10 lines
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
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v2 2/3] rtc: Add Cortina Systems CS7542 RTC driver
You are right: I used the core's calendar-validation boundary for the minimum, but range_min should describe the physical hardware calendar and its offset handling.
I checked the lower range on Almond+ with a separate Linux 7.4-rc4 RAM fixture calling the driver's set_time/read_time callbacks under ops_lock. The normal RTC core rejects pre-1970 dates, so the bypass was confined to that test module. These six cases passed:
- 0000-01-01, 00:00:00 to 00:00:01, with raw BCDYEAR=0
- 0000-02-28 to February 29
- 0099-12-31 to 0100-01-01
- 0100-02-28 to March 1
- 0400-02-28 to February 29
- 1969-12-31 to 1970-01-01
The direct callbacks succeeded for the low years while the unchanged core validator returned EINVAL; the 1970 transition became core-valid. The module recorded 219 checks with no failures and restored current UTC. The RAM supervisor independently restored UTC before watchdog return, and fresh host UTC was verified again in installed OpenWrt. No firmware was flashed.
V4 uses RTC_TIMESTAMP_BEGIN_0000 through RTC_TIMESTAMP_END_9999. Its Kconfig help explicitly describes the hardware's four-digit calendar; ordinary core calendar validation is unchanged. The source tests cover all 10000 BCD-year round trips, and the ARM built-in/module builds passed. The hardware evidence consists of the boundary cases above plus the previous upper-century/9999 tests, not a hardware sweep of every year.
V4 is posted here:
https://lore.kernel.org/all/[email protected]/
Thanks,
Fil
PATCH v2 3/3 MAINTAINERS: Add Cortina Systems CS7542 RTC support
In reply to Fil DunskyRoute changes to the CS7542 calendar clock driver and binding to their subsystem mailing list and the platform maintainer.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -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 <[email protected]> +L: [email protected] +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 <[email protected]> M: Linus Walleij <[email protected]>
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has finished reviewing this 3-patch series:
Sashiko has finished reviewing this 3-patch series:
- Patches 1 and 2: no issues found.
- Patch 3: skipped (not reviewed).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]