Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp260617imu; Mon, 10 Dec 2018 21:14:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/V2T/GzUx1+4StPpeqacR0hXqIJs7BtUve89yfaU6XXQutpLBEhqX9Y19Ia9+hjcyjuOMNg X-Received: by 2002:a63:413:: with SMTP id 19mr13214713pge.7.1544505255165; Mon, 10 Dec 2018 21:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544505255; cv=none; d=google.com; s=arc-20160816; b=ZQhVBl6Q5PfFQf8HWX4EWYnna2q6/bA86fh38G7TwMDjClkP1md9Comhuj4cVgB8ai 4bNRE9w4dLmau/yIw7euJlwwHrdlY3BRCTC3RDozbMixiEOsSsbAT6ZJZthsguI1He+P c4omsHdbwTy5Rme4K1BVDtxdj0Yb0t69J7V2n9EB2xprfpca4XW93ogOffsmYik4u/XI em35AmcVC/8pt3PoxCl+J7/K9GRwaIz6aZrxk/UdecgUEdA6D55Bus7EAE0/Rh5W4vDC MaE8IyKU/d7tmrP9fiSShjhqE0pd0mIg4s4QkdEXzRUBoDDgU4sJGmmWJI9EWS6MOVst t8kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1/Lb2oEGzz7ehTOWWeWZutnQqBEa4OqF87hz911xRHU=; b=a1or1JjWmwt4pV2Xpercj2ITxiaI7D+5QIJ37te/0FFPalwMnlLdrwPIGhxDQDd8mv GiMevN8zJIDUn8IFAmZelxpXAEH3bAN82E2/KOm2KfM94oO2EDwvF7Aqfd88Mx5LGF+H xpoHaBC5IOEzp9MPFHEGpDK/9KFyfIL8C/qfEMBHrNMw/yJNnhBvEZLTUvGWJst3Ac4O HaCPRAvsyGoGFo+i1UOgAyxsoQgiWcfvVFaHx7sWgLuXs1jU7nprTZEaW6QKN3Ee18U8 vsJdcfzFH0E1/Wnqb++IsQYldA0xYrbGsZDY8B28xHE2HhTg+b8xfj54PZdMmoYhCQ0d YqPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u184si11313543pgd.262.2018.12.10.21.14.00; Mon, 10 Dec 2018 21:14:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729418AbeLKCGP (ORCPT + 99 others); Mon, 10 Dec 2018 21:06:15 -0500 Received: from muru.com ([72.249.23.125]:57258 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729389AbeLKCGN (ORCPT ); Mon, 10 Dec 2018 21:06:13 -0500 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 Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Kuninori Morimoto Subject: [PATCH 2/2] ASoC: audio-graph-card: Fix parsing of multiple endpoints 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.19.2