ASoC: add ESS Technology ES9039Q2M codec driver
Subsystems (3)
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 has two control personalities selected by its MODE pin: hardware mode, strapped by HW0/HW1/HW2 with no 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. A board can feed it a fixed oscillator and never touch the clock again. In that asynchronous mode the part requires MCLK >= 130 x Fs, so the driver installs a startup constraint deriving the maximum rate from the MCLK it was given rather than advertising rates the hardware cannot honour.
- Selecting an input format is 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; 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.
Everything the driver exposes has been verified against the silicon on hardware rather than against the driver's own read-back: each control is written through ALSA and the chip's register is then read 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.
Two limitations are deliberate and worth stating up front, because both look like omissions:
- The programmable FIR coefficient controls are write-only. 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 with five different sequences - 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.
- Coefficient uploads pulse PROG_COEFF_WE per coefficient, as the datasheet's sequence specifies. Holding it high across the whole upload also works on this silicon, but that is not what the documentation says.
DSD, DoP and S/PDIF input are all implemented. 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, which is the only way DoP works in practice. An earlier revision of this driver required userspace to select DoP through a kcontrol first; no player can do that, and the result was that DoP-encoded material rendered as the near- silent hiss the DoP marker design deliberately degrades to. The datasheet attaches a "data must be provided on the DATA2 pin" condition to automatic detection; that applies to identifying DSD, whose channels arrive on separate data lines, and DoP detects correctly on a two-channel I2S link without it.
DoP was verified end to end by generating a DSD64 test tone, carrying it as 32-bit PCM at 176400 Hz with nothing selected by hand, and confirming the part's own DOP_VALID flag and INPUT_SELECT_OVERRIDE readback while it played.
ESS Technology has no bindings in the tree today, so the series also introduces the vendor prefix.
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/ess,es9039q2m.yaml | 61 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 7 + sound/soc/codecs/Kconfig | 14 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/es9039q2m.c | 1259 +++++++++++++++++ 6 files changed, 1345 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/ess,es9039q2m.yaml create mode 100644 sound/soc/codecs/es9039q2m.c
Signature · 1 line
2.34.1
PATCH 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.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -549,6 +549,8 @@ patternProperties: description: Seiko Epson Corp. "^esp,.*": description: Espressif Systems Co. Ltd. + "^ess,.*": + description: ESS Technology, Inc. "^est,.*": description: ESTeem Wireless Modems "^eswin,.*":
Signature · 1 line
2.34.1
PATCH 2/4 ASoC: dt-bindings: add ESS Technology ES9039Q2M
In reply to Karl AsseilyAdd 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.
--- .../bindings/sound/ess,es9039q2m.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/ess,es9039q2m.yaml
Documentation/devicetree/bindings/sound/ess,es9039q2m.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/ess,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. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + const: ess,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 + + "#sound-dai-cells": + const: 0 + +required: + - compatible + - reg + - "#sound-dai-cells" + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + audio-codec@48 { + compatible = "ess,es9039q2m"; + reg = <0x48>; + #sound-dai-cells = <0>; + clocks = <&dac_mclk>; + clock-names = "mclk"; + }; + };
Signature · 1 line
2.34.1
PATCH 3/4 ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
In reply to Karl AsseilyThe 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. In that asynchronous mode the part requires MCLK >= 130 x Fs, so the driver installs a startup constraint that derives the maximum rate from the MCLK it was given 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.
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.
--- sound/soc/codecs/Kconfig | 14 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/es9039q2m.c | 1259 ++++++++++++++++++++++++++++++++++ 3 files changed, 1275 insertions(+) create mode 100644 sound/soc/codecs/es9039q2m.c
sound/soc/codecs/Kconfig +14 -0
@@ -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
@@ -1315,6 +1316,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
@@ -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
@@ -584,6 +585,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 +1259 -0
1,259 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 4/4 MAINTAINERS: add entry for the ES9039Q2M codec driver
In reply to Karl AsseilyAdd myself as maintainer of the ES9039Q2M codec driver and its binding.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9625,6 +9625,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/ess,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
Re: [PATCH 1/4] dt-bindings: vendor-prefixes: add ESS Technology
In reply to Karl AsseilyQuoted 4 lines · Karl Asseily
Add the vendor prefix for ESS Technology, Inc., maker of the SABRE family of audio DACs.
Signed-off-by Karl Asseily <[email protected]>
Website is esstech.com, so your prefix should be esstech. Unless the website is ess.com?
Best regards,
Krzysztof
[email protected]
AI reviewRe: [PATCH 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
In reply to Karl AsseilyThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] es9039_dop_put() corrupts hardware state when toggled mid-stream and races with hw_params().…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] es9039_dop_put() corrupts hardware state when toggled mid-stream and races with hw_params().
- [Medium] 'Clock Fault' status control queries the wrong register offset.
- [Medium] Probe initialization disables VOLUME_HOLD contrary to its documented intent. --
--- Patch [3]: [PATCH 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver --- commit bc64110211ab9eddd7d7d8ac88b78bebe86562d6
Author: Karl Asseily <[email protected]>
ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
This commit introduces the ASoC driver for the ESS Technology ES9039Q2M codec. It implements the software control mode over I2C, supporting PCM, DSD, DoP, and S/PDIF inputs along with an asynchronous sample rate converter.
Quoted 4 lines
sound/soc/codecs/es9039q2m.c new file +0
-0
[ ... ]
Quoted 6 lines
sound/soc/codecs/es9039q2m.c new file +6
-0+static int es9039_dop_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *c =snd_kcontrol_chip (kcontrol); +struct es9039q2m_priv *priv =snd_soc_component_get_drvdata (c); +bool on = !!ucontrol->value.integer.value[0 ];
sound/soc/codecs/es9039q2m.c line 727
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+int ret; + +if (on == priv->dop_auto) +return 0 ; + + priv->dop_auto = on; + + ret =regmap_update_bits (priv->regmap,ES9039_INPUT_SEL , +ES9039_AUTO_INPUT_SEL , + on ?ES9039_AUTO_INPUT_SEL :0 );
[Severity: Medium]
Will toggling this control mid-stream corrupt the hardware state?
If toggled on, it sets ES9039_AUTO_INPUT_SEL here but doesn't update ES9039_SYS_MODE to set ES9039_ENABLE_DOP_DECODE, since that was only evaluated in es9039q2m_hw_params() when the stream started.
The commit message notes that selecting DoP without enabling the marker decoder leaves the part hunting and causes it to mute. Is there a need to synchronize the decoder state in ES9039_SYS_MODE when this control is toggled?
[ ... ]
sound/soc/codecs/es9039q2m.c line 808
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+/* --- status, read-only --- */ +ES9039_STAT ("Automute Active CH1" ,ES9039_AUTOMUTE_READ ,BIT (0 ),1 ), +ES9039_STAT ("Automute Active CH2" ,ES9039_AUTOMUTE_READ ,BIT (1 ),1 ), +ES9039_STAT ("DoP Valid" ,ES9039_INPUT_STREAM_READ , +ES9039_RD_DOP_VALID ,1 ), +ES9039_STAT ("TDM Data Valid" ,ES9039_INPUT_STREAM_READ , +ES9039_RD_TDM_VALID ,1 ), +ES9039_STAT ("SPDIF Valid" ,ES9039_INPUT_STREAM_READ , +ES9039_RD_SPDIF_VALID ,1 ), + ES9039_STAT("Clock Fault", ES9039_IRQ_SOURCES + 1, BIT(7), 1),
[Severity: Medium]
Is this querying the wrong register offset for the clock fault bit?
ES9039_SRC_BCK_WS_FAIL is defined as BIT(7) of the 16-bit word at ES9039_IRQ_SOURCES. By adding 1 to the register address and still using BIT(7) as the mask, won't this check bit 15 of the 16-bit word instead of bit 7?
[ ... ]
Quoted 11 lines
sound/soc/codecs/es9039q2m.c new file +11
-0+static int es9039q2m_component_probe (struct snd_soc_component *component) +{ +struct es9039q2m_priv *priv =snd_soc_component_get_drvdata (component); +int ret; + +/* +* Come up muted. The volume registers default to 0 dB, and an unmuted +* DAC arriving into an already-powered analogue stage is how you get a +* thump. ASoC unmutes via mute_stream() when a stream starts. +*/ + ret = regmap_update_bits(priv->regmap, ES9039_DAC_MUTE,
sound/soc/codecs/es9039q2m.c line 1106
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+ ES9039_MUTE_BOTH, ES9039_MUTE_BOTH); +if (ret) +return ret; + +/* +* VOLUME_HOLD makes both channel volumes latch together, so a stereo +* change can never momentarily skew the image. +*/ + ret =regmap_update_bits (priv->regmap,ES9039_IIR_SPDIF , +ES9039_VOLUME_HOLD ,0 );
[Severity: Medium]
Is this intended to disable the volume hold feature?
The comment explicitly mentions that VOLUME_HOLD makes the channel volumes latch together, but passing 0 disables it. Should this pass ES9039_VOLUME_HOLD instead of 0 to enable the feature?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 1/4] dt-bindings: vendor-prefixes: add ESS Technology
In reply to Krzysztof KozlowskiYou're right — esstech.com. I'll switch the prefix to esstech and rename the binding accordingly in v2.
Thanks,
Karl
Quoted 13 lines · Krzysztof Kozlowski
Quoted 4 lines · Karl Asseily
Add the vendor prefix for ESS Technology, Inc., maker of the SABRE family of audio DACs.
Signed-off-by Karl Asseily <[email protected]>Website is esstech.com, so your prefix should be esstech. Unless the website is ess.com?
Best regards,
Krzysztof
Mark Brown
maintainerRe: [PATCH 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
In reply to Karl Asseilysound/soc/codecs/es9039q2m.c line 3
Quoted 12 lines · 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.
sound/soc/codecs/es9039q2m.c new file +3
-0@@ -0,0 +1,1259 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* ESS Technology ES9039Q2M 32-bit 2-channel audio DAC
Please make the entire comment block a C++ one so things look more intentional.
sound/soc/codecs/es9039q2m.c line 65
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+#define ES9039_SYS_MODE 0x01/* reg 1, reset 0xb1 */ +#define ES9039_ENABLE_TDM_DECODE BIT(0)/* set at reset */ +#define ES9039_ENABLE_DSD_DECODE BIT(1) +#define ES9039_ENABLE_DOP_DECODE BIT(2) +#define ES9039_ENABLE_SPDIF_DECODE BIT(3) +#define ES9039_SYNC_MODE BIT(6)/* 0 = ASYNC, which DATUM uses */ +#define ES9039_ENABLE_DAC_CLK BIT(7)/* set at reset */ +#define ES9039_DECODE_MASK (ES9039_ENABLE_TDM_DECODE | \ + ES9039_ENABLE_DSD_DECODE | \ + ES9039_ENABLE_DOP_DECODE)
_DECODE_MASK doesn't cover S/PDIF.
sound/soc/codecs/es9039q2m.c line 324
Quoted 4 lines
sound/soc/codecs/es9039q2m.c new file +4
-0+ + ret =es9039_write_le (priv->regmap, p->reg + (p->shift /8 ),2 , + (u16 )v); +return ret ? ret :1 ;
Please write normal conditional expressions rather than ternary ones for improved legibility.
Quoted 11 lines
sound/soc/codecs/es9039q2m.c new file +11
-0+static int es9039_dop_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *c =snd_kcontrol_chip (kcontrol); +struct es9039q2m_priv *priv =snd_soc_component_get_drvdata (c); +bool on = !!ucontrol->value.integer.value[0 ]; +int ret; + +if (on == priv->dop_auto) +return 0 ; +
sound/soc/codecs/es9039q2m.c line 732
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+ priv->dop_auto = on; + + ret =regmap_update_bits (priv->regmap,ES9039_INPUT_SEL , +ES9039_AUTO_INPUT_SEL , + on ?ES9039_AUTO_INPUT_SEL :0 ); +if (ret) +return ret; + +return 1 ; +}
If a stream is already running then the handling in hw_params() won't have a chance to kick in - should this return an error in that case, or try to do some reconfiguration?
sound/soc/codecs/es9039q2m.c line 764
Quoted 8 lines
sound/soc/codecs/es9039q2m.c new file +8
-0+/* +* Not "... Volume". ALSA reserves that suffix for gain controls +* carrying a dB scale, and these are signed correction coefficients +* for the second and third harmonic - they have no dB meaning and no +* TLV. Useful values come from measuring a given board's distortion on +* an analyser and solving for them; zero, the reset value, is the only +* honest default until someone has. +*/
Volume controls don't *need* TLV data or dB scales, it's more about their intended effect.
sound/soc/codecs/es9039q2m.c line 808
Quoted 1 line
sound/soc/codecs/es9039q2m.c new file +1
-0+ ES9039_STAT("Clock Fault", ES9039_IRQ_SOURCES + 1, BIT(7), 1),
There was a symbolic name for WS_FAIL, and there's TDM_VALID as well. It feels like this should be able to use the defines, especially since it's a driver local control type.
Quoted 15 lines
sound/soc/codecs/es9039q2m.c new file +15
-0+/* +* In asynchronous mode - a fixed oscillator with no relationship to the incoming +* frame clock, which is how any board using the ASRC properly is wired - the +* datasheet requires MCLK >= 130 * FS (hardware mode table, ASYNC rows). Cap the +* rate accordingly so a machine driver cannot open a stream the clock cannot +* legally carry. With a 24.576 MHz oscillator that ceiling is 189 kHz, which +* means 176.4 kHz is available and 192 kHz is not. +*/ +#define ES9039_ASYNC_MIN_MCLK_FS 130 + +static int es9039q2m_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct es9039q2m_priv *priv =snd_soc_component_get_drvdata (dai->component); +unsigned int max_rate;
sound/soc/codecs/es9039q2m.c line 867
Quoted 10 lines
sound/soc/codecs/es9039q2m.c new file +10
-0+ +if (!priv->mclk_rate) +return 0 ; + + max_rate = priv->mclk_rate /ES9039_ASYNC_MIN_MCLK_FS ; + +return snd_pcm_hw_constraint_minmax (substream->runtime, +SNDRV_PCM_HW_PARAM_RATE , +8000 , max_rate); +}
This means that if MCLK is specified but syncronous we'll reject things that could be supported, that doesn't seem ideal. We should have some mechanism for specifying if the clock is actually async.
sound/soc/codecs/es9039q2m.c line 881
Quoted 7 lines
sound/soc/codecs/es9039q2m.c new file +7
-0+/* +* The part can generate BCLK/WS (PCM_MASTER_MODE), but on a board fed a +* fixed oscillator that means deriving them from MCLK and throwing away +* the ASRC's entire purpose. Consumer only, and say so. +*/ +if ((fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) !=SND_SOC_DAIFMT_CBC_CFC ) +return -EINVAL ;
That seems odd - usually an ASRC is a workaround for mismatched clocks, not a goal. It is very common for the CODEC to drive clocks on the audio bus from a high quality MCLK.
sound/soc/codecs/es9039q2m.c line 1053
Quoted 7 lines
sound/soc/codecs/es9039q2m.c new file +7
-0+static int es9039q2m_mute_stream (struct snd_soc_dai *dai,int mute,int dir) +{ +struct es9039q2m_priv *priv =snd_soc_component_get_drvdata (dai->component); + +return regmap_update_bits (priv->regmap,ES9039_DAC_MUTE , +ES9039_MUTE_BOTH , mute ?ES9039_MUTE_BOTH :0 ); +}
This is shared with the user visible mute control, they're going to fight and be buggy. The register needs to be owned by one of them or they need to coordinate.
sound/soc/codecs/es9039q2m.c line 1214
Quoted 7 lines
sound/soc/codecs/es9039q2m.c new file +7
-0+if (priv->mclk) { + priv->mclk_rate =clk_get_rate (priv->mclk); +if (priv->mclk_rate >50000000 ) +return dev_err_probe (dev, -EINVAL , +"mclk %u Hz exceeds the 50 MHz maximum\n" , + priv->mclk_rate); + }
As per the above comments on driving the clocks from the CODEC it'd be pretty standard to use clk_set_rate() to configure the MCLK to be a suitable multiple of the sample rate and get everything nice and synchronous.
Re: [PATCH 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
Quoted 2 lines · Mark Brown
Please make the entire comment block a C++ one so things look more intentional.
Done.
Quoted 1 line
_DECODE_MASKdoesn't cover S/PDIF.
Fixed, and it was a real bug rather than a naming one - the mask is what hw_params() uses to enable one decoder and clear the rest, so the S/PDIF decoder was being left enabled alongside whichever one was selected.
Quoted 2 lines
Please write normal conditional expressions rather than ternary ones for improved legibility.
Done.
Quoted 3 lines
If a stream is already running then the handling in
hw_params()won't have a chance to kick in - should this return an error in that case, or try to do some reconfiguration?
It now returns -EBUSY while a stream is open. Reconfiguring live would mean redoing the decoder and input selection underneath a running stream, and I have no way to test that the part tolerates it; refusing is honest and the control is a setup-time thing in practice.
Quoted 2 lines
Volume controls don't *need* TLV data or dB scales, it's more about their intended effect.
Fair - the TLV reasoning was wrong and I have replaced it. I do not think these are volume controls by intended effect either, though: they are signed correction coefficients for the second and third harmonic, they cancel distortion contributed by the analogue stage, and turning one up does not make anything louder. I have kept the names and fixed the comment to say that instead. Happy to rename if you still read them as level controls.
Quoted 3 lines
There was a symbolic name for
WS_FAIL, and there'sTDM_VALIDas well. It feels like this should be able to use the defines, especially since it's a driver local control type.
Agreed, and using the define turned up a bug: the control read ES9039_IRQ_SOURCES + 1 with BIT(7), which is bit 15 of a 16-bit word and reserved, so it could never have reported a fault. It now reads ES9039_SRC_BCK_WS_FAIL from the correct byte. The other status controls use their defines already.
Quoted 4 lines
This means that if MCLK is specified but syncronous we'll reject things that could be supported, that doesn't seem ideal. We should have some mechanism for specifying if the clock is actually async.
Quoted 8 lines
That seems odd - usually an ASRC is a workaround for mismatched clocks, not a goal. It is very common for the CODEC to drive clocks on the audio bus from a high quality MCLK.
As per the above comments on driving the clocks from the CODEC it'd be pretty standard to use
clk_set_rate()to configure the MCLK to be a suitable multiple of the sample rate and get everything nice and synchronous.
Taking these three together, because they were one mistake: I had written a board policy into the driver. v2:
- accepts SND_SOC_DAIFMT_CBP_CFP and programs PCM_MASTER_MODE, with MASTER_BCK_DIV computed from MCLK and the frame size. The part drives both clocks or neither, so CBP_CFC and CBC_CFP are still rejected.
- calls clk_set_rate() for 256 * FS in hw_params() when the clock can be retuned, and uses the rate the clock actually settles on.
- derives synchronous rather than being told it: the part is synchronous when it drives the clocks, or when MCLK could be retuned to suit the rate. Only a fixed oscillator feeding a consumer-mode part is genuinely asynchronous. That is detected at probe by asking clk_round_rate() for a different rate and seeing whether the clock offers one.
- applies the datasheet's two floors rather than one: MCLK >= 128 * FS synchronous, >= 130 * FS asynchronous (Table 7, note 1). That difference is not academic - with a 24.576 MHz clock, 128 * FS makes 192 kHz exactly legal while 130 * FS caps at 189 kHz, so v1 was refusing a rate that works.
The startup() constraint now only applies when the clock is genuinely fixed; with a retunable one hw_params() raises MCLK and fails cleanly if it cannot.
For context rather than argument: the board I wrote this on feeds the part a fixed 24.576 MHz oscillator and runs it as a clock consumer, which is why I had the async case in front of me and the synchronous one not. That is a board choice and it stays in the board's DT, not in the driver.
Quoted 3 lines
This is shared with the user visible mute control, they're going to fight and be buggy. The register needs to be owned by one of them or they need to coordinate.
Fixed. Both now record what they want in the driver and the register is written from the union, so a user unmute cannot unmute a stopped stream and a stream start cannot override a user mute. The control reports the user's own setting rather than the register, since the register also carries the stream mute.
v2 is on the list, with all of the above on hardware:
https://lore.kernel.org/r/[email protected]
Thanks for the review.
Karl
Mark Brown
maintainerRe: [PATCH 3/4] ASoC: es9039q2m: add ESS Technology ES9039Q2M codec driver
Quoted 4 lines · Karl Asseily
For context rather than argument: the board I wrote this on feeds the part a fixed 24.576 MHz oscillator and runs it as a clock consumer, which is why I had the async case in front of me and the synchronous one not. That is a board choice and it stays in the board's DT, not in the driver.
That's a convenient base clock for 8kHz based sample rates.