summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-04-13 09:51:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-15 12:31:23 +0200
commite9823e711b80a2f7a3eb0f9b592f7b15e597898e (patch)
tree25a197d28c769a14f94a3a20f2a40a7600b65498 /drivers/of
parentb2e6ed0aa03cbedcbeb3a47aa27b5d1f4913e03a (diff)
downloadbarebox-e9823e711b80a2f7a3eb0f9b592f7b15e597898e.tar.gz
barebox-e9823e711b80a2f7a3eb0f9b592f7b15e597898e.tar.xz
of: port Linux of_get_compatible_child helper
Incoming Linux code port makes use of the helper. Add it now instead of having to open-code it later. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9ede052274..cf3bdbfe8c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1681,6 +1681,31 @@ int of_get_available_child_count(const struct device_node *parent)
EXPORT_SYMBOL(of_get_available_child_count);
/**
+ * of_get_compatible_child - Find compatible child node
+ * @parent: parent node
+ * @compatible: compatible string
+ *
+ * Lookup child node whose compatible property contains the given compatible
+ * string.
+ *
+ * Returns a node pointer with refcount incremented, use of_node_put() on it
+ * when done; or NULL if not found.
+ */
+struct device_node *of_get_compatible_child(const struct device_node *parent,
+ const char *compatible)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(parent, child) {
+ if (of_device_is_compatible(child, compatible))
+ return child;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_compatible_child);
+
+/**
* of_get_child_by_name - Find the child node by name for a given parent
* @node: parent node
* @name: child name to look for.