diff options
author | Biju Das <biju.das.jz@bp.renesas.com> | 2023-06-07 19:57:38 +0300 |
---|---|---|
committer | Wolfram Sang <wsa@kernel.org> | 2023-06-09 18:30:47 +0300 |
commit | 564d73c4d9201526bd976b9379d2aaf1a7133e84 (patch) | |
tree | 13dd5b78191f18f1848b952b8c59823be7be3ecf /drivers/i2c | |
parent | edaac7d9fff62718d0edaa7ae99fd0be36450f32 (diff) | |
download | linux-564d73c4d9201526bd976b9379d2aaf1a7133e84.tar.xz |
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 <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>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-core-base.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index ae3af738b03f..60746652fd52 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -114,6 +114,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); |