[PATCHv3 2/5] of: base: Add of_find_node_by_phandle_from

Teresa Gámez t.gamez at phytec.de
Tue Sep 30 04:15:27 PDT 2014


Added of_find_node_by_phandle_from() to find nodes by
phandle with a given root node.

Signed-off-by: Teresa Gámez <t.gamez at phytec.de>
---
 drivers/of/base.c | 28 ++++++++++++++++++++++++----
 include/of.h      |  8 ++++++++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index c440a69..061fc79 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -265,19 +265,39 @@ struct device_node *of_find_node_by_alias(struct device_node *root, const char *
 EXPORT_SYMBOL_GPL(of_find_node_by_alias);
 
 /*
- * of_find_node_by_phandle - Find a node given a phandle
- * @handle:    phandle of the node to find
+ * of_find_node_by_phandle_from - Find a node given a phandle from given
+ * root node.
+ * @handle:  phandle of the node to find
+ * @root:    root node of the tree to search in. If NULL use the
+ *           internal tree.
  */
-struct device_node *of_find_node_by_phandle(phandle phandle)
+struct device_node *of_find_node_by_phandle_from(phandle phandle,
+		struct device_node *root)
 {
 	struct device_node *node;
 
-	of_tree_for_each_node_from(node, root_node)
+	if (!root)
+		root = root_node;
+
+	if (!root)
+		return 0;
+
+	of_tree_for_each_node_from(node, root)
 		if (node->phandle == phandle)
 			return node;
 
 	return NULL;
 }
+EXPORT_SYMBOL(of_find_node_by_phandle_from);
+
+/*
+ * of_find_node_by_phandle - Find a node given a phandle
+ * @handle:    phandle of the node to find
+ */
+struct device_node *of_find_node_by_phandle(phandle phandle)
+{
+	return of_find_node_by_phandle_from(phandle, root_node);
+}
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
 /*
diff --git a/include/of.h b/include/of.h
index cd2bfe0..4281cce 100644
--- a/include/of.h
+++ b/include/of.h
@@ -123,6 +123,8 @@ extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
 extern struct device_node *of_find_node_by_path(const char *path);
 extern struct device_node *of_find_node_by_phandle(phandle phandle);
+extern struct device_node *of_find_node_by_phandle_from(phandle phandle,
+	struct device_node *root);
 extern struct device_node *of_find_node_by_type(struct device_node *from,
 	const char *type);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
@@ -472,6 +474,12 @@ static inline struct device_node *of_find_node_by_phandle(phandle phandle)
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_phandle_from(phandle phandle,
+	struct device_node *root)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_compatible_node(
 						struct device_node *from,
 						const char *type,
-- 
1.9.1




More information about the barebox mailing list