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 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