From cdb6aa0afb52da34306c4339f2f4d6cbd3b0ad02 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:07 -0600 Subject: dm: core: Add a function to find the first inactive child Some devices have children and want to press an existing inactive child into service when needed. Add a function to help with this. Signed-off-by: Simon Glass --- drivers/core/device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'drivers') diff --git a/drivers/core/device.c b/drivers/core/device.c index a9e5906e7cd..5176aa3f866 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -681,6 +681,24 @@ int device_find_next_child(struct udevice **devp) return 0; } +int device_find_first_inactive_child(struct udevice *parent, + enum uclass_id uclass_id, + struct udevice **devp) +{ + struct udevice *dev; + + *devp = NULL; + list_for_each_entry(dev, &parent->child_head, sibling_node) { + if (!device_active(dev) && + device_get_uclass_id(dev) == uclass_id) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + struct udevice *dev_get_parent(const struct udevice *child) { return child->parent; -- cgit v1.3.1