Skip to contentSkip to conversation

ASoC: codecs: Add Everest ES7202 support

PATCH Superseded Jun Yan 3 participants 6 messages Oct 21 – Oct 31

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jun Yan

author
#0 lore raw

v2 cover ASoC: codecs: Add Everest ES7202 support

This series adds support for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C. Patch 1 adds the DT bindings and patch 2 the ASoC codec driver.

The driver is based on the Rockchip BSP driver, reworked for mainline to use regmap and devm_ helpers, probe the device ID, and report the actual per-step PGA gain.

Changes in v2:
- Drop the hard-coded 30.75 dB PGA gain from the power-up sequence; the PGA keeps its power-on default and the capture volume controls apply the requested gain.
- Keep the PDM outputs muted until a capture stream starts, instead of unmuting at the end of the init sequence.
- Re-run the power-up sequence on resume before syncing the regmap cache.
- Handle the regulator_get_voltage() error return as an int.
- Drop the unnecessary of_match_ptr().
- Fix the copyright header.

Link to v1: https://lore.kernel.org/linux-sound/[email protected]

Jun Yan (2):
dt-bindings: sound: add Everest ES7202
ASoC: codecs: add support for Everest ES7202 PDM ADC

 .../bindings/sound/everest,es7202.yaml        |  56 +++
 sound/soc/codecs/Kconfig                      |  10 +
 sound/soc/codecs/Makefile                     |   2 +
 sound/soc/codecs/es7202.c                     | 367 ++++++++++++++++++
 sound/soc/codecs/es7202.h                     | 131 +++++++
 5 files changed, 566 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es7202.yaml
 create mode 100644 sound/soc/codecs/es7202.c
 create mode 100644 sound/soc/codecs/es7202.h
Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v2 1/2 dt-bindings: sound: add Everest ES7202

Add the device-tree bindings for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C.

---
 .../bindings/sound/everest,es7202.yaml        | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es7202.yaml
Documentation/devicetree/bindings/sound/everest,es7202.yaml new file +56 -0
new file mode 100644
index 000000000000..ce98d2d600d4
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/everest,es7202.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Everest ES7202 2 channel PDM analog to digital converter
+
+maintainers:
+  - Jun Yan <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - everest,es7202
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description: GPIO connected to the reset pin (active low)
+
+  vdd-supply:
+    description: Main power supply, 1.8 V or 3.3 V. Optional; defaults to 3.3 V
+
+  "#sound-dai-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - "#sound-dai-cells"
+
+allOf:
+  - $ref: dai-common.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        es7202: codec@30 {
+            compatible = "everest,es7202";
+            reg = <0x30>;
+            #sound-dai-cells = <0>;
+            reset-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
+            vdd-supply = <&vcc3v3_sys>;
+        };
+    };
+...
Signature · 1 line
2.56.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: sound: add Everest ES7202

Quoted 9 lines · Jun Yan

Add the device-tree bindings for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C.

---
 .../bindings/sound/everest,es7202.yaml        | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es7202.yaml
author
#3 lore raw

PATCH v2 2/2 ASoC: codecs: add support for Everest ES7202 PDM ADC

In reply to Jun Yan

Add support for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C. The device outputs PDM data to the SoC PDM controller and is configured through registers for supply voltage, analog front-end and per-channel PGA gain.

Based on the Rockchip BSP driver[1] by Binyuan Lan <[email protected]> (committed by Tao Huang <[email protected]>), originally written by David Yang <[email protected]>.

[1] https://github.com/rockchip-linux/kernel/blob/develop-6.1/sound/soc/codecs/es7202.c

---
 sound/soc/codecs/Kconfig  |  10 ++
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/es7202.c | 367 ++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/es7202.h | 131 ++++++++++++++
 4 files changed, 510 insertions(+)
 create mode 100644 sound/soc/codecs/es7202.c
 create mode 100644 sound/soc/codecs/es7202.h
sound/soc/codecs/Kconfig +10 -0
index ba59dabeeccd..c1eeebd12cf0 100644
@@ -1274,6 +1274,16 @@ config SND_SOC_HDMI_CODEC
 config SND_SOC_ES7134
 	tristate "Everest Semi ES7134 CODEC"
 
+config SND_SOC_ES7202
+	tristate "Everest Semi ES7202 CODEC"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Enable support for the Everest Semiconductor ES7202, a 2-channel
+	  PDM analog-to-digital converter controlled over I2C. The device
+	  outputs PDM data to a SoC PDM controller and is configured through
+	  registers for supply voltage, analog front-end and PGA gain.
+
 config SND_SOC_ES7241
 	tristate "Everest Semi ES7241 CODEC"
 
sound/soc/codecs/Makefile +2 -0
index 3826f9e4fce8..2a56fad9073a 100644
@@ -129,6 +129,7 @@ snd-soc-da732x-y := da732x.o
 snd-soc-da9055-y := da9055.o
 snd-soc-dmic-y := dmic.o
 snd-soc-es7134-y := es7134.o
+snd-soc-es7202-y := es7202.o
 snd-soc-es7241-y := es7241.o
 snd-soc-es83xx-dsm-common-y := es83xx-dsm-common.o
 snd-soc-es8311-y := es8311.o
@@ -577,6 +578,7 @@ obj-$(CONFIG_SND_SOC_DA732X)	+= snd-soc-da732x.o
 obj-$(CONFIG_SND_SOC_DA9055)	+= snd-soc-da9055.o
 obj-$(CONFIG_SND_SOC_DMIC)	+= snd-soc-dmic.o
 obj-$(CONFIG_SND_SOC_ES7134)	+= snd-soc-es7134.o
+obj-$(CONFIG_SND_SOC_ES7202)	+= snd-soc-es7202.o
 obj-$(CONFIG_SND_SOC_ES7241)	+= snd-soc-es7241.o
 obj-$(CONFIG_SND_SOC_ES83XX_DSM_COMMON)    += snd-soc-es83xx-dsm-common.o
 obj-$(CONFIG_SND_SOC_ES8311)    += snd-soc-es8311.o
sound/soc/codecs/es7202.c new file +367 -0

367 lines not on this page · raw message

sound/soc/codecs/es7202.h new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.56.0
maintainer
#4 lore raw

Re: [PATCH v2 2/2] ASoC: codecs: add support for Everest ES7202 PDM ADC

Quoted 4 lines

Add support for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C. The device outputs PDM data to the SoC PDM controller and is configured through registers for supply voltage, analog front-end and per-channel PGA gain.

This looks pretty good, a few relatively minor issues below but nothing major.

sound/soc/codecs/Kconfig config SND_SOC_HDMI_CODEC · line 1280

Quoted 10 lines
sound/soc/codecs/Kconfig +4 -0
@@ -1274,6 +1274,16 @@ config SND_SOC_HDMI_CODEC
 config SND_SOC_ES7134
 	tristate "Everest Semi ES7134 CODEC"
 
+config SND_SOC_ES7202
+	tristate "Everest Semi ES7202 CODEC"
+	depends on I2C
+	select REGMAP_I2C

You should also add this to SND_SOC_ALL_CODECS.

sound/soc/codecs/es7202.c line 5

Quoted 8 lines
sound/soc/codecs/es7202.c new file +5 -0
@@ -0,0 +1,367 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 Everest Semiconductor Co Ltd.,
+ * Copyright (C) 2026 Jun Yan <[email protected]>
+ */

Please make the whole comment block C++ so things look more intentional.

sound/soc/codecs/es7202.c line 17

Quoted 11 lines
sound/soc/codecs/es7202.c new file +11 -0
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>

linux/of.h and sound/pcm_params.h aren't needed I think.

sound/soc/codecs/es7202.c line 43

Quoted 7 lines
sound/soc/codecs/es7202.c new file +7 -0
+static bool es7202_volatile_reg(struct device *dev, unsigned int reg)
+{
+	/* status and device-id registers are read-only, never cached */
+	return reg == ES7202_CHIP_STA ||
+	       reg == ES7202_DEV_ID1 ||
+	       reg == ES7202_DEV_ID0;
+}

A switch statement would be neater and would probably generate equivalent code. Are you sure that the ID registers are actually volatile, that's quite unusual? If they've volatile the hardware is accessed on each read, if you just omit the default then they will be cached after the first read.

Also should the rest register be uncached so we don't try to write it back out as part of a cache sync by mistake?

sound/soc/codecs/es7202.c line 78

Quoted 8 lines
sound/soc/codecs/es7202.c new file +8 -0
+static const struct regmap_config es7202_regmap = {
+	.reg_bits	= 8,
+	.val_bits	= 8,
+	.max_register	= ES7202_DEV_ID0,
+	.reg_defaults	= es7202_reg_defaults,
+	.num_reg_defaults = ARRAY_SIZE(es7202_reg_defaults),
+	.volatile_reg	= es7202_volatile_reg,
+	.cache_type	= REGCACHE_MAPLE,

I notice that other Everest devices set use_single_read and use_single_write - especially for write we can easily trigger multi-register write as part of a regcache sync so if the device lacks support it'll create bugs.

sound/soc/codecs/es7202.c line 274

Quoted 2 lines
sound/soc/codecs/es7202.c new file +2 -0
+	es7202->supply = devm_regulator_get_optional(dev, "vdd");
+	if (IS_ERR(es7202->supply)) {

Unless the device can operate without power this should be a normal regulator_get(), the core will substitude a dummy regulator if it's not configurd by the firmware.

Signature · 1 line
Mark Brown <[email protected]>
author
#5 lore raw

Re: [PATCH v2 2/2] ASoC: codecs: add support for Everest ES7202 PDM ADC

Hi,

Thanks for your review.

Quoted 14 lines
Quoted 4 lines

Add support for the Everest ES7202, a 2-channel PDM analog-to-digital converter controlled over I2C. The device outputs PDM data to the SoC PDM controller and is configured through registers for supply voltage, analog front-end and per-channel PGA gain.

This looks pretty good, a few relatively minor issues below but nothing major.

Quoted 6 lines
sound/soc/codecs/Kconfig +0 -0
@@ -1274,6 +1274,16 @@ config SND_SOC_HDMI_CODEC
 config SND_SOC_ES7134
 	tristate "Everest Semi ES7134 CODEC"
 
Quoted 6 lines

sound/soc/codecs/Kconfig config SND_SOC_HDMI_CODEC · line 1280

Quoted 4 lines
sound/soc/codecs/Kconfig +4 -0
+config SND_SOC_ES7202
+	tristate "Everest Semi ES7202 CODEC"
+	depends on I2C
+	select REGMAP_I2C

You should also add this to SND_SOC_ALL_CODECS.

Added.

Quoted 11 lines

sound/soc/codecs/es7202.c line 5

Quoted 9 lines
sound/soc/codecs/es7202.c new file +5 -0
@@ -0,0 +1,367 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 Everest Semiconductor Co Ltd.,
+ * Copyright (C) 2026 Jun Yan <[email protected]>
+ */

Please make the whole comment block C++ so things look more intentional.

Done.

Quoted 15 lines

sound/soc/codecs/es7202.c line 17

Quoted 12 lines
sound/soc/codecs/es7202.c new file +11 -0
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>

linux/of.h and sound/pcm_params.h aren't needed I think.

Right, both removed.

Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/es7202.c new file +5 -0
+static bool es7202_volatile_reg(struct device *dev, unsigned int reg)
+{
+	/* status and device-id registers are read-only, never cached */
+	return reg == ES7202_CHIP_STA ||
+	       reg == ES7202_DEV_ID1 ||
Quoted 9 lines

sound/soc/codecs/es7202.c line 43

Quoted 2 lines
sound/soc/codecs/es7202.c new file +2 -0
+	       reg == ES7202_DEV_ID0;
+}

A switch statement would be neater and would probably generate equivalent code. Are you sure that the ID registers are actually volatile, that's quite unusual? If they've volatile the hardware is accessed on each read, if you just omit the default then they will be cached after the first read.

Thanks for catching this. The ID registers are static and don't need volatile marking. I'll drop them from es7202_volatile_reg() and use .writeable_reg to make them read-only, so they are still cached after the first read but skipped by regcache_sync().

Quoted 3 lines

Also should the rest register be uncached so we don't try to write it back out as part of a cache sync by mistake?

Agreed, I missed this. I'll mark ES7202_RESET volatile so it can't be written back during a cache sync.

Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/es7202.c new file +5 -0
+static const struct regmap_config es7202_regmap = {
+	.reg_bits	= 8,
+	.val_bits	= 8,
+	.max_register	= ES7202_DEV_ID0,
+	.reg_defaults	= es7202_reg_defaults,
Quoted 9 lines

sound/soc/codecs/es7202.c line 78

Quoted 3 lines
sound/soc/codecs/es7202.c new file +3 -0
+	.num_reg_defaults = ARRAY_SIZE(es7202_reg_defaults),
+	.volatile_reg	= es7202_volatile_reg,
+	.cache_type	= REGCACHE_MAPLE,

I notice that other Everest devices set use_single_read and use_single_write - especially for write we can easily trigger multi-register write as part of a regcache sync so if the device lacks support it'll create bugs.

Thanks. The other Everest codecs are the only precedent here - the ES7202 datasheet does not document multi-register (auto-increment) writes, so I cannot rely on them. I'll set use_single_read and use_single_write so a regcache sync can never turn into a burst write.

Quoted 7 lines

sound/soc/codecs/es7202.c line 274

Quoted 2 lines
sound/soc/codecs/es7202.c new file +2 -0
+	es7202->supply = devm_regulator_get_optional(dev, "vdd");
+	if (IS_ERR(es7202->supply)) {

Unless the device can operate without power this should be a normal regulator_get(), the core will substitude a dummy regulator if it's not configurd by the firmware.

Right, VDD supply is required. I'll use devm_regulator_get() instead.

I'll send a v3 with these changes.

Quoted 2 lines
Signature · 1 line
Mark Brown <[email protected]>