mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: qcom: q6asm: Reset PCM positions when preparing a stream
@ 2026-10-21 20:42 Michael McAllister
  2026-11-09 12:08 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Michael McAllister @ 2026-10-21 20:42 UTC (permalink / raw)
  To: linux-sound
  Cc: Srinivas Kandagatla, Mark Brown, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, linux-arm-msm, linux-kernel

Preparing an existing PCM stream closes the DSP stream and remaps its
buffers, but leaves queue_ptr, dsp_buf and hw_ptr at their previous
positions. ALSA resets appl_ptr during prepare, so q6asm_dai_ack() can
subtract a stale queue_ptr from the new appl_ptr and queue an incorrect
number of periods.

On the Motorola Moto G10, playback works after opening the PCM device,
but the first write after snd_pcm_drop() and snd_pcm_prepare() fails
with -EBUSY and "Error queuing playback buffer -16".

Reset queue_ptr in prepare, and reset the DSP buffer index and hardware
pointer when allocating the new buffer ring. This keeps the queued,
submitted and completed positions aligned with the new PCM stream.

Fixes: e386c2cf3df2 ("ASoC: qcom: q6asm-dai: schedule all available frames to avoid dsp under-runs")
Fixes: 44432315444c ("ASoC: qcom: q6asm-dai: use q6asm_get_hw_pointer")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
Tested on a Motorola Moto G10 using a Linux 7.2.9-based port, with
48 kHz S16_LE stereo playback, a 3840-frame buffer and 960-frame periods.
After two seconds of playback, snd_pcm_drop() followed by
snd_pcm_prepare() and snd_pcm_writei() on the same handle returned -EBUSY
without this change. With the change, both playback cycles completed.

Both affected objects also build with ARCH=arm64 W=1 against sound's
for-next branch at bef34efba74d. This maintainer-tree build has not been
booted on the device.

 sound/soc/qcom/qdsp6/q6asm-dai.c | 3 +++
 sound/soc/qcom/qdsp6/q6asm.c     | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
index 4261c3048c..94416ddf7a 100644
--- a/sound/soc/qcom/qdsp6/q6asm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
@@ -243,6 +243,9 @@ static int q6asm_dai_prepare(struct snd_soc_component *component,
 		prtd->state = Q6ASM_STREAM_STOPPED;
 	}
 
+	/* ALSA resets appl_ptr for every prepare, including xrun recovery. */
+	prtd->queue_ptr = 0;
+
 	ret = q6asm_map_memory_regions(substream->stream, prtd->audio_client,
 				       prtd->phys,
 				       (prtd->pcm_size / prtd->periods),
diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index de0bd8fd08..8dde9a3b9c 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -514,6 +514,8 @@ int q6asm_map_memory_regions(unsigned int dir, struct audio_client *ac,
 
 
 	ac->port[dir].buf = buf;
+	ac->port[dir].dsp_buf = 0;
+	atomic_set(&ac->port[dir].hw_ptr, 0);
 
 	buf[0].phys = phys;
 	buf[0].size = period_sz;

base-commit: bef34efba74d87d5c20e3bb93539fa45b3cb8a83
-- 
2.50.1 (Apple Git-155)



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

* Re: [PATCH] ASoC: qcom: q6asm: Reset PCM positions when preparing a stream
  2026-10-21 20:42 [PATCH] ASoC: qcom: q6asm: Reset PCM positions when preparing a stream Michael McAllister
@ 2026-11-09 12:08 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-11-09 12:08 UTC (permalink / raw)
  To: linux-sound, Michael McAllister
  Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, linux-arm-msm, linux-kernel

On Wed, 21 Oct 2026 21:42:02 +0100, Michael McAllister wrote:
> ASoC: qcom: q6asm: Reset PCM positions when preparing a stream

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/1] ASoC: qcom: q6asm: Reset PCM positions when preparing a stream
      https://git.kernel.org/broonie/sound/c/54e89fab723d

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


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

end of thread, other threads:[~2026-11-09 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 20:42 [PATCH] ASoC: qcom: q6asm: Reset PCM positions when preparing a stream Michael McAllister
2026-11-09 12:08 ` Mark Brown

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

all inboxes | Powered by JetHome®