ASoC: soc-pcm: test if a BE can be prepared
PATCH 1/1 ASoC: soc-pcm: test if a BE can be prepared
From: Ranjani Sridharan <[email protected]>
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.
--- include/sound/soc-dpcm.h | 4 ++++ sound/soc/soc-pcm.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/sound/soc-dpcm.h +4 -0
@@ -122,6 +122,10 @@ int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,int snd_soc_dpcm_can_be_params (struct snd_soc_pcm_runtime *fe,struct snd_soc_pcm_runtime *be,int stream); +/* can this BE perform prepare */ +int snd_soc_dpcm_can_be_prepared (struct snd_soc_pcm_runtime *fe, +struct snd_soc_pcm_runtime *be,int stream); +/* is the current PCM operation for this FE ? */ int snd_soc_dpcm_fe_can_update (struct snd_soc_pcm_runtime *fe,int stream);
sound/soc/soc-pcm.c +20 -0
@@ -2405,6 +2405,9 @@ int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)if (!snd_soc_dpcm_be_can_update (fe, be, stream))continue ; +if (!snd_soc_dpcm_can_be_prepared (fe, be, stream)) +continue ; + if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND) &&
@@ -3042,3 +3045,20 @@ int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,return snd_soc_dpcm_check_state (fe, be, stream, state,ARRAY_SIZE (state)); }EXPORT_SYMBOL_GPL (snd_soc_dpcm_can_be_params); + +/* +* We can only prepare a BE DAI if any of it's FE are not prepared, +* running or paused for the specified stream direction. +*/ +int snd_soc_dpcm_can_be_prepared (struct snd_soc_pcm_runtime *fe, +struct snd_soc_pcm_runtime *be,int stream) +{ +const enum snd_soc_dpcm_state state[] = { +SND_SOC_DPCM_STATE_START , +SND_SOC_DPCM_STATE_PAUSED , +SND_SOC_DPCM_STATE_PREPARE , + }; + +return snd_soc_dpcm_check_state (fe, be, stream, state,ARRAY_SIZE (state)); +} +EXPORT_SYMBOL_GPL (snd_soc_dpcm_can_be_prepared);
Signature · 1 line
2.37.2
Quoted 21 lines · Pierre-Louis Bossart
From: Ranjani Sridharan <[email protected]>
In the BE
hw_paramsconfiguration, 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 ofhw_paramswhich 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 withhw_paramsskipped.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.
Quoted 5 lines
Signed-off-by Ranjani Sridharan <[email protected]>Signed-off-by Bard Liao <[email protected]>Signed-off-by Pierre-Louis Bossart <[email protected]>---
Makes sense, I lightly tested it myself with multi FE configuration and then asked validation to run a round of tests with multiple FE topology and everything seems to work, so
Mark Brown
maintainerQuoted 5 lines · Pierre-Louis Bossart
In the BE
hw_paramsconfiguration, 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 ofhw_paramswhich the ALSA state machine supports.
Quoted 7 lines
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 withhw_paramsskipped.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: soc-pcm: test if a BE can be prepared
commit: e123036be377ddf628226a7c6d4f9af5efd113d3
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