public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@kernel.org>
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 <sboyd@kernel.org>
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	[thread overview]
Message-ID: <20260327180600.8150-5-daniel.lezcano@kernel.org> (raw)
In-Reply-To: <20260327180600.8150-1-daniel.lezcano@kernel.org>

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 <daniel.lezcano@kernel.org>
---
 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
 
+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.
 
 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;
 
+	if (!IS_ENABLED(CONFIG_EARLY_TIMER))
+		return 0;
+
 	for_each_pdev_timer_table(drv)
 		__timer_pdev_probe(*drv);
 
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[];
 
-#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 = { \
 		.probe = __probe,					\
 		.remove = __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") = &__pdev_timer_table_entry_##__name
 
+#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 = __pdev_timer_table;     \
 	     __pdev < __pdev_timer_table_end; \
-- 
2.43.0


  parent reply	other threads:[~2026-03-27 18:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27 18:05 [PATCH v1 resend 0/7] Timer driver module support Daniel Lezcano
2026-03-27 18:05 ` [PATCH resend v1 1/7] clocksource/drivers/timer-probe: Create a platform_device before the framework is initialized Daniel Lezcano
2026-03-28  6:55   ` kernel test robot
2026-03-28  7:39   ` kernel test robot
2026-03-28 13:05   ` kernel test robot
2026-03-27 18:05 ` [PATCH resend v1 2/7] clocksource/drivers/mmio: Make the code compatible with modules Daniel Lezcano
2026-03-27 18:09   ` John Stultz
2026-03-27 18:05 ` [PATCH resend v1 3/7] clocksource/drivers/timer-of: " Daniel Lezcano
2026-03-27 18:05 ` Daniel Lezcano [this message]
2026-03-27 18:05 ` [PATCH resend v1 5/7] clocksource/drivers/rockchip: Use the TIMER_PDEV_DECLARE() macro Daniel Lezcano
2026-03-27 18:05 ` [PATCH resend v1 6/7] clocksource/drivers/rockchip: Add rockchip timer module support Daniel Lezcano
2026-03-27 18:05 ` [PATCH resend v1 7/7] clocksource/drivers/mediatek: Convert to " Daniel Lezcano
2026-04-03  7:59 ` [EXT] [PATCH v1 resend 0/7] Timer driver " Zhipeng Wang
2026-04-03  8:50   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260327180600.8150-5-daniel.lezcano@kernel.org \
    --to=daniel.lezcano@kernel.org \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=tglx@kernel.org \
    --cc=zhipeng.wang_1@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox