ASoC: soc-pcm: Use conditional PCM hardware parameter initialization
RFC 1/1 ASoC: soc-pcm: Use conditional PCM hardware parameter initialization
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.
---
Hi,
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
sound/soc/soc-pcm.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
sound/soc/soc-pcm.c +26 -13
@@ -570,14 +570,31 @@ 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) +static void soc_pcm_hw_init (struct snd_pcm_hardware *hw,bool preserve_config) { - 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 ; +if (preserve_config) { +/* +* preserve the configuration which might be done by components +* Note: if the rates/rate_max/channels_max/formats are left to +* 0 we still need to initialize them for the parameter updates +* to work +*/ +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 ; + }else { + 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_update_rate(struct snd_pcm_hardware *hw,
@@ -626,7 +643,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, false);/* first calculate min/max only for CPUs in the DAI link */ for_each_rtd_cpu_dais (rtd, i, cpu_dai) {
@@ -1738,13 +1755,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, true);for_each_rtd_cpu_dais (fe, i, dai) {const struct snd_soc_pcm_stream *cpu_stream;
Signature · 1 line
2.51.1.dirty
Quoted 92 lines · Peter Ujfalusi
Component drivers can prepare
snd_pcm_hardwarestruct based on the hardware capabilities which information should not be discarded.Only touch the rates,
channels_maxand formats if they were left to 0, otherwise keep the provided configuration intact for the parameter cross checking decision.Signed-off-by Peter Ujfalusi <[email protected]>---
Hi,this patch in essence extends the special casing of formats done by
083a25b18d6a("ASoC: soc-pcm: fixhw->formatscleared bysoc_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,
Petersound/soc/soc-pcm.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)sound/soc/soc-pcm.c +25
-8@@ -570,14 +570,31 @@ 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) +static void soc_pcm_hw_init (struct snd_pcm_hardware *hw,bool preserve_config) { - 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 ; +if (preserve_config) { +/* +* preserve the configuration which might be done by components +* Note: if the rates/rate_max/channels_max/formats are left to +* 0 we still need to initialize them for the parameter updates +* to work +*/ +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 ; + }else { + 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_update_rate(struct snd_pcm_hardware *hw,@@ -626,7 +643,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, false);/* first calculate min/max only for CPUs in the DAI link */ for_each_rtd_cpu_dais (rtd, i, cpu_dai) {@@ -1738,13 +1755,9 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream)struct snd_pcm_hardware *hw = &runtime->hw;
sound/soc/soc-pcm.c static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream) · line 1760
Quoted 10 lines
sound/soc/soc-pcm.c +1
-5struct 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, true);
Instead of changing the soc_pcm_hw_init() it might be better to move the relevant implementation inline here. I will do this for the patch.
Quoted 3 lines
sound/soc/soc-pcm.c +0
-0for_each_rtd_cpu_dais (fe, i, dai) {const struct snd_soc_pcm_stream *cpu_stream;
Signature · 1 line
Péter