]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: core: Add a way to set a device name
authorSimon Glass <sjg@chromium.org>
Thu, 30 Jul 2015 19:40:39 +0000 (13:40 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:17:18 +0000 (08:17 +0200)
Some devices are bound entirely by probing and do not have the benefit of
a device tree to give them a name. This is very common with PCI and USB. In
most cases this is fine, but we should add an official way to set a device
name. This should be called in the device's bind() method.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
drivers/core/device.c
include/dm/device.h

index caaf2319214a58ca56387232d74c2bd3213bab7d..bbe7a94f2a1f35a5cbd408627b72ef444dbd0965 100644 (file)
@@ -603,3 +603,13 @@ bool device_is_last_sibling(struct udevice *dev)
                return false;
        return list_is_last(&dev->sibling_node, &parent->child_head);
 }
+
+int device_set_name(struct udevice *dev, const char *name)
+{
+       name = strdup(name);
+       if (!name)
+               return -ENOMEM;
+       dev->name = name;
+
+       return 0;
+}
index 53773a8f9d9c9b1e7f83e03e9ee5b2ea96fa6c4b..1f78963803d85d45a32f532c5d7851a3a269fbfa 100644 (file)
@@ -470,6 +470,21 @@ bool device_has_active_children(struct udevice *dev);
  */
 bool device_is_last_sibling(struct udevice *dev);
 
+/**
+ * device_set_name() - set the name of a device
+ *
+ * This must be called in the device's bind() method and no later. Normally
+ * this is unnecessary but for probed devices which don't get a useful name
+ * this function can be helpful.
+ *
+ * @dev:       Device to update
+ * @name:      New name (this string is allocated new memory and attached to
+ *             the device)
+ * @return 0 if OK, -ENOMEM if there is not enough memory to allocate the
+ * string
+ */
+int device_set_name(struct udevice *dev, const char *name);
+
 /* device resource management */
 typedef void (*dr_release_t)(struct udevice *dev, void *res);
 typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);