]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/of/base.c
Consolidate of_get_next_child
[mv-sheeva.git] / drivers / of / base.c
index 70b60845140e9168db718be0cf540a0337f3c17e..6b6dfcc56522122ff4e5f99af3d227318cef8b40 100644 (file)
@@ -113,3 +113,48 @@ int of_device_is_compatible(const struct device_node *device,
        return 0;
 }
 EXPORT_SYMBOL(of_device_is_compatible);
+
+/**
+ *     of_get_parent - Get a node's parent if any
+ *     @node:  Node to get parent
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+       struct device_node *np;
+
+       if (!node)
+               return NULL;
+
+       read_lock(&devtree_lock);
+       np = of_node_get(node->parent);
+       read_unlock(&devtree_lock);
+       return np;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ *     of_get_next_child - Iterate a node childs
+ *     @node:  parent node
+ *     @prev:  previous child of the parent node, or NULL to get first
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_get_next_child(const struct device_node *node,
+       struct device_node *prev)
+{
+       struct device_node *next;
+
+       read_lock(&devtree_lock);
+       next = prev ? prev->sibling : node->child;
+       for (; next; next = next->sibling)
+               if (of_node_get(next))
+                       break;
+       of_node_put(prev);
+       read_unlock(&devtree_lock);
+       return next;
+}
+EXPORT_SYMBOL(of_get_next_child);