Skip to contentSkip to conversation

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

PATCH Superseded Valerio Setti 4 participants 18 messages Oct 1 – Oct 12

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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 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                       | 371 +++++++++++++++++++++
 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, 893 insertions(+), 15 deletions(-)

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

Best regards,

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

PATCH v4 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
Reviewed-by on v4 1/7
#2 lore raw

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

Quoted 10 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(+)

Best regards,
Krzysztof

#3 lore raw

PATCH v4 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
#5 lore raw

PATCH v4 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]/

---
 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
maintainer
#6 lore raw

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

Quoted 28 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.

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]/

---
 sound/soc/meson/aiu-encoder-i2s.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
sound/soc/meson/aiu-encoder-i2s.c +0 -0
index 58dce9f08c9d..70ea39c77b32 100644

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream, · line 222

Quoted 4 lines
sound/soc/meson/aiu-encoder-i2s.c +1 -0
@@ -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);

Not sure about peeking on the other path like this :/

Quoted 4 lines
sound/soc/meson/aiu-encoder-i2s.c +0 -2
 	struct snd_soc_component *component = dai->component;
 
-	/*
-	 * If this is the last substream being closed then disable the i2s

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream, · line 229

Quoted 10 lines
sound/soc/meson/aiu-encoder-i2s.c +4 -5
-	 * 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);
+

Looks like a race condition is possible here if one stream closes while the other one starts.

I think you need a common structure between the 2 paths (with a counter possibly) and it needs to be protected by a lock.

Quoted 12 lines
sound/soc/meson/aiu-encoder-i2s.c +0 -0
 		clk_disable_unprepare(ts->iface->mclk);
 		ts->clk_enabled = false;
 	}
Signature · 8 lines
-- 
2.47.3


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 1 line
Jerome
#7 lore raw

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

Hi, thanks for the feedback and sorry for the late reply.

Quoted 11 lines

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream, · line 222

Quoted 9 lines
sound/soc/meson/aiu-encoder-i2s.c +1 -0
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);

Not sure about peeking on the other path like this :/

Yeah, I know this is perhaps not the nicest approach, but it's the same one I used for the bs-quirk handling (see the "startup()" and "hw_params()" callbacks). Since there can only be the playback and the capture stream, checking the other stream's "clk_enabled" is equivalent to a user counter in "gx_iface", without adding a second piece of state that has to be kept in sync with it. Is that acceptable to you?

Quoted 18 lines
Quoted 4 lines
sound/soc/meson/aiu-encoder-i2s.c +0 -2
  	struct snd_soc_component *component = dai->component;
 
-	/*
-	 * If this is the last substream being closed then disable the i2s

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream, · line 229

Quoted 10 lines
sound/soc/meson/aiu-encoder-i2s.c +4 -5
-	 * 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);
+

Looks like a race condition is possible here if one stream closes while the other one starts.

Quoted 3 lines

I think you need a common structure between the 2 paths (with a counter possibly) and it needs to be protected by a lock.

I might be wrong, but I'm not sure a race condition can happen while managing these 2 clocks. Here's what I found:
- "iface->mclk" and "i2s_divider" are enabled/disabled on "prepare()"/"hw_free()" respectively.
- when "prepare()"/"hw_free()" are called the framework holds the "card->pcm_mutex".

So when one stream performs one operation, either "prepare()" or "hw_free()", it can read and modify (if needed) "ts->clk_enabled" both for itself and for the other stream safely.

Am I missing something?

Signature · 1 line
Valerio
#8 lore raw

PATCH v4 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          | 371 ++++++++++++++++++++++++++++++++++
 sound/soc/meson/audin-formatter-i2s.c | 174 ++++++++++++++++
 sound/soc/meson/audin.c               | 188 +++++++++++++++++
 sound/soc/meson/audin.h               |  30 +++
 6 files changed, 776 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 +371 -0

371 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
#9 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Race condition in PAUSE_RELEASE corrupts hrtimer state - [High] Use-after-free of hrtimer data…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Race condition in PAUSE_RELEASE corrupts hrtimer state
- [High] Use-after-free of hrtimer data during device unbind
- [Medium] Hardware state loss in AUDIN FIFO during system suspend
--

commit 3526087ac379aa85de8aca3b698b812a10b5da4e
Author: Valerio Setti <[email protected]>

ASoC: meson: add AUDIN driver

AUDIN provides audio input support to the Amlogic GX based platforms (GXBB/GXL). It is the counterpart of AIU for capture and instantiates each of the FIFOs as a component DAI.

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

[ ... ]

Quoted 7 lines
sound/soc/meson/audin-fifo.c new file +7 -0
+static int audin_fifo_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+				  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;
+
+	switch (cmd) {

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

Quoted 10 lines
sound/soc/meson/audin-fifo.c new file +10 -0
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
+					      AUDIN_FIFO_CTRL_EN,
+					      AUDIN_FIFO_CTRL_EN);
+		WRITE_ONCE(data->running, true);
+		hrtimer_start(&data->polling_timer,
+			      audin_fifo_bytes_to_ns(data, data->period_bytes),
+			      HRTIMER_MODE_REL_SOFT);

[Severity: High]
Does this blindly re-enqueue the timer without synchronizing with a potentially running callback?

If a user rapidly toggles SNDRV_PCM_IOCTL_PAUSE, PAUSE_PUSH uses a non-blocking hrtimer_try_to_cancel(). If the timer is running and skips snd_pcm_period_elapsed() (e.g. because delta < period_bytes), it won't take the PCM stream lock and will execute hrtimer_forward_now() concurrently with PAUSE_RELEASE.

PAUSE_RELEASE then blindly calls hrtimer_start(), which enqueues the timer. When the running callback in audin_fifo_timer_cb() reads running=true, it returns HRTIMER_RESTART, resulting in a double enqueue of the same timer which can corrupt the hrtimer rbtree.

Quoted 20 lines
sound/soc/meson/audin-fifo.c new file +20 -0
+		break;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	case SNDRV_PCM_TRIGGER_STOP:
+		WRITE_ONCE(data->running, false);
+		/*
+		 * PCM stream lock is held here. If the timer callback is running
+		 * (i.e. it cannot be stopped) there is also hrtimer_cancel()
+		 * in hw_free().
+		 */
+		hrtimer_try_to_cancel(&data->polling_timer);
+		snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
+					      AUDIN_FIFO_CTRL_EN, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}

[ ... ]

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

Quoted 6 lines
sound/soc/meson/audin-fifo.c new file +6 -0
+static int audin_fifo_dai_remove(struct snd_soc_dai *dai)
+{
+	kfree(snd_soc_dai_dma_data_get_capture(dai));
+
+	return 0;
+}

[Severity: High]
Does this free the DAI data without waiting for the polling timer to finish?

If the driver is unbound while an audio stream is open, the ALSA core triggers a stream stop which uses a non-blocking hrtimer_try_to_cancel(). If the timer callback is running concurrently, it will write to this freed memory.

[ ... ]

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

Quoted 7 lines
sound/soc/meson/audin-fifo.c new file +7 -0
+int audin_fifo_sync_stop(struct snd_soc_component *component, struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
+
+	hrtimer_cancel(&data->polling_timer);

[Severity: High]
Could this deferred callback access the freed data pointer?

If the driver was unbound and audin_fifo_dai_remove() freed the DAI data, when the file descriptor is eventually closed this deferred sync_stop callback will access the freed data pointer to cancel the timer.

Quoted 9 lines
sound/soc/meson/audin-fifo.c new file +4 -0
+	WRITE_ONCE(data->running, false);
+
+	return 0;
+}
sound/soc/meson/audin.c new file +0 -0
new file mode 100644
index 0000000000000..808e7d4fd31a2

[ ... ]

sound/soc/meson/audin.c line 124

Quoted 6 lines
sound/soc/meson/audin.c new file +6 -0
+static const struct regmap_config audin_regmap_cfg = {
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_stride	= 4,
+	.max_register	= 0x148,
+};

[Severity: Medium]
Will hardware state like the channel mask and endianness be lost across system suspend and resume cycles?

ALSA calls the driver's prepare() callback to recover a suspended stream, but not hw_params(). Because this regmap lacks a cache configuration, it cannot automatically restore the register state configured during hw_params() when the system resumes.

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

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

Quoted 6 lines · On Thu 01 Oct 2026 at 16:23, [email protected] wrote:
Quoted 5 lines
sound/soc/meson/audin.c new file +0 -0
new file mode 100644
index 0000000000000..808e7d4fd31a2

[ ... ]

Quoted 10 lines

sound/soc/meson/audin.c line 124

Quoted 6 lines
sound/soc/meson/audin.c new file +6 -0
+static const struct regmap_config audin_regmap_cfg = {
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_stride	= 4,
+	.max_register	= 0x148,
+};

[Severity: Medium]
Will hardware state like the channel mask and endianness be lost across system suspend and resume cycles?

It is a good question but I'd consider this a pre-existing issue, if it is one.

Amlogic audio drivers have seen very little testing, if any, when it comes to suspend/resume, because the suspend support from the platforms them self was very limited too. I have no idea if the situation has improved lately but the subject is definitely not limited to this driver.

IOW, the issue might exist (or not) but I do not think it should be a blocking point ATM.

Quoted 13 lines

ALSA calls the driver's prepare() callback to recover a suspended stream, but not hw_params(). Because this regmap lacks a cache configuration, it cannot automatically restore the register state configured during hw_params() when the system resumes.

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 1 line
Jerome
#11 lore raw

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

In reply to [email protected]
Quoted 28 lines
Quoted 7 lines
sound/soc/meson/audin-fifo.c new file +7 -0
+static int audin_fifo_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+				  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;
+
+	switch (cmd) {

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

Quoted 10 lines
sound/soc/meson/audin-fifo.c new file +10 -0
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
+					      AUDIN_FIFO_CTRL_EN,
+					      AUDIN_FIFO_CTRL_EN);
+		WRITE_ONCE(data->running, true);
+		hrtimer_start(&data->polling_timer,
+			      audin_fifo_bytes_to_ns(data, data->period_bytes),
+			      HRTIMER_MODE_REL_SOFT);

[Severity: High]
Does this blindly re-enqueue the timer without synchronizing with a potentially running callback?

If a user rapidly toggles SNDRV_PCM_IOCTL_PAUSE, PAUSE_PUSH uses a non-blocking hrtimer_try_to_cancel(). If the timer is running and skips snd_pcm_period_elapsed() (e.g. because delta < period_bytes), it won't take the PCM stream lock and will execute hrtimer_forward_now() concurrently with PAUSE_RELEASE.

Quoted 4 lines

PAUSE_RELEASE then blindly calls hrtimer_start(), which enqueues the timer. When the running callback in audin_fifo_timer_cb() reads running=true, it returns HRTIMER_RESTART, resulting in a double enqueue of the same timer which can corrupt the hrtimer rbtree.

This looks correct. I will send an update for this.

Quoted 10 lines

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

Quoted 6 lines
sound/soc/meson/audin-fifo.c new file +6 -0
+static int audin_fifo_dai_remove(struct snd_soc_dai *dai)
+{
+	kfree(snd_soc_dai_dma_data_get_capture(dai));
+
+	return 0;
+}

[Severity: High]
Does this free the DAI data without waiting for the polling timer to finish?

Quoted 4 lines

If the driver is unbound while an audio stream is open, the ALSA core triggers a stream stop which uses a non-blocking hrtimer_try_to_cancel(). If the timer callback is running concurrently, it will write to this freed memory.

This and the following issue look a bit of corner case to me (i.e. unbouding a driver while record is ongoing), but I agree that's a weak point so I will fix it.

Quoted 36 lines

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

Quoted 7 lines
sound/soc/meson/audin-fifo.c new file +7 -0
+int audin_fifo_sync_stop(struct snd_soc_component *component, struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
+
+	hrtimer_cancel(&data->polling_timer);

[Severity: High]
Could this deferred callback access the freed data pointer?

If the driver was unbound and audin_fifo_dai_remove() freed the DAI data, when the file descriptor is eventually closed this deferred sync_stop callback will access the freed data pointer to cancel the timer.

Quoted 9 lines
sound/soc/meson/audin-fifo.c new file +4 -0
+	WRITE_ONCE(data->running, false);
+
+	return 0;
+}
sound/soc/meson/audin.c new file +0 -0
new file mode 100644
index 0000000000000..808e7d4fd31a2

[ ... ]

sound/soc/meson/audin.c line 124

Quoted 6 lines
sound/soc/meson/audin.c new file +6 -0
+static const struct regmap_config audin_regmap_cfg = {
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_stride	= 4,
+	.max_register	= 0x148,
+};

[Severity: Medium]
Will hardware state like the channel mask and endianness be lost across system suspend and resume cycles?

Quoted 4 lines

ALSA calls the driver's prepare() callback to recover a suspended stream, but not hw_params(). Because this regmap lacks a cache configuration, it cannot automatically restore the register state configured during hw_params() when the system resumes.

This was already answered by Jerome [1] (thanks!) so that's out of scope for this series.

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

Signature · 1 line
Valerio
#12 lore raw

PATCH v4 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.

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
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
maintainer Reviewed-by on v4 5/7
#13 lore raw

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

Quoted 5 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.

Quoted 7 lines

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.

---

Quoted 9 lines

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.

I don't think this part of the description is necessary.

Apart from that

Quoted 32 lines
---
 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 · 8 lines
-- 
2.47.3


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 1 line
Jerome
#14 lore raw

PATCH v4 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
#16 lore raw

PATCH v4 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
maintainer Reviewed-by on v4 7/7
#17 lore raw

Re: [PATCH v4 7/7] arm64: dts: amlogic: gx: add AUDIN node

Quoted 28 lines · 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";
    };
Quoted 7 lines

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