summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2015-03-25 00:41:08 -0500
committerRob Herring <robh@kernel.org>2015-03-25 00:41:08 -0500
commit8147e2e8f13d823307e1edf2add5a8df84180cca (patch)
tree476eae8727d98c56027ca1036a8f61ff261c9c51 /drivers/of
parentbc465aa9d045feb0e13b4a8f32cc33c1943f62d6 (diff)
parentbfe446e37c4efd8ade454911e8f80414bcbfc10d (diff)
Merge tag 'of-graph-for-4.0' of git://git.pengutronix.de/git/pza/linux into for-next
Pull of-graph helpers from Philipp Zabel: of: Add of-graph helpers to loop over endpoints and find ports by id This series converts of_graph_get_next_endpoint to decrement the refcount of the passed prev parameter. This allows to add a for_each_endpoint_of_node helper macro to loop over all endpoints in a device tree node. The of_graph_get_port_by_id function is added to retrieve a port by its known port id (contained in the reg property) from the device tree.
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8f165b112e03..69566b6a876d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2083,13 +2083,44 @@ int of_graph_parse_endpoint(const struct device_node *node,
EXPORT_SYMBOL(of_graph_parse_endpoint);
/**
+ * of_graph_get_port_by_id() - get the port matching a given id
+ * @parent: pointer to the parent device node
+ * @id: id of the port
+ *
+ * Return: A 'port' node pointer with refcount incremented. The caller
+ * has to use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id)
+{
+ struct device_node *node, *port;
+
+ node = of_get_child_by_name(parent, "ports");
+ if (node)
+ parent = node;
+
+ for_each_child_of_node(parent, port) {
+ u32 port_id = 0;
+
+ if (of_node_cmp(port->name, "port") != 0)
+ continue;
+ of_property_read_u32(port, "reg", &port_id);
+ if (id == port_id)
+ break;
+ }
+
+ of_node_put(node);
+
+ return port;
+}
+EXPORT_SYMBOL(of_graph_get_port_by_id);
+
+/**
* of_graph_get_next_endpoint() - get next endpoint node
* @parent: pointer to the parent device node
* @prev: previous endpoint node, or NULL to get first
*
* Return: An 'endpoint' node pointer with refcount incremented. Refcount
- * of the passed @prev node is not decremented, the caller have to use
- * of_node_put() on it when done.
+ * of the passed @prev node is decremented.
*/
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *prev)
@@ -2125,12 +2156,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
__func__, prev->full_name))
return NULL;
-
- /*
- * Avoid dropping prev node refcount to 0 when getting the next
- * child below.
- */
- of_node_get(prev);
}
while (1) {