diff mbox series

[06/20] ASoC: soc-pcm.c: cleanup normal connection loop at soc_get_playback_capture() part1

Message ID 87ttwap4wq.wl-kuninori.morimoto.gx@renesas.com
State Superseded
Headers show
Series ASoC: replace dpcm_playback/capture to playback/capture_only | expand

Commit Message

Kuninori Morimoto May 18, 2023, 5:47 a.m. UTC
soc_get_playback_capture() (A) is handling both DPCM (X) / Normal (Y)
connection.

(A)	static int soc_get_playback_capture(...)
	{
		...
 ^		if (dai_link->dynamic || dai_link->no_pcm) {
(X)			...
 v
 ^		} else {
 |			...
 |(@)			for_each_rtd_codec_dais(rtd, i, codec_dai) {
 |				if (dai_link->num_cpus == 1) {
 |(a)					cpu_dai = ...
(Y)				} else if (dai_link->num_cpus == dai_link->num_codecs) {
 |(b)					cpu_dai = ...
 |				} else {
 |(c)					dev_err(...);
 |				}
 |				...
 |			}
 |			...
 v		}
		...
	}

In Normal connection case (Y), it is checking number of CPU / Codec.
	(a) is for Single CPU case
	(b) is for Multi  CPU case
	(c) is for other case (error)

Because this loop (@) is not related to dai_link->num_xxx,
we can judge (c) before entering this loop.
And it is needed not only for Normal connection case (Y),
but DPCM connection case (X) too.

This patch moves (c) to top side.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-pcm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Amadeusz Sławiński May 18, 2023, 10:38 a.m. UTC | #1
On 5/18/2023 7:47 AM, Kuninori Morimoto wrote:
> soc_get_playback_capture() (A) is handling both DPCM (X) / Normal (Y)
> connection.
> 
> (A)	static int soc_get_playback_capture(...)
> 	{
> 		...
>   ^		if (dai_link->dynamic || dai_link->no_pcm) {
> (X)			...
>   v
>   ^		} else {
>   |			...
>   |(@)			for_each_rtd_codec_dais(rtd, i, codec_dai) {
>   |				if (dai_link->num_cpus == 1) {
>   |(a)					cpu_dai = ...
> (Y)				} else if (dai_link->num_cpus == dai_link->num_codecs) {
>   |(b)					cpu_dai = ...
>   |				} else {
>   |(c)					dev_err(...);
>   |				}
>   |				...
>   |			}
>   |			...
>   v		}
> 		...
> 	}
> 
> In Normal connection case (Y), it is checking number of CPU / Codec.
> 	(a) is for Single CPU case
> 	(b) is for Multi  CPU case
> 	(c) is for other case (error)
> 
> Because this loop (@) is not related to dai_link->num_xxx,
> we can judge (c) before entering this loop.
> And it is needed not only for Normal connection case (Y),
> but DPCM connection case (X) too.
> 
> This patch moves (c) to top side.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---

Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
diff mbox series

Patch

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 89416c127dca..8ce6dbf37014 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2742,6 +2742,12 @@  static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
 		return -EINVAL;
 	}
 
+	if (dai_link->num_cpus != dai_link->num_codecs) {
+		dev_err(rtd->dev, "%s: %d cpus to %d codecs link is not supported yet\n",
+			dai_link->name, dai_link->num_cpus, dai_link->num_codecs);
+		return -EINVAL;
+	}
+
 	if (dai_link->dynamic || dai_link->no_pcm) {
 		int stream;
 
@@ -2792,10 +2798,6 @@  static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
 				cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 			} else if (dai_link->num_cpus == dai_link->num_codecs) {
 				cpu_dai = asoc_rtd_to_cpu(rtd, i);
-			} else {
-				dev_err(rtd->card->dev,
-					"N cpus to M codecs link is not supported yet\n");
-				return -EINVAL;
 			}
 
 			if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&