Skip to content

Commit

Permalink
drivers/of: Add the of_find_i2c_device_by_node function.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jon Smirl authored and Grant Likely committed Jan 9, 2009
1 parent f502038 commit 2526c15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/of/of_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,23 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
}
EXPORT_SYMBOL(of_register_i2c_devices);

static int of_dev_node_match(struct device *dev, void *data)
{
return dev_archdata_get_node(&dev->archdata) == data;
}

/* must call put_device() when done with returned i2c_client device */
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
{
struct device *dev;

dev = bus_find_device(&i2c_bus_type, NULL, node,
of_dev_node_match);
if (!dev)
return NULL;

return to_i2c_client(dev);
}
EXPORT_SYMBOL(of_find_i2c_device_by_node);

MODULE_LICENSE("GPL");
3 changes: 3 additions & 0 deletions include/linux/of_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
void of_register_i2c_devices(struct i2c_adapter *adap,
struct device_node *adap_node);

/* must call put_device() when done with returned i2c_client device */
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);

#endif /* __LINUX_OF_I2C_H */

0 comments on commit 2526c15

Please sign in to comment.