Skip to content

Commit 564d73c

Browse files
bijudaswsakernel
authored andcommitted
i2c: Add i2c_get_match_data()
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 <[email protected]> Signed-off-by: Biju Das <[email protected]> [wsa: simplified var initialization] Signed-off-by: Wolfram Sang <[email protected]>
1 parent edaac7d commit 564d73c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
114114
}
115115
EXPORT_SYMBOL_GPL(i2c_match_id);
116116

117+
const void *i2c_get_match_data(const struct i2c_client *client)
118+
{
119+
struct i2c_driver *driver = to_i2c_driver(client->dev.driver);
120+
const struct i2c_device_id *match;
121+
const void *data;
122+
123+
data = device_get_match_data(&client->dev);
124+
if (!data) {
125+
match = i2c_match_id(driver->id_table, client);
126+
if (!match)
127+
return NULL;
128+
129+
data = (const void *)match->driver_data;
130+
}
131+
132+
return data;
133+
}
134+
EXPORT_SYMBOL(i2c_get_match_data);
135+
117136
static int i2c_device_match(struct device *dev, struct device_driver *drv)
118137
{
119138
struct i2c_client *client = i2c_verify_client(dev);

include/linux/i2c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ struct i2c_adapter *i2c_verify_adapter(struct device *dev);
367367
const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
368368
const struct i2c_client *client);
369369

370+
const void *i2c_get_match_data(const struct i2c_client *client);
371+
370372
static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
371373
{
372374
struct device * const dev = kobj_to_dev(kobj);

0 commit comments

Comments
 (0)