Skip to content

Commit b85ad49

Browse files
committed
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 <[email protected]> Acked-by: Philipp Zabel <[email protected]>
1 parent bd0096d commit b85ad49

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

drivers/of/base.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,3 +2472,40 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
24722472
return of_get_next_parent(np);
24732473
}
24742474
EXPORT_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+
*/
2485+
struct 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+
}
2511+
EXPORT_SYMBOL(of_graph_get_remote_node);

include/linux/of_graph.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct device_node *of_graph_get_endpoint_by_regs(
5151
struct device_node *of_graph_get_remote_port_parent(
5252
const struct device_node *node);
5353
struct device_node *of_graph_get_remote_port(const struct device_node *node);
54+
struct device_node *of_graph_get_remote_node(const struct device_node *node,
55+
u32 port, u32 endpoint);
5456
#else
5557

5658
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(
8991
{
9092
return NULL;
9193
}
94+
static 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+
}
92100

93101
#endif /* CONFIG_OF */
94102

0 commit comments

Comments
 (0)