From patchwork Tue Dec 11 02:05:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 10722967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F72613BF for ; Tue, 11 Dec 2018 02:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D9AB2A8B0 for ; Tue, 11 Dec 2018 02:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51D8F2A8B1; Tue, 11 Dec 2018 02:06:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD1912A8B2 for ; Tue, 11 Dec 2018 02:06:27 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D07F4267B42; Tue, 11 Dec 2018 03:06:21 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 723F926770D; Tue, 11 Dec 2018 03:06:15 +0100 (CET) Received: from muru.com (muru.com [72.249.23.125]) by alsa0.perex.cz (Postfix) with ESMTP id D1C1C267B38 for ; Tue, 11 Dec 2018 03:06:12 +0100 (CET) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id B9EE78132; Tue, 11 Dec 2018 02:06:14 +0000 (UTC) From: Tony Lindgren To: Mark Brown Date: Mon, 10 Dec 2018 18:05:56 -0800 Message-Id: <20181211020557.61783-2-tony@atomide.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181211020557.61783-1-tony@atomide.com> References: <20181211020557.61783-1-tony@atomide.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Kuninori Morimoto , Liam Girdwood , linux-kernel@vger.kernel.org, Takashi Iwai , linux-omap@vger.kernel.org Subject: [alsa-devel] [PATCH 1/2] ASoC: simple-card-utils: revert port changes to follow graph binding X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Commit b6f3fc005a2c ("ASoC: simple-card-utils: fixup asoc_simple_card_get_dai_id() counting") changed endpoint parsing for asoc_simple_card_get_dai_id(), but it seems the old code is correct. This code should follow the generic binding documentation for Documentation/devicetree/bindings/graph.txt that allows multiple endpoints for each port. Cc: Kuninori Morimoto Signed-off-by: Tony Lindgren --- sound/soc/generic/simple-card-utils.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -269,19 +269,35 @@ EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dai); static int asoc_simple_card_get_dai_id(struct device_node *ep) { - struct of_endpoint info; + struct device_node *node; + struct device_node *endpoint; + int i, id; int ret; ret = snd_soc_get_dai_id(ep); if (ret != -ENOTSUPP) return ret; + node = of_graph_get_port_parent(ep); + /* * Non HDMI sound case, counting port/endpoint on its DT * is enough. Let's count it. */ - of_graph_parse_endpoint(ep, &info); - return info.port; + i = 0; + id = -1; + for_each_endpoint_of_node(node, endpoint) { + if (endpoint == ep) + id = i; + i++; + } + + of_node_put(node); + + if (id < 0) + return -ENODEV; + + return id; } int asoc_simple_card_parse_graph_dai(struct device_node *ep, From patchwork Tue Dec 11 02:05:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 10722969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BFA113AF for ; Tue, 11 Dec 2018 02:06:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBA1C2A8B0 for ; Tue, 11 Dec 2018 02:06:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC9142A8B2; Tue, 11 Dec 2018 02:06:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DC752A8B0 for ; Tue, 11 Dec 2018 02:06:33 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 6664F267B41; Tue, 11 Dec 2018 03:06:24 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 80976267B38; Tue, 11 Dec 2018 03:06:16 +0100 (CET) Received: from muru.com (muru.com [72.249.23.125]) by alsa0.perex.cz (Postfix) with ESMTP id 65FC0267B41 for ; Tue, 11 Dec 2018 03:06:14 +0100 (CET) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 48DB68138; Tue, 11 Dec 2018 02:06:16 +0000 (UTC) From: Tony Lindgren To: Mark Brown Date: Mon, 10 Dec 2018 18:05:57 -0800 Message-Id: <20181211020557.61783-3-tony@atomide.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181211020557.61783-1-tony@atomide.com> References: <20181211020557.61783-1-tony@atomide.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Kuninori Morimoto , Liam Girdwood , linux-kernel@vger.kernel.org, Takashi Iwai , linux-omap@vger.kernel.org Subject: [alsa-devel] [PATCH 2/2] ASoC: audio-graph-card: Fix parsing of multiple endpoints X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP We currently use only the first endpoint even if multiple endpoints are configured for a port. We should follow what's specified in the device graph binding document Documentation/devicetree/bindings/graph.txt in paragraph "Organisation of ports and endpoints": "If a single port is connected to more than one remote device, an 'endpoint' child node must be provided for each link." This is the case for example for I2S where multiple devices can be connected to a single I2S port sharing it using TDM (Time-Division Multiplexing). To fix this, we need to iterate over each endpoint for a port. Note that the dts "dais" property should still contain a single property for each port, and not for each endpoint. Cc: Kuninori Morimoto Signed-off-by: Tony Lindgren --- sound/soc/generic/audio-graph-card.c | 41 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -156,17 +156,17 @@ static int asoc_graph_card_dai_init(struct snd_soc_pcm_runtime *rtd) return 0; } -static int asoc_graph_card_dai_link_of(struct device_node *cpu_port, +static int asoc_graph_card_ep_of(struct device_node *cpu_port, + struct device_node *cpu_ep, struct graph_card_data *priv, int *dai_idx, int link_idx) { struct device *dev = graph_priv_to_dev(priv); struct snd_soc_dai_link *dai_link = graph_priv_to_link(priv, link_idx); struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx); + struct device_node *codec_ep = of_graph_get_remote_endpoint(cpu_ep); struct asoc_simple_dai *cpu_dai; struct asoc_simple_dai *codec_dai; - struct device_node *cpu_ep = of_get_next_child(cpu_port, NULL); - struct device_node *codec_ep = of_graph_get_remote_endpoint(cpu_ep); int ret; cpu_dai = @@ -230,6 +230,31 @@ static int asoc_graph_card_dai_link_of(struct device_node *cpu_port, return ret; } +static int asoc_graph_card_dai_link_of(struct device_node *cpu_port, + struct graph_card_data *priv, + int *dai_idx, int link_idx) +{ + struct device *dev = graph_priv_to_dev(priv); + struct device_node *ep = NULL; + int num_ep, ep_idx, ret; + + num_ep = of_get_child_count(cpu_port); + if (!num_ep) { + dev_err(dev, "no cpu endpoints found for %pOf\n", cpu_port); + return -ENODEV; + } + + for (ep_idx = 0; ep_idx < num_ep; ep_idx++) { + ep = of_get_next_child(cpu_port, ep); + ret = asoc_graph_card_ep_of(cpu_port, ep, priv, + dai_idx, link_idx + ep_idx); + if (ret) + return ret; + } + + return ret; +} + static int asoc_graph_card_parse_of(struct graph_card_data *priv) { struct of_phandle_iterator it; @@ -272,8 +297,14 @@ static int asoc_graph_get_dais_count(struct device *dev) int count = 0; int rc; - of_for_each_phandle(&it, rc, node, "dais", NULL, 0) - count++; + of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { + int ep_count = of_get_child_count(it.node); + + if (ep_count) + count += ep_count; + else + count++; + } return count; }