Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
@ 2025-10-23  8:14 Peter Ujfalusi
  2025-10-27  6:11 ` Kuninori Morimoto
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Ujfalusi @ 2025-10-23  8:14 UTC (permalink / raw)
  To: lgirdwood, broonie
  Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
	pierre-louis.bossart, shengjiu.wang

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 RFC [1]:
- 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, but
sent as RFC to see what people think. 

Br,
Peter

[1] https://lore.kernel.org/linux-sound/20251020073750.27784-1-peter.ujfalusi@linux.intel.com/

 sound/soc/soc-pcm.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2c21fd528afd..0877daab7b38 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1738,13 +1738,21 @@ 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;
+	/*
+	 * Initialize only pcm hardware patameters that has not been initialized
+	 * and preserve the configuration which might have been provided by
+	 * component drivers
+	 */
+	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;
 
 	for_each_rtd_cpu_dais(fe, i, dai) {
 		const struct snd_soc_pcm_stream *cpu_stream;
-- 
2.51.1.dirty


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

* Re: [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-23  8:14 [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe Peter Ujfalusi
@ 2025-10-27  6:11 ` Kuninori Morimoto
  2025-10-27  6:20   ` Péter Ujfalusi
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2025-10-27  6:11 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: lgirdwood, broonie, linux-sound, kai.vehmanen, ranjani.sridharan,
	yung-chuan.liao, pierre-louis.bossart, shengjiu.wang


Hi Peter

Thank you for the patch

> 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>
> ---
(snip)
> -	soc_pcm_hw_init(hw);
> -
> -	if (formats)
> -		hw->formats &= formats;
> +	/*
> +	 * Initialize only pcm hardware patameters that has not been initialized
> +	 * and preserve the configuration which might have been provided by
> +	 * component drivers
> +	 */
> +	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;

soc_pcm_hw_init() is used from only 2 functions

	(a) snd_soc_runtime_calc_hw()
	(b) dpcm_runtime_setup_fe()

And this patch fixed not to use it in (b).
Setting same variable in multiple method is not good idea, IMO.

How about like this ?

	static void soc_pcm_hw_init(struct snd_pcm_hardware *hw, boot force)
	{
		if (force || !hw->rates)
			hw->rates		= UINT_MAX;
		if (force || !hw->rate_max)
			hw->rate_max		= UINT_MAX;
		if (force || !hw->channels_max)
			hw->channels_max	= UINT_MAX;
		if (force || !hw->formats)
			hw->formats		= ULLONG_MAX;

		hw->rate_min		= 0;
		hw->channels_min	= 0;
	}

	int snd_soc_runtime_calc_hw(...)
	{
		...
		soc_pcm_hw_init(hw, true);
		...
	}

	int dpcm_runtime_setup_fe(...)
	{
		...
		soc_pcm_hw_init(hw, false);
		...
	}


Thank you for your help !!

Best regards
---
Kuninori Morimoto

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

* Re: [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-27  6:11 ` Kuninori Morimoto
@ 2025-10-27  6:20   ` Péter Ujfalusi
  2025-10-27  6:54     ` Kuninori Morimoto
  0 siblings, 1 reply; 6+ messages in thread
From: Péter Ujfalusi @ 2025-10-27  6:20 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: lgirdwood, broonie, linux-sound, kai.vehmanen, ranjani.sridharan,
	yung-chuan.liao, pierre-louis.bossart, shengjiu.wang

Hi Morimoto-san,

On 27/10/2025 08:11, Kuninori Morimoto wrote:
> 
> Hi Peter
> 
> Thank you for the patch
> 
>> 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>
>> ---
> (snip)
>> -	soc_pcm_hw_init(hw);
>> -
>> -	if (formats)
>> -		hw->formats &= formats;
>> +	/*
>> +	 * Initialize only pcm hardware patameters that has not been initialized
>> +	 * and preserve the configuration which might have been provided by
>> +	 * component drivers
>> +	 */
>> +	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;
> 
> soc_pcm_hw_init() is used from only 2 functions
> 
> 	(a) snd_soc_runtime_calc_hw()
> 	(b) dpcm_runtime_setup_fe()
> 
> And this patch fixed not to use it in (b).
> Setting same variable in multiple method is not good idea, IMO.
> 
> How about like this ?

This is how the RFC was done, but decided to not modify
soc_pcm_hw_init() with an added bool.
Other option would be to add a new function which would do only
conditional initialization.

https://lore.kernel.org/linux-sound/20251020073750.27784-1-peter.ujfalusi@linux.intel.com/

> 
> 	static void soc_pcm_hw_init(struct snd_pcm_hardware *hw, boot force)
> 	{
> 		if (force || !hw->rates)
> 			hw->rates		= UINT_MAX;
> 		if (force || !hw->rate_max)
> 			hw->rate_max		= UINT_MAX;
> 		if (force || !hw->channels_max)
> 			hw->channels_max	= UINT_MAX;
> 		if (force || !hw->formats)
> 			hw->formats		= ULLONG_MAX;
> 
> 		hw->rate_min		= 0;
> 		hw->channels_min	= 0;

This way we would loose the rate_min, channel_min from components, see
my RFC which covers this, but it is using reverse condition (preserve vs
force).
The force boolean might be better than the preserve_config as parameter
if the preference is to modify the soc_pcm_hw_init()

> 	}
> 
> 	int snd_soc_runtime_calc_hw(...)
> 	{
> 		...
> 		soc_pcm_hw_init(hw, true);
> 		...
> 	}
> 
> 	int dpcm_runtime_setup_fe(...)
> 	{
> 		...
> 		soc_pcm_hw_init(hw, false);
> 		...
> 	}
> 
> 
> Thank you for your help !!
> 
> Best regards
> ---
> Kuninori Morimoto

-- 
Péter


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

* Re: [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-27  6:20   ` Péter Ujfalusi
@ 2025-10-27  6:54     ` Kuninori Morimoto
  2025-10-27  7:07       ` Péter Ujfalusi
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2025-10-27  6:54 UTC (permalink / raw)
  To: Péter Ujfalusi
  Cc: lgirdwood, broonie, linux-sound, kai.vehmanen, ranjani.sridharan,
	yung-chuan.liao, pierre-louis.bossart, shengjiu.wang


Hi Péter

Thank you for your feedback

> This is how the RFC was done, but decided to not modify
> soc_pcm_hw_init() with an added bool.
> Other option would be to add a new function which would do only
> conditional initialization.

Yes, I have noticed about this RFC, and you used other metod
083a25b18d6a.

> This way we would loose the rate_min, channel_min from components, see
> my RFC which covers this, but it is using reverse condition (preserve vs
> force).
> The force boolean might be better than the preserve_config as parameter
> if the preference is to modify the soc_pcm_hw_init()

I guess you can ignore setup xx_min if "force" was set ?

Thank you for your help !!

Best regards
---
Kuninori Morimoto

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

* Re: [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-27  6:54     ` Kuninori Morimoto
@ 2025-10-27  7:07       ` Péter Ujfalusi
  2025-10-28 21:57         ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Péter Ujfalusi @ 2025-10-27  7:07 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: lgirdwood, broonie, linux-sound, kai.vehmanen, ranjani.sridharan,
	yung-chuan.liao, pierre-louis.bossart, shengjiu.wang

Hi Morimoto-san,

On 27/10/2025 08:54, Kuninori Morimoto wrote:
> 
> Hi Péter
> 
> Thank you for your feedback
> 
>> This is how the RFC was done, but decided to not modify
>> soc_pcm_hw_init() with an added bool.
>> Other option would be to add a new function which would do only
>> conditional initialization.
> 
> Yes, I have noticed about this RFC, and you used other metod
> 083a25b18d6a.

I,m not sure what 083a25b18d6a is.

>> This way we would loose the rate_min, channel_min from components, see
>> my RFC which covers this, but it is using reverse condition (preserve vs
>> force).
>> The force boolean might be better than the preserve_config as parameter
>> if the preference is to modify the soc_pcm_hw_init()
> 
> I guess you can ignore setup xx_min if "force" was set ?

Yes, in a same way as it was done in RFC under the preserve_config case.

> Thank you for your help !!
> 
> Best regards
> ---
> Kuninori Morimoto
> 

-- 
Péter


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

* Re: [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe
  2025-10-27  7:07       ` Péter Ujfalusi
@ 2025-10-28 21:57         ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2025-10-28 21:57 UTC (permalink / raw)
  To: Péter Ujfalusi
  Cc: Kuninori Morimoto, lgirdwood, linux-sound, kai.vehmanen,
	ranjani.sridharan, yung-chuan.liao, pierre-louis.bossart,
	shengjiu.wang

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

On Mon, Oct 27, 2025 at 09:07:11AM +0200, Péter Ujfalusi wrote:
> On 27/10/2025 08:54, Kuninori Morimoto wrote:

> > Yes, I have noticed about this RFC, and you used other metod
> > 083a25b18d6a.

> I,m not sure what 083a25b18d6a is.

https://lore.kernel.org/r/1678346017-3660-1-git-send-email-shengjiu.wang@nxp.com

(that's a commit ID upstream).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2025-10-28 21:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-23  8:14 [PATCH] ASoC: soc-pcm: Preserve hw parameters from components in dpcm_runtime_setup_fe Peter Ujfalusi
2025-10-27  6:11 ` Kuninori Morimoto
2025-10-27  6:20   ` Péter Ujfalusi
2025-10-27  6:54     ` Kuninori Morimoto
2025-10-27  7:07       ` Péter Ujfalusi
2025-10-28 21:57         ` Mark Brown

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