From nobody Mon Dec 1 23:35:11 2025 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E46324A046; Wed, 26 Nov 2025 06:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764136884; cv=none; b=iqQ8m0SvtAn0xS2VR9qsClOUcJocbSyMdbJU6FsF/n3KOGgSFS++oTvhNe+H3MmAs5vHl6KaqGmj+YD+4NBct4WpU3YYqXMURWOxtgFKwc2Ko9OXrfV+Fi3gCrif6HiW5XMUDidqkTcATrAJ+qDqM4EWSgajuXeK9prJp5KXrXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764136884; c=relaxed/simple; bh=xrwHfnwuN8q98Lz6mML4Q/pOzK4LhHwcrh8WEB5de+M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WJmTTYzO/28jLL9fzaCJDjw8iU2NKjVIY3Jhd1Dk4fjGhYW0exkadaVsjBXqDEwwNoxzQfJdY+ZfZMkc8+l7SvhaFQklq4udM+palVwVzRuDBIa0fz+twAFmSQdsA68sleLkeUGnfQTJ/vcGhJPTAfHnZBKyjRKvqV4lI6IjLYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b=fXT7ybrE; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b="fXT7ybrE" X-SpamFilter-By: ArmorX SpamTrap 5.80 with qID 5AQ61AAr8315782, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=realtek.com; s=dkim; t=1764136871; bh=s5Rq4zC0pGSTG+06J42cRa/N3OoI7AoohrdOnwCfK3M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type; b=fXT7ybrEnPpWW8kikxZO7p5yvm2GTpfAS4g+IDceCR1JNb8OfGOcYu/aqRxwvo+o+ Px1BBL4bUcO44AxG7WRLGgFCswgwvUf1K00Rs6wjSjxA/dgLOvYMmOCLdpVaR5H9WY gvTm18T8f11/QazA5sdJpTWOJbK8kKC5ORdDla/HSP2RimFaj0hszU7WJHVI27Hhsk SYKc9O1GwHG/ZfvLWx7DRygqT5Le4RKffv8ROUPRBMZhf8iRMsS2l3X0u+IEtEjtMa ts6ufLwPHTSqyV5Xgb29RZVKC6Ey3vW9FMUaUpHwgTPuVbkwWNcnwr/x/kxJZgdIsa rWSthSKl2pbXQ== Received: from mail.realtek.com (rtkexhmbs03.realtek.com.tw[10.21.1.53]) by rtits2.realtek.com.tw (8.15.2/3.21/5.94) with ESMTPS id 5AQ61AAr8315782 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Nov 2025 14:01:11 +0800 Received: from RTKEXHMBS06.realtek.com.tw (10.21.1.56) by RTKEXHMBS03.realtek.com.tw (10.21.1.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.27; Wed, 26 Nov 2025 14:01:11 +0800 Received: from RTKEXHMBS03.realtek.com.tw (10.21.1.53) by RTKEXHMBS06.realtek.com.tw (10.21.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.27; Wed, 26 Nov 2025 14:01:10 +0800 Received: from ww-haowen.ting (172.21.177.97) by RTKEXHMBS03.realtek.com.tw (10.21.1.53) with Microsoft SMTP Server id 15.2.1544.27 via Frontend Transport; Wed, 26 Nov 2025 14:01:10 +0800 From: Hao-Wen Ting To: , CC: , , , , , , , , , , , , , , , Krzysztof Kozlowski Subject: [PATCH v5 1/2] dt-bindings: timer: Add Realtek SYSTIMER Date: Wed, 26 Nov 2025 14:01:09 +0800 Message-ID: <20251126060110.198330-2-haowen.ting@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251126060110.198330-1-haowen.ting@realtek.com> References: <20251126060110.198330-1-haowen.ting@realtek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Krzysztof Kozlowski --- .../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-systim= er.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 + +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 capabil= ity, + the timer natively supports oneshot mode for tick broadcast functionalit= y. + +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 + + timer@89420 { + compatible =3D "realtek,rtd1635-systimer", + "realtek,rtd1625-systimer"; + reg =3D <0x89420 0x18>; + interrupts =3D ; + }; --=20 2.34.1 From nobody Mon Dec 1 23:35:11 2025 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7FFF25782D; Wed, 26 Nov 2025 06:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764136884; cv=none; b=QZHDS4TTKH3AE30WecqHg4kpQQ7hCdP3hLYd10ADfpr/AmaVxEQJ1qp+oeU7m9yv9h6Y/pu9ZctmA012nISEsZftBUMQG9YwoCA6IXzJWlVRqDULqxytRHoWCfPz0iQ2LZJFxLHyLV6ln26NkBt9au4J3IsbwCUDVJ6eyvUNzuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764136884; c=relaxed/simple; bh=jtKjZYfKex07R5qltKOiGpOwQeAx0FQEIE7FwJTNrUQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o7whuiU51SDealGII5MhtMOGebDCGK6AgJKpObG1P4IfmXFdtXR2HaCiElaR688YWPs8vbL9STR8kcXfVR6l7oZF/PQz+M2ELXGQ66G4FSAy2nOPKyE/zfTBPyz/QxmxyOFLLxQq1Iw9Ez1hdJd5jV4IM0Y8oP1ePVM2JmEKjLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b=gzKUwLeA; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b="gzKUwLeA" X-SpamFilter-By: ArmorX SpamTrap 5.80 with qID 5AQ61CxL4315786, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=realtek.com; s=dkim; t=1764136872; bh=DYUJa6xhmHLbnSTO05pwW0RS8dTKC+BgTHmjXc1ZDtI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type; b=gzKUwLeAqPserY2HCvSP2HBq/7T+ihq4+jFgIzgud3dl416qlsVVNt1L24bI1PWW0 s+vEVy2Zd+gMVWM237YpUWfPH8MJe2z96+x9zOcVH5hh/VBRJUf3A8Lg1IAQPj1ZAj Hf+prSWmrjvgH84V8egQtt/aNToT/er0pi22BQruuJhoATA0/NBsybzhGP7IBR/aOg qXgkboNBmjUiySjCSo1JcKQ59q7ATQquYGW2SbMbeg8k7ZzxOH0Z+9IUVtetrArEqc X9CcJS6haev6ZMJbdbU4kDM8vxADyiw0RqilN1oO8f2035dQtnFv85NvvVAyF2CbSB DaUL2gHChc+dQ== Received: from mail.realtek.com (rtkexhmbs02.realtek.com.tw[172.21.6.41]) by rtits2.realtek.com.tw (8.15.2/3.21/5.94) with ESMTPS id 5AQ61CxL4315786 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Nov 2025 14:01:12 +0800 Received: from RTKEXHMBS06.realtek.com.tw (10.21.1.56) by RTKEXHMBS02.realtek.com.tw (172.21.6.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.27; Wed, 26 Nov 2025 14:01:12 +0800 Received: from RTKEXHMBS03.realtek.com.tw (10.21.1.53) by RTKEXHMBS06.realtek.com.tw (10.21.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.27; Wed, 26 Nov 2025 14:01:10 +0800 Received: from ww-haowen.ting (172.21.177.97) by RTKEXHMBS03.realtek.com.tw (10.21.1.53) with Microsoft SMTP Server id 15.2.1544.27 via Frontend Transport; Wed, 26 Nov 2025 14:01:10 +0800 From: Hao-Wen Ting To: , CC: , , , , , , , , , , , , , , Subject: [PATCH v5 2/2] clocksource: Add Realtek system timer driver Date: Wed, 26 Nov 2025 14:01:10 +0800 Message-ID: <20251126060110.198330-3-haowen.ting@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251126060110.198330-1-haowen.ting@realtek.com> References: <20251126060110.198330-1-haowen.ting@realtek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Thomas Gleixner --- 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 =20 +REALTEK SYSTIMER DRIVER +M: Hao-Wen Ting +S: Maintained +F: drivers/clocksource/timer-realtek.c + REALTEK WIRELESS DRIVER (rtlwifi family) M: Ping-Ke Shih 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. =20 +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) +=3D timer-loongson1-p= wm.o obj-$(CONFIG_EP93XX_TIMER) +=3D timer-ep93xx.o obj-$(CONFIG_RALINK_TIMER) +=3D timer-ralink.o obj-$(CONFIG_NXP_STM_TIMER) +=3D timer-nxp-stm.o +obj-$(CONFIG_RTK_SYSTIMER) +=3D timer-realtek.o diff --git a/drivers/clocksource/timer-realtek.c b/drivers/clocksource/time= r-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 +#include +#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 =3D readl(systimer_base + TS_LW_OFST); + high =3D readl(systimer_base + TS_HW_OFST); + ts =3D ((u64)high << 32) | low; + + return ts; +} + +static void rtk_cmp_value_write(u64 value) +{ + u32 high, low; + + low =3D value & 0xFFFFFFFF; + high =3D 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 =3D TS_WR_EN0_MASK; + if (cmp_en =3D=3D ENBL) + val |=3D TS_CMP_EN_MASK; + + writel(val, systimer_base + TS_CMP_CTRL_OFST); +} + +static int rtk_syst_clkevt_next_event(unsigned long cycles, struct clock_e= vent_device *clkevt) +{ + u64 cmp_val; + + rtk_cmp_en_write(DSBL); + cmp_val =3D 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 =3D dev_id; + void __iomem *reg_base; + u32 val; + + /* Disable TS CMP Match */ + rtk_cmp_en_write(DSBL); + + /* Clear TS CMP INTR */ + reg_base =3D systimer_base + TS_CMP_STAT_OFST; + val =3D 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 =3D 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 =3D systimer_base + TS_CMP_STAT_OFST; + writel(TS_CMP_EN_MASK, reg_base); + return 0; +} + +static struct timer_of rtk_timer_to =3D { + .flags =3D TIMER_OF_IRQ | TIMER_OF_BASE, + + .clkevt =3D { + .name =3D "rtk-clkevt", + .rating =3D 300, + .cpumask =3D cpu_possible_mask, + .features =3D CLOCK_EVT_FEAT_DYNIRQ | + CLOCK_EVT_FEAT_ONESHOT, + .set_next_event =3D rtk_syst_clkevt_next_event, + .set_state_oneshot =3D rtk_syst_shutdown, + .set_state_shutdown =3D rtk_syst_shutdown, + }, + + .of_irq =3D { + .flags =3D IRQF_TIMER | IRQF_IRQPOLL, + .handler =3D rtk_ts_match_intr_handler, + }, +}; + +static int __init rtk_systimer_init(struct device_node *node) +{ + int ret; + + ret =3D timer_of_init(node, &rtk_timer_to); + if (ret) + return ret; + + systimer_base =3D 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_in= it); --=20 2.34.1