From: Peng Fan <peng.fan@linux.dev>
To: Andi Shyti <andi.shyti@kernel.org>, Lee Jones <lee@kernel.org>,
Support Opensource <support.opensource@diasemi.com>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Matti Vaittinen <mazziesaccount@gmail.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: linux-i2c@vger.kernel.org, mfd@lists.linux.dev,
patches@opensource.cirrus.com, linux-kernel@vger.kernel.org,
linux-omap@vger.kernel.org, Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 1/2] i2c: add subsys_i2c_driver() macro
Date: Tue, 01 Dec 2026 17:45:51 +0800 [thread overview]
Message-ID: <20261201-add-i2c-subsys-mfd-v1-1-e7b1db408abf@nxp.com> (raw)
In-Reply-To: <20261201-add-i2c-subsys-mfd-v1-0-e7b1db408abf@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
Add subsys_i2c_driver() and subsys_i2c_driver_probe() macros so that
I2C drivers registered at the subsys_initcall() level can avoid the
open-coded init/exit boilerplate.
subsys_i2c_driver() replaces subsys_initcall() plus module_exit() for
drivers that need an unregister path. subsys_i2c_driver_probe() replaces
subsys_initcall() for drivers without an exit callback.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
include/linux/i2c.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6a847fc88d25..f26bb2e0ba0d 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -915,6 +915,29 @@ void i2c_del_driver(struct i2c_driver *driver);
#define i2c_add_driver(driver) \
i2c_register_driver(THIS_MODULE, driver)
+/*
+ * subsys_i2c_driver() - Helper macro for i2c 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 subsys_initcall() and module_exit().
+ */
+#define subsys_i2c_driver(__i2c_driver) \
+ subsys_driver(__i2c_driver, i2c_add_driver, i2c_del_driver)
+
+/*
+ * subsys_i2c_driver_probe() - Helper macro for drivers that don't do
+ * anything special in driver register 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.
+ */
+#define subsys_i2c_driver_probe(__i2c_driver) \
+static int __init __i2c_driver##_init(void) \
+{ \
+ return i2c_add_driver(&__i2c_driver); \
+} \
+subsys_initcall(__i2c_driver##_init)
+
static inline bool i2c_client_has_driver(struct i2c_client *client)
{
return !IS_ERR_OR_NULL(client) && client->dev.driver;
--
2.56.0
next prev parent reply other threads:[~2026-12-01 9:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:45 [PATCH 0/2] Add subsys_i2c_driver() helpers and convert MFD I2C drivers Peng Fan
2026-12-01 9:45 ` Peng Fan [this message]
2026-12-01 9:45 ` [PATCH 2/2] mfd: Convert to subsys_i2c_driver() Peng Fan
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=20261201-add-i2c-subsys-mfd-v1-1-e7b1db408abf@nxp.com \
--to=peng.fan@linux.dev \
--cc=aaro.koskinen@iki.fi \
--cc=andi.shyti@kernel.org \
--cc=andreas@kemnade.info \
--cc=ckeepax@opensource.cirrus.com \
--cc=cw00.choi@samsung.com \
--cc=khilman@baylibre.com \
--cc=krzk@kernel.org \
--cc=lee@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=mfd@lists.linux.dev \
--cc=patches@opensource.cirrus.com \
--cc=peng.fan@nxp.com \
--cc=rf@opensource.cirrus.com \
--cc=rogerq@kernel.org \
--cc=support.opensource@diasemi.com \
--cc=tony@atomide.com \
--cc=wsa+renesas@sang-engineering.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
all inboxes | Powered by JetHome®