diff options
author | Jon Smirl <jonsmirl@gmail.com> | 2009-01-09 17:49:06 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2009-01-09 17:49:06 -0500 |
commit | 2526c151c31358aec66b63921dd712bbec5ee0cb (patch) | |
tree | ee1cd5878c6970d469e348f2440c5d0074def379 | |
parent | f5020384e4fa8ab9397aa6fa176e61e9bf7947f7 (diff) |
drivers/of: Add the of_find_i2c_device_by_node function.
The of_find_i2c_device_by_node function allows you to follow a
reference in the device tree to an i2c device node and then locate
the linux device instantiated by the device tree. Example use: an I2S
bus driver finding the i2c_device instance for a codec described by
a device tree node.
This was waiting for Anton's i2c patches that were just added.
Signed-off-by: Jon Smirl <jonsmirl@gmail.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
-rw-r--r-- | drivers/of/of_i2c.c | 19 | ||||
-rw-r--r-- | include/linux/of_i2c.h | 3 |
2 files changed, 22 insertions, 0 deletions
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c index e1b0ad6e918f..fa65a2b2ae2e 100644 --- a/drivers/of/of_i2c.c +++ b/drivers/of/of_i2c.c | |||
@@ -66,4 +66,23 @@ void of_register_i2c_devices(struct i2c_adapter *adap, | |||
66 | } | 66 | } |
67 | EXPORT_SYMBOL(of_register_i2c_devices); | 67 | EXPORT_SYMBOL(of_register_i2c_devices); |
68 | 68 | ||
69 | static int of_dev_node_match(struct device *dev, void *data) | ||
70 | { | ||
71 | return dev_archdata_get_node(&dev->archdata) == data; | ||
72 | } | ||
73 | |||
74 | /* must call put_device() when done with returned i2c_client device */ | ||
75 | struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) | ||
76 | { | ||
77 | struct device *dev; | ||
78 | |||
79 | dev = bus_find_device(&i2c_bus_type, NULL, node, | ||
80 | of_dev_node_match); | ||
81 | if (!dev) | ||
82 | return NULL; | ||
83 | |||
84 | return to_i2c_client(dev); | ||
85 | } | ||
86 | EXPORT_SYMBOL(of_find_i2c_device_by_node); | ||
87 | |||
69 | MODULE_LICENSE("GPL"); | 88 | MODULE_LICENSE("GPL"); |
diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h index bd2a870ec296..34974b5a76f7 100644 --- a/include/linux/of_i2c.h +++ b/include/linux/of_i2c.h | |||
@@ -17,4 +17,7 @@ | |||
17 | void of_register_i2c_devices(struct i2c_adapter *adap, | 17 | void of_register_i2c_devices(struct i2c_adapter *adap, |
18 | struct device_node *adap_node); | 18 | struct device_node *adap_node); |
19 | 19 | ||
20 | /* must call put_device() when done with returned i2c_client device */ | ||
21 | struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); | ||
22 | |||
20 | #endif /* __LINUX_OF_I2C_H */ | 23 | #endif /* __LINUX_OF_I2C_H */ |