Current of_graph_get_next_endpoint() will get next endpoint. ports { port@0 { endpoint@0 {...}; (A) endpoint@1 {...}; }; port@1 { (B) endpoint {...}; }; ... };
If it reached to end of port (A), it will get next endpoint from next port (B). This behavior is not intuitive to user. User assume it return NULL after (A) from this function name. This function gets "endpoint" from "device" one after another instead of "port". So let's rename related functions as of_graph_get_next_endpoint() -> of_graph_get_next_device_endpoint() of_graph_get_endpoint_count() -> of_graph_get_device_endpoint_count() for_each_endpoint_of_node() -> for_each_device_endpoint_of_node() Signed-off-by: Kuninori Morimoto <kuninori.morimoto...@renesas.com> --- .clang-format | 2 +- drivers/of/property.c | 24 +++++++++++++----------- include/linux/of_graph.h | 23 ++++++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.clang-format b/.clang-format index 0bbb1991defe..e8ca6d577073 100644 --- a/.clang-format +++ b/.clang-format @@ -231,6 +231,7 @@ ForEachMacros: - 'for_each_dedup_cand' - 'for_each_dev_addr' - 'for_each_dev_scope' + - 'for_each_device_endpoint_of_node' - 'for_each_dma_cap_mask' - 'for_each_dpcm_be' - 'for_each_dpcm_be_rollback' @@ -243,7 +244,6 @@ ForEachMacros: - 'for_each_element' - 'for_each_element_extid' - 'for_each_element_id' - - 'for_each_endpoint_of_node' - 'for_each_event' - 'for_each_event_tps' - 'for_each_evictable_lru' diff --git a/drivers/of/property.c b/drivers/of/property.c index 25d73409aeee..007729d66972 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -632,15 +632,17 @@ struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id) EXPORT_SYMBOL(of_graph_get_port_by_id); /** - * of_graph_get_next_endpoint() - get next endpoint node + * of_graph_get_next_device_endpoint() - get next endpoint node. If it reached to end of the port, + * it gets next endpoint from next port. + * * @parent: pointer to the parent device node * @prev: previous endpoint node, or NULL to get first * * Return: An 'endpoint' node pointer with refcount incremented. Refcount * of the passed @prev node is decremented. */ -struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, - struct device_node *prev) +struct device_node *of_graph_get_next_device_endpoint(const struct device_node *parent, + struct device_node *prev) { struct device_node *endpoint; struct device_node *port; @@ -696,7 +698,7 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, } while (!of_node_name_eq(port, "port")); } } -EXPORT_SYMBOL(of_graph_get_next_endpoint); +EXPORT_SYMBOL(of_graph_get_next_device_endpoint); /** * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers @@ -714,7 +716,7 @@ struct device_node *of_graph_get_endpoint_by_regs( struct of_endpoint endpoint; struct device_node *node = NULL; - for_each_endpoint_of_node(parent, node) { + for_each_device_endpoint_of_node(parent, node) { of_graph_parse_endpoint(node, &endpoint); if (((port_reg == -1) || (endpoint.port == port_reg)) && ((reg == -1) || (endpoint.id == reg))) @@ -812,22 +814,22 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node) EXPORT_SYMBOL(of_graph_get_remote_port); /** - * of_graph_get_endpoint_count() - get count of endpoint + * of_graph_get_device_endpoint_count() - get count of endpoint * @np: pointer to the parent device node * * Return: count of endpoint of this device node */ -unsigned int of_graph_get_endpoint_count(const struct device_node *np) +unsigned int of_graph_get_device_endpoint_count(const struct device_node *np) { struct device_node *endpoint; int num = 0; - for_each_endpoint_of_node(np, endpoint) + for_each_device_endpoint_of_node(np, endpoint) num++; return num; } -EXPORT_SYMBOL(of_graph_get_endpoint_count); +EXPORT_SYMBOL(of_graph_get_device_endpoint_count); /** * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint @@ -1017,8 +1019,8 @@ static struct fwnode_handle * of_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { - return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode), - to_of_node(prev))); + return of_fwnode_handle(of_graph_get_next_device_endpoint(to_of_node(fwnode), + to_of_node(prev))); } static struct fwnode_handle * diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index a4bea62bfa29..80b7a579e96a 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -26,25 +26,30 @@ struct of_endpoint { const struct device_node *local_node; }; +/* REMOVE ME */ +#define of_graph_get_next_endpoint(parent, previous) of_graph_get_next_device_endpoint(parent, previous) +#define for_each_endpoint_of_node(parent, child) for_each_device_endpoint_of_node(parent, child) +#define of_graph_get_endpoint_count(np) of_graph_get_device_endpoint_count(np) + /** - * for_each_endpoint_of_node - iterate over every endpoint in a device node + * for_each_device_endpoint_of_node - iterate over every endpoint in a device node * @parent: parent device node containing ports and endpoints * @child: loop variable pointing to the current endpoint node * * When breaking out of the loop, of_node_put(child) has to be called manually. */ -#define for_each_endpoint_of_node(parent, child) \ - for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \ - child = of_graph_get_next_endpoint(parent, child)) +#define for_each_device_endpoint_of_node(parent, child) \ + for (child = of_graph_get_next_device_endpoint(parent, NULL); child != NULL; \ + child = of_graph_get_next_device_endpoint(parent, child)) #ifdef CONFIG_OF bool of_graph_is_present(const struct device_node *node); int of_graph_parse_endpoint(const struct device_node *node, struct of_endpoint *endpoint); -unsigned int of_graph_get_endpoint_count(const struct device_node *np); +unsigned int of_graph_get_device_endpoint_count(const struct device_node *np); struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id); -struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, - struct device_node *previous); +struct device_node *of_graph_get_next_device_endpoint(const struct device_node *parent, + struct device_node *previous); struct device_node *of_graph_get_endpoint_by_regs( const struct device_node *parent, int port_reg, int reg); struct device_node *of_graph_get_remote_endpoint( @@ -68,7 +73,7 @@ static inline int of_graph_parse_endpoint(const struct device_node *node, return -ENOSYS; } -static inline unsigned int of_graph_get_endpoint_count(const struct device_node *np) +static inline unsigned int of_graph_get_device_endpoint_count(const struct device_node *np) { return 0; } @@ -79,7 +84,7 @@ static inline struct device_node *of_graph_get_port_by_id( return NULL; } -static inline struct device_node *of_graph_get_next_endpoint( +static inline struct device_node *of_graph_get_next_device_endpoint( const struct device_node *parent, struct device_node *previous) { -- 2.25.1