summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2014-10-13 23:41:49 -0600
committerSimon Glass <sjg@chromium.org>2014-10-22 10:36:45 -0600
commita8981d4f80b010666ad754d20a4f389f94d6726d (patch)
tree48bf392bb2e0f00248ac4949fdceefa4b7509cb6 /drivers
parent0b304a2494eed170562a9fdd64e31332ad5ae73a (diff)
downloadu-boot-imx-a8981d4f80b010666ad754d20a4f389f94d6726d.zip
u-boot-imx-a8981d4f80b010666ad754d20a4f389f94d6726d.tar.gz
u-boot-imx-a8981d4f80b010666ad754d20a4f389f94d6726d.tar.bz2
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/device.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 32e80e8..9538874 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -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;
+}