]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/of/of_i2c.c
of/i2c: Fill the archdata for I2C devices
[linux-2.6.git] / drivers / of / of_i2c.c
index 631689171159fd8d590eb5d3d58c8d55d16ccf46..e1b0ad6e918f0bec0a843888e4de826d1cccf825 100644 (file)
 
 #include <linux/i2c.h>
 #include <linux/of.h>
-
-struct i2c_driver_device {
-       char    *of_device;
-       char    *i2c_type;
-};
-
-static struct i2c_driver_device i2c_devices[] = {
-       { "dallas,ds1374", "rtc-ds1374" },
-};
-
-static int of_find_i2c_driver(struct device_node *node,
-                             struct i2c_board_info *info)
-{
-       int i, cplen;
-       const char *compatible;
-       const char *p;
-
-       /* 1. search for exception list entry */
-       for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
-               if (!of_device_is_compatible(node, i2c_devices[i].of_device))
-                       continue;
-               if (strlcpy(info->type, i2c_devices[i].i2c_type,
-                           I2C_NAME_SIZE) >= I2C_NAME_SIZE)
-                       return -ENOMEM;
-
-               return 0;
-       }
-
-       compatible = of_get_property(node, "compatible", &cplen);
-       if (!compatible)
-               return -ENODEV;
-
-       /* 2. search for linux,<i2c-type> entry */
-       p = compatible;
-       while (cplen > 0) {
-               if (!strncmp(p, "linux,", 6)) {
-                       p += 6;
-                       if (strlcpy(info->type, p,
-                                   I2C_NAME_SIZE) >= I2C_NAME_SIZE)
-                               return -ENOMEM;
-                       return 0;
-               }
-
-               i = strlen(p) + 1;
-               p += i;
-               cplen -= i;
-       }
-
-       /* 3. take fist compatible entry and strip manufacturer */
-       p = strchr(compatible, ',');
-       if (!p)
-               return -ENODEV;
-       p++;
-       if (strlcpy(info->type, p, I2C_NAME_SIZE) >= I2C_NAME_SIZE)
-               return -ENOMEM;
-       return 0;
-}
+#include <linux/of_i2c.h>
+#include <linux/module.h>
 
 void of_register_i2c_devices(struct i2c_adapter *adap,
                             struct device_node *adap_node)
@@ -79,9 +24,13 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
 
        for_each_child_of_node(adap_node, node) {
                struct i2c_board_info info = {};
+               struct dev_archdata dev_ad = {};
                const u32 *addr;
                int len;
 
+               if (of_modalias_node(node, info.type, sizeof(info.type)) < 0)
+                       continue;
+
                addr = of_get_property(node, "reg", &len);
                if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
                        printk(KERN_ERR
@@ -90,17 +39,13 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
                }
 
                info.irq = irq_of_parse_and_map(node, 0);
-               if (info.irq == NO_IRQ)
-                       info.irq = -1;
-
-               if (of_find_i2c_driver(node, &info) < 0) {
-                       irq_dispose_mapping(info.irq);
-                       continue;
-               }
 
                info.addr = *addr;
 
-               request_module(info.type);
+               dev_archdata_set_node(&dev_ad, node);
+               info.archdata = &dev_ad;
+
+               request_module("%s", info.type);
 
                result = i2c_new_device(adap, &info);
                if (result == NULL) {
@@ -110,6 +55,15 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
                        irq_dispose_mapping(info.irq);
                        continue;
                }
+
+               /*
+                * Get the node to not lose the dev_archdata->of_node.
+                * Currently there is no way to put it back, as well as no
+                * of_unregister_i2c_devices() call.
+                */
+               of_node_get(node);
        }
 }
 EXPORT_SYMBOL(of_register_i2c_devices);
+
+MODULE_LICENSE("GPL");