ASoC: meson: gx: add base support for I2S audio input
Subsystems (5)
v2 cover ASoC: meson: gx: add base support for I2S audio input
This series is the 2nd part of the initial RFC [1] proposed to add audio input support to the Meson GX SoCs. After the AIU reshaping series [2] that has recently been merged, this one adds the audio input path itself.
Apart from some glue commits for gx-formatter Kconfig split, DT, bindings and integration with gx-card, the core commit is the 3rd one, which adds the AUDIN driver.
This is the counterpart of AIU for capture: it gets the entire register range, it handles peripheral clock and reset, it instantiates the I2S data formatter as widget and FIFOs as DAIs.
Resulting capture topology is:
pads --> AIU I2S Encoder -> AUDIN I2S Formatter -> AUDIN FIFO -> RAM
This series includes all the changes related to this work (dt-bindings, drivers and device-tree) in order to give the full picture in one single place.
Unfortunately, since no Meson GXBB/GXL board available in the tree features an I2S capture capable codec, this work cannot be directly tested out of the box. To test it an external codec must be connected to the SoC. When working on this series, a custom hat board with an NXP SGTL5000 codec has been plugged on top of an Odroid-C2 (GXBB). The last commit of this series fully details all the device-tree changes which are required to finalize the support for this scenario.
With this hardware configuration it has been possible to successfully validate the implementation with:
- alsa tools (arecord)
- pcm-tests
[1]: https://lore.kernel.org/linux-sound/[email protected]/
[2]: https://lore.kernel.org/linux-sound/[email protected]/
---
Changes in v2:
- Dropped FIFO child nodes from AUDIN in device-tree. Now AUDIN is the only sound component and FIFOs are its DAIs. This is the same design used in AIU. [Krzysztof]
- Renamed driver compatible, using 'amlogic,gx-audin' as fallback and 'amlogic,gx[bb|l]-audin' as SoC specific. Fixed also other reported comments on the binding. [Krzysztof]
- Adjusted headers inclusion in 'audin.c' and spacing in the empty entry of 'meson_gx_audin_of_match'. [Uwe]
- Replaced 'snd_soc_component_read' with 'regmap_read' in 'audin_fifo_pos' in order to prevent sleeping in atomic context. Also changed the hrtimer from hard-irq to a soft-irq one. [Sashiko]
- Added 'sync_stop' callback in 'audin_component' to ensure the hrtimer is fully stopped before attempting to restart the stream in a "start->stop->prepare->start" scenario.
- Link to v1: https://patch.msgid.link/[email protected]
To: Jerome Brunet <[email protected]>
To: Liam Girdwood <[email protected]>
To: Mark Brown <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Valerio Setti <[email protected]>
To: Jaroslav Kysela <[email protected]>
To: Takashi Iwai <[email protected]>
To: Neil Armstrong <[email protected]>
To: Kevin Hilman <[email protected]>
To: Martin Blumenstingl <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Valerio Setti (6):
ASoC: dt-bindings: amlogic,gx-audin: add schema
ASoC: meson: build gx-formatter as a separate module
ASoC: meson: add AUDIN driver
ASoC: meson: aiu: add I2S Capture DAI
ASoC: meson: gx-card: add support for audin FIFO
arm64: dts: amlogic: gx: add AUDIN node
.../bindings/sound/amlogic,gx-audin.yaml | 66 ++++ arch/arm64/boot/dts/amlogic/meson-gx.dtsi | 9 + arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 6 + arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 + sound/soc/meson/Kconfig | 14 + sound/soc/meson/Makefile | 7 +- sound/soc/meson/aiu.c | 7 + sound/soc/meson/audin-fifo.c | 367 +++++++++++++++++++++ sound/soc/meson/audin-formatter-i2s.c | 174 ++++++++++ sound/soc/meson/audin.c | 186 +++++++++++ sound/soc/meson/audin.h | 30 ++ sound/soc/meson/gx-card.c | 16 +- 12 files changed, 880 insertions(+), 8 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260831-audin-9cabb450cc94
Best regards,
Signature · 1 line
Valerio Setti <[email protected]>
PATCH v2 1/6 ASoC: dt-bindings: amlogic,gx-audin: add schema
AUDIN provides I2S audio input support to the Meson GX platforms (GXBB/GXL).
Note: GXBB and GXL are not known to differ so the driver binds on the 'amlogic,gx-audin' fallback.
--- .../bindings/sound/amlogic,gx-audin.yaml | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+)
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml new file +66 -0
@@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/amlogic,gx-audin.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic GX AUDIN + +maintainers: + - Valerio Setti <[email protected]> + +description: + AUDIN is the audio input block of the Amlogic GXBB/GXL SoCs. It supports + various input formatters (I2S, SPDIF, PCM, HDMI) feeding three FIFOs that + transfer captured samples to memory. The sound-dai cell selects the FIFO. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + items: + - enum: + - amlogic,gxbb-audin + - amlogic,gxl-audin + - const: amlogic,gx-audin + + reg: + maxItems: 1 + + resets: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: AUDIN peripheral clock + +required: + - compatible + - reg + - resets + - interrupts + - clocks + - "#sound-dai-cells" + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/gxbb-clkc.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/reset/amlogic,meson-gxbb-reset.h> + + audio-controller@a000 { + compatible = "amlogic,gxbb-audin", "amlogic,gx-audin"; + reg = <0xa000 0x148>; + resets = <&reset RESET_AUDIN>; + interrupts = <GIC_SPI 7 IRQ_TYPE_EDGE_RISING>; + sound-name-prefix = "AUDIN"; + #sound-dai-cells = <1>; + clocks = <&clkc CLKID_I2S_SPDIF>; + };
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 1/6] ASoC: dt-bindings: amlogic,gx-audin: add schema
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: amlogic,gx-audin: missing const constraint for #sound-dai-cells --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: amlogic,gx-audin: missing const constraint for #sound-dai-cells --
commit 1813eec5eb42b623e2aae169825ca6cb3dcd09e8
Author: Valerio Setti <[email protected]>
ASoC: dt-bindings: amlogic,gx-audin: add schema
AUDIN provides I2S audio input support to the Meson GX platforms (GXBB/GXL).
Quoted 4 lines
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml line 21
Quoted 5 lines
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml new file +5
-0+allOf: + - $ref: dai-common.yaml# + +properties: + compatible:
[Severity: Low]
Should #sound-dai-cells be explicitly defined here with a const constraint?
The binding requires #sound-dai-cells below, but fails to define it in the properties block with a const constraint. Relying on dai-common.yaml, which only defines it as true (unconstrained), allows invalid configurations with incorrect cell counts (e.g., <0> or <2>) to silently pass validation.
Quoted 5 lines
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml new file +5
-0+ items: + - enum: + - amlogic,gxbb-audin + - amlogic,gxl-audin + - const: amlogic,gx-audin
[ ... ]
Quoted 8 lines
Documentation/devicetree/bindings/sound/amlogic,gx-audin.yaml new file +8
-0+required: + - compatible + - reg + - resets + - interrupts + - clocks + - "#sound-dai-cells" +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 2/6 ASoC: meson: build gx-formatter as a separate module
In reply to Valerio SettiInstead of including it in 'snd-soc-meson-aiu', create a separate module for it. This way it can be independently selected by either AIU or the (upcoming) AUDIN.
--- sound/soc/meson/Kconfig | 5 +++++ sound/soc/meson/Makefile | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-)
sound/soc/meson/Kconfig +5 -0
@@ -2,10 +2,15 @@ menu "Amlogic" depends on ARCH_MESON || (COMPILE_TEST && COMMON_CLK) +config SND_MESON_GX_FORMATTER + tristate + select REGMAP_MMIO + config SND_MESON_AIU tristate "Amlogic AIU" select SND_MESON_CODEC_GLUE select SND_PCM_IEC958 + select SND_MESON_GX_FORMATTER imply SND_SOC_MESON_T9015 imply SND_SOC_HDMI_CODEC if DRM_MESON_DW_HDMI help
sound/soc/meson/Makefile +2 -1
@@ -4,12 +4,12 @@ snd-soc-meson-aiu-y := aiu.o snd-soc-meson-aiu-y += aiu-acodec-ctrl.o snd-soc-meson-aiu-y += aiu-codec-ctrl.o snd-soc-meson-aiu-y += aiu-encoder-i2s.o -snd-soc-meson-aiu-y += gx-formatter.o snd-soc-meson-aiu-y += aiu-formatter-i2s.o snd-soc-meson-aiu-y += aiu-encoder-spdif.o snd-soc-meson-aiu-y += aiu-fifo.o snd-soc-meson-aiu-y += aiu-fifo-i2s.o snd-soc-meson-aiu-y += aiu-fifo-spdif.o +snd-soc-meson-gx-formatter-y := gx-formatter.o snd-soc-meson-axg-fifo-y := axg-fifo.o snd-soc-meson-axg-frddr-y := axg-frddr.o snd-soc-meson-axg-toddr-y := axg-toddr.o
@@ -29,6 +29,7 @@ snd-soc-meson-g12a-tohdmitx-y := g12a-tohdmitx.o snd-soc-meson-t9015-y := t9015.o obj-$(CONFIG_SND_MESON_AIU) += snd-soc-meson-aiu.o +obj-$(CONFIG_SND_MESON_GX_FORMATTER) += snd-soc-meson-gx-formatter.o obj-$(CONFIG_SND_MESON_AXG_FIFO) += snd-soc-meson-axg-fifo.o obj-$(CONFIG_SND_MESON_AXG_FRDDR) += snd-soc-meson-axg-frddr.o obj-$(CONFIG_SND_MESON_AXG_TODDR) += snd-soc-meson-axg-toddr.o
Signature · 1 line
2.47.3
PATCH v2 3/6 ASoC: meson: add AUDIN driver
In reply to Valerio SettiAUDIN provides audio input support to the Amlogic GX based platforms (GXBB/GXL). It is the counterpart of AIU for capture and it strictly follows the same structure:
- It takes the ownership of the entire register range;
- It sets up peripheral clock and handles the reset;
- It adds support for I2S data formatter through a widget;
- It instantiates each of the FIFOs as component's DAI.
Both I2S data formatter and FIFO code live separate files ('audin-formatter-i2s' and 'audin-fifo', respectively) for a better code organization. Unfortunately it wasn't possible to add them as independent devices due to the messy register layout organization that has been implemented by the manufacturer on this platform.
This component could ideally handle multiple input sources (SPDIF, I2S, PCM, HDMI), but for the time being only I2S is added and has been tested.
Note: due to default register configuration, at boot all FIFO input sources are set to "SPDIF". In order to be able to test I2S they must be switched to "I2S". This can easily be achieved with:
$ amixer sset 'AUDIN FIFO0 SRC SEL' 'I2S'
--- sound/soc/meson/Kconfig | 9 + sound/soc/meson/Makefile | 4 + sound/soc/meson/audin-fifo.c | 367 ++++++++++++++++++++++++++++++++++ sound/soc/meson/audin-formatter-i2s.c | 174 ++++++++++++++++ sound/soc/meson/audin.c | 186 +++++++++++++++++ sound/soc/meson/audin.h | 30 +++ 6 files changed, 770 insertions(+)
sound/soc/meson/Kconfig +9 -0
@@ -17,6 +17,14 @@ config SND_MESON_AIU Select Y or M to add support for the Audio output subsystem found in the Amlogic Meson8, Meson8b and GX SoC families +config SND_MESON_AUDIN + tristate "Amlogic AUDIN" + select REGMAP_MMIO + select SND_MESON_GX_FORMATTER + help + Select Y or M to add support for the audio input subsystem found + in the Amlogic GX SoC family. Currently only I2S input is supported. + config SND_MESON_AXG_FIFO tristate select REGMAP_MMIO
@@ -113,6 +121,7 @@ config SND_MESON_GX_SOUND_CARD tristate "Amlogic GX Sound Card Support" select SND_MESON_CARD_UTILS imply SND_MESON_AIU + imply SND_MESON_AUDIN help Select Y or M to add support for the GXBB/GXL SoC sound card
sound/soc/meson/Makefile +4 -0
@@ -10,6 +10,9 @@ snd-soc-meson-aiu-y += aiu-fifo.o snd-soc-meson-aiu-y += aiu-fifo-i2s.o snd-soc-meson-aiu-y += aiu-fifo-spdif.o snd-soc-meson-gx-formatter-y := gx-formatter.o +snd-soc-meson-audin-y := audin.o +snd-soc-meson-audin-y += audin-formatter-i2s.o +snd-soc-meson-audin-y += audin-fifo.o snd-soc-meson-axg-fifo-y := axg-fifo.o snd-soc-meson-axg-frddr-y := axg-frddr.o snd-soc-meson-axg-toddr-y := axg-toddr.o
@@ -30,6 +33,7 @@ snd-soc-meson-t9015-y := t9015.o obj-$(CONFIG_SND_MESON_AIU) += snd-soc-meson-aiu.o obj-$(CONFIG_SND_MESON_GX_FORMATTER) += snd-soc-meson-gx-formatter.o +obj-$(CONFIG_SND_MESON_AUDIN) += snd-soc-meson-audin.o obj-$(CONFIG_SND_MESON_AXG_FIFO) += snd-soc-meson-axg-fifo.o obj-$(CONFIG_SND_MESON_AXG_FRDDR) += snd-soc-meson-axg-frddr.o obj-$(CONFIG_SND_MESON_AXG_TODDR) += snd-soc-meson-axg-toddr.o
sound/soc/meson/audin-fifo.c new file +367 -0
367 lines not on this page · raw message
sound/soc/meson/audin-formatter-i2s.c new file +174 -0
174 lines not on this page · raw message
sound/soc/meson/audin.c new file +186 -0
186 lines not on this page · raw message
sound/soc/meson/audin.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ +/* +* Copyright (c) 2026 BayLibre, SAS. +* Author: Valerio Setti <[email protected]> +*/ + +#ifndef _MESON_AUDIN_H +#define _MESON_AUDIN_H + +#include "gx-formatter.h" + +/* FIFOx CTRL registers and bits */ +#define AUDIN_FIFO_CTRL 0x14 +#define AUDIN_FIFO_CTRL_EN BIT(0) +#define AUDIN_FIFO_CTRL_RST BIT(1) +#define AUDIN_FIFO_CTRL_LOAD BIT(2) +#define AUDIN_FIFO_CTRL_DIN_SEL_OFF 3 +#define AUDIN_FIFO_CTRL_ENDIAN_MASK GENMASK(10, 8) +#define AUDIN_FIFO_CTRL_CHAN_MASK GENMASK(14, 11) +#define AUDIN_FIFO_CTRL_UG BIT(15) + +extern const struct gx_formatter_driver audin_formatter_i2s_drv; + +extern const struct snd_soc_dai_ops audin_fifo_dai_ops; +extern snd_pcm_uframes_t audin_fifo_component_pointer (struct snd_soc_component *component, +struct snd_pcm_substream *substream); +extern int audin_fifo_sync_stop (struct snd_soc_component *component, +struct snd_pcm_substream *substream); + +#endif
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 3/6] ASoC: meson: add AUDIN driver
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] sound/soc/meson: period drift in timer callback due to incorrect last_pos update - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] sound/soc/meson: period drift in timer callback due to incorrect last_pos update
- [Medium] sound/soc/meson: global state pollution due to mutating static widget array
- [Medium] sound/soc/meson: stack overflow in recursive DAPM graph traversal without cycle detection --
commit cc303f24603b3290227ada8353fd36a74cf1a83e
Author: Valerio Setti <[email protected]>
ASoC: meson: add AUDIN driver
AUDIN provides audio input support to the Amlogic GX based platforms (GXBB/GXL). It adds support for I2S data formatter through a widget and instantiates each of the FIFOs as component's DAI.
Quoted 5 lines
sound/soc/meson/audin-fifo.c new file +0
-0
[ ... ]
Quoted 8 lines
sound/soc/meson/audin-fifo.c new file +8
-0+static enum hrtimer_restart audin_fifo_timer_cb (struct hrtimer *timer) +{ +struct audin_fifo_dai_data *data = + container_of(timer, struct audin_fifo_dai_data, polling_timer); +struct snd_pcm_runtime *runtime = data->substream->runtime; +unsigned int curr_pos, delta, sleep_time; + +if (!READ_ONCE (data->running))
sound/soc/meson/audin-fifo.c line 293
Quoted 10 lines
sound/soc/meson/audin-fifo.c new file +10
-0+return HRTIMER_NORESTART ; + + curr_pos =audin_fifo_pos (data->dai, runtime); + delta = (curr_pos >= data->last_pos) ? + curr_pos - data->last_pos : + (runtime->dma_bytes - data->last_pos) + curr_pos; + +/* Report only when the period is completed. */ +if (delta >= data->period_bytes) { + data->last_pos = curr_pos;
[Severity: Medium]
Does setting data->last_pos directly to curr_pos introduce cumulative period drift?
Because the hrtimer callback might be delayed, curr_pos might be past the exact period boundary. Updating the base to curr_pos locks in these scheduling delays, which could cause the reported hw_ptr to desynchronize from actual hardware DMA and lead to audio stuttering or xruns.
Should data->last_pos be incremented by exact multiples of data->period_bytes instead?
Quoted 3 lines
sound/soc/meson/audin-fifo.c new file +3
-0+ delta = delta % data->period_bytes; +snd_pcm_period_elapsed (data->substream); + }
[ ... ]
Quoted 5 lines
sound/soc/meson/audin-formatter-i2s.c new file +0
-0
[ ... ]
Quoted 4 lines
sound/soc/meson/audin-formatter-i2s.c new file +4
-0+static struct snd_soc_dai * +audin_formatter_i2s_get_be (struct snd_soc_dapm_widget *w) +{ +struct snd_soc_dapm_path *p;
sound/soc/meson/audin-formatter-i2s.c line 39
Quoted 10 lines
sound/soc/meson/audin-formatter-i2s.c new file +10
-0+struct snd_soc_dai *be; + +snd_soc_dapm_widget_for_each_source_path (w, p) { +if (!p->connect) +continue ; + +if (p->source->id == snd_soc_dapm_dai_out) +return (struct snd_soc_dai *)p->source->priv; + + be =audin_formatter_i2s_get_be (p->source);
[Severity: Medium]
Can this recursive call lead to a kernel stack overflow if there is a cycle in the DAPM graph?
The traversal using snd_soc_dapm_widget_for_each_source_path() does not appear to track visited nodes or limit the recursion depth. A malformed device tree audio-routing or an unexpected userspace mixer configuration that creates a cycle could trigger infinite recursion when evaluating the graph.
Quoted 6 lines
sound/soc/meson/audin-formatter-i2s.c new file +6
-0+if (be) +return be; + } + +return NULL ; +}
[ ... ]
Quoted 5 lines
sound/soc/meson/audin.c new file +0
-0
[ ... ]
Quoted 5 lines
sound/soc/meson/audin.c new file +5
-0+static struct snd_soc_dapm_widget audin_dapm_widgets[] = { + [AUDIN_WIDGET_I2S_FORMATTER ] = +SND_SOC_DAPM_PGA_E ("I2S Formatter" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 , + gx_formatter_event, + (SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_PRE_PMD )),
[ ... ]
Quoted 7 lines
sound/soc/meson/audin.c new file +7
-0+static int audin_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +void __iomem *mmio; +struct regmap *regmap; +struct clk *clk; +int ret;
[ ... ]
sound/soc/meson/audin.c line 151
Quoted 2 lines
sound/soc/meson/audin.c new file +2
-0+ ret =gx_formatter_create (dev, &audin_dapm_widgets[AUDIN_WIDGET_I2S_FORMATTER ], + &audin_formatter_i2s_drv, regmap);
[Severity: Medium]
Is it safe to mutate the static global audin_dapm_widgets array during device probe?
Looking at gx_formatter_create(), it allocates memory with devm_kzalloc() and assigns it to the widget's priv pointer. If the probe defers, fails later, or if the device is unbound, the devm-managed memory is freed but the static global template retains a dangling pointer.
This could lead to a use-after-free or memory corruption if multiple device instances are probed, as they would be sharing and overwriting the same static widget state.
Quoted 2 lines
sound/soc/meson/audin.c new file +2
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to allocate formatter\n" );
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v2 4/6 ASoC: meson: aiu: add I2S Capture DAI
In reply to Valerio SettiAdd capture stream to CPU_I2S_ENCODER making it able to handle both playback and capture streams. Captured data is formatted from "audin-formatter-i2s" widget, buffered from "audin-fifo" into an internal FIFO and then bulk transmitted into RAM when the FIFO is full.
As for the naming of the stream "I2S Encoder" is kept as base following the same pattern used for the playback stream and with the goal to minimize changes.
Supported format for capture is currently limited to S16_LE because it's the only one that has been tested. According to the manual also S24_LE should be supported, but this is kept as follow-up.
This capture support also takes advantage of the following commits that has recently been merged:
commit df3c987ab3d7 ("ASoC: meson: aiu-encoder-i2s: reflect bs quirk in hw constraints") commit e82159384a50 ("ASoC: meson: aiu-encoder-i2s: use the core symmetric_rate handling")
They ensure bs_quirk and rate symmetry across playback and capture streams.
--- sound/soc/meson/aiu.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/meson/aiu.c +7 -0
@@ -153,6 +153,13 @@ static struct snd_soc_dai_driver aiu_cpu_dai_drv[] = { .rates = SNDRV_PCM_RATE_8000_192000, .formats = AIU_FORMATS, }, + .capture = { + .stream_name = "I2S Encoder Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_8000_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, .ops = &aiu_encoder_i2s_dai_ops, .symmetric_rate = 1, },
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 4/6] ASoC: meson: aiu: add I2S Capture DAI
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] ASoC: meson: permanent clock divider leak in aiu_encoder_i2s_hw_free() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ASoC: meson: permanent clock divider leak in aiu_encoder_i2s_hw_free() --
commit 7076c7f044003c89d276b88e15e27dd0533c4d92
Author: Valerio Setti <[email protected]>
ASoC: meson: aiu: add I2S Capture DAI
This commit adds a capture stream to the CPU_I2S_ENCODER, enabling it to handle both playback and capture streams concurrently. It also formats and buffers the captured data using existing components.
Quoted 5 lines
sound/soc/meson/aiu.c +0
-0
sound/soc/meson/aiu.c static struct snd_soc_dai_driver aiu_cpu_dai_drv[] = { · line 162
Quoted 10 lines
sound/soc/meson/aiu.c +7
-0@@ -153,6 +153,13 @@ static struct snd_soc_dai_driver aiu_cpu_dai_drv[] = { .rates = SNDRV_PCM_RATE_8000_192000, .formats = AIU_FORMATS, }, + .capture = { + .stream_name = "I2S Encoder Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_8000_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + },
[Severity: High]
Does adding this capture stream introduce a permanent clock divider leak when hw_free is explicitly called?
Now that both playback and capture streams can be active simultaneously, snd_soc_dai_active(dai) can evaluate to 2.
In sound/soc/meson/aiu-encoder-i2s.c:aiu_encoder_i2s_hw_free():
if (snd_soc_dai_active(dai) <= 1)
aiu_encoder_i2s_divider_enable(component, 0);If a user opens both streams so snd_soc_dai_active(dai) evaluates to 2, and explicitly calls SNDRV_PCM_IOCTL_HW_FREE before closing them, snd_soc_dai_active(dai) remains 2. This skips disabling the clock divider.
When the streams are subsequently closed, the ALSA core skips invoking hw_free again because the state was already changed to SNDRV_PCM_STATE_OPEN. This would leave the clock divider permanently enabled, potentially draining battery or blocking system suspend.
Quoted 3 lines
sound/soc/meson/aiu.c +0
-0.ops = &aiu_encoder_i2s_dai_ops, .symmetric_rate = 1, },
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v2 4/6] ASoC: meson: aiu: add I2S Capture DAI
Quoted 14 lines
[Severity: High]
Does adding this capture stream introduce a permanent clock divider leak whenhw_freeis explicitly called?Now that both playback and capture streams can be active simultaneously,
snd_soc_dai_active(dai)can evaluate to 2.In sound/soc/meson/aiu-encoder-i2s.c:aiu_encoder_i2s_hw_free():
if (snd_soc_dai_active(dai) <= 1) aiu_encoder_i2s_divider_enable(component, 0);
Quoted 9 lines
If a user opens both streams so
snd_soc_dai_active(dai)evaluates to 2, and explicitly callsSNDRV_PCM_IOCTL_HW_FREEbefore closing them,snd_soc_dai_active(dai)remains 2. This skips disabling the clock divider.When the streams are subsequently closed, the ALSA core skips invoking
hw_freeagain because the state was already changed toSNDRV_PCM_STATE_OPEN. This would leave the clock divider permanently enabled, potentially draining battery or blocking system suspend.
Oh, this seems to be a right claim. I can use 'ts->clk_enabled' for this and gate the call to 'aiu_encoder_i2s_divider_enable' based on what both streams are doing.
Let's wait a bit for other comments (if any) to show up, then I can prepare a v3 to fix this.
Signature · 1 line
Valerio
PATCH v2 5/6 ASoC: meson: gx-card: add support for audin FIFO
In reply to Valerio SettiSlightly modify "gx_card_cpu_identify()" by making the compatible matching string an input parameter. This allows to easily support also AUDIN's FIFO with minimal changes.
--- sound/soc/meson/gx-card.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
sound/soc/meson/gx-card.c +9 -7
@@ -66,10 +66,10 @@ static int gx_card_parse_i2s(struct snd_soc_card *card, }static int gx_card_cpu_identify (struct snd_soc_dai_link_component *c, -char *match) +const char *compatible_match,const char *dai_match) { -if (of_device_is_compatible (c->of_node,DT_PREFIX "aiu" )) { -if (strstr (c->dai_name, match)) +if (of_device_is_compatible (c->of_node, compatible_match)) { +if (strstr (c->dai_name, dai_match))return 1 ; }
@@ -96,21 +96,23 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,if (ret)return ret; -if (gx_card_cpu_identify (dai_link->cpus,"FIFO" )) -return meson_card_set_fe_link (card, dai_link, np, true); +if (gx_card_cpu_identify (dai_link->cpus,DT_PREFIX "aiu" ,"FIFO" )) +return meson_card_set_fe_link (card, dai_link, np, true); +if (gx_card_cpu_identify (dai_link->cpus,DT_PREFIX "gx-audin" ,"FIFO" )) +return meson_card_set_fe_link (card, dai_link, np, false); ret =meson_card_set_be_link (card, dai_link, np);if (ret)return ret;/* Or apply codec to codec params if necessary */ -if (gx_card_cpu_identify (dai_link->cpus,"CODEC CTRL" )) { +if (gx_card_cpu_identify (dai_link->cpus,DT_PREFIX "aiu" ,"CODEC CTRL" )) { dai_link->c2c_params = &codec_params; dai_link->num_c2c_params =1 ; }else { dai_link->no_pcm =1 ;/* Check if the cpu is the i2s encoder and parse i2s data */ -if (gx_card_cpu_identify (dai_link->cpus,"I2S Encoder" )) +if (gx_card_cpu_identify (dai_link->cpus,DT_PREFIX "aiu" ,"I2S Encoder" )) ret =gx_card_parse_i2s (card, np, index); }
Signature · 1 line
2.47.3
PATCH v2 6/6 arm64: dts: amlogic: gx: add AUDIN node
In reply to Valerio SettiAUDIN provides audio input support to Amlogic Meson GXBB/GXL platforms.
What's missing after this to get capture support working is to connect a capture capable codec to the SoC. For example to test these changes an NXP SGTL5000 chip has been connected to an OdroidC2 (Meson GXBB) board using a custom hat board.
The following additions/overlay are required on top of 'amlogic/meson-gxbb-odroidc2.dts' to make that hat board to work:
&sound {
audio-routing = "AUDIN I2S Formatter", "AIU I2S Encoder Capture";
dai-link-1 {
codec-1 {
sound-dai = <&sgtl5000>;
};
};
dai-link-3 {
sound-dai = <&audin 0>;
};
};
&audin {
status = "okay";
};Then, from userspace:
$ amixer sset 'AUDIN FIFO0 SRC SEL' 'I2S'
$ arecord -l # find the "FIFO Capture" device
$ arecord -D hw:0,<N> -f S16_LE -r 48000 -c 2 /tmp/in.wav--- arch/arm64/boot/dts/amlogic/meson-gx.dtsi | 9 +++++++++ arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 6 ++++++ arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 ++++++ 3 files changed, 21 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gx.dtsi +9 -0
@@ -436,6 +436,15 @@ watchdog@98d0 { reg = <0x0 0x098d0 0x0 0x10>; clocks = <&xtal>; }; + + audin: audio-controller@a000 { + compatible = "amlogic,gx-audin"; + reg = <0x0 0xa000 0x0 0x148>; + interrupts = <GIC_SPI 7 IRQ_TYPE_EDGE_RISING>; + sound-name-prefix = "AUDIN"; + #sound-dai-cells = <1>; + status = "disabled"; + }; }; gic: interrupt-controller@c4301000 {
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +6 -0
@@ -84,6 +84,12 @@ &aiu { resets = <&reset RESET_AIU>; }; +&audin { + compatible = "amlogic,gxbb-audin", "amlogic,gx-audin"; + clocks = <&clkc CLKID_I2S_SPDIF>; + resets = <&reset RESET_AUDIN>; +}; + &aobus { pinctrl_aobus: pinctrl@14 { compatible = "amlogic,meson-gxbb-aobus-pinctrl";
arch/arm64/boot/dts/amlogic/meson-gxl.dtsi +6 -0
@@ -100,6 +100,12 @@ &aiu { resets = <&reset RESET_AIU>; }; +&audin { + compatible = "amlogic,gxl-audin", "amlogic,gx-audin"; + clocks = <&clkc CLKID_I2S_SPDIF>; + resets = <&reset RESET_AUDIN>; +}; + &apb { usb2_phy0: phy@78000 { compatible = "amlogic,meson-gxl-usb2-phy";
Signature · 1 line
2.47.3