diff options
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 28d5f53bc631..cb1c49ae3b88 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1601,6 +1601,7 @@ int of_phandle_iterator_init(struct of_phandle_iterator *it, | |||
1601 | 1601 | ||
1602 | return 0; | 1602 | return 0; |
1603 | } | 1603 | } |
1604 | EXPORT_SYMBOL_GPL(of_phandle_iterator_init); | ||
1604 | 1605 | ||
1605 | int of_phandle_iterator_next(struct of_phandle_iterator *it) | 1606 | int of_phandle_iterator_next(struct of_phandle_iterator *it) |
1606 | { | 1607 | { |
@@ -1670,6 +1671,7 @@ err: | |||
1670 | 1671 | ||
1671 | return -EINVAL; | 1672 | return -EINVAL; |
1672 | } | 1673 | } |
1674 | EXPORT_SYMBOL_GPL(of_phandle_iterator_next); | ||
1673 | 1675 | ||
1674 | int of_phandle_iterator_args(struct of_phandle_iterator *it, | 1676 | int of_phandle_iterator_args(struct of_phandle_iterator *it, |
1675 | uint32_t *args, | 1677 | uint32_t *args, |
@@ -2485,6 +2487,41 @@ struct device_node *of_graph_get_endpoint_by_regs( | |||
2485 | EXPORT_SYMBOL(of_graph_get_endpoint_by_regs); | 2487 | EXPORT_SYMBOL(of_graph_get_endpoint_by_regs); |
2486 | 2488 | ||
2487 | /** | 2489 | /** |
2490 | * of_graph_get_remote_endpoint() - get remote endpoint node | ||
2491 | * @node: pointer to a local endpoint device_node | ||
2492 | * | ||
2493 | * Return: Remote endpoint node associated with remote endpoint node linked | ||
2494 | * to @node. Use of_node_put() on it when done. | ||
2495 | */ | ||
2496 | struct device_node *of_graph_get_remote_endpoint(const struct device_node *node) | ||
2497 | { | ||
2498 | /* Get remote endpoint node. */ | ||
2499 | return of_parse_phandle(node, "remote-endpoint", 0); | ||
2500 | } | ||
2501 | EXPORT_SYMBOL(of_graph_get_remote_endpoint); | ||
2502 | |||
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 | /** | ||
2488 | * 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 |
2489 | * @node: pointer to a local endpoint device_node | 2526 | * @node: pointer to a local endpoint device_node |
2490 | * | 2527 | * |
@@ -2495,18 +2532,11 @@ struct device_node *of_graph_get_remote_port_parent( | |||
2495 | const struct device_node *node) | 2532 | const struct device_node *node) |
2496 | { | 2533 | { |
2497 | struct device_node *np; | 2534 | struct device_node *np; |
2498 | unsigned int depth; | ||
2499 | 2535 | ||
2500 | /* Get remote endpoint node. */ | 2536 | /* Get remote endpoint node. */ |
2501 | np = of_parse_phandle(node, "remote-endpoint", 0); | 2537 | np = of_graph_get_remote_endpoint(node); |
2502 | 2538 | ||
2503 | /* Walk 3 levels up only if there is 'ports' node. */ | 2539 | return of_graph_get_port_parent(np); |
2504 | for (depth = 3; depth && np; depth--) { | ||
2505 | np = of_get_next_parent(np); | ||
2506 | if (depth == 2 && of_node_cmp(np->name, "ports")) | ||
2507 | break; | ||
2508 | } | ||
2509 | return np; | ||
2510 | } | 2540 | } |
2511 | EXPORT_SYMBOL(of_graph_get_remote_port_parent); | 2541 | EXPORT_SYMBOL(of_graph_get_remote_port_parent); |
2512 | 2542 | ||
@@ -2522,13 +2552,25 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node) | |||
2522 | struct device_node *np; | 2552 | struct device_node *np; |
2523 | 2553 | ||
2524 | /* Get remote endpoint node. */ | 2554 | /* Get remote endpoint node. */ |
2525 | np = of_parse_phandle(node, "remote-endpoint", 0); | 2555 | np = of_graph_get_remote_endpoint(node); |
2526 | if (!np) | 2556 | if (!np) |
2527 | return NULL; | 2557 | return NULL; |
2528 | return of_get_next_parent(np); | 2558 | return of_get_next_parent(np); |
2529 | } | 2559 | } |
2530 | EXPORT_SYMBOL(of_graph_get_remote_port); | 2560 | EXPORT_SYMBOL(of_graph_get_remote_port); |
2531 | 2561 | ||
2562 | int of_graph_get_endpoint_count(const struct device_node *np) | ||
2563 | { | ||
2564 | struct device_node *endpoint; | ||
2565 | int num = 0; | ||
2566 | |||
2567 | for_each_endpoint_of_node(np, endpoint) | ||
2568 | num++; | ||
2569 | |||
2570 | return num; | ||
2571 | } | ||
2572 | EXPORT_SYMBOL(of_graph_get_endpoint_count); | ||
2573 | |||
2532 | /** | 2574 | /** |
2533 | * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint | 2575 | * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint |
2534 | * @node: pointer to parent device_node containing graph port/endpoint | 2576 | * @node: pointer to parent device_node containing graph port/endpoint |