diff options
author | Simon Glass <sjg@chromium.org> | 2020-01-27 08:49:48 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-02-05 19:33:45 -0700 |
commit | 903e83ee84649c1a70bfd8b9ec84dacb8c24e7cb (patch) | |
tree | 3b22285081f2921225d80a4c7437bf618335262a /include/dm | |
parent | f262d4ca4b2bf8a99acb37c6151c54cd80251566 (diff) | |
download | u-boot-903e83ee84649c1a70bfd8b9ec84dacb8c24e7cb.tar.gz u-boot-903e83ee84649c1a70bfd8b9ec84dacb8c24e7cb.tar.bz2 u-boot-903e83ee84649c1a70bfd8b9ec84dacb8c24e7cb.zip |
dm: core: Add a way to iterate through children, probing each
It is sometimes useful to process all children, making sure they are
probed first. Add functions to help with this and a macro to make it more
convenient.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm')
-rw-r--r-- | include/dm/device.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/dm/device.h b/include/dm/device.h index 2618952336..517ae7fc90 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -603,6 +603,28 @@ int device_first_child_ofdata_err(struct udevice *parent, int device_next_child_ofdata_err(struct udevice **devp); /** + * device_first_child_err() - Get the first child of a device + * + * The device returned is probed if necessary, and ready for use + * + * @parent: Parent device to search + * @devp: Returns device found, if any + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_first_child_err(struct udevice *parent, struct udevice **devp); + +/** + * device_next_child_err() - Get the next child of a parent device + * + * The device returned is probed if necessary, and ready for use + * + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next sibling if no error occurred + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_next_child_err(struct udevice **devp); + +/** * device_has_children() - check if a device has any children * * @dev: Device to check @@ -749,6 +771,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) _ret = device_next_child_ofdata_err(&dev)) /** + * device_foreach_child_probe() - iterate through children, probing them + * + * This creates a for() loop which works through the available children of + * a device in order from start to end. Devices are probed if necessary, + * and ready for use. + * + * This stops when it gets an error, with @pos set to the device that failed to + * probe + * + * @pos: struct udevice * for the current device + * @parent: parent device to scan + */ +#define device_foreach_child_probe(pos, parent) \ + for (int _ret = device_first_child_err(parent, &dev); !_ret; \ + _ret = device_next_child_err(&dev)) + +/** * dm_scan_fdt_dev() - Bind child device in a the device tree * * This handles device which have sub-nodes in the device tree. It scans all |