public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
@ 2025-10-29  7:36 Peter Ujfalusi
  2025-11-06 23:53 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Ujfalusi @ 2025-10-29  7:36 UTC (permalink / raw)
  To: lgirdwood, broonie
  Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
	pierre-louis.bossart, shengjiu.wang, kuninori.morimoto.gx

Component drivers can prepare snd_pcm_hardware struct based on the hardware
capabilities which information should not be discarded.

Only touch the rates, channels_max and formats if they were left to 0,
otherwise keep the provided configuration intact for the parameter cross
checking decision.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
Hi,

Changes since v1:
- Move the implementation into soc_pcm_hw_init() with added 'force' flag
  Basically the RFC version with inverted flag.

Changes since RFC:
- move the hw parameter initialization/preserve code inline to
  dpcm_runtime_setup_fe

this patch in essence extends the special casing of formats done by
083a25b18d6a ("ASoC: soc-pcm: fix hw->formats cleared by soc_pcm_hw_init() for dpcm")

Other parameters might have been set in the same way as the formats
and preserving these are equally important.

A case for this is SOF used with HDA codec (analog or more importantly, HDMI)
where the hw-> params are set based on the connected display/device and
should be preserved so we can report correct rate, format and channels
supported by the equipment.

If the hw-> parameters are left uninitialized then we still need to
set the UINT/ULLONG_MAX for the refining code to work.

This applies only for FE setup, in other cases we shall (as before) do
a full re-initialization.

I think this makes sense and I cannot think where this might flop.

Regards,
Peter

 sound/soc/soc-pcm.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2c21fd528afd..c82b10578ba6 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -570,14 +570,26 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
 	soc_pcm_set_msb(substream, cpu_bits);
 }
 
-static void soc_pcm_hw_init(struct snd_pcm_hardware *hw)
-{
-	hw->rates		= UINT_MAX;
-	hw->rate_min		= 0;
-	hw->rate_max		= UINT_MAX;
-	hw->channels_min	= 0;
-	hw->channels_max	= UINT_MAX;
-	hw->formats		= ULLONG_MAX;
+static void soc_pcm_hw_init(struct snd_pcm_hardware *hw, bool force)
+{
+	if (force) {
+		hw->rates = UINT_MAX;
+		hw->rate_min = 0;
+		hw->rate_max = UINT_MAX;
+		hw->channels_min = 0;
+		hw->channels_max = UINT_MAX;
+		hw->formats = ULLONG_MAX;
+	} else {
+		/* Preserve initialized parameters */
+		if (!hw->rates)
+			hw->rates = UINT_MAX;
+		if (!hw->rate_max)
+			hw->rate_max = UINT_MAX;
+		if (!hw->channels_max)
+			hw->channels_max = UINT_MAX;
+		if (!hw->formats)
+			hw->formats = ULLONG_MAX;
+	}
 }
 
 static void soc_pcm_hw_update_rate(struct snd_pcm_hardware *hw,
@@ -626,7 +638,7 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
 	unsigned int cpu_chan_min = 0, cpu_chan_max = UINT_MAX;
 	int i;
 
-	soc_pcm_hw_init(hw);
+	soc_pcm_hw_init(hw, true);
 
 	/* first calculate min/max only for CPUs in the DAI link */
 	for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
@@ -1738,13 +1750,9 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream)
 	struct snd_pcm_hardware *hw = &runtime->hw;
 	struct snd_soc_dai *dai;
 	int stream = substream->stream;
-	u64 formats = hw->formats;
 	int i;
 
-	soc_pcm_hw_init(hw);
-
-	if (formats)
-		hw->formats &= formats;
+	soc_pcm_hw_init(hw, false);
 
 	for_each_rtd_cpu_dais(fe, i, dai) {
 		const struct snd_soc_pcm_stream *cpu_stream;
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-29  7:36 [PATCH v2] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe Peter Ujfalusi
@ 2025-11-06 23:53 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-11-06 23:53 UTC (permalink / raw)
  To: lgirdwood, Peter Ujfalusi
  Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
	pierre-louis.bossart, shengjiu.wang, kuninori.morimoto.gx

On Wed, 29 Oct 2025 09:36:00 +0200, Peter Ujfalusi wrote:
> Component drivers can prepare snd_pcm_hardware struct based on the hardware
> capabilities which information should not be discarded.
> 
> Only touch the rates, channels_max and formats if they were left to 0,
> otherwise keep the provided configuration intact for the parameter cross
> checking decision.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
      commit: 6d34b66fb726a613b98c936adee70d42aa5e4aa7

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-06 23:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29  7:36 [PATCH v2] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe Peter Ujfalusi
2025-11-06 23:53 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox