summaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-06 20:27:21 -0600
committerTom Rini <trini@konsulko.com>2022-09-29 22:43:43 -0400
commit085d59411ca7cde4ca5c70beeab4fdcea209aed6 (patch)
tree2d5b1b974b7230c21a605394279657b14147ab39 /include/dm
parenta3f50d038695887808497c1a15c9fcc122d964e6 (diff)
downloadu-boot-085d59411ca7cde4ca5c70beeab4fdcea209aed6.tar.gz
u-boot-085d59411ca7cde4ca5c70beeab4fdcea209aed6.tar.bz2
u-boot-085d59411ca7cde4ca5c70beeab4fdcea209aed6.zip
dm: core: Add ofnode functions to obtain an oftree
At present dm_test_ofnode_root() does this manually. Add some inline functions to handle it, so this code can be centralised. Add oftree functions to produce a null tree and to check whether a tree is valid or not. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/ofnode.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index f68896711e..328e1edad4 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -174,6 +174,38 @@ static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
}
/**
+ * oftree_valid() - check if an oftree is valid
+ *
+ * @tree: Reference containing oftree
+ * Return: true if the reference contains a valid oftree, false if node
+ */
+static inline bool oftree_valid(oftree tree)
+{
+ if (of_live_active())
+ return tree.np;
+ else
+ return tree.fdt;
+}
+
+/**
+ * oftree_null() - Obtain a null oftree
+ *
+ * This returns an oftree which points to no tree. It works both with the flat
+ * tree and livetree.
+ */
+static inline oftree oftree_null(void)
+{
+ oftree tree;
+
+ if (of_live_active())
+ tree.np = NULL;
+ else
+ tree.fdt = NULL;
+
+ return tree;
+}
+
+/**
* ofnode_null() - Obtain a null ofnode
*
* This returns an ofnode which points to no node. It works both with the flat
@@ -235,6 +267,37 @@ static inline oftree oftree_default(void)
}
/**
+ * 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
*