dm: uclass: Add uclass_foreach_dev_probe
authorPatrice Chotard <patrice.chotard@st.com>
Wed, 24 Oct 2018 12:10:16 +0000 (14:10 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 16 Nov 2018 21:51:55 +0000 (16:51 -0500)
Add uclass_foreach_dev_probe() which iterates through
devices of a given uclass. Devices are probed if necessary
and are ready to use.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
include/dm/uclass.h

index 93f761c96eb80f2e13d21c991a4bef5432ecc311..1bc62d523ee8a9e4a3c00416184b6239604d9b0c 100644 (file)
@@ -393,4 +393,20 @@ int uclass_resolve_seq(struct udevice *dev);
 #define uclass_foreach_dev_safe(pos, next, uc) \
        list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node)
 
+/**
+ * uclass_foreach_dev_probe() - Helper function to iteration through devices
+ * of given uclass
+ *
+ * This creates a for() loop which works through the available devices in
+ * a uclass in order from start to end. Devices are probed if necessary,
+ * and ready for use.
+ *
+ * @id: Uclass ID
+ * @dev: struct udevice * to hold the current device. Set to NULL when there
+ * are no more devices.
+ */
+#define uclass_foreach_dev_probe(id, dev)      \
+       for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \
+            _ret = uclass_next_device_err(&dev))
+
 #endif