From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D46B337C931; Fri, 27 Mar 2026 17:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634155; cv=none; b=PuuikJkM0v9KoZrITbwf92lSOINMtchU3i/CqNKdSPFT32UKKVPTCn+ky9F3FIHqj04DVAdDKm/D88Q9kjRivhc+VqJRlRNQ0CxXxBbCK5IawCQFlzWhd3zaUwla6SnzXRITqRk8oikhUEDVCsPesKuZTm1YIYqAk1T9IzY/cuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634155; c=relaxed/simple; bh=ExYu4MocTJ/m1GTF+9uD6AaFYfgRkiFOMtaD+oQsvJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oAG0ez7xU56u729/0vrsjcG+W42+Pq/fUgTY2998WL/iZxH8rAsiaUzU6c2pM8ibxYF0oD/463IQmOxKMGKb8dOYhAlUYwSH93TUYN8dLKZywub8KFCOvWFZSMDfC88gqB1WASQSG8HbMgOKdOV3j9teEOLIAUVNg9nOFOCxCXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=af1Wo0Zt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="af1Wo0Zt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3CE0C19423; Fri, 27 Mar 2026 17:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634155; bh=ExYu4MocTJ/m1GTF+9uD6AaFYfgRkiFOMtaD+oQsvJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=af1Wo0ZtuO6MYBGrbihyFM0Wl2bpxPl4QrLEWLsCVRXyqTrC2m9luHH3f79eoCncd ATH97Q8I+CX0cMh45LGrN2UIEJIbanfJTaNqADDLTHRAOfXyJJtmVRLgTwx2AmXOM7 oQV2YcTkYNG/z21ZEdDAgxZPoY4+z7qnPERyrgtcUZ4locVAgvc5hq7bvkaWgiDxTj mfM8W+SXAjeG+KuF8Ve3yOoG4SZeUm1jIL+Gb7f91RNIX0BJpn4p/N9PshUWy7/pY0 w2aqOQRR+cTkE2M9UGAk7woUZBBny7ungDcY/1lEwNXJRCn168vWJnk79+IpK5THIl Yca2wiOv+tblQ== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Daniel Lezcano , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Bryan O'Donoghue , Rob Herring , Greg Kroah-Hartman , Arnd Bergmann , Stephen Boyd , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH v1 1/7] clocksource/drivers/timer-probe: Create a platform_device before the framework is initialized Date: Fri, 27 Mar 2026 18:55:22 +0100 Message-ID: <20260327175533.3044-2-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Daniel Lezcano In the context of the time keeping and the timers, some platforms have timers which need to be initialized very early. It is the case of the ARM platform which do not have the architected timers. The macro TIMER_OF_DECLARE adds an entry in the timer init functions array at compile time and the function timer_probe is called from the timer_init() function in kernel/time.c This array contains a tuple with the init function and the compatible string. The init function has a device node pointer parameter. The timer_probe() function browses the of nodes and find the ones matching the compatible string given when using the TIMER_OF_DECLARE macro. It then calls the init function with the device node as a pointer. But there are some platforms where there are multiple timers like the ARM64 with the architected timers. Those are always initialized very early and the other timers can be initialized later. For this reason we find timer drivers with the platform_driver incarnation. Consequently their init functions are different, they have a platform_device pointer parameter and rely on the devm_ function for rollbacking. To summarize, we have: - TIMER_OF_DECLARE with init function prototype: int (*init)(struct device_node *np); - module_platform_driver (and variant) with the probe function prototype: int (*init)(struct platform_device *pdev); The current situation with the timers is the following: - Two platforms can have the same timer hardware, hence the same driver but one without alternate timers and the other with multiple timers. For example, the Exynos platform has only the Exynos MCT on ARM but has the architeched timers in addition on the ARM64. - The timer drivers can be modules now which was not the case until recently. TIMER_OF_DECLARE do not allow the build as a module. It results in duplicate init functions (one with rollback and one with devm_) and different way to declare the driver (TIMER_OF_DECLARE and module_platform_driver). This proposed change is to unify the prototyping of the init functions to receive a platform_device pointer as parameter. Consequently, it will allow a smoother and nicer module conversion and a huge cleanup of the init functions by removing all the rollback code from all the timer drivers. It introduces a TIMER_PDEV_DECLARE() macro. If the macro is used a platform_device is manually allocated and initialized with the needed information for the probe function. Otherwise module_platform_driver can be use instead with the same probe function without the timer_probe() initialization. The plan is to have all timers to use TIMER_PDEV_DECLARE with all the init functions optimized and then remove the TIMER_OF_DECLARE macro. Signed-off-by: Daniel Lezcano Cc: Hans de Goede Cc: Ilpo J=C3=A4rvinen Cc: Bryan O'Donoghue Cc: Rob Herring Cc: Greg Kroah-Hartman --- drivers/clocksource/timer-probe.c | 66 +++++++++++++++++++++++++++++-- include/asm-generic/vmlinux.lds.h | 10 +++++ include/linux/clocksource.h | 21 ++++++++++ 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/drivers/clocksource/timer-probe.c b/drivers/clocksource/timer-= probe.c index b7860bc0db4b..cdaceb68d356 100644 --- a/drivers/clocksource/timer-probe.c +++ b/drivers/clocksource/timer-probe.c @@ -7,13 +7,11 @@ #include #include #include +#include =20 extern struct of_device_id __timer_of_table[]; =20 -static const struct of_device_id __timer_of_table_sentinel - __used __section("__timer_of_table_end"); - -void __init timer_probe(void) +static int __init timer_of_probe(void) { struct device_node *np; const struct of_device_id *match; @@ -38,6 +36,66 @@ void __init timer_probe(void) timers++; } =20 + return timers; +} + +static int __init __timer_pdev_probe(struct platform_driver *drv) +{ + struct device_node *np; + struct platform_device *pdev; + const struct of_device_id *match; + unsigned int timers =3D 0; + int ret; + + for_each_matching_node_and_match(np, drv->driver.of_match_table, &match) { + if (!of_device_is_available(np)) + continue; + + pdev =3D platform_device_alloc(of_node_full_name(np), -1); + if (!pdev) + continue; + + ret =3D device_add_of_node(&pdev->dev, np); + if (ret) { + platform_device_put(pdev); + continue; + } + + dev_set_name(&pdev->dev, pdev->name); + + ret =3D drv->probe(pdev); + if (!ret) { + timers++; + continue; + } + + if (ret !=3D -EPROBE_DEFER) + pr_err("Failed to initialize '%pOF': %d\n", np, ret); + + device_remove_of_node(&pdev->dev); + + platform_device_put(pdev); + } + + return timers; +} + +static int __init timer_pdev_probe(void) +{ + struct platform_driver **drv; + + for_each_pdev_timer_table(drv) + __timer_pdev_probe(*drv); + + return 0; +} + +void __init timer_probe(void) +{ + unsigned timers =3D 0; + + timers +=3D timer_of_probe(); + timers +=3D timer_pdev_probe(); timers +=3D acpi_probe_device_table(timer); =20 if (!timers) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index eeb070f330bd..5d619e831dce 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -359,6 +359,15 @@ #define THERMAL_TABLE(name) #endif =20 +#ifdef CONFIG_TIMER_OF +#define TIMER_TABLE(name) \ + . =3D ALIGN(8); \ + BOUNDED_SECTION_POST_LABEL(__##name##_timer_table, \ + __##name##_timer_table,, _end) +#else +#define TIMER_TABLE(name) +#endif + #define KERNEL_DTB() \ STRUCT_ALIGN(); \ __dtb_start =3D .; \ @@ -738,6 +747,7 @@ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ THERMAL_TABLE(governor) \ + TIMER_TABLE(pdev) \ EARLYCON_TABLE() \ LSM_TABLE() \ EARLY_LSM_TABLE() \ diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 65b7c41471c3..6e05b78e64b8 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include =20 @@ -295,6 +296,26 @@ extern void timer_probe(void); static inline void timer_probe(void) {} #endif =20 +extern struct platform_driver *__pdev_timer_table[]; +extern struct platform_driver *__pdev_timer_table_end[]; + +#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ + static struct platform_driver __pdev_timer_table_entry_##__name =3D { \ + .probe =3D __probe, \ + .remove =3D __remove, \ + .driver =3D { \ + .name =3D #__name, \ + .of_match_table =3D __match \ + }, \ + }; \ + static struct platform_driver *___pdev_timer_table_entry_##__name \ + __used __section("__pdev_timer_table") =3D &__pdev_timer_table_entry_##__= name + +#define for_each_pdev_timer_table(__pdev) \ + for (__pdev =3D __pdev_timer_table; \ + __pdev < __pdev_timer_table_end; \ + __pdev++) + #define TIMER_ACPI_DECLARE(name, table_id, fn) \ ACPI_DECLARE_PROBE_ENTRY(timer, name, table_id, 0, NULL, 0, fn) =20 --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 59A453FEB1B for ; Fri, 27 Mar 2026 17:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634160; cv=none; b=PhlUr1KoVB+CcLNHy3jo2hrU/9jl+790P0BLiU9KszEB/SvEJMpdeLIcbEykxQkzsHbmTftuh7UuwZAI8V63knpXtXypazMdUI9unjrrK3XjcpHjb9AoNZ8AdEl/2ZK6cSNM1ZxlwCc7jcr4fVParf8BNwvJHE9REnlLTO7To9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634160; c=relaxed/simple; bh=6VMELURq/QqF9iasRhmGpYOPp+WVfGDU26yJiywk46s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ar1fljC8jcE7KeobnXkbABRAwRMDGoeFlnlJSdHT1kgQ2XBuIGcRVM8BqThV45dXOK6nBJyXKU6IDGCWbCrzOpAkdYWK9Y6qXHnQoJEmxXczIxRvE+1b6zqtGgQPe5E2um+em1ouabfIeJS5vQb7Xum4QA6rSsyd2LoV1Bx0GB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tr2Hvdge; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tr2Hvdge" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D23A8C2BCB0; Fri, 27 Mar 2026 17:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634159; bh=6VMELURq/QqF9iasRhmGpYOPp+WVfGDU26yJiywk46s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tr2HvdgehY6UchLQvk6Ht1ZRogPcs72Ccf4wbrBTHSSinZLqUSfmfyGIT0IS0vuWU +YAX1wLPU8KjCr2tETzLrPQoVg/FicumRZH3baXgxIUnCiQc1hG5L3w1dfdHMZXkYt 6XtoWhjlXUuNaPMobUcoNJX9IJuB8crWZECPbTC0qU/jWHB3mOky3CnmP+yTF2rAJM J8aWgmea8/w3ci9QMD1twupHqhddkGBld8ndGS2VcPTU13TRjeV9lcrkenobEhq5MU 2VNJfIiUESy/F4ndwe7rFhqYFL0cyyvXseqZqYc1I7IzMygAkAG2Y0aSPCMcbTEs+w gya1LT+tdJLFw== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Heiko Stuebner , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH v1 2/7] drivers/clocksource/rockchip: Use the TIMER_PDEV_DECLARE() macro Date: Fri, 27 Mar 2026 18:55:24 +0100 Message-ID: <20260327175533.3044-4-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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 previous change introduce the TIMER_PDEV_DECLARE() marco which allows to use the platform driver to initialize a timer driver with the benefit of having the devres to rollback automatically in case of error. Use this macro and change the function to rely on the devm_ variants, allowing to cleanup the code. Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-rockchip.c | 99 ++++++++++------------------ 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/drivers/clocksource/timer-rockchip.c b/drivers/clocksource/tim= er-rockchip.c index 540a16667145..486bbffba464 100644 --- a/drivers/clocksource/timer-rockchip.c +++ b/drivers/clocksource/timer-rockchip.c @@ -124,18 +124,18 @@ static u64 notrace rk_timer_sched_read(void) return ~readl_relaxed(rk_clksrc->base + TIMER_CURRENT_VALUE0); } =20 -static int __init -rk_timer_probe(struct rk_timer *timer, struct device_node *np) +static int rk_timer_init(struct rk_timer *timer, struct device *dev) { + struct device_node *np =3D dev->of_node; struct clk *timer_clk; struct clk *pclk; - int ret =3D -EINVAL, irq; + int irq; u32 ctrl_reg =3D TIMER_CONTROL_REG3288; =20 - timer->base =3D of_iomap(np, 0); - if (!timer->base) { + timer->base =3D devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(timer->base)) { pr_err("Failed to get base address for '%s'\n", TIMER_NAME); - return -ENXIO; + return PTR_ERR(timer->base); } =20 if (of_device_is_compatible(np, "rockchip,rk3399-timer")) @@ -143,31 +143,17 @@ rk_timer_probe(struct rk_timer *timer, struct device_= node *np) =20 timer->ctrl =3D timer->base + ctrl_reg; =20 - pclk =3D of_clk_get_by_name(np, "pclk"); + pclk =3D devm_clk_get_enabled(dev, "pclk"); if (IS_ERR(pclk)) { - ret =3D PTR_ERR(pclk); pr_err("Failed to get pclk for '%s'\n", TIMER_NAME); - goto out_unmap; - } - - ret =3D clk_prepare_enable(pclk); - if (ret) { - pr_err("Failed to enable pclk for '%s'\n", TIMER_NAME); - goto out_unmap; + return PTR_ERR(pclk); } timer->pclk =3D pclk; =20 - timer_clk =3D of_clk_get_by_name(np, "timer"); + timer_clk =3D devm_clk_get_enabled(dev, "timer"); if (IS_ERR(timer_clk)) { - ret =3D PTR_ERR(timer_clk); pr_err("Failed to get timer clock for '%s'\n", TIMER_NAME); - goto out_timer_clk; - } - - ret =3D clk_prepare_enable(timer_clk); - if (ret) { - pr_err("Failed to enable timer clock\n"); - goto out_timer_clk; + return PTR_ERR(timer_clk); } timer->clk =3D timer_clk; =20 @@ -175,47 +161,32 @@ rk_timer_probe(struct rk_timer *timer, struct device_= node *np) =20 irq =3D irq_of_parse_and_map(np, 0); if (!irq) { - ret =3D -EINVAL; pr_err("Failed to map interrupts for '%s'\n", TIMER_NAME); - goto out_irq; + return -EINVAL; } timer->irq =3D irq; =20 rk_timer_interrupt_clear(timer); rk_timer_disable(timer); - return 0; - -out_irq: - clk_disable_unprepare(timer_clk); -out_timer_clk: - clk_disable_unprepare(pclk); -out_unmap: - iounmap(timer->base); - - return ret; -} =20 -static void __init rk_timer_cleanup(struct rk_timer *timer) -{ - clk_disable_unprepare(timer->clk); - clk_disable_unprepare(timer->pclk); - iounmap(timer->base); + return 0; } =20 -static int __init rk_clkevt_init(struct device_node *np) +static int rk_clkevt_init(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; struct clock_event_device *ce; int ret =3D -EINVAL; =20 - rk_clkevt =3D kzalloc_obj(struct rk_clkevt); + rk_clkevt =3D devm_kzalloc(dev, sizeof(*rk_clkevt), GFP_KERNEL); if (!rk_clkevt) { ret =3D -ENOMEM; goto out; } =20 - ret =3D rk_timer_probe(&rk_clkevt->timer, np); + ret =3D rk_timer_init(&rk_clkevt->timer, dev); if (ret) - goto out_probe; + goto out; =20 ce =3D &rk_clkevt->ce; ce->name =3D TIMER_NAME; @@ -233,36 +204,33 @@ static int __init rk_clkevt_init(struct device_node *= np) if (ret) { pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); - goto out_irq; + goto out; } =20 clockevents_config_and_register(&rk_clkevt->ce, rk_clkevt->timer.freq, 1, UINT_MAX); return 0; =20 -out_irq: - rk_timer_cleanup(&rk_clkevt->timer); -out_probe: - kfree(rk_clkevt); out: /* Leave rk_clkevt not NULL to prevent future init */ rk_clkevt =3D ERR_PTR(ret); return ret; } =20 -static int __init rk_clksrc_init(struct device_node *np) +static int rk_clksrc_init(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; int ret =3D -EINVAL; =20 - rk_clksrc =3D kzalloc_obj(struct rk_timer); + rk_clksrc =3D devm_kzalloc(dev, sizeof(*rk_clksrc), GFP_KERNEL); if (!rk_clksrc) { ret =3D -ENOMEM; goto out; } =20 - ret =3D rk_timer_probe(rk_clksrc, np); + ret =3D rk_timer_init(rk_clksrc, dev); if (ret) - goto out_probe; + goto out; =20 rk_timer_update_counter(UINT_MAX, rk_clksrc); rk_timer_enable(rk_clksrc, 0); @@ -272,33 +240,34 @@ static int __init rk_clksrc_init(struct device_node *= np) clocksource_mmio_readl_down); if (ret) { pr_err("Failed to register clocksource\n"); - goto out_clocksource; + goto out; } =20 sched_clock_register(rk_timer_sched_read, 32, rk_clksrc->freq); return 0; =20 -out_clocksource: - rk_timer_cleanup(rk_clksrc); -out_probe: - kfree(rk_clksrc); out: /* Leave rk_clksrc not NULL to prevent future init */ rk_clksrc =3D ERR_PTR(ret); return ret; } =20 -static int __init rk_timer_init(struct device_node *np) +static int rk_timer_probe(struct platform_device *pdev) { if (!rk_clkevt) - return rk_clkevt_init(np); + return rk_clkevt_init(pdev); =20 if (!rk_clksrc) - return rk_clksrc_init(np); + return rk_clksrc_init(pdev); =20 pr_err("Too many timer definitions for '%s'\n", TIMER_NAME); return -EINVAL; } =20 -TIMER_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer", rk_timer_init); -TIMER_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer", rk_timer_init); +static const struct of_device_id rk_timer_match_table[] =3D { + { .compatible =3D "rockchip,rk3288-timer" }, + { .compatible =3D "rockchip,rk3399-timer" }, + { /* sentinel */ } +}; + +TIMER_PDEV_DECLARE(rk_timer, rk_timer_probe, NULL, rk_timer_match_table); --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9BC773FF89A for ; Fri, 27 Mar 2026 17:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634157; cv=none; b=EZ8XC1LxAiRXHImiZRoR1ktO8Qv/qTdvinqGRQ1Q8aVKVIeicJTqVBHy4BDbPIZr0Fk9wEtYR8RoIAJGYn1bY6hflDWiac10f+dVBtqWA3PYhSqfrMMfURnsWTFm5KArNLSgOCoTEHPKsbOYkHbyaeCRe2YrISnsbLYF5LwidrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634157; c=relaxed/simple; bh=m63W0gv+X0rmLX4ADUZdodixmhiFM20HW0wib0b4iYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jVFX6e34uc2EB6IXjhZVCaMS7dZLquqPfbUq6i/sxXmATHfls8QPGvN+CGR2eWknq88zKdIPOAmKhH7Dv43XTQUFFJucl2ZgOHNh/I1hWUCddPQayCMgRDme/5EgYSLHi8s2ox7I5QWH8dUmv7vHp7Epuy62WGmG+57TwkHvUCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YIMDgRAd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YIMDgRAd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C0DDC19423; Fri, 27 Mar 2026 17:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634157; bh=m63W0gv+X0rmLX4ADUZdodixmhiFM20HW0wib0b4iYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIMDgRAdtolmgCzvMmSISOy7L0yCu4a00GSpSZVKZEMWt37he6aoT1wO0TT6rlGSz 1QhsJeKu99EyQhTle6q7pRtI4+3oIxM3GCp+ldWHx7XN8IuDt4AQrLYR8qOf+gXn7t uNw6z1Q6AMPBrtk+dEO+uVBSTmBEinXbRUpDYvVdI63Zj4Wdvu1odX/cTfx63Gkkno s37RK2hzZygqYnuyPpPDKrWkCKLI8LLz2LclwgVlLNr7ShcP6MaDhtMp5ymuHXqw0L on2PLIzjCREGWVT94uPqiLDJfWIIJxCU+nO+4dIEA7S8SE4Sc7hUcvulCAAgH8OgW/ mTqkeqNGaqJUg== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/7] clocksource/drivers/mmio: Make the code compatible with modules Date: Fri, 27 Mar 2026 18:55:23 +0100 Message-ID: <20260327175533.3044-3-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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 next changes will bring the module support on the timer drivers. Those use the API exported by the mmio clocksource which are not exporting their symbols. Fix that by adding EXPORT_SYMBOL_GPL(). Signed-off-by: Daniel Lezcano --- drivers/clocksource/mmio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c index cd5fbf49ac29..0fee8edb837a 100644 --- a/drivers/clocksource/mmio.c +++ b/drivers/clocksource/mmio.c @@ -21,21 +21,25 @@ u64 clocksource_mmio_readl_up(struct clocksource *c) { return (u64)readl_relaxed(to_mmio_clksrc(c)->reg); } +EXPORT_SYMBOL_GPL(clocksource_mmio_readl_up); =20 u64 clocksource_mmio_readl_down(struct clocksource *c) { return ~(u64)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask; } +EXPORT_SYMBOL_GPL(clocksource_mmio_readl_down); =20 u64 clocksource_mmio_readw_up(struct clocksource *c) { return (u64)readw_relaxed(to_mmio_clksrc(c)->reg); } +EXPORT_SYMBOL_GPL(clocksource_mmio_readw_up); =20 u64 clocksource_mmio_readw_down(struct clocksource *c) { return ~(u64)readw_relaxed(to_mmio_clksrc(c)->reg) & c->mask; } +EXPORT_SYMBOL_GPL(clocksource_mmio_readw_down); =20 /** * clocksource_mmio_init - Initialize a simple mmio based clocksource @@ -46,9 +50,9 @@ u64 clocksource_mmio_readw_down(struct clocksource *c) * @bits: Number of valid bits * @read: One of clocksource_mmio_read*() above */ -int __init clocksource_mmio_init(void __iomem *base, const char *name, - unsigned long hz, int rating, unsigned bits, - u64 (*read)(struct clocksource *)) +int clocksource_mmio_init(void __iomem *base, const char *name, + unsigned long hz, int rating, unsigned bits, + u64 (*read)(struct clocksource *)) { struct clocksource_mmio *cs; =20 @@ -68,3 +72,4 @@ int __init clocksource_mmio_init(void __iomem *base, cons= t char *name, =20 return clocksource_register_hz(&cs->clksrc, hz); } +EXPORT_SYMBOL_GPL(clocksource_mmio_init); --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8BA3E3FEB1B for ; Fri, 27 Mar 2026 17:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634163; cv=none; b=Xw8RugT2IvVOse8Ii+rFvJIVzK3efIStPi+qoDYfO11p47Eg4MyflT6pXeWJDIW2myCPDY763fIHZs0pF6yqSB88/vmKVVOXddgocefDWhssKEIQged/2poyTFeePM9o6A/m3M/bDms7QoTWtLPvM83CXh7zcT48lI+edz18c+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634163; c=relaxed/simple; bh=Z2BA3YqAghsU/JejqCzKkjwpMzA7NGZMhKsDjlTJIog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TO3MQQKtF5xrsHt0piTKKq/6mSxrUTJeOSslLd5TceXafpysh9JCHWUITxJwmP73VvYl9AojOLeP9H6PHcngXAxHr42mifO3ufFbBfc3Df9RG1nJPD9lffWqGw2gpNDZatHwgKc7uTHmkhvZw7SqpTyHpUJXc7HXZxpelLOAqxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dq0GC/cZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dq0GC/cZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB67FC2BCB0; Fri, 27 Mar 2026 17:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634163; bh=Z2BA3YqAghsU/JejqCzKkjwpMzA7NGZMhKsDjlTJIog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dq0GC/cZt6iWn0Txmvp/XPTINB0Xcu0Y9e2HgNPt6xnrRljSAoONoYbydqR4iDKo+ hoQHstoNkHQ3Eye8P7LQnEMJWUuZQVUlyCVm9m0XZUdBgMUkDphMhiyY02L5/33tIG LBh8Rmn6KjikpAbjtfGtI5YgtYftF2Fp6qwYVcwRDU2OpDuVyaDTXn0c5/IYcAiTji GoaawlQo3kfj2TLs9MhlR4Ph2KLFHYKsAO0V+Q6z8mRVHW5UVmFOJWinXzaZxEV3FQ JTnnUjPx3vJoEjrpRvOBmtZUabfzaNaITNAwaMLf2OClbr6TvInVPgfPcSnsFIWDvu i82HBKsMtySLQ== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/7] clocksource/drivers/timer-of: Make the code compatible with modules Date: Fri, 27 Mar 2026 18:55:26 +0100 Message-ID: <20260327175533.3044-6-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-of.c | 24 +++++++++++++----------- drivers/clocksource/timer-of.h | 5 ++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c index 420202bf76e4..ba63433211b0 100644 --- a/drivers/clocksource/timer-of.c +++ b/drivers/clocksource/timer-of.c @@ -19,7 +19,7 @@ * * Free the irq resource */ -static __init void timer_of_irq_exit(struct of_timer_irq *of_irq) +static void timer_of_irq_exit(struct of_timer_irq *of_irq) { struct timer_of *to =3D container_of(of_irq, struct timer_of, of_irq); =20 @@ -41,8 +41,8 @@ static __init void timer_of_irq_exit(struct of_timer_irq = *of_irq) * * Returns 0 on success, < 0 otherwise */ -static __init int timer_of_irq_init(struct device_node *np, - struct of_timer_irq *of_irq) +static int timer_of_irq_init(struct device_node *np, + struct of_timer_irq *of_irq) { int ret; struct timer_of *to =3D container_of(of_irq, struct timer_of, of_irq); @@ -82,7 +82,7 @@ static __init int timer_of_irq_init(struct device_node *n= p, * * Disables and releases the refcount on the clk */ -static __init void timer_of_clk_exit(struct of_timer_clk *of_clk) +static void timer_of_clk_exit(struct of_timer_clk *of_clk) { of_clk->rate =3D 0; clk_disable_unprepare(of_clk->clk); @@ -98,8 +98,8 @@ static __init void timer_of_clk_exit(struct of_timer_clk = *of_clk) * * Returns 0 on success, < 0 otherwise */ -static __init int timer_of_clk_init(struct device_node *np, - struct of_timer_clk *of_clk) +static int timer_of_clk_init(struct device_node *np, + struct of_timer_clk *of_clk) { int ret; =20 @@ -137,13 +137,13 @@ static __init int timer_of_clk_init(struct device_nod= e *np, goto out; } =20 -static __init void timer_of_base_exit(struct of_timer_base *of_base) +static void timer_of_base_exit(struct of_timer_base *of_base) { iounmap(of_base->base); } =20 -static __init int timer_of_base_init(struct device_node *np, - struct of_timer_base *of_base) +static int timer_of_base_init(struct device_node *np, + struct of_timer_base *of_base) { of_base->base =3D of_base->name ? of_io_request_and_map(np, of_base->index, of_base->name) : @@ -156,7 +156,7 @@ static __init int timer_of_base_init(struct device_node= *np, return 0; } =20 -int __init timer_of_init(struct device_node *np, struct timer_of *to) +int timer_of_init(struct device_node *np, struct timer_of *to) { int ret =3D -EINVAL; int flags =3D 0; @@ -200,6 +200,7 @@ int __init timer_of_init(struct device_node *np, struct= timer_of *to) timer_of_base_exit(&to->of_base); return ret; } +EXPORT_SYMBOL_GPL(timer_of_init); =20 /** * timer_of_cleanup - release timer_of resources @@ -208,7 +209,7 @@ int __init timer_of_init(struct device_node *np, struct= timer_of *to) * Release the resources that has been used in timer_of_init(). * This function should be called in init error cases */ -void __init timer_of_cleanup(struct timer_of *to) +void timer_of_cleanup(struct timer_of *to) { if (to->flags & TIMER_OF_IRQ) timer_of_irq_exit(&to->of_irq); @@ -219,3 +220,4 @@ void __init timer_of_cleanup(struct timer_of *to) if (to->flags & TIMER_OF_BASE) timer_of_base_exit(&to->of_base); } +EXPORT_SYMBOL_GPL(timer_of_cleanup); diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h index 01a2c6b7db06..74a632b85b47 100644 --- a/drivers/clocksource/timer-of.h +++ b/drivers/clocksource/timer-of.h @@ -65,9 +65,8 @@ static inline unsigned long timer_of_period(struct timer_= of *to) return to->of_clk.period; } =20 -extern int __init timer_of_init(struct device_node *np, - struct timer_of *to); +int timer_of_init(struct device_node *np, struct timer_of *to); =20 -extern void __init timer_of_cleanup(struct timer_of *to); +void timer_of_cleanup(struct timer_of *to); =20 #endif --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B08383FEB27 for ; Fri, 27 Mar 2026 17:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634161; cv=none; b=hc+iz8y04L6J4MU2STvzEaEb8/iBZl2ME4r4j9/3MoiWoqyXJK5LVT3y0SvxaHdBdD0fFYvT3rL7E88wIHSjpfx95SCXffXarH0OgrVhek6KpkLY1OSPdJIoqiBsJVhGAPo3qAxgozg6eOWOXcLekG/cwXoQgdjw8l9WfSd+vSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634161; c=relaxed/simple; bh=m63W0gv+X0rmLX4ADUZdodixmhiFM20HW0wib0b4iYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iPx6eL2HJd3pSQlLeetSh9YmOrba+hU7EPzvGFD+QQJd6lL8Ky/RzhWVpgjT3oOp60Fr1JtIpx9flXIgAtMBIT3L06EzM5l0yB62ve/VubTIe3CEWq44dpVB8o21KkzqncNvjGpr8TWfEiXRTnofJEIpw6PPH0hxtXn9LjP+vCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ivgkJGlJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ivgkJGlJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21F1DC19424; Fri, 27 Mar 2026 17:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634161; bh=m63W0gv+X0rmLX4ADUZdodixmhiFM20HW0wib0b4iYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ivgkJGlJ7UzHqXzx9CWwk5IhcyAlzyVXXyMYBNgA5k2txkES240XK/aIru42lPJv9 RHTv27/MIiluuNSRn4+VoY0CgaHLsmd4wyvNcIZTyuS/ZuknujQ3iZo/q4OjPxzqW7 mFaN0Duvff3AN775EmqWw6K21OQ2pfXDpB4Ica5d7MiLzrvy8Usf2fHEamV2zKlLxT wLF2SHWc7MSlHsnuQCYVNmr4XnVyNRT/7GvHfzOq3W7JEN7yn9m/IYuSO0Bmv6r2dA bZBq+T6Y6Ysm4XEEwtuIC7c2mI3Cd54HX9gjLk06FeYXACFwHi1+AIWLhAY+WkZ2zr 2YMNAj+YogQhw== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/7] clocksource/drivers/mmio: Make the code compatible with modules Date: Fri, 27 Mar 2026 18:55:25 +0100 Message-ID: <20260327175533.3044-5-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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 next changes will bring the module support on the timer drivers. Those use the API exported by the mmio clocksource which are not exporting their symbols. Fix that by adding EXPORT_SYMBOL_GPL(). Signed-off-by: Daniel Lezcano --- drivers/clocksource/mmio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c index cd5fbf49ac29..0fee8edb837a 100644 --- a/drivers/clocksource/mmio.c +++ b/drivers/clocksource/mmio.c @@ -21,21 +21,25 @@ u64 clocksource_mmio_readl_up(struct clocksource *c) { return (u64)readl_relaxed(to_mmio_clksrc(c)->reg); } +EXPORT_SYMBOL_GPL(clocksource_mmio_readl_up); =20 u64 clocksource_mmio_readl_down(struct clocksource *c) { return ~(u64)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask; } +EXPORT_SYMBOL_GPL(clocksource_mmio_readl_down); =20 u64 clocksource_mmio_readw_up(struct clocksource *c) { return (u64)readw_relaxed(to_mmio_clksrc(c)->reg); } +EXPORT_SYMBOL_GPL(clocksource_mmio_readw_up); =20 u64 clocksource_mmio_readw_down(struct clocksource *c) { return ~(u64)readw_relaxed(to_mmio_clksrc(c)->reg) & c->mask; } +EXPORT_SYMBOL_GPL(clocksource_mmio_readw_down); =20 /** * clocksource_mmio_init - Initialize a simple mmio based clocksource @@ -46,9 +50,9 @@ u64 clocksource_mmio_readw_down(struct clocksource *c) * @bits: Number of valid bits * @read: One of clocksource_mmio_read*() above */ -int __init clocksource_mmio_init(void __iomem *base, const char *name, - unsigned long hz, int rating, unsigned bits, - u64 (*read)(struct clocksource *)) +int clocksource_mmio_init(void __iomem *base, const char *name, + unsigned long hz, int rating, unsigned bits, + u64 (*read)(struct clocksource *)) { struct clocksource_mmio *cs; =20 @@ -68,3 +72,4 @@ int __init clocksource_mmio_init(void __iomem *base, cons= t char *name, =20 return clocksource_register_hz(&cs->clksrc, hz); } +EXPORT_SYMBOL_GPL(clocksource_mmio_init); --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 823F7401A3B for ; Fri, 27 Mar 2026 17:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634167; cv=none; b=MixHHLl7q1xpqCGFKJT49sgSiZvvSLM2hoYRzzeqPNrdQEwm4XQdyno1cZhRL4pIamhW/yiEq1JuyHUzkfu+jlqUrcH2ZtadLppiQGsEm1UgrmNzRPa4kLCo0i8OU3bVQIKI7nArbz19yaMoPBkH1wyqX0Ry2rZQC0Trf69XB/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634167; c=relaxed/simple; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsEWcdwx63sj5k8i6TJF2GA3Tyyb2fNLgxUkbcK9sfSBF5P0bIUtgNVqQOKRSrMCWliKRe4U9hpyfaI3/UMl8FIclO9Gg6S3noMVl8zQvEczJ+SNzKxSkWHdriLeGwD5cBV71VBRH7HURL0ORlMN537AOixNPcLJl2hgjIlVyqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D1q/mDp/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D1q/mDp/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99585C19423; Fri, 27 Mar 2026 17:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634167; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D1q/mDp/DN3EKl2dGMOVeEsMvxgJQegnM8Dp1WAPLQl0o244c8mCuZSY6FlLE4Jtt ByoPqAAH12ozK89Twejj5ndAHAHq2MHMv36TERu4XuqESkpyw3z+h+D701Bj2ylxDe VInfh+iFKl8XodpzXAgK/rCpFojtjswA8o2hP4pmD2raXVaJ+CIa/MQlEMb+8Hif6y INjyLNelcvIYc0ez3CWwN4HPt0/Fo+4xiXa7nErZ6MQUi6emXptROfbcmubFukU35K psuptuQjp0Rv2LtskzudJ9AZbPKqu1OZ29Mkh6ZHcGbN/wBpZJJ5XgbRKWXhPDYMCb EElQ4DdrfFSoA== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Stephen Boyd Subject: [PATCH v1 4/7] clocksource/drivers/timer-probe: Add the module support for the TIMER_PDEV_DECLARE() macro Date: Fri, 27 Mar 2026 18:55:28 +0100 Message-ID: <20260327175533.3044-8-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" A driver using the macro TIMER_PDEV_DECLARE can now be compiled as a module. When it is the case the TIMER_PDEV_DECLARE() macro will add module_platform_driver() and MODULE_DEVICE_TABLE() automatically. However if the early timer initialization is needed in place of the module init section like what we have now, we should enable CONFIG_EARLY_TIMER. When all drivers will be converted to TIMER_PDEV_DECLARE(), the TIMER_OF_DECLARE() can be removed and we will end up with the following configuration: * On ARM architecture, we enable automatically CONFIG_EARLY_TIMER, no timer can be compiled as a module * On ARM64 architecture, we can enable as a module, otherwise it will be compiled-in. The CONFIG_EARLY_TIMER is not needed on this arch because the architected timers are always present * On other architecture, that needs to be defined but I suspect we have the same scheme Signed-off-by: Daniel Lezcano --- drivers/clocksource/Kconfig | 7 ++++++- drivers/clocksource/timer-probe.c | 3 +++ include/linux/clocksource.h | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index fd9112706545..ee2372f21e78 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -2,6 +2,11 @@ menu "Clock Source drivers" depends on GENERIC_CLOCKEVENTS =20 +config EARLY_TIMER + bool "Early driver initialization" + help + Enables early timer driver loading + config TIMER_OF bool select TIMER_PROBE @@ -100,7 +105,7 @@ config IXP4XX_TIMER Enables support for the Intel XScale IXP4xx SoC timer. =20 config ROCKCHIP_TIMER - bool "Rockchip timer driver" if COMPILE_TEST + bool "Rockchip timer driver" if COMPILE_TEST depends on ARM || ARM64 select TIMER_OF select CLKSRC_MMIO diff --git a/drivers/clocksource/timer-probe.c b/drivers/clocksource/timer-= probe.c index cdaceb68d356..0fc582e4afde 100644 --- a/drivers/clocksource/timer-probe.c +++ b/drivers/clocksource/timer-probe.c @@ -84,6 +84,9 @@ static int __init timer_pdev_probe(void) { struct platform_driver **drv; =20 + if (!IS_ENABLED(CONFIG_EARLY_TIMER)) + return 0; + for_each_pdev_timer_table(drv) __timer_pdev_probe(*drv); =20 diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 6e05b78e64b8..6b09fe67d37f 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -299,7 +299,7 @@ static inline void timer_probe(void) {} extern struct platform_driver *__pdev_timer_table[]; extern struct platform_driver *__pdev_timer_table_end[]; =20 -#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ +#define __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ static struct platform_driver __pdev_timer_table_entry_##__name =3D { \ .probe =3D __probe, \ .remove =3D __remove, \ @@ -311,6 +311,16 @@ extern struct platform_driver *__pdev_timer_table_end[= ]; static struct platform_driver *___pdev_timer_table_entry_##__name \ __used __section("__pdev_timer_table") =3D &__pdev_timer_table_entry_##__= name =20 +#if !defined(CONFIG_EARLY_TIMER) || defined(MODULE) +#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ + MODULE_DEVICE_TABLE(of, __match); \ + __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match); \ + module_platform_driver(__pdev_timer_table_entry_##__name); +#else +#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ + __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) +#endif + #define for_each_pdev_timer_table(__pdev) \ for (__pdev =3D __pdev_timer_table; \ __pdev < __pdev_timer_table_end; \ --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7ABD33FFAB8 for ; Fri, 27 Mar 2026 17:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634165; cv=none; b=pATbGKHrgktPhFlx7o5mQbjq0N5V2E2OFYnOp036zCVg/xp78DPfJGEZiDcIhJPN5zfXQL30e24eux1/dKJM1Htz9+tbJu1Mv1KlxSzkkKMqP3Qi238QuyOfnfmqnEOsx5YTYt+w6gzSDk1Zn38cmPxjwGTAU5UTUmf++hSxi9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634165; c=relaxed/simple; bh=Z2BA3YqAghsU/JejqCzKkjwpMzA7NGZMhKsDjlTJIog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AgWBvmDm6D2U57MSW+tiMOkJj6ghwWCWW4sCCHDZtFf++KHKw49vgE34gwXPv4v559nHxK/LQT0sP1OvsN81XpOdOWE697eTefpshM+KPQ/xzDypaaPvdon3xc5Vyz1hAjDNsnR63WJwImy8tT4tsFwdpafMzUnR4oFPQA6cXIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gxi8gXhl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gxi8gXhl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDAFFC2BCB0; Fri, 27 Mar 2026 17:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634165; bh=Z2BA3YqAghsU/JejqCzKkjwpMzA7NGZMhKsDjlTJIog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gxi8gXhlolXeMflMMlGQ2L3CT/hC44QFjy3SSMD4IHVkt3CFrkBNeO+9UuyfkhtBh EG9E0OS2ro6TZEmD0QaL1cSZ5bsUMQKOkqqGpn2id7n9yIklRRAn5ojZvStt2INGUk 8Zv+vHQ3C0pI2JzLsT0N1j4HquLu6hCNWh8AvqkEnK+H0uib40zNJnadKm2WrvXSoL 6RMmEffHWO/wLaUlqZrsE+VW5RB6e6tYSgbPkx6ZlS+d2Un9GxwCndmI7jwh39yv1y vX9vwfA0psCgXd40RZxQi44FdNa11vgQUKapFzdE74X0zkmfVu2sX9b2A7T51XPOqG jaMiODd54vOLA== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/7] clocksource/drivers/timer-of: Make the code compatible with modules Date: Fri, 27 Mar 2026 18:55:27 +0100 Message-ID: <20260327175533.3044-7-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-of.c | 24 +++++++++++++----------- drivers/clocksource/timer-of.h | 5 ++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c index 420202bf76e4..ba63433211b0 100644 --- a/drivers/clocksource/timer-of.c +++ b/drivers/clocksource/timer-of.c @@ -19,7 +19,7 @@ * * Free the irq resource */ -static __init void timer_of_irq_exit(struct of_timer_irq *of_irq) +static void timer_of_irq_exit(struct of_timer_irq *of_irq) { struct timer_of *to =3D container_of(of_irq, struct timer_of, of_irq); =20 @@ -41,8 +41,8 @@ static __init void timer_of_irq_exit(struct of_timer_irq = *of_irq) * * Returns 0 on success, < 0 otherwise */ -static __init int timer_of_irq_init(struct device_node *np, - struct of_timer_irq *of_irq) +static int timer_of_irq_init(struct device_node *np, + struct of_timer_irq *of_irq) { int ret; struct timer_of *to =3D container_of(of_irq, struct timer_of, of_irq); @@ -82,7 +82,7 @@ static __init int timer_of_irq_init(struct device_node *n= p, * * Disables and releases the refcount on the clk */ -static __init void timer_of_clk_exit(struct of_timer_clk *of_clk) +static void timer_of_clk_exit(struct of_timer_clk *of_clk) { of_clk->rate =3D 0; clk_disable_unprepare(of_clk->clk); @@ -98,8 +98,8 @@ static __init void timer_of_clk_exit(struct of_timer_clk = *of_clk) * * Returns 0 on success, < 0 otherwise */ -static __init int timer_of_clk_init(struct device_node *np, - struct of_timer_clk *of_clk) +static int timer_of_clk_init(struct device_node *np, + struct of_timer_clk *of_clk) { int ret; =20 @@ -137,13 +137,13 @@ static __init int timer_of_clk_init(struct device_nod= e *np, goto out; } =20 -static __init void timer_of_base_exit(struct of_timer_base *of_base) +static void timer_of_base_exit(struct of_timer_base *of_base) { iounmap(of_base->base); } =20 -static __init int timer_of_base_init(struct device_node *np, - struct of_timer_base *of_base) +static int timer_of_base_init(struct device_node *np, + struct of_timer_base *of_base) { of_base->base =3D of_base->name ? of_io_request_and_map(np, of_base->index, of_base->name) : @@ -156,7 +156,7 @@ static __init int timer_of_base_init(struct device_node= *np, return 0; } =20 -int __init timer_of_init(struct device_node *np, struct timer_of *to) +int timer_of_init(struct device_node *np, struct timer_of *to) { int ret =3D -EINVAL; int flags =3D 0; @@ -200,6 +200,7 @@ int __init timer_of_init(struct device_node *np, struct= timer_of *to) timer_of_base_exit(&to->of_base); return ret; } +EXPORT_SYMBOL_GPL(timer_of_init); =20 /** * timer_of_cleanup - release timer_of resources @@ -208,7 +209,7 @@ int __init timer_of_init(struct device_node *np, struct= timer_of *to) * Release the resources that has been used in timer_of_init(). * This function should be called in init error cases */ -void __init timer_of_cleanup(struct timer_of *to) +void timer_of_cleanup(struct timer_of *to) { if (to->flags & TIMER_OF_IRQ) timer_of_irq_exit(&to->of_irq); @@ -219,3 +220,4 @@ void __init timer_of_cleanup(struct timer_of *to) if (to->flags & TIMER_OF_BASE) timer_of_base_exit(&to->of_base); } +EXPORT_SYMBOL_GPL(timer_of_cleanup); diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h index 01a2c6b7db06..74a632b85b47 100644 --- a/drivers/clocksource/timer-of.h +++ b/drivers/clocksource/timer-of.h @@ -65,9 +65,8 @@ static inline unsigned long timer_of_period(struct timer_= of *to) return to->of_clk.period; } =20 -extern int __init timer_of_init(struct device_node *np, - struct timer_of *to); +int timer_of_init(struct device_node *np, struct timer_of *to); =20 -extern void __init timer_of_cleanup(struct timer_of *to); +void timer_of_cleanup(struct timer_of *to); =20 #endif --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 724FA402447 for ; Fri, 27 Mar 2026 17:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634169; cv=none; b=lhY3+sVOWmjnK/gMRJKtUX4v1MPWad9vtxlOGEN/F4fNX689pFeoo95rtMSI8ovRd1S3SisL4rlGXwldgQXJYVc2Ij8qzK4KmDYi2YP+srr6b7A/4md021iyWuhVaKC5BTZbZynKAW6PtZm/M/kIW34So0aXRZ/k/74LHddNU68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634169; c=relaxed/simple; bh=NF+8zTAwUcyuWSbqAv5EfRD6h1aQWSDUVa0i+26A4WM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mym7SV7v/KMShGVGL0aMrkV32WRNjwxgQ4jBUZ47hzxCChNolxRNyrfH2iVPTxKkn5y8atXMuYhoXRl3zfvkQa+1ud1kyNtpWf5koFJxVv+sFhM5icN1x716I6aCSOD4KaafI4/E+yxgaG7zBQ6u0rSf4feuBDcijJWYpju6XU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EMU/UO7y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EMU/UO7y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93FA0C19424; Fri, 27 Mar 2026 17:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634169; bh=NF+8zTAwUcyuWSbqAv5EfRD6h1aQWSDUVa0i+26A4WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EMU/UO7yah7g58RdvelfWdTFJBeJqtlzqv45Uj99/U3yCbHikW6Vv5l7/fGocFQDi UR4GnW8KnjtDfdxl5BuXD0Ya3XLMB6ULG88BI6dCK57wZ99SVgOzQC2x41Ie1T8D+m njGPSiFyjZuDovWB99aKusvSiE8HEDLkb3dfNJRjTnOyVE9U3t6o/TC1KIu6P2R/Iy kmP7KS6/ZAFwuNpdzaPk/xgWvIi4M2h1nJCa0/U7Q9j+5UEIA2m6TVShlHIy5txF5V /fIgLaW3QpmY8jqWPnDOY4pYqvKecD+HewBpObjbS/n7Yv2LmNHFSiReTRQDAqMnFw fWsDNJwttLFbw== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Heiko Stuebner , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH v1 5/7] clocksource/drivers/rockchip: Use the TIMER_PDEV_DECLARE() macro Date: Fri, 27 Mar 2026 18:55:29 +0100 Message-ID: <20260327175533.3044-9-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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 previous changes introduced the TIMER_PDEV_DECLARE() macro which allows to use the platform driver to initialize a timer driver with the benefit of having the devres to rollback automatically in case of error. Use this macro and change the function to rely on the devm_ variants, allowing to cleanup the code. Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-rockchip.c | 99 ++++++++++------------------ 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/drivers/clocksource/timer-rockchip.c b/drivers/clocksource/tim= er-rockchip.c index 540a16667145..486bbffba464 100644 --- a/drivers/clocksource/timer-rockchip.c +++ b/drivers/clocksource/timer-rockchip.c @@ -124,18 +124,18 @@ static u64 notrace rk_timer_sched_read(void) return ~readl_relaxed(rk_clksrc->base + TIMER_CURRENT_VALUE0); } =20 -static int __init -rk_timer_probe(struct rk_timer *timer, struct device_node *np) +static int rk_timer_init(struct rk_timer *timer, struct device *dev) { + struct device_node *np =3D dev->of_node; struct clk *timer_clk; struct clk *pclk; - int ret =3D -EINVAL, irq; + int irq; u32 ctrl_reg =3D TIMER_CONTROL_REG3288; =20 - timer->base =3D of_iomap(np, 0); - if (!timer->base) { + timer->base =3D devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(timer->base)) { pr_err("Failed to get base address for '%s'\n", TIMER_NAME); - return -ENXIO; + return PTR_ERR(timer->base); } =20 if (of_device_is_compatible(np, "rockchip,rk3399-timer")) @@ -143,31 +143,17 @@ rk_timer_probe(struct rk_timer *timer, struct device_= node *np) =20 timer->ctrl =3D timer->base + ctrl_reg; =20 - pclk =3D of_clk_get_by_name(np, "pclk"); + pclk =3D devm_clk_get_enabled(dev, "pclk"); if (IS_ERR(pclk)) { - ret =3D PTR_ERR(pclk); pr_err("Failed to get pclk for '%s'\n", TIMER_NAME); - goto out_unmap; - } - - ret =3D clk_prepare_enable(pclk); - if (ret) { - pr_err("Failed to enable pclk for '%s'\n", TIMER_NAME); - goto out_unmap; + return PTR_ERR(pclk); } timer->pclk =3D pclk; =20 - timer_clk =3D of_clk_get_by_name(np, "timer"); + timer_clk =3D devm_clk_get_enabled(dev, "timer"); if (IS_ERR(timer_clk)) { - ret =3D PTR_ERR(timer_clk); pr_err("Failed to get timer clock for '%s'\n", TIMER_NAME); - goto out_timer_clk; - } - - ret =3D clk_prepare_enable(timer_clk); - if (ret) { - pr_err("Failed to enable timer clock\n"); - goto out_timer_clk; + return PTR_ERR(timer_clk); } timer->clk =3D timer_clk; =20 @@ -175,47 +161,32 @@ rk_timer_probe(struct rk_timer *timer, struct device_= node *np) =20 irq =3D irq_of_parse_and_map(np, 0); if (!irq) { - ret =3D -EINVAL; pr_err("Failed to map interrupts for '%s'\n", TIMER_NAME); - goto out_irq; + return -EINVAL; } timer->irq =3D irq; =20 rk_timer_interrupt_clear(timer); rk_timer_disable(timer); - return 0; - -out_irq: - clk_disable_unprepare(timer_clk); -out_timer_clk: - clk_disable_unprepare(pclk); -out_unmap: - iounmap(timer->base); - - return ret; -} =20 -static void __init rk_timer_cleanup(struct rk_timer *timer) -{ - clk_disable_unprepare(timer->clk); - clk_disable_unprepare(timer->pclk); - iounmap(timer->base); + return 0; } =20 -static int __init rk_clkevt_init(struct device_node *np) +static int rk_clkevt_init(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; struct clock_event_device *ce; int ret =3D -EINVAL; =20 - rk_clkevt =3D kzalloc_obj(struct rk_clkevt); + rk_clkevt =3D devm_kzalloc(dev, sizeof(*rk_clkevt), GFP_KERNEL); if (!rk_clkevt) { ret =3D -ENOMEM; goto out; } =20 - ret =3D rk_timer_probe(&rk_clkevt->timer, np); + ret =3D rk_timer_init(&rk_clkevt->timer, dev); if (ret) - goto out_probe; + goto out; =20 ce =3D &rk_clkevt->ce; ce->name =3D TIMER_NAME; @@ -233,36 +204,33 @@ static int __init rk_clkevt_init(struct device_node *= np) if (ret) { pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); - goto out_irq; + goto out; } =20 clockevents_config_and_register(&rk_clkevt->ce, rk_clkevt->timer.freq, 1, UINT_MAX); return 0; =20 -out_irq: - rk_timer_cleanup(&rk_clkevt->timer); -out_probe: - kfree(rk_clkevt); out: /* Leave rk_clkevt not NULL to prevent future init */ rk_clkevt =3D ERR_PTR(ret); return ret; } =20 -static int __init rk_clksrc_init(struct device_node *np) +static int rk_clksrc_init(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; int ret =3D -EINVAL; =20 - rk_clksrc =3D kzalloc_obj(struct rk_timer); + rk_clksrc =3D devm_kzalloc(dev, sizeof(*rk_clksrc), GFP_KERNEL); if (!rk_clksrc) { ret =3D -ENOMEM; goto out; } =20 - ret =3D rk_timer_probe(rk_clksrc, np); + ret =3D rk_timer_init(rk_clksrc, dev); if (ret) - goto out_probe; + goto out; =20 rk_timer_update_counter(UINT_MAX, rk_clksrc); rk_timer_enable(rk_clksrc, 0); @@ -272,33 +240,34 @@ static int __init rk_clksrc_init(struct device_node *= np) clocksource_mmio_readl_down); if (ret) { pr_err("Failed to register clocksource\n"); - goto out_clocksource; + goto out; } =20 sched_clock_register(rk_timer_sched_read, 32, rk_clksrc->freq); return 0; =20 -out_clocksource: - rk_timer_cleanup(rk_clksrc); -out_probe: - kfree(rk_clksrc); out: /* Leave rk_clksrc not NULL to prevent future init */ rk_clksrc =3D ERR_PTR(ret); return ret; } =20 -static int __init rk_timer_init(struct device_node *np) +static int rk_timer_probe(struct platform_device *pdev) { if (!rk_clkevt) - return rk_clkevt_init(np); + return rk_clkevt_init(pdev); =20 if (!rk_clksrc) - return rk_clksrc_init(np); + return rk_clksrc_init(pdev); =20 pr_err("Too many timer definitions for '%s'\n", TIMER_NAME); return -EINVAL; } =20 -TIMER_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer", rk_timer_init); -TIMER_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer", rk_timer_init); +static const struct of_device_id rk_timer_match_table[] =3D { + { .compatible =3D "rockchip,rk3288-timer" }, + { .compatible =3D "rockchip,rk3399-timer" }, + { /* sentinel */ } +}; + +TIMER_PDEV_DECLARE(rk_timer, rk_timer_probe, NULL, rk_timer_match_table); --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 740B040243E for ; Fri, 27 Mar 2026 17:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634171; cv=none; b=jtBDHIKKHx211QjZtRrFl0BzX5Nw9BTCAvbeGJ05L58bEMqwego6iUKHghxbbqTD6eT9Ms6VFgQBArnLk/jfmrPdUHtM+53E7qiWljNUey6rJt5zMvblwuwNL7en7jO4N8NQ7E0pK0akJbiDHKtc7IS0X6/MzHxpTuyg3TrWwxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634171; c=relaxed/simple; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=exm8fR7LHJvFtdISnEagf2Sw1hN45MJgeky+7mzmZf2eUeSAENkYaTUAN1myzz5/ej0UvkMiG/dOJvl3EXf3OKEmZDbMEuGYFVKJkk63LhAWYPJ3T0PcAVpeCn1RPInXPo0vkstuFQf07H6nAREHR51ftys2hYgmGnLKd0p8iww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o9f3nN5E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o9f3nN5E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5CF1C2BC9E; Fri, 27 Mar 2026 17:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634171; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o9f3nN5EsoMfc1D8Ccn6vW5u4ISGUpOOaOUWuZy5jFd/YQTA/L0jnNY0ujY6cdgFu nC3axot8CTzM2dDy9dS/IkkU09Z524qWA6O4GfZDmTG6117GfLE0a7rk8WG7/ZMKY1 ZHf+7Q2J04V9mX/S5TLGA0j0Ug7AYriIyKPpDhOGGVdHbZ+vMRjMgWyhaFCQWAYSFD 9zonr09JWtvbJxtAyvmmw2jlpCHT0NSjAw/wTNGmLr+INS5lTO789AmjoaQ1fV0cFA YXZ6bXCIaHLaquqBcKEop3kNo+v7gtlOc9bRgvJtetcqTHfEVAAtaCp/Whlse+L1Ob 6Nen6K2i+858g== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Stephen Boyd Subject: [PATCH v1 5/7] clocksource/drivers/timer-probe: Add the module support for the TIMER_PDEV_DECLARE() macro Date: Fri, 27 Mar 2026 18:55:30 +0100 Message-ID: <20260327175533.3044-10-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" A driver using the macro TIMER_PDEV_DECLARE can now be compiled as a module. When it is the case the TIMER_PDEV_DECLARE() macro will add module_platform_driver() and MODULE_DEVICE_TABLE() automatically. However if the early timer initialization is needed in place of the module init section like what we have now, we should enable CONFIG_EARLY_TIMER. When all drivers will be converted to TIMER_PDEV_DECLARE(), the TIMER_OF_DECLARE() can be removed and we will end up with the following configuration: * On ARM architecture, we enable automatically CONFIG_EARLY_TIMER, no timer can be compiled as a module * On ARM64 architecture, we can enable as a module, otherwise it will be compiled-in. The CONFIG_EARLY_TIMER is not needed on this arch because the architected timers are always present * On other architecture, that needs to be defined but I suspect we have the same scheme Signed-off-by: Daniel Lezcano --- drivers/clocksource/Kconfig | 7 ++++++- drivers/clocksource/timer-probe.c | 3 +++ include/linux/clocksource.h | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index fd9112706545..ee2372f21e78 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -2,6 +2,11 @@ menu "Clock Source drivers" depends on GENERIC_CLOCKEVENTS =20 +config EARLY_TIMER + bool "Early driver initialization" + help + Enables early timer driver loading + config TIMER_OF bool select TIMER_PROBE @@ -100,7 +105,7 @@ config IXP4XX_TIMER Enables support for the Intel XScale IXP4xx SoC timer. =20 config ROCKCHIP_TIMER - bool "Rockchip timer driver" if COMPILE_TEST + bool "Rockchip timer driver" if COMPILE_TEST depends on ARM || ARM64 select TIMER_OF select CLKSRC_MMIO diff --git a/drivers/clocksource/timer-probe.c b/drivers/clocksource/timer-= probe.c index cdaceb68d356..0fc582e4afde 100644 --- a/drivers/clocksource/timer-probe.c +++ b/drivers/clocksource/timer-probe.c @@ -84,6 +84,9 @@ static int __init timer_pdev_probe(void) { struct platform_driver **drv; =20 + if (!IS_ENABLED(CONFIG_EARLY_TIMER)) + return 0; + for_each_pdev_timer_table(drv) __timer_pdev_probe(*drv); =20 diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 6e05b78e64b8..6b09fe67d37f 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -299,7 +299,7 @@ static inline void timer_probe(void) {} extern struct platform_driver *__pdev_timer_table[]; extern struct platform_driver *__pdev_timer_table_end[]; =20 -#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ +#define __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ static struct platform_driver __pdev_timer_table_entry_##__name =3D { \ .probe =3D __probe, \ .remove =3D __remove, \ @@ -311,6 +311,16 @@ extern struct platform_driver *__pdev_timer_table_end[= ]; static struct platform_driver *___pdev_timer_table_entry_##__name \ __used __section("__pdev_timer_table") =3D &__pdev_timer_table_entry_##__= name =20 +#if !defined(CONFIG_EARLY_TIMER) || defined(MODULE) +#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ + MODULE_DEVICE_TABLE(of, __match); \ + __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match); \ + module_platform_driver(__pdev_timer_table_entry_##__name); +#else +#define TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) \ + __TIMER_PDEV_DECLARE(__name, __probe, __remove, __match) +#endif + #define for_each_pdev_timer_table(__pdev) \ for (__pdev =3D __pdev_timer_table; \ __pdev < __pdev_timer_table_end; \ --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D85FB4035C9 for ; Fri, 27 Mar 2026 17:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634173; cv=none; b=Ycp6D8+raG6zAqWH7RL0fjh2/ikwzzO3YCc+WmW/sMk7zK6AIZg+3ENUXwTJ3wOlOxb3bvAdQ9HzEr2AQppqgKBUaHruvLAVbinxRdl69jRKhck9lUb979o01NDvYDE3ONLtW2pBcavphURP078cv/RoL9us8C9lzcHV8vlRAyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634173; c=relaxed/simple; bh=vEdr7EPXzpO1kaiix0EvAxi+W/Op3ANhnxGGu30cNiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxRSP6AQpWnf1M5dcx9OS/bX/dOB2f+wYZoQNm91nDr8m/wh1vAKShsKFhNzIY+QpD7VjBAWEERvwUltXGXzZzKbsdHWGU0/RehmelcRLQseXelQy6Xghskyv3+f61dvl9Pg4FiPW7zFUsjhRkkwYVtrBfZ++20cgBJzwW0Peqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mXyJXV4g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mXyJXV4g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D908CC4AF09; Fri, 27 Mar 2026 17:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634173; bh=vEdr7EPXzpO1kaiix0EvAxi+W/Op3ANhnxGGu30cNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXyJXV4g4qysYi+mmyLXrAxwK05bu9xhANdW1jwCIgQAlR9qmyUMqmzGNlKxNoeqh gZYCDSJsvhZ87sUtZEJqodSbljBNVnrqQu2S/85TnkzrS2me6nCuKcOauew0A73QL3 uzRgVt0+tfMOObhQat8QM876gkW2jztdXVT8+HXZxr4cIXVtolQREv1E9QTAoKXBQG Cl7JYACYUy0mg0wVoPwHl1nZORuhx3ICeQv8y3H3nv5sBH6qU0MNthWv59y2UYBmeM 9LZFuDZi0flPbuY98HdbSwtK3imPEuqLGmxGRhpBDvd3j2QF7QaAn5KF72p4svw2aJ 3ABIbWDMEzeYQ== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Heiko Stuebner , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH v1 6/7] clocksource/drivers/rockchip: Add rockchip timer module support Date: Fri, 27 Mar 2026 18:55:31 +0100 Message-ID: <20260327175533.3044-11-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" Now the TIMER_PDEV_DECLARE() allows the driver to be compiled as a module. Add the MODULE_DESCRIPTION and the MODULE_LICENSE left for the one converting the driver as a module. Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-rockchip.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/clocksource/timer-rockchip.c b/drivers/clocksource/tim= er-rockchip.c index 486bbffba464..61433b295882 100644 --- a/drivers/clocksource/timer-rockchip.c +++ b/drivers/clocksource/timer-rockchip.c @@ -271,3 +271,5 @@ static const struct of_device_id rk_timer_match_table[]= =3D { }; =20 TIMER_PDEV_DECLARE(rk_timer, rk_timer_probe, NULL, rk_timer_match_table); +MODULE_DESCRIPTION("Rockchip timer driver"); +MODULE_LICENSE("GPL"); --=20 2.43.0 From nobody Thu Apr 2 15:35:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 88E404014B5 for ; Fri, 27 Mar 2026 17:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634176; cv=none; b=QP6rzyYYZxgycwnkgMiI/6kDBHPVXrtugspQQdSPOW0H299+2hKm28qnFaCmRjsL8rusFa6nogZnErWqF0NAjmuQDO7xMWb3uUtQI2sFF81K4gMYcO7uw8IdOwWVTsWP8mpDwcBwxJtmUwzVcB/24XVkejplGSc9N6VchEdbTq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634176; c=relaxed/simple; bh=SQ5nAKYuYrS/ghYaKZeLV4R3AbXgYqFqYO/0dF0j/aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NFNg0YAZGVPegR1dJAuxKBbBfla4Cq2pNL7dwAH3MqiyEAm78b2oRYUBzVghqhNI3fnPwHzTyPvjIZDb/RzaBDDaeY8PBNbpqqMlwF14hD1v9PxYsilsdKVtFPatYngmBrtAddenTAzszVeR3uMk/DUpAM6ncP2o+Jn3FafU3+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dZo3NmGw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dZo3NmGw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3037EC2BCB0; Fri, 27 Mar 2026 17:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634176; bh=SQ5nAKYuYrS/ghYaKZeLV4R3AbXgYqFqYO/0dF0j/aU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dZo3NmGwecP8iLMlnr6gvtr8rW/uzyZwWOMIiJBH2Mh5oH+5U3Vt2TEkRcSFpztzX kSGoCbEzvpVdKtlXr6LvaZ7OKoFeLAdDpZXRp3AANg1wGD+Bh5LlnjmrOqhg6A782l frEC+1oqBxC2odsVETOxkYQcrLBs+zyCcN3VMr9ElLRrU5qa/XEeW0VIXycBcZ5c/W bmfCm0i6hdkPO1o3u2NxqgaxMk0rXTHZj+LAuOplaPWyazKcFCwQF3KMvZnQlxZnGs 491fzBCiU8TjwWTmEpe6WromBdCWxSmQOoarHfcIyKQ8C7QB/E/xymYDHF9mseNRLo 1lQlZTHoicePQ== From: Daniel Lezcano To: daniel.lezcano@kernel.org, tglx@kernel.org, zhipeng.wang_1@nxp.com Cc: shawnguo@kernel.org, jstultz@google.com, linux-kernel@vger.kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support) Subject: [PATCH v1 7/7] clocksource/drivers/mediatek: Convert to module support Date: Fri, 27 Mar 2026 18:55:32 +0100 Message-ID: <20260327175533.3044-12-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327175533.3044-1-daniel.lezcano@kernel.org> References: <20260327175533.3044-1-daniel.lezcano@kernel.org> 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" Now the TIMER_PDEV_DECLARE() allows the driver to be compiled as a module. Add the MODULE_DESCRIPTION and the MODULE_LICENSE left for the one converting the driver as a module. Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-mediatek.c | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/timer-mediatek.c b/drivers/clocksource/tim= er-mediatek.c index 7bcb4a3f26fb..f5de5f397730 100644 --- a/drivers/clocksource/timer-mediatek.c +++ b/drivers/clocksource/timer-mediatek.c @@ -215,8 +215,7 @@ static irqreturn_t mtk_gpt_interrupt(int irq, void *dev= _id) return IRQ_HANDLED; } =20 -static void -__init mtk_gpt_setup(struct timer_of *to, u8 timer, u8 option) +static void mtk_gpt_setup(struct timer_of *to, u8 timer, u8 option) { writel(GPT_CTRL_CLEAR | GPT_CTRL_DISABLE, timer_of_base(to) + GPT_CTRL_REG(timer)); @@ -281,7 +280,7 @@ static struct timer_of to =3D { }, }; =20 -static int __init mtk_syst_init(struct device_node *node) +static int mtk_syst_init(struct device_node *node) { int ret; =20 @@ -302,7 +301,7 @@ static int __init mtk_syst_init(struct device_node *nod= e) return 0; } =20 -static int __init mtk_gpt_init(struct device_node *node) +static int mtk_gpt_init(struct device_node *node) { int ret; =20 @@ -337,5 +336,23 @@ static int __init mtk_gpt_init(struct device_node *nod= e) =20 return 0; } -TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init); -TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init); + +static int mtk_timer_probe(struct platform_device *pdev) +{ + struct device_node *np =3D pdev->dev.of_node; + int (*probe_func)(struct device_node *node); + + probe_func =3D of_device_get_match_data(&pdev->dev); + + return probe_func(np); +} + +static const struct of_device_id mtk_timer_match_table[] =3D { + { .compatible =3D "mediatek,mt6577-timer", .data =3D mtk_gpt_init }, + { .compatible =3D "mediatek,mt6765-timer", .data =3D mtk_syst_init }, + { /* sentinel */ } +}; + +TIMER_PDEV_DECLARE(mtk_timer, mtk_timer_probe, NULL, mtk_timer_match_table= ); +MODULE_DESCRIPTION("Mediatek timer driver"); +MODULE_LICENSE("GPL"); --=20 2.43.0