dm: core: Add functions for iterating through device children
Buses need to iterate through their children in some situations. Add a few functions to make this easy. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
This commit is contained in:
@@ -514,3 +514,30 @@ int device_get_child_by_of_offset(struct udevice *parent, int seq,
|
||||
ret = device_find_child_by_of_offset(parent, seq, &dev);
|
||||
return device_get_device_tail(dev, ret, devp);
|
||||
}
|
||||
|
||||
int device_find_first_child(struct udevice *parent, struct udevice **devp)
|
||||
{
|
||||
if (list_empty(&parent->child_head)) {
|
||||
*devp = NULL;
|
||||
} else {
|
||||
*devp = list_first_entry(&parent->child_head, struct udevice,
|
||||
sibling_node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_find_next_child(struct udevice **devp)
|
||||
{
|
||||
struct udevice *dev = *devp;
|
||||
struct udevice *parent = dev->parent;
|
||||
|
||||
if (list_is_last(&dev->sibling_node, &parent->child_head)) {
|
||||
*devp = NULL;
|
||||
} else {
|
||||
*devp = list_entry(dev->sibling_node.next, struct udevice,
|
||||
sibling_node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user