From patchwork Fri Mar 26 03:25:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 409567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29ABEC433C1 for ; Fri, 26 Mar 2021 03:27:30 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E399E61A2A for ; Fri, 26 Mar 2021 03:27:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E399E61A2A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EF470165D; Fri, 26 Mar 2021 04:26:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EF470165D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729247; bh=jUAF/XKaOUmCX3OFnWxUi47cFOhXx0s/77zBfyOAWlY=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AuxL45OpxdjV3AiT00yp2Ime8xs494otkYwy+FS5PgziKcj2PrsyS7qasGPUjfs+S +tKqI+ZsN+aj1O3nqCxtvGqqlDDgtqLWwCz+JK7CTWXuq3Z4n72NwqcGheHxAAVEBF fx9UcUB79TAeY9n9E5k4Hg+anUbYJ0UeiALnr1xA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1DE0DF8032C; Fri, 26 Mar 2021 04:26:10 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 16B34F8032C; Fri, 26 Mar 2021 04:26:08 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 406B6F80240 for ; Fri, 26 Mar 2021 04:25:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 406B6F80240 Date: 26 Mar 2021 12:25:57 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76117669" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 26 Mar 2021 12:25:57 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id CACFB400A115; Fri, 26 Mar 2021 12:25:57 +0900 (JST) Message-ID: <87czvm1tq2.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto commit adb76b5b9c474 ("ASoC: soc-core: remove legacy style dai_link") removed snd_soc_init_multicodec(). The comment on asoc_simple_init_priv() is no longer needed. This patch removes it. Signed-off-by: Kuninori Morimoto --- sound/soc/generic/simple-card-utils.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 06c2512b6f2d..6897455219d1 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -617,11 +617,6 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, } /* - * Use snd_soc_dai_link_component instead of legacy style - * It is codec only. but cpu/platform will be supported in the future. - * see - * soc-core.c :: snd_soc_init_multicodec() - * * "platform" might be removed * see * simple-card-utils.c :: asoc_simple_canonicalize_platform() From patchwork Fri Mar 26 03:26:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 410206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E84BC433E2 for ; Fri, 26 Mar 2021 03:27:37 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BBF961A28 for ; Fri, 26 Mar 2021 03:27:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BBF961A28 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 332091684; Fri, 26 Mar 2021 04:26:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 332091684 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729255; bh=kpF3vOOF7IeNzwndGbUFv2X1O30WBin5Hpm7H1cGJmo=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=reLGES9iDPnlheSHZasGT3nLKONDbtUL6uHmpN9FP5MHtfJuPn0ns7WhKAYaBd/4j GvZSugVYQo8xiVxpyWWE5muXL0My45+y/P1V8H7pa3dv3YY5YHFqtmA0XtbbDIdf6t iEIDrw1Yc1s7vLIOGYD7SvCNuEpF0hQeDM6P0v6E= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7F55AF80425; Fri, 26 Mar 2021 04:26:17 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 52F30F80425; Fri, 26 Mar 2021 04:26:11 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 38404F802E3 for ; Fri, 26 Mar 2021 04:26:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 38404F802E3 Date: 26 Mar 2021 12:26:06 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76117694" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 26 Mar 2021 12:26:06 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id E624C41A2E15; Fri, 26 Mar 2021 12:26:04 +0900 (JST) Message-ID: <87blb61tpv.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto simple-card / audio-graph are assuming single CPU/Codec/Platform on dai_link. Because of it, it is difficult to support Multi-CPU/Codec. This patch allocs CPU/Codec/Platform dai_link imformation instead of using existing props information. It can update to multi-CPU/Codec, but is still assuming single-CPU/Codec for now. Signed-off-by: Kuninori Morimoto --- include/sound/simple_card_utils.h | 7 ++++--- sound/soc/generic/simple-card-utils.c | 15 +++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index ba4a3e1897b9..86e46cbf9e14 100644 --- a/include/sound/simple_card_utils.h +++ b/include/sound/simple_card_utils.h @@ -43,9 +43,9 @@ struct asoc_simple_priv { struct simple_dai_props { struct asoc_simple_dai *cpu_dai; struct asoc_simple_dai *codec_dai; - struct snd_soc_dai_link_component cpus; /* single cpu */ - struct snd_soc_dai_link_component codecs; /* single codec */ - struct snd_soc_dai_link_component platforms; + struct snd_soc_dai_link_component *cpus; + struct snd_soc_dai_link_component *codecs; + struct snd_soc_dai_link_component *platforms; struct asoc_simple_data adata; struct snd_soc_codec_conf *codec_conf; unsigned int mclk_fs; @@ -54,6 +54,7 @@ struct asoc_simple_priv { struct asoc_simple_jack mic_jack; struct snd_soc_dai_link *dai_link; struct asoc_simple_dai *dais; + struct snd_soc_dai_link_component *dlcs; struct snd_soc_codec_conf *codec_conf; struct gpio_desc *pa_gpio; const struct snd_soc_ops *ops; diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 6897455219d1..f05954529dfc 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -601,13 +601,15 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, struct snd_soc_dai_link *dai_link; struct simple_dai_props *dai_props; struct asoc_simple_dai *dais; + struct snd_soc_dai_link_component *dlcs; struct snd_soc_codec_conf *cconf = NULL; int i; dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); dais = devm_kcalloc(dev, li->dais, sizeof(*dais), GFP_KERNEL); - if (!dai_props || !dai_link || !dais) + dlcs = devm_kcalloc(dev, li->link * 3, sizeof(*dai_props), GFP_KERNEL); + if (!dai_props || !dai_link || !dais || !dlcs) return -ENOMEM; if (li->conf) { @@ -622,17 +624,22 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, * simple-card-utils.c :: asoc_simple_canonicalize_platform() */ for (i = 0; i < li->link; i++) { - dai_link[i].cpus = &dai_props[i].cpus; + dai_props[i].cpus = dlcs + (3 * i) + 0; + dai_props[i].codecs = dlcs + (3 * i) + 1; + dai_props[i].platforms = dlcs + (3 * i) + 2; + + dai_link[i].cpus = dai_props[i].cpus; dai_link[i].num_cpus = 1; - dai_link[i].codecs = &dai_props[i].codecs; + dai_link[i].codecs = dai_props[i].codecs; dai_link[i].num_codecs = 1; - dai_link[i].platforms = &dai_props[i].platforms; + dai_link[i].platforms = dai_props[i].platforms; dai_link[i].num_platforms = 1; } priv->dai_props = dai_props; priv->dai_link = dai_link; priv->dais = dais; + priv->dlcs = dlcs; priv->codec_conf = cconf; card->dai_link = priv->dai_link; From patchwork Fri Mar 26 03:26:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 409566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7D76C433C1 for ; Fri, 26 Mar 2021 03:28:08 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2018D61A2A for ; Fri, 26 Mar 2021 03:28:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2018D61A2A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 962E615DC; Fri, 26 Mar 2021 04:27:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 962E615DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729286; bh=H/UelChSB7UORVUH3I7ymFDVjZsbGBiYa4VbB4vLAzI=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=urWD5sPjYmCO92/Qjw9qf5blCBkigrqpgrqY34jn0zeyiVFHqCQaddDqGYjvU8bZI SxdEaz4jGxH6MV1IS+9UAfxpcj4wMEU7SOSEUA4ZA3fvTRg+jYLo/8YG3+oMdSjfb4 JhUxvQXl+3gFYZDN2QhopLPzRqYuA4XOidROJpOI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C7CDBF80431; Fri, 26 Mar 2021 04:26:19 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CFAADF80424; Fri, 26 Mar 2021 04:26:17 +0100 (CET) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by alsa1.perex.cz (Postfix) with ESMTP id 5D304F8032D for ; Fri, 26 Mar 2021 04:26:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5D304F8032D Date: 26 Mar 2021 12:26:11 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76343900" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 26 Mar 2021 12:26:11 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 02FC240104F3; Fri, 26 Mar 2021 12:26:11 +0900 (JST) Message-ID: <87a6qq1tpp.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 3/6] ASoC: audio-graph: count DAI / link numbers as in order User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto audio-graph checks DT links 2 times. 1st is for counting DAIs / links to allocating memory, 2nd is for detecting DAIs. To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case, it uses loops 2 times at 2nd DT link check. But it doesn't do it at 1st DT link check. for (li.cpu = 1; li.cpu >= 0; li.cpu--) { /* * Detect all CPU first, and Detect all Codec 2n * * In Normal sound case, all DAIs are detected * as "CPU-Codec". * * In DPCM sound case, * all CPUs are detected as "CPU-dummy", and * all Codecs are detected as "dummy-Codec". * To avoid random sub-device numbering, * detect "dummy-Codec" in last; */ ret = graph_for_each_link(...); ... } To prepare supporting multi-CPU/Codec, and code cleanup, this patch use same loop for 1st DT link check, too. Signed-off-by: Kuninori Morimoto --- sound/soc/generic/audio-graph-card.c | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 8c5cdcdc8713..3a967c520b01 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -617,6 +617,10 @@ static int graph_count_noml(struct asoc_simple_priv *priv, { struct device *dev = simple_priv_to_dev(priv); + /* Do it only CPU turn */ + if (!li->cpu) + return 0; + li->link += 1; /* 1xCPU-Codec */ li->dais += 2; /* 1xCPU + 1xCodec */ @@ -633,10 +637,22 @@ static int graph_count_dpcm(struct asoc_simple_priv *priv, { struct device *dev = simple_priv_to_dev(priv); - li->link++; /* 1xCPU-dummy */ - li->dais++; /* 1xCPU */ + /* + * Codec endpoint can be NULL for pluggable audio HW. + * Platform DT can populate the Codec endpoint depending on the + * plugged HW. + */ + if (!li->cpu && !codec_ep) + return 0; + + /* Do it all CPU endpoint, and 1st Codec endpoint */ + if (!li->cpu && dup_codec) + return 0; - if (!dup_codec && codec_ep) { + if (li->cpu) { + li->link++; /* 1xCPU-dummy */ + li->dais++; /* 1xCPU */ + } else if (!dup_codec && codec_ep) { li->link++; /* 1xdummy-Codec */ li->conf++; /* 1xdummy-Codec */ li->dais++; /* 1xCodec */ @@ -698,9 +714,10 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv, * => 4 DAIs = 2xCPU + 2xCodec * => 1 ccnf = 1xdummy-Codec */ - graph_for_each_link(priv, li, - graph_count_noml, - graph_count_dpcm); + for (li->cpu = 1; li->cpu >= 0; li->cpu--) + graph_for_each_link(priv, li, + graph_count_noml, + graph_count_dpcm); dev_dbg(dev, "link %d, dais %d, ccnf %d\n", li->link, li->dais, li->conf); } From patchwork Fri Mar 26 03:26:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 410205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5721AC433DB for ; Fri, 26 Mar 2021 03:28:21 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF67E61A27 for ; Fri, 26 Mar 2021 03:28:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF67E61A27 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 61F971688; Fri, 26 Mar 2021 04:27:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 61F971688 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729299; bh=5YPcscsBdvFP+cK/tNy9Of5UBgpF/7eB6JTeFog/GHA=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BSt0ye8X0J7ITQj6N3t40bSMjNjBmfa3iPZs9O7A6EpYXoB6EUoRQYUzBTiipIDET oQ46rHO7hteUMipn3eFnf5svC1T+8H0TZ+vCj1FZqntTH6SsQy8Zx9+Mr3/OVapYXV KfWSaen0Fui7Nq1Rtw8yvfQQOda947cWziWWXqkU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AF695F801EC; Fri, 26 Mar 2021 04:26:40 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 81322F80156; Fri, 26 Mar 2021 04:26:38 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id BB54AF80475 for ; Fri, 26 Mar 2021 04:26:21 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BB54AF80475 Date: 26 Mar 2021 12:26:20 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76117708" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 26 Mar 2021 12:26:20 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id D744D400F4F5; Fri, 26 Mar 2021 12:26:20 +0900 (JST) Message-ID: <878s6a1tpf.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 4/6] ASoC: audio-graph: cleanup graph_for_each_link() User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto audio-graph checks DT links 2 times. 1st is for counting DAIs / links to allocating memory, 2nd is for detecting DAIs. To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case, it uses loops 2 times. Because of this kind of complex background, it needs to use local varuable for it, and each call-back functions need to care about it. Now, 1st and 2nd DT link check are using same order, thus we can share same code. This patch do it. Signed-off-by: Kuninori Morimoto --- sound/soc/generic/audio-graph-card.c | 129 +++++++++++++-------------- 1 file changed, 61 insertions(+), 68 deletions(-) diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 3a967c520b01..ee1d924d68e5 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -212,8 +212,7 @@ static void graph_parse_mclk_fs(struct device_node *top, static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv, struct device_node *cpu_ep, struct device_node *codec_ep, - struct link_info *li, - int dup_codec) + struct link_info *li) { struct device *dev = simple_priv_to_dev(priv); struct snd_soc_card *card = simple_priv_to_card(priv); @@ -229,18 +228,6 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv, struct snd_soc_dai_link_component *codecs = dai_link->codecs; int ret; - /* - * Codec endpoint can be NULL for pluggable audio HW. - * Platform DT can populate the Codec endpoint depending on the - * plugged HW. - */ - if (!li->cpu && !codec_ep) - return 0; - - /* Do it all CPU endpoint, and 1st Codec endpoint */ - if (!li->cpu && dup_codec) - return 0; - port = of_get_parent(ep); ports = of_get_parent(port); node = of_graph_get_port_parent(ep); @@ -382,10 +369,6 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv, struct asoc_simple_dai *codec_dai; int ret, single_cpu; - /* Do it only CPU turn */ - if (!li->cpu) - return 0; - dev_dbg(dev, "link_of (%pOF)\n", cpu_ep); li->link++; @@ -466,7 +449,7 @@ static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv, return false; } -static int graph_for_each_link(struct asoc_simple_priv *priv, +static int __graph_for_each_link(struct asoc_simple_priv *priv, struct link_info *li, int (*func_noml)(struct asoc_simple_priv *priv, struct device_node *cpu_ep, @@ -475,7 +458,7 @@ static int graph_for_each_link(struct asoc_simple_priv *priv, int (*func_dpcm)(struct asoc_simple_priv *priv, struct device_node *cpu_ep, struct device_node *codec_ep, - struct link_info *li, int dup_codec)) + struct link_info *li)) { struct of_phandle_iterator it; struct device *dev = simple_priv_to_dev(priv); @@ -486,7 +469,7 @@ static int graph_for_each_link(struct asoc_simple_priv *priv, struct device_node *codec_port; struct device_node *codec_port_old = NULL; struct asoc_simple_data adata; - int rc, ret; + int rc, ret = 0; /* loop for all listed CPU port */ of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { @@ -509,12 +492,21 @@ static int graph_for_each_link(struct asoc_simple_priv *priv, graph_parse_convert(dev, cpu_ep, &adata); /* check if link requires DPCM parsing */ - if (parse_as_dpcm_link(priv, codec_port, &adata)) - ret = func_dpcm(priv, cpu_ep, codec_ep, li, - (codec_port_old == codec_port)); + if (parse_as_dpcm_link(priv, codec_port, &adata)) { + /* + * Codec endpoint can be NULL for pluggable audio HW. + * Platform DT can populate the Codec endpoint depending on the + * plugged HW. + */ + /* Do it all CPU endpoint, and 1st Codec endpoint */ + if (li->cpu || + ((codec_port_old != codec_port) && codec_ep)) + ret = func_dpcm(priv, cpu_ep, codec_ep, li); /* else normal sound */ - else - ret = func_noml(priv, cpu_ep, codec_ep, li); + } else { + if (li->cpu) + ret = func_noml(priv, cpu_ep, codec_ep, li); + } of_node_put(codec_ep); of_node_put(codec_port); @@ -529,6 +521,39 @@ static int graph_for_each_link(struct asoc_simple_priv *priv, return 0; } +static int graph_for_each_link(struct asoc_simple_priv *priv, + struct link_info *li, + int (*func_noml)(struct asoc_simple_priv *priv, + struct device_node *cpu_ep, + struct device_node *codec_ep, + struct link_info *li), + int (*func_dpcm)(struct asoc_simple_priv *priv, + struct device_node *cpu_ep, + struct device_node *codec_ep, + struct link_info *li)) +{ + int ret; + /* + * Detect all CPU first, and Detect all Codec 2nd. + * + * In Normal sound case, all DAIs are detected + * as "CPU-Codec". + * + * In DPCM sound case, + * all CPUs are detected as "CPU-dummy", and + * all Codecs are detected as "dummy-Codec". + * To avoid random sub-device numbering, + * detect "dummy-Codec" in last; + */ + for (li->cpu = 1; li->cpu >= 0; li->cpu--) { + ret = __graph_for_each_link(priv, li, func_noml, func_dpcm); + if (ret < 0) + break; + } + + return ret; +} + static void graph_get_dais_count(struct asoc_simple_priv *priv, struct link_info *li); @@ -566,25 +591,11 @@ int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev) return ret; memset(&li, 0, sizeof(li)); - for (li.cpu = 1; li.cpu >= 0; li.cpu--) { - /* - * Detect all CPU first, and Detect all Codec 2nd. - * - * In Normal sound case, all DAIs are detected - * as "CPU-Codec". - * - * In DPCM sound case, - * all CPUs are detected as "CPU-dummy", and - * all Codecs are detected as "dummy-Codec". - * To avoid random sub-device numbering, - * detect "dummy-Codec" in last; - */ - ret = graph_for_each_link(priv, &li, - graph_dai_link_of, - graph_dai_link_of_dpcm); - if (ret < 0) - goto err; - } + ret = graph_for_each_link(priv, &li, + graph_dai_link_of, + graph_dai_link_of_dpcm); + if (ret < 0) + goto err; ret = asoc_simple_parse_card_name(card, NULL); if (ret < 0) @@ -617,10 +628,6 @@ static int graph_count_noml(struct asoc_simple_priv *priv, { struct device *dev = simple_priv_to_dev(priv); - /* Do it only CPU turn */ - if (!li->cpu) - return 0; - li->link += 1; /* 1xCPU-Codec */ li->dais += 2; /* 1xCPU + 1xCodec */ @@ -632,27 +639,14 @@ static int graph_count_noml(struct asoc_simple_priv *priv, static int graph_count_dpcm(struct asoc_simple_priv *priv, struct device_node *cpu_ep, struct device_node *codec_ep, - struct link_info *li, - int dup_codec) + struct link_info *li) { struct device *dev = simple_priv_to_dev(priv); - /* - * Codec endpoint can be NULL for pluggable audio HW. - * Platform DT can populate the Codec endpoint depending on the - * plugged HW. - */ - if (!li->cpu && !codec_ep) - return 0; - - /* Do it all CPU endpoint, and 1st Codec endpoint */ - if (!li->cpu && dup_codec) - return 0; - if (li->cpu) { li->link++; /* 1xCPU-dummy */ li->dais++; /* 1xCPU */ - } else if (!dup_codec && codec_ep) { + } else { li->link++; /* 1xdummy-Codec */ li->conf++; /* 1xdummy-Codec */ li->dais++; /* 1xCodec */ @@ -714,10 +708,9 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv, * => 4 DAIs = 2xCPU + 2xCodec * => 1 ccnf = 1xdummy-Codec */ - for (li->cpu = 1; li->cpu >= 0; li->cpu--) - graph_for_each_link(priv, li, - graph_count_noml, - graph_count_dpcm); + graph_for_each_link(priv, li, + graph_count_noml, + graph_count_dpcm); dev_dbg(dev, "link %d, dais %d, ccnf %d\n", li->link, li->dais, li->conf); } From patchwork Fri Mar 26 03:26:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 409565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5921C433C1 for ; Fri, 26 Mar 2021 03:28:48 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7F9260201 for ; Fri, 26 Mar 2021 03:28:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7F9260201 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2FA661660; Fri, 26 Mar 2021 04:27:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2FA661660 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729326; bh=h3vS7OSgf2thte2+K98th30/zFy+1JIAIlrRvPoTJGw=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=o/VGCfHrEbntOXgtO7jVzvVbi/GGrtLGYVfvxQMYczBQ+Nc5t0n0St9ic6Q/nZKAs ST9lbKsQ8liwQYwzyKQ4tnI4jysaTb9vpPDvHucPJxFzIv7Tk5C1JVbolDOtj8QjDm YOloXo69/wSa0wFUD95hHRQ+N1RO2irRhoIkGnJc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9451EF802E3; Fri, 26 Mar 2021 04:26:46 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 93D5EF804A9; Fri, 26 Mar 2021 04:26:41 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 237E1F8049C for ; Fri, 26 Mar 2021 04:26:33 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 237E1F8049C Date: 26 Mar 2021 12:26:33 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76117727" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 26 Mar 2021 12:26:33 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id B100B40104F3; Fri, 26 Mar 2021 12:26:33 +0900 (JST) Message-ID: <877dlu1tp2.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 5/6] ASoC: simple-card: count DAI / link numbers as in order User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto simple-card checks DT links 2 times. 1st is for counting DAIs / links to allocating memory, 2nd is for detecting DAIs. To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case, it uses loops 2 times at 2nd DT link check. But it doesn't do it at 1st DT link check. for (li.cpu = 1; li.cpu >= 0; li.cpu--) { /* * Detect all CPU first, and Detect all Codec 2n * * In Normal sound case, all DAIs are detected * as "CPU-Codec". * * In DPCM sound case, * all CPUs are detected as "CPU-dummy", and * all Codecs are detected as "dummy-Codec". * To avoid random sub-device numbering, * detect "dummy-Codec" in last; */ ret = simple_for_each_link(...); ... } To prepare supporting multi-CPU/Codec, and code cleanup, this patch use same loop for 1st DT link check, too. Signed-off-by: Kuninori Morimoto --- sound/soc/generic/simple-card.c | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 75365c7bb393..f53f76ee0a8b 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -483,9 +483,17 @@ static int simple_count_noml(struct asoc_simple_priv *priv, struct device_node *codec, struct link_info *li, bool is_top) { - li->dais++; /* CPU or Codec */ - if (np != codec) - li->link++; /* CPU-Codec */ + /* + * |CPU |Codec : turn + * CPU |Pass |return + * Codec |return|return + * np + */ + if (!li->cpu || np == codec) + return 0; + + li->link += 1; + li->dais += 2; return 0; } @@ -495,10 +503,23 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv, struct device_node *codec, struct link_info *li, bool is_top) { - li->dais++; /* CPU or Codec */ - li->link++; /* CPU-dummy or dummy-Codec */ - if (np == codec) + /* + * |CPU |Codec : turn + * CPU |Pass |return + * Codec |return|Pass + * np + */ + if (li->cpu == (np == codec)) + return 0; + + if (li->cpu) { + li->link++; /* CPU-dummy */ + li->dais++; + } else { + li->link++; /* dummy-Codec */ + li->dais++; li->conf++; + } return 0; } @@ -562,9 +583,10 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv, return; } - simple_for_each_link(priv, li, - simple_count_noml, - simple_count_dpcm); + for (li->cpu = 1; li->cpu >= 0; li->cpu--) + simple_for_each_link(priv, li, + simple_count_noml, + simple_count_dpcm); dev_dbg(dev, "link %d, dais %d, ccnf %d\n", li->link, li->dais, li->conf); From patchwork Fri Mar 26 03:26:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 410204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 108E0C433C1 for ; Fri, 26 Mar 2021 03:29:10 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80314619E8 for ; Fri, 26 Mar 2021 03:29:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80314619E8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 14F241669; Fri, 26 Mar 2021 04:28:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 14F241669 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616729348; bh=gWA293B7AUVDA5tBlL86umvGlLD8OeBKnqNUJ/a42mQ=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jbB59fVNEN04MX23cghs7WF4cugBcHYSBu2rqAppOY6Pd/ylyEZ1c/GS45cfHOR3+ m9+r+cJOL7i3kEzZjsHbN45v4Hc33dxsA5bLFuV92begaJ56vHIuXRhG9vH46KDjeP QNAKLuf7fRU+3tT1wCNZk3cP27yNhN9HhNq7LKpk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 73DB2F804AA; Fri, 26 Mar 2021 04:26:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 38BFCF8049C; Fri, 26 Mar 2021 04:26:46 +0100 (CET) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by alsa1.perex.cz (Postfix) with ESMTP id 6EDF3F80104 for ; Fri, 26 Mar 2021 04:26:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6EDF3F80104 Date: 26 Mar 2021 12:26:40 +0900 X-IronPort-AV: E=Sophos;i="5.81,279,1610377200"; d="scan'208";a="76343937" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 26 Mar 2021 12:26:40 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1D19941A2E1B; Fri, 26 Mar 2021 12:26:40 +0900 (JST) Message-ID: <875z1e1tov.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link() User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> References: <87eeg21tqz.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Kuninori Morimoto simple-card checks DT links 2 times. 1st is for counting DAIs / links to allocating memory, 2nd is for detecting DAIs. To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case, it uses loops 2 times. Because of this kind of complex background, it needs to use local varuable for it, and each call-back functions need to care about it. Now, 1st and 2nd DT link check are using same order, thus we can share same code. This patch do it. Signed-off-by: Kuninori Morimoto --- sound/soc/generic/simple-card.c | 125 ++++++++++++++++---------------- 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index f53f76ee0a8b..41aa40765a8d 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -129,15 +129,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv, char *prefix = ""; int ret; - /* - * |CPU |Codec : turn - * CPU |Pass |return - * Codec |return|Pass - * np - */ - if (li->cpu == (np == codec)) - return 0; - dev_dbg(dev, "link_of DPCM (%pOF)\n", np); li->link++; @@ -260,15 +251,6 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv, char *prefix = ""; int ret, single_cpu; - /* - * |CPU |Codec : turn - * CPU |Pass |return - * Codec |return|return - * np - */ - if (!li->cpu || np == codec) - return 0; - cpu = np; node = of_get_parent(np); li->link++; @@ -342,7 +324,7 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv, return ret; } -static int simple_for_each_link(struct asoc_simple_priv *priv, +static int __simple_for_each_link(struct asoc_simple_priv *priv, struct link_info *li, int (*func_noml)(struct asoc_simple_priv *priv, struct device_node *np, @@ -402,11 +384,26 @@ static int simple_for_each_link(struct asoc_simple_priv *priv, */ if (dpcm_selectable && (num > 2 || - adata.convert_rate || adata.convert_channels)) - ret = func_dpcm(priv, np, codec, li, is_top); + adata.convert_rate || adata.convert_channels)) { + /* + * np + * |1(CPU)|0(Codec) li->cpu + * CPU |Pass |return + * Codec |return|Pass + */ + if (li->cpu != (np == codec)) + ret = func_dpcm(priv, np, codec, li, is_top); /* else normal sound */ - else - ret = func_noml(priv, np, codec, li, is_top); + } else { + /* + * np + * |1(CPU)|0(Codec) li->cpu + * CPU |Pass |return + * Codec |return|return + */ + if (li->cpu && (np != codec)) + ret = func_noml(priv, np, codec, li, is_top); + } if (ret < 0) { of_node_put(codec); @@ -424,6 +421,39 @@ static int simple_for_each_link(struct asoc_simple_priv *priv, return ret; } +static int simple_for_each_link(struct asoc_simple_priv *priv, + struct link_info *li, + int (*func_noml)(struct asoc_simple_priv *priv, + struct device_node *np, + struct device_node *codec, + struct link_info *li, bool is_top), + int (*func_dpcm)(struct asoc_simple_priv *priv, + struct device_node *np, + struct device_node *codec, + struct link_info *li, bool is_top)) +{ + int ret; + /* + * Detect all CPU first, and Detect all Codec 2nd. + * + * In Normal sound case, all DAIs are detected + * as "CPU-Codec". + * + * In DPCM sound case, + * all CPUs are detected as "CPU-dummy", and + * all Codecs are detected as "dummy-Codec". + * To avoid random sub-device numbering, + * detect "dummy-Codec" in last; + */ + for (li->cpu = 1; li->cpu >= 0; li->cpu--) { + ret = __simple_for_each_link(priv, li, func_noml, func_dpcm); + if (ret < 0) + break; + } + + return ret; +} + static int simple_parse_of(struct asoc_simple_priv *priv) { struct device *dev = simple_priv_to_dev(priv); @@ -449,25 +479,11 @@ static int simple_parse_of(struct asoc_simple_priv *priv) /* Single/Muti DAI link(s) & New style of DT node */ memset(&li, 0, sizeof(li)); - for (li.cpu = 1; li.cpu >= 0; li.cpu--) { - /* - * Detect all CPU first, and Detect all Codec 2nd. - * - * In Normal sound case, all DAIs are detected - * as "CPU-Codec". - * - * In DPCM sound case, - * all CPUs are detected as "CPU-dummy", and - * all Codecs are detected as "dummy-Codec". - * To avoid random sub-device numbering, - * detect "dummy-Codec" in last; - */ - ret = simple_for_each_link(priv, &li, - simple_dai_link_of, - simple_dai_link_of_dpcm); - if (ret < 0) - return ret; - } + ret = simple_for_each_link(priv, &li, + simple_dai_link_of, + simple_dai_link_of_dpcm); + if (ret < 0) + return ret; ret = asoc_simple_parse_card_name(card, PREFIX); if (ret < 0) @@ -483,15 +499,6 @@ static int simple_count_noml(struct asoc_simple_priv *priv, struct device_node *codec, struct link_info *li, bool is_top) { - /* - * |CPU |Codec : turn - * CPU |Pass |return - * Codec |return|return - * np - */ - if (!li->cpu || np == codec) - return 0; - li->link += 1; li->dais += 2; @@ -503,15 +510,6 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv, struct device_node *codec, struct link_info *li, bool is_top) { - /* - * |CPU |Codec : turn - * CPU |Pass |return - * Codec |return|Pass - * np - */ - if (li->cpu == (np == codec)) - return 0; - if (li->cpu) { li->link++; /* CPU-dummy */ li->dais++; @@ -583,10 +581,9 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv, return; } - for (li->cpu = 1; li->cpu >= 0; li->cpu--) - simple_for_each_link(priv, li, - simple_count_noml, - simple_count_dpcm); + simple_for_each_link(priv, li, + simple_count_noml, + simple_count_dpcm); dev_dbg(dev, "link %d, dais %d, ccnf %d\n", li->link, li->dais, li->conf);