[PATCH 16/21] dm: core: Add ofnode functions to obtain an oftree
Simon Glass
sjg at chromium.org
Wed Aug 31 05:08:12 CEST 2022
At present dm_test_ofnode_root() does this manually. Add some inline
functions to handle it, so this code can be centralised.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
include/dm/ofnode.h | 31 +++++++++++++++++++++++++++++++
test/dm/ofnode.c | 4 ++--
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index e879feab002..d8d5082806e 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -238,6 +238,37 @@ static inline oftree oftree_default(void)
return tree;
}
+/**
+ * oftree_from_np() - Returns an oftree from a node pointer
+ *
+ * @root: Root node of the tree
+ * Returns: reference to the given node
+ */
+static inline oftree oftree_from_np(struct device_node *root)
+{
+ oftree tree;
+
+ tree.np = root;
+
+ return tree;
+}
+
+/**
+ * oftree_from_fdt() - Returns an oftree from a flat device tree pointer
+ *
+ * @fdt: Device tree to use
+ *
+ * Returns: reference to the given node
+ */
+static inline oftree oftree_from_fdt(void *fdt)
+{
+ oftree tree;
+
+ tree.fdt = fdt;
+
+ return tree;
+}
+
/**
* ofnode_name_eq() - Check if the node name is equivalent to a given name
* ignoring the unit address
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index a36fd104048..7f195a725a0 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -518,9 +518,9 @@ static int dm_test_ofnode_root(struct unit_test_state *uts)
ut_assertok(make_ofnode_fdt(uts, fdt, sizeof(fdt)));
if (of_live_active()) {
ut_assertok(unflatten_device_tree(fdt, &root));
- tree.np = root;
+ tree = oftree_from_np(root);
} else {
- tree.fdt = fdt;
+ tree = oftree_from_fdt(fdt);
}
/* Make sure they don't work on this new tree */
--
2.37.2.672.g94769d06f0-goog
More information about the U-Boot
mailing list