summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>2013-06-13 22:43:51 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-06-20 21:20:54 +0200
commit234be066c1ba19eea5f0230c98d6557faef04f51 (patch)
tree41697e4b9ffd8503f3362c1454d60650a1df651b /drivers/of
parentb45e2c0b47c52ccb68d74b7b79b5226b9a944bff (diff)
downloadbarebox-234be066c1ba19eea5f0230c98d6557faef04f51.tar.gz
barebox-234be066c1ba19eea5f0230c98d6557faef04f51.tar.xz
OF: base: import parent/child functions from Linux OF API
This imports of_get_parent, of_get_next_available_child, and of_get_child_by_name and corresponding helpers from Linux OF API. of_get_next_child is not imported but implemented as list iterator instead. Also, of_get_child_count and of_get_available_child_count are introduced. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 50153b5908..6ffcd08fd8 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -875,6 +875,103 @@ int of_device_is_available(const struct device_node *device)
}
EXPORT_SYMBOL(of_device_is_available);
+/**
+ * of_get_parent - Get a node's parent if any
+ * @node: Node to get parent
+ *
+ * Returns a pointer to the parent node or NULL if already at root.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+ return (!node) ? NULL : node->parent;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ * of_get_next_available_child - Find the next available child node
+ * @node: parent node
+ * @prev: previous child of the parent node, or NULL to get first
+ *
+ * This function is like of_get_next_child(), except that it
+ * automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+ struct device_node *prev)
+{
+ for_each_child_of_node(node, prev)
+ if (of_device_is_available(prev))
+ return prev;
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
+ * of_get_child_count - Count child nodes of given parent node
+ * @parent: parent node
+ *
+ * Returns the number of child nodes or -EINVAL on NULL parent node.
+ */
+int of_get_child_count(const struct device_node *parent)
+{
+ struct device_node *child;
+ int num = 0;
+
+ if (!parent)
+ return -EINVAL;
+
+ for_each_child_of_node(parent, child)
+ num++;
+
+ return num;
+}
+EXPORT_SYMBOL(of_get_child_count);
+
+/**
+ * of_get_available_child_count - Count available child nodes of given
+ * parent node
+ * @parent: parent node
+ *
+ * Returns the number of available child nodes or -EINVAL on NULL parent
+ * node.
+ */
+int of_get_available_child_count(const struct device_node *parent)
+{
+ struct device_node *child;
+ int num = 0;
+
+ if (!parent)
+ return -EINVAL;
+
+ for_each_child_of_node(parent, child)
+ if (of_device_is_available(child))
+ num++;
+
+ return num;
+}
+EXPORT_SYMBOL(of_get_available_child_count);
+
+/**
+ * of_get_child_by_name - Find the child node by name for a given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name
+ *
+ * Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(node, child)
+ if (child->name && (of_node_cmp(child->name, name) == 0))
+ return child;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
void of_print_nodes(struct device_node *node, int indent)
{
struct device_node *n;