[PATCH v2 09/45] dm: core: Pass a root node to of_find_node_by_phandle()

Simon Glass sjg at chromium.org
Wed Sep 7 04:26:57 CEST 2022


This function currently assumes that the control FDT is used. Update it
to allow a root node to be passed, so it can work with any tree.

Also add a comment to ofnode_get_by_phandle() so that its purpose is
clear.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 drivers/core/of_access.c | 7 ++++---
 drivers/core/ofnode.c    | 2 +-
 include/dm/of_access.h   | 4 +++-
 include/dm/ofnode.h      | 2 ++
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index a52f5a6b18b..ee09bbb7550 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -445,14 +445,15 @@ struct device_node *of_find_node_by_prop_value(struct device_node *from,
 	return np;
 }
 
-struct device_node *of_find_node_by_phandle(phandle handle)
+struct device_node *of_find_node_by_phandle(struct device_node *root,
+					    phandle handle)
 {
 	struct device_node *np;
 
 	if (!handle)
 		return NULL;
 
-	for_each_of_allnodes(np)
+	for_each_of_allnodes_from(root, np)
 		if (np->phandle == handle)
 			break;
 	(void)of_node_get(np);
@@ -659,7 +660,7 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
 			 * below.
 			 */
 			if (cells_name || cur_index == index) {
-				node = of_find_node_by_phandle(phandle);
+				node = of_find_node_by_phandle(NULL, phandle);
 				if (!node) {
 					debug("%s: could not find phandle\n",
 					      np->full_name);
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 45ea84e9fb8..bf8eaf6d09a 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -329,7 +329,7 @@ ofnode ofnode_get_by_phandle(uint phandle)
 	ofnode node;
 
 	if (of_live_active())
-		node = np_to_ofnode(of_find_node_by_phandle(phandle));
+		node = np_to_ofnode(of_find_node_by_phandle(NULL, phandle));
 	else
 		node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob,
 							    phandle);
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index 5b7821d0a1b..c0ac91a416a 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -258,11 +258,13 @@ struct device_node *of_find_node_by_prop_value(struct device_node *from,
 /**
  * of_find_node_by_phandle() - Find a node given a phandle
  *
+ * @root:	root node to start from (NULL for default device tree)
  * @handle:	phandle of the node to find
  *
  * Return: node pointer, or NULL if not found
  */
-struct device_node *of_find_node_by_phandle(phandle handle);
+struct device_node *of_find_node_by_phandle(struct device_node *root,
+					    phandle handle);
 
 /**
  * of_read_u32() - Find and read a 32-bit integer from a property
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 7ce1e4c6d91..018ee70c2ff 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -461,6 +461,8 @@ int ofnode_get_path(ofnode node, char *buf, int buflen);
 /**
  * ofnode_get_by_phandle() - get ofnode from phandle
  *
+ * This uses the default (control) device tree
+ *
  * @phandle:	phandle to look up
  * Return: ofnode reference to the phandle
  */
-- 
2.37.2.789.g6183377224-goog



More information about the U-Boot mailing list