From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kuninori Morimoto Subject: [PATCH 3/7] of_graph: add of_graph_port/endpoint_type_is() Date: Fri, 24 Jun 2016 02:32:59 +0000 Message-ID: <87bn2rxqyq.wl%kuninori.morimoto.gx@renesas.com> References: <87fus3xr2q.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: <87fus3xr2q.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Rob Herring , Mark Brown , Mark Brown , Laurent , Guennadi , Grant Likely , Frank Rowand Cc: Linux-Kernel , Linux-DT , Linux-ALSA List-Id: devicetree@vger.kernel.org From: Kuninori Morimoto OF graph endpoint is now used for V4L2 video, but ALSA will use it too. Then for example HDMI case, it needs to indicate endpoint type. Otherwise, ALSA can't handle sound endpoint correctly. This patch adds of_graph_port/endpoint_type_is() for it, and adds of_graph_port/endpoint_type_is_sound macro Signed-off-by: Kuninori Morimoto --- drivers/of/base.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_graph.h | 15 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 347118e..a0fc63c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2384,3 +2384,49 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node) return of_get_next_parent(np); } EXPORT_SYMBOL(of_graph_get_remote_port); + +static bool of_graph_node_type_is(struct device_node *np, char *type) +{ + const char *prop = NULL; + + of_property_read_string(np, "type", &prop); + + if (prop && + strcmp(prop, type) == 0) + return true; + + return false; +} + +bool of_graph_port_type_is(struct device_node *port, char *type) +{ + struct device_node *ports; + bool ret; + + /* try port side */ + ret = of_graph_node_type_is(port, type); + if (ret) + return ret; + + /* try ports side */ + ports = of_get_next_parent(port); + if (ports && of_node_cmp(ports->name, "ports") == 0) + return of_graph_node_type_is(ports, type); + + return false; +} +EXPORT_SYMBOL(of_graph_port_type_is); + +bool of_graph_endpoint_type_is(struct device_node *ep, char *type) +{ + bool ret; + + /* try endpoint side */ + ret = of_graph_node_type_is(ep, type); + if (ret) + return ret; + + /* try port side */ + return of_graph_port_type_is(of_get_parent(ep), type); +} +EXPORT_SYMBOL(of_graph_endpoint_type_is); diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index d9d6d9c..1750d5c 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -40,9 +40,14 @@ struct of_endpoint { for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \ 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_endpoint_type_is_sound(n) of_graph_endpoint_type_is(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); +bool of_graph_endpoint_type_is(struct device_node *ep, char *type); 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); @@ -61,6 +66,16 @@ static inline int of_graph_parse_endpoint(const struct device_node *node, return -ENOSYS; } +static bool of_graph_port_type_is(struct device_node *port, char *type) +{ + return false; +} + +static bool of_graph_endpoint_type_is(struct device_node *ep, char *type) +{ + return false; +} + 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