Skip to content

Commit 298d4de

Browse files
Lee JonesWolfram Sang
authored andcommitted
i2c: Match using traditional OF methods, then by vendor-less compatible strings
This function provides a single call for all I2C devices which need to match firstly using traditional OF means i.e by of_node, then if that fails we attempt to match using the supplied I2C client name with a list of supplied compatible strings with the '<vendor>,' string removed. The latter is required due to the unruly naming conventions used currently by I2C devices. Acked-by: Grant Likely <[email protected]> Signed-off-by: Lee Jones <[email protected]> [Kieran: Fix static inline usage on !CONFIG_OF] Tested-by: Kieran Bingham <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Tested-by: Javier Martinez Canillas <[email protected]> Signed-off-by: Kieran Bingham <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent cabcf4f commit 298d4de

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/i2c/i2c-core.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,22 @@ i2c_of_match_device_sysfs(const struct of_device_id *matches,
17991799
return NULL;
18001800
}
18011801

1802+
const struct of_device_id
1803+
*i2c_of_match_device(const struct of_device_id *matches,
1804+
struct i2c_client *client)
1805+
{
1806+
const struct of_device_id *match;
1807+
1808+
if (!(client && matches))
1809+
return NULL;
1810+
1811+
match = of_match_device(matches, &client->dev);
1812+
if (match)
1813+
return match;
1814+
1815+
return i2c_of_match_device_sysfs(matches, client);
1816+
}
1817+
EXPORT_SYMBOL_GPL(i2c_of_match_device);
18021818
#else
18031819
static void of_i2c_register_devices(struct i2c_adapter *adap) { }
18041820
#endif /* CONFIG_OF */

include/linux/i2c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,10 @@ extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
774774
/* must call i2c_put_adapter() when done with returned i2c_adapter device */
775775
struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
776776

777+
extern const struct of_device_id
778+
*i2c_of_match_device(const struct of_device_id *matches,
779+
struct i2c_client *client);
780+
777781
#else
778782

779783
static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
@@ -790,6 +794,14 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
790794
{
791795
return NULL;
792796
}
797+
798+
static inline const struct of_device_id
799+
*i2c_of_match_device(const struct of_device_id *matches,
800+
struct i2c_client *client)
801+
{
802+
return NULL;
803+
}
804+
793805
#endif /* CONFIG_OF */
794806

795807
#if IS_ENABLED(CONFIG_ACPI)

0 commit comments

Comments
 (0)