]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Add a way to look up a phandle in an oftree
authorSimon Glass <sjg@chromium.org>
Wed, 7 Sep 2022 02:27:22 +0000 (20:27 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 30 Sep 2022 02:43:43 +0000 (22:43 -0400)
When we have multiple trees, the ofnode logic needs to be told which one
to use. Create a new function which takes an oftree argument, along with
a helper to obtain the FDT pointer from an oftree.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index 48d4dec1ccb1c1cb1d81a7e6c3a259bc54a5f337..012cb8cddaae5cd6579adc0e0cd8178944dca21b 100644 (file)
@@ -410,6 +410,20 @@ ofnode ofnode_get_by_phandle(uint phandle)
        return node;
 }
 
+ofnode oftree_get_by_phandle(oftree tree, uint phandle)
+{
+       ofnode node;
+
+       if (of_live_active())
+               node = np_to_ofnode(of_find_node_by_phandle(tree.np, phandle));
+       else
+               node.of_offset =
+                       fdt_node_offset_by_phandle(oftree_lookup_fdt(tree),
+                                                  phandle);
+
+       return node;
+}
+
 static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
                                               fdt_size_t *size, bool translate)
 {
index 328e1edad4cd906a1816fba96f322a4573cf5b10..fa72bb9effbb9526ecb6bf90e6a5254ef80a9079 100644 (file)
@@ -102,6 +102,22 @@ static inline bool ofnode_valid(ofnode node)
                return node.of_offset >= 0;
 }
 
+/**
+ * oftree_lookup_fdt() - obtain the FDT pointer from an oftree
+ *
+ * This can only be called when flat tree is enabled
+ *
+ * @tree: Tree to look at
+ * @return FDT pointer from the tree
+ */
+static inline void *oftree_lookup_fdt(oftree tree)
+{
+       if (of_live_active())
+               return NULL;
+       else
+               return tree.fdt;
+}
+
 /**
  * offset_to_ofnode() - convert a DT offset to an ofnode
  *
@@ -594,6 +610,15 @@ int ofnode_get_path(ofnode node, char *buf, int buflen);
  */
 ofnode ofnode_get_by_phandle(uint phandle);
 
+/**
+ * oftree_get_by_phandle() - get ofnode from phandle
+ *
+ * @tree:      tree to use
+ * @phandle:   phandle to look up
+ * Return: ofnode reference to the phandle
+ */
+ofnode oftree_get_by_phandle(oftree tree, uint phandle);
+
 /**
  * ofnode_read_size() - read the size of a property
  *
index f146b52d62554bf2c211c846ab9fa0d545507a3e..f6bb04642e8ddc704dfe7e6d39a438021b1f7e8e 100644 (file)
@@ -36,6 +36,8 @@ static int dm_test_ofnode_get_by_phandle(struct unit_test_state *uts)
        /* test unknown phandle */
        ut_assert(!ofnode_valid(ofnode_get_by_phandle(0x1000000)));
 
+       ut_assert(ofnode_valid(oftree_get_by_phandle(oftree_default(), 1)));
+
        return 0;
 }
 DM_TEST(dm_test_ofnode_get_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);