Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-pcm: test if a BE can be prepared

In the BE hw_params configuration, the existing code checks if any of the
existing FEs are prepared, running, paused or suspended - and skips the
configuration in those cases. This allows multiple calls of hw_params
which the ALSA state machine supports.

This check is not handled for the prepare stage, which can lead to the
same BE being prepared multiple times. This patch adds a check similar to
that of the hw_params, with the main difference being that the suspended
state is allowed: the ALSA state machine allows a transition from
suspended to prepared with hw_params skipped.

This problem was detected on Intel IPC4/SoundWire devices, where the BE
dailink .prepare stage is used to configure the SoundWire stream with a
bank switch. Multiple .prepare calls lead to conflicts with the .trigger
operation with IPC4 configurations. This problem was not detected earlier
on Intel devices, HDaudio BE dailinks detect that the link is already
prepared and skip the configuration, and for IPC3 devices there is no BE
trigger.

Link: https://github.com/thesofproject/sof/issues/7596
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com
Link: https://lore.kernel.org/r/20230517185731.487124-1-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org

authored by

Ranjani Sridharan and committed by
Mark Brown
e123036b 8b271370

+24
+4
include/sound/soc-dpcm.h
··· 122 122 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, 123 123 struct snd_soc_pcm_runtime *be, int stream); 124 124 125 + /* can this BE perform prepare */ 126 + int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe, 127 + struct snd_soc_pcm_runtime *be, int stream); 128 + 125 129 /* is the current PCM operation for this FE ? */ 126 130 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream); 127 131
+20
sound/soc/soc-pcm.c
··· 2405 2405 if (!snd_soc_dpcm_be_can_update(fe, be, stream)) 2406 2406 continue; 2407 2407 2408 + if (!snd_soc_dpcm_can_be_prepared(fe, be, stream)) 2409 + continue; 2410 + 2408 2411 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && 2409 2412 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && 2410 2413 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND) && ··· 3045 3042 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state)); 3046 3043 } 3047 3044 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params); 3045 + 3046 + /* 3047 + * We can only prepare a BE DAI if any of it's FE are not prepared, 3048 + * running or paused for the specified stream direction. 3049 + */ 3050 + int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe, 3051 + struct snd_soc_pcm_runtime *be, int stream) 3052 + { 3053 + const enum snd_soc_dpcm_state state[] = { 3054 + SND_SOC_DPCM_STATE_START, 3055 + SND_SOC_DPCM_STATE_PAUSED, 3056 + SND_SOC_DPCM_STATE_PREPARE, 3057 + }; 3058 + 3059 + return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state)); 3060 + } 3061 + EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_prepared);