From nobody Thu Apr 2 17:15:02 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 8A0AC3F54CC for ; Fri, 27 Mar 2026 18:06: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=1774634776; cv=none; b=hhJU0lOLiqQz3GfGCo4/TED6VZzRlZJRkLt7uFyWGFESYuH9+9QUHwnEt4xOqQ7z4YlTwN45MvPJy1SpqbpvBiku1f3TrKmfMKNEjQ0SVtMYRwQgLj/sPdnpeaKtNPHwkQ71KxzVckgQFc+RTLytJx3FVL7kZzVm3/35/NSitrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634776; c=relaxed/simple; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KjhvYbu7P0PIQajTfdZuS97buP/1gN+MkQFVxxbvYdiZbZZXWKcWeJb6nhTH5PoAD66oqrBs91l5/ounTwUYwZ0tXwUa2JbwE+/G0wVvFcotNbxLAC8C7JcgjsIF1IlrIjD92lSDVOoIWslVVEAhkya9CjnHSgV7zncorF1PSkU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DgBKR2eD; 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="DgBKR2eD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC542C19424; Fri, 27 Mar 2026 18:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774634776; bh=97lDUidSE9o63Ge6U3LwrVURpGigQQLUwAM/FVrascc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DgBKR2eD4oUMDeDvC2Bvy5r/zEx0EqN7DPF027z4/YKh3OJHDcqu1ZVJcwVXvNjJ+ REJyPBKXJJ6RZjvzbYxFCLTN3ljcEiZh3Cz8eM6Jrdi+/vn69AkuLcePtgiHsWMwGm 0t974SkoD81WlBCGhQ/pRD1g5uB25PuoJVf5BQXQ+5p2A9GG6Zk0TSGQm3O2uRujtM uTb+/SoRmQtZJ0YYAIRr+mH2cdYwh/kHE7yiGegMIelvRr5OaRzg1Eib8a6GmFk3+o lVtRsqpjxUr2c84iBFDjM2EQw0V/JwnkkgGnWZ/i2SRXtZ6NpG+G5rHB1zwmhk3aIi hTSLMqymoCNMQ== 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 resend v1 4/7] clocksource/drivers/timer-probe: Add the module support for the TIMER_PDEV_DECLARE() macro Date: Fri, 27 Mar 2026 19:05:56 +0100 Message-ID: <20260327180600.8150-5-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327180600.8150-1-daniel.lezcano@kernel.org> References: <20260327180600.8150-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