From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kuninori Morimoto Subject: [PATCH 17/23] of_graph: add of_graph_get_endpoint_count() Date: Mon, 17 Oct 2016 08:37:32 +0000 Message-ID: <874m4b4bxm.wl%kuninori.morimoto.gx@renesas.com> References: <87shrv4c8x.wl%kuninori.morimoto.gx@renesas.com> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset="US-ASCII" Return-path: In-Reply-To: <87shrv4c8x.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Rob Herring , Mark Brown Cc: Linux-ALSA , Liam Girdwood , Simon , Laurent , Guennadi , Grant Likely , Frank Rowand , Linux-DT , Linux-Kernel List-Id: devicetree@vger.kernel.org From: Kuninori Morimoto OF graph want to count its endpoint number, same as of_get_child_count(). This patch adds of_graph_get_endpoint_count() which can check specific type. It will count all endpoint if type was NULL. Signed-off-by: Kuninori Morimoto --- drivers/of/base.c | 16 ++++++++++++++++ include/linux/of_graph.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 131f416..03a5bfc 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2529,3 +2529,19 @@ bool of_graph_port_type_is(struct device_node *port, char *type) return false; } EXPORT_SYMBOL(of_graph_port_type_is); + +int of_graph_get_endpoint_count(const struct device_node *np, char *type) +{ + struct device_node *port, *endpoint; + int num = 0; + + for_each_of_endpoint(np, port, endpoint) { + if (!type) + num++; + else + num += of_graph_port_type_is(port, type); + } + + return num; +} +EXPORT_SYMBOL(of_graph_get_endpoint_count); diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index eca1f3b..2d16be7 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -52,11 +52,13 @@ struct of_endpoint { child = of_graph_get_next_endpoint(parent, child)) #define of_graph_port_type_is_sound(n) of_graph_port_type_is(n, "sound") +#define of_graph_get_sound_endpoint_count(n) of_graph_get_endpoint_count(n, "sound") #ifdef CONFIG_OF int of_graph_parse_endpoint(const struct device_node *node, struct of_endpoint *endpoint); bool of_graph_port_type_is(struct device_node *port, char *type); +int of_graph_get_endpoint_count(const struct device_node *np, char *type); struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id); struct device_node *of_graph_get_top_port(struct device *dev); struct device_node *of_graph_get_next_port(const struct device_node *parent, @@ -87,6 +89,12 @@ static bool of_graph_port_type_is(struct device_node *port, char *type) return false; } +static inline int of_graph_get_endpoint_count(const struct device_node *np, + char *type) +{ + return 0; +} + static inline struct device_node *of_graph_get_port_by_id( struct device_node *node, u32 id) { -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html