From: "Mukunda,Vijendar" <vijendar.mukunda@amd.com>
To: Robin Everaars <robineveraars@pm.me>, linux-sound@vger.kernel.org
Cc: venkataprasad.potturu@amd.com, lgirdwood@gmail.com,
broonie@kernel.org, linux-kernel@vger.kernel.org,
Mario Limonciello <Mario.Limonciello@amd.com>,
"Dommati, Sunil-kumar" <Sunil-kumar.Dommati@amd.com>,
Syed Saba Kareem <syed.sabakareem@amd.com>
Subject: Re: ASoC: amd: acp-pdm: full-scale burst on every DMIC capture start
Date: Wed, 12 Aug 2026 15:08:43 +0530 [thread overview]
Message-ID: <25022e80-1dff-46d8-891e-5fe7219f7331@amd.com> (raw)
In-Reply-To: <20260811123336.197402-1-robineveraars@pm.me>
[-- Attachment #1: Type: text/plain, Size: 1802 bytes --]
On 8/11/26 18:03, Robin Everaars wrote:
>> Could you please try attached patch?
> Thanks. I checked the bound driver before building it and found an error in my
> original report: I named acp-pdm.c, but that is not the path used by this
> machine.
>
> The PX13 is bound as follows:
>
> /sys/bus/platform/devices/acp_ps_pdm_dma.0/driver/module
> -> /sys/module/snd_ps_pdm_dma
>
> snd_ps_pdm_dma:
> sound/soc/amd/ps/snd-ps-pdm-dma.ko.xz
> platform alias acp_ps_pdm_dma
>
> The attached patch changes sound/soc/amd/acp/acp-pdm.c, which builds
> snd-acp-pdm. That module is installed but does not own this PCM, so applying the
> patch as-is would not exercise the reported hardware.
>
> The corresponding start sequence is acp63_start_pdm_dma() in
> sound/soc/amd/ps/ps-pdm-dma.c. It also enables the PDM clock, decimator and DMA
> without a settling interval. I can port the 300 ms delay and FIFO flush there
> and test it, but I would prefer to test the exact shape you want upstream. Would
> you send an equivalent patch for snd-ps-pdm-dma,
> or would you like me to prepare
> the test diff?
>
> One detail may also need handling in both versions. PAUSE_PUSH currently takes
> the stop path and disables PDM. After moving PDM_ENABLE to prepare(),
> PAUSE_RELEASE arms only the DMA, and ALSA does not necessarily call prepare()
> between those commands. Should PAUSE_PUSH leave the decimator running, or
> should PAUSE_RELEASE use a separate non-sleeping re-enable path?
PAUSE_PUSH should leave the decimator running. That is the safer ALSA
design and
avoids both the transient and a 300 ms pause-resume latency.
Try attached patch.
>
> Sorry for pointing the original report at the wrong driver. The measurements
> and PCM are unchanged; only my source attribution was wrong.
[-- Attachment #2: 0001-ASoC-amd-ps-pdm-fix-decimator-transient-on-stream-st.patch --]
[-- Type: text/x-patch, Size: 8374 bytes --]
From e59d4aead850caff2ed0b293ebfcdb19ae5e8721 Mon Sep 17 00:00:00 2001
From: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Date: Wed, 12 Aug 2026 14:41:42 +0530
Subject: [PATCH] ASoC: amd: ps: pdm: fix decimator transient on stream start
The ACP PDM DMIC emits a full-scale Nyquist-rate burst at the beginning
of every capture stream. The burst lasts ~4 ms on a warm start (ACP
already running) and ~250 ms on a cold start (ACP runtime-suspended),
and is audible to remote call participants as a click on join.
Root cause: acp63_start_pdm_dma() enables the PDM decimator and the DMA
in the same call, so the CIC filter chain's unflushed initial state goes
directly to userspace. An exponentially growing alternating pattern
collapses into full-scale saturation on both channels in antiphase --
the classic signature of a CIC integrator/comb chain running from a
non-zero initial condition.
Fix: add a prepare() DAI callback that enables PDM_ENABLE and waits
300 ms before the DMA starts. 300 ms is chosen to cover the cold-start
case; the warm-start transient clears in under 5 ms. After the
settling delay, flush ACP_WOV_PDM_FIFO_FLUSH so the DMA sees a clean
buffer. acp63_start_pdm_dma() then only arms the DMA, skipping the
PDM_ENABLE write when prepare() has already set it.
For the RESUME path where prepare() is not called, PDM_ENABLE is set
conditionally in acp63_start_pdm_dma() if not already active.
PAUSE handling: PAUSE_PUSH previously disabled both the DMA and the PDM
decimator via acp63_stop_pdm_dma(). After moving PDM_ENABLE to
prepare(), ALSA does not call prepare() between PAUSE_PUSH and
PAUSE_RELEASE, so PAUSE_RELEASE would have re-enabled PDM without the
300 ms settling delay, reproducing the transient on every resume from
pause.
Fix the pause path by adding acp63_pause_pdm_dma(), which stops the DMA
only and leaves the PDM decimator running. PAUSE_RELEASE flushes the
FIFO to discard samples accumulated while the DMA was stopped, then
restarts the DMA. Since the CIC filter never stopped, no settling delay
is needed. STOP and SUSPEND continue to use acp63_stop_pdm_dma(), which
disables both DMA and PDM.
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
sound/soc/amd/ps/ps-pdm-dma.c | 103 ++++++++++++++++++++++++++++++++--
1 file changed, 97 insertions(+), 6 deletions(-)
diff --git a/sound/soc/amd/ps/ps-pdm-dma.c b/sound/soc/amd/ps/ps-pdm-dma.c
index 04c014349347..6d0e06b50002 100644
--- a/sound/soc/amd/ps/ps-pdm-dma.c
+++ b/sound/soc/amd/ps/ps-pdm-dma.c
@@ -5,6 +5,7 @@
* Copyright 2022, 2025 Advanced Micro Devices, Inc.
*/
+#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/bitfield.h>
@@ -19,6 +20,17 @@
#define DRV_NAME "acp_ps_pdm_dma"
+/*
+ * Time in milliseconds to wait after enabling the PDM clock before
+ * starting the DMA. The PDM microphone and the CIC/decimation filter
+ * chain need this time to reach a stable state; without it the first
+ * frames delivered to userspace contain a saturated Nyquist-rate
+ * transient (unflushed decimator initial state). 300 ms covers both
+ * the warm-start case (~4 ms) and the cold-start case (~250 ms, when
+ * the ACP has been runtime-suspended).
+ */
+#define PDM_SETTLING_DELAY_MS 300
+
static int pdm_gain = 3;
module_param(pdm_gain, int, 0644);
MODULE_PARM_DESC(pdm_gain, "Gain control (0-3)");
@@ -107,12 +119,19 @@ static int acp63_start_pdm_dma(void __iomem *acp_base)
u32 pdm_dma_enable;
int timeout;
- pdm_enable = 0x01;
- pdm_dma_enable = 0x01;
-
acp63_enable_pdm_clock(acp_base);
- writel(pdm_enable, acp_base + ACP_WOV_PDM_ENABLE);
- writel(pdm_dma_enable, acp_base + ACP_WOV_PDM_DMA_ENABLE);
+
+ /*
+ * PDM_ENABLE and the clock were already set in prepare() for the
+ * initial stream start to allow the CIC filter to settle. Only
+ * write PDM_ENABLE if it is not already set, to cover the
+ * RESUME and PAUSE_RELEASE paths where prepare() was not called.
+ */
+ pdm_enable = readl(acp_base + ACP_WOV_PDM_ENABLE);
+ if (!(pdm_enable & ACP_PDM_ENABLE))
+ writel(ACP_PDM_ENABLE, acp_base + ACP_WOV_PDM_ENABLE);
+
+ writel(0x01, acp_base + ACP_WOV_PDM_DMA_ENABLE);
timeout = 0;
while (++timeout < ACP_COUNTER) {
pdm_dma_enable = readl(acp_base + ACP_WOV_PDM_DMA_ENABLE);
@@ -154,6 +173,32 @@ static int acp63_stop_pdm_dma(void __iomem *acp_base)
return 0;
}
+static int acp63_pause_pdm_dma(void __iomem *acp_base)
+{
+ u32 pdm_dma_enable;
+ int timeout;
+
+ /*
+ * Stop only the DMA; leave the PDM decimator running so that
+ * PAUSE_RELEASE does not need to wait for the CIC filter to
+ * settle again. The caller is responsible for flushing the FIFO
+ * before restarting the DMA on PAUSE_RELEASE.
+ */
+ pdm_dma_enable = readl(acp_base + ACP_WOV_PDM_DMA_ENABLE);
+ if (!(pdm_dma_enable & 0x01))
+ return 0;
+
+ writel(0x02, acp_base + ACP_WOV_PDM_DMA_ENABLE);
+ timeout = 0;
+ while (++timeout < ACP_COUNTER) {
+ pdm_dma_enable = readl(acp_base + ACP_WOV_PDM_DMA_ENABLE);
+ if ((pdm_dma_enable & 0x02) == 0x00)
+ return 0;
+ udelay(DELAY_US);
+ }
+ return -ETIMEDOUT;
+}
+
static void acp63_config_dma(struct pdm_stream_instance *rtd, int direction)
{
u16 page_idx;
@@ -286,6 +331,29 @@ static int acp63_pdm_dma_close(struct snd_soc_component *component,
return 0;
}
+static int acp63_pdm_dma_prepare(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct pdm_stream_instance *rtd = substream->runtime->private_data;
+
+ if (!rtd || substream->stream != SNDRV_PCM_STREAM_CAPTURE)
+ return 0;
+
+ /*
+ * Enable the PDM decimator now, before the DMA starts. The
+ * CIC filter chain and the microphone itself need time to reach
+ * a stable state after the clock is applied. Without this
+ * settling period the first frames captured by the DMA contain
+ * a saturated Nyquist-rate transient. Wait for the decimator
+ * to flush, then clear the FIFO so the DMA sees a clean buffer.
+ */
+ acp63_enable_pdm_clock(rtd->acp63_base);
+ writel(ACP_PDM_ENABLE, rtd->acp63_base + ACP_WOV_PDM_ENABLE);
+ msleep(PDM_SETTLING_DELAY_MS);
+ writel(0x01, rtd->acp63_base + ACP_WOV_PDM_FIFO_FLUSH);
+ return 0;
+}
+
static int acp63_pdm_dai_trigger(struct snd_pcm_substream *substream,
int cmd, struct snd_soc_dai *dai)
{
@@ -306,21 +374,43 @@ static int acp63_pdm_dai_trigger(struct snd_pcm_substream *substream,
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
+ writel(ch_mask, rtd->acp63_base + ACP_WOV_PDM_NO_OF_CHANNELS);
+ writel(PDM_DECIMATION_FACTOR, rtd->acp63_base + ACP_WOV_PDM_DECIMATION_FACTOR);
+ rtd->bytescount = acp63_pdm_get_byte_count(rtd, substream->stream);
+ pdm_status = acp63_check_pdm_dma_status(rtd->acp63_base);
+ if (!pdm_status)
+ ret = acp63_start_pdm_dma(rtd->acp63_base);
+ break;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
writel(ch_mask, rtd->acp63_base + ACP_WOV_PDM_NO_OF_CHANNELS);
writel(PDM_DECIMATION_FACTOR, rtd->acp63_base + ACP_WOV_PDM_DECIMATION_FACTOR);
rtd->bytescount = acp63_pdm_get_byte_count(rtd, substream->stream);
+ /*
+ * The PDM decimator was left running during PAUSE_PUSH so no
+ * 300 ms settling delay is needed. Flush the FIFO to discard
+ * samples accumulated while the DMA was stopped, then restart
+ * the DMA.
+ */
+ writel(0x01, rtd->acp63_base + ACP_WOV_PDM_FIFO_FLUSH);
pdm_status = acp63_check_pdm_dma_status(rtd->acp63_base);
if (!pdm_status)
ret = acp63_start_pdm_dma(rtd->acp63_base);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
pdm_status = acp63_check_pdm_dma_status(rtd->acp63_base);
if (pdm_status)
ret = acp63_stop_pdm_dma(rtd->acp63_base);
break;
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ /*
+ * Leave the PDM decimator running so that PAUSE_RELEASE does
+ * not need the 300 ms CIC settling delay. Only stop the DMA.
+ */
+ pdm_status = acp63_check_pdm_dma_status(rtd->acp63_base);
+ if (pdm_status)
+ ret = acp63_pause_pdm_dma(rtd->acp63_base);
+ break;
default:
ret = -EINVAL;
break;
@@ -329,6 +419,7 @@ static int acp63_pdm_dai_trigger(struct snd_pcm_substream *substream,
}
static const struct snd_soc_dai_ops acp63_pdm_dai_ops = {
+ .prepare = acp63_pdm_dma_prepare,
.trigger = acp63_pdm_dai_trigger,
};
--
2.48.1
next prev parent reply other threads:[~2026-08-12 9:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 18:11 Robin Everaars
2026-08-10 5:11 ` Mukunda,Vijendar
2026-08-11 12:33 ` Robin Everaars
2026-08-11 15:27 ` Mukunda,Vijendar
2026-08-12 9:38 ` Mukunda,Vijendar [this message]
2026-08-12 13:41 ` Robin Everaars
2026-08-13 5:10 ` Mukunda,Vijendar
2026-08-13 12:16 ` Robin Everaars
2026-08-13 12:26 ` Robin Everaars
2026-08-14 8:35 ` Mukunda,Vijendar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25022e80-1dff-46d8-891e-5fe7219f7331@amd.com \
--to=vijendar.mukunda@amd.com \
--cc=Mario.Limonciello@amd.com \
--cc=Sunil-kumar.Dommati@amd.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=robineveraars@pm.me \
--cc=syed.sabakareem@amd.com \
--cc=venkataprasad.potturu@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®