From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796419092; b=2FzcQ69fFo86IDpCO5gpds1M+hUAMKkqBYWGSWnkN3NGKrHDyTshDdhZKT7a+kWcO+JL Ulbu4uUKK0z+e1OVM+7mcTFBBWI+DWN8I7MUt6Iosq2LOyeQZUlmWWxBL6sYOIRqRbpm2 PkFYZQWwg89wYnnfuoQBWZQbnD7dGogqo1t3LmLUsHUZhrEfQsfjMIrXhA1IZvu4cwhzE 4urAuIUEB+GlyqcgINexjYMHyv3Y/rAQXmj3I8cjVIyWBV901Yhcd3yZZt0X6HanFyl7Q Tg8z1Wqm0EAO4huFgF6erIz/qhutSFq10ItdK8ZXD8Ox9gh1DfLQn1ajexvdkDJ9wlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796419092; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=IYcrfMf/GoJQYabzMHQc2HXcSLnjd2RIcHCVSb/9wIQ=; b=IstGP3MITCxHD4PDOf4/eG9LOjEsyzgzVgvNH7rjslJQjZ93ZZM0g5dMHVn9o95wQIfu I5L6ApxVzkOFJP73YmfwmaLFleDWOLVYIbI9A5m6L22GgrK+MmaQ2nOZjrvryZD+CUr4h gweN7QGWqj0qk6NhvsUNf1U2xP5pqGezdLaut+kL4gW4xJkkaKmM0LLsgY4DjenuTiX5B eNhqBzc4eLImEv0DpRWw2wmU2rxIkPzW4xYBLQ9FVatLnlUTHS1bdqkwOkLhxXOGxihNJ d+d/Z31LqoFeT5VDD1eImsH+UhVmjz12v4OrGtkQEn7NjbVaduXJ60XOTdEUV5F5D8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AZCsk9Ny; arc=none smtp.remote-ip=209.85.221.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02622606A322 for ; Fri, 4 Dec 2026 21:18:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 02622606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AZCsk9Ny Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4a42b34e930so1194106f8f.2 for ; Fri, 04 Dec 2026 13:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796419090; x=1797023890; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IYcrfMf/GoJQYabzMHQc2HXcSLnjd2RIcHCVSb/9wIQ=; b=AZCsk9NydsKtnlFSWzE4b/4RhZq7Rbr1/TtrMsiZ94uI/xgnx2BiHmK98EkvDDrJUt c6m2jhMZXLpyzKyGSdCRC1akIdMrPyDAGnXn3PTCoa6Mfw08s6uWoj8qxVQpuX4YkBuh PLBUW3HzgNOuCFsux1p3qfBFWJ/iNrkYfKOmxMhwE6Sze9AMcmYeQ/qaWm656i7j9wO0 TGVtpZT6v0Qh4jrb3W4gHA851SiutBbcm1i1vzFRg4jTIxMc4PRSHgNR6+DJ7sAr5ezP Ajky0C7rvsSdexN40L60fonqW6AJQUumTbKzpT+dBxawpt5LikhC++gkQj9g7ImOFaRf Yfvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796419090; x=1797023890; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=IYcrfMf/GoJQYabzMHQc2HXcSLnjd2RIcHCVSb/9wIQ=; b=zzVW02JJukNz3XrW5vFxhspx1wkgeGX7PNlxSesm3vtX3AQz4sDPtzFFYu+roVvRyt ELWEAqTcGm4m4MUDNrRh42Be50fNnpchezz7KBXBQGHqKldM9R8WZLRt7c3MTMWkoZS4 nmbaJuDjS92DQVvAc8IQEHNf23spXJA8ytNomoD0eXonW+MpbOb/rEjySPIseJrxaEPP nEqtf+SeiJGl+0qV7WVF4oWg2jc5cCGe/eD3XOXyOHKAA+5q9c/PmAwSB8Uz4XSj4hiK 9IHniF5PJ+BVh0yWSHAe7yT9CaZ/ejD0Em7xi6At9gzzlPelPJeg11nvVJnl7bz548wS nKZA== X-Forwarded-Encrypted: i=1; AL+hErG7mUzMnSoXVtgIOTmt9ix+G026VTU7D5GbAeDhHHldFaFLdToDVMYDL5CXdmjThc4zcirFgsE4Iw4eBg==@vger.kernel.org X-Gm-Message-State: AB4q+uE3o7VPFLCf8KWnk+IVPBsS3vyE5DjcqqeeBgT9pQFOdn4cV0V/ XIJLUfy4WKI0Bp9SytxX8SPykCbN8BU6wIPdo5RgUseuaAmvQk8YE0A6 X-Gm-Gg: AZFdTZeYFT1ud7AjAKgMpZs/IsFkNWfDDbPT8Ur2yaQ9jYRdFawejmw+yLWpaOYd2UM zXZ5JBCwi9fD0HWRzERTPoasjs4S+hrE5Yrrv5TxQnPcll1zzauDcrLiUo8R8uE3bHRPewZMYij D2MDYcbZnaf+/W/qhxMTusvv0/GGrm1hyQz3OxJVOCPbw92BruNFF/bMbj7hfkXvYIf0/Vb9A52 0xP7MkNbP4tVVDhaTvyhUBs8vzkEs71qYLRAF5/rP+tcB8rQ7kakvH8yzNfE93LxJElYxVD1W2a Pw9SFoQQGGNpsDUVot8DoTxTS5xaIRbLmOFzSYUkECkFYz8Pjdfw6N4nPnBlRwpThMTgJ7Mf98E asJxrrw4B30n9tchL6m1nrFu/Fhde7lOP+n/zg3acW1Dq4jI9HUefFB0QCrjT2jH/Zrs2/tPuwp WYgiouiXKBUcZlbMOKh+Ur+GAxpiCV/PnmPVx3UMW3jZ0V3R7uFbIE92ertjdUb8l6qhR48lKsq O7Lf92YBgMzD68UOm5TOtNdc1GQkueyZoYdK+w8aqrg26lGpEHi6zj+JJGLRbKeZT4IzrIuXNr9 qsWxjen176n/0gIzCqp67gFVS2MkDOMMEzCRqvDuwjjG/2zudZHm1SDGHQ== X-Received: by 2002:a05:6000:188a:b0:48f:fcac:a5e2 with SMTP id ffacd0b85a97d-4d1eb6e1723mr6023727f8f.38.1796419090092; Fri, 04 Dec 2026 13:18:10 -0800 (PST) Received: from andev-BOM-WXX9 ([88.230.183.63]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41e27sm6955066f8f.21.2026.12.04.13.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 13:18:09 -0800 (PST) From: =?UTF-8?q?Bahad=C4=B1r=20Hamza=20=C3=96zt=C3=BCrk?= 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, =?UTF-8?q?Bahad=C4=B1r=20Hamza=20=C3=96zt=C3=BCrk?= Subject: [PATCH v2] ASoC: amd: acp: add DMIC capture switch Date: Sat, 5 Dec 2026 00:17:50 +0300 Message-ID: <20261204211751.13825-1-bahadirhamza2@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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