Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: es8316: Allow more time for headset mic bias to settle
@ 2026-11-10 14:58 Ilya Muhamadeev
  2026-11-10 15:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Muhamadeev @ 2026-11-10 14:58 UTC (permalink / raw)
  To: linux-sound, Mark Brown, Liam Girdwood
  Cc: Ilya Muhamadeev, Jaroslav Kysela, Takashi Iwai, linux-kernel,
	stable

On the 3Logic Group Graviton N15i-K2, a TRRS headset is detected as
headphones, leaving its microphone unavailable. The driver waits 20 ms
after enabling microphone bias before reading GPIO_FLAG to distinguish
a headset from headphones.

Register reads on this machine show that GM_NOT_SHORTED remains clear
through 40 ms and becomes set at approximately 60 ms after enabling
microphone bias. Reading the bit after only 20 ms therefore incorrectly
identifies the headset microphone as shorted to ground.

Increase the settling delay to 100 ms to cover the observed settling
time with some margin. This adds 80 ms to the microphone bias enable
sequence used for jack detection.

Fixes: 822257661031 ("ASoC: es8316: Add jack-detect support")
Cc: stable@vger.kernel.org
Signed-off-by: Ilya Muhamadeev <nicourced@altlinux.org>
---
 sound/soc/codecs/es8316.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 334ac9119c18f34d51d79fb357c3d82096935c7f..470c503010fc1c02fba9d8e9aaf0ea61b4be3637 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -616,7 +616,7 @@ static void es8316_enable_micbias_for_mic_gnd_short_detect(
 	snd_soc_dapm_sync_unlocked(dapm);
 	snd_soc_dapm_mutex_unlock(dapm);
 
-	msleep(20);
+	msleep(100);
 }
 
 static void es8316_disable_micbias_for_mic_gnd_short_detect(

base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9

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

* Re: [PATCH] ASoC: es8316: Allow more time for headset mic bias to settle
  2026-11-10 14:58 [PATCH] ASoC: es8316: Allow more time for headset mic bias to settle Ilya Muhamadeev
@ 2026-11-10 15:03 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-10 15:03 UTC (permalink / raw)
  To: Ilya Muhamadeev, linux-sound

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] ASoC: es8316: uninitialized variable read in es8316_irq() [1]
--

commit 83fd03ee6536ad322b774377b945917b625ffca5
Author: Ilya Muhamadeev <nicourced@altlinux.org>

ASoC: es8316: Allow more time for headset mic bias to settle

This commit increases the settling delay in
es8316_enable_micbias_for_mic_gnd_short_detect() from 20 ms to 100 ms so
that ES8316_GPIO_FLAG_GM_NOT_SHORTED settles before jack detection reads
ES8316_GPIO_FLAG.

> diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
> index 334ac9119c18f..470c503010fc1 100644
> --- a/sound/soc/codecs/es8316.c
> +++ b/sound/soc/codecs/es8316.c
> @@ -616,7 +616,7 @@ static void es8316_enable_micbias_for_mic_gnd_short_detect(
>  	snd_soc_dapm_sync_unlocked(dapm);
>  	snd_soc_dapm_mutex_unlock(dapm);
>  
> -	msleep(20);
> +	msleep(100);
>  }

[Severity: Medium]
This problem wasn't introduced by this patch, but can es8316_irq()
evaluate an uninitialized flags variable [1] if regmap_read() fails?

sound/soc/codecs/es8316.c:es8316_irq() {
	...
	unsigned int flags;

	guard(mutex)(&es8316->lock);

	regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags);
	if (flags == 0x00)
		return IRQ_HANDLED; /* Powered-down / reset */
	...
	} else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) {
		/* Jack inserted, determine type */
		es8316_enable_micbias_for_mic_gnd_short_detect(comp);
		regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags);
		if (es8316->jd_inverted)
			flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED;
	...
}

Neither regmap_read() call checks for errors.  If an I2C read fails (or
returns -EBUSY while the regcache is in cache-only mode during resume),
es8316_irq() branches on indeterminate stack data, which can report bogus
jack events to userspace or leave mic bias enabled in the wrong state.

[1] https://sashiko.dev/#/bug/linux-3f2856a8-3cfe-4dc1-bfa0-d15ea515aabd

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110145835.106381-1-nicourced@altlinux.org?part=1

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

end of thread, other threads:[~2026-11-10 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 14:58 [PATCH] ASoC: es8316: Allow more time for headset mic bias to settle Ilya Muhamadeev
2026-11-10 15:03 ` sashiko-bot

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