Skip to contentSkip to conversation

ASoC: add ESS Technology ES9039Q2M codec driver

PATCH In review Karl Asseily 3 participants 8 messages Sep 18 – Sep 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover ASoC: add ESS Technology ES9039Q2M codec driver

This series adds support for the ESS Technology ES9039Q2M, a 32-bit two-channel audio DAC with an asynchronous sample rate converter, controlled over I2C. The part also has a hardware mode strapped by HW0/HW1/HW2 with no control bus at all; this driver implements the software mode that MODE = GND selects.

Two things about the part shape the driver:

- Selecting an input format takes two registers, not one. INPUT_SEL chooses the port; SYS MODE CONFIG enables the matching decoder, and at reset only ENABLE_TDM_DECODE is set. Selecting DoP without also enabling ENABLE_DOP_DECODE leaves the part hunting for a marker with the marker decoder switched off, so it finds nothing and mutes. The driver writes both.

- Several registers have non-zero reserved defaults - register 88 reads 0xb8 at reset - so every write is read-modify-write.

The programmable FIR coefficient controls are write-only by design. PROG_COEFF_OUT is documented as a coefficient readback but is not a RAM read port: it returns the last coefficient written, whatever address is selected in PROG_COEFF_ADDR. Measured with the driver out of the path, five sequences, ten reads, all returning the same value. A get() built on that register would return something with the shape of data and none of its meaning, so there is none.

Every control has been verified against the silicon rather than against the driver's own read-back - written through ALSA, then read over raw I2C
- and DSD, DoP and S/PDIF input are all implemented and tested on hardware.

ESS Technology has no bindings in the tree today, so the series also adds the vendor prefix, taken from the company's domain esstech.com.

Link to v1: https://lore.kernel.org/r/[email protected]
Link to v2: https://lore.kernel.org/r/[email protected]
Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v4:

- Describe the part's four supply inputs in the binding, and require them. Rob Herring and the sashiko reviewer both raised this on v3. AVDD, VCCA, AVCC_DAC1 and AVCC_DAC2 are all nominally 3.3 V. DVDD deliberately gets no property: the part's 1.2 V digital rail is generated on chip and that pin wants a decoupling capacitor, not a regulator. As sashiko noted, adding required supplies after the fact would break device trees written against the first schema, so they go in now.

- The driver gets those supplies and enables them in the order the datasheet gives - figure 22: AVDD, VCCA about 200 us later, then the two output-stage references, reversed on the way down. They are enabled one at a time rather than with regulator_bulk_enable(), which makes no ordering guarantee; the bulk API is still used to get them, where order does not matter. The datasheet states no settling time between the last supply and the first register access, so none is invented.

- Resume re-uploads the programmable FIR coefficient RAM. Mark Brown asked on v3 how the coefficient upload survives a suspend that powers the part down, and it did not. The RAM is write-only - PROG_COEFF_OUT returns the last coefficient written rather than the addressed one, as patch 3 describes - so regmap cannot cache it and nothing else in the system holds a copy. A board that keeps the part powered loses nothing, but one that removes the supplies came back with the RAM undefined while regcache_sync() had just restored the filter selection from the cache, which would point the interpolator at whatever the RAM powered up holding. The driver now keeps a shadow of the last upload for each stage and replays it after the sync. Stages never written have no shadow and keep the part's own defaults.

- Serialise the coefficient upload. Splitting the upload loop into a helper for the above made it visible that both FIR controls drive the same address, data and write-enable registers with nothing ordering them, so two concurrent uploads could interleave into each other's RAM. The upload now runs under the driver mutex, which orders the two controls against each other and against resume. The write-enable stays a per-coefficient strobe, which is the sequence the datasheet gives.

- The multi-register controls read the whole field, modified it and wrote it back. ES9039_AUTOMUTE_TIME spans registers 124-125 while MUTE_RAMP_TO_GND is bit 3 of register 125 and has a control of its own, and the ALSA put path holds card->controls_rwsem for read, so two controls really can run at once and a change to that neighbouring bit could be lost between the read and the write-back. Each register is now updated through regmap_update_bits(), inside regmap's own lock and touching no bit outside the field's mask.

- The volume control raises VOLUME_HOLD, lets the generic handler write both channels and drops it again, but took no lock. Two callers interleaving would let the second write its volumes after the first had already dropped the hold, which is the torn stereo update the bit exists to prevent. It now holds the driver mutex across the sequence.

- Collect Krzysztof Kozlowski's Acked-by on patch 1 and Reviewed-by on patch 2, both given on v2 and both missing from v3 through my error. Note that patch 2 has changed since he read it - the supplies above - so the Reviewed-by is carried rather than re-earned.

Changes in v3:

- Fix the MCLK selection introduced in v2. hw_params() called clk_set_rate() for 256 * FS unconditionally, which is above the part's 50 MHz MCLK maximum for any rate over 192 kHz, and the rate the clock settled on was never re-checked against that ceiling. The ratio is now taken from the highest that fits.

- Decide 64FS mode from the MCLK/FS ratio in use rather than from a rate threshold. The 128 * FS floor was applied even in 64FS mode, where the datasheet asks for 64 * FS, so the 768 kHz this driver advertises in SNDRV_PCM_RATE_8000_768000 could never be reached - 128 * 768000 is 98.304 MHz. Register 0[6] is keyed to the ratio, not the rate: 384 kHz from 24.576 MHz needs it as much as 768 kHz from 49.152 MHz does. The asynchronous floor is also strictly greater than 130 * FS now, as Table 7 note 1 has it.

- The mute and DoP controls moved their shadow state before the I2C write and left it moved if the write failed. Both short-circuit on "no change", so a retry with the same value was a no-op and the control stayed permanently at odds with the register. They now restore the old value on failure.

- Enable the datapath at component probe. SYSTEM_CONFIG[1] is clear at reset, so in software mode the analogue output was dead until something outside the driver set that bit. Written after the mute and never before it.

- Add system suspend and resume. Where a board feeds the part a free-running oscillator, nothing in the system can gate its clock and it stayed fully clocked through suspend; suspend now clears ENABLE_DAC_CLK and resume resynchronises the cache. Resume mutes first, because regcache_sync() walks registers in ascending address order and would otherwise restore DAC_MODE in register 0 long before the mute in register 86, on any board that removes the part's supplies.

- Remove board-specific references from the comments - measurement attributions, dates, and two pointers at a repository outside the tree. No functional change.

- Note on what is and is not tested: everything at 176.4 kHz and below runs on the board this driver was written for. The paths above it are derived from the datasheet and not measured - that board feeds the part a fixed 24.576 MHz oscillator as a clock consumer and cannot reach them.

Changes in v2:

- Accept SND_SOC_DAIFMT_CBP_CFP rather than requiring CBC_CFC. v1 rejected every provider mode but consumer, which was one board's choice written into the driver. CBP_CFP now programs PCM_MASTER_MODE, hw_params() calls clk_set_rate() to pull MCLK to a multiple of the sample rate where the clock allows it, and the datasheet's two MCLK floors are applied separately - 128 x Fs synchronous, 130 x Fs asynchronous - instead of 130 x Fs unconditionally, which had been refusing 192 kHz on synchronous boards that can carry it.

- ES9039_DECODE_MASK did not cover ENABLE_SPDIF_DECODE. hw_params() uses that mask to enable one decoder and clear the rest, so the S/PDIF decoder stayed enabled alongside whichever decoder was selected.

- mute_stream() and the "Master Playback Switch" control both wrote ES9039_DAC_MUTE and overwrote each other. Each now records its own intent and the register is written from the union of the two.

- The DoP control returns -EBUSY while a stream is open rather than half-applying a change hw_params() will not re-run, and both halves of automatic DoP detection go through one helper under a mutex, so AUTO_INPUT_SEL and ENABLE_DOP_DECODE can no longer disagree.

- Status controls use the symbolic source-bit names rather than bare BIT() values. Doing so found a bug: "Clock Fault" read bit 7 of register 235, which is reserved, rather than BCK_WS_FAIL_SOURCE in register 234, and could never have reported a fault.

- The volume put() raises VOLUME_HOLD around the pair of channel writes and drops it afterwards, which is what the bit is for. A stereo change previously left the channels briefly at different levels.

- Rename the vendor prefix from "ess" to "esstech", after Krzysztof Kozlowski pointed out that ESS Technology's domain is esstech.com. The binding file, its $id and the compatible string follow.

- The harmonic correction controls keep their names rather than gaining a "Volume" suffix. The justification in the comment was wrong - TLV data is not what decides - but they cancel distortion rather than set a level, so the name stands and the comment now says why.

- Style: the header block is one C++ comment, and the "return ret ? ret :
1" ternaries are plain conditionals.

- Add the Assisted-by tag that Documentation/process/coding-assistants.rst asks for, which v1 omitted. This driver was developed with AI assistance. The board it was written against, the register-level measurements quoted above, and the responsibility for what is in it, are mine.

v4 has had a run on the board the driver was written for.

Karl Asseily (4):
dt-bindings: vendor-prefixes: add ESS Technology
ASoC: dt-bindings: add ESS Technology ES9039Q2M
ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
MAINTAINERS: add entry for the ES9039Q2M codec driver

 .../bindings/sound/esstech,es9039q2m.yaml     |   94 +
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 MAINTAINERS                                   |    7 +
 sound/soc/codecs/Kconfig                      |   14 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/es9039q2m.c                  | 2008 +++++++++++++++++
 6 files changed, 2127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/esstech,es9039q2m.yaml
 create mode 100644 sound/soc/codecs/es9039q2m.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/4 dt-bindings: vendor-prefixes: add ESS Technology

Add the vendor prefix for ESS Technology, Inc., maker of the SABRE family of audio DACs. The prefix follows the company's domain, esstech.com.

Assisted-by Claude:claude-opus-5

---

Notes:
v2: rename the vendor prefix to esstech, after the company domain

 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index ba200296937..ff4a85f4cbd 100644
@@ -559,6 +559,8 @@ patternProperties:
     description: Seiko Epson Corp.
   "^esp,.*":
     description: Espressif Systems Co. Ltd.
+  "^esstech,.*":
+    description: ESS Technology, Inc.
   "^est,.*":
     description: ESTeem Wireless Modems
   "^eswin,.*":
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/4 ASoC: dt-bindings: add ESS Technology ES9039Q2M

In reply to Karl Asseily

Add a binding for the ES9039Q2M, a 32-bit two-channel audio DAC with an asynchronous sample rate converter.

The part selects between two control personalities with its MODE pin:
hardware mode, strapped by HW0/HW1/HW2 with no control bus at all, and software mode over I2C or SPI. This binding describes software mode over I2C, which MODE = GND selects.

The four supply inputs are described and required. DVDD is not among
them: the part's 1.2V digital rail is generated on chip and the pin takes only a decoupling capacitor. The datasheet asks for the supplies in a set order - AVDD, then VCCA about 200us later, then the two output-stage references, and the reverse on the way down - which the description records, so a board with separately switchable rails has it to hand.

Assisted-by Claude:claude-opus-5

---

Notes:
v4:
- describe the four supply inputs - AVDD, VCCA, AVCC_DAC1 and AVCC_DAC2 - and require them, as Rob Herring and the sashiko reviewer both asked. DVDD gets no property on purpose: the part's 1.2V digital rail is generated on chip and that pin takes a decoupling capacitor, not a regulator
- NOTE ON THE Reviewed-by BELOW. It was given on v2 and this patch has changed since, by exactly the supplies above. It is carried forward rather than re-earned, and flagged here so it can be withdrawn if you disagree
v2: rename the binding to esstech,es9039q2m and update its $id and compatible

 .../bindings/sound/esstech,es9039q2m.yaml     | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/esstech,es9039q2m.yaml
Documentation/devicetree/bindings/sound/esstech,es9039q2m.yaml new file +94 -0
new file mode 100644
index 00000000000..15db30af4b6
@@ -0,0 +1,94 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/esstech,es9039q2m.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ESS Technology ES9039Q2M audio DAC
+
+maintainers:
+  - Karl Asseily <[email protected]>
+
+description:
+  The ES9039Q2M is a 32-bit two-channel audio DAC supporting PCM to 768 kHz,
+  DSD64 to DSD1024, DoP and S/PDIF. It is controlled over I2C or SPI when the
+  MODE pin selects software mode; this binding covers the I2C interface. The
+  part contains an asynchronous sample rate converter, so the system clock need
+  not be synchronous with the audio bit or frame clocks.
+
+  The four supplies are all nominally 3.3V and the datasheet requires a set
+  order - AVDD first, then VCCA about 200us later, then AVCC_DAC1 and
+  AVCC_DAC2, and the reverse on the way down. DVDD, the part's 1.2V rail, is
+  on-chip and needs only its decoupling capacitor - it is not a supply input
+  and has no property here.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: esstech,es9039q2m
+
+  reg:
+    description:
+      I2C address, selected by the ADDR0 and ADDR1 pins - 0x48, 0x49, 0x4a or
+      0x4b for GND/GND, GND/AVDD, AVDD/GND and AVDD/AVDD respectively.
+    enum: [ 0x48, 0x49, 0x4a, 0x4b ]
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: mclk
+
+  avdd-supply:
+    description:
+      3.3V supply for the part's internal digital regulator, pin AVDD. It is
+      the first rail up and the last down, per the ordering described above.
+
+  vcca-supply:
+    description: 3.3V analogue supply, pin VCCA.
+
+  avcc-dac1-supply:
+    description:
+      3.3V reference supply for the channel 1 analogue output stage, pin
+      AVCC_DAC1. The datasheet allows this rail to move by up to 15% where a
+      calibrating regulator tracks the DAC's output impedance.
+
+  avcc-dac2-supply:
+    description:
+      3.3V reference supply for the channel 2 analogue output stage, pin
+      AVCC_DAC2, with the same 15% allowance as channel 1.
+
+  "#sound-dai-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - vcca-supply
+  - avcc-dac1-supply
+  - avcc-dac2-supply
+  - "#sound-dai-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        audio-codec@48 {
+            compatible = "esstech,es9039q2m";
+            reg = <0x48>;
+            #sound-dai-cells = <0>;
+            clocks = <&dac_mclk>;
+            clock-names = "mclk";
+            avdd-supply = <&dac_3v3>;
+            vcca-supply = <&dac_3v3>;
+            avcc-dac1-supply = <&dac_avcc1>;
+            avcc-dac2-supply = <&dac_avcc2>;
+        };
+    };
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/4 ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver

In reply to Karl Asseily

The ES9039Q2M is a 32-bit two-channel audio DAC with an asynchronous sample rate converter. It selects between two control personalities with its MODE pin: hardware mode, strapped by HW0/HW1/HW2 with no control bus at all, and software mode over I2C or SPI. This driver implements software mode over I2C, which MODE = GND selects.

Three properties of the part shape the driver:

- The ASRC in front of the DAC means MCLK need not be synchronous with BCLK or LRCK, so a board can feed it a fixed oscillator and never touch the clock again. The driver derives which case it is in rather than assuming one: the part runs synchronously when it drives the bus clocks itself, or when the MCLK it was given can be set to a multiple of the sample rate, and asynchronously only when a fixed oscillator feeds it as a clock consumer. The datasheet's MCLK floor differs between the two - 128 x Fs synchronous, 130 x Fs asynchronous
- and where the clock is fixed a startup constraint derives the maximum rate from the MCLK actually present rather than advertising rates the hardware cannot honour.

- Selecting an input format takes two registers, not one. Register 57 INPUT_SEL chooses which port to listen to; register 1 SYS MODE CONFIG enables the corresponding decoder, and at reset only ENABLE_TDM_DECODE is set. Selecting DoP without also enabling ENABLE_DOP_DECODE leaves the part hunting for a marker with the marker decoder switched off, so it finds no valid DoP and mutes. The driver sets both.

- Several registers have non-zero reserved defaults - register 88 reads 0xb8 at reset - so every write is read-modify-write.

The part has four supply inputs and the datasheet asks for them in a set
order: AVDD, then VCCA about 200us later, then the two output-stage references AVCC_DAC1 and AVCC_DAC2, with power-down exactly reversed. The driver enables them one at a time for that reason rather than calling regulator_bulk_enable(), which makes no ordering guarantee; the bulk API still acquires them, where order does not matter. DVDD is not among them:
the part's 1.2V digital rail is generated on chip and that pin takes only a decoupling capacitor. No settling time is inserted before the first register access because the datasheet specifies none.

The datapath is off at reset and the driver turns it on at component probe. SYSTEM_CONFIG[1] is clear when the part comes out of reset, so in software mode nothing enables it at power-up and the analogue output stays dead until the driver writes that bit. It is written after the mute and never before it: bringing the datapath up into an unmuted part whose volume registers still sit at their 0 dB reset value is the thump the mute is there to prevent. Note when testing that a warm reboot does not reset this part - registers and coefficient RAM both survive one, and only removing power clears them - so the previous boot's value can hide whether the write happened at all.

DoP is detected by the part rather than announced by the host:
AUTO_INPUT_SEL is enabled and both the TDM and DoP decoders run, so a player can simply send DoP-encoded PCM. That is the only way DoP works in practice, because no player can select a DAC mode through a kcontrol first, and material sent to a part that is not looking for the marker renders as the near-silent hiss the DoP design deliberately degrades to.

The programmable FIR coefficient controls are write-only by design. The part has a PROG_COEFF_OUT register described as "Programmable FIR coefficient readback", but it is not a RAM read port: it returns the last coefficient written, whatever address is selected in PROG_COEFF_ADDR. Measured by writing two different coefficients to addresses 0 and 1 and reading them back five ways - plain, with a settle delay, with PROG_COEFF_EN set, with the address written twice, and with a write-enable pulse after the address. All ten reads returned the value written to address 1. A get() built on that register would return something with the shape of data and none of its meaning, so there is none.

Every control was verified against the silicon rather than against the driver's own read-back: written through ALSA, then read from the chip over raw I2C. That covers the eight filter shapes, the modulator bandwidth, the IIR bandwidth, the four signed 16-bit THD compensation coefficients at both extremes of their range, and the automute enable, time, level and off-level fields including the neighbouring MUTE_RAMP_TO_GND bit that shares a register with the 11-bit time field. The coefficient upload, whose RAM cannot be read back, was verified from the I2C bus itself.

System suspend gates the part's internal clock tree. Where the part is clocked from the SoC, system suspend stops its clock as a side effect and there is nothing for a driver to do; where the board feeds it a free-running oscillator - which the ASRC makes an attractive design, since MCLK then need not track BCLK or LRCK - nothing in the system can gate that clock and the part stays fully clocked for the whole of suspend. Clearing ENABLE_DAC_CLK is the only part of its consumption software can reach; the analogue supplies are the board's business. Measured on an RK3588 board with a fixed 24.576 MHz oscillator, system suspend power fell from 1.98 W to 1.95 W and followed the register in both directions across an A/B.

Resume mutes the part before regcache_sync(), because the sync walks registers in ascending address order. A board that keeps the supplies up needs nothing, but one that removes them brings the part back at reset defaults - DAC_MODE clear, both channels unmuted, both volume registers at 0 dB - and the sync would set DAC_MODE in register 0 and only restore the real mute in register 86, lighting the datapath up at full scale in between.

Resume also re-uploads the programmable FIR coefficient RAM. regcache_sync() cannot restore it - the RAM is write-only, so nothing caches it - but the sync does restore the filter selection, so a board that removed the supplies would come back with the programmable filter selected and the RAM holding whatever it powered up with. The driver keeps a shadow of each stage it uploaded and replays it after the sync. Stages never written have no shadow and keep the part's own defaults.

Assisted-by Claude:claude-opus-5

---

Notes:
v4:
- get the four supplies and enable them one at a time in the order the datasheet gives - AVDD, then VCCA about 200us later, then the two output-stage references - and disable them in reverse. regulator_bulk_enable() gives no ordering guarantee, so only the get is done in bulk, where order does not matter. The datasheet states no settling time before the first register access, so none is invented
- resume re-uploads the programmable FIR RAM from a shadow of the last upload, answering Mark Brown's review of v3. regcache_sync() cannot restore write-only RAM, and it does restore the filter selection, so a board that drops the part's supplies came back pointing the interpolator at undefined coefficients. Stages never uploaded keep the part's defaults
- serialise the upload. Both FIR controls drive the same address, data and write-enable registers and nothing ordered them, so two uploads at once could interleave into each other's RAM. The mutex that orders an upload against resume closes that too
- the multi-register controls update one register at a time through regmap_update_bits() instead of reading the whole field and writing it back. AUTOMUTE_TIME spans registers 124-125 and MUTE_RAMP_TO_GND is bit 3 of register 125 with a control of its own; two puts can run at once, so the read-modify-write could lose that bit
- the volume control holds the driver mutex across VOLUME_HOLD and the pair of channel writes. Without it a second caller could write its volumes after the first had dropped the hold - the torn update the bit prevents
v3:
- fix the MCLK selection added in v2. clk_set_rate() asked for 256 * FS unconditionally, which is above the part's 50 MHz maximum for anything over 192 kHz, and the rate the clock settled on was not re-checked. The ratio is now the highest of 512/256/128/64 that fits
- 64FS mode is decided from the MCLK/FS ratio in use rather than from a rate threshold, so the advertised 768 kHz is reachable instead of always failing the 128 * FS floor, and the asynchronous floor is strictly greater than 130 * FS as the datasheet has it
- the mute and DoP controls restore their shadow state if the register write fails. Both short-circuit on "no change", so a retry with the same value was a no-op and the control stayed permanently at odds with the register
- enable the datapath at component probe. SYSTEM_CONFIG[1] is clear at reset, so in software mode the analogue output was dead until something outside the driver set that bit. Written after the mute, never before it
- add system suspend and resume. Suspend clears ENABLE_DAC_CLK, which gates the internal clock tree and is all that software can reach where MCLK is a free-running oscillator the system cannot gate. Resume mutes before regcache_sync(), because the sync walks registers in ascending address order and would otherwise restore DAC_MODE in register 0 long before the mute in register 86, on any board that removes the part's supplies
- comments: board-specific measurement attributions, dates and two pointers outside the tree removed. No functional change
v2: address Mark Brown's review of v1
- make the whole header block a C++ comment
- ES9039_DECODE_MASK now covers S/PDIF. hw_params() uses it to enable one decoder and clear the rest, so omitting it left S/PDIF enabled alongside whichever decoder was selected
- plain conditionals in place of "return ret ? ret : 1"
- mute_stream() and the Master Playback Switch no longer both write ES9039_DAC_MUTE. Each records its intent and the register is written from the union, so neither can override the other
- the DoP control returns -EBUSY while a stream is open rather than half-applying a change hw_params() will not re-run
- the status controls use the symbolic source bits; TDM_VALID gained one
- the harmonic correction controls keep their names. The TLV justification was wrong and is gone, but they cancel distortion rather than set a level
- clocking, which was one mistake in three places. SND_SOC_DAIFMT_CBP_CFP is accepted and programs PCM_MASTER_MODE; clk_set_rate() pulls MCLK to 256 * FS when the clock is settable; synchronous operation is derived rather than assumed; and the MCLK floor is 128 * FS synchronous or 130 * FS asynchronous, not 130 unconditionally, so a synchronous board is no longer refused rates it can carry
- fix the Clock Fault control, which read the byte above the status bit and so could never report a fault
- hold both DoP bits consistent under a mutex, and use VOLUME_HOLD so the two channel volumes latch together

 sound/soc/codecs/Kconfig     |   14 +
 sound/soc/codecs/Makefile    |    2 +
 sound/soc/codecs/es9039q2m.c | 2008 ++++++++++++++++++++++++++++++++++
 3 files changed, 2024 insertions(+)
 create mode 100644 sound/soc/codecs/es9039q2m.c
sound/soc/codecs/Kconfig +14 -0
index e78d725e61e..fefda526277 100644
@@ -123,6 +123,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_ES8328_I2C
 	imply SND_SOC_ES8375
 	imply SND_SOC_ES8389
+	imply SND_SOC_ES9039Q2M
 	imply SND_SOC_ES9356
 	imply SND_SOC_ES7134
 	imply SND_SOC_ES7241
@@ -1317,6 +1318,19 @@ config SND_SOC_ES8389
 	tristate "Everest Semi ES8389 CODEC"
 	depends on I2C
 
+config SND_SOC_ES9039Q2M
+	tristate "ESS Technology ES9039Q2M CODEC"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Enable support for the ESS Technology ES9039Q2M, a 32-bit
+	  two-channel audio DAC with an asynchronous sample rate converter,
+	  supporting PCM, DSD, DoP and S/PDIF input. This driver covers the
+	  I2C control interface, which the MODE pin selects.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-soc-es9039q2m.
+
 config SND_SOC_ES9356
 	tristate "Everest Semi ES9356 CODEC SDW"
 	depends on SND_SOC_SDCA
sound/soc/codecs/Makefile +2 -0
index 9287a602d41..1679c3ffc63 100644
@@ -140,6 +140,7 @@ snd-soc-es8328-i2c-y := es8328-i2c.o
 snd-soc-es8328-spi-y := es8328-spi.o
 snd-soc-es8375-y := es8375.o
 snd-soc-es8389-y := es8389.o
+snd-soc-es9039q2m-y := es9039q2m.o
 snd-soc-es9356-y := es9356.o
 snd-soc-framer-y := framer-codec.o
 snd-soc-fs-amp-lib-y := fs-amp-lib.o
@@ -586,6 +587,7 @@ 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_ES8375)    += snd-soc-es8375.o
 obj-$(CONFIG_SND_SOC_ES8389)    += snd-soc-es8389.o
+obj-$(CONFIG_SND_SOC_ES9039Q2M)	+= snd-soc-es9039q2m.o
 obj-$(CONFIG_SND_SOC_ES9356)    += snd-soc-es9356.o
 obj-$(CONFIG_SND_SOC_FRAMER)	+= snd-soc-framer.o
 obj-$(CONFIG_SND_SOC_FS_AMP_LIB)+= snd-soc-fs-amp-lib.o
sound/soc/codecs/es9039q2m.c new file +2008 -0

2,008 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v4 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ASoC: es9039q2m: FIR coefficient upload corrupts data with TLV header - [Low] i2c: positional…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: es9039q2m: FIR coefficient upload corrupts data with TLV header
- [Low] i2c: positional initializer used for i2c_device_id
--

commit 3aee2b23f8220349aa3bc4bfbb0d2fa6dfeb5b60
Author: Karl Asseily <[email protected]>

ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver

This commit introduces a new ALSA SoC codec driver for the ESS Technology ES9039Q2M 32-bit audio DAC. It supports software mode over I2C, implementing programmable FIR filters, custom routing, and DSD/DoP stream detection.

Quoted 5 lines
sound/soc/codecs/es9039q2m.c new file +0 -0
new file mode 100644
index 0000000000000..4e9f86cb78606

[ ... ]

Quoted 5 lines
sound/soc/codecs/es9039q2m.c new file +5 -0
+static int es9039_fir_put(struct snd_kcontrol *kcontrol,
+			  const unsigned int __user *bytes, unsigned int size)
+{
+	struct snd_soc_component *c = snd_kcontrol_chip(kcontrol);
+	struct es9039q2m_priv *priv = snd_soc_component_get_drvdata(c);

sound/soc/codecs/es9039q2m.c line 598

Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10 -0
+	struct soc_bytes_ext *be = (void *)kcontrol->private_value;
+	struct es9039_fir_ctl *p = container_of(be, struct es9039_fir_ctl, be);
+	unsigned int idx = p->stage_4x ? 1 : 0;
+	u8 *buf;
+	int ret;
+
+	if (size != p->taps * ES9039_COEFF_BYTES)
+		return -EINVAL;
+
+	buf = memdup_user(bytes, size);

[Severity: High]
Does this copy include the ALSA TLV header along with the coefficient payload?

When userspace writes coefficients via the ALSA TLV control, snd_ctl_tlv_ioctl passes the TLV array down to snd_soc_bytes_tlv_callback. This array starts with a 2-word header containing the type and length.

Because memdup_user starts from the very beginning of the bytes array without skipping this 8-byte header, the hardware's coefficient RAM might receive the header data instead of the actual coefficients, and the last 8 bytes of the intended payload would be truncated.

Quoted 2 lines
sound/soc/codecs/es9039q2m.c new file +2 -0
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);

[ ... ]

sound/soc/codecs/es9039q2m.c line 1991

Quoted 2 lines
sound/soc/codecs/es9039q2m.c new file +2 -0
+static const struct i2c_device_id es9039q2m_i2c_id[] = {
+	{ "es9039q2m" },

[Severity: Low]
This isn't a functional bug, but should this use a named initializer to conform to the I2C subsystem guidelines for i2c_device_id arrays? For example, using { .name = "es9039q2m" }.

Quoted 3 lines
sound/soc/codecs/es9039q2m.c new file +3 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, es9039q2m_i2c_id);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#5 lore raw

Re: [PATCH v4 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver

Quoted 3 lines

[Severity: High]
Does this copy include the ALSA TLV header along with the coefficient payload?

No. snd_soc_bytes_tlv_callback() in sound/soc/soc-ops.c passes the pointer through unchanged:

unsigned int count = size < params->max ? size : params->max;
...
ret = params->put(kcontrol, tlv, count);

There is no &tlv[2] and no size adjustment, so the driver receives the control payload and nothing else. The payload format for this control is raw coefficients with no type/length header, which is what wm_adsp does too; SOF embeds its own header, so both conventions exist in tree.

The hazard you describe is real, though, and I have met it. A userspace tool of mine did prepend an 8-byte header once. Because the callback clamps count to params->max, the driver still saw exactly 384 bytes, the size check passed, and the two header words were loaded as taps - one non-zero tap in 128, about -33 dB, found only from i2c tracepoints.

The driver cannot defend against that: the clamp means the true size never reaches .put, so a header-bearing write is indistinguishable from a correct one. I will document the payload format at the control definition so the contract is stated rather than implied.

Quoted 2 lines

[Severity: Low]
should this use a named initializer

Answered on v3. sound/soc/codecs carries 202 i2c_device_id tables and 136 of their entries use the positional form, so it is the prevailing style rather than a deviation. No change.

#6 lore raw

PATCH v4 4/4 MAINTAINERS: add entry for the ES9039Q2M codec driver

In reply to Karl Asseily

Add myself as maintainer of the ES9039Q2M codec driver and its binding.

Assisted-by Claude:claude-opus-5

---

Notes:
v2: follow the binding rename

 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 20d67cc0e7a..1095476c1d9 100644
@@ -9699,6 +9699,13 @@ S:	Maintained
 F:	include/linux/errseq.h
 F:	lib/errseq.c
 
+ES9039Q2M AUDIO CODEC DRIVER
+M:	Karl Asseily <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/sound/esstech,es9039q2m.yaml
+F:	sound/soc/codecs/es9039q2m.c
+
 ESD CAN NETWORK DRIVERS
 M:	Stefan Mätje <[email protected]>
 R:	[email protected]
Signature · 1 line
2.34.1
maintainer
#7 lore raw
In reply to Karl Asseily
Quoted 9 lines · Karl Asseily

ASoC: add ESS Technology ES9039Q2M codec driver

This series adds support for the ESS Technology ES9039Q2M, a 32-bit two-channel audio DAC with an asynchronous sample rate converter, controlled over I2C. The part also has a hardware mode strapped by HW0/HW1/HW2 with no control bus at all; this driver implements the software mode that MODE = GND selects.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/4] dt-bindings: vendor-prefixes: add ESS Technology

      https://git.kernel.org/broonie/sound/c/beb56d1d3de5
[2/4] ASoC: dt-bindings: add ESS Technology ES9039Q2M
      https://git.kernel.org/broonie/sound/c/ab1a02163fcd
[3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
      https://git.kernel.org/broonie/sound/c/004e260a5475
[4/4] MAINTAINERS: add entry for the ES9039Q2M codec driver
      https://git.kernel.org/broonie/sound/c/10d321c76b1e

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark