]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
drivers/of: Add the of_find_i2c_device_by_node function.
authorJon Smirl <jonsmirl@gmail.com>
Fri, 9 Jan 2009 22:49:06 +0000 (15:49 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Fri, 9 Jan 2009 22:49:06 +0000 (15:49 -0700)
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>
drivers/of/of_i2c.c
include/linux/of_i2c.h

index e1b0ad6e918f0bec0a843888e4de826d1cccf825..fa65a2b2ae2e44737edb5d4e19daf767e331bd9c 100644 (file)
@@ -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");
index bd2a870ec29621f54b4b53aea5dd15f8bb8c346f..34974b5a76f78d1d9d142c3df4fb0e23a0ba106e 100644 (file)
@@ -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 */