]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
i2c: Add i2c_get_match_data()
authorBiju Das <biju.das.jz@bp.renesas.com>
Wed, 7 Jun 2023 16:57:38 +0000 (17:57 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:07:44 +0000 (15:07 +0200)
[ Upstream commit 564d73c4d9201526bd976b9379d2aaf1a7133e84 ]

Add i2c_get_match_data() to get match data for I2C, ACPI and
DT-based matching, so that we can optimize the driver code.

Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
[wsa: simplified var initialization]
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 119abf7d1815 ("hwmon: (max16065) Fix alarm attributes")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/i2c/i2c-core-base.c
include/linux/i2c.h

index 6fac638e423ac30cd28bb2f21f08a7dd1b11887e..ef6d52a38b5c94c64f49ad023734a64bb991da6c 100644 (file)
@@ -92,6 +92,25 @@ const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
 }
 EXPORT_SYMBOL_GPL(i2c_match_id);
 
+const void *i2c_get_match_data(const struct i2c_client *client)
+{
+       struct i2c_driver *driver = to_i2c_driver(client->dev.driver);
+       const struct i2c_device_id *match;
+       const void *data;
+
+       data = device_get_match_data(&client->dev);
+       if (!data) {
+               match = i2c_match_id(driver->id_table, client);
+               if (!match)
+                       return NULL;
+
+               data = (const void *)match->driver_data;
+       }
+
+       return data;
+}
+EXPORT_SYMBOL(i2c_get_match_data);
+
 static int i2c_device_match(struct device *dev, struct device_driver *drv)
 {
        struct i2c_client       *client = i2c_verify_client(dev);
index 6cfb530b3d43fb66ecc3e7fd11dc46647750f4ee..63476bcf955d5def77f2ac5c4ec1ae3113b48aea 100644 (file)
@@ -342,6 +342,8 @@ struct i2c_adapter *i2c_verify_adapter(struct device *dev);
 const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
                                         const struct i2c_client *client);
 
+const void *i2c_get_match_data(const struct i2c_client *client);
+
 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
 {
        struct device * const dev = kobj_to_dev(kobj);