of: introduce of_graph_get_remote_node
authorRob Herring <robh@kernel.org>
Fri, 3 Feb 2017 18:39:03 +0000 (12:39 -0600)
committerRob Herring <robh@kernel.org>
Wed, 15 Feb 2017 14:53:32 +0000 (08:53 -0600)
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>
drivers/of/base.c
include/linux/of_graph.h

index ce8206f9f97aade503cf62ba85283cfc5b0de30c..8f2a1dbfe75c5195b01dff5698088358374fc422 100644 (file)
@@ -2472,3 +2472,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);
index bb3a5a2cd5705062231fe7d87fac4361a5bde889..abdb02eaef0689a64fcb2acab45625057097ecda 100644 (file)
@@ -51,6 +51,8 @@ struct device_node *of_graph_get_endpoint_by_regs(
 struct device_node *of_graph_get_remote_port_parent(
                                        const struct device_node *node);
 struct device_node *of_graph_get_remote_port(const struct device_node *node);
+struct device_node *of_graph_get_remote_node(const struct device_node *node,
+                                            u32 port, u32 endpoint);
 #else
 
 static 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(
 {
        return NULL;
 }
+static inline struct device_node *of_graph_get_remote_node(
+                                       const struct device_node *node,
+                                       u32 port, u32 endpoint)
+{
+       return NULL;
+}
 
 #endif /* CONFIG_OF */