Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] ASoC: codecs: Everest: fix clock and supply balance
@ 2026-12-01 19:22 Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 1/3] ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level Arina Kharlamova via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:22 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Binbin Zhou, Zhang Yi, David Yang
  Cc: linux-sound, Arina Kharlamova

Fixes for unbalanced clock and supply handling in the es8323,
es8375 and es8326 drivers. The es8326 patch is last because it
changes when mclk is on; the first two do not depend on it.

I found these with spec2patch. I model-checked the probe and remove
paths of each driver with CBMC against formal specifications of the
kernel APIs they call. The specifications are checked against the kernel
source, and some of them are proved in Rocq against a transcription of
the kernel code. I also checked lock usage separately. With the help of
an AI coding assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.

---
Arina Kharlamova (3):
      ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level
      ASoC: codecs: es8375: Disable core supplies on unbind
      ASoC: codecs: ES8326: Keep mclk enabled while the device is bound

 sound/soc/codecs/es8323.c |  8 --------
 sound/soc/codecs/es8326.c | 14 +-------------
 sound/soc/codecs/es8375.c | 13 +++++++++++++
 3 files changed, 14 insertions(+), 21 deletions(-)
---
base-commit: 20ee6031645dbed8ddf8f4833edf415f3760607f
change-id: 20261201-s2p-asoc-es-6a6fc4f2b0b8

Best regards,
--  
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>



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

* [PATCH 1/3] ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level
  2026-12-01 19:22 [PATCH 0/3] ASoC: codecs: Everest: fix clock and supply balance Arina Kharlamova via B4 Relay
@ 2026-12-01 19:22 ` Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 3/3] ASoC: codecs: ES8326: Keep mclk enabled while the device is bound Arina Kharlamova via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:22 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Binbin Zhou, Zhang Yi, David Yang
  Cc: linux-sound, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

es8323_probe() enables mclk and es8323_remove() disables it, so the
clock is on for as long as the component is bound to a card.
es8323_set_bias_level() also enables it for SND_SOC_BIAS_PREPARE and
disables it for SND_SOC_BIAS_OFF, and these calls do not balance.

DAPM passes through PREPARE on the way to ON and again on the way back,
so each cycle from OFF to ON and back to OFF enables the clock twice
and disables it once. es8323_remove() calls es8323_set_bias_level()
with SND_SOC_BIAS_OFF after its own clk_disable_unprepare(), which
disables the clock a second time. If the card is unbound before any
stream was played, that disable has no matching enable and the clk core
can warn "already disabled" and "already unprepared". After two or more
such cycles the clock stays enabled when the card is unbound.

Remove the clock calls from es8323_set_bias_level() and keep the pair
in es8323_probe() and es8323_remove(). The clock state while the card
is bound does not change, because the enable in es8323_probe() already
kept the clock on.

Fixes: b97391a604b9 ("ASoC: codecs: Add support for ES8323")
Fixes: 3c5ddd56aa93 ("ASoC: codecs: es8323: Enable proper DAPM widgets for chip power")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 sound/soc/codecs/es8323.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/sound/soc/codecs/es8323.c b/sound/soc/codecs/es8323.c
index 4cd9ddc48412..022d5c2cef57 100644
--- a/sound/soc/codecs/es8323.c
+++ b/sound/soc/codecs/es8323.c
@@ -686,17 +686,10 @@ static int es8323_probe(struct snd_soc_component *component)
 static int es8323_set_bias_level(struct snd_soc_component *component,
 				 enum snd_soc_bias_level level)
 {
-	struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component);
-	int ret;
-
 	switch (level) {
 	case SND_SOC_BIAS_ON:
 		break;
 	case SND_SOC_BIAS_PREPARE:
-		ret = clk_prepare_enable(es8323->mclk);
-		if (ret)
-			return ret;
-
 		snd_soc_component_write(component, ES8323_CHIPLOPOW1, 0x00);
 		snd_soc_component_write(component, ES8323_CHIPLOPOW2, 0x00);
 		snd_soc_component_update_bits(component, ES8323_ADCPOWER,
@@ -707,7 +700,6 @@ static int es8323_set_bias_level(struct snd_soc_component *component,
 	case SND_SOC_BIAS_OFF:
 		snd_soc_component_write(component, ES8323_CHIPLOPOW1, 0xff);
 		snd_soc_component_write(component, ES8323_CHIPLOPOW2, 0xff);
-		clk_disable_unprepare(es8323->mclk);
 		break;
 	}
 

-- 
Git-157)



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

* [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind
  2026-12-01 19:22 [PATCH 0/3] ASoC: codecs: Everest: fix clock and supply balance Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 1/3] ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level Arina Kharlamova via B4 Relay
@ 2026-12-01 19:22 ` Arina Kharlamova via B4 Relay
  2026-12-01 19:33   ` sashiko-bot
  2026-12-01 19:22 ` [PATCH 3/3] ASoC: codecs: ES8326: Keep mclk enabled while the device is bound Arina Kharlamova via B4 Relay
  2 siblings, 1 reply; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:22 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Binbin Zhou, Zhang Yi, David Yang
  Cc: linux-sound, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

es8375_read_device_properities() enables the vddd and vdda supplies and
only es8375_i2c_shutdown() disables them. The driver has no remove
callback, so the supplies are still enabled when the i2c device is
unbound or when devm_snd_soc_register_component() fails in probe. The
devres release of devm_regulator_bulk_get() then puts regulators that
are still enabled and hits the WARN_ON() in _regulator_put().

Add a devres action that disables the supplies. It is registered before
the component, so it runs after the component is unregistered and
before the regulators are put.

The mclk enable is not touched. es8375_set_bias_level() drops it on the
first transition to SND_SOC_BIAS_STANDBY after a card is bound, so a
disable on unbind would not be balanced.

Fixes: de2b3119f9f7 ("ASoC: codecs: add support for ES8375")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 sound/soc/codecs/es8375.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sound/soc/codecs/es8375.c b/sound/soc/codecs/es8375.c
index 7bb6c8d3a778..14361e5fcab5 100644
--- a/sound/soc/codecs/es8375.c
+++ b/sound/soc/codecs/es8375.c
@@ -662,6 +662,13 @@ static struct snd_soc_component_driver es8375_codec_driver = {
 	.suspend_bias_off = 1,
 };
 
+static void es8375_disable_supplies(void *data)
+{
+	struct es8375_priv *es8375 = data;
+
+	regulator_bulk_disable(ARRAY_SIZE(es8375_core_supplies), es8375->core_supply);
+}
+
 static int es8375_read_device_properities(struct device *dev, struct es8375_priv *es8375)
 {
 	int ret, i;
@@ -698,6 +705,12 @@ static int es8375_read_device_properities(struct device *dev, struct es8375_priv
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, es8375_disable_supplies, es8375);
+	if (ret) {
+		clk_disable_unprepare(es8375->mclk);
+		return ret;
+	}
+
 	return 0;
 }
 

-- 
Git-157)



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

* [PATCH 3/3] ASoC: codecs: ES8326: Keep mclk enabled while the device is bound
  2026-12-01 19:22 [PATCH 0/3] ASoC: codecs: Everest: fix clock and supply balance Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 1/3] ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level Arina Kharlamova via B4 Relay
  2026-12-01 19:22 ` [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind Arina Kharlamova via B4 Relay
@ 2026-12-01 19:22 ` Arina Kharlamova via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:22 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Binbin Zhou, Zhang Yi, David Yang
  Cc: linux-sound, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

es8326_i2c_probe() enables mclk, es8326_set_bias_level() enables it
again for SND_SOC_BIAS_ON and disables it for SND_SOC_BIAS_OFF, and
es8326_remove() forces SND_SOC_BIAS_OFF.

The bias level can go from OFF to STANDBY and back without reaching
ON: es8326_enable_micbias() forces the MICBIAS supplies for headset
button detection and from es8326_init() on resume. Each such cycle
disables the clock without a matching enable. The first one drops the
reference taken in probe, the next one makes the clk core warn
"already disabled" and "already unprepared". A second card bind and
unbind does the same.

Get the clock with devm_clk_get_optional_enabled() and remove the clock
calls from es8326_set_bias_level(), along with the SND_SOC_BIAS_OFF
call in es8326_remove() that only disabled the clock. In the common
case the clock already stayed on from probe; it is now held for as
long as the device is bound.

Fixes: 5c439937775d ("ASoC: codecs: add support for ES8326")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 sound/soc/codecs/es8326.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/sound/soc/codecs/es8326.c b/sound/soc/codecs/es8326.c
index 23e6f2c888ff..bf821835a446 100644
--- a/sound/soc/codecs/es8326.c
+++ b/sound/soc/codecs/es8326.c
@@ -795,14 +795,9 @@ static int es8326_set_bias_level(struct snd_soc_component *codec,
 				 enum snd_soc_bias_level level)
 {
 	struct es8326_priv *es8326 = snd_soc_component_get_drvdata(codec);
-	int ret;
 
 	switch (level) {
 	case SND_SOC_BIAS_ON:
-		ret = clk_prepare_enable(es8326->mclk);
-		if (ret)
-			return ret;
-
 		regmap_update_bits(es8326->regmap, ES8326_RESET, 0x02, 0x02);
 		usleep_range(5000, 10000);
 		regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk);
@@ -832,7 +827,6 @@ static int es8326_set_bias_level(struct snd_soc_component *codec,
 		regmap_update_bits(es8326->regmap, ES8326_CLK_MUX, 0x80, 0x80);
 		break;
 	case SND_SOC_BIAS_OFF:
-		clk_disable_unprepare(es8326->mclk);
 		break;
 	}
 
@@ -1401,7 +1395,6 @@ static void es8326_remove(struct snd_soc_component *component)
 	struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
 
 	es8326_disable_jack_detect(component);
-	es8326_set_bias_level(component, SND_SOC_BIAS_OFF);
 	regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01);
 	usleep_range(1000, 3000);
 	regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00);
@@ -1465,7 +1458,7 @@ static int es8326_i2c_probe(struct i2c_client *i2c)
 		es8326->irq = -ENXIO;
 	}
 
-	es8326->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+	es8326->mclk = devm_clk_get_optional_enabled(&i2c->dev, "mclk");
 	if (IS_ERR(es8326->mclk)) {
 		dev_err(&i2c->dev, "unable to get mclk\n");
 		return PTR_ERR(es8326->mclk);
@@ -1473,11 +1466,6 @@ static int es8326_i2c_probe(struct i2c_client *i2c)
 	if (!es8326->mclk)
 		dev_warn(&i2c->dev, "assuming static mclk\n");
 
-	ret = clk_prepare_enable(es8326->mclk);
-	if (ret) {
-		dev_err(&i2c->dev, "unable to enable mclk\n");
-		return ret;
-	}
 	return devm_snd_soc_register_component(&i2c->dev,
 					&soc_component_dev_es8326,
 					&es8326_dai, 1);

-- 
Git-157)



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

* Re: [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind
  2026-12-01 19:22 ` [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind Arina Kharlamova via B4 Relay
@ 2026-12-01 19:33   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-01 19:33 UTC (permalink / raw)
  To: Arina Kharlamova; +Cc: 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:
- [High] ASoC: codecs: es8375: unpowered I2C access in
  es8375_i2c_probe() [1]
--

commit bbbd18d6639b0c2567cfd29b9dd747544cbb0291
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

ASoC: codecs: es8375: Disable core supplies on unbind

This commit registers a devres action in es8375_read_device_properities()
to disable the codec's core regulators when the device is unbound or probe
fails.

> diff --git a/sound/soc/codecs/es8375.c b/sound/soc/codecs/es8375.c
> index 7bb6c8d3a7788..14361e5fcab5a 100644
> --- a/sound/soc/codecs/es8375.c
> +++ b/sound/soc/codecs/es8375.c
> @@ -662,6 +662,13 @@ static struct snd_soc_component_driver es8375_codec_driver = {
>  	.suspend_bias_off = 1,
>  };
>  
> +static void es8375_disable_supplies(void *data)
> +{
> +	struct es8375_priv *es8375 = data;
> +
> +	regulator_bulk_disable(ARRAY_SIZE(es8375_core_supplies), es8375->core_supply);
> +}
> +
>  static int es8375_read_device_properities(struct device *dev, struct es8375_priv *es8375)
>  {
>  	int ret, i;
> @@ -698,6 +705,12 @@ static int es8375_read_device_properities(struct device *dev, struct es8375_priv
>  		return ret;
>  	}
>  
> +	ret = devm_add_action_or_reset(dev, es8375_disable_supplies, es8375);
> +	if (ret) {
> +		clk_disable_unprepare(es8375->mclk);
> +		return ret;
> +	}
> +
>  	return 0;
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can the ES8375_CHIP_ID1
and ES8375_CHIP_ID0 reads in es8375_i2c_probe() succeed when the codec is
initially unpowered [1]?

es8375_i2c_probe() reads the chip ID registers before calling
es8375_read_device_properities(), which requests and enables core_supply
and mclk:

sound/soc/codecs/es8375.c:es8375_i2c_probe() {
    ...
	ret = regmap_read(es8375->regmap, ES8375_CHIP_ID1, &val);
	if (ret < 0) {
		dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n",
				i2c_client->addr);
		return ret;
	}
    ...
	ret = es8375_read_device_properities(dev, es8375);
    ...
}

When those supplies are off at probe time, the I2C reads fail and abort
probing before the regulators and clock are enabled.

[1] https://sashiko.dev/#/bug/linux-71adb255-1596-4ed2-a0f3-9cde51b1f16c

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-s2p-asoc-es-v1-0-a628a12e89ad@mbzuai.ac.ae?part=2

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

end of thread, other threads:[~2026-12-01 19:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:22 [PATCH 0/3] ASoC: codecs: Everest: fix clock and supply balance Arina Kharlamova via B4 Relay
2026-12-01 19:22 ` [PATCH 1/3] ASoC: codecs: es8323: Remove mclk calls from es8323_set_bias_level Arina Kharlamova via B4 Relay
2026-12-01 19:22 ` [PATCH 2/3] ASoC: codecs: es8375: Disable core supplies on unbind Arina Kharlamova via B4 Relay
2026-12-01 19:33   ` sashiko-bot
2026-12-01 19:22 ` [PATCH 3/3] ASoC: codecs: ES8326: Keep mclk enabled while the device is bound Arina Kharlamova via B4 Relay

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