Skip to contentSkip to conversation

ASoC: Add ESS ES9218P codec driver

PATCH Superseded Aidan MacDonald 2 participants 10 messages May 10, 2023 – May 11, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 2/3 dt-bindings: vendor-prefixes: Add ESS Technology vendor prefix

In reply to Aidan MacDonald

Add prefix "ess" for ESS Technology <https://www.esstech.com>.

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 82d39ab0231b..95c42e32e02e 100644
@@ -438,6 +438,8 @@ patternProperties:
     description: Seiko Epson Corp.
   "^esp,.*":
     description: Espressif Systems Co. Ltd.
+  "^ess,.*":
+    description: ESS Technology, Inc.
   "^est,.*":
     description: ESTeem Wireless Modems
   "^ettus,.*":
Signature · 1 line
2.39.2
#0 lore raw

PATCH 1/3 ASoC: Add ESS ES9218P codec driver

The ES9218P is a 32-bit stereo codec featuring an integrated headphone amp with analog volume control and up to 2.0 V rms output, and a low-power bypass path for passing through an analog signal from an alternate source.

The digital audio interface supports 16/24/32-bit I2S inputs ranging from 8 KHz to 384 KHz, and DSD inputs. This driver only supports I2S operation.

---
 sound/soc/codecs/Kconfig       |   6 +
 sound/soc/codecs/Makefile      |   2 +
 sound/soc/codecs/ess-es9218p.c | 785 +++++++++++++++++++++++++++++++++
 3 files changed, 793 insertions(+)
 create mode 100644 sound/soc/codecs/ess-es9218p.c
sound/soc/codecs/Kconfig +6 -0
index 8020097d4e4c..973ce164e1e5 100644
@@ -108,6 +108,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_ES8328_I2C
 	imply SND_SOC_ES7134
 	imply SND_SOC_ES7241
+	imply SND_SOC_ESS_ES9218P
 	imply SND_SOC_GTM601
 	imply SND_SOC_HDAC_HDMI
 	imply SND_SOC_HDAC_HDA
@@ -1017,6 +1018,11 @@ config SND_SOC_ES8328_SPI
 	depends on SPI_MASTER
 	select SND_SOC_ES8328
 
+config SND_SOC_ESS_ES9218P
+	tristate "ESS Technology ES9218P CODEC"
+	depends on I2C
+	select REGMAP_I2C
+
 config SND_SOC_GTM601
 	tristate 'GTM601 UMTS modem audio codec'
 
sound/soc/codecs/Makefile +2 -0
index 5cdbae88e6e3..1c119f1d9cb1 100644
@@ -114,6 +114,7 @@ snd-soc-es8326-objs := es8326.o
 snd-soc-es8328-objs := es8328.o
 snd-soc-es8328-i2c-objs := es8328-i2c.o
 snd-soc-es8328-spi-objs := es8328-spi.o
+snd-soc-ess-es9218p-objs := ess-es9218p.o
 snd-soc-gtm601-objs := gtm601.o
 snd-soc-hdac-hdmi-objs := hdac_hdmi.o
 snd-soc-hdac-hda-objs := hdac_hda.o
@@ -488,6 +489,7 @@ obj-$(CONFIG_SND_SOC_ES8326)    += snd-soc-es8326.o
 obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
+obj-$(CONFIG_SND_SOC_ESS_ES9218P)	+= snd-soc-ess-es9218p.o
 obj-$(CONFIG_SND_SOC_GTM601)    += snd-soc-gtm601.o
 obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o
 obj-$(CONFIG_SND_SOC_HDAC_HDA) += snd-soc-hdac-hda.o
sound/soc/codecs/ess-es9218p.c new file +785 -0

785 lines not on this page · raw message

Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/3 dt-bindings: ASoC: Add ESS ES9218P codec bindings

Device tree bindings for the ESS ES9218P codec, which uses an I2C control interface.

---
 .../bindings/sound/ess,es9218p.yaml           | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ess,es9218p.yaml
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +104 -0
new file mode 100644
index 000000000000..d205b6a8bbb2
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/ess,es9218p.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ESS ES9218P audio codec
+
+maintainers:
+  - Aidan MacDonald <[email protected]>
+
+properties:
+  compatible:
+    const: ess,es9218p
+
+  reg:
+    maxItems: 1
+
+  "#sound-dai-cells":
+    const: 0
+
+  avdd-supply:
+    description:
+      Definition of the regulator used for digital core power supply.
+
+  vcca-supply:
+    description:
+      Definition of the regulator used for oscillator and DAC power supply.
+
+  avcc3v3-supply:
+    description:
+      Definition of the 3.3V regulator for amplifier, switch, and charge pumps.
+
+  avcc1v8-supply:
+    description:
+      Definition of the 1.8V regulator for amplifier, switch, and charge pumps.
+
+  clocks:
+    items:
+      - description: clock for master clock (MCLK)
+
+  clock-names:
+    items:
+      - const: mclk
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      Pin used for codec hardware reset, corresponds to the RESETB pin.
+
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1
+
+  ess,oscillator-pad-bias:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Sets the oscillator pad drive bias. 0 - full bias, 15 - disabled.
+    minimum: 0
+    maximum: 15
+    default: 0
+
+required:
+  - compatible
+  - reg
+  - "#sound-dai-cells"
+  - avdd-supply
+  - vcca-supply
+  - avcc3v3-supply
+  - avcc1v8-supply
+  - clocks
+  - clock-names
+  - reset-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        codec@48 {
+            compatible = "ess,es9218p";
+            reg = <0x48>;
+            #sound-dai-cells = <0>;
+            avdd-supply = <&avdd>;
+            vcca-supply = <&vcca>;
+            avcc3v3-supply = <&avcc3v3>;
+            avcc1v8-supply = <&avcc1v8>;
+            clocks = <&xtal_clock>;
+            clock-names = "mclk";
+            reset-gpios = <&gpio 1 GPIO_ACTIVE_LOW>;
+        };
+    };
Signature · 1 line
2.39.2
#9 lore raw
In reply to Aidan MacDonald
Quoted 8 lines · Aidan MacDonald

The ES9218P is a 32-bit stereo codec featuring an integrated headphone amp with analog volume control and up to 2.0 V rms output, and a low-power bypass path for passing through an analog signal from an alternate source.

The digital audio interface supports 16/24/32-bit I2S inputs ranging from 8 KHz to 384 KHz, and DSD inputs. This driver only supports I2S operation.

...

Quoted 6 lines
sound/soc/codecs/ess-es9218p.c new file +6 -0
+static const struct of_device_id es9218p_of_match[] = {
+	{ .compatible = "ess,es9218p" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, es9218p_of_match);
+

sound/soc/codecs/ess-es9218p.c line 776

Quoted 10 lines
sound/soc/codecs/ess-es9218p.c new file +10 -0
+static const struct i2c_device_id es9218p_i2c_id[] = {
+	{ "ess-es9218p", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, es9218p_i2c_id);
+
+static struct i2c_driver es9218p_i2c_driver = {
+	.driver = {
+		.name = "ess-es9218p",
+		.of_match_table = of_match_ptr(es9218p_of_match),

Drop of_match_ptr or add __maybe_unused to the table.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v1 3/3] dt-bindings: ASoC: Add ESS ES9218P codec bindings

In reply to Aidan MacDonald
Quoted 3 lines · Aidan MacDonald

Device tree bindings for the ESS ES9218P codec, which uses an I2C control interface.

Thank you for your patch. There is something to discuss/improve.

Subject: reverse dt-bindings and ASoC.

Subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.

Quoted 13 lines
---
 .../bindings/sound/ess,es9218p.yaml           | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ess,es9218p.yaml
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +1 -0
new file mode 100644
index 000000000000..d205b6a8bbb2
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 11

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/ess,es9218p.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ESS ES9218P audio codec
+
+maintainers:
+  - Aidan MacDonald <[email protected]>
+

allOf with ref to dai-common.

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 24

Quoted 13 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +13 -0
+properties:
+  compatible:
+    const: ess,es9218p
+
+  reg:
+    maxItems: 1
+
+  "#sound-dai-cells":
+    const: 0
+
+  avdd-supply:
+    description:
+      Definition of the regulator used for digital core power supply.

Drop "Definition of the regulator used for"

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 29

Quoted 5 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +5 -0
+
+  vcca-supply:
+    description:
+      Definition of the regulator used for oscillator and DAC power supply.
+

Ditto

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 32

Quoted 3 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +3 -0
+  avcc3v3-supply:
+    description:
+      Definition of the 3.3V regulator for amplifier, switch, and charge pumps.

Drop "Definition of"

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +4 -0
+
+  avcc1v8-supply:
+    description:
+      Definition of the 1.8V regulator for amplifier, switch, and charge pumps.

Ditto

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 44

Quoted 8 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +8 -0
+
+  clocks:
+    items:
+      - description: clock for master clock (MCLK)
+
+  clock-names:
+    items:
+      - const: mclk

Drop entire names, not really useful.

Quoted 9 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +9 -0
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      Pin used for codec hardware reset, corresponds to the RESETB pin.
+
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1

Why do you need to customize it per board?

Quoted 11 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +11 -0
+
+  ess,oscillator-pad-bias:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Sets the oscillator pad drive bias. 0 - full bias, 15 - disabled.
+    minimum: 0
+    maximum: 15
+    default: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 84

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+  - "#sound-dai-cells"
+  - avdd-supply
+  - vcca-supply
+  - avcc3v3-supply
+  - avcc1v8-supply
+  - clocks
+  - clock-names
+  - reset-gpios
+
+additionalProperties: false

Instead: unevaluatedProperties: false

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 86

Quoted 2 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +2 -0
+
+examples:

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v1 3/3] dt-bindings: ASoC: Add ESS ES9218P codec bindings

Quoted 16 lines · Krzysztof Kozlowski
Quoted 4 lines · Aidan MacDonald

...

Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +3 -0
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1
Quoted 2 lines

Why do you need to customize it per board?

There's no generic API to read or change the bus speed (SCL frequency) for I2C adapters, so it's impossible to calculate a limit on the MCLK divider automatically.

Defaulting to 1 is always safe, but means wasting power at lower sample rates. If you know what the bus speed is you can use a higher divider limit to save power, and it has to be done at the board/firmware level because that's the only place where the bus speed is known.

Quoted 25 lines
Quoted 11 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +11 -0
+
+  ess,oscillator-pad-bias:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Sets the oscillator pad drive bias. 0 - full bias, 15 - disabled.
+    minimum: 0
+    maximum: 15
+    default: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 84

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+  - "#sound-dai-cells"
+  - avdd-supply
+  - vcca-supply
+  - avcc3v3-supply
+  - avcc1v8-supply
+  - clocks
+  - clock-names
+  - reset-gpios
+
+additionalProperties: false

Instead: unevaluatedProperties: false

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+examples:

Best regards,
Krzysztof

Everything else agreed, I'll send v2 later today.

Regards,
Aidan

#6 lore raw

Re: [PATCH v1 3/3] dt-bindings: ASoC: Add ESS ES9218P codec bindings

Quoted 22 lines · Aidan MacDonald
Quoted 16 lines · Krzysztof Kozlowski
Quoted 4 lines · Aidan MacDonald

...

Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +3 -0
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1
Quoted 2 lines

Why do you need to customize it per board?

Quoted 8 lines

There's no generic API to read or change the bus speed (SCL frequency) for I2C adapters, so it's impossible to calculate a limit on the MCLK divider automatically.

Defaulting to 1 is always safe, but means wasting power at lower sample rates. If you know what the bus speed is you can use a higher divider limit to save power, and it has to be done at the board/firmware level because that's the only place where the bus speed is known.

If I understand correctly, you only miss a way to get bus_freq_hz from i2c_timings to calculate the divider by yourself? This looks like Linux limitation, so we shouldn't push it into DT, but rather fix Linux. The I2C bus rate is known, the MCLK rate as well, so divider is possible to deduce.

I am actually surprised that I2C core does not store the timings anywhere and each bus host has to deal with it on its own.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v1 3/3] dt-bindings: ASoC: Add ESS ES9218P codec bindings

Quoted 38 lines · Krzysztof Kozlowski
Quoted 22 lines · Aidan MacDonald
Quoted 16 lines · Krzysztof Kozlowski
Quoted 4 lines · Aidan MacDonald

...

Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +3 -0
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1
Quoted 2 lines

Why do you need to customize it per board?

Quoted 8 lines

There's no generic API to read or change the bus speed (SCL frequency) for I2C adapters, so it's impossible to calculate a limit on the MCLK divider automatically.

Defaulting to 1 is always safe, but means wasting power at lower sample rates. If you know what the bus speed is you can use a higher divider limit to save power, and it has to be done at the board/firmware level because that's the only place where the bus speed is known.

If I understand correctly, you only miss a way to get bus_freq_hz from i2c_timings to calculate the divider by yourself? This looks like Linux limitation, so we shouldn't push it into DT, but rather fix Linux. The I2C bus rate is known, the MCLK rate as well, so divider is possible to deduce.

Quoted 5 lines

I am actually surprised that I2C core does not store the timings anywhere and each bus host has to deal with it on its own.

Best regards,
Krzysztof

I agree it'd be better if Linux provided access the bus frequency, but even if that API was added it will take time for every I2C adapter to support it. So in that case we would still need a DT property to provide a safe limit or use a safe default, and miss potential power savings.

I'd prefer to add the DT property to allow power savings to be had now, and drop it if/when the kernel gets an API for bus frequency. That will be safe from a compatibility point of view -- the property won't be providing any useful information so it won't matter if old DTs have it.

Regards,
Aidan

#8 lore raw

Re: [PATCH v1 3/3] dt-bindings: ASoC: Add ESS ES9218P codec bindings

Quoted 52 lines · Aidan MacDonald
Quoted 38 lines · Krzysztof Kozlowski
Quoted 22 lines · Aidan MacDonald
Quoted 16 lines · Krzysztof Kozlowski
Quoted 4 lines · Aidan MacDonald

...

Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +3 -0
+  ess,max-clock-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:

Documentation/devicetree/bindings/sound/ess,es9218p.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/ess,es9218p.yaml new file +10 -0
+      Sets the maximum MCLK divider for generating the internal CLK.
+      CLK must be at least 20x the I2C bus speed or I2C transactions
+      will fail. The maximum divider should be chosen to ensure that
+      CLK will not fall below the limit.
+    enum:
+      - 1
+      - 2
+      - 4
+      - 8
+    default: 1
Quoted 2 lines

Why do you need to customize it per board?

Quoted 8 lines

There's no generic API to read or change the bus speed (SCL frequency) for I2C adapters, so it's impossible to calculate a limit on the MCLK divider automatically.

Defaulting to 1 is always safe, but means wasting power at lower sample rates. If you know what the bus speed is you can use a higher divider limit to save power, and it has to be done at the board/firmware level because that's the only place where the bus speed is known.

If I understand correctly, you only miss a way to get bus_freq_hz from i2c_timings to calculate the divider by yourself? This looks like Linux limitation, so we shouldn't push it into DT, but rather fix Linux. The I2C bus rate is known, the MCLK rate as well, so divider is possible to deduce.

Quoted 5 lines

I am actually surprised that I2C core does not store the timings anywhere and each bus host has to deal with it on its own.

Best regards,
Krzysztof

I agree it'd be better if Linux provided access the bus frequency, but even if that API was added it will take time for every I2C adapter to support it. So in that case we would still need a DT property to provide a safe limit or use a safe default, and miss potential power savings.

Quoted 4 lines

I'd prefer to add the DT property to allow power savings to be had now, and drop it if/when the kernel gets an API for bus frequency. That will be safe from a compatibility point of view -- the property won't be providing any useful information so it won't matter if old DTs have it.

OK, sounds good.

Best regards,
Krzysztof