summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Walle <michael@walle.cc>2021-10-15 15:15:17 +0200
committerPriyanka Jain <priyanka.jain@nxp.com>2021-11-09 17:18:23 +0530
commitb8ec9458a35167ab689b3ebfba169f520e1064c4 (patch)
treed7e10831dcf8c70ed074603959be06692c42c983
parentc7155d29fb041143e33e0b2d691699e614d84936 (diff)
dm: core: add ofnode_for_each_compatible_node()
Add a helper to iterate over all nodes with a given compatible string. Signed-off-by: Michael Walle <michael@walle.cc> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
-rw-r--r--include/dm/ofnode.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 6a714d0c7b..0f680e5aa6 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -1010,6 +1010,30 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
node = ofnode_next_subnode(node))
/**
+ * ofnode_for_each_compatible_node() - iterate over all nodes with a given
+ * compatible string
+ *
+ * @node: child node (ofnode, lvalue)
+ * @compat: compatible string to match
+ *
+ * This is a wrapper around a for loop and is used like so:
+ *
+ * ofnode node;
+ *
+ * ofnode_for_each_compatible_node(node, parent, compatible) {
+ * Use node
+ * ...
+ * }
+ *
+ * Note that this is implemented as a macro and @node is used as
+ * iterator in the loop.
+ */
+#define ofnode_for_each_compatible_node(node, compat) \
+ for (node = ofnode_by_compatible(ofnode_null(), compat); \
+ ofnode_valid(node); \
+ node = ofnode_by_compatible(node, compat))
+
+/**
* ofnode_get_child_count() - get the child count of a ofnode
*
* @node: valid node to get its child count