aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-06 20:27:23 -0600
committerTom Rini <trini@konsulko.com>2022-09-29 16:11:32 -0400
commitfbf19ca1cf8113c80b059b91e513bea80a4e1f31 (patch)
treec103b045bdaa0466edd5091d9d491e5c24bce9e3
parent4a0461d9550ffa9507dce8ef2a4ddd8acc686a1d (diff)
downloadu-boot-fbf19ca1cf8113c80b059b91e513bea80a4e1f31.zip
u-boot-fbf19ca1cf8113c80b059b91e513bea80a4e1f31.tar.gz
u-boot-fbf19ca1cf8113c80b059b91e513bea80a4e1f31.tar.bz2
dm: core: Allow obtaining a node offset in the same tree
In some cases we want to obtain an ofnode in the same tree as a different ofnode, such as when looking up a subnode. At present this is trivial, since there is only one tree. When there are multiple trees, this implementation will change. Also move the ofnode_to_offset() function up higher in the header file, since we will need to provide a different implementation with multiple trees. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/core/ofnode.c19
-rw-r--r--include/dm/ofnode.h44
2 files changed, 42 insertions, 21 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 05e3512..d7273a9 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -278,7 +278,7 @@ ofnode ofnode_find_subnode(ofnode node, const char *subnode_name)
} else {
int ooffset = fdt_subnode_offset(ofnode_to_fdt(node),
ofnode_to_offset(node), subnode_name);
- subnode = offset_to_ofnode(ooffset);
+ subnode = noffset_to_ofnode(node, ooffset);
}
debug("%s\n", ofnode_valid(subnode) ?
ofnode_get_name(subnode) : "<none>");
@@ -326,7 +326,7 @@ ofnode ofnode_first_subnode(ofnode node)
if (ofnode_is_np(node))
return np_to_ofnode(node.np->child);
- return offset_to_ofnode(
+ return noffset_to_ofnode(node,
fdt_first_subnode(ofnode_to_fdt(node), ofnode_to_offset(node)));
}
@@ -336,7 +336,7 @@ ofnode ofnode_next_subnode(ofnode node)
if (ofnode_is_np(node))
return np_to_ofnode(node.np->sibling);
- return offset_to_ofnode(
+ return noffset_to_ofnode(node,
fdt_next_subnode(ofnode_to_fdt(node), ofnode_to_offset(node)));
}
#endif /* !DM_INLINE_OFNODE */
@@ -1168,8 +1168,8 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat)
(struct device_node *)ofnode_to_np(from), NULL,
compat));
} else {
- return offset_to_ofnode(fdt_node_offset_by_compatible(
- ofnode_to_fdt(from),
+ return noffset_to_ofnode(from,
+ fdt_node_offset_by_compatible(ofnode_to_fdt(from),
ofnode_to_offset(from), compat));
}
}
@@ -1182,9 +1182,10 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
(struct device_node *)ofnode_to_np(from), propname,
propval, proplen));
} else {
- return offset_to_ofnode(fdt_node_offset_by_prop_value(
- ofnode_to_fdt(from), ofnode_to_offset(from),
- propname, propval, proplen));
+ return noffset_to_ofnode(from,
+ fdt_node_offset_by_prop_value(ofnode_to_fdt(from),
+ ofnode_to_offset(from), propname, propval,
+ proplen));
}
}
@@ -1338,7 +1339,7 @@ int ofnode_add_subnode(ofnode node, const char *name, ofnode *subnodep)
}
if (offset < 0)
return -EINVAL;
- subnode = offset_to_ofnode(offset);
+ subnode = noffset_to_ofnode(node, offset);
}
*subnodep = subnode;
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index fa72bb9..a53cffb 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -55,6 +55,23 @@ static inline void *ofnode_to_fdt(ofnode node)
}
/**
+ * ofnode_to_offset() - convert an ofnode to a flat DT offset
+ *
+ * This cannot be called if the reference contains a node pointer.
+ *
+ * @node: Reference containing offset (possibly invalid)
+ * Return: DT offset (can be -1)
+ */
+static inline int ofnode_to_offset(ofnode node)
+{
+#ifdef OF_CHECKS
+ if (of_live_active())
+ return -1;
+#endif
+ return node.of_offset;
+}
+
+/**
* ofnode_to_np() - convert an ofnode to a live DT node pointer
*
* This cannot be called if the reference contains an offset.
@@ -72,20 +89,22 @@ static inline struct device_node *ofnode_to_np(ofnode node)
}
/**
- * ofnode_to_offset() - convert an ofnode to a flat DT offset
+ * noffset_to_ofnode() - convert a DT offset to an ofnode
*
- * This cannot be called if the reference contains a node pointer.
- *
- * @node: Reference containing offset (possibly invalid)
- * Return: DT offset (can be -1)
+ * @other_node: Node in the same tree to use as a reference
+ * @of_offset: DT offset (either valid, or -1)
+ * Return: reference to the associated DT offset
*/
-static inline int ofnode_to_offset(ofnode node)
+static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset)
{
-#ifdef OF_CHECKS
+ ofnode node;
+
if (of_live_active())
- return -1;
-#endif
- return node.of_offset;
+ node.np = NULL;
+ else
+ node.of_offset = of_offset;
+
+ return node;
}
/**
@@ -1175,8 +1194,9 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat);
* Find the next node after @from that has a @propname with a value
* @propval and a length @proplen.
*
- * @from: ofnode to start from (use ofnode_null() to start at the
- * beginning)
+ * @from: ofnode to start from. Use ofnode_null() to start at the
+ * beginning, or the return value from oftree_root() to start at the first
+ * child of the root
* @propname: property name to check
* @propval: property value to search for
* @proplen: length of the value in propval