Re: [RFC PATCH 02/23] ASoC: soc-pcm: add multi_direction_codecs link flag

From: Srinivas Kandagatla

Date: Sun Nov 15 2026 - 16:04:18 EST


On 11/15/26 5:36 PM, Mark Brown wrote:
>> Speaker protection needs the amplifiers' V/I sense capture running
>> whenever the speakers play. Putting the capture codec DAIs on the
>> playback BE link ties the two together, but the core skips codec DAIs
>> whose direction does not match the substream.
>
>> Add a multi_direction_codecs link flag. When set, the core also calls
>> .hw_params and .hw_free on codec DAIs of the other direction, with the
>> substream direction switched to theirs for the call under pcm_mutex,
>> and sends the matching stream events so their widgets power up and
>> down. An optional multi_direction_params_fixup callback lets the
>> machine driver set the parameters for those DAIs. Links without the
>> flag are unchanged.
>
>> +3. Optionally calls ``.multi_direction_params_fixup`` so the machine
>> + driver can rewrite rate/format/channels on a per-codec copy of the
>
> Probably worth mentioning the ordering with regard to other fixups.
>
>> @@ -986,6 +986,9 @@ static int __soc_pcm_prepare(struct snd_soc_pcm_runtime *rtd,
>>
>> snd_soc_dapm_stream_event(rtd, substream->stream,
>> SND_SOC_DAPM_STREAM_START);
>> + if (rtd->dai_link->multi_direction_codecs)
>> + snd_soc_dapm_stream_event(rtd, substream->stream ^ 1,
>> + SND_SOC_DAPM_STREAM_START);
>
> This will update every DAI, including CPU DAIs. That will mean that a
> CPU DAI could be flagged as actively capturing due to playback or vice
> versa.

Correct, we should limit this to codec dais, will fix that in v2.

>
>> +static int soc_pcm_dai_hw_params_at_stream(struct snd_soc_dai *dai,
>> + struct snd_pcm_substream *substream,
>> + struct snd_pcm_hw_params *params,
>> + int stream)
>> +{
>> + int saved_stream = substream->stream;
>> + int ret;
>> +
>> + if (stream == saved_stream)
>> + return snd_soc_dai_hw_params(dai, substream, params);
>> +
>> + substream->stream = stream;
>> + ret = snd_soc_dai_hw_params(dai, substream, params);
>
> We flipped stream but nothing else, if hw_params checks things in the
> substream->runtime things will get confused. Usually everything is just
> checking params though.


I think the documentation should capture this and the codec dai that is
supports multi-directional should be ready to handle this.

I will add a comment about this both here and Documentation.

>
>> @@ -1061,9 +1117,20 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
>> snd_soc_pcm_component_hw_free(substream, rollback);
>>
>> /* now free hw params for the DAIs */
>> - for_each_rtd_dais(rtd, i, dai)
>> - if (snd_soc_dai_stream_valid(dai, substream->stream))
>> - snd_soc_dai_hw_free(dai, substream, rollback);
>> + for_each_rtd_dais(rtd, i, dai) {
>
> This has flipping that __soc_pcm_hw_params() doesn't unless I'm
> something?

Yes, this needs to be split like what we do for hw_params, splitting
both cpu and codec dais. Will fix in v2.

--srini

>