From patchwork Mon Apr 1 00:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 785959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E9BC9CD1284 for ; Mon, 1 Apr 2024 00:31:30 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3E1591939; Mon, 1 Apr 2024 02:31:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3E1591939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1711931489; bh=k4h/PoOk62pxaDjSieSsv/A95jwkgPCD9LsoO8EOQ4g=; h=To:In-Reply-To:References:From:Subject:Date:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=B4eHVkacsr4Qf7WPGUzcRouaEjKk0ObgsqmyDEhb+Dw8hqMO7bo0M3g3ymZG01KTE f2HX79jdnkkKjaSuXvvIhG55HbmG3dUSmASAhLfiRijO7b5+dNB+J0IzIbJNgABCY+ WNAk3O46sU7uUGImLnbzlJMbpp/hwMORxxUESwPA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5CBF9F80114; Mon, 1 Apr 2024 02:31:07 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id EEFF5F80589; Mon, 1 Apr 2024 02:31:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C2A57F80236; Mon, 1 Apr 2024 02:31:02 +0200 (CEST) Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on20701.outbound.protection.outlook.com [IPv6:2a01:111:f403:2019::701]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5498FF80130 for ; Mon, 1 Apr 2024 02:30:51 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5498FF80130 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=renesas.com header.i=@renesas.com header.a=rsa-sha256 header.s=selector1 header.b=DUoX4IcQ ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V5ggZCDySXxmQ+g1CPCbcbfxJnM3s0TuP6mt+OPz8UmDEJXdl68KciN4jdc+pGO0ymFObZynIF9E2og1zjpez9yxhCIiG+nfq0Af5pkScmmwj6bWW+ptOovgM781gUsDkoXMROrcNwJRJCXiSgrm8rECPxswp17Y//OFTm+2eKaiqc6TQVn/UQWhsjeGSr8A4SqUGow45AxbL8v8iaIPgEX+vyTkAD544RHtSvmUHb22qPHkc3uTJrrD7qGt3VQ1CExEuBPZEKwccAwsXI6PPxkVmFX/jVOqSLIdflzbhEVE6WNgW7XYjblWM77Eo70nnRoJTxiW6Avw+9D6XYogqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oCIf78DfRZi1HpBCdp3ABqBxydUBtA/1mzGbWu+Nix8=; b=G2N9tVKnRgMUN8f/0OjTW0/jaURGe1F3wv2y7HCJmLYrrhUHRiCkJ9C8ThAxJI1AVKbfBKCGtg7PmzEh9tbA3boi3koZI64ZFJQPdgouLBgwHw5yMUmFRLhnxMDh4uQId0VGROL0Jd6SRvudjocZ0H5kolwe2in/OWehV2gEKlj9jPX8Ay2Onph/2gBQ7rmpqL3u1tXS1AQQJDLsL9XOCkfZ24wCoCumG/K8v/a3oFopAU52pSQLqLYSVU3BYQurhHQfHLJ4BxEhx8T+llTVuIN1/SCNn8NDyaGQjU67yuX6h969zTG0ShGKqNXx106Kyk/Gudfn7zqh5jot+JjqVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=renesas.com; dmarc=pass action=none header.from=renesas.com; dkim=pass header.d=renesas.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oCIf78DfRZi1HpBCdp3ABqBxydUBtA/1mzGbWu+Nix8=; b=DUoX4IcQGGltpM8PJ1K/8sqoxhL6LBHeOzAtKuuZ6ZZmXRrh3y/YUt81RWG20xxtGPrKAbY33FqSujUmJZDSBxGQimibyGBvMJ8zEsgxo9Iy2roZcaH0UAi5C/bU7/4SN1HXHCoOxhbYCM3VTtCm8wPgnxBJoSKk+GgZe2HDxUQ= Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) by OS3PR01MB8258.jpnprd01.prod.outlook.com (2603:1096:604:175::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Mon, 1 Apr 2024 00:30:46 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::131e:55c0:a4a0:713b]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::131e:55c0:a4a0:713b%7]) with mapi id 15.20.7386.025; Mon, 1 Apr 2024 00:30:46 +0000 Message-ID: <87y19xudor.wl-kuninori.morimoto.gx@renesas.com> To: =?iso-8859-2?q?=22Amadeusz_S=B3awi=F1ski=22?= , Alper Nebi Yasak , AngeloGioacchino Del Regno , Banajit Goswami , Bard Liao , Brent Lu , Cezary Rojewski , Cristian Ciocaltea , Daniel Baluta , Hans de Goede , Jaroslav Kysela , Jerome Brunet , Kai Vehmanen , Kevin Hilman , Liam Girdwood , Linus Walleij , Mark Brown , Maso Huang , Matthias Brugger , Neil Armstrong , Peter Ujfalusi , Pierre-Louis Bossart , Ranjani Sridharan , Sascha Hauer , Shawn Guo , Shengjiu Wang , Srinivas Kandagatla , Sylwester Nawrocki , Takashi Iwai , Trevor Wu , Vinod Koul , Xiubo Li , alsa-devel@alsa-project.org, imx@lists.linux.dev, linux-sound@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com In-Reply-To: <87zfuesz8y.wl-kuninori.morimoto.gx@renesas.com> References: <87zfuesz8y.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2 01/16] ASoC: soc-pcm.c: cleanup soc_get_playback_capture() Date: Mon, 1 Apr 2024 00:30:45 +0000 X-ClientProxiedBy: TYCPR01CA0189.jpnprd01.prod.outlook.com (2603:1096:400:2b0::14) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|OS3PR01MB8258:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1++s4R9u97+n/Mr8kfOOMjQb9dKueE+E0NX7YIKeZ9iiyD3O0Th7TX82KWdj8J+d3zTPn34EvuoEmrr14zHOSbxWnEEG1uCbKRecMhjndy2JyvoEk5kydjJud29fPSi2pvJp3+DneRZ6frFJk2ZjjyKkP0oLIuSTdig/UVhIgleuNLo5EWBFCqQlFB0ZJgtK3yAOlcK0y9L4w8I3kKsmK+x3p1PRc5uZ5g8WNu8eAEiqxaZUvdFB1JUNm1+dQnvQ8FvZlPdV9QTW80txYbRPPone1GCuV4Lgvd/e2TivuW4nPK3DkUCciep/kVC8GzoTn9ZHTl7DlPEoWu13MS5Op1cDnMzGNgzHQT5tJ++hUEA+AsIZ4bJVJq5FYKloaIchMG70ZArWAHPYUI6+QJQwS5adyKq7YBQo4DLt6JMgriAYK36EWI3IV/LA2MnhhZzaETABcmg4lebjh+RlqbKZScpH6NATxsAhnTA0QZcrEvXwpLwCjWaG4a2CPsS32wCjzLv0Hm7fXjxktFOGhT5KL7VewzNWK9oLu+6myhZX+JzACWUwB5v5cogHevhsT7s3k1HR3be5PXbydx5lGaafD30wxdLckIWv4rIPRsyKaIQimWtkB2wUOIfWbb0aRaqJBmhq6r9sPx4ifAwYM8zNl0rJtX3mI3TYKct76eZQtvE+U+w/uR37pvCGRPsOyT5dw9LgZnegO5yOlxDkZSxN17qCCmbL3NhTMmW+SFJt11c= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TYCPR01MB10914.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(7416005)(376005)(52116005)(1800799015)(366007)(921011)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 02+J29oLPUn8MFmdJAi8cF6GNO581O4JtP9vqCbTUZMM8sMEMti7GdewCDLT3G0ByW8Pv0MD5zfGZrN3qagndVOXHWefs8BNr4REfEcIEWE+AKMechLdjJZaNwaUmY+vBFWUehUWy/SJaRsGHiZW8P4avyKqNtRUEezV3yOpkg3BezO+66jIiTgynZhK3zfSWqYPouXMoeEetYC8X5QUzRU298zHqQKXajZ1RgLQYuWltWDfeGyCpC1gmdi0paUAP9cg2v3zd4ZG0eX5MDtWseP31uhxncHJDZ2J3ZkgfYUPtCb7M55W/PQRX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tZD4W1WkMY18HdxS8wc6MKt1jNCEtyMWXCa98Rg3IvztH7TKCp7oBdMjmTdo/hNqfZ+UY+GHKrSWInRDRvkV7MX+WkIYr+jU+k0z1rNDDwq15Ow2VH5C1U3NMruNvcviTOdPzB1DfhzT5iLFxDOdUpvLrEiaIwaci2Q60Ocnb0notgSA4Im+8bAL4WEqVbjCEj5duccQ5ruIq+uwSiLVOs9hXD8nOoKacW0rVqOYm94QnThI3WBCSYTZladGHqT+YY= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f42b437-b18d-4399-842a-08dc51e2f8bb X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2024 00:30:46.1535 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vfus/xBNnx+NyEc0EwsW4LQqsheEx4V4njsFwWryao2NFpe9I8OhNGDd7rgBw5Hpm6WWk+f1O8F9HR+cAppIWJiqpH6Jw2t3R6ptEvX7alDAQrcvUqhkqUtQDx1n5AVM X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3PR01MB8258 Message-ID-Hash: 2S2L26TF2XEMTVP5WO5G43NUKXSCKLIQ X-Message-ID-Hash: 2S2L26TF2XEMTVP5WO5G43NUKXSCKLIQ X-MailFrom: kuninori.morimoto.gx@renesas.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Current soc_get_playback_capture() (A) is checking playback/capture availability for DPCM (X) / Normal (Y) / Codec2Codec (Z) connections. (A) static int soc_get_playback_capture(...) { ... ^ if (dai_link->dynamic || dai_link->no_pcm) { | ... |(a) if (dai_link->dpcm_playback) { | ... | ^ for_each_rtd_cpu_dais(rtd, i, cpu_dai) { |(*) ... | v } | ... (X) } |(b) if (dai_link->dpcm_capture) { | ... | ^ for_each_rtd_cpu_dais(rtd, i, cpu_dai) { |(*) ... | v } | ... v } } else { ^ ^ /* Adapt stream for codec2codec links */ |(Z) int cpu_capture = ... | v int cpu_playback = ... (Y) | ^ for_each_rtd_ch_maps(rtd, i, ch_maps) { |(*) ... v v } } ... } (*) part is checking each DAI's availability. At first, (X) part is for DPCM, and it checks playback/capture availability if dai_link has dpcm_playback/capture flag (a)(b). But we are already using playback/capture_only flag for Normal (Y) and Codec2Codec (Z). We can use this flags for DPCM too. Before After dpcm_playback = 1; => /* no flags */ dpcm_capture = 1; dpcm_playback = 1; => playback_only = 1; dpcm_capture = 1; => capture_only = 1; dpcm_playback = 0; => error dpcm_capture = 0; This patch convert dpcm_ flags to _only flag, and dpcm_ flag will be removed if all driver switched to _only flags. Here, CPU <-> Codec relationship is like this DPCM [CPU/dummy]-[dummy/Codec] ^^^^ ^^^^^ Normal [CPU/Codec] ^^^^^^^^^^^ DPCM part (X) is checking only CPU DAI, and Normal part (Y) is checking both CPU/Codec DAI Here, validation check on dummy DAI is always true, Therefor we want to expand validation check to all cases. One note here is that unfortunately DPCM BE Codec had been no validation check before, but all cases validation check breaks compatibility on some vender's devices. Thus this patch ignore it. Signed-off-by: Kuninori Morimoto --- sound/soc/soc-pcm.c | 90 +++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 77ee103b7cd1..8761ae8fc05f 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2793,7 +2793,12 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd, int *playback, int *capture) { struct snd_soc_dai_link *dai_link = rtd->dai_link; + struct snd_soc_dai_link_ch_map *ch_maps; struct snd_soc_dai *cpu_dai; + struct snd_soc_dai *codec_dai; + struct snd_soc_dai *dummy_dai = snd_soc_find_dai(&snd_soc_dummy_dlc); + int cpu_playback; + int cpu_capture; int has_playback = 0; int has_capture = 0; int i; @@ -2803,65 +2808,46 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd, return -EINVAL; } + /* REMOVE ME */ if (dai_link->dynamic || dai_link->no_pcm) { - int stream; - - if (dai_link->dpcm_playback) { - stream = SNDRV_PCM_STREAM_PLAYBACK; - - for_each_rtd_cpu_dais(rtd, i, cpu_dai) { - if (snd_soc_dai_stream_valid(cpu_dai, stream)) { - has_playback = 1; - break; - } - } - if (!has_playback) { - dev_err(rtd->card->dev, - "No CPU DAIs support playback for stream %s\n", - dai_link->stream_name); - return -EINVAL; - } + if (dai_link->dpcm_playback && !dai_link->dpcm_capture) + dai_link->playback_only = 1; + if (!dai_link->dpcm_playback && dai_link->dpcm_capture) + dai_link->capture_only = 1; + if (!dai_link->dpcm_playback && !dai_link->dpcm_capture) { + dev_err(rtd->dev, "no dpcm_playback/capture are selected\n"); + return -EINVAL; } - if (dai_link->dpcm_capture) { - stream = SNDRV_PCM_STREAM_CAPTURE; + } - for_each_rtd_cpu_dais(rtd, i, cpu_dai) { - if (snd_soc_dai_stream_valid(cpu_dai, stream)) { - has_capture = 1; - break; - } - } + /* Adapt stream for codec2codec links */ + cpu_playback = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_PLAYBACK); + cpu_capture = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_CAPTURE); - if (!has_capture) { - dev_err(rtd->card->dev, - "No CPU DAIs support capture for stream %s\n", - dai_link->stream_name); - return -EINVAL; - } - } - } else { - struct snd_soc_dai_link_ch_map *ch_maps; - struct snd_soc_dai *codec_dai; - - /* Adapt stream for codec2codec links */ - int cpu_capture = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_CAPTURE); - int cpu_playback = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_PLAYBACK); + /* + * see + * soc.h :: [dai_link->ch_maps Image sample] + */ + for_each_rtd_ch_maps(rtd, i, ch_maps) { + cpu_dai = snd_soc_rtd_to_cpu(rtd, ch_maps->cpu); + codec_dai = snd_soc_rtd_to_codec(rtd, ch_maps->codec); /* - * see - * soc.h :: [dai_link->ch_maps Image sample] + * FIXME + * + * DPCM BE Codec has been no checked before. + * It should be checked, but it breaks compatibility. + * It ignores BE Codec here, so far. */ - for_each_rtd_ch_maps(rtd, i, ch_maps) { - cpu_dai = snd_soc_rtd_to_cpu(rtd, ch_maps->cpu); - codec_dai = snd_soc_rtd_to_codec(rtd, ch_maps->codec); - - if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && - snd_soc_dai_stream_valid(cpu_dai, cpu_playback)) - has_playback = 1; - if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && - snd_soc_dai_stream_valid(cpu_dai, cpu_capture)) - has_capture = 1; - } + if (dai_link->no_pcm) + codec_dai = dummy_dai; + + if (snd_soc_dai_stream_valid(cpu_dai, cpu_playback) && + snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK)) + has_playback = 1; + if (snd_soc_dai_stream_valid(cpu_dai, cpu_capture) && + snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE)) + has_capture = 1; } if (dai_link->playback_only)