Linux I2C development
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@linux.dev>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: 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>,
	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: Re: [PATCH 1/2] i2c: add subsys_i2c_driver() macro
Date: Wed, 2 Dec 2026 14:50:18 +0800	[thread overview]
Message-ID: <aw-_qlLgnGMK7mEK@fedora> (raw)
In-Reply-To: <aw9PM_y9LYe8hcEI@shikoro>

Hi Wolfram,
On Tue, Dec 01, 2026 at 11:50:27PM +0100, Wolfram Sang wrote:
>On Tue, Dec 01, 2026 at 05:45:51PM +0800, Peng Fan wrote:
>> 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>
>
>Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
>
>Applied to my for-andi branch, thanks!

Thanks for applying.

Sashiko reported minor issue:
https://sashiko.dev/#/message/sashiko-outbox-243018%40kernel.org

I am thinking to use below simplied version, do you expect a V2 or the applied
version is fine for you?

Thanks
Peng

------------------------------------------------------
Subject: [PATCH V2] i2c: add subsys_i2c_driver() macro

Add subsys_i2c_driver() so that I2C drivers registered at the
subsys_initcall() level can avoid the open-coded init/exit boilerplate.
It replaces subsys_initcall() plus module_exit() and is a parallel of
module_i2c_driver() with the init call promoted to subsys_initcall() when
built in.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 include/linux/i2c.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6a847fc88d25..c583fd1ab691 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -1020,6 +1020,19 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
 #define builtin_i2c_driver(__i2c_driver) \
 	builtin_driver(__i2c_driver, i2c_add_driver)
 
+/**
+ * subsys_i2c_driver() - Helper macro for registering an I2C driver
+ * @__i2c_driver: i2c_driver struct
+ *
+ * Helper macro for I2C drivers which do not do anything special in their
+ * init/exit and need to be registered 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)
+
 /* must call put_device() when done with returned i2c_client device */
 struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode);
 
-- 
2.56.0

  reply	other threads:[~2026-12-02  6:50 UTC|newest]

Thread overview: 6+ 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 ` [PATCH 1/2] i2c: add subsys_i2c_driver() macro Peng Fan
2026-12-01 22:50   ` Wolfram Sang
2026-12-02  6:50     ` Peng Fan [this message]
2026-12-01  9:45 ` [PATCH 2/2] mfd: Convert to subsys_i2c_driver() Peng Fan
2026-12-01 22:49 ` [PATCH 0/2] Add subsys_i2c_driver() helpers and convert MFD I2C drivers Wolfram Sang

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=aw-_qlLgnGMK7mEK@fedora \
    --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