dm: Add a function to bind a device by driver name
authorSimon Glass <sjg@chromium.org>
Tue, 11 Nov 2014 17:46:21 +0000 (10:46 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 22 Nov 2014 09:16:47 +0000 (10:16 +0100)
In some cases we need to manually bind a device to a particular driver.
Add a function to do this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Acked-by: Heiko Schocher <hs@denx.de>
drivers/core/lists.c
include/dm/lists.h

index 24d2864924bbabe0e7f1abdd10ac290c40740dcf..7a1d6604d42faa36c5a8f1eebe3eedb53870ccd8 100644 (file)
@@ -77,6 +77,27 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
        return result;
 }
 
+int device_bind_driver(struct udevice *parent, const char *drv_name,
+                      const char *dev_name, struct udevice **devp)
+{
+       struct driver *drv;
+       int ret;
+
+       drv = lists_driver_lookup_name(drv_name);
+       if (!drv) {
+               printf("Cannot find driver '%s'\n", drv_name);
+               return -ENOENT;
+       }
+       ret = device_bind(parent, drv, dev_name, NULL, -1, devp);
+       if (ret) {
+               printf("Cannot create device named '%s' (err=%d)\n",
+                      dev_name, ret);
+               return ret;
+       }
+
+       return 0;
+}
+
 #ifdef CONFIG_OF_CONTROL
 /**
  * driver_check_compatible() - Check if a driver is compatible with this node
index 704e33e37fb9dadc739f71312e15f79c4f9bb651..1b50af9f23c19af91d8cc61bca853f05ec709982 100644 (file)
@@ -60,4 +60,17 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only);
 int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
                   struct udevice **devp);
 
+/**
+ * device_bind_driver() - bind a device to a driver
+ *
+ * This binds a new device to a driver.
+ *
+ * @parent:    Parent device
+ * @drv_name:  Name of driver to attach to this parent
+ * @dev_name:  Name of the new device thus created
+ * @devp:      Returns the newly bound device
+ */
+int device_bind_driver(struct udevice *parent, const char *drv_name,
+                      const char *dev_name, struct udevice **devp);
+
 #endif