Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: amd: acp: add DMIC capture switch with mic mute LED support
@ 2026-12-04 20:01 Bahadır Hamza Öztürk
  2026-12-04 20:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Bahadır Hamza Öztürk @ 2026-12-04 20:01 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Vijendar Mukunda
  Cc: Venkata Prasad Potturu, Jaroslav Kysela, Takashi Iwai,
	linux-sound, Bahadır Hamza Öztürk

On ACP platforms using the legacy PDM path (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 ctl-led layer never sees a mute and the mic mute
LED (exposed as platform::micmute by huawei-wmi) never lights up.

Register-level experiments on a MateBook D15 (BOM-WXX9, Renoir)
found no usable hardware mute in the ACP PDM block:
 - 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, but the decimator then
   outputs a constant full-scale negative DC value instead of silence

Add a "DMIC Capture Switch" control with SNDRV_CTL_ELEM_ACCESS_MIC_LED
and implement the mute in software: while the switch is off, captured
data between the last handled position and the current hardware
position is cleared in the .pointer callback, before the hw_ptr is
updated, so neither period-based nor mmap readers can observe it.

The control is only added when the ACP PDM controller is present.

Tested on Huawei MateBook D15 (BOM-WXX9): with the switch off the
recording is digital silence, the stream keeps running and the mic
mute LED follows the switch.

Signed-off-by: Bahadır Hamza Öztürk <bahadirhamza2@gmail.com>
---
 sound/soc/amd/acp/acp-platform.c | 78 ++++++++++++++++++++++++++++++++
 sound/soc/amd/acp/amd.h          |  2 +
 2 files changed, 80 insertions(+)

diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-platform.c
index f2c885377..2163e233e 100644
--- a/sound/soc/amd/acp/acp-platform.c
+++ b/sound/soc/amd/acp/acp-platform.c
@@ -268,10 +268,33 @@ static int acp_dma_hw_params(struct snd_soc_component *component,
 	/* Configure ACP DMA block with params */
 	config_pte_for_stream(chip, stream);
 	config_acp_dma(chip, stream, size);
+	stream->mute_pos = 0;
 
 	return 0;
 }
 
+/*
+ * The ACP PDM block has no mute control, so mute the DMIC in software:
+ * every captured byte between the last handled position and the
+ * current hardware position is cleared before user space can see it.
+ * This is called from the .pointer callback, which runs before any
+ * hw_ptr update, so it covers both period interrupts and mmap readers
+ * that query the position in between.
+ */
+static void acp_dmic_soft_mute(struct snd_pcm_substream *substream,
+			       struct acp_stream *stream, u32 pos, u32 buffersize)
+{
+	unsigned char *area = substream->runtime->dma_area;
+	u32 start = stream->mute_pos;
+
+	if (start <= pos) {
+		memset(area + start, 0, pos - start);
+	} else {
+		memset(area + start, 0, buffersize - start);
+		memset(area, 0, pos);
+	}
+}
+
 static snd_pcm_uframes_t acp_dma_pointer(struct snd_soc_component *component,
 					 struct snd_pcm_substream *substream)
 {
@@ -291,6 +314,13 @@ static snd_pcm_uframes_t acp_dma_pointer(struct snd_soc_component *component,
 
 	pos = do_div(bytescount, buffersize);
 
+	if (stream->dai_id == DMIC_INSTANCE &&
+	    substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+		if (READ_ONCE(chip->dmic_mute))
+			acp_dmic_soft_mute(substream, stream, pos, buffersize);
+		stream->mute_pos = pos;
+	}
+
 	return bytes_to_frames(substream->runtime, pos);
 }
 
@@ -320,8 +350,56 @@ 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 *chip = dev_get_drvdata(component->dev->parent);
+
+	ucontrol->value.integer.value[0] = !READ_ONCE(chip->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 *chip = dev_get_drvdata(component->dev->parent);
+	bool mute = !ucontrol->value.integer.value[0];
+
+	if (mute == READ_ONCE(chip->dmic_mute))
+		return 0;
+
+	WRITE_ONCE(chip->dmic_mute, mute);
+	return 1;
+}
+
+static const struct snd_kcontrol_new acp_dmic_controls[] = {
+	{
+		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name	= "DMIC Capture Switch",
+		.access	= SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_MIC_LED,
+		.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 acp_chip_info *chip = dev_get_drvdata(component->dev->parent);
+
+	if (!chip->is_pdm_dev)
+		return 0;
+
+	return snd_soc_add_component_controls(component, acp_dmic_controls,
+					      ARRAY_SIZE(acp_dmic_controls));
+}
+
 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..4fc7b85f9 100644
--- a/sound/soc/amd/acp/amd.h
+++ b/sound/soc/amd/acp/amd.h
@@ -170,6 +170,7 @@ 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;		/* set when the "DMIC Capture Switch" is off */
 };
 
 struct acp_stream {
@@ -183,6 +184,7 @@ struct acp_stream {
 	u32 reg_offset;
 	u32 pte_offset;
 	u32 fifo_offset;
+	u32 mute_pos;		/* DMIC: buffer offset already handled by soft mute */
 };
 
 struct acp_resource {
-- 
2.53.0


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

end of thread, other threads:[~2026-12-04 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 20:01 [PATCH] ASoC: amd: acp: add DMIC capture switch with mic mute LED support Bahadır Hamza Öztürk
2026-12-04 20:23 ` sashiko-bot

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