summaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-06 20:27:16 -0600
committerTom Rini <trini@konsulko.com>2022-09-29 16:11:15 -0400
commit52ad21aa2cc55f53da19436f457a8590abf0d125 (patch)
tree30846bc4e1f2d41259d9e9e39b238ba93bd19e9b /include/dm
parentf46ec93ed593e7a442629a2a56fd541debc41329 (diff)
dm: core: Add a macro to iterate through properties
Add a 'for_each' macro like we have for nodes. Fix the comment for struct ofprop while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/ofnode.h38
-rw-r--r--include/dm/ofnode_decl.h2
2 files changed, 39 insertions, 1 deletions
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 1e23a40c99..7b0ef109b7 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -177,6 +177,20 @@ static inline ofnode ofnode_root(void)
}
/**
+ * ofprop_valid() - check if an ofprop is valid
+ *
+ * @prop: Pointer to ofprop to check
+ * Return: true if the reference contains a valid ofprop, false if not
+ */
+static inline bool ofprop_valid(struct ofprop *prop)
+{
+ if (of_live_active())
+ return prop->prop;
+ else
+ return prop->offset >= 0;
+}
+
+/**
* oftree_default() - Returns the default device tree (U-Boot's control FDT)
*
* Returns: reference to the control FDT
@@ -822,6 +836,30 @@ int ofnode_first_property(ofnode node, struct ofprop *prop);
int ofnode_next_property(struct ofprop *prop);
/**
+ * ofnode_for_each_prop() - iterate over all properties of a node
+ *
+ * @prop: struct ofprop
+ * @node: node (lvalue, ofnode)
+ *
+ * This is a wrapper around a for loop and is used like this::
+ *
+ * ofnode node;
+ * struct ofprop prop;
+ *
+ * ofnode_for_each_prop(prop, node) {
+ * ...use prop...
+ * }
+ *
+ * Note that this is implemented as a macro and @prop is used as
+ * iterator in the loop. The parent variable can be a constant or even a
+ * literal.
+ */
+#define ofnode_for_each_prop(prop, node) \
+ for (ofnode_first_property(node, &prop); \
+ ofprop_valid(&prop); \
+ ofnode_next_property(&prop))
+
+/**
* ofprop_get_property() - get a pointer to the value of a property
*
* Get value for the property identified by the provided reference.
diff --git a/include/dm/ofnode_decl.h b/include/dm/ofnode_decl.h
index 8d0d7885aa..f666a0287b 100644
--- a/include/dm/ofnode_decl.h
+++ b/include/dm/ofnode_decl.h
@@ -57,7 +57,7 @@ typedef union ofnode_union {
*
* @node: Pointer to device node
* @offset: Pointer into flat device tree, used for flat tree.
- * @prop: Pointer to property, used for live treee.
+ * @prop: Pointer to property, used for live tree.
*/
struct ofprop {