From nobody Thu Apr 2 17:10:00 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