aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2015-03-25 01:41:08 -0400
committerRob Herring <robh@kernel.org>2015-03-25 01:41:08 -0400
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,
2083EXPORT_SYMBOL(of_graph_parse_endpoint); 2083EXPORT_SYMBOL(of_graph_parse_endpoint);
2084 2084
2085/** 2085/**
2086 * of_graph_get_port_by_id() - get the port matching a given id
2087 * @parent: pointer to the parent device node
2088 * @id: id of the port
2089 *
2090 * Return: A 'port' node pointer with refcount incremented. The caller
2091 * has to use of_node_put() on it when done.
2092 */
2093struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id)
2094{
2095 struct device_node *node, *port;
2096
2097 node = of_get_child_by_name(parent, "ports");
2098 if (node)
2099 parent = node;
2100
2101 for_each_child_of_node(parent, port) {
2102 u32 port_id = 0;
2103
2104 if (of_node_cmp(port->name, "port") != 0)
2105 continue;
2106 of_property_read_u32(port, "reg", &port_id);
2107 if (id == port_id)
2108 break;
2109 }
2110
2111 of_node_put(node);
2112
2113 return port;
2114}
2115EXPORT_SYMBOL(of_graph_get_port_by_id);
2116
2117/**
2086 * of_graph_get_next_endpoint() - get next endpoint node 2118 * of_graph_get_next_endpoint() - get next endpoint node
2087 * @parent: pointer to the parent device node 2119 * @parent: pointer to the parent device node
2088 * @prev: previous endpoint node, or NULL to get first 2120 * @prev: previous endpoint node, or NULL to get first
2089 * 2121 *
2090 * Return: An 'endpoint' node pointer with refcount incremented. Refcount 2122 * Return: An 'endpoint' node pointer with refcount incremented. Refcount
2091 * of the passed @prev node is not decremented, the caller have to use 2123 * of the passed @prev node is decremented.
2092 * of_node_put() on it when done.
2093 */ 2124 */
2094struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, 2125struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
2095 struct device_node *prev) 2126 struct device_node *prev)
@@ -2125,12 +2156,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
2125 if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n", 2156 if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
2126 __func__, prev->full_name)) 2157 __func__, prev->full_name))
2127 return NULL; 2158 return NULL;
2128
2129 /*
2130 * Avoid dropping prev node refcount to 0 when getting the next
2131 * child below.
2132 */
2133 of_node_get(prev);
2134 } 2159 }
2135 2160
2136 while (1) { 2161 while (1) {