Linux Sound subsystem development
 help / color / mirror / Atom feed
From: "Bahadır Hamza Öztürk" <bahadirhamza2@gmail.com>
To: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Cc: "Venkata Prasad Potturu" <venkataprasad.potturu@amd.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	linux-sound@vger.kernel.org,
	"Bahadır Hamza Öztürk" <bahadirhamza2@gmail.com>
Subject: [PATCH] ASoC: amd: acp: add DMIC capture switch with mic mute LED support
Date: Fri,  4 Dec 2026 23:01:15 +0300	[thread overview]
Message-ID: <20261204200115.10636-1-bahadirhamza2@gmail.com> (raw)

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


             reply	other threads:[~2026-12-04 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:01 Bahadır Hamza Öztürk [this message]
2026-12-04 20:23 ` [PATCH] ASoC: amd: acp: add DMIC capture switch with mic mute LED support sashiko-bot

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=20261204200115.10636-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