summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2018-08-09 16:17:45 +0200
committerMarek Vasut <marex@denx.de>2018-08-21 16:21:37 +0200
commit3be9bcb04883497b422f3f2e4a468657056dd48d (patch)
tree79f1d053520c4b767421d9034555231c000c14bb
parent7ec9181d6a2b68480a289c36e5729487f2a4add1 (diff)
downloadu-boot-3be9bcb04883497b422f3f2e4a468657056dd48d.tar.gz
device: expose the functions used to remove and unbind children of a device
Also add a 'drv' parameter to filter the children to remove/unbind. Exporting those functions is a preparatory work for the addition of the bind/unbind commands. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
-rw-r--r--drivers/core/device-remove.c30
-rw-r--r--include/dm/device-internal.h38
2 files changed, 49 insertions, 19 deletions
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 1cf2278e9e..586fadee0a 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -17,16 +17,7 @@
#include <dm/uclass-internal.h>
#include <dm/util.h>
-/**
- * device_chld_unbind() - Unbind all device's children from the device
- *
- * On error, the function continues to unbind all children, and reports the
- * first error.
- *
- * @dev: The device that is to be stripped of its children
- * @return 0 on success, -ve on error
- */
-static int device_chld_unbind(struct udevice *dev)
+int device_chld_unbind(struct udevice *dev, struct driver *drv)
{
struct udevice *pos, *n;
int ret, saved_ret = 0;
@@ -34,6 +25,9 @@ static int device_chld_unbind(struct udevice *dev)
assert(dev);
list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
+ if (drv && (pos->driver != drv))
+ continue;
+
ret = device_unbind(pos);
if (ret && !saved_ret)
saved_ret = ret;
@@ -42,13 +36,8 @@ static int device_chld_unbind(struct udevice *dev)
return saved_ret;
}
-/**
- * device_chld_remove() - Stop all device's children
- * @dev: The device whose children are to be removed
- * @pre_os_remove: Flag, if this functions is called in the pre-OS stage
- * @return 0 on success, -ve on error
- */
-static int device_chld_remove(struct udevice *dev, uint flags)
+int device_chld_remove(struct udevice *dev, struct driver *drv,
+ uint flags)
{
struct udevice *pos, *n;
int ret;
@@ -56,6 +45,9 @@ static int device_chld_remove(struct udevice *dev, uint flags)
assert(dev);
list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
+ if (drv && (pos->driver != drv))
+ continue;
+
ret = device_remove(pos, flags);
if (ret)
return ret;
@@ -87,7 +79,7 @@ int device_unbind(struct udevice *dev)
return ret;
}
- ret = device_chld_unbind(dev);
+ ret = device_chld_unbind(dev, NULL);
if (ret)
return ret;
@@ -178,7 +170,7 @@ int device_remove(struct udevice *dev, uint flags)
if (ret)
return ret;
- ret = device_chld_remove(dev, flags);
+ ret = device_chld_remove(dev, NULL, flags);
if (ret)
goto err;
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index f4af15448f..02ac4c7952 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -131,6 +131,44 @@ static inline void device_free(struct udevice *dev) {}
#endif
/**
+ * device_chld_unbind() - Unbind all device's children from the device if bound
+ * to drv
+ *
+ * On error, the function continues to unbind all children, and reports the
+ * first error.
+ *
+ * @dev: The device that is to be stripped of its children
+ * @drv: The targeted driver
+ * @return 0 on success, -ve on error
+ */
+#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+int device_chld_unbind(struct udevice *dev, struct driver *drv);
+#else
+static inline int device_chld_unbind(struct udevice *dev, struct driver *drv)
+{
+ return 0;
+}
+#endif
+
+/**
+ * device_chld_remove() - Stop all device's children
+ * @dev: The device whose children are to be removed
+ * @drv: The targeted driver
+ * @flags: Flag, if this functions is called in the pre-OS stage
+ * @return 0 on success, -ve on error
+ */
+#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+int device_chld_remove(struct udevice *dev, struct driver *drv,
+ uint flags);
+#else
+static inline int device_chld_remove(struct udevice *dev, struct driver *drv,
+ uint flags)
+{
+ return 0;
+}
+#endif
+
+/**
* simple_bus_translate() - translate a bus address to a system address
*
* This handles the 'ranges' property in a simple bus. It translates the