[PATCH 1/4] of: base: import of_find_node_by_type

Renaud Barbier renaud.barbier at ge.com
Fri Aug 30 09:34:26 EDT 2013


Import of_find_node_by_type from Linux drivers/of/base.c -
commit id d8dfad3.
This function retrieves a node pointer based on the "device_type"
property of the node.

This is used by device tree update functions in PPC support.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 drivers/of/base.c |   29 +++++++++++++++++++++++++++++
 include/of.h      |    2 ++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4770421..2f19ea5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -319,6 +319,35 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 EXPORT_SYMBOL(of_find_node_by_name);
 
 /**
+ *	of_find_node_by_type - Find a node by its "device_type" property
+ *	@from:  The node to start searching from, or NULL to start searching
+ *		the entire device tree. The node you pass will not be
+ *		searched, only the next one will; typically, you pass
+ *		what the previous call returned.
+ *	@type:  The type string to match against.
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_type(struct device_node *from,
+		const char *type)
+{
+	struct device_node *np;
+	const char *device_type;
+	int ret;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node_from(np, from) {
+		ret = of_property_read_string(np, "device_type", &device_type);
+		if (!ret && !of_node_cmp(device_type, type))
+			return np;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_type)
+
+/**
  *	of_find_compatible_node - Find a node based on type and one of the
  *                                tokens in its "compatible" property
  *	@from:		The node to start searching from or NULL, the node
diff --git a/include/of.h b/include/of.h
index b99f0b2..a565190 100644
--- a/include/of.h
+++ b/include/of.h
@@ -124,6 +124,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_type(struct device_node *from,
+	const char *type);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
 	const char *type, const char *compat);
 extern const struct of_device_id *of_match_node(
-- 
1.7.1




More information about the barebox mailing list