From: Brian Masney <bmasney@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Stephen Boyd <sboyd@kernel.org>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Geert Uytterhoeven <geert+renesas@glider.be>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
linux-renesas-soc@vger.kernel.org,
Brian Masney <bmasney@redhat.com>
Subject: [PATCH 2/4] driver: core: platform: add subsys_platform_driver() macro
Date: Tue, 08 Sep 2026 13:47:19 -0400 [thread overview]
Message-ID: <20260908-subsys_initcall-v1-2-cbccf4cd4288@redhat.com> (raw)
In-Reply-To: <20260908-subsys_initcall-v1-0-cbccf4cd4288@redhat.com>
Add a new macro subsys_platform_driver() to eliminate some boilerplate
code in drivers that need to register earlier in the boot at the
subsys_initcall level.
Signed-off-by: Brian Masney <bmasney@redhat.com>
Assisted-by: Claude:claude-opus-4-8
---
include/linux/platform_device.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 3d5bbcbae730..3bd0f1f0d870 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -344,6 +344,19 @@ static inline void platform_set_drvdata(struct platform_device *pdev,
#define builtin_platform_driver(__platform_driver) \
builtin_driver(__platform_driver, platform_driver_register)
+/*
+ * subsys_platform_driver() - Helper macro for drivers that don't do anything
+ * special in module init/exit but need to register earlier, at
+ * subsys_initcall level, when built in. This eliminates a lot of
+ * boilerplate. Each driver may only use this macro once, and calling it
+ * replaces module_init() and module_exit(). This is meant to be a parallel
+ * of module_platform_driver() above, but with the init call promoted to
+ * subsys_initcall() so built-in providers are available earlier during boot.
+ */
+#define subsys_platform_driver(__platform_driver) \
+ subsys_driver(__platform_driver, platform_driver_register, \
+ platform_driver_unregister)
+
/* module_platform_driver_probe() - Helper macro for drivers that don't do
* anything special in module init/exit. This eliminates a lot of
* boilerplate. Each module may only use this macro once, and
@@ -376,6 +389,23 @@ static int __init __platform_driver##_init(void) \
} \
device_initcall(__platform_driver##_init); \
+/*
+ * subsys_platform_driver_probe() - Helper macro for drivers that don't do
+ * anything special in device init and have no exit, but need to register
+ * earlier, at subsys_initcall level. This eliminates some boilerplate. Each
+ * driver may only use this macro once, and using it replaces subsys_initcall.
+ * This is meant to be a parallel of builtin_platform_driver_probe above, but
+ * with the init call promoted to subsys_initcall so the provider is available
+ * earlier during boot.
+ */
+#define subsys_platform_driver_probe(__platform_driver, __platform_probe) \
+static int __init __platform_driver##_init(void) \
+{ \
+ return platform_driver_probe(&(__platform_driver), \
+ __platform_probe); \
+} \
+subsys_initcall(__platform_driver##_init) \
+
#define platform_create_bundle(driver, probe, res, n_res, data, size) \
__platform_create_bundle(driver, probe, res, n_res, data, size, THIS_MODULE, KBUILD_MODNAME)
extern struct platform_device *__platform_create_bundle(
--
2.55.0
next prev parent reply other threads:[~2026-09-08 17:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 17:47 [PATCH 0/4] driver: core: add subsys_platform_driver() to reduce boilerplate code in drivers Brian Masney
2026-09-08 17:47 ` [PATCH 1/4] driver: core: add subsys_driver() macro Brian Masney
2026-09-09 11:44 ` Abel Vesa
2026-09-09 15:14 ` Geert Uytterhoeven
2026-09-08 17:47 ` Brian Masney [this message]
2026-09-09 11:44 ` [PATCH 2/4] driver: core: platform: add subsys_platform_driver() macro Abel Vesa
2026-09-09 15:16 ` Geert Uytterhoeven
2026-09-08 17:47 ` [PATCH 3/4] clk: qcom: convert drivers over to use subsys_platform_driver() Brian Masney
2026-09-09 11:25 ` Konrad Dybcio
2026-09-09 11:45 ` Abel Vesa
2026-09-09 12:10 ` Brian Masney
2026-09-08 17:47 ` [PATCH 4/4] clk: renesas: " Brian Masney
2026-09-09 15:19 ` Geert Uytterhoeven
2026-09-09 14:40 ` [PATCH 0/4] driver: core: add subsys_platform_driver() to reduce boilerplate code in drivers Pankaj Patil
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=20260908-subsys_initcall-v1-2-cbccf4cd4288@redhat.com \
--to=bmasney@redhat.com \
--cc=andersson@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet+clk@baylibre.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sboyd@kernel.org \
/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
all inboxes | Powered by JetHome®