summaryrefslogtreecommitdiff
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2017-02-03 12:39:03 -0600
committerTao Huang <huangtao@rock-chips.com>2017-11-08 10:29:35 +0800
commitb5a7bc39962a52030bcb65c90660f466037ef756 (patch)
tree424da379a16874329f6445ea6be36ca83e0efb72 /drivers/of/base.c
parent4eb94cdf608008ed279bef63278831b0facf0d24 (diff)
UPSTREAM: 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. (cherry picked from commit b85ad494098bf881c3713218fbd74193e5d5c488) Change-Id: Iaee6a0f3c176d43d4bc6225f195aaaff1e7b419a Signed-off-by: Rob Herring <robh@kernel.org> Acked-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 31341290cd91..8861b9f2131c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2310,3 +2310,40 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
return of_get_next_parent(np);
}
EXPORT_SYMBOL(of_graph_get_remote_port);
+
+/**
+ * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
+ * @node: pointer to parent device_node containing graph port/endpoint
+ * @port: identifier (value of reg property) of the parent port node
+ * @endpoint: identifier (value of reg property) of the endpoint node
+ *
+ * Return: Remote device node associated with remote endpoint node linked
+ * to @node. Use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_remote_node(const struct device_node *node,
+ u32 port, u32 endpoint)
+{
+ struct device_node *endpoint_node, *remote;
+
+ endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint);
+ if (!endpoint_node) {
+ pr_debug("no valid endpoint (%d, %d) for node %s\n",
+ port, endpoint, node->full_name);
+ return NULL;
+ }
+
+ remote = of_graph_get_remote_port_parent(endpoint_node);
+ of_node_put(endpoint_node);
+ if (!remote) {
+ pr_debug("no valid remote node\n");
+ return NULL;
+ }
+
+ if (!of_device_is_available(remote)) {
+ pr_debug("not available for remote node\n");
+ return NULL;
+ }
+
+ return remote;
+}
+EXPORT_SYMBOL(of_graph_get_remote_node);