From nobody Sun Jun 14 02:12:21 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 622673F23B5 for ; Wed, 29 Apr 2026 11:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463467; cv=none; b=afobp0ntMYyrMNp0AZ5sw702lVDBr1oHUD4PBpka6D43hIxXBfiIjN5FwmdIJlpJALi/E1wJqI4QqIX/C1l+yOOHEeZQM6Alh2o3MEEPO35hYIQf9RocxgengLA6HXld3vzclxD0aVwGARbzwi+j/Q3N8VQEqOaaNnbGG5xvjQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463467; c=relaxed/simple; bh=G754Rfbykse9QtKThpKHuYxkMF1za0eRu5ICzuhMxsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QDW/DLTM8w/WdsCEqRUmoCdg/Te1jAFL2H/Lmo4fStw2Plf0vAzj1a1SpmUC/JOma7tanOcyuSxcAoG+QDsNQmtHmGM824IEZi6sgnYcQ04D1ACTz9oUYbH7t02sKp/KBqa5XdH+kmHDgc/gRmDR8cuS3vKmvBb7RZ96N0PRMJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=mKIrY3Qy; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="mKIrY3Qy" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 0B7194E42AF3; Wed, 29 Apr 2026 11:51:05 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D61F3601DF; Wed, 29 Apr 2026 11:51:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id AB9A81072824E; Wed, 29 Apr 2026 13:51:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777463463; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=IJLd/bKb+ZyJDbV8sgfNPrpyA1J1ZWNGq3+hTeI0zQM=; b=mKIrY3QyaUN79SdrgxwphVI2D5jhzxmYQ+jdEAFJ8XKx4dZ/CB+/yG/RcCw84+7comEvNr 4EKrDiqn+TznCrD6aIj/5ieVRiYAA5HXQwoibuixs0w+dbxPR055OWMcMoC9nYkqhW25ba cWwJYknrxvK3DDA9tlfh2dcKkEpu2F/FEmmkCxp+DB98uFajl2W0J1ROR6AnAW0A4AcdX9 EMhS02yAOUYbdcPG0Bjmw4rq8JoLTvNYAa1DQ1COw5XS7zM6VCa4ts2NVv2CDFBA+i9Zsx FpI29mSBqgqt5SVXrUoaHPf1sRJgE1PnQAHwZv7A6BfmPmLhsglYfAvja4EcQQ== From: "Herve Codina (Schneider Electric)" To: Wolfram Sang , Herve Codina , Daniel Lezcano , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Pascal Eberhard , Miquel Raynal , Thomas Petazzoni , Krzysztof Kozlowski Subject: [PATCH v2 1/4] dt-bindings: timer: Add the Renesas RZ/N1 timer Date: Wed, 29 Apr 2026 13:50:20 +0200 Message-ID: <20260429115054.158160-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429115054.158160-1-herve.codina@bootlin.com> References: <20260429115054.158160-1-herve.codina@bootlin.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 X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The Renesas RZ/N1 timer block controller is the controller in charge of timers available in the Renesas RZ/N1 SoCs family. This controller handles 8 timers: - 6 16-bit timers - 2 32-bit timers Signed-off-by: Herve Codina (Schneider Electric) Reviewed-by: Krzysztof Kozlowski --- .../bindings/timer/renesas,rzn1-timer.yaml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/renesas,rzn1-ti= mer.yaml diff --git a/Documentation/devicetree/bindings/timer/renesas,rzn1-timer.yam= l b/Documentation/devicetree/bindings/timer/renesas,rzn1-timer.yaml new file mode 100644 index 000000000000..f00ad941f8cc --- /dev/null +++ b/Documentation/devicetree/bindings/timer/renesas,rzn1-timer.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/renesas,rzn1-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas RZ/N1 timers + +maintainers: + - Herve Codina + +description: | + The Renesas RZ/N1 SoCs timers block controller is composed of 8 independ= ent + timers. + - 6 are 16-bit timers + - 2 are 32-bit timers + + Each timer has its own interrupt line and can work in either one-shot or + periodic mode. + +properties: + compatible: + items: + - const: renesas,r9a06g032-timer # RZ/N1D + - const: renesas,rzn1-timer + + reg: + maxItems: 1 + + clocks: + items: + - description: APB internal bus clock + + clock-names: + items: + - const: pclk + + power-domains: + maxItems: 1 + + interrupts: + maxItems: 8 + +required: + - compatible + - reg + - clocks + - clock-names + - power-domains + - interrupts + +additionalProperties: false + +examples: + - | + #include + #include + + timer@51001000 { + compatible =3D "renesas,r9a06g032-timer", "renesas,rzn1-timer"; + reg =3D <0x51001000 0x400>; + clocks =3D <&sysctrl R9A06G032_HCLK_TIMER0>; + clock-names =3D "pclk"; + power-domains =3D <&sysctrl>; + interrupts =3D , + , + , + , + , + , + , + ; + }; +... --=20 2.53.0 From nobody Sun Jun 14 02:12:21 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80EBE3F2117; Wed, 29 Apr 2026 11:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463470; cv=none; b=BsLjqoqNPOJk+Gds4KIQHDNc8etQC9s4EVdukL/GmmJQT/336jqNnOyrVzw7be1KFt8bibkt0uzEgNzo5tou3Ax1CxP1zGxUpuuOAmKPJZe4Nx+6ox/CwL6LWv+HwovbHlqJnby7dVD2njdzcofOv8RWo7VKM2UGCnlnL/Q9UVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463470; c=relaxed/simple; bh=8vbtotmnLl+jf5j6AqmH9R3IX/J1gu4+SOOLKAXG+Ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z351cNbq2yYYGiDtD/2RDiPfvE3BIn5rzbdZkIwWdKeY1LTgA5XP20QBTolWu75Ve0sBjAvpGqjvJR89AHxUZTxV6y41bg+PpPcvpzzNeqTTlr4C7J+3MTFQ1cdcmXh/mGZ5g7hEGGv4ZLQrUDa9A94OtxY6UhBOIyu/kOCyso0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=sZmb7nN6; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="sZmb7nN6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 38B5FC5EF22; Wed, 29 Apr 2026 11:51:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 22655601DF; Wed, 29 Apr 2026 11:51:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A8E4C10728DDC; Wed, 29 Apr 2026 13:51:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777463466; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=QBLyVbc6XfhGx6fDWTmeL0AR9E9NNbe5OatPXW5jehI=; b=sZmb7nN6CgNb1teEIfkJ/dxPYAf15uyNsQcgwYP68RRyZ9MiRYTFEbN4cSYVafoxV1uUcz C/HyMG2aPWcR5cpDR8W/hTLk+injrc5072SKmm7UjsnW+1VCdqnrrbd9yXBNaeSd1heLET fSuqHdPxdJKaD/1XF/MICzZUlMPFzgd/ic5Mtto6mtaG2rKyaC6xnr7knpgK5w+5Rus8O8 c53Ws5ymqvAhYnqAfilOv5jQ9Jzlwk5pXmrCAHwkm5qCJaOA1HIzZT/YQUqLmryseVljCX pcgIM82Q60VZkOPqeDYoEVHtW3M886jYkZ8iZG3I0vqrt40vs3T46zBya7dAGA== From: "Herve Codina (Schneider Electric)" To: Wolfram Sang , Herve Codina , Daniel Lezcano , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Pascal Eberhard , Miquel Raynal , Thomas Petazzoni Subject: [PATCH v2 2/4] clocksource/drivers: Add support for the Renesas RZ/N1 timers Date: Wed, 29 Apr 2026 13:50:21 +0200 Message-ID: <20260429115054.158160-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429115054.158160-1-herve.codina@bootlin.com> References: <20260429115054.158160-1-herve.codina@bootlin.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 X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The Renesas RZ/N1 timer block controller is the controller in charge of timers available in the Renesas RZ/N1 SoCs family. This controller handles 8 timers: - 6 16-bit timers - 2 32-bit timers Each timer has its own interrupt, its own prescaler that can be used to device the clock by 25 and all of them can work in either one-shot or periodic mode. Signed-off-by: Herve Codina (Schneider Electric) --- drivers/clocksource/Kconfig | 10 + drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-rzn1.c | 442 +++++++++++++++++++++++++++++++ 3 files changed, 453 insertions(+) create mode 100644 drivers/clocksource/timer-rzn1.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index d1a33a231a44..f8e49a4ac8f6 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -152,6 +152,16 @@ config REALTEK_OTTO_TIMER RT8391, RTL8392, RTL8393 and RTL8396 and chips of the RTL930x series such as RTL9301, RTL9302 or RTL9303. =20 +config RZN1_TIMER + bool "Renesas RZ/N1 Timer" + depends on HAS_IOMEM && COMMON_CLK && (ARCH_RZN1 || COMPILE_TEST) + help + Enables support for RZ/N1 SoC timers. + A timers block in RZ/N1 SoCs is composed of 8 timers + - 6 16-bit timers + - 2 32-bit timers + Two timers blocks are available in RZ/N1 SoCs. + config SUN4I_TIMER bool "Sun4i timer driver" if COMPILE_TEST depends on HAS_IOMEM diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index b46376af6b49..464ec6690ab6 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -96,3 +96,4 @@ 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 +obj-$(CONFIG_RZN1_TIMER) +=3D timer-rzn1.o diff --git a/drivers/clocksource/timer-rzn1.c b/drivers/clocksource/timer-r= zn1.c new file mode 100644 index 000000000000..1b95b0b5cd3b --- /dev/null +++ b/drivers/clocksource/timer-rzn1.c @@ -0,0 +1,442 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * RZ/N1 timers driver + * + * Copyright (C) 2026 Schneider-Electric + * + * Author: Herve Codina + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Per-timer register offsets */ +#define RZN1_TIMER_LOAD_COUNT_REG 0x00 +#define RZN1_TIMER_CURRENT_COUNT_REG 0x04 +#define RZN1_TIMER_CONTROL_REG 0x08 +#define RZN1_TIMER_CONTROL_INT_UNMASK BIT(3) +#define RZN1_TIMER_CONTROL_ENABLE BIT(2) +#define RZN1_TIMER_CONTROL_AUTORELOAD BIT(1) +#define RZN1_TIMER_CONTROL_PRESCALER_DIV25 BIT(0) +#define RZN1_TIMER_CLEAR_INT_REG 0x0c +#define RZN1_TIMER_STATUS_INT0_REG 0x10 +#define RZN1_TIMER_STATUS_INT1_REG 0x14 + +/* + * 8 timers are available. Among those 8 timers, the first 6 timers are 16= -bit + * timers and the last two ones are 32-bit timers. + */ +#define RZN1_TIMER_BASE_INDEX_16BIT_TIMERS 0 +#define RZN1_TIMER_NB_16BIT_TIMERS 6 + +#define RZN1_TIMER_BASE_INDEX_32BIT_TIMER 6 +#define RZN1_TIMER_NB_32BIT_TIMERS 2 + +#define RZN1_TIMER_IS_16BIT_TIMER(_i) ((_i) < RZN1_TIMER_BASE_INDEX_32BIT_= TIMER) + +/* Total numbers of timers */ +#define RZN1_TIMER_NB_TIMERS (RZN1_TIMER_NB_16BIT_TIMERS + \ + RZN1_TIMER_NB_32BIT_TIMERS) + +/* Offset of registers related to the timer number _i in the timers regs a= rea */ +#define RZN1_TIMER_REGS_OFFSET(_i) (0x20 * (_i)) + +struct rzn1_timer { + void __iomem *base; + unsigned int width; + unsigned long rate; + unsigned long hz_period; + struct clock_event_device ced; +}; + +static int rzn1_timer_config(struct rzn1_timer *timer, u32 period, bool is= _periodic) +{ + u32 ctrl; + + ctrl =3D readl(timer->base + RZN1_TIMER_CONTROL_REG); + + /* Disable the timer */ + writel(ctrl & ~RZN1_TIMER_CONTROL_ENABLE, + timer->base + RZN1_TIMER_CONTROL_REG); + + /* Set the new period */ + writel(period, timer->base + RZN1_TIMER_LOAD_COUNT_REG); + + /* Prepare the timer mode */ + if (is_periodic) + ctrl |=3D RZN1_TIMER_CONTROL_AUTORELOAD; + else + ctrl &=3D ~RZN1_TIMER_CONTROL_AUTORELOAD; + + /* + * Enable the timer. + * + * This automatically resets the CURRENT_COUNT register. + */ + ctrl |=3D RZN1_TIMER_CONTROL_ENABLE; + writel(ctrl, timer->base + RZN1_TIMER_CONTROL_REG); + + return 0; +} + +static void rzn1_timer_disable(struct rzn1_timer *timer) +{ + u32 ctrl; + + ctrl =3D readl(timer->base + RZN1_TIMER_CONTROL_REG); + ctrl &=3D ~RZN1_TIMER_CONTROL_ENABLE; + writel(ctrl, timer->base + RZN1_TIMER_CONTROL_REG); +} + +static void rzn1_timer_int_enable(struct rzn1_timer *timer) +{ + u32 ctrl; + + ctrl =3D readl(timer->base + RZN1_TIMER_CONTROL_REG); + ctrl |=3D RZN1_TIMER_CONTROL_INT_UNMASK; + writel(ctrl, timer->base + RZN1_TIMER_CONTROL_REG); +} + +static irqreturn_t rzn1_timer_interrupt(int irq, void *dev_id) +{ + struct rzn1_timer *timer =3D dev_id; + + /* Ack the interrupt */ + readl(timer->base + RZN1_TIMER_CLEAR_INT_REG); + + timer->ced.event_handler(&timer->ced); + return IRQ_HANDLED; +} + +static int rzn1_clkevt_set_next_event(unsigned long cycles, + struct clock_event_device *evt) +{ + struct rzn1_timer *timer =3D container_of(evt, struct rzn1_timer, ced); + + return rzn1_timer_config(timer, cycles, false); +} + +static int rzn1_clkevt_shutdown(struct clock_event_device *evt) +{ + struct rzn1_timer *timer =3D container_of(evt, struct rzn1_timer, ced); + + rzn1_timer_disable(timer); + return 0; +} + +static int rzn1_clkevt_set_periodic(struct clock_event_device *evt) +{ + struct rzn1_timer *timer =3D container_of(evt, struct rzn1_timer, ced); + + rzn1_timer_config(timer, timer->hz_period, true); + return 0; +} + +/* + * This global lock is used to prevent race conditions during global timers + * test and set operation in case the driver is using the async probe opti= on. + */ +static DEFINE_MUTEX(rzn1_global_timers_lock); + +static int rzn1_timer_instance; + +/* scheduler and clocksource */ +static struct rzn1_timer *rzn1_sched_clock; + +static u64 notrace rzn1_sched_read(void) +{ + return readl_relaxed(rzn1_sched_clock->base + RZN1_TIMER_CURRENT_COUNT_RE= G); +} + +static u64 rzn1_clksrc_read(struct clocksource *cs) +{ + return readl_relaxed(rzn1_sched_clock->base + RZN1_TIMER_CURRENT_COUNT_RE= G); +} + +static struct clocksource rzn1_clocksource =3D { + .name =3D "rzn1_timer_clocksource", + .rating =3D 200, + .flags =3D CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP, + .read =3D rzn1_clksrc_read, +}; + +/* Timers table where 32-bit timers will be assigned per-cpu */ +static struct rzn1_timer *rzn1_tab_timers; + +static int rzn1_local_timer_starting_cpu(unsigned int cpu) +{ + struct rzn1_timer *timer; + + if (cpu > RZN1_TIMER_NB_32BIT_TIMERS) + return -EINVAL; + + timer =3D &rzn1_tab_timers[cpu + RZN1_TIMER_BASE_INDEX_32BIT_TIMER]; + + timer->ced.cpumask =3D cpumask_of(cpu); + irq_force_affinity(timer->ced.irq, cpumask_of(cpu)); + clockevents_config_and_register(&timer->ced, timer->rate, 1, + GENMASK(timer->width - 1, 0)); + + return 0; +} + +static void rzn1_timer_init(struct rzn1_timer *timer, unsigned int index, + void __iomem *timers_base, unsigned long clock_rate) +{ + timer->base =3D timers_base + RZN1_TIMER_REGS_OFFSET(index); + + /* Disable the timer */ + writel(0, timer->base + RZN1_TIMER_CONTROL_REG); + + /* Clear potential interrupts */ + readl(timer->base + RZN1_TIMER_CLEAR_INT_REG); + + if (RZN1_TIMER_IS_16BIT_TIMER(index)) { + timer->width =3D 16; + /* + * Enable pre-scaler for 16-bit timers. + * + * Timers are fed by a 25MHz clock. With this pre-scaler (1/25) + * enabled, the 16-bit timers resolution is 1 microsecond. + */ + writel(RZN1_TIMER_CONTROL_PRESCALER_DIV25, + timer->base + RZN1_TIMER_CONTROL_REG); + timer->rate =3D clock_rate / 25; + } else { + timer->width =3D 32; + timer->rate =3D clock_rate; + } + timer->hz_period =3D DIV_ROUND_UP(timer->rate, HZ); +} + +static void rzn1_timer_clkevt_init_ced(struct rzn1_timer *timer, const cha= r *name, + int irq) +{ + timer->ced.features =3D CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; + timer->ced.set_next_event =3D rzn1_clkevt_set_next_event; + timer->ced.set_state_shutdown =3D rzn1_clkevt_shutdown; + timer->ced.set_state_periodic =3D rzn1_clkevt_set_periodic; + timer->ced.cpumask =3D cpu_possible_mask; + + /* + * 32-bit timers are fed with a 25 MHz clock directly derived from the + * main PLL (1 GHz). The arch timer, ARMv7 CP15 in RZ/N1 SoCs, is fed + * with to a 6.25 MHz clock. + * + * The clock of the RZ/N1 timers block is a stable one and the RZ/N1 + * timers have a higher resolution than the ARM CP15 one. + * + * Also those 32-bit RZ/N1 timers are assigned per-cpu. + * + * Use a high rating for the 32-bit RZ/N1 timers in order to have them + * chosen by the system. + */ + timer->ced.rating =3D timer->width =3D=3D 16 ? 200 : 460; + timer->ced.owner =3D THIS_MODULE; + timer->ced.name =3D name; + timer->ced.irq =3D irq; +} + +static int rzn1_timer_probe_first(struct platform_device *pdev, struct rzn= 1_timer *tab_timers, + void __iomem *base, unsigned long clock_rate) +{ + struct device *dev =3D &pdev->dev; + struct rzn1_timer *timer; + unsigned int i; + char *name; + int irq; + int ret; + + /* + * Probe the first instance. In that case, timers are assigned as + * follow: + * - First 16-bit timer: clocksource and sched_clock + * - Other 16-bit timers: clock events for all possible CPUs + * - 32-bit timers: clock events per CPU + * + * First step, perform all operation that could fail without calling + * clockevents_config_and_register(), sched_clock_register() nor + * cpuhp_setup_state(). Those operation don't have unregister nor + * teardown counterparts and so, once called, we cannot remove the + * related resource. + */ + + /* + * First step for 16-bit timers except the first one and all 32-bit + * timers. + */ + for (i =3D RZN1_TIMER_BASE_INDEX_16BIT_TIMERS + 1; i < RZN1_TIMER_NB_TIME= RS; i++) { + timer =3D &tab_timers[i]; + + rzn1_timer_init(timer, i, base, clock_rate); + + irq =3D platform_get_irq(pdev, i); + if (irq < 0) + return irq; + + name =3D devm_kasprintf(dev, GFP_KERNEL, "%s-%u", dev_name(dev), i); + if (!name) + return -ENOMEM; + + rzn1_timer_clkevt_init_ced(timer, name, irq); + + ret =3D devm_request_irq(dev, timer->ced.irq, rzn1_timer_interrupt, + IRQF_TIMER, timer->ced.name, timer); + if (ret < 0) + return dev_err_probe(dev, irq, "timer%d: Failed to request IRQ\n", i); + + rzn1_timer_int_enable(timer); + } + + /* + * Second step, almost all operations that can fail have been called. + * Timers are ready to work. Start with the last operation that can fail, + * installing and invoking hotplug callbacks + */ + rzn1_tab_timers =3D tab_timers; + ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, + "clockevents/rzn1/global_timer:starting", + rzn1_local_timer_starting_cpu, NULL); + if (ret < 0) + return dev_err_probe(dev, ret, "Setup CPU hotplug state failed\n"); + + /* + * At this point, no more operations can fail. Perform remaining + * operations. Starting by handling the first 16-bit timer + */ + timer =3D &tab_timers[RZN1_TIMER_BASE_INDEX_16BIT_TIMERS]; + + rzn1_timer_init(timer, RZN1_TIMER_BASE_INDEX_16BIT_TIMERS, base, clock_ra= te); + rzn1_timer_config(timer, GENMASK(timer->width - 1, 0), true); + + rzn1_sched_clock =3D timer; + + sched_clock_register(rzn1_sched_read, rzn1_sched_clock->width, rzn1_sched= _clock->rate); + + rzn1_clocksource.mask =3D CLOCKSOURCE_MASK(rzn1_sched_clock->width); + clocksource_register_hz(&rzn1_clocksource, rzn1_sched_clock->rate); + + /* + * Register clockevents only for 16-bit timers. 32-bit timers clockevents + * are registered by CPU hotplug startup function set previously by the + * cpuhp_setup_state() call. + */ + for (i =3D RZN1_TIMER_BASE_INDEX_16BIT_TIMERS + 1; i < RZN1_TIMER_NB_16BI= T_TIMERS; i++) { + timer =3D &tab_timers[i]; + clockevents_config_and_register(&timer->ced, timer->rate, + 1, GENMASK(timer->width - 1, 0)); + } + + return 0; +} + +static int rzn1_timer_probe_other(struct platform_device *pdev, struct rzn= 1_timer *tab_timers, + void __iomem *base, unsigned long clock_rate) +{ + struct device *dev =3D &pdev->dev; + struct rzn1_timer *timer; + unsigned int i; + char *name; + int irq; + int ret; + + /* + * Probe other instance(s), i.e. not the first one. In that case, + * all timers are used as clock events and available for all possible + * CPUs + * + * First step, perform all operation that could fail without calling + * clockevents_config_and_register(). Unregister counterpart does not + * exist and so, once called, we cannot remove the related resource. + */ + for (i =3D 0; i < RZN1_TIMER_NB_TIMERS; i++) { + timer =3D &tab_timers[i]; + + rzn1_timer_init(timer, i, base, clock_rate); + + irq =3D platform_get_irq(pdev, i); + if (irq < 0) + return irq; + + name =3D devm_kasprintf(dev, GFP_KERNEL, "%s-%u", dev_name(dev), i); + if (!name) + return -ENOMEM; + + rzn1_timer_clkevt_init_ced(timer, name, irq); + + ret =3D devm_request_irq(dev, timer->ced.irq, rzn1_timer_interrupt, + IRQF_TIMER, timer->ced.name, timer); + if (ret < 0) + return dev_err_probe(dev, irq, "timer%d: Failed to request IRQ\n", i); + + rzn1_timer_int_enable(timer); + } + + /* + * Second step, all operation that can fail have been called. We can + * register our timers + */ + + for (i =3D 0; i < RZN1_TIMER_NB_TIMERS; i++) { + timer =3D &tab_timers[i]; + clockevents_config_and_register(&timer->ced, timer->rate, + 1, GENMASK(timer->width - 1, 0)); + } + + return 0; +} + +static int rzn1_timer_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct rzn1_timer *tab_timers; + unsigned long clock_rate; + void __iomem *base; + struct clk *clk; + int ret; + + tab_timers =3D devm_kcalloc(dev, RZN1_TIMER_NB_TIMERS, sizeof(*tab_timers= ), + GFP_KERNEL); + if (!tab_timers) + return -ENOMEM; + + base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + clk =3D devm_clk_get_enabled(dev, "pclk"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "Failed to get pclk\n"); + + clock_rate =3D clk_get_rate(clk); + + scoped_guard(mutex, &rzn1_global_timers_lock) { + ret =3D !rzn1_timer_instance ? + rzn1_timer_probe_first(pdev, tab_timers, base, clock_rate) : + rzn1_timer_probe_other(pdev, tab_timers, base, clock_rate); + if (!ret) + rzn1_timer_instance++; + } + + return ret; +} + +static const struct of_device_id rzn1_timer_of_match[] =3D { + { .compatible =3D "renesas,rzn1-timer", }, + { /* sentinel */ } +}; + +static struct platform_driver rzn1_timer_driver =3D { + .driver =3D { + .name =3D "rzn1_timer", + .of_match_table =3D rzn1_timer_of_match, + }, +}; +builtin_platform_driver_probe(rzn1_timer_driver, rzn1_timer_probe); --=20 2.53.0 From nobody Sun Jun 14 02:12:21 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CDD63F23C2 for ; Wed, 29 Apr 2026 11:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463475; cv=none; b=cmvB1rnKKu7CjvkY18gMyQRXnl7ALKJJSyCMX3FvXCs4PHxIRhN9k0tm7b3YRUNaVzXBrddpbc/X445EvSZxCkjcOApK7+RZueocTBKz2hG4AmLPK3jFPsvq6CVTqWTmAyD1fAkb/S6XEgDcjhjl5xMA2tHvAjeanQZhH7U/l7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463475; c=relaxed/simple; bh=YB0zZ417pPJLv9gKaLWcEu6H1usATHagKlTF7j6mUHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EwpqECOvrzHo2rvaYXrSraDFW4G3FJNzhpIj8YoSCsPTRWvemyKUs8+2HI4bEppzLuXzxHECqRDnwWKnYwqVPopzZ4l+PiRj83p7P44DBHSJgirpkpo/Sw43OqnDcUpjNP5PJEUAgMA6l+3EHymU3zpcHjP6dwdyz843BxFURCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=NytjCkyG; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="NytjCkyG" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 509134E42B3E; Wed, 29 Apr 2026 11:51:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 26FBB601DF; Wed, 29 Apr 2026 11:51:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BF39610728DD6; Wed, 29 Apr 2026 13:51:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777463468; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=XFdnAQ+zG+czHlNsfQu+J0GXRK/1/96xZW3qt2+UsSs=; b=NytjCkyG9DnqNC2lIaS677PEpQAmQ4fi7jimqD8eamoGsB+Sv8GOOGRF29fJN73D5LYBpe IVvVgCDech47zrdwPu6BYWCh3PWqc5obCLz7YRzsP4Wd2MA2CGC+VOH4yxYp4fNsKq/LcY 53EdwVgWi4jFJ7SNpQ9ln/p6EegU+hyB44bRHHr9+5MKG5y2XebAwxBqBWZPp3bY6oI4BN 7nJU1r3FtevgcGGD/DjS/Db7fUcjrreGDUh5M9SysTbO68YkVqNTE0U0flxzh4KIBo2kbH COpIhk26sHGN10/494ppA1ZQPuF4bmHJ/LtRq1gX6YC5zNNLRLwAVsxptBryGA== From: "Herve Codina (Schneider Electric)" To: Wolfram Sang , Herve Codina , Daniel Lezcano , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Pascal Eberhard , Miquel Raynal , Thomas Petazzoni Subject: [PATCH v2 3/4] ARM: dts: r9a06g032: Add support for timers Date: Wed, 29 Apr 2026 13:50:22 +0200 Message-ID: <20260429115054.158160-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429115054.158160-1-herve.codina@bootlin.com> References: <20260429115054.158160-1-herve.codina@bootlin.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 X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In the Renesas RZ/N1 SoCs family, two timers block are available. Each block contains 8 timers composed of 6 16-bits timers and 2 32-bits timers. Each timer has its own interrupt line. Describe those timers blocks. Signed-off-by: Herve Codina (Schneider Electric) --- arch/arm/boot/dts/renesas/r9a06g032.dtsi | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/arch/arm/boot/dts/renesas/r9a06g032.dtsi b/arch/arm/boot/dts/r= enesas/r9a06g032.dtsi index 442ea26b40f5..ba3f011e8c17 100644 --- a/arch/arm/boot/dts/renesas/r9a06g032.dtsi +++ b/arch/arm/boot/dts/renesas/r9a06g032.dtsi @@ -722,6 +722,40 @@ gpioirqmux: interrupt-controller@51000480 { status =3D "disabled"; }; =20 + timer0: timer@51001000 { + compatible =3D "renesas,r9a06g032-timer", "renesas,rzn1-timer"; + reg =3D <0x51001000 0x400>; + clocks =3D <&sysctrl R9A06G032_HCLK_TIMER0>; + clock-names =3D "pclk"; + power-domains =3D <&sysctrl>; + interrupts =3D , + , + , + , + , + , + , + ; + status =3D "disabled"; + }; + + timer1: timer@51002000 { + compatible =3D "renesas,r9a06g032-timer", "renesas,rzn1-timer"; + reg =3D <0x51002000 0x400>; + clocks =3D <&sysctrl R9A06G032_HCLK_TIMER1>; + clock-names =3D "pclk"; + power-domains =3D <&sysctrl>; + interrupts =3D , + , + , + , + , + , + , + ; + status =3D "disabled"; + }; + can0: can@52104000 { compatible =3D "renesas,r9a06g032-sja1000", "renesas,rzn1-sja1000"; reg =3D <0x52104000 0x800>; --=20 2.53.0 From nobody Sun Jun 14 02:12:21 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6CE13EDAB6 for ; Wed, 29 Apr 2026 11:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463477; cv=none; b=qlPfSB/R0WoNkARJABQjgcZIJPT0pI+otaZo545ticHQkbFGOdJj2nhdBjM5/CBk3klaShjji+/MwHLZ2jIHkNswlXpV6bPkm6UtQuIPoqtI67Iu9Sn5HIRcloLZq9ZVNHrgaxjpqySOnAU6EZlIvZvqm3KWIrkL9wV/9iSSdmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777463477; c=relaxed/simple; bh=VAJSA2xgO3c4cQcXZQBkqY65yBvsEuuS1NjB7gElWtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cHhC68Ssco95dyC99teoO8NV7dLA5JrAB3KaholrxKEBR3TS307Ckr3lpjnFqyo0dzsAqzG+e1R/2FNcg/yqNc+vTwDYYoc0ciuMsYuatPlyhchA4U1CLw7ClYPSa/LEPjOEgLO6ENadvqEWW1z9GMayFo7ztv1ULQ/X/Gj+fWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Zdg5iybp; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Zdg5iybp" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C1010C5EF23; Wed, 29 Apr 2026 11:51:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AD0E2601DF; Wed, 29 Apr 2026 11:51:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CA08010729012; Wed, 29 Apr 2026 13:51:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777463469; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=kYgU7p+5G7jRn2Lu2neiA6JjUceaSNvUkJDhIyk539E=; b=Zdg5iybpl50u7W6h5DFjstn0a8BWQtxfafcPB2bcM9TYKLAvWFqs66pfSKmtm7P3pzmiqY O4WyrW3q4ovV9HRkBsU7KGUrazY3Hv5xZJV4lfgii7qacpTpqhqYlhCNL8+WJpiIqxf+9x PRW9xiL9vfk4trACNdFQMDv5dpDmfeXS1SsBKWyS6/TC9CCk0imLEM8J93s1g3a3BzeKDB IvjHZMonKaTiTtI3Ju11c8tUo2DkQ2JMX2wGC+4QNUxOHwfcgia+IgEMW0KWxX5rF3lx7o PD4Mfhy6bFzkLe93GkxdIVFgiNhKy9a64V6mSKul9vQno28eozIPS+fEdWHErQ== From: "Herve Codina (Schneider Electric)" To: Wolfram Sang , Herve Codina , Daniel Lezcano , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Pascal Eberhard , Miquel Raynal , Thomas Petazzoni Subject: [PATCH v2 4/4] MAINTAINERS: Add the Renesas RZ/N1 timers driver entry Date: Wed, 29 Apr 2026 13:50:23 +0200 Message-ID: <20260429115054.158160-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429115054.158160-1-herve.codina@bootlin.com> References: <20260429115054.158160-1-herve.codina@bootlin.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 X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" After contributing the driver, add myself as the maintainer for the Renesas RZ/N1 timers driver. Signed-off-by: Herve Codina (Schneider Electric) --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 2fb1c75afd16..6f0bc793d657 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22708,6 +22708,13 @@ S: Maintained F: Documentation/devicetree/bindings/rtc/renesas,rzn1-rtc.yaml F: drivers/rtc/rtc-rzn1.c =20 +RENESAS RZ/N1 TIMERS DRIVER +M: Herve Codina +L: linux-renesas-soc@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/timer/renesas,rzn1-timer.yaml +F: drivers/clocksource/timer-rzn1.c + RENESAS RZ/N1 USBF CONTROLLER DRIVER M: Herve Codina L: linux-renesas-soc@vger.kernel.org --=20 2.53.0