All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 5/5] ASoC: soc-pcm: fixup snd_pcm_limit_hw_rates() timing
Date: 22 Jan 2021 10:13:53 +0900	[thread overview]
Message-ID: <8735ytaig8.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87a6t1aihl.wl-kuninori.morimoto.gx@renesas.com>


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

soc-pcm has snd_pcm_limit_hw_rates() which determine rate_min/rate_max.
It updates runtime->hw.rate_min/max (A) based on hw->rates (B).

	int snd_pcm_limit_hw_rates(...)
	{
		int i;
		for (...) {
(B)			if (runtime->hw.rates & (1 << i)) {
(A)				runtime->hw.rate_min = ...
				break;
			}
		}
		for (...) {
(B)			if (runtime->hw.rates & (1 << i)) {
(A)				runtime->hw.rate_max = ...
				break;
			}
		}
		return 0;
	}

This means, setup order is

	1) set hw->rates
	2) call snd_pcm_limit_hw_rates()
	3) update hw->rate_min/max

soc_pcm_init_runtime_hw() is calling it in good order

	static void soc_pcm_init_runtime_hw(xxx)
	{
		...
1)		hw->rates = snd_pcm_rate_mask_intersect(...);

2)		snd_pcm_limit_hw_rates(...);

3)		hw->rate_min = max(...);
		hw->rate_min = max(...);
		hw->rate_max = min_not_zero(...);
		hw->rate_max = min_not_zero(...);
	}

But, dpcm_fe_dai_startup() is not.

	static int dpcm_fe_dai_startup(xxx)
	{
		...
1) 3)		dpcm_set_fe_runtime(...);
2)		snd_pcm_limit_hw_rates(...);
		...
	}

More detail of dpcm_set_fe_runtime() is

	static void dpcm_set_fe_runtime()
	{
		...
		for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
			...

3) 1)			dpcm_init_runtime_hw(...);
		}
		...
3) 1)		dpcm_runtime_merge_rate(...);
	}

This patch fixup these into

	static void dpcm_set_fe_runtime()
	{
		...
		for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
			...

1) 2) 3)		dpcm_init_runtime_hw(...);
		}
		...
1) 2) 3)	dpcm_runtime_merge_rate(...);
	}

	static int dpcm_fe_dai_startup(xxx)
	{
		...
		dpcm_set_fe_runtime(...);
-		snd_pcm_limit_hw_rates(...);
		...
	}

Link: https://lore.kernel.org/r/87k15l7ewd.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-pcm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2a625ce0bacb..b79f064887d4 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1514,6 +1514,10 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
 				 struct snd_soc_pcm_stream *stream)
 {
+	runtime->hw.rates = stream->rates;
+
+	snd_pcm_limit_hw_rates(runtime);
+
 	runtime->hw.rate_min = stream->rate_min;
 	runtime->hw.rate_max = min_not_zero(stream->rate_max, UINT_MAX);
 	runtime->hw.channels_min = stream->channels_min;
@@ -1522,7 +1526,6 @@ static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
 		runtime->hw.formats &= stream->formats;
 	else
 		runtime->hw.formats = stream->formats;
-	runtime->hw.rates = stream->rates;
 }
 
 static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
@@ -1648,9 +1651,12 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
 
 			pcm = snd_soc_dai_get_pcm_stream(dai, stream);
 
+			hw->rates = snd_pcm_rate_mask_intersect(hw->rates, pcm->rates);
+
+			snd_pcm_limit_hw_rates(runtime);
+
 			hw->rate_min = max(hw->rate_min, pcm->rate_min);
 			hw->rate_max = min_not_zero(hw->rate_max, pcm->rate_max);
-			hw->rates = snd_pcm_rate_mask_intersect(hw->rates, pcm->rates);
 		}
 	}
 }
@@ -1738,7 +1744,6 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
 static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
 {
 	struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
-	struct snd_pcm_runtime *runtime = fe_substream->runtime;
 	int stream = fe_substream->stream, ret = 0;
 
 	dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
@@ -1761,7 +1766,6 @@ static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
 	fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
 
 	dpcm_set_fe_runtime(fe_substream);
-	snd_pcm_limit_hw_rates(runtime);
 
 	ret = dpcm_apply_symmetry(fe_substream, stream);
 	if (ret < 0)
-- 
2.25.1


  parent reply	other threads:[~2021-01-22  1:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22  1:13 [PATCH 0/5] ASoC: soc-pcm: cleanup soc_new_pcm() and bugfix Kuninori Morimoto
2021-01-22  1:13 ` [PATCH 1/5] ASoC: soc-pcm: tidyup pcm setting Kuninori Morimoto
2021-01-22  1:13 ` [PATCH 2/5] ASoC: soc-pcm: add soc_get_playback_capture() and simplify soc_new_pcm() Kuninori Morimoto
2021-01-22  1:13 ` [PATCH 3/5] ASoC: soc-pcm: add soc_create_pcm() " Kuninori Morimoto
2021-01-22  1:13 ` [PATCH 4/5] ASoC: soc-pcm: use snd_pcm_hardware at dpcm_runtime_merge_xxx() Kuninori Morimoto
2021-01-22  1:13 ` Kuninori Morimoto [this message]
2021-02-03 21:07 ` [PATCH 0/5] ASoC: soc-pcm: cleanup soc_new_pcm() and bugfix Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735ytaig8.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.