From: "Bahadır Hamza Öztürk" <bahadirhamza2@gmail.com>
To: broonie@kernel.org, lgirdwood@gmail.com, Vijendar.Mukunda@amd.com
Cc: venkataprasad.potturu@amd.com, perex@perex.cz, tiwai@suse.com,
linux-sound@vger.kernel.org,
"Bahadır Hamza Öztürk" <bahadirhamza2@gmail.com>
Subject: [PATCH v2] ASoC: amd: acp: add DMIC capture switch
Date: Sat, 5 Dec 2026 00:17:50 +0300 [thread overview]
Message-ID: <20261204211751.13825-1-bahadirhamza2@gmail.com> (raw)
On ACP platforms using the PDM microphone, e.g. Huawei MateBook
D15/D16/14 AMD with the acp3x-es83xx machine driver, the internal
digital microphone has no capture switch. User space can only mute it
in software, so the mic mute LED (platform::micmute from huawei-wmi)
cannot follow the mute state.
The ACP PDM block has no documented mute. Experiments on a MateBook D15
(BOM-WXX9, Renoir):
- the gain field in ACP_WOV_MISC_CTRL[4:3] only attenuates (~19 dB)
- clearing ACP_WOV_PDM_ENABLE stalls the DMA and the stream
- ACP_WOV_MISC_CTRL bit 5 gates the PDM data input: no microphone data
reaches memory and the stream keeps running, but the decimator then
outputs a constant full-scale negative value instead of silence
Add a "DMIC Capture Switch" control. While it is off:
- on Renoir, the PDM data input is gated with bit 5, also when the PDM
settings are restored on resume, so microphone data never reaches
the buffer, not even for mmap readers looking ahead of the hardware
pointer
- the whole capture buffer is cleared each time the hardware position
is read, before user space is told about new data, which turns the
gated constant (or, on other revisions, the live data) into silence
After unmuting, clearing goes on until at least 10 ms of new data has
been captured, so data captured while muted and the 1 ms full-scale
step the decimator produces when the gate opens are not delivered.
Clearing the whole buffer avoids tracking positions across wraparounds,
stream restarts and resume.
The control does not set SNDRV_CTL_ELEM_ACCESS_MIC_LED: on systems
where the PDM microphone is a second card next to HDA, an always
unmuted LED control would keep the mic mute LED off. Machines that
want the LED to follow the switch can attach it from UCM.
The mute state is kept in the platform data, which is valid from probe
on, rather than in the PCI drvdata, which is only set after the machine
driver may already have probed. The control is only added when the
component has the PDM DAI.
Tested on Huawei MateBook D15 (BOM-WXX9): with the switch off the
recording is digital silence, the stream keeps running, there is no
click on unmute, and with the LED attached from UCM it follows the
switch.
Signed-off-by: Bahadır Hamza Öztürk <bahadirhamza2@gmail.com>
---
Changes in v2:
- Fix issues found by the Sashiko AI review of v1:
- Keep the mute state in the platform data. The PCI drvdata is not
set yet when the component may probe, which could dereference NULL.
Add the control only when the component has the PDM DAI.
- Gate the PDM data input on Renoir (MISC_CTRL bit 5), so mmap
readers looking ahead of the hardware pointer never see live data.
- Clear the whole buffer instead of tracking positions. This removes
the stale position after restart/resume, the full-buffer wraparound
case, and data captured while muted being delivered after unmute.
Keep clearing for 10 ms after unmute to drop the gate's 1 ms step.
- Drop SNDRV_CTL_ELEM_ACCESS_MIC_LED, so other ACP systems (PDM card
next to HDA) keep their current mic mute LED behaviour. The LED is
attached from UCM for acp3x-es83xx instead.
- Read the mute state once per position read, so the gate and the
buffer clearing always agree, and set the gate again when the PDM
settings are restored on resume.
- AMD folks: bit 5 of ACP_WOV_MISC_CTRL is not documented in the
driver. I only verified its effect on Renoir, so it is only used
there. Is there a proper name or a better way to mute the PDM input?
v1: https://lore.kernel.org/linux-sound/20261204200115.10636-1-bahadirhamza2@gmail.com/
sound/soc/amd/acp/acp-legacy-common.c | 2 +
sound/soc/amd/acp/acp-pdm.c | 1 +
sound/soc/amd/acp/acp-platform.c | 102 +++++++++++++++++++++++++-
sound/soc/amd/acp/amd.h | 30 ++++++++
4 files changed, 134 insertions(+), 1 deletion(-)
diff --git a/sound/soc/amd/acp/acp-legacy-common.c b/sound/soc/amd/acp/acp-legacy-common.c
index 9c0528a7d..a66d46574 100644
--- a/sound/soc/amd/acp/acp-legacy-common.c
+++ b/sound/soc/amd/acp/acp-legacy-common.c
@@ -178,6 +178,8 @@ static void set_acp_pdm_clk(struct snd_pcm_substream *substream,
pdm_ctrl = readl(chip->base + ACP_WOV_MISC_CTRL);
pdm_ctrl |= PDM_MISC_CTRL_MASK;
writel(pdm_ctrl, chip->base + ACP_WOV_MISC_CTRL);
+ /* The gate is lost over suspend, set it again before the stream resumes */
+ acp_dmic_update_gate(chip, READ_ONCE(chip->dmic_mute));
set_acp_pdm_ring_buffer(substream, dai);
}
diff --git a/sound/soc/amd/acp/acp-pdm.c b/sound/soc/amd/acp/acp-pdm.c
index 1bfc34c2a..0daa935a5 100644
--- a/sound/soc/amd/acp/acp-pdm.c
+++ b/sound/soc/amd/acp/acp-pdm.c
@@ -40,6 +40,7 @@ static int acp_dmic_prepare(struct snd_pcm_substream *substream,
dmic_ctrl = readl(chip->base + ACP_WOV_MISC_CTRL);
dmic_ctrl |= PDM_MISC_CTRL_MASK;
writel(dmic_ctrl, chip->base + ACP_WOV_MISC_CTRL);
+ acp_dmic_update_gate(chip, READ_ONCE(chip->dmic_mute));
period_bytes = frames_to_bytes(substream->runtime,
substream->runtime->period_size);
diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-platform.c
index f2c885377..9deeb9d4d 100644
--- a/sound/soc/amd/acp/acp-platform.c
+++ b/sound/soc/amd/acp/acp-platform.c
@@ -272,6 +272,49 @@ static int acp_dma_hw_params(struct snd_soc_component *component,
return 0;
}
+/*
+ * Mute for the PDM microphone. The ACP PDM block has no mute control.
+ * Where possible the PDM data input is gated, which keeps microphone data
+ * out of memory, but the decimator then outputs a constant full-scale
+ * value instead of silence. So while muted the whole capture buffer is
+ * also cleared whenever the hardware position is read, before user space
+ * is told about new data. After unmuting, clearing goes on until at least
+ * ACP_DMIC_SETTLE_MS of new data has been captured, which drops the
+ * full-scale step the decimator produces when the gate opens.
+ *
+ * The mute state lives in the platform data, which is valid from probe on.
+ */
+#define ACP_DMIC_SETTLE_MS 10
+
+static void acp_dmic_mute_update(struct acp_chip_info *pdata,
+ struct snd_pcm_substream *substream,
+ struct acp_stream *stream, u64 total,
+ u32 buffersize)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ bool mute = READ_ONCE(pdata->dmic_mute);
+ u32 settle;
+
+ acp_dmic_update_gate(pdata, mute);
+
+ if (mute) {
+ stream->dmic_clearing = true;
+ stream->dmic_open_pos = U64_MAX;
+ } else if (!stream->dmic_clearing) {
+ return;
+ } else if (stream->dmic_open_pos == U64_MAX) {
+ stream->dmic_open_pos = total;
+ } else {
+ settle = frames_to_bytes(runtime, runtime->rate / 1000 *
+ ACP_DMIC_SETTLE_MS);
+ if (total < stream->dmic_open_pos ||
+ total - stream->dmic_open_pos >= settle)
+ stream->dmic_clearing = false;
+ }
+
+ memset(runtime->dma_area, 0, buffersize);
+}
+
static snd_pcm_uframes_t acp_dma_pointer(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
@@ -279,7 +322,7 @@ static snd_pcm_uframes_t acp_dma_pointer(struct snd_soc_component *component,
struct acp_chip_info *chip = dev_get_drvdata(dev->parent);
struct acp_stream *stream = substream->runtime->private_data;
u32 pos, buffersize;
- u64 bytescount;
+ u64 bytescount, total;
buffersize = frames_to_bytes(substream->runtime,
substream->runtime->buffer_size);
@@ -289,8 +332,14 @@ static snd_pcm_uframes_t acp_dma_pointer(struct snd_soc_component *component,
if (bytescount > stream->bytescount)
bytescount -= stream->bytescount;
+ total = bytescount;
pos = do_div(bytescount, buffersize);
+ if (stream->dai_id == DMIC_INSTANCE &&
+ substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ acp_dmic_mute_update(dev_get_platdata(dev), substream, stream,
+ total, buffersize);
+
return bytes_to_frames(substream->runtime, pos);
}
@@ -320,8 +369,59 @@ static int acp_dma_close(struct snd_soc_component *component,
return 0;
}
+static int acp_dmic_switch_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct acp_chip_info *pdata = dev_get_platdata(component->dev);
+
+ ucontrol->value.integer.value[0] = !READ_ONCE(pdata->dmic_mute);
+ return 0;
+}
+
+static int acp_dmic_switch_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct acp_chip_info *pdata = dev_get_platdata(component->dev);
+ bool mute = !ucontrol->value.integer.value[0];
+
+ if (mute == READ_ONCE(pdata->dmic_mute))
+ return 0;
+
+ /* Applied by the next prepare or position read */
+ WRITE_ONCE(pdata->dmic_mute, mute);
+ return 1;
+}
+
+static const struct snd_kcontrol_new acp_dmic_controls[] = {
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "DMIC Capture Switch",
+ .info = snd_ctl_boolean_mono_info,
+ .get = acp_dmic_switch_get,
+ .put = acp_dmic_switch_put,
+ },
+};
+
+static int acp_pcm_probe(struct snd_soc_component *component)
+{
+ struct snd_soc_dai *dai;
+
+ /* Only offer the switch when the PDM DAI is part of this component */
+ for_each_component_dais(component, dai) {
+ if (dai->driver->id == DMIC_INSTANCE)
+ return snd_soc_add_component_controls(component,
+ acp_dmic_controls,
+ ARRAY_SIZE(acp_dmic_controls));
+ }
+
+ return 0;
+}
+
static const struct snd_soc_component_driver acp_pcm_component = {
.name = DRV_NAME,
+ .probe = acp_pcm_probe,
.open = acp_dma_open,
.close = acp_dma_close,
.hw_params = acp_dma_hw_params,
diff --git a/sound/soc/amd/acp/amd.h b/sound/soc/amd/acp/amd.h
index 73a028e67..e150706d0 100644
--- a/sound/soc/amd/acp/amd.h
+++ b/sound/soc/amd/acp/amd.h
@@ -131,6 +131,11 @@
#define PDM_DEC_64 0x2
#define PDM_CLK_FREQ_MASK 0x07
#define PDM_MISC_CTRL_MASK 0x18
+/*
+ * Not documented: with this bit set the PDM data input is gated and the
+ * decimator outputs a constant value instead of microphone data.
+ */
+#define PDM_MISC_DATA_GATE BIT(5)
#define PDM_ENABLE 0x01
#define PDM_DISABLE 0x00
#define DMA_EN_MASK 0x02
@@ -170,6 +175,8 @@ struct acp_chip_info {
bool is_pdm_config; /* flag set to true when PDM configuration is selected from BIOS */
bool is_i2s_config; /* flag set to true when I2S configuration is selected from BIOS */
bool tdm_mode;
+ bool dmic_mute; /* "DMIC Capture Switch" is off */
+ bool dmic_gated; /* PDM_MISC_DATA_GATE was set by the driver */
};
struct acp_stream {
@@ -183,6 +190,8 @@ struct acp_stream {
u32 reg_offset;
u32 pte_offset;
u32 fifo_offset;
+ bool dmic_clearing; /* DMIC buffer is being cleared */
+ u64 dmic_open_pos; /* byte count when the gate was opened */
};
struct acp_resource {
@@ -362,4 +371,25 @@ static inline u64 acp_get_byte_count(struct acp_chip_info *chip, int dai_id, int
POINTER_RETURN_BYTES:
return byte_count;
}
+
+/*
+ * Gate the PDM data input while the DMIC is muted. Only done on Renoir,
+ * where the effect of the bit has been verified; the bit is only cleared
+ * again if the driver set it. The mute state is passed in, so a caller
+ * that also acts on it uses the same state as the gate.
+ */
+static inline void acp_dmic_update_gate(struct acp_chip_info *pdata, bool mute)
+{
+ u32 ctrl, val;
+
+ if (pdata->acp_rev != ACP_RN_PCI_ID || (!mute && !pdata->dmic_gated))
+ return;
+
+ ctrl = readl(pdata->base + ACP_WOV_MISC_CTRL);
+ val = mute ? ctrl | PDM_MISC_DATA_GATE : ctrl & ~PDM_MISC_DATA_GATE;
+ if (val != ctrl)
+ writel(val, pdata->base + ACP_WOV_MISC_CTRL);
+ pdata->dmic_gated = mute;
+}
+
#endif
--
2.53.0
reply other threads:[~2026-12-04 21:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204211751.13825-1-bahadirhamza2@gmail.com \
--to=bahadirhamza2@gmail.com \
--cc=Vijendar.Mukunda@amd.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.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