Skip to content

Commit 6622337

Browse files
angiglesiaswsakernel
authored andcommitted
i2c: core: Introduce i2c_client_get_device_id helper function
Introduces new helper function to aid in .probe_new() refactors. In order to use existing i2c_get_device_id() on the probe callback, the device match table needs to be accessible in that function, which would require bigger refactors in some drivers using the deprecated .probe callback. This issue was discussed in more detail in the IIO mailing list. Link: https://lore.kernel.org/all/[email protected]/ Suggested-by: Nuno Sá <[email protected]> Suggested-by: Andy Shevchenko <[email protected]> Suggested-by: Jonathan Cameron <[email protected]> Signed-off-by: Angel Iglesias <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 9abf231 commit 6622337

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,20 @@ int i2c_get_device_id(const struct i2c_client *client,
22362236
}
22372237
EXPORT_SYMBOL_GPL(i2c_get_device_id);
22382238

2239+
/**
2240+
* i2c_client_get_device_id - get the driver match table entry of a device
2241+
* @client: the device to query. The device must be bound to a driver
2242+
*
2243+
* Returns a pointer to the matching entry if found, NULL otherwise.
2244+
*/
2245+
const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client)
2246+
{
2247+
const struct i2c_driver *drv = to_i2c_driver(client->dev.driver);
2248+
2249+
return i2c_match_id(drv->id_table, client);
2250+
}
2251+
EXPORT_SYMBOL_GPL(i2c_client_get_device_id);
2252+
22392253
/* ----------------------------------------------------
22402254
* the i2c address scanning function
22412255
* Will not work for 10-bit addresses!

include/linux/i2c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,
189189
u8 *values);
190190
int i2c_get_device_id(const struct i2c_client *client,
191191
struct i2c_device_identity *id);
192+
const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client);
192193
#endif /* I2C */
193194

194195
/**

0 commit comments

Comments
 (0)