aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2017-02-03 13:39:03 -0500
committerRob Herring <robh@kernel.org>2017-02-15 09:53:32 -0500
commitb85ad494098bf881c3713218fbd74193e5d5c488 (patch)
treea57c1f3e5f422f3b4535f7069fe17b840a873722
parentbd0096d7467fbfa723cb1c12011098abf16de525 (diff)
of: introduce of_graph_get_remote_node
The OF graph API leaves too much of the graph walking to clients when in many cases the driver doesn't care about accessing the port or endpoint nodes. The drivers typically just want the device connected via a particular graph connection. of_graph_get_remote_node provides this functionality. Signed-off-by: Rob Herring <robh@kernel.org> Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
-rw-r--r--drivers/of/base.c37
-rw-r--r--include/linux/of_graph.h8
2 files changed, 45 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ce8206f9f97a..8f2a1dbfe75c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2472,3 +2472,40 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
2472 return of_get_next_parent(np); 2472 return of_get_next_parent(np);
2473} 2473}
2474EXPORT_SYMBOL(of_graph_get_remote_port); 2474EXPORT_SYMBOL(of_graph_get_remote_port);
2475
2476/**
2477 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
2478 * @node: pointer to parent device_node containing graph port/endpoint
2479 * @port: identifier (value of reg property) of the parent port node
2480 * @endpoint: identifier (value of reg property) of the endpoint node
2481 *
2482 * Return: Remote device node associated with remote endpoint node linked
2483 * to @node. Use of_node_put() on it when done.
2484 */
2485struct device_node *of_graph_get_remote_node(const struct device_node *node,
2486 u32 port, u32 endpoint)
2487{
2488 struct device_node *endpoint_node, *remote;
2489
2490 endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint);
2491 if (!endpoint_node) {
2492 pr_debug("no valid endpoint (%d, %d) for node %s\n",
2493 port, endpoint, node->full_name);
2494 return NULL;
2495 }
2496
2497 remote = of_graph_get_remote_port_parent(endpoint_node);
2498 of_node_put(endpoint_node);
2499 if (!remote) {
2500 pr_debug("no valid remote node\n");
2501 return NULL;
2502 }
2503
2504 if (!of_device_is_available(remote)) {
2505 pr_debug("not available for remote node\n");
2506 return NULL;
2507 }
2508
2509 return remote;
2510}
2511EXPORT_SYMBOL(of_graph_get_remote_node);
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index bb3a5a2cd570..abdb02eaef06 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -51,6 +51,8 @@ struct device_node *of_graph_get_endpoint_by_regs(
51struct device_node *of_graph_get_remote_port_parent( 51struct device_node *of_graph_get_remote_port_parent(
52 const struct device_node *node); 52 const struct device_node *node);
53struct device_node *of_graph_get_remote_port(const struct device_node *node); 53struct device_node *of_graph_get_remote_port(const struct device_node *node);
54struct device_node *of_graph_get_remote_node(const struct device_node *node,
55 u32 port, u32 endpoint);
54#else 56#else
55 57
56static inline int of_graph_parse_endpoint(const struct device_node *node, 58static inline int of_graph_parse_endpoint(const struct device_node *node,
@@ -89,6 +91,12 @@ static inline struct device_node *of_graph_get_remote_port(
89{ 91{
90 return NULL; 92 return NULL;
91} 93}
94static inline struct device_node *of_graph_get_remote_node(
95 const struct device_node *node,
96 u32 port, u32 endpoint)
97{
98 return NULL;
99}
92 100
93#endif /* CONFIG_OF */ 101#endif /* CONFIG_OF */
94 102