Skip to contentSkip to conversation

i2c: add subsys_i2c_driver() macro

PATCH New Peng Fan 2 participants 2 messages Dec 2

Subsystems (3)
lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH v2 1/1 i2c: add subsys_i2c_driver() macro

From: Peng Fan <[email protected]>

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.

---
Changes in v2:
- Drop subsys_i2c_driver_probe.
- I drop the mfd patch in this version, and shrink the To/Cc list.
will repost mfd after this patch land in upstream. And I will also
convert other subsystem drivers to use this new helper later.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 include/linux/i2c.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/linux/i2c.h +13 -0
index 6a847fc88d25..c583fd1ab691 100644
@@ -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);
 

---
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
change-id: 20261201-add-i2c-subsys-mfd-120cdb5f68a1

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

From: Peng Fan <[email protected]>

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1