rtc: Add Cortina Systems CS7542 calendar clock support
Subsystems (2)
v5 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.
Decode the four-digit BCD year, bound retries across second changes and retain RTCEN after programming. Leave a disabled or reset RTC alone at probe and report its time as invalid until a known time is set. The RTC core validates the decoded calendar and handles absent alarm callbacks.
Validate each BCD digit before decoding. Fill weekday and day of year from the validated date. The RTC core supplies the 1970 lower bound and the driver advertises 9999 as the upper bound.
Alarm interrupts and suspend wake are not implemented.
The three patches are the binding, driver/Kconfig/Makefile and a MAINTAINERS entry, based on v7.4-rc4 without the pending CS75xx platform or clock/pinctrl series.
Validation:
- strict source checkpatch: no errors, warnings or checks
- complete minimal ARM vmlinux and modules builds, RTC built in and modular, GCC 14.2, W=1, COMPILE_TEST=n, without the platform
- actual read/set/probe functions and core calendar validation helpers with mocked MMIO and UBSAN: 10000 BCD-year round trips from 0000 through 9999, all 256 control-byte patterns, disabled/reset rejection, probe side effects, known-time enable, future boundaries and error paths; pre-1970 core rejection is checked separately from callback decoding
On Almond+, an additional Linux 7.4-rc4 RAM-only fixture called the actual RTC callbacks under ops_lock to check the physical lower range. It bypassed core calendar validation only inside the separate test module. These six transitions passed, with raw BCDYEAR and decoded callback fields recorded:
- 0000-01-01, 00:00:00 to 00:00:01, with raw year 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 module recorded 219 checks, no failures, and verified current-UTC restoration. The outer RAM supervisor independently verified restoration before watchdog return, followed by fresh host-UTC restoration in installed OpenWrt. Firmware was not flashed. Direct pre-1970 callback reads succeeded while the unchanged core validator returned EINVAL; the transition into 1970 became core-valid.
The v3 review run had already checked disabled/reset reprobe, invalid reads, known-current-time set/enable and counting. Its separate range fixture passed 1970 and 2038 ticks, year 2000 leap day, century carries into 2100/2200/2400, non-leap 2100/2200, leap 2400, and 9999-12-31 at 23:59:58 to 23:59:59. These are targeted hardware cases. The 10000-year round trips above are software encoding checks, not a hardware sweep of every year.
---
Changes in v5:
- Reject invalid BCD digits before decoding, populate weekday and day
of year, and use the core default lower time bound.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Describe the hardware's 0000-9999 range using RTC_TIMESTAMP_BEGIN_0000; keep the core's ordinary pre-1970 calendar validation unchanged.
- Check year 0000, early-century carry/leap transitions and 1969 to 1970 through direct callbacks in a guarded RAM-only fixture.
- State the hardware calendar range explicitly in Kconfig help.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Preserve RTC enable/reset state at probe; report disabled/reset time
as invalid and initialise it only when setting a known time.
- Let the core validate calendar fields and remove redundant ALARM
feature clearing and the two noisy probe messages.
- Advertise 1970-9999 after checking the 16-bit BCD field, critical century carries, Gregorian century leap rules and the 9999 endpoint on hardware.
- Link to v2: https://patch.msgid.link/[email protected]
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 | 173 +++++++++++++++++++++ 5 files changed, 238 insertions(+)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-rtc-f0818d77fda2
Best regards,
Signature · 1 line
Fil Dunsky <[email protected]>
PATCH v5 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 v5 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.
Leave the RTC control state unchanged at probe and reject reads when it is disabled or held in reset. Enable it and clear reset when a known time is supplied through set_time. Let the RTC core validate calendar fields and handle the absence of alarm callbacks.
Describe the physical 0000-9999 calendar with RTC_TIMESTAMP_BEGIN_0000 and RTC_TIMESTAMP_END_9999. The vendor BCDYEAR register has 16 year-data bits; direct-callback RAM tests on Almond+ verified year 0000 and early century carry/leap transitions, plus 1969 to 1970, in addition to the upper-century
and 9999 endpoint tests. Core validation of normal reads/sets before 1970 is unchanged; only the separate fixture bypassed it. These are targeted hardware checks, not a sweep of every year.
Alarm interrupts and suspend wake are not supported.
Reject invalid BCD digits before decoding, populate weekday and day of year, and use the core default lower time bound.
--- drivers/rtc/Kconfig | 9 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-cs75xx.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 183 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. + The hardware's four-digit calendar covers years 0000-9999. + 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 +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v5 2/3] rtc: Add Cortina Systems CS7542 RTC driver
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] rtc: cs75xx: g2_rtc_probe() omits range_min = RTC_TIMESTAMP_BEGIN_0000 - [Medium] rtc: cs75xx…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] rtc: cs75xx: g2_rtc_probe() omits range_min = RTC_TIMESTAMP_BEGIN_0000
- [Medium] rtc: cs75xx: g2_rtc_gettime() calls rtc_valid_tm() before core validation
--
commit a8e8adc4666286ba8c3135f712792dd1734294d1
Author: Fil Dunsky <[email protected]>
rtc: Add Cortina Systems CS7542 RTC driver
This commit adds an RTC driver for the Cortina Systems CS7542 SoC with four-digit BCD year decoding and read/set calendar callbacks.
Quoted 5 lines
drivers/rtc/rtc-cs75xx.c new file +0
-0
[ ... ]
Quoted 27 lines
drivers/rtc/rtc-cs75xx.c new file +27
-0+static int g2_rtc_gettime (struct device *dev,struct rtc_time *tm) +{ +struct g2_rtc *p =dev_get_drvdata (dev); +u32 year, ctrl; +u8 sec, min, hour, day, mon; +int ret, retry; + + ctrl =g2_rtc_readb (p,G2_RTC_RTCCON ); +if (!(ctrl &G2_RTC_RTCCON_RTCEN ) || (ctrl &G2_RTC_RTCCON_CLKRST )) +return -EINVAL ; + +for (retry =0 ; retry <3 ; retry++) { + sec =g2_rtc_readb (p,G2_RTC_RTCSEC ); + min =g2_rtc_readb (p,G2_RTC_RTCMIN ); + hour =g2_rtc_readb (p,G2_RTC_RTCHOUR ); + day =g2_rtc_readb (p,G2_RTC_RTCDATE ); + mon =g2_rtc_readb (p,G2_RTC_RTCMON ); + year =g2_rtc_readl (p,G2_RTC_RTCYEAR ) &0xffff ; +if (sec ==g2_rtc_readb (p,G2_RTC_RTCSEC )) { +if (!bcd_is_valid (sec) || !bcd_is_valid (min) || + !bcd_is_valid (hour) || !bcd_is_valid (day) || + !bcd_is_valid (mon) || !bcd_is_valid (year &0xff ) || + !bcd_is_valid (year >>8 )) +return -EINVAL ; + + tm->tm_sec =bcd2bin (sec); + tm->tm_min =bcd2bin (min);
drivers/rtc/rtc-cs75xx.c line 102
Quoted 10 lines
drivers/rtc/rtc-cs75xx.c new file +10
-0+ tm->tm_hour =bcd2bin (hour); + tm->tm_mday =bcd2bin (day); + tm->tm_mon =bcd2bin (mon) -1 ; + tm->tm_year =bcd2bin (year &0xff ) + +bcd2bin (year >>8 ) *100 -1900 ; + ret =rtc_valid_tm (tm); +if (ret) +return ret; +rtc_time64_to_tm (rtc_tm_to_time64 (tm), tm); +return 0 ;
[Severity: Medium]
As reported by Alexandre Belloni on v2 [1], should g2_rtc_gettime() leave rtc_valid_tm() validation to the RTC core instead of calling it and doing a rtc_time64_to_tm(rtc_tm_to_time64(tm), tm) round-trip here?
__rtc_read_time() applies rtc_add_offset() after .read_time() returns and then calls rtc_valid_tm(tm) itself, and the core does not require .read_time callbacks to populate tm_wday or tm_yday. Validating tm inside g2_rtc_gettime() rejects pre-1970 raw hardware dates with -EINVAL before __rtc_read_time() can apply rtc_add_offset(), and also contradicts the commit message ("Let the RTC core validate calendar fields").
[ ... ]
Quoted 13 lines
drivers/rtc/rtc-cs75xx.c new file +13
-0+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); +
drivers/rtc/rtc-cs75xx.c line 154
Quoted 10 lines
drivers/rtc/rtc-cs75xx.c new file +10
-0+platform_set_drvdata (pdev, 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_max =RTC_TIMESTAMP_END_9999 ; + +return devm_rtc_register_device (p->rtc); +}
[Severity: Medium]
As reported by Alexandre Belloni on v2 [2], should g2_rtc_probe() also set p->rtc->range_min = RTC_TIMESTAMP_BEGIN_0000?
Leaving range_min at 0 causes /sys/class/rtc/rtcN/range and rtc_device_get_offset() to treat 1970-01-01 rather than 0000-01-01 as the hardware lower bound, and contradicts the third paragraph of the commit message ("Describe the physical 0000-9999 calendar with RTC_TIMESTAMP_BEGIN_0000 and RTC_TIMESTAMP_END_9999").
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v5 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:
- Patch 1: no issues found.
- Patch 2 ("rtc: Add Cortina Systems CS7542 RTC driver"): 2 potential issues (2 Medium)
- Patch 3: skipped (not reviewed).
A detailed review has been sent as a separate reply to patch 2.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]