Skip to contentSkip to conversation

i2c: Reduce use of i2c_of_match_device()

PATCH Superseded Andy Shevchenko 2 participants 5 messages Feb 12, 2025 – Feb 13, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Please, review and ack.

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 |  6 ++----
 include/linux/i2c.h                 | 11 -----------
 4 files changed, 11 insertions(+), 16 deletions(-)
Signature · 1 line
2.45.1.3035.g276e886db78b
#1 lore raw

PATCH 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 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/power/supply/ip5xxx_power.c +2 -4
index c448e0ac0dfa..717ec86c769b 100644
@@ -828,7 +828,7 @@ 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;
@@ -843,9 +843,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
Acked-by on v1 1/2
#2 lore raw

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

Hi,

Quoted 4 lines · Andy Shevchenko

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

---

-- Sebastian

Quoted 30 lines
 drivers/power/supply/ip5xxx_power.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/power/supply/ip5xxx_power.c +2 -4
index c448e0ac0dfa..717ec86c769b 100644
@@ -828,7 +828,7 @@ 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;
@@ -843,9 +843,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
#3 lore raw

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

Quoted 2 lines · Sebastian Reichel
Quoted 1 line · Andy Shevchenko

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

...

Quoted 1 line

Thank you!

...

Quoted 8 lines

drivers/power/supply/ip5xxx_power.c static void ip5xxx_setup_regs(struct device *dev, struct ip5xxx *ip5xxx, · line 834

Quoted 8 lines

static int ip5xxx_power_probe(struct i2c_client *client) {

drivers/power/supply/ip5xxx_power.c +1 -1
-	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;

Seems I forgot to drop this (unused) variable.

Quoted 8 lines
Quoted 8 lines
drivers/power/supply/ip5xxx_power.c +1 -3
@@ -843,9 +843,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;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH 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 ae2ef3da6ecd..4d281ff5582b 100644
@@ -1039,10 +1039,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);
 
@@ -1063,13 +1059,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