diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2017-04-19 21:32:17 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-05-17 05:21:12 -0400 |
commit | 0ef472a973ebbfc20f2f12769e77a8cfd3612778 (patch) | |
tree | ef4228cd70a146b12f63e699e64e726e5b5cd54b | |
parent | 4c9c3d595f1bad021cc126d20879df4016801736 (diff) |
of_graph: add of_graph_get_port_parent()
Linux kernel already has of_graph_get_remote_port_parent(),
but, sometimes we want to get own port parent.
This patch adds of_graph_get_port_parent()
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/of/base.c | 30 | ||||
-rw-r--r-- | include/linux/of_graph.h | 7 |
2 files changed, 29 insertions, 8 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index b169508a9b56..4c305599a664 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -2501,6 +2501,27 @@ struct device_node *of_graph_get_remote_endpoint(const struct device_node *node) | |||
2501 | EXPORT_SYMBOL(of_graph_get_remote_endpoint); | 2501 | EXPORT_SYMBOL(of_graph_get_remote_endpoint); |
2502 | 2502 | ||
2503 | /** | 2503 | /** |
2504 | * of_graph_get_port_parent() - get port's parent node | ||
2505 | * @node: pointer to a local endpoint device_node | ||
2506 | * | ||
2507 | * Return: device node associated with endpoint node linked | ||
2508 | * to @node. Use of_node_put() on it when done. | ||
2509 | */ | ||
2510 | struct device_node *of_graph_get_port_parent(struct device_node *node) | ||
2511 | { | ||
2512 | unsigned int depth; | ||
2513 | |||
2514 | /* Walk 3 levels up only if there is 'ports' node. */ | ||
2515 | for (depth = 3; depth && node; depth--) { | ||
2516 | node = of_get_next_parent(node); | ||
2517 | if (depth == 2 && of_node_cmp(node->name, "ports")) | ||
2518 | break; | ||
2519 | } | ||
2520 | return node; | ||
2521 | } | ||
2522 | EXPORT_SYMBOL(of_graph_get_port_parent); | ||
2523 | |||
2524 | /** | ||
2504 | * of_graph_get_remote_port_parent() - get remote port's parent node | 2525 | * of_graph_get_remote_port_parent() - get remote port's parent node |
2505 | * @node: pointer to a local endpoint device_node | 2526 | * @node: pointer to a local endpoint device_node |
2506 | * | 2527 | * |
@@ -2511,18 +2532,11 @@ struct device_node *of_graph_get_remote_port_parent( | |||
2511 | const struct device_node *node) | 2532 | const struct device_node *node) |
2512 | { | 2533 | { |
2513 | struct device_node *np; | 2534 | struct device_node *np; |
2514 | unsigned int depth; | ||
2515 | 2535 | ||
2516 | /* Get remote endpoint node. */ | 2536 | /* Get remote endpoint node. */ |
2517 | np = of_graph_get_remote_endpoint(node); | 2537 | np = of_graph_get_remote_endpoint(node); |
2518 | 2538 | ||
2519 | /* Walk 3 levels up only if there is 'ports' node. */ | 2539 | return of_graph_get_port_parent(np); |
2520 | for (depth = 3; depth && np; depth--) { | ||
2521 | np = of_get_next_parent(np); | ||
2522 | if (depth == 2 && of_node_cmp(np->name, "ports")) | ||
2523 | break; | ||
2524 | } | ||
2525 | return np; | ||
2526 | } | 2540 | } |
2527 | EXPORT_SYMBOL(of_graph_get_remote_port_parent); | 2541 | EXPORT_SYMBOL(of_graph_get_remote_port_parent); |
2528 | 2542 | ||
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index 0c9473a169dd..9db632d16cbc 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h | |||
@@ -50,6 +50,7 @@ struct device_node *of_graph_get_endpoint_by_regs( | |||
50 | const struct device_node *parent, int port_reg, int reg); | 50 | const struct device_node *parent, int port_reg, int reg); |
51 | struct device_node *of_graph_get_remote_endpoint( | 51 | struct device_node *of_graph_get_remote_endpoint( |
52 | const struct device_node *node); | 52 | const struct device_node *node); |
53 | struct device_node *of_graph_get_port_parent(struct device_node *node); | ||
53 | struct device_node *of_graph_get_remote_port_parent( | 54 | struct device_node *of_graph_get_remote_port_parent( |
54 | const struct device_node *node); | 55 | const struct device_node *node); |
55 | struct device_node *of_graph_get_remote_port(const struct device_node *node); | 56 | struct device_node *of_graph_get_remote_port(const struct device_node *node); |
@@ -88,6 +89,12 @@ static inline struct device_node *of_graph_get_remote_endpoint( | |||
88 | return NULL; | 89 | return NULL; |
89 | } | 90 | } |
90 | 91 | ||
92 | static inline struct device_node *of_graph_get_port_parent( | ||
93 | struct device_node *node) | ||
94 | { | ||
95 | return NULL; | ||
96 | } | ||
97 | |||
91 | static inline struct device_node *of_graph_get_remote_port_parent( | 98 | static inline struct device_node *of_graph_get_remote_port_parent( |
92 | const struct device_node *node) | 99 | const struct device_node *node) |
93 | { | 100 | { |