Skip to contentSkip to conversation

i2c: Reduce use of i2c_of_match_device()

PATCH Applied Andy Shevchenko 4 participants 8 messages Feb 13, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover i2c: Reduce use of i2c_of_match_device()

The i2c_of_match_device() was developed as internal API and was exported just in case well before we get an idea of the generic helper for getting driver data for the matched device. For all the times of i2c_of_match_device() being exported there were _only_ three users, two of which had been already converted to better API. For preventing the use of i2c_of_match_device(), make it private to I²C subsystem.

This is assumed to go via I²C tree, but can be done differently taking into account the immutable tag or branch for involved subsystems.

In v2:
- collected tags (Sebastian)
- removed one leftover in the first patch

Andy Shevchenko (2):
power: ip5xxx_power: Make use of i2c_get_match_data()
i2c: Unexport i2c_of_match_device()

 drivers/i2c/i2c-core-of.c           |  1 -
 drivers/i2c/i2c-core.h              |  9 +++++++++
 drivers/power/supply/ip5xxx_power.c |  7 ++-----
 include/linux/i2c.h                 | 11 -----------
 4 files changed, 11 insertions(+), 17 deletions(-)
Signature · 1 line
2.45.1.3035.g276e886db78b
#1 lore raw

PATCH v2 1/2 power: ip5xxx_power: Make use of i2c_get_match_data()

Get matching data in one step by switching to use i2c_get_match_data().

---
 drivers/power/supply/ip5xxx_power.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/power/supply/ip5xxx_power.c +2 -5
index c448e0ac0dfa..a293b2765771 100644
@@ -828,10 +828,9 @@ static void ip5xxx_setup_regs(struct device *dev, struct ip5xxx *ip5xxx,
 
 static int ip5xxx_power_probe(struct i2c_client *client)
 {
-	const struct ip5xxx_regfield_config *fields = &ip51xx_fields;
+	const struct ip5xxx_regfield_config *fields;
 	struct power_supply_config psy_cfg = {};
 	struct device *dev = &client->dev;
-	const struct of_device_id *of_id;
 	struct power_supply *psy;
 	struct ip5xxx *ip5xxx;
 
@@ -843,9 +842,7 @@ static int ip5xxx_power_probe(struct i2c_client *client)
 	if (IS_ERR(ip5xxx->regmap))
 		return PTR_ERR(ip5xxx->regmap);
 
-	of_id = i2c_of_match_device(dev->driver->of_match_table, client);
-	if (of_id)
-		fields = (const struct ip5xxx_regfield_config *)of_id->data;
+	fields = i2c_get_match_data(client) ?: &ip51xx_fields;
 	ip5xxx_setup_regs(dev, ip5xxx, fields);
 
 	psy_cfg.of_node = dev->of_node;
Signature · 1 line
2.45.1.3035.g276e886db78b
Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] power: ip5xxx_power: Make use of i2c_get_match_data()

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

Get matching data in one step by switching to use i2c_get_match_data().

Now sending the tag from my different email address for the sake of consistency.

Thank you for the change.

--
Best wishes,
Vladimir

#5 lore raw

PATCH v2 2/2 i2c: Unexport i2c_of_match_device()

In reply to Andy Shevchenko

i2c_of_match_device() is not used anymore outside of I²C framework, unexport it.

---
 drivers/i2c/i2c-core-of.c |  1 -
 drivers/i2c/i2c-core.h    |  9 +++++++++
 include/linux/i2c.h       | 11 -----------
 3 files changed, 9 insertions(+), 12 deletions(-)
drivers/i2c/i2c-core-of.c +0 -1
index a6c407d36800..02feee6c9ba9 100644
@@ -157,7 +157,6 @@ const struct of_device_id
 
 	return i2c_of_match_device_sysfs(matches, client);
 }
-EXPORT_SYMBOL_GPL(i2c_of_match_device);
 
 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
 static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
drivers/i2c/i2c-core.h +9 -0
index 36587f38dff3..4797ba88331c 100644
@@ -84,8 +84,17 @@ static inline void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter) {
 
 #ifdef CONFIG_OF
 void of_i2c_register_devices(struct i2c_adapter *adap);
+const struct of_device_id *i2c_of_match_device(const struct of_device_id *matches,
+					       struct i2c_client *client);
+
 #else
 static inline void of_i2c_register_devices(struct i2c_adapter *adap) { }
+static inline
+const struct of_device_id *i2c_of_match_device(const struct of_device_id *matches,
+					       struct i2c_client *client)
+{
+	return NULL;
+}
 #endif
 extern struct notifier_block i2c_of_notifier;
 
include/linux/i2c.h +0 -11
index 2b2af24d2a43..997e80649889 100644
@@ -1029,10 +1029,6 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
 	return i2c_get_adapter_by_fwnode(of_fwnode_handle(node));
 }
 
-const struct of_device_id
-*i2c_of_match_device(const struct of_device_id *matches,
-		     struct i2c_client *client);
-
 int of_i2c_get_board_info(struct device *dev, struct device_node *node,
 			  struct i2c_board_info *info);
 
@@ -1053,13 +1049,6 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
 	return NULL;
 }
 
-static inline const struct of_device_id
-*i2c_of_match_device(const struct of_device_id *matches,
-		     struct i2c_client *client)
-{
-	return NULL;
-}
-
 static inline int of_i2c_get_board_info(struct device *dev,
 					struct device_node *node,
 					struct i2c_board_info *info)
Signature · 1 line
2.45.1.3035.g276e886db78b