Skip to contentSkip to conversation

ASoC: meson: gx: add base support for I2S audio input

PATCH In review Valerio Setti 3 participants 22 messages Oct 18 – Nov 25

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

v5 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, a fix for i2s clock divider disabling in aiu-encoder-i2s, DT, bindings and integration with gx-card, the core commit is the 4th 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 v5:
- Take the PCM stream lock in the FIFO polling timer callback and skip re-arming it if a trigger already did so, fixing a race on quick PAUSE_PUSH -> PAUSE_RELEASE transitions. [Sashiko]
- Cancel the FIFO polling timer in the DAI 'shutdown' callback, so the timer is guaranteed to be stopped before the DAI data is freed on driver unbind. [Sashiko]
- Fixed commit message for commit 'ASoC: meson: aiu: add I2S Capture DAI' as requested by Jerome. Since the code is unchanged I kept the 'Reviewed-by' tag.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- Dropped the family compatible 'amlogic,gx-audin'. 'amlogic,gxbb-audin' and 'amlogic,gxl-audin' are now the compatibles for GXBB and GXL SoCs, respectively, with the former also used as fallback for the latter. [Krzysztof]
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Fixed i2s clock divider disabling in 'aiu-encoder-i2s' 'hw_free'. [Sashiko]
- Specified const value of "#sound-dai-cells" property in dt-binding. [Sashiko]
- Advance 'last_pos' by whole periods in the FIFO polling timer to avoid drifting period notifications. [Sashiko]
- Link to v2: https://patch.msgid.link/[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 (7):
ASoC: dt-bindings: add amlogic,gxbb-audin
ASoC: meson: build gx-formatter as a separate module
ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free
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,gxbb-audin.yaml         |  69 ++++
 arch/arm64/boot/dts/amlogic/meson-gx.dtsi          |   9 +
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |   5 +
 arch/arm64/boot/dts/amlogic/meson-gxl.dtsi         |   6 +
 sound/soc/meson/Kconfig                            |  14 +
 sound/soc/meson/Makefile                           |   7 +-
 sound/soc/meson/aiu-encoder-i2s.c                  |  12 +-
 sound/soc/meson/aiu.c                              |   7 +
 sound/soc/meson/audin-fifo.c                       | 392 +++++++++++++++++++++
 sound/soc/meson/audin-formatter-i2s.c              | 174 +++++++++
 sound/soc/meson/audin.c                            | 188 ++++++++++
 sound/soc/meson/audin.h                            |  30 ++
 sound/soc/meson/gx-card.c                          |  16 +-
 13 files changed, 914 insertions(+), 15 deletions(-)

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260831-audin-9cabb450cc94

Best regards,

Signature · 1 line
Valerio Setti <[email protected]>
#1 lore raw

PATCH v5 1/7 ASoC: dt-bindings: add amlogic,gxbb-audin

AUDIN provides I2S audio input support to the Meson GXBB and GXL SoCs.

The AUDIN block on GXL is identical to the GXBB one, so "amlogic,gxl-audin" uses "amlogic,gxbb-audin" as fallback; the SoC-specific compatible is added so that differences can be handled later if any are found.

---
 .../bindings/sound/amlogic,gxbb-audin.yaml         | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +69 -0
new file mode 100644
index 000000000000..4df4796623ed
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/amlogic,gxbb-audin.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic GXBB AUDIN audio input controller
+
+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:
+    oneOf:
+      - const: amlogic,gxbb-audin
+      - items:
+          - const: amlogic,gxl-audin
+          - const: amlogic,gxbb-audin
+
+  reg:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: AUDIN peripheral clock
+
+  "#sound-dai-cells":
+    const: 1
+
+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";
+      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
#2 lore raw

Re: [PATCH v5 1/7] ASoC: dt-bindings: add amlogic,gxbb-audin

Hi Valerio,

Quoted 35 lines · Valerio Setti

AUDIN provides I2S audio input support to the Meson GXBB and GXL SoCs.

The AUDIN block on GXL is identical to the GXBB one, so "amlogic,gxl-audin" uses "amlogic,gxbb-audin" as fallback; the SoC-specific compatible is added so that differences can be handled later if any are found.

---
 .../bindings/sound/amlogic,gxbb-audin.yaml         | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +16 -0
new file mode 100644
index 000000000000..4df4796623ed
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/amlogic,gxbb-audin.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic GXBB AUDIN audio input controller
+
+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.
+

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +10 -0
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,gxbb-audin
+      - items:
+          - const: amlogic,gxl-audin
+          - const: amlogic,gxbb-audin

From what I can tell it's even amlogic,meson8-audin compatible. Although I didn't have the time to test in on hardware yet.

[...]

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 63

Quoted 3 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +3 -0
+    audio-controller@a000 {
+      compatible = "amlogic,gxbb-audin";
+      reg = <0xa000 0x148>;

I believe the audin registers are 0x300 wide.
Both, GXL datasheet [0] page 43 and GXM datasheet [1] page 48 claim that the register area is 0x100 wide.
The last documented register with AUDIN_ prefix is AUDIN_FIFO2_PIO_RDH = 0xb8. The datasheet [0] (page 395) lists register numbers divided by 4, so to get the actual address in the memory map we need to multiply it by 4, which gives 0x2e0.
The 32-bit SoC vendor kernel [2] has a header that states: #define AUDIN_ADDR_END 0x28bf (same as in datasheet, we need to multiply this by 4).

I'm bringing this up because dt-bindings are supposed to be complete. So even if the driver doesn't use a resource yet we're supposed to still describe it.
I don't see any additional resources that we'd need to describe and #sound-dai-cells allows adding the additional SPDIF input later. From what I saw in the registers there's also the possibility to send the input signal to AUDIN but I couldn't find any additional resources we'd need to describe in the dt-bindings for this.

[0] https://dl.khadas.com/products/vim1/datasheet/s905x-datasheet-v0.3.pdf
[1] https://dl.khadas.com/products/vim2/datasheet/s912-datasheet.pdf
[2] https://github.com/endlessm/linux-meson/blob/d6e13c220931110fe676ede6da69fc61a7cb04b6/arch/arm/mach-meson8/include/mach/register.h#L2274

#3 lore raw

Re: [PATCH v5 1/7] ASoC: dt-bindings: add amlogic,gxbb-audin

Hi Martin

Quoted 10 lines

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 26

Quoted 7 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +7 -0
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,gxbb-audin
+      - items:
+          - const: amlogic,gxl-audin
+          - const: amlogic,gxbb-audin

From what I can tell it's even amlogic,meson8-audin compatible.
Although I didn't have the time to test in on hardware yet.

Thanks for catching it!
Any testing is more than welcome. I don't have that board at home and, based on my quick search, it seems not super easy to find one these days.

Quoted 4 lines

[...]

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 63

Quoted 3 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +3 -0
+    audio-controller@a000 {
+      compatible = "amlogic,gxbb-audin";
+      reg = <0xa000 0x148>;
Quoted 10 lines

I believe the audin registers are 0x300 wide.
Both, GXL datasheet [0] page 43 and GXM datasheet [1] page 48 claim that the register area is 0x100 wide.
The last documented register with AUDIN_ prefix is AUDIN_FIFO2_PIO_RDH = 0xb8. The datasheet [0] (page 395) lists register numbers divided by 4, so to get the actual address in the memory map we need to multiply it by 4, which gives 0x2e0.
The 32-bit SoC vendor kernel [2] has a header that states: #define AUDIN_ADDR_END 0x28bf (same as in datasheet, we need to multiply this by 4).

I know that the register layout in these SoC is a bit messy, so let me explain how I got to the 0x148 that I wrote above.

When working at this driver I used the S095 and S905X manuals that I found online, but based on the link you shared for the S912, I would say it's the same when it comes to AUDIN.

Using [0] as reference, the highest register being mentioned in the AUDIN chapter is AUD_RESAMPLE_STATUS whose offset is 0x304 (i.e. 0xc1 * 4). However I noticed that before that there are a lot of registers whose name doesn't start with AUDIN_, but rather with AUDOUT_, PCMOUT_, PCMIN_. The first contiguous block of AUDIN_ stops at AUDIN_FIFO_INT which is 0x148 (= 0x52 * 4). The other AUDIN_ block you mentioned is between AUDIN_FIFO0_PIO_STS (at 0x2c0) and AUDIN_FIFO2_PIO_RDH (at 0x2e0).

Quoted 3 lines

I'm bringing this up because dt-bindings are supposed to be complete. So even if the driver doesn't use a resource yet we're supposed to still describe it.

I perfectly agree with this, but at the same time I thought that including registers which potentially do not belong to AUDIN was dangerous in the other direction, i.e. we cover a too large area that will be hard to use in the future if/when we want to use it and we realize it's really not part of AUDIN.

Quoted 2 lines

I don't see any additional resources that we'd need to describe and #sound-dai-cells allows adding the additional SPDIF input later.

That's exactly why I cut the range at 0x148: that seems to be enough to implement what we need for I2S/SPDIF audio input.

Honestly I don't understand what the second range 0x2c0-0x2e0 stands for as it's not described in the manual. For sake of curiosity I just tried looking into the Hardkernel kernel for Odroid C2 [0] but I didn't find any usage of AUDIN_FIFO0_PIO_xxx registers. So my question is: are we sure we really need them?

[0] https://github.com/hardkernel/linux.git - branch 'odroidc2-3.14.y'

Quoted 9 lines

From what I saw in the registers there's also the possibility to send
the input signal to AUDIN but I couldn't find any additional resources we'd need to describe in the dt-bindings for this.

[0] https://dl.khadas.com/products/vim1/datasheet/s905x-datasheet-v0.3.pdf
[1] https://dl.khadas.com/products/vim2/datasheet/s912-datasheet.pdf
[2] https://github.com/endlessm/linux-meson/blob/d6e13c220931110fe676ede6da69fc61a7cb04b6/arch/arm/mach-meson8/include/mach/register.h#L2274

Best regards,

Signature · 1 line
Valerio
#4 lore raw

Re: [PATCH v5 1/7] ASoC: dt-bindings: add amlogic,gxbb-audin

Hi Valerio,

+Cc Xianwei Zhao, I would appreciate it if you could take some time to help us clarify the questions below (or refer us to a colleague).

Quoted 40 lines · Valerio Setti

Hi Martin

Quoted 10 lines

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 26

Quoted 7 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +7 -0
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,gxbb-audin
+      - items:
+          - const: amlogic,gxl-audin
+          - const: amlogic,gxbb-audin

From what I can tell it's even amlogic,meson8-audin compatible.
Although I didn't have the time to test in on hardware yet.

Thanks for catching it!
Any testing is more than welcome. I don't have that board at home and, based on my quick search, it seems not super easy to find one these days.

Quoted 4 lines

[...]

Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml line 63

Quoted 3 lines
Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file +3 -0
+    audio-controller@a000 {
+      compatible = "amlogic,gxbb-audin";
+      reg = <0xa000 0x148>;
Quoted 10 lines

I believe the audin registers are 0x300 wide.
Both, GXL datasheet [0] page 43 and GXM datasheet [1] page 48 claim that the register area is 0x100 wide.
The last documented register with AUDIN_ prefix is AUDIN_FIFO2_PIO_RDH = 0xb8. The datasheet [0] (page 395) lists register numbers divided by 4, so to get the actual address in the memory map we need to multiply it by 4, which gives 0x2e0.
The 32-bit SoC vendor kernel [2] has a header that states: #define AUDIN_ADDR_END 0x28bf (same as in datasheet, we need to multiply this by 4).

I know that the register layout in these SoC is a bit messy, so let me explain how I got to the 0x148 that I wrote above.

When working at this driver I used the S095 and S905X manuals that I found online, but based on the link you shared for the S912, I would say it's the same when it comes to AUDIN.

Quoted 8 lines

Using [0] as reference, the highest register being mentioned in the AUDIN chapter is AUD_RESAMPLE_STATUS whose offset is 0x304 (i.e. 0xc1 * 4). However I noticed that before that there are a lot of registers whose name doesn't start with AUDIN_, but rather with AUDOUT_, PCMOUT_, PCMIN_.
The first contiguous block of AUDIN_ stops at AUDIN_FIFO_INT which is 0x148 (= 0x52 * 4). The other AUDIN_ block you mentioned is between AUDIN_FIFO0_PIO_STS (at 0x2c0) and AUDIN_FIFO2_PIO_RDH (at 0x2e0).

Your approach is logical. And I have no way of proving my theory. So the question for someone with access to better documentation or the actual hardware description is:
- how big is the AUDIN IP block register space?
- what inputs are routed to the AUDIN IP block that neither Valerio nor I identified so far (one reset line, one clock input, one interrupt)?

Quoted 9 lines
Quoted 3 lines

I'm bringing this up because dt-bindings are supposed to be complete. So even if the driver doesn't use a resource yet we're supposed to still describe it.

I perfectly agree with this, but at the same time I thought that including registers which potentially do not belong to AUDIN was dangerous in the other direction, i.e. we cover a too large area that will be hard to use in the future if/when we want to use it and we realize it's really not part of AUDIN.

My concern is actually that the AUDIN hardware block spans 0x300 (or close to it) and we'll find out later that there's a bit that we need to toggle which is outside of the 0x148 area covered already. Even worse: what if we put another register area after AUDIN and then find out that this theoretical bit sits in the second register area.

Best regards,
Martin

#5 lore raw

PATCH v5 2/7 ASoC: meson: build gx-formatter as a separate module

In reply to Valerio Setti

Instead 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
index d9a730994a2a..4c40bf60dc4e 100644
@@ -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
index f9ec0ebb01f0..1b1fbe8a0458 100644
@@ -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
#7 lore raw

PATCH v5 3/7 ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free

In reply to Valerio Setti

A recent Sashiko review [1] on this code revealed the following problem:

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.

This commit resolves this problem by using the 'clk_enabled' field of 'struct gx_stream'. In particular when 'hw_free()' is called on a stream the code check what is the status of the other stream and then only if both are off the clock divider is disabled.

[1]: https://lore.kernel.org/all/[email protected]/

---

This patch is unchanged compared to v4 because, as I mentioned in my reply [2], based on my understanding the race condition should not happen. In case I missed some corner case please let me know and I'll be glad to fix it.

[2]: https://lore.kernel.org/all/[email protected]/

---
 sound/soc/meson/aiu-encoder-i2s.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
sound/soc/meson/aiu-encoder-i2s.c +5 -7
index 58dce9f08c9d..70ea39c77b32 100644
@@ -219,16 +219,14 @@ static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream,
 				   struct snd_soc_dai *dai)
 {
 	struct gx_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
+	struct gx_stream *other = snd_soc_dai_dma_data_get(dai, !substream->stream);
 	struct snd_soc_component *component = dai->component;
 
-	/*
-	 * If this is the last substream being closed then disable the i2s
-	 * clock divider.
-	 */
-	if (snd_soc_dai_active(dai) <= 1)
-		aiu_encoder_i2s_divider_enable(component, 0);
-
 	if (ts->clk_enabled) {
+		/* Disable the clk divider only if also the other stream is not using it */
+		if (!other || !other->clk_enabled)
+			aiu_encoder_i2s_divider_enable(component, false);
+
 		clk_disable_unprepare(ts->iface->mclk);
 		ts->clk_enabled = false;
 	}
Signature · 1 line
2.47.3
reviewer Reviewed-by on v5 3/7
#8 lore raw

Re: [PATCH v5 3/7] ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free

Quoted 12 lines · Valerio Setti

A recent Sashiko review [1] on this code revealed the following problem:

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 8 lines

This commit resolves this problem by using the 'clk_enabled' field of 'struct gx_stream'. In particular when 'hw_free()' is called on a stream the code check what is the status of the other stream and then only if both are off the clock divider is disabled.

[1]: https://lore.kernel.org/all/[email protected]/

#9 lore raw

PATCH v5 4/7 ASoC: meson: add AUDIN driver

In reply to Valerio Setti

AUDIN 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          | 392 ++++++++++++++++++++++++++++++++++
 sound/soc/meson/audin-formatter-i2s.c | 174 +++++++++++++++
 sound/soc/meson/audin.c               | 188 ++++++++++++++++
 sound/soc/meson/audin.h               |  30 +++
 6 files changed, 797 insertions(+)
sound/soc/meson/Kconfig +9 -0
index 4c40bf60dc4e..9d8589b5a88f 100644
@@ -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
index 1b1fbe8a0458..4af75df0d19b 100644
@@ -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 +392 -0

392 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 +188 -0

188 lines not on this page · raw message

sound/soc/meson/audin.h new file +30 -0
new file mode 100644
index 000000000000..7f3b58a780c0
@@ -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
#10 lore raw

Re: [PATCH v5 4/7] ASoC: meson: add AUDIN driver

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] ASoC: meson: audin: sleeping mutex_lock() in atomic trigger and softirq timer context --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ASoC: meson: audin: sleeping mutex_lock() in atomic trigger and softirq timer context --

commit f3bd154de23b0a57bb8257b40dc479a985fa6c9a
Author: Valerio Setti <[email protected]>

ASoC: meson: add AUDIN driver

This commit adds the AUDIN audio input driver for Amlogic GX platforms (GXBB/GXL), including FIFO capture DAIs and an I2S data formatter widget.

Quoted 5 lines
sound/soc/meson/audin-fifo.c new file +0 -0
new file mode 100644
index 0000000000000..5b254c90c7100

[ ... ]

Quoted 35 lines
sound/soc/meson/audin-fifo.c new file +35 -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_substream *substream = data->substream;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	unsigned int curr_pos;
+	unsigned int delta, elapsed_periods_bytes, extra_bytes, sleep_bytes;
+
+	/*
+	 * Take the stream lock to prevent userspace from issuing a quick
+	 * PAUSE_PUSH -> PAUSE_RELEASE transition while we're running this
+	 * callback. Doing so would cause "hrtimer_forward_now()" to be called
+	 * (see below) while the timer is already enqueued.
+	 */
+	guard(pcm_stream_lock_irqsave)(substream);
+
+	/* Stopped, or a trigger already re-armed the timer while we waited. */
+	if (!READ_ONCE(data->running) || hrtimer_is_queued(timer))
+		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;
+	extra_bytes = delta % data->period_bytes;
+	elapsed_periods_bytes = delta - extra_bytes;
+
+	/* Report only when the period is completed. */
+	if (delta >= data->period_bytes) {
+		data->last_pos = data->last_pos + elapsed_periods_bytes;
+		if (data->last_pos >= runtime->dma_bytes)
+			data->last_pos %= runtime->dma_bytes;
+		snd_pcm_period_elapsed_under_stream_lock(substream);
+	}

[ ... ]

Quoted 5 lines
sound/soc/meson/audin-formatter-i2s.c new file +0 -0
new file mode 100644
index 0000000000000..8bbb5cdb52dc8

[ ... ]

sound/soc/meson/audin-formatter-i2s.c line 56

Quoted 10 lines
sound/soc/meson/audin-formatter-i2s.c new file +10 -0
+static struct gx_stream *
+audin_formatter_i2s_get_stream(struct snd_soc_dapm_widget *w)
+{
+	struct snd_soc_dai *be = audin_formatter_i2s_get_be(w);
+
+	if (!be)
+		return NULL;
+
+	return snd_soc_dai_dma_data_get_capture(be);
+}

[Severity: High]
Does binding the AUDIN formatter to gx_stream lead to sleeping in atomic and softirq contexts during PCM trigger operations?

In audin_fifo_dai_probe(), polling_timer is set up with HRTIMER_MODE_REL_SOFT, so audin_fifo_timer_cb() runs in softirq context and acquires guard(pcm_stream_lock_irqsave)(substream). This requires substream->pcm->nonatomic to be false, otherwise _snd_pcm_stream_lock_irqsave() would attempt to acquire substream->self_group.mutex from softirq context.

However, with nonatomic set to false on the FE and BE substreams, PCM trigger operations hold spin_lock_irqsave on the PCM stream locks (for example via dpcm_be_dai_trigger()). This also occurs in softirq context when an XRUN is detected:

audin_fifo_timer_cb()
-> snd_pcm_period_elapsed_under_stream_lock()

    -> snd_pcm_update_hw_ptr0()
      -> snd_pcm_stop()
        -> dpcm_fe_dai_trigger()
          -> dpcm_be_dai_trigger()
            -> aiu_encoder_i2s_trigger()
              -> gx_stream_stop()

Because audin_formatter_i2s_get_stream() attaches the AUDIN formatter to the backend DAI's struct gx_stream, starting or stopping the capture stream calls aiu_encoder_i2s_trigger() -> gx_stream_start() or gx_stream_stop(), both of which acquire the sleeping mutex ts->lock:

sound/soc/meson/gx-formatter.c:gx_stream_start() {
	mutex_lock(&ts->lock);

	/* Start all the formatters attached to the stream */
	list_for_each_entry(formatter, &ts->formatter_list, list) {
		ret = gx_formatter_enable(formatter);

...
}

sound/soc/meson/gx-formatter.c:gx_stream_stop() {
	mutex_lock(&ts->lock);
	ts->ready = false;

	/* Stop all the formatters attached to the stream */
	list_for_each_entry(formatter, &ts->formatter_list, list) {
		gx_formatter_disable(formatter);
	}

	mutex_unlock(&ts->lock);
}

Won't calling mutex_lock(&ts->lock) while holding the PCM stream spinlocks with interrupts disabled (and from softirq context on XRUN) trigger a sleeping in atomic context bug?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#11 lore raw

Re: [PATCH v5 4/7] ASoC: meson: add AUDIN driver

Quoted 103 lines
Quoted 35 lines
sound/soc/meson/audin-fifo.c new file +35 -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_substream *substream = data->substream;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	unsigned int curr_pos;
+	unsigned int delta, elapsed_periods_bytes, extra_bytes, sleep_bytes;
+
+	/*
+	 * Take the stream lock to prevent userspace from issuing a quick
+	 * PAUSE_PUSH -> PAUSE_RELEASE transition while we're running this
+	 * callback. Doing so would cause "hrtimer_forward_now()" to be called
+	 * (see below) while the timer is already enqueued.
+	 */
+	guard(pcm_stream_lock_irqsave)(substream);
+
+	/* Stopped, or a trigger already re-armed the timer while we waited. */
+	if (!READ_ONCE(data->running) || hrtimer_is_queued(timer))
+		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;
+	extra_bytes = delta % data->period_bytes;
+	elapsed_periods_bytes = delta - extra_bytes;
+
+	/* Report only when the period is completed. */
+	if (delta >= data->period_bytes) {
+		data->last_pos = data->last_pos + elapsed_periods_bytes;
+		if (data->last_pos >= runtime->dma_bytes)
+			data->last_pos %= runtime->dma_bytes;
+		snd_pcm_period_elapsed_under_stream_lock(substream);
+	}

[ ... ]

Quoted 5 lines
sound/soc/meson/audin-formatter-i2s.c new file +0 -0
new file mode 100644
index 0000000000000..8bbb5cdb52dc8

[ ... ]

sound/soc/meson/audin-formatter-i2s.c line 56

Quoted 10 lines
sound/soc/meson/audin-formatter-i2s.c new file +10 -0
+static struct gx_stream *
+audin_formatter_i2s_get_stream(struct snd_soc_dapm_widget *w)
+{
+	struct snd_soc_dai *be = audin_formatter_i2s_get_be(w);
+
+	if (!be)
+		return NULL;
+
+	return snd_soc_dai_dma_data_get_capture(be);
+}

[Severity: High]
Does binding the AUDIN formatter to gx_stream lead to sleeping in atomic and softirq contexts during PCM trigger operations?

In audin_fifo_dai_probe(), polling_timer is set up with HRTIMER_MODE_REL_SOFT, so audin_fifo_timer_cb() runs in softirq context and acquires guard(pcm_stream_lock_irqsave)(substream). This requires substream->pcm->nonatomic to be false, otherwise _snd_pcm_stream_lock_irqsave() would attempt to acquire substream->self_group.mutex from softirq context.

However, with nonatomic set to false on the FE and BE substreams, PCM trigger operations hold spin_lock_irqsave on the PCM stream locks (for example via dpcm_be_dai_trigger()). This also occurs in softirq context when an XRUN is detected:

audin_fifo_timer_cb()
-> snd_pcm_period_elapsed_under_stream_lock()

     -> snd_pcm_update_hw_ptr0()
       -> snd_pcm_stop()
         -> dpcm_fe_dai_trigger()
           -> dpcm_be_dai_trigger()
             -> aiu_encoder_i2s_trigger()
               -> gx_stream_stop()

Because audin_formatter_i2s_get_stream() attaches the AUDIN formatter to the backend DAI's struct gx_stream, starting or stopping the capture stream calls aiu_encoder_i2s_trigger() -> gx_stream_start() or gx_stream_stop(), both of which acquire the sleeping mutex ts->lock:

sound/soc/meson/gx-formatter.c:gx_stream_start() {
	mutex_lock(&ts->lock);

	/* Start all the formatters attached to the stream */
	list_for_each_entry(formatter, &ts->formatter_list, list) {
		ret = gx_formatter_enable(formatter);

...
}

sound/soc/meson/gx-formatter.c:gx_stream_stop() {
	mutex_lock(&ts->lock);
	ts->ready = false;

	/* Stop all the formatters attached to the stream */
	list_for_each_entry(formatter, &ts->formatter_list, list) {
		gx_formatter_disable(formatter);
	}

	mutex_unlock(&ts->lock);
}
Quoted 4 lines

Won't calling mutex_lock(&ts->lock) while holding the PCM stream spinlocks with interrupts disabled (and from softirq context on XRUN) trigger a sleeping in atomic context bug?

The analysis is technically correct, but let me share my analysis first and then gather some feedback.

The issue is not introduced by this series. gx_stream_start() and gx_stream_stop() have been called from aiu_encoder_i2s_trigger() since commit 9335117a221a ("ASoC: meson: aiu-encoder-i2s: prepare for multiple streams"), which is already upstream. GX links are atomic, so the playback path already takes the 'gx_stream->lock' mutex with the PCM stream spinlock held. This patch only extends the same pattern to the capture path.

Now back to the issue. Taking 'gx_stream->lock' mutex in trigger means taking a sleeping lock in atomic context which, of course, cannot sleep. For the sleep to happen it requires the mutex to be contended:
- trigger vs. trigger cannot contend, since dpcm_be_dai_trigger() holds the BE substream lock around the BE trigger, which serializes all calls on the same gx_stream (even with multiple AUDIN FIFOs sharing the BE);
- the formatter attach/detach from the DAPM widget events also takes the mutex. This normally happens in prepare/hw_free, when the stream is not running, but a mixer change (e.g. "FIFOx Input Source" moved away from I2S) powers the formatter down under the DAPM mutex only, while the BE is still running. A trigger on another CPU at that moment (userspace or XRUN) would find the mutex held. However since AUDIN FIFO only supports I2S for now, I don't see a real reason for this switch to happen in practice.

Now the solution. Moving the gx-card links to be nonatomic seems a bit too much intrusive to me. I think the best solution is to change 'gx_stream->lock' to be a spinlock. This is fine for GX formatter because all ops are pure MMIO regmap accesses, so they shouldn't sleep.

Finally the question. As I said, since the issue described by Sashiko seems a bit hard to hit, I think the fix can be postponed to a quick follow-up series. However if reviewers deem that it's absolutely mandatory to fix the issue before this series lands, I will either prepare a small pre-requisite series or add a new commit to this one (I would like to know what's the reviewers preference on this case).

Thanks in advance for the replies! :)

Signature · 1 line
Valerio
#12 lore raw

Re: [PATCH v5 4/7] ASoC: meson: add AUDIN driver

Quoted 7 lines · Valerio Setti

Finally the question. As I said, since the issue described by Sashiko seems a bit hard to hit, I think the fix can be postponed to a quick follow-up series. However if reviewers deem that it's absolutely mandatory to fix the issue before this series lands, I will either prepare a small pre-requisite series or add a new commit to this one (I would like to know what's the reviewers preference on this case).

Never mind, I decided to follow the correct way and sent a separate patch fix for this yesterday night [1] :)
[1] becomes a pre-requisite for this series and, once merged, all Sashiko concerns about this series should be resolved.

Sorry for the noise.

[1] https://lore.kernel.org/linux-sound/20261021-gx-formatter-use-spinlock-v1-1-71ebc9224c03@baylibre.com/

Signature · 1 line
Valerio
#13 lore raw

Re: [PATCH v5 4/7] ASoC: meson: add AUDIN driver

In reply to Valerio Setti

On Sun, Oct 18, 2026 at 12:18 PM Valerio Setti <[email protected]> wrote:
[...]

Quoted 20 lines
sound/soc/meson/audin-fifo.c new file +20 -0
+static int audin_fifo_dai_prepare(struct snd_pcm_substream *substream,
+                                 struct snd_soc_dai *dai)
+{
+       struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
+       struct snd_soc_component *component = dai->component;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       dma_addr_t dma_end = runtime->dma_addr + runtime->dma_bytes - AUDIN_FIFO_LANE_SIZE;
+       unsigned int val;
+
+       data->last_pos = 0;
+
+       /*
+        * Setup memory boundaries.
+        * Note: DMA has a 32-bit mask, so it's OK to take lower 32 bits.
+        */
+       snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_START,
+                               lower_32_bits(runtime->dma_addr));
+       snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_PTR,
+                               lower_32_bits(runtime->dma_addr));
+       snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_END,

sound/soc/meson/audin-fifo.c line 161

Quoted 10 lines
sound/soc/meson/audin-fifo.c new file +10 -0
+                               lower_32_bits(dma_end));
+
+       /* Load new addresses (both LOAD and UG are self-clearing). */
+       val = AUDIN_FIFO_CTRL_LOAD | AUDIN_FIFO_CTRL_UG;
+       snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, val, val);
+
+       /* Reset (RST is self-clearing). */
+       snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
+                                     AUDIN_FIFO_CTRL_RST,
+                                     AUDIN_FIFO_CTRL_RST);

not a problem but a hint in case you experienced some weirdness during testing:
older vendor kernels have a different register write order and also do a retry-reset dance when _PTR and _START don't match: [0]

[0] https://github.com/endlessm/linux-meson/blob/d6e13c220931110fe676ede6da69fc61a7cb04b6/sound/soc/aml/m8/aml_audio_hw.c#L348-L357

#14 lore raw

PATCH v5 5/7 ASoC: meson: aiu: add I2S Capture DAI

In reply to Valerio Setti

Add 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.

---
 sound/soc/meson/aiu.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/meson/aiu.c +7 -0
index 535fbf7c1639..14d0e20a4bd6 100644
@@ -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
reviewer Reviewed-by on v5 5/7
#15 lore raw

Re: [PATCH v5 5/7] ASoC: meson: aiu: add I2S Capture DAI

Quoted 10 lines · Valerio Setti

Add 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.

Quoted 6 lines

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.

#16 lore raw

PATCH v5 6/7 ASoC: meson: gx-card: add support for audin FIFO

In reply to Valerio Setti

Slightly 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
index 932be0a09306..7e9b34e02275 100644
@@ -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 "gxbb-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
#17 lore raw

Re: [PATCH v5 6/7] ASoC: meson: gx-card: add support for audin FIFO

On Sun, Oct 18, 2026 at 12:18 PM Valerio Setti <[email protected]> wrote:
[...]

sound/soc/meson/gx-card.c static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, · line 102

Quoted 2 lines
sound/soc/meson/gx-card.c +2 -0
+       if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "gxbb-audin", "FIFO"))
+               return meson_card_set_fe_link(card, dai_link, np, false);

I suggest using the "audin" prefix. AIU / audin seem close enough on all supported SoCs that we don't need a SoC generation prefix in there to handle this differently.

#18 lore raw

Re: [PATCH v5 6/7] ASoC: meson: gx-card: add support for audin FIFO

Quoted 7 lines · Martin Blumenstingl

On Sun, Oct 18, 2026 at 12:18 PM Valerio Setti <[email protected]> wrote:
[...]

sound/soc/meson/gx-card.c static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, · line 102

Quoted 2 lines
sound/soc/meson/gx-card.c +2 -0
+       if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "gxbb-audin", "FIFO"))
+               return meson_card_set_fe_link(card, dai_link, np, false);

I suggest using the "audin" prefix. AIU / audin seem close enough on all supported SoCs that we don't need a SoC generation prefix in there to handle this differently.

Do you mean using "meson,audin" instead of "meson,gxbb-audin" for the compatible?
If so I'm not sure this is allowed nowadays. As far as I understood "meson,aiu" is a sort of legacy naming. 'writing-binidings.rst' says

"DO use a SoC-specific compatible for all SoC devices [...]"

Signature · 1 line
Valerio
#19 lore raw

Re: [PATCH v5 6/7] ASoC: meson: gx-card: add support for audin FIFO

Quoted 10 lines · Valerio Setti
Quoted 7 lines · Martin Blumenstingl

On Sun, Oct 18, 2026 at 12:18 PM Valerio Setti <[email protected]> wrote:
[...]

sound/soc/meson/gx-card.c static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, · line 102

Quoted 2 lines
sound/soc/meson/gx-card.c +2 -0
+       if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "gxbb-audin", "FIFO"))
+               return meson_card_set_fe_link(card, dai_link, np, false);

I suggest using the "audin" prefix. AIU / audin seem close enough on all supported SoCs that we don't need a SoC generation prefix in there to handle this differently.

Quoted 6 lines

Do you mean using "meson,audin" instead of "meson,gxbb-audin" for the compatible?
If so I'm not sure this is allowed nowadays. As far as I understood "meson,aiu" is a sort of legacy naming. 'writing-binidings.rst' says

"DO use a SoC-specific compatible for all SoC devices [...]"

Let me use an example as I realize that I wasn't very clear:
compatible = "amlogic,gxbb-audin", "amlogic,audin";
Does fulfill the criteria (as far as I understand it). What doesn't work is "amlogic,audin" alone.

The GXL example then would be:
compatible = "amlogic,gxl-audin", "amlogic,gxbb-audin", "amlogic,audin";

And for Meson8/8b (sorry, I didn't get around to testing) I would then use:
compatible = "amlogic,meson8-audin", "amlogic,audin";
compatible = "amlogic,meson8b-audin", "amlogic,meson8-audin", "amlogic,audin";

Best regards,
Martin

#20 lore raw

Re: [PATCH v5 6/7] ASoC: meson: gx-card: add support for audin FIFO

Quoted 16 lines · Martin Blumenstingl
Quoted 15 lines · Valerio Setti
Quoted 7 lines · Martin Blumenstingl

On Sun, Oct 18, 2026 at 12:18 PM Valerio Setti <[email protected]> wrote:
[...]

sound/soc/meson/gx-card.c static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, · line 102

Quoted 2 lines
sound/soc/meson/gx-card.c +2 -0
+       if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "gxbb-audin", "FIFO"))
+               return meson_card_set_fe_link(card, dai_link, np, false);

I suggest using the "audin" prefix. AIU / audin seem close enough on all supported SoCs that we don't need a SoC generation prefix in there to handle this differently.

Do you mean using "meson,audin" instead of "meson,gxbb-audin" for the compatible?
If so I'm not sure this is allowed nowadays. As far as I understood "meson,aiu" is a sort of legacy naming. 'writing-binidings.rst' says

Quoted 5 lines
Quoted 1 line

"DO use a SoC-specific compatible for all SoC devices [...]"

Let me use an example as I realize that I wasn't very clear:

   compatible = "amlogic,gxbb-audin", "amlogic,audin";

Does fulfill the criteria (as far as I understand it). What doesn't work is "amlogic,audin" alone.

This is the thing I'm not sure about: "amlogic,audin" does not seem to include SoC-specific details (in my opinion).

Quoted 8 lines

The GXL example then would be:

   compatible = "amlogic,gxl-audin", "amlogic,gxbb-audin", "amlogic,audin";

And for Meson8/8b (sorry, I didn't get around to testing) I would then use:

   compatible = "amlogic,meson8-audin", "amlogic,audin";
   compatible = "amlogic,meson8b-audin", "amlogic,meson8-audin", "amlogic,audin";

Ok, so if I understand correctly you would like "amlogic,audin" to become a sort of alternative fallback so that:
- meson8 and meson8b do not need to have an "amlogic,gxbb..." compatible as fallback
- the change in 'gx-card.c' is more aligned with what's currently being done for AIU.

Is my understanding correct?

Krzysztof, since you already approved the dt-bindings change in this series (1st commit), what do you think about Martin proposal? If you don't have anything against it, I will add it.

Best regards,

Signature · 1 line
Valerio
#21 lore raw

PATCH v5 7/7 arm64: dts: amlogic: gx: add AUDIN node

In reply to Valerio Setti

AUDIN provides audio input support to Amlogic GXBB/GXL SoCs.

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 (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 | 5 +++++
 arch/arm64/boot/dts/amlogic/meson-gxl.dtsi  | 6 ++++++
 3 files changed, 20 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gx.dtsi +9 -0
index c1d8e81d95cb..2b92a99ab2cb 100644
@@ -436,6 +436,15 @@ watchdog@98d0 {
 				reg = <0x0 0x098d0 0x0 0x10>;
 				clocks = <&xtal>;
 			};
+
+			audin: audio-controller@a000 {
+				compatible = "amlogic,gxbb-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 +5 -0
index a9c830a570cc..8f3c7ca06a3c 100644
@@ -84,6 +84,11 @@ &aiu {
 	resets = <&reset RESET_AIU>;
 };
 
+&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
index d5e0f72892f8..de213c0b63a3 100644
@@ -100,6 +100,12 @@ &aiu {
 	resets = <&reset RESET_AIU>;
 };
 
+&audin {
+	compatible = "amlogic,gxl-audin", "amlogic,gxbb-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