CHROMIUM: mfd: chromeos_ec: instantiate sub-devices from device tree
authorVincent Palatin <vpalatin@chromium.org>
Fri, 22 Feb 2013 00:58:44 +0000 (16:58 -0800)
committerChromeBot <chrome-bot@google.com>
Sat, 23 Feb 2013 02:14:34 +0000 (18:14 -0800)
If the EC device tree node has sub-nodes, try to instantiate them as MFD
sub-devices.
We can configure the EC features provided by the board.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BUG=chrome-os-partner:17812
TEST=on Spring, check that flashrom is working to re-flash the EC
firmware.

Change-Id: Ib1501eb3408cc13acb05073928ee958cd94f9107
Reviewed-on: https://gerrit.chromium.org/gerrit/43783
Reviewed-by: Todd Broch <tbroch@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>

drivers/mfd/chromeos_ec.c

index 96a91c8..25f8d02 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/chromeos_ec.h>
 #include <linux/mfd/chromeos_ec_commands.h>
+#include <linux/of_platform.h>
 
 int cros_ec_prepare_tx(struct chromeos_ec_device *ec_dev,
                       struct chromeos_ec_msg *msg)
@@ -129,25 +130,14 @@ static struct mfd_cell cros_devs[] = {
                .name = "cros_ec-fw",
                .id = 2,
        },
-       {
-               .name = "cros_ec-i2c",
-               .id = 3,
-       },
-       /*
-        * TODO(clchiou): We should look for EC specification in device tree
-        * and add this mfd sub-device optionally.  But for now, this should
-        * be fine.
-        */
-       {
-               .name = "chromeos_vbc_ec",
-               .id = 4,
-       },
 };
 
 int __devinit cros_ec_register(struct chromeos_ec_device *ec_dev)
 {
        struct device *dev = ec_dev->dev;
        int err = 0;
+       struct device_node *node;
+       int id = 0;
 
        BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier);
        BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->wake_notifier);
@@ -198,6 +188,26 @@ int __devinit cros_ec_register(struct chromeos_ec_device *ec_dev)
        if (err)
                goto fail_mfd;
 
+       /* adding sub-devices declared in the device tree */
+       for_each_child_of_node(dev->of_node, node) {
+               char name[128];
+               struct mfd_cell cell = {
+                       .id = id++,
+                       .name = name,
+               };
+
+               dev_dbg(dev, "adding MFD sub-device %s\n", node->name);
+               if (of_modalias_node(node, name, sizeof(name)) < 0) {
+                       dev_err(dev, "modalias failure on %s\n",
+                               node->full_name);
+                       continue;
+               }
+
+               err = mfd_add_devices(dev, 0x10, &cell, 1, NULL, 0);
+               if (err)
+                       dev_err(dev, "fail to add %s\n", node->full_name);
+       }
+
        dev_info(dev, "Chrome EC (%s)\n", ec_dev->name);
 
        return 0;