Skip to content

Commit 8ccd0d0

Browse files
Hyungwon Hwangdaeinki
authored andcommitted
of: add helper for getting endpoint node of specific identifiers
When there are multiple ports or multiple endpoints in a port, they have to be distinguished by the value of reg property. It is common. The drivers can get the specific endpoint in the specific port via this function. Now the drivers have to implement this code in themselves or have to force the order of dt nodes to get the right node. Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com> Acked-by: Rob Herring <robh+dt@kernel.org> Signed-off-by: Inki Dae <inki.dae@samsung.com>
1 parent c8466a9 commit 8ccd0d0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

drivers/of/base.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,39 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
22322232
}
22332233
EXPORT_SYMBOL(of_graph_get_next_endpoint);
22342234

2235+
/**
2236+
* of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
2237+
* @parent: pointer to the parent device node
2238+
* @port_reg: identifier (value of reg property) of the parent port node
2239+
* @reg: identifier (value of reg property) of the endpoint node
2240+
*
2241+
* Return: An 'endpoint' node pointer which is identified by reg and at the same
2242+
* is the child of a port node identified by port_reg. reg and port_reg are
2243+
* ignored when they are -1.
2244+
*/
2245+
struct device_node *of_graph_get_endpoint_by_regs(
2246+
const struct device_node *parent, int port_reg, int reg)
2247+
{
2248+
struct of_endpoint endpoint;
2249+
struct device_node *node, *prev_node = NULL;
2250+
2251+
while (1) {
2252+
node = of_graph_get_next_endpoint(parent, prev_node);
2253+
of_node_put(prev_node);
2254+
if (!node)
2255+
break;
2256+
2257+
of_graph_parse_endpoint(node, &endpoint);
2258+
if (((port_reg == -1) || (endpoint.port == port_reg)) &&
2259+
((reg == -1) || (endpoint.id == reg)))
2260+
return node;
2261+
2262+
prev_node = node;
2263+
}
2264+
2265+
return NULL;
2266+
}
2267+
22352268
/**
22362269
* of_graph_get_remote_port_parent() - get remote port's parent node
22372270
* @node: pointer to a local endpoint device_node

include/linux/of_graph.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int of_graph_parse_endpoint(const struct device_node *node,
4545
struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
4646
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
4747
struct device_node *previous);
48+
struct device_node *of_graph_get_endpoint_by_regs(
49+
const struct device_node *parent, int port_reg, int reg);
4850
struct device_node *of_graph_get_remote_port_parent(
4951
const struct device_node *node);
5052
struct device_node *of_graph_get_remote_port(const struct device_node *node);
@@ -69,6 +71,12 @@ static inline struct device_node *of_graph_get_next_endpoint(
6971
return NULL;
7072
}
7173

74+
struct device_node *of_graph_get_endpoint_by_regs(
75+
const struct device_node *parent, int port_reg, int reg)
76+
{
77+
return NULL;
78+
}
79+
7280
static inline struct device_node *of_graph_get_remote_port_parent(
7381
const struct device_node *node)
7482
{

0 commit comments

Comments
 (0)