* [PATCH v5 0/2] Add Realtek System Timer
@ 2025-11-26 6:01 Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Hao-Wen Ting @ 2025-11-26 6:01 UTC (permalink / raw)
To: daniel.lezcano, tglx
Cc: jinn.cheng, edwardwu, phelic, shawn.huang724, haowen.ting,
cy.huang, james.tai, stanley_chang, cylee12, phinex, conor+dt,
krzk+dt, robh, devicetree, linux-kernel
Changes v5:
PATCH 1/2
- Drop redundant description markers in binding documentation.
- Add "Reviewed-by" tag
PATCH 2/2
- Add "Acked-by" tag
---
Changes v4:
PATCH 1/2
- Adjust compatible property description to match actual DTS and validate
it with dt_binding_check.
- Refine binding documentation descriptions.
PATCH 2/2
- Reorder variable declarations.
- Remove debug prints.
- Eliminate unnecessary line breaks.
- Switch to set_next_event() callback instead of set_next_ktime().
- Remove operations that caused build error.
- Rename the struct `timer_of` instance variable for clarity.
- Tabularize struct initializers.
- Refine descriptions.
---
Changes v3:
PATCH 1/2
- Rename binding documentation to match compatible string.
- Drop redundant "binding" from commit subject.
- Add example node and description for realtek,rtd1635-systimer.
PATCH 2/2
- Add Kconfig dependency: ARCH_REALTEK || COMPILE_TEST.
---
Changes v2:
PATCH 1/2
- Add full name 'system timer' to description.
- Remove redundant commit messages.
- Clarify compatible strings for specific verified SoCs.
- Remove redundant reg and interrupts description sentences.
- Use generic node name in example.
PATCH 2/2
- Correct MAINTAINERS to alphabetical order.
- Update Kconfig: switch dependency to ARM/ARM64.
- Remove redundant pr_info output.
---
This patch series adds support for the Realtek System Timer, a 64-bit counter
that serves as a clock event device on Realtek SoCs.
Technical details:
- Implements a 64-bit timer operating at 1MHz fixed frequency.
- Supports oneshot mode and tick broadcast functionality.
- Remains active during CPU power-down states.
Testing:
- Functionality verified for tick broadcast on both RTD1625 and RTD1635 SoCs.
- Confirmed binding documentation passes yamllint, dt_binding_check, and dtbs_check.
- Driver successfully built under COMPILE_TEST.
Patch organization:
Patch 1/2: Device Tree binding documentation
Patch 2/2: Clocksource driver implementation
Best regards,
Hao-Wen Ting
Hao-Wen Ting (2):
dt-bindings: timer: Add Realtek SYSTIMER
clocksource: Add Realtek system timer driver
.../timer/realtek,rtd1625-systimer.yaml | 47 ++++++
MAINTAINERS | 5 +
drivers/clocksource/Kconfig | 11 ++
drivers/clocksource/Makefile | 1 +
drivers/clocksource/timer-realtek.c | 150 ++++++++++++++++++
5 files changed, 214 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
create mode 100644 drivers/clocksource/timer-realtek.c
base-commit: 948b99877bf5a1cd58bee930e455b7574daba5c3
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER
2025-11-26 6:01 [PATCH v5 0/2] Add Realtek System Timer Hao-Wen Ting
@ 2025-11-26 6:01 ` Hao-Wen Ting
2025-11-26 8:43 ` Krzysztof Kozlowski
2025-11-26 14:40 ` [tip: timers/clocksource] " tip-bot2 for Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 2/2] clocksource: Add Realtek system timer driver Hao-Wen Ting
2025-11-26 10:26 ` [PATCH v5 0/2] Add Realtek System Timer Daniel Lezcano
2 siblings, 2 replies; 7+ messages in thread
From: Hao-Wen Ting @ 2025-11-26 6:01 UTC (permalink / raw)
To: daniel.lezcano, tglx
Cc: jinn.cheng, edwardwu, phelic, shawn.huang724, haowen.ting,
cy.huang, james.tai, stanley_chang, cylee12, phinex, conor+dt,
krzk+dt, robh, devicetree, linux-kernel, Krzysztof Kozlowski
The Realtek SYSTIMER (System Timer) is a 64-bit global hardware counter
operating at a fixed 1MHz frequency. Thanks to its compare match
interrupt capability, the timer natively supports oneshot mode for tick
broadcast functionality.
Signed-off-by: Hao-Wen Ting <haowen.ting@realtek.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
---
.../timer/realtek,rtd1625-systimer.yaml | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
diff --git a/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml b/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
new file mode 100644
index 000000000000..e08d3d2d306b
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/realtek,rtd1625-systimer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek System Timer
+
+maintainers:
+ - Hao-Wen Ting <haowen.ting@realtek.com>
+
+description:
+ The Realtek SYSTIMER (System Timer) is a 64-bit global hardware counter operating
+ at a fixed 1MHz frequency. Thanks to its compare match interrupt capability,
+ the timer natively supports oneshot mode for tick broadcast functionality.
+
+properties:
+ compatible:
+ oneOf:
+ - const: realtek,rtd1625-systimer
+ - items:
+ - const: realtek,rtd1635-systimer
+ - const: realtek,rtd1625-systimer
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+ - interrupts
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ timer@89420 {
+ compatible = "realtek,rtd1635-systimer",
+ "realtek,rtd1625-systimer";
+ reg = <0x89420 0x18>;
+ interrupts = <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 2/2] clocksource: Add Realtek system timer driver
2025-11-26 6:01 [PATCH v5 0/2] Add Realtek System Timer Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
@ 2025-11-26 6:01 ` Hao-Wen Ting
2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers: " tip-bot2 for Hao-Wen Ting
2025-11-26 10:26 ` [PATCH v5 0/2] Add Realtek System Timer Daniel Lezcano
2 siblings, 1 reply; 7+ messages in thread
From: Hao-Wen Ting @ 2025-11-26 6:01 UTC (permalink / raw)
To: daniel.lezcano, tglx
Cc: jinn.cheng, edwardwu, phelic, shawn.huang724, haowen.ting,
cy.huang, james.tai, stanley_chang, cylee12, phinex, conor+dt,
krzk+dt, robh, devicetree, linux-kernel
Add a system timer driver for Realtek SoCs.
This driver registers the 1 MHz global hardware counter on Realtek
platforms as a clock event device. Since this hardware counter starts
counting automatically after SoC power-on, no clock initialization is
required. Because the counter does not stop or get affected by CPU power
down, and it supports oneshot mode, it is typically used as a tick
broadcast timer.
Signed-off-by: Hao-Wen Ting <haowen.ting@realtek.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
---
MAINTAINERS | 5 +
drivers/clocksource/Kconfig | 11 ++
drivers/clocksource/Makefile | 1 +
drivers/clocksource/timer-realtek.c | 150 ++++++++++++++++++++++++++++
4 files changed, 167 insertions(+)
create mode 100644 drivers/clocksource/timer-realtek.c
diff --git a/MAINTAINERS b/MAINTAINERS
index c7a116b795d5..90f511bb4982 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21670,6 +21670,11 @@ S: Maintained
F: Documentation/devicetree/bindings/spi/realtek,rtl9301-snand.yaml
F: drivers/spi/spi-realtek-rtl-snand.c
+REALTEK SYSTIMER DRIVER
+M: Hao-Wen Ting <haowen.ting@realtek.com>
+S: Maintained
+F: drivers/clocksource/timer-realtek.c
+
REALTEK WIRELESS DRIVER (rtlwifi family)
M: Ping-Ke Shih <pkshih@realtek.com>
L: linux-wireless@vger.kernel.org
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index ffcd23668763..aa59e5b13351 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -782,4 +782,15 @@ config NXP_STM_TIMER
Enables the support for NXP System Timer Module found in the
s32g NXP platform series.
+config RTK_SYSTIMER
+ bool "Realtek SYSTIMER support"
+ depends on ARM || ARM64
+ depends on ARCH_REALTEK || COMPILE_TEST
+ select TIMER_OF
+ help
+ This option enables the driver that registers the global 1 MHz hardware
+ counter as a clock event device on Realtek SoCs. Make sure to enable
+ this option only when building for a Realtek platform or for compilation
+ testing.
+
endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index ec4452ee958f..b46376af6b49 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -95,3 +95,4 @@ obj-$(CONFIG_CLKSRC_LOONGSON1_PWM) += timer-loongson1-pwm.o
obj-$(CONFIG_EP93XX_TIMER) += timer-ep93xx.o
obj-$(CONFIG_RALINK_TIMER) += timer-ralink.o
obj-$(CONFIG_NXP_STM_TIMER) += timer-nxp-stm.o
+obj-$(CONFIG_RTK_SYSTIMER) += timer-realtek.o
diff --git a/drivers/clocksource/timer-realtek.c b/drivers/clocksource/timer-realtek.c
new file mode 100644
index 000000000000..4f0439de9939
--- /dev/null
+++ b/drivers/clocksource/timer-realtek.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2025 Realtek Semiconductor Corp.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/irqflags.h>
+#include <linux/interrupt.h>
+#include "timer-of.h"
+
+#define ENBL 1
+#define DSBL 0
+
+#define SYSTIMER_RATE 1000000
+#define SYSTIMER_MIN_DELTA 0x64
+#define SYSTIMER_MAX_DELTA ULONG_MAX
+
+/* SYSTIMER Register Offset (RTK Internal Use) */
+#define TS_LW_OFST 0x0
+#define TS_HW_OFST 0x4
+#define TS_CMP_VAL_LW_OFST 0x8
+#define TS_CMP_VAL_HW_OFST 0xC
+#define TS_CMP_CTRL_OFST 0x10
+#define TS_CMP_STAT_OFST 0x14
+
+/* SYSTIMER CMP CTRL REG Mask */
+#define TS_CMP_EN_MASK 0x1
+#define TS_WR_EN0_MASK 0x2
+
+static void __iomem *systimer_base;
+
+static u64 rtk_ts64_read(void)
+{
+ u32 low, high;
+ u64 ts;
+
+ /* Caution: Read LSB word (TS_LW_OFST) first then MSB (TS_HW_OFST) */
+ low = readl(systimer_base + TS_LW_OFST);
+ high = readl(systimer_base + TS_HW_OFST);
+ ts = ((u64)high << 32) | low;
+
+ return ts;
+}
+
+static void rtk_cmp_value_write(u64 value)
+{
+ u32 high, low;
+
+ low = value & 0xFFFFFFFF;
+ high = value >> 32;
+
+ writel(high, systimer_base + TS_CMP_VAL_HW_OFST);
+ writel(low, systimer_base + TS_CMP_VAL_LW_OFST);
+}
+
+static inline void rtk_cmp_en_write(bool cmp_en)
+{
+ u32 val;
+
+ val = TS_WR_EN0_MASK;
+ if (cmp_en == ENBL)
+ val |= TS_CMP_EN_MASK;
+
+ writel(val, systimer_base + TS_CMP_CTRL_OFST);
+}
+
+static int rtk_syst_clkevt_next_event(unsigned long cycles, struct clock_event_device *clkevt)
+{
+ u64 cmp_val;
+
+ rtk_cmp_en_write(DSBL);
+ cmp_val = rtk_ts64_read();
+
+ /* Set CMP value to current timestamp plus delta_us */
+ rtk_cmp_value_write(cmp_val + cycles);
+ rtk_cmp_en_write(ENBL);
+ return 0;
+}
+
+static irqreturn_t rtk_ts_match_intr_handler(int irq, void *dev_id)
+{
+ struct clock_event_device *clkevt = dev_id;
+ void __iomem *reg_base;
+ u32 val;
+
+ /* Disable TS CMP Match */
+ rtk_cmp_en_write(DSBL);
+
+ /* Clear TS CMP INTR */
+ reg_base = systimer_base + TS_CMP_STAT_OFST;
+ val = readl(reg_base) & TS_CMP_EN_MASK;
+ writel(val | TS_CMP_EN_MASK, reg_base);
+ clkevt->event_handler(clkevt);
+
+ return IRQ_HANDLED;
+}
+
+static int rtk_syst_shutdown(struct clock_event_device *clkevt)
+{
+ void __iomem *reg_base;
+ u64 cmp_val = 0;
+
+ /* Disable TS CMP Match */
+ rtk_cmp_en_write(DSBL);
+ /* Set compare value to 0 */
+ rtk_cmp_value_write(cmp_val);
+
+ /* Clear TS CMP INTR */
+ reg_base = systimer_base + TS_CMP_STAT_OFST;
+ writel(TS_CMP_EN_MASK, reg_base);
+ return 0;
+}
+
+static struct timer_of rtk_timer_to = {
+ .flags = TIMER_OF_IRQ | TIMER_OF_BASE,
+
+ .clkevt = {
+ .name = "rtk-clkevt",
+ .rating = 300,
+ .cpumask = cpu_possible_mask,
+ .features = CLOCK_EVT_FEAT_DYNIRQ |
+ CLOCK_EVT_FEAT_ONESHOT,
+ .set_next_event = rtk_syst_clkevt_next_event,
+ .set_state_oneshot = rtk_syst_shutdown,
+ .set_state_shutdown = rtk_syst_shutdown,
+ },
+
+ .of_irq = {
+ .flags = IRQF_TIMER | IRQF_IRQPOLL,
+ .handler = rtk_ts_match_intr_handler,
+ },
+};
+
+static int __init rtk_systimer_init(struct device_node *node)
+{
+ int ret;
+
+ ret = timer_of_init(node, &rtk_timer_to);
+ if (ret)
+ return ret;
+
+ systimer_base = timer_of_base(&rtk_timer_to);
+ clockevents_config_and_register(&rtk_timer_to.clkevt, SYSTIMER_RATE,
+ SYSTIMER_MIN_DELTA, SYSTIMER_MAX_DELTA);
+
+ return 0;
+}
+
+TIMER_OF_DECLARE(rtk_systimer, "realtek,rtd1625-systimer", rtk_systimer_init);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
@ 2025-11-26 8:43 ` Krzysztof Kozlowski
2025-11-26 14:40 ` [tip: timers/clocksource] " tip-bot2 for Hao-Wen Ting
1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 8:43 UTC (permalink / raw)
To: Hao-Wen Ting
Cc: daniel.lezcano, tglx, jinn.cheng, edwardwu, phelic,
shawn.huang724, cy.huang, james.tai, stanley_chang, cylee12,
phinex, conor+dt, krzk+dt, robh, devicetree, linux-kernel
On Wed, Nov 26, 2025 at 02:01:09PM +0800, Hao-Wen Ting wrote:
> The Realtek SYSTIMER (System Timer) is a 64-bit global hardware counter
> operating at a fixed 1MHz frequency. Thanks to its compare match
> interrupt capability, the timer natively supports oneshot mode for tick
> broadcast functionality.
>
> Signed-off-by: Hao-Wen Ting <haowen.ting@realtek.com>
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---
> .../timer/realtek,rtd1625-systimer.yaml | 47 +++++++++++++++++++
I received THREE same emails from you. Please read the output of
commands you run, e.g. when testing git send-email.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v5 0/2] Add Realtek System Timer
2025-11-26 6:01 [PATCH v5 0/2] Add Realtek System Timer Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 2/2] clocksource: Add Realtek system timer driver Hao-Wen Ting
@ 2025-11-26 10:26 ` Daniel Lezcano
2 siblings, 0 replies; 7+ messages in thread
From: Daniel Lezcano @ 2025-11-26 10:26 UTC (permalink / raw)
To: Hao-Wen Ting, tglx
Cc: jinn.cheng, edwardwu, phelic, shawn.huang724, cy.huang, james.tai,
stanley_chang, cylee12, phinex, conor+dt, krzk+dt, robh,
devicetree, linux-kernel
On 11/26/25 07:01, Hao-Wen Ting wrote:
> Changes v5:
> PATCH 1/2
> - Drop redundant description markers in binding documentation.
> - Add "Reviewed-by" tag
>
> PATCH 2/2
> - Add "Acked-by" tag
> ---
Applied, thanks
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: timers/clocksource] clocksource/drivers: Add Realtek system timer driver
2025-11-26 6:01 ` [PATCH v5 2/2] clocksource: Add Realtek system timer driver Hao-Wen Ting
@ 2025-11-26 14:40 ` tip-bot2 for Hao-Wen Ting
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Hao-Wen Ting @ 2025-11-26 14:40 UTC (permalink / raw)
To: linux-tip-commits
Cc: Hao-Wen Ting, Daniel Lezcano, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: d1780dce9575072303b9c574614b72b5c8c5c44c
Gitweb: https://git.kernel.org/tip/d1780dce9575072303b9c574614b72b5c8c5c44c
Author: Hao-Wen Ting <haowen.ting@realtek.com>
AuthorDate: Wed, 26 Nov 2025 14:01:10 +08:00
Committer: Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Wed, 26 Nov 2025 11:25:15 +01:00
clocksource/drivers: Add Realtek system timer driver
Add a system timer driver for Realtek SoCs.
This driver registers the 1 MHz global hardware counter on Realtek
platforms as a clock event device. Since this hardware counter starts
counting automatically after SoC power-on, no clock initialization is
required. Because the counter does not stop or get affected by CPU power
down, and it supports oneshot mode, it is typically used as a tick
broadcast timer.
Signed-off-by: Hao-Wen Ting <haowen.ting@realtek.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251126060110.198330-3-haowen.ting@realtek.com
---
MAINTAINERS | 5 +-
drivers/clocksource/Kconfig | 11 ++-
drivers/clocksource/Makefile | 1 +-
drivers/clocksource/timer-realtek.c | 150 +++++++++++++++++++++++++++-
4 files changed, 167 insertions(+)
create mode 100644 drivers/clocksource/timer-realtek.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 3da2c26..b72b987 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21669,6 +21669,11 @@ S: Maintained
F: Documentation/devicetree/bindings/spi/realtek,rtl9301-snand.yaml
F: drivers/spi/spi-realtek-rtl-snand.c
+REALTEK SYSTIMER DRIVER
+M: Hao-Wen Ting <haowen.ting@realtek.com>
+S: Maintained
+F: drivers/clocksource/timer-realtek.c
+
REALTEK WIRELESS DRIVER (rtlwifi family)
M: Ping-Ke Shih <pkshih@realtek.com>
L: linux-wireless@vger.kernel.org
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index ffcd236..aa59e5b 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -782,4 +782,15 @@ config NXP_STM_TIMER
Enables the support for NXP System Timer Module found in the
s32g NXP platform series.
+config RTK_SYSTIMER
+ bool "Realtek SYSTIMER support"
+ depends on ARM || ARM64
+ depends on ARCH_REALTEK || COMPILE_TEST
+ select TIMER_OF
+ help
+ This option enables the driver that registers the global 1 MHz hardware
+ counter as a clock event device on Realtek SoCs. Make sure to enable
+ this option only when building for a Realtek platform or for compilation
+ testing.
+
endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index ec4452e..b46376a 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -95,3 +95,4 @@ obj-$(CONFIG_CLKSRC_LOONGSON1_PWM) += timer-loongson1-pwm.o
obj-$(CONFIG_EP93XX_TIMER) += timer-ep93xx.o
obj-$(CONFIG_RALINK_TIMER) += timer-ralink.o
obj-$(CONFIG_NXP_STM_TIMER) += timer-nxp-stm.o
+obj-$(CONFIG_RTK_SYSTIMER) += timer-realtek.o
diff --git a/drivers/clocksource/timer-realtek.c b/drivers/clocksource/timer-realtek.c
new file mode 100644
index 0000000..4f0439d
--- /dev/null
+++ b/drivers/clocksource/timer-realtek.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2025 Realtek Semiconductor Corp.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/irqflags.h>
+#include <linux/interrupt.h>
+#include "timer-of.h"
+
+#define ENBL 1
+#define DSBL 0
+
+#define SYSTIMER_RATE 1000000
+#define SYSTIMER_MIN_DELTA 0x64
+#define SYSTIMER_MAX_DELTA ULONG_MAX
+
+/* SYSTIMER Register Offset (RTK Internal Use) */
+#define TS_LW_OFST 0x0
+#define TS_HW_OFST 0x4
+#define TS_CMP_VAL_LW_OFST 0x8
+#define TS_CMP_VAL_HW_OFST 0xC
+#define TS_CMP_CTRL_OFST 0x10
+#define TS_CMP_STAT_OFST 0x14
+
+/* SYSTIMER CMP CTRL REG Mask */
+#define TS_CMP_EN_MASK 0x1
+#define TS_WR_EN0_MASK 0x2
+
+static void __iomem *systimer_base;
+
+static u64 rtk_ts64_read(void)
+{
+ u32 low, high;
+ u64 ts;
+
+ /* Caution: Read LSB word (TS_LW_OFST) first then MSB (TS_HW_OFST) */
+ low = readl(systimer_base + TS_LW_OFST);
+ high = readl(systimer_base + TS_HW_OFST);
+ ts = ((u64)high << 32) | low;
+
+ return ts;
+}
+
+static void rtk_cmp_value_write(u64 value)
+{
+ u32 high, low;
+
+ low = value & 0xFFFFFFFF;
+ high = value >> 32;
+
+ writel(high, systimer_base + TS_CMP_VAL_HW_OFST);
+ writel(low, systimer_base + TS_CMP_VAL_LW_OFST);
+}
+
+static inline void rtk_cmp_en_write(bool cmp_en)
+{
+ u32 val;
+
+ val = TS_WR_EN0_MASK;
+ if (cmp_en == ENBL)
+ val |= TS_CMP_EN_MASK;
+
+ writel(val, systimer_base + TS_CMP_CTRL_OFST);
+}
+
+static int rtk_syst_clkevt_next_event(unsigned long cycles, struct clock_event_device *clkevt)
+{
+ u64 cmp_val;
+
+ rtk_cmp_en_write(DSBL);
+ cmp_val = rtk_ts64_read();
+
+ /* Set CMP value to current timestamp plus delta_us */
+ rtk_cmp_value_write(cmp_val + cycles);
+ rtk_cmp_en_write(ENBL);
+ return 0;
+}
+
+static irqreturn_t rtk_ts_match_intr_handler(int irq, void *dev_id)
+{
+ struct clock_event_device *clkevt = dev_id;
+ void __iomem *reg_base;
+ u32 val;
+
+ /* Disable TS CMP Match */
+ rtk_cmp_en_write(DSBL);
+
+ /* Clear TS CMP INTR */
+ reg_base = systimer_base + TS_CMP_STAT_OFST;
+ val = readl(reg_base) & TS_CMP_EN_MASK;
+ writel(val | TS_CMP_EN_MASK, reg_base);
+ clkevt->event_handler(clkevt);
+
+ return IRQ_HANDLED;
+}
+
+static int rtk_syst_shutdown(struct clock_event_device *clkevt)
+{
+ void __iomem *reg_base;
+ u64 cmp_val = 0;
+
+ /* Disable TS CMP Match */
+ rtk_cmp_en_write(DSBL);
+ /* Set compare value to 0 */
+ rtk_cmp_value_write(cmp_val);
+
+ /* Clear TS CMP INTR */
+ reg_base = systimer_base + TS_CMP_STAT_OFST;
+ writel(TS_CMP_EN_MASK, reg_base);
+ return 0;
+}
+
+static struct timer_of rtk_timer_to = {
+ .flags = TIMER_OF_IRQ | TIMER_OF_BASE,
+
+ .clkevt = {
+ .name = "rtk-clkevt",
+ .rating = 300,
+ .cpumask = cpu_possible_mask,
+ .features = CLOCK_EVT_FEAT_DYNIRQ |
+ CLOCK_EVT_FEAT_ONESHOT,
+ .set_next_event = rtk_syst_clkevt_next_event,
+ .set_state_oneshot = rtk_syst_shutdown,
+ .set_state_shutdown = rtk_syst_shutdown,
+ },
+
+ .of_irq = {
+ .flags = IRQF_TIMER | IRQF_IRQPOLL,
+ .handler = rtk_ts_match_intr_handler,
+ },
+};
+
+static int __init rtk_systimer_init(struct device_node *node)
+{
+ int ret;
+
+ ret = timer_of_init(node, &rtk_timer_to);
+ if (ret)
+ return ret;
+
+ systimer_base = timer_of_base(&rtk_timer_to);
+ clockevents_config_and_register(&rtk_timer_to.clkevt, SYSTIMER_RATE,
+ SYSTIMER_MIN_DELTA, SYSTIMER_MAX_DELTA);
+
+ return 0;
+}
+
+TIMER_OF_DECLARE(rtk_systimer, "realtek,rtd1625-systimer", rtk_systimer_init);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [tip: timers/clocksource] dt-bindings: timer: Add Realtek SYSTIMER
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
2025-11-26 8:43 ` Krzysztof Kozlowski
@ 2025-11-26 14:40 ` tip-bot2 for Hao-Wen Ting
1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Hao-Wen Ting @ 2025-11-26 14:40 UTC (permalink / raw)
To: linux-tip-commits
Cc: Hao-Wen Ting, Daniel Lezcano, Krzysztof Kozlowski, x86,
linux-kernel
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: 40caba2bd027ab57c196b690e4e7f3c1746acb96
Gitweb: https://git.kernel.org/tip/40caba2bd027ab57c196b690e4e7f3c1746acb96
Author: Hao-Wen Ting <haowen.ting@realtek.com>
AuthorDate: Wed, 26 Nov 2025 14:01:09 +08:00
Committer: Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Wed, 26 Nov 2025 11:25:15 +01:00
dt-bindings: timer: Add Realtek SYSTIMER
The Realtek SYSTIMER (System Timer) is a 64-bit global hardware counter
operating at a fixed 1MHz frequency. Thanks to its compare match
interrupt capability, the timer natively supports oneshot mode for tick
broadcast functionality.
Signed-off-by: Hao-Wen Ting <haowen.ting@realtek.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Link: https://patch.msgid.link/20251126060110.198330-2-haowen.ting@realtek.com
---
Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
diff --git a/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml b/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
new file mode 100644
index 0000000..e08d3d2
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/realtek,rtd1625-systimer.yaml
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/realtek,rtd1625-systimer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek System Timer
+
+maintainers:
+ - Hao-Wen Ting <haowen.ting@realtek.com>
+
+description:
+ The Realtek SYSTIMER (System Timer) is a 64-bit global hardware counter operating
+ at a fixed 1MHz frequency. Thanks to its compare match interrupt capability,
+ the timer natively supports oneshot mode for tick broadcast functionality.
+
+properties:
+ compatible:
+ oneOf:
+ - const: realtek,rtd1625-systimer
+ - items:
+ - const: realtek,rtd1635-systimer
+ - const: realtek,rtd1625-systimer
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+ - interrupts
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ timer@89420 {
+ compatible = "realtek,rtd1635-systimer",
+ "realtek,rtd1625-systimer";
+ reg = <0x89420 0x18>;
+ interrupts = <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>;
+ };
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-26 14:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 6:01 [PATCH v5 0/2] Add Realtek System Timer Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Hao-Wen Ting
2025-11-26 8:43 ` Krzysztof Kozlowski
2025-11-26 14:40 ` [tip: timers/clocksource] " tip-bot2 for Hao-Wen Ting
2025-11-26 6:01 ` [PATCH v5 2/2] clocksource: Add Realtek system timer driver Hao-Wen Ting
2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers: " tip-bot2 for Hao-Wen Ting
2025-11-26 10:26 ` [PATCH v5 0/2] Add Realtek System Timer Daniel Lezcano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox