diff mbox series

[U-Boot,v4,04/11] dm: uclass: Add uclass_foreach_dev_probe

Message ID 1540383023-1807-5-git-send-email-patrice.chotard@st.com
State Accepted
Commit 37b596ac5c5f7ac405602af2577405b1f7d38cce
Delegated to: Tom Rini
Headers show
Series Add pinmux command | expand

Commit Message

Patrice CHOTARD Oct. 24, 2018, 12:10 p.m. UTC
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>
---

Changes in v4:
 - Replace respectively uclass_first_device() and uclass_next_device()
   by uclass_first_device_err() and uclass_next_device_err()

Changes in v3: None
Changes in v2: None

 include/dm/uclass.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Simon Glass Nov. 3, 2018, 6:07 a.m. UTC | #1
On 24 October 2018 at 06:10, Patrice Chotard <patrice.chotard@st.com> wrote:
> 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>
> ---
>
> Changes in v4:
>  - Replace respectively uclass_first_device() and uclass_next_device()
>    by uclass_first_device_err() and uclass_next_device_err()
>
> Changes in v3: None
> Changes in v2: None
>
>  include/dm/uclass.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Nov. 17, 2018, 1:33 p.m. UTC | #2
On Wed, Oct 24, 2018 at 02:10:16PM +0200, Patrice Chotard wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 39d0fdb540e9..11e6df391b20 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -391,4 +391,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