Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

of: property: add of_graph_get_next_port_endpoint()

We already have of_graph_get_next_endpoint(), but it is not
intuitive to use in some case.

(X) node {
(Y) ports {
(P0) port@0 { endpoint { remote-endpoint = ...; };};
(P10) port@1 { endpoint { remote-endpoint = ...; };
(P11) endpoint { remote-endpoint = ...; };};
(P2) port@2 { endpoint { remote-endpoint = ...; };};
};
};

For example, if I want to handle port@1's 2 endpoints (= P10, P11),
I want to use like below

P10 = of_graph_get_next_endpoint(port1, NULL);
P11 = of_graph_get_next_endpoint(port1, P10);

But 1st one will be error, because of_graph_get_next_endpoint()
requested 1st parameter is "node" (X) or "ports" (Y), not but "port".
Below works well, but it will get P0

P0 = of_graph_get_next_endpoint(node, NULL);
P0 = of_graph_get_next_endpoint(ports, NULL);

In other words, we can't handle P10/P11 directly via
of_graph_get_next_endpoint().

There is another non intuitive behavior on of_graph_get_next_endpoint().
In case of if I could get P10 pointer for some way, and if I want to
handle port@1 things by loop, I would like use it like below

/*
* "ep" is now P10, and handle port1 things here,
* but we don't know how many endpoints port1 have.
*
* Because "ep" is non NULL now, we can use port1
* as of_graph_get_next_endpoint(port1, xxx)
*/
do {
/* do something for port1 specific things here */
} while (ep = of_graph_get_next_endpoint(port1, ep))

But it also not worked as I expected.
I expect it will be P10 -> P11 -> NULL,
but it will be P10 -> P11 -> P2, because
of_graph_get_next_endpoint() will fetch "endpoint" beyond the "port".
It is not useful for generic driver.

To handle endpoint more intuitive, create of_graph_get_next_port_endpoint()

of_graph_get_next_port_endpoint(port1, NULL); // P10
of_graph_get_next_port_endpoint(port1, P10); // P11
of_graph_get_next_port_endpoint(port1, P11); // NULL

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87jzdyb5t5.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Kuninori Morimoto and committed by
Rob Herring (Arm)
58fe47d6 02ac5f9d

+48
+27
drivers/of/property.c
··· 668 668 EXPORT_SYMBOL(of_graph_get_next_port); 669 669 670 670 /** 671 + * of_graph_get_next_port_endpoint() - get next endpoint node in port. 672 + * If it reached to end of the port, it will return NULL. 673 + * @port: pointer to the target port node 674 + * @prev: previous endpoint node, or NULL to get first 675 + * 676 + * Return: An 'endpoint' node pointer with refcount incremented. Refcount 677 + * of the passed @prev node is decremented. 678 + */ 679 + struct device_node *of_graph_get_next_port_endpoint(const struct device_node *port, 680 + struct device_node *prev) 681 + { 682 + while (1) { 683 + prev = of_get_next_child(port, prev); 684 + if (!prev) 685 + break; 686 + if (WARN(!of_node_name_eq(prev, "endpoint"), 687 + "non endpoint node is used (%pOF)", prev)) 688 + continue; 689 + 690 + break; 691 + } 692 + 693 + return prev; 694 + } 695 + EXPORT_SYMBOL(of_graph_get_next_port_endpoint); 696 + 697 + /** 671 698 * of_graph_get_next_endpoint() - get next endpoint node 672 699 * @parent: pointer to the parent device node 673 700 * @prev: previous endpoint node, or NULL to get first
+21
include/linux/of_graph.h
··· 50 50 for (struct device_node *child __free(device_node) = of_graph_get_next_port(parent, NULL);\ 51 51 child != NULL; child = of_graph_get_next_port(parent, child)) 52 52 53 + /** 54 + * for_each_of_graph_port_endpoint - iterate over every endpoint in a port node 55 + * @parent: parent port node 56 + * @child: loop variable pointing to the current endpoint node 57 + * 58 + * When breaking out of the loop, and continue to use the @child, you need to 59 + * use return_ptr(@child) or no_free_ptr(@child) not to call __free() for it. 60 + */ 61 + #define for_each_of_graph_port_endpoint(parent, child) \ 62 + for (struct device_node *child __free(device_node) = of_graph_get_next_port_endpoint(parent, NULL);\ 63 + child != NULL; child = of_graph_get_next_port_endpoint(parent, child)) 64 + 53 65 #ifdef CONFIG_OF 54 66 bool of_graph_is_present(const struct device_node *node); 55 67 int of_graph_parse_endpoint(const struct device_node *node, ··· 73 61 struct device_node *previous); 74 62 struct device_node *of_graph_get_next_port(const struct device_node *parent, 75 63 struct device_node *port); 64 + struct device_node *of_graph_get_next_port_endpoint(const struct device_node *port, 65 + struct device_node *prev); 76 66 struct device_node *of_graph_get_endpoint_by_regs( 77 67 const struct device_node *parent, int port_reg, int reg); 78 68 struct device_node *of_graph_get_remote_endpoint( ··· 122 108 } 123 109 124 110 static inline struct device_node *of_graph_get_next_port( 111 + const struct device_node *parent, 112 + struct device_node *previous) 113 + { 114 + return NULL; 115 + } 116 + 117 + static inline struct device_node *of_graph_get_next_port_endpoint( 125 118 const struct device_node *parent, 126 119 struct device_node *previous) 127 120 {