Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ASoC: es8316: Add regulator support
@ 2026-08-12  9:35 Hongyang Zhao
  2026-08-12  9:35 ` [PATCH v2 1/2] ASoC: dt-bindings: es8316: Add regulator supplies Hongyang Zhao
  2026-08-12  9:35 ` [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support Hongyang Zhao
  0 siblings, 2 replies; 4+ messages in thread
From: Hongyang Zhao @ 2026-08-12  9:35 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Daniel Drake, Katsuhiro Suzuki, Matteo Martelli,
	Binbin Zhou, Jaroslav Kysela, Takashi Iwai
  Cc: Konrad Dybcio, Roger Shimizu, linux-sound, devicetree,
	linux-kernel, Hongyang Zhao

Add regulator support for the four ES8316 power domains so board
descriptions can model and control the codec supplies.

The binding patch documents AVDD, CPVDD, DVDD and PVDD as optional
supplies for ES8316, preserving compatibility with existing device-tree
descriptions. The driver patch enables the supplies before initializing
the regmap and keeps them enabled for the lifetime of the I2C device.

The missing supply model was identified while reviewing the RubikPi 3
audio support:
https://lore.kernel.org/linux-arm-msm/c293d9c7-bdb7-4303-80c8-404228c434d7@oss.qualcomm.com/

Signed-off-by: Hongyang Zhao <hongyang.zhao@thundersoft.com>
---
Changes in v2:
- Restrict the supply properties to the ES8316 compatible.
- Enable the regulators before regmap initialization and keep them enabled
  for the lifetime of the I2C device.
- Link to v1: https://lore.kernel.org/r/20260723-es8316-regulator-next-20260722-v1-0-721f757879a0@thundersoft.com

---
Hongyang Zhao (2):
      ASoC: dt-bindings: es8316: Add regulator supplies
      ASoC: codecs: es8316: Add regulator support

 .../devicetree/bindings/sound/everest,es8316.yaml  | 27 ++++++++++++++++++++++
 sound/soc/codecs/es8316.c                          | 13 +++++++++++
 2 files changed, 40 insertions(+)
---
base-commit: 5e6de6a2b522f659defacb1551d0465ba6ce13cf
change-id: 20260723-es8316-regulator-next-20260722-7d96badfd4da

Best regards,
-- 
Hongyang Zhao <hongyang.zhao@thundersoft.com>


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

* [PATCH v2 1/2] ASoC: dt-bindings: es8316: Add regulator supplies
  2026-08-12  9:35 [PATCH v2 0/2] ASoC: es8316: Add regulator support Hongyang Zhao
@ 2026-08-12  9:35 ` Hongyang Zhao
  2026-08-12  9:35 ` [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support Hongyang Zhao
  1 sibling, 0 replies; 4+ messages in thread
From: Hongyang Zhao @ 2026-08-12  9:35 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Daniel Drake, Katsuhiro Suzuki, Matteo Martelli,
	Binbin Zhou, Jaroslav Kysela, Takashi Iwai
  Cc: Konrad Dybcio, Roger Shimizu, linux-sound, devicetree,
	linux-kernel, Hongyang Zhao

The ES8316 has separate AVDD, CPVDD, DVDD and PVDD supply inputs for
its analog, charge pump, digital core and digital I/O domains. Describe
all four inputs so boards can model the codec power topology.

The binding also covers ES8311 and ES8323, whose supply inputs differ,
so restrict these properties to the ES8316 compatible. Keep them
optional for compatibility with existing descriptions.

Signed-off-by: Hongyang Zhao <hongyang.zhao@thundersoft.com>
---
 .../devicetree/bindings/sound/everest,es8316.yaml  | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/everest,es8316.yaml b/Documentation/devicetree/bindings/sound/everest,es8316.yaml
index fe5d938ca310..276c73bb4790 100644
--- a/Documentation/devicetree/bindings/sound/everest,es8316.yaml
+++ b/Documentation/devicetree/bindings/sound/everest,es8316.yaml
@@ -30,6 +30,17 @@ description: |
 
 allOf:
   - $ref: dai-common.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: everest,es8316
+    else:
+      properties:
+        avdd-supply: false
+        cpvdd-supply: false
+        dvdd-supply: false
+        pvdd-supply: false
 
 properties:
   compatible:
@@ -49,6 +60,18 @@ properties:
     items:
       - const: mclk
 
+  avdd-supply:
+    description: Regulator providing the analog supply, from 2.0 V to 3.6 V
+
+  cpvdd-supply:
+    description: Regulator providing the charge pump supply, from 1.6 V to 2.0 V
+
+  dvdd-supply:
+    description: Regulator providing the digital core supply, from 1.6 V to 3.6 V
+
+  pvdd-supply:
+    description: Regulator providing the digital I/O supply, from 1.6 V to 3.6 V
+
   interrupts:
     maxItems: 1
     description: Headphone detect interrupt
@@ -77,6 +100,10 @@ examples:
         reg = <0x11>;
         clocks = <&clks 10>;
         clock-names = "mclk";
+        avdd-supply = <&reg_3p3v>;
+        cpvdd-supply = <&reg_1p8v>;
+        dvdd-supply = <&reg_1p8v>;
+        pvdd-supply = <&reg_1p8v>;
         #sound-dai-cells = <0>;
       };
     };

-- 
2.43.0


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

* [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support
  2026-08-12  9:35 [PATCH v2 0/2] ASoC: es8316: Add regulator support Hongyang Zhao
  2026-08-12  9:35 ` [PATCH v2 1/2] ASoC: dt-bindings: es8316: Add regulator supplies Hongyang Zhao
@ 2026-08-12  9:35 ` Hongyang Zhao
  2026-08-12  9:57   ` sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: Hongyang Zhao @ 2026-08-12  9:35 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Daniel Drake, Katsuhiro Suzuki, Matteo Martelli,
	Binbin Zhou, Jaroslav Kysela, Takashi Iwai
  Cc: Konrad Dybcio, Roger Shimizu, linux-sound, devicetree,
	linux-kernel, Hongyang Zhao

ES8316 has separate AVDD, CPVDD, DVDD and PVDD supply inputs.

Request and enable the supplies during I2C probe, before initializing
the regmap. Keep them enabled for the lifetime of the I2C device so the
regmap cannot access an unpowered device and its cache remains
synchronized if the ASoC component is unbound and rebound.

Signed-off-by: Hongyang Zhao <hongyang.zhao@thundersoft.com>
---
 sound/soc/codecs/es8316.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 87f331868dc7..24ec8b211cdb 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -15,6 +15,7 @@
 #include <linux/i2c.h>
 #include <linux/mutex.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
@@ -31,6 +32,13 @@ static const unsigned int supported_mclk_lrck_ratios[] = {
 	256, 384, 400, 500, 512, 768, 1024
 };
 
+static const char * const es8316_supply_names[] = {
+	"avdd",
+	"cpvdd",
+	"dvdd",
+	"pvdd",
+};
+
 struct es8316_priv {
 	struct mutex lock;
 	struct clk *mclk;
@@ -866,6 +874,11 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client)
 
 	i2c_set_clientdata(i2c_client, es8316);
 
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(es8316_supply_names),
+					     es8316_supply_names);
+	if (ret)
+		return dev_err_probe(dev, ret, "unable to enable supplies\n");
+
 	es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
 	if (IS_ERR(es8316->regmap))
 		return PTR_ERR(es8316->regmap);

-- 
2.43.0


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

* Re: [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support
  2026-08-12  9:35 ` [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support Hongyang Zhao
@ 2026-08-12  9:57   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-08-12  9:57 UTC (permalink / raw)
  To: Hongyang Zhao; +Cc: conor+dt, robh, devicetree

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Medium] Potential I2C communication failure due to missing stabilization delay after enabling regulators.

Pre-existing issues:
- [Critical] Use-After-Free of snd_soc_component in the IRQ handler due to devres teardown order.
- [High] Regmap cache desynchronization due to pre-existing hardware reset defeating the patch's premise.
--

--- Patch [2]: [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support ---
commit 3daba0da576ac350b6f022776265341a98e4d7f5
Author: Hongyang Zhao <hongyang.zhao@thundersoft.com>

ASoC: codecs: es8316: Add regulator support
    
ES8316 has separate AVDD, CPVDD, DVDD and PVDD supply inputs.

> Request and enable the supplies during I2C probe, before initializing
> the regmap. Keep them enabled for the lifetime of the I2C device so the
> regmap cannot access an unpowered device and its cache remains
> synchronized if the ASoC component is unbound and rebound.

[Severity: High]
This isn't a bug introduced by this patch, but does the pre-existing hardware
reset in es8316_probe() defeat the premise of keeping the regmap synchronized?

When the component is unbound and rebound, es8316_probe() executes:

sound/soc/codecs/es8316.c:es8316_probe() {
    ...
    snd_soc_component_write(component, ES8316_RESET, 0x3f);
    ...
}

This wipes the physical chip state without marking the regcache dirty.
Consequently, subsequent ALSA control writes matching the stale cache might be
dropped, leading to silent audio or incorrect settings.

> Signed-off-by: Hongyang Zhao <hongyang.zhao@thundersoft.com>

> diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
> index 87f331868dc7f..24ec8b211cdba 100644
> --- a/sound/soc/codecs/es8316.c
> +++ b/sound/soc/codecs/es8316.c
[ ... ]
> @@ -866,6 +874,11 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client)
>  
>  	i2c_set_clientdata(i2c_client, es8316);
>  
> +	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(es8316_supply_names),
> +					     es8316_supply_names);

[Severity: Medium]
Will this lack of stabilization delay cause I2C communication failures?

If the ES8316 requires a delay after power is applied before its I2C state
machine is ready, the first I2C write during the component probe could
receive a NACK. Might it be safer to add a small post-power-on delay here?

> +	if (ret)
> +		return dev_err_probe(dev, ret, "unable to enable supplies\n");
> +

[Severity: Critical]
This is a pre-existing issue, but is there a use-after-free risk during
devres teardown?

During module removal or I2C device unbind, devres tears down resources in
reverse order of allocation. The IRQ is requested later in this function
before the component memory is allocated via devres.

If the hardware asserts the IRQ in the narrow window after the component
is freed but before the IRQ is disabled and freed, es8316_irq() will
dereference the freed component pointer:

sound/soc/codecs/es8316.c:es8316_irq() {
    ...
    dev_dbg(comp->dev, "gpio flags %#04x\n", flags);
    ...
}

Can this lead to memory corruption if the handler executes late?

>  	es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
>  	if (IS_ERR(es8316->regmap))
>  		return PTR_ERR(es8316->regmap);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812-es8316-regulator-next-20260722-v2-0-e7078bc9bc9c@thundersoft.com?part=2

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

end of thread, other threads:[~2026-08-12  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12  9:35 [PATCH v2 0/2] ASoC: es8316: Add regulator support Hongyang Zhao
2026-08-12  9:35 ` [PATCH v2 1/2] ASoC: dt-bindings: es8316: Add regulator supplies Hongyang Zhao
2026-08-12  9:35 ` [PATCH v2 2/2] ASoC: codecs: es8316: Add regulator support Hongyang Zhao
2026-08-12  9:57   ` sashiko-bot

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