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: 13612360 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2132.outbound.protection.outlook.com [40.107.113.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EA15621 for ; Mon, 1 Apr 2024 00:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.113.132 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711931451; cv=fail; b=iw8y+grsI4XoV2MG8qcIdtJVyldu/HnEWtq9I5HWZEVeOL4GsEVNli35HC88xl8heHBqrLQTc0J+J35eozBc9Vck08BgoW2TrrLmbanWgy4lbV1XSDaQRgU7s/HejWVtwmWiw0aJMl2GzpiWAsq7Eg4c7Qr0gVY7mB5UNRIP/K0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711931451; c=relaxed/simple; bh=k4h/PoOk62pxaDjSieSsv/A95jwkgPCD9LsoO8EOQ4g=; h=Message-ID:To:In-Reply-To:References:From:Subject:Content-Type: Date:MIME-Version; b=XNQiu4zRy1zkjlMCRSXm79mJIXpCTqEsB3B5QlCPUz1K/eo8AyvGU6zTP7O4b68xNz3aVqpCOniy60RZp/UP2u6boo8EGRAsYzRVHfEVr22t+8TTlpPjCZviCvXjrIhZHDXgocNrxu1IZjQu39fmsLlg/VNIJ72ADya9MTAlk7s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=DUoX4IcQ; arc=fail smtp.client-ip=40.107.113.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com 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) Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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/PQRXnXVsUfBiyvu/V8ScaCrc/3tpJk6FPIMeH4GwHeGqXt4Ddg9h7gX45S8wISsKVGbfbWE6lH7D7fesRBL13/8+RoQr21sps9+WuUvDrwBPMnLtm43RyemhL0OGzMqLcKkgfYiTv0spkHw0uoSuSdgosQLjxUZ5EIfoc0Zpid8EsIZgAVAmZAIyUEfmTZ2YM8TdB4/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ccQ5ruIq+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 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)