Skip to contentSkip to conversation

Add support for AUDIN driver in Amlogic GXBB

RFC PATCH In review Valerio Setti 4 participants 25 messages Apr 11 – Apr 23

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

v2 cover Add support for AUDIN driver in Amlogic GXBB

This series adds support for I2S audio input (AUDIN) on the Amlogic GXBB platform.

It has been largely reshaped compared to what proposed in v1. Instead of adding an HACK commit to allow AIU to export its clock so that also AUDIN can control it, now the design closely follows what was implemented in the Meson AXG platform. "aiu-encoder-i2s" becomes the shared interface for playback/capture and it controls pins and clocks; data formatting is implemented in formatters which are named "aiu-formatter-i2s" and "audin-decoder-i2s" [1].
Formatters are DAPM widgets which are dynamically attached/detached to the streams when the latters starts/stop, respectively.

As of now only I2S input is supported, because it's the only one I could physically test in my setup, but other input sources (ex: SPDIF) are also allowed according to the SOC's manual and can be added in the future.
This series was tested on an OdroidC2 board (Amlogic S905 SOC) with an NXP SGTL5000 codec connected to its I2S input port.

Since this work brings GX platform very close to the AXG one, once this series is accepted, follow up work will be done in order to unify GX and AXG formatters so as to minimize the number of implementations.

The series a bit long and it includes changes to drivers, dt-bindings and device-tree. Of course this only happens because this is an RFC and I wanted to give a full overview of what will be the final design. If no objection is raised, this patch series will be split into 3: one for reshaping AIU and introducing formatters, one to add AUDIN driver and its dt-bindings, one for the device-tree changes.

[1]: Different naming for the aiu part is related to the fact that "aiu-encoder-i2s" is already used for the interface and the goal of this series was to introduce the minimum amount of changes that allow I2S capture to work. Renaming can be implemented in the future as follow up activity.

v1 -> v2:
- Reshaped design so that GX platforms will use the same design pattern of AXG ones. This helped removing the need for an HACK commit.

--
2.39.5

---
Valerio Setti (11):
ASoC: meson: gx: add gx-formatter and gx-interface
ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures
ASoC: meson: aiu: introduce I2S output formatter
ASoC: meson: aiu: use aiu-formatter-i2s to format I2S output data
ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr
ASoC: meson: gx: add AUDIN I2S Decoder driver
ASoC: meson: gx: add AUDIN FIFO driver
ASoC: meson: aiu: add I2S Capture DAI
ASoC: meson: gx-card: add support for AUDIN FIFO
arm64: dts: amlogic: gx: add nodes for AUDIN decoder and FIFO
arm64: dts: amlogic: odroid-c2: add support for I2S audio input

 .../sound/amlogic,meson-gx-audin-decoder-i2s.yaml  |  49 +++
 .../sound/amlogic,meson-gx-audin-fifo.yaml         |  63 +++
 arch/arm64/boot/dts/amlogic/meson-gx.dtsi          |  32 ++
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts |  34 ++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |  26 ++
 sound/soc/meson/Kconfig                            |  17 +
 sound/soc/meson/Makefile                           |   6 +
 sound/soc/meson/aiu-encoder-i2s.c                  | 219 +++++++----
 sound/soc/meson/aiu-formatter-i2s.c                | 106 +++++
 sound/soc/meson/aiu.c                              |  37 +-
 sound/soc/meson/aiu.h                              |   4 +
 sound/soc/meson/audin-decoder-i2s.c                | 218 +++++++++++
 sound/soc/meson/audin-fifo.c                       | 432 +++++++++++++++++++++
 sound/soc/meson/gx-card.c                          |  14 +-
 sound/soc/meson/gx-formatter.c                     | 304 +++++++++++++++
 sound/soc/meson/gx-formatter.h                     |  47 +++
 sound/soc/meson/gx-interface.h                     |  50 +++
 17 files changed, 1567 insertions(+), 91 deletions(-)

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260410-audin-rfc-243bcbf95e43

Best regards,

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

RFC PATCH v2 1/11 ASoC: meson: gx: add gx-formatter and gx-interface

These files are the basic block which allow to shape I2S in GX devices the same as the AXG ones: the DAI backend only controls the interface (i.e. clocks and pins) whereas a formatter takes care of properly formatting the data.

gx-formatter and gx-interface are strongly inspired to axg-tdm-formatter and axg-tdm, respectively. The long term plan is to join the two platforms to use the same formatter solution.

There is only a minor addition here compared to what has been done for AXG and it's "gx_formatter_create()" which is required in order to let already existing AIU code to make use of this formatter without making any devicetree change.

---
 sound/soc/meson/Makefile       |   1 +
 sound/soc/meson/gx-formatter.c | 304 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/meson/gx-formatter.h |  47 +++++++
 sound/soc/meson/gx-interface.h |  50 +++++++
 4 files changed, 402 insertions(+)
sound/soc/meson/Makefile +1 -0
index 24078e4396b02d545d8ba4bcb1632979001354e3..146ec81526ba091a174a113ce3d8412ddbbfd9dd 100644
@@ -4,6 +4,7 @@ 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-encoder-spdif.o
 snd-soc-meson-aiu-y += aiu-fifo.o
 snd-soc-meson-aiu-y += aiu-fifo-i2s.o
sound/soc/meson/gx-formatter.c new file +304 -0

304 lines not on this page · raw message

sound/soc/meson/gx-formatter.h new file +47 -0

47 lines not on this page · raw message

sound/soc/meson/gx-interface.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.39.5
maintainer
#2 lore raw

Re: [PATCH RFC v2 01/11] ASoC: meson: gx: add gx-formatter and gx-interface

sound/soc/meson/gx-formatter.c line 185

Quoted 11 lines · Valerio Setti

These files are the basic block which allow to shape I2S in GX devices the same as the AXG ones: the DAI backend only controls the interface (i.e. clocks and pins) whereas a formatter takes care of properly formatting the data.

sound/soc/meson/gx-formatter.c new file +6 -0
+int gx_formatter_probe(struct platform_device *pdev)
+{
+
+	return snd_soc_register_component(dev, drv->component_drv, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(gx_formatter_probe);

The other allocations in this are devm_ but the component is registered without using devm. Not using devm also means that all the users need remove() functions to unregister the component, there isn't one for AUDIN.

#3 lore raw

RFC PATCH v2 2/11 ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures

In reply to Valerio Setti

Start using gx_iface and gx_stream to store interface and stream info, respectively. probe()/remove() functions are added to allocate/free the gx_stream structures for each PCM stream.

Clock-wise instead of bulk enabling all the clocks on startup and disabling them on shutdown, only the peripheral's internal ones are enabled/disabled in those functions, whereas MCLK and I2S clock divider are handled in hw_params/hw_free.
Interface wide rate symmetry is also enforced here. This is useful when the interface is used for playback and capture at the same time.

Finally a trigger() callback is also added to start/stop the associated I2S data formatter.

---
 sound/soc/meson/aiu-encoder-i2s.c | 163 ++++++++++++++++++++++++++++++++------
 sound/soc/meson/aiu.h             |   3 +
 2 files changed, 141 insertions(+), 25 deletions(-)
sound/soc/meson/aiu-encoder-i2s.c +138 -25
index 3b4061508c18047fe8d6f3f98061720f8ce238f2..76a33878b9df101ad62b18abd8cc14b7908c2c42 100644
@@ -10,6 +10,8 @@
 #include <sound/soc-dai.h>
 
 #include "aiu.h"
+#include "gx-formatter.h"
+#include "gx-interface.h"
 
 #define AIU_I2S_SOURCE_DESC_MODE_8CH	BIT(0)
 #define AIU_I2S_SOURCE_DESC_MODE_24BIT	BIT(5)
@@ -79,7 +81,7 @@ static int aiu_encoder_i2s_setup_desc(struct snd_soc_component *component,
 }
 
 static int aiu_encoder_i2s_set_legacy_div(struct snd_soc_component *component,
-					  struct snd_pcm_hw_params *params,
+					  struct gx_stream *ts,
 					  unsigned int bs)
 {
 	switch (bs) {
@@ -109,7 +111,7 @@ static int aiu_encoder_i2s_set_legacy_div(struct snd_soc_component *component,
 }
 
 static int aiu_encoder_i2s_set_more_div(struct snd_soc_component *component,
-					struct snd_pcm_hw_params *params,
+					struct gx_stream *ts,
 					unsigned int bs)
 {
 	/*
@@ -119,7 +121,7 @@ static int aiu_encoder_i2s_set_more_div(struct snd_soc_component *component,
 	 * increased by 50% to get the correct output rate.
 	 * No idea why !
 	 */
-	if (params_width(params) == 16 && params_channels(params) == 8) {
+	if (ts->width == 16 && ts->channels == 8) {
 		if (bs % 2) {
 			dev_err(component->dev,
 				"Cannot increase i2s divider by 50%%\n");
@@ -142,24 +144,18 @@ static int aiu_encoder_i2s_set_more_div(struct snd_soc_component *component,
 }
 
 static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component,
-				      struct snd_pcm_hw_params *params)
+				      struct gx_stream *ts)
 {
 	struct aiu *aiu = snd_soc_component_get_drvdata(component);
-	unsigned int srate = params_rate(params);
 	unsigned int fs, bs;
 	int ret;
 
 	/* Get the oversampling factor */
-	fs = DIV_ROUND_CLOSEST(clk_get_rate(aiu->i2s.clks[MCLK].clk), srate);
+	fs = DIV_ROUND_CLOSEST(ts->iface->mclk_rate, ts->iface->rate);
 
 	if (fs % 64)
 		return -EINVAL;
 
-	/* Send data MSB first */
-	snd_soc_component_update_bits(component, AIU_I2S_DAC_CFG,
-				      AIU_I2S_DAC_CFG_MSB_FIRST,
-				      AIU_I2S_DAC_CFG_MSB_FIRST);
-
 	/* Set bclk to lrlck ratio */
 	snd_soc_component_update_bits(component, AIU_CODEC_DAC_LRCLK_CTRL,
 				      AIU_CODEC_DAC_LRCLK_CTRL_DIV,
@@ -169,9 +165,9 @@ static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component,
 	bs = fs / 64;
 
 	if (aiu->platform->has_clk_ctrl_more_i2s_div)
-		ret = aiu_encoder_i2s_set_more_div(component, params, bs);
+		ret = aiu_encoder_i2s_set_more_div(component, ts, bs);
 	else
-		ret = aiu_encoder_i2s_set_legacy_div(component, params, bs);
+		ret = aiu_encoder_i2s_set_legacy_div(component, ts, bs);
 
 	if (ret)
 		return ret;
@@ -188,11 +184,15 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 				     struct snd_pcm_hw_params *params,
 				     struct snd_soc_dai *dai)
 {
+	struct gx_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
+	struct gx_iface *iface = ts->iface;
 	struct snd_soc_component *component = dai->component;
 	int ret;
 
-	/* Disable the clock while changing the settings */
-	aiu_encoder_i2s_divider_enable(component, false);
+	iface->rate = params_rate(params);
+	ts->physical_width = params_physical_width(params);
+	ts->width = params_width(params);
+	ts->channels = params_channels(params);
 
 	ret = aiu_encoder_i2s_setup_desc(component, params);
 	if (ret) {
@@ -200,13 +200,17 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
-	ret = aiu_encoder_i2s_set_clocks(component, params);
+	ret = aiu_encoder_i2s_set_clocks(component, ts);
 	if (ret) {
 		dev_err(dai->dev, "setting i2s clocks failed\n");
 		return ret;
 	}
 
-	aiu_encoder_i2s_divider_enable(component, true);
+	ret = gx_stream_set_cont_clocks(ts, iface->fmt);
+	if (ret)
+		dev_err(dai->dev, "failed to apply continuous clock setting\n");
+
+	aiu_encoder_i2s_divider_enable(component, 1);
 
 	return 0;
 }
@@ -214,16 +218,20 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 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 snd_soc_component *component = dai->component;
 
-	aiu_encoder_i2s_divider_enable(component, false);
-
-	return 0;
+	/* This is the last substream open and that is going to be closed. */
+	if (snd_soc_dai_active(dai) <= 1)
+		aiu_encoder_i2s_divider_enable(component, 0);
+	return gx_stream_set_cont_clocks(ts, 0);
 }
 
 static int aiu_encoder_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = dai->component;
+	struct aiu *aiu = snd_soc_component_get_drvdata(component);
+	struct gx_iface *iface = &aiu->i2s.iface;
 	unsigned int inv = fmt & SND_SOC_DAIFMT_INV_MASK;
 	unsigned int val = 0;
 	unsigned int skew;
@@ -255,9 +263,12 @@ static int aiu_encoder_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		skew = 0;
 		break;
 	default:
+		dev_err(dai->dev, "unsupported dai format\n");
 		return -EINVAL;
 	}
 
+	iface->fmt = fmt;
+
 	val |= FIELD_PREP(AIU_CLK_CTRL_LRCLK_SKEW, skew);
 	snd_soc_component_update_bits(component, AIU_CLK_CTRL,
 				      AIU_CLK_CTRL_LRCLK_INVERT |
@@ -284,6 +295,8 @@ static int aiu_encoder_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 	if (ret)
 		dev_err(dai->dev, "Failed to set sysclk to %uHz", freq);
 
+	aiu->i2s.iface.mclk_rate = freq;
+
 	return ret;
 }
 
@@ -298,6 +311,7 @@ static int aiu_encoder_i2s_startup(struct snd_pcm_substream *substream,
 				   struct snd_soc_dai *dai)
 {
 	struct aiu *aiu = snd_soc_component_get_drvdata(dai->component);
+	struct gx_iface *iface = &aiu->i2s.iface;
 	int ret;
 
 	/* Make sure the encoder gets either 2 or 8 channels */
@@ -309,11 +323,40 @@ static int aiu_encoder_i2s_startup(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
-	ret = clk_bulk_prepare_enable(aiu->i2s.clk_num, aiu->i2s.clks);
-	if (ret)
-		dev_err(dai->dev, "failed to enable i2s clocks\n");
+	if (snd_soc_dai_active(dai)) {
+		/* Apply interface wide rate symmetry */
+		ret = snd_pcm_hw_constraint_single(substream->runtime,
+						   SNDRV_PCM_HW_PARAM_RATE,
+						   iface->rate);
+		if (ret < 0)
+			dev_err(dai->dev, "can't set iface rate constraint\n");
+	}
 
-	return ret;
+	/*
+	 * Enable only clocks which are required for the interface internal
+	 * logic. MCLK is enabled/disabled from the formatter and the I2S
+	 * divider is enabled/disabled in "hw_params"/"hw_free", respectively.
+	 */
+	ret = clk_prepare_enable(aiu->i2s.clks[PCLK].clk);
+	if (ret) {
+		dev_err(dai->dev, "failed to enable PCLK\n");
+		return ret;
+	}
+	ret = clk_prepare_enable(aiu->i2s.clks[MIXER].clk);
+	if (ret) {
+		dev_err(dai->dev, "failed to enable MIXER\n");
+		clk_disable_unprepare(aiu->i2s.clks[PCLK].clk);
+		return ret;
+	}
+	ret = clk_prepare_enable(aiu->i2s.clks[AOCLK].clk);
+	if (ret) {
+		dev_err(dai->dev, "failed to enable AOCLK\n");
+		clk_disable_unprepare(aiu->i2s.clks[MIXER].clk);
+		clk_disable_unprepare(aiu->i2s.clks[PCLK].clk);
+		return ret;
+	}
+
+	return 0;
 }
 
 static void aiu_encoder_i2s_shutdown(struct snd_pcm_substream *substream,
@@ -321,14 +364,84 @@ static void aiu_encoder_i2s_shutdown(struct snd_pcm_substream *substream,
 {
 	struct aiu *aiu = snd_soc_component_get_drvdata(dai->component);
 
-	clk_bulk_disable_unprepare(aiu->i2s.clk_num, aiu->i2s.clks);
+	clk_disable_unprepare(aiu->i2s.clks[AOCLK].clk);
+	clk_disable_unprepare(aiu->i2s.clks[MIXER].clk);
+	clk_disable_unprepare(aiu->i2s.clks[PCLK].clk);
+}
+
+static int aiu_encoder_i2s_trigger(struct snd_pcm_substream *substream,
+				   int cmd,
+				   struct snd_soc_dai *dai)
+{
+	struct gx_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
+	int ret;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		ret = gx_stream_start(ts);
+		break;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	case SNDRV_PCM_TRIGGER_STOP:
+		gx_stream_stop(ts);
+		ret = 0;
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static int aiu_encoder_i2s_remove_dai(struct snd_soc_dai *dai)
+{
+	int stream;
+
+	for_each_pcm_streams(stream) {
+		struct gx_stream *ts = snd_soc_dai_dma_data_get(dai, stream);
+
+		if (ts)
+			gx_stream_free(ts);
+	}
+
+	return 0;
+}
+
+static int aiu_encoder_i2s_probe_dai(struct snd_soc_dai *dai)
+{
+	struct aiu *aiu = snd_soc_dai_get_drvdata(dai);
+	struct gx_iface *iface = &aiu->i2s.iface;
+	int stream;
+
+	for_each_pcm_streams(stream) {
+		struct gx_stream *ts;
+
+		if (!snd_soc_dai_get_widget(dai, stream))
+			continue;
+
+		ts = gx_stream_alloc(iface);
+		if (!ts) {
+			aiu_encoder_i2s_remove_dai(dai);
+			return -ENOMEM;
+		}
+		snd_soc_dai_dma_data_set(dai, stream, ts);
+	}
+
+	iface->mclk = aiu->i2s.clks[MCLK].clk;
+
+	return 0;
 }
 
 const struct snd_soc_dai_ops aiu_encoder_i2s_dai_ops = {
+	.probe		= aiu_encoder_i2s_probe_dai,
+	.remove		= aiu_encoder_i2s_remove_dai,
 	.hw_params	= aiu_encoder_i2s_hw_params,
 	.hw_free	= aiu_encoder_i2s_hw_free,
 	.set_fmt	= aiu_encoder_i2s_set_fmt,
 	.set_sysclk	= aiu_encoder_i2s_set_sysclk,
 	.startup	= aiu_encoder_i2s_startup,
 	.shutdown	= aiu_encoder_i2s_shutdown,
+	.trigger	= aiu_encoder_i2s_trigger,
 };
sound/soc/meson/aiu.h +3 -0
index 0f94c8bf608181112d78402532b832eb50c2d409..68310de0bdf7a97d8de2ff306c159248ee9b0ede 100644
@@ -7,6 +7,8 @@
 #ifndef _MESON_AIU_H
 #define _MESON_AIU_H
 
+#include "gx-formatter.h"
+
 struct clk;
 struct clk_bulk_data;
 struct device;
@@ -25,6 +27,7 @@ struct aiu_interface {
 	struct clk_bulk_data *clks;
 	unsigned int clk_num;
 	int irq;
+	struct gx_iface iface;
 };
 
 struct aiu_platform_data {
Signature · 1 line
2.39.5
maintainer
#4 lore raw

Re: [PATCH RFC v2 02/11] ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures

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

Quoted 8 lines · Valerio Setti
sound/soc/meson/aiu-encoder-i2s.c +5 -1
@@ -200,13 +200,17 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 
-	aiu_encoder_i2s_divider_enable(component, true);
+	ret = gx_stream_set_cont_clocks(ts, iface->fmt);
+	if (ret)
+		dev_err(dai->dev, "failed to apply continuous clock setting\n");
+
+	aiu_encoder_i2s_divider_enable(component, 1);

If we're checking the error here we should probably return it as well. Including the error code in the log message is also generally helpful.

Quoted 5 lines
sound/soc/meson/aiu-encoder-i2s.c +1 -0
@@ -214,16 +218,20 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 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);

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

Quoted 10 lines
sound/soc/meson/aiu-encoder-i2s.c +4 -3
 	struct snd_soc_component *component = dai->component;
 
-	aiu_encoder_i2s_divider_enable(component, false);
-
-	return 0;
+	/* This is the last substream open and that is going to be closed. */
+	if (snd_soc_dai_active(dai) <= 1)
+		aiu_encoder_i2s_divider_enable(component, 0);
+	return gx_stream_set_cont_clocks(ts, 0);
 }

Note that we only hw_free() if we preprared, but we enable in hw_params().

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, · line 301

Quoted 8 lines
sound/soc/meson/aiu-encoder-i2s.c +2 -0
@@ -284,6 +295,8 @@ static int aiu_encoder_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 	if (ret)
 		dev_err(dai->dev, "Failed to set sysclk to %uHz", freq);
 
+	aiu->i2s.iface.mclk_rate = freq;
+
 	return ret;
 }

This means we store the new rate even if the set above failed.

maintainer
#5 lore raw

Re: [PATCH RFC v2 02/11] ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures

Quoted 21 lines · Mark Brown

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

Quoted 8 lines · Valerio Setti
sound/soc/meson/aiu-encoder-i2s.c +5 -1
@@ -200,13 +200,17 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 
-	aiu_encoder_i2s_divider_enable(component, true);
+	ret = gx_stream_set_cont_clocks(ts, iface->fmt);
+	if (ret)
+		dev_err(dai->dev, "failed to apply continuous clock setting\n");
+
+	aiu_encoder_i2s_divider_enable(component, 1);

If we're checking the error here we should probably return it as well. Including the error code in the log message is also generally helpful.

Quoted 7 lines
sound/soc/meson/aiu-encoder-i2s.c +1 -0
@@ -214,16 +218,20 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 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 snd_soc_component *component = dai->component;
 
Quoted 11 lines

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

Quoted 8 lines
sound/soc/meson/aiu-encoder-i2s.c +4 -3
-	aiu_encoder_i2s_divider_enable(component, false);
-
-	return 0;
+	/* This is the last substream open and that is going to be closed. */
+	if (snd_soc_dai_active(dai) <= 1)
+		aiu_encoder_i2s_divider_enable(component, 0);
+	return gx_stream_set_cont_clocks(ts, 0);
 }

Note that we only hw_free() if we preprared, but we enable in hw_params().

Huh interresting, I had not thought of that. Valerio and I discussed the clock part a lot for this rework. It is the crux since since the interface and clock setting lives in the AIU subsys but serves both the AIU and AUDIN subsys.

Valerio maybe you could keep function above just to set the rate, but enabling the clocks through a DAPM supply widget ? This is kind of what the AXG is doing.

what do you think ?

(actually in the AXG the each formatter widget call CCF clk_prepare_enable() but a supply widget poking the register would do the same thing)

Quoted 11 lines

sound/soc/meson/aiu-encoder-i2s.c static int aiu_encoder_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, · line 301

Quoted 9 lines
sound/soc/meson/aiu-encoder-i2s.c +2 -0
@@ -284,6 +295,8 @@ static int aiu_encoder_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 	if (ret)
 		dev_err(dai->dev, "Failed to set sysclk to %uHz", freq);
 
+	aiu->i2s.iface.mclk_rate = freq;
+
 	return ret;
 }

This means we store the new rate even if the set above failed.

Signature · 1 line
Jerome
maintainer
#6 lore raw

Re: [PATCH RFC v2 02/11] ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures

Quoted 5 lines · Jerome Brunet

Valerio maybe you could keep function above just to set the rate, but enabling the clocks through a DAPM supply widget ? This is kind of what the AXG is doing.

what do you think ?

FWIW this seems like a sensible plan to me.

#7 lore raw

Re: [PATCH RFC v2 02/11] ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures

In reply to Jerome Brunet
Quoted 10 lines · Jerome Brunet

Huh interresting, I had not thought of that. Valerio and I discussed the clock part a lot for this rework. It is the crux since since the interface and clock setting lives in the AIU subsys but serves both the AIU and AUDIN subsys.

Valerio maybe you could keep function above just to set the rate, but enabling the clocks through a DAPM supply widget ? This is kind of what the AXG is doing.

Quoted 6 lines

what do you think ?

(actually in the AXG the each formatter widget call CCF clk_prepare_enable() but a supply widget poking the register would do the same thing)

Hi Jerome,

thanks for your review and suggestion.
I took some time to investigate it and I think I have a different proposal that reduces the amount of changes compared to the current implementation, but gets to the same result.

The thing is in "axg-tdm-interface.c" MCLK is enabled/disabled using "set_bias_level()" callback which works fine because in that case the interface driver is also a standalone component. On the GX platform the interface is a DAI which is part of the AIU component, so this callback isn't available. To get the same behavior I would need to add a new DAPM widget in "aiu_cpu_dapm_widgets[]" and then add it to both "aiu_cpu_dapm_routes[]" both in "aiu.c" and in the device-tree for AUDIN.

What if instead I add the "prepare()" callback to "aiu_encoder_i2s_dai_ops" and enable MCLK and I2S clock divider there? This would match "hw_free()" calls and it would be a change only internal to "aiu-encoder-i2s.c". To support this I will:
- remove calls to "gx_stream_set_cont_clocks" which are arguably not very useful for the GX platform;
- use the "clk_enabled" field of "struct gx_stream" (unused after removal of "gx_stream_set_cont_clocks" calls) to track the status of MCLK and enable/disable it only when necessary (ex: prevent multiple calls to "prepare" to enable MCLK multiple times, etc);
- keep using "snd_soc_dai_active" in "hw_free" to know when to disable the I2S clock divider. Or perhaps I can rely on "clk_enabled" also for this one so that I can manage these 2 clocks uniformly.

Is this an acceptable alternative approach for you?

Signature · 1 line
Valerio
#8 lore raw

RFC PATCH v2 3/11 ASoC: meson: aiu: introduce I2S output formatter

In reply to Valerio Setti

Introduce aiu-formatter-i2s, a gx_formatter implementation for the AIU I2S playback path. This is going to replace data formatting tasks that are currently being implemented in aiu-encoder-i2s.

This should ideally follow the same design pattern used on the AXG platform (see axg-tdmout), but the problem here is that all playback features (including data formatting) so far are implemented in the AIU component. Getting the full AXG design would mean introducing incompatible device-tree changes. Therefore aiu-formatter-i2s is kept very simple and it only implements the bare minimum functionalities to provide I2S playback formatting. It's not a standalone component though because this is still implemented by AIU.

---
 sound/soc/meson/Makefile            |   1 +
 sound/soc/meson/aiu-formatter-i2s.c | 106 ++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
sound/soc/meson/Makefile +1 -0
index 146ec81526ba091a174a113ce3d8412ddbbfd9dd..f9ec0ebb01f048728b8f85fd8e58fb90df990470 100644
@@ -5,6 +5,7 @@ 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
sound/soc/meson/aiu-formatter-i2s.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.39.5
#9 lore raw

RFC PATCH v2 4/11 ASoC: meson: aiu: use aiu-formatter-i2s to format I2S output data

In reply to Valerio Setti

Create a new DAPM widget for "I2S formatter" and place it on the path between FIFO and output DAI interface. Remove I2S output formatting code from aiu-encoder-i2s since it's now implemented from aiu-formatter-i2s.

---
 sound/soc/meson/aiu-encoder-i2s.c | 56 ---------------------------------------
 sound/soc/meson/aiu.c             | 30 ++++++++++++++++++---
 sound/soc/meson/aiu.h             |  1 +
 3 files changed, 27 insertions(+), 60 deletions(-)
sound/soc/meson/aiu-encoder-i2s.c +0 -56
index 76a33878b9df101ad62b18abd8cc14b7908c2c42..ce28850fde23f4fd1872c4364e13588138ba26ba 100644
@@ -13,13 +13,6 @@
 #include "gx-formatter.h"
 #include "gx-interface.h"
 
-#define AIU_I2S_SOURCE_DESC_MODE_8CH	BIT(0)
-#define AIU_I2S_SOURCE_DESC_MODE_24BIT	BIT(5)
-#define AIU_I2S_SOURCE_DESC_MODE_32BIT	BIT(9)
-#define AIU_I2S_SOURCE_DESC_MODE_SPLIT	BIT(11)
-#define AIU_RST_SOFT_I2S_FAST		BIT(0)
-
-#define AIU_I2S_DAC_CFG_MSB_FIRST	BIT(2)
 #define AIU_CLK_CTRL_I2S_DIV_EN		BIT(0)
 #define AIU_CLK_CTRL_I2S_DIV		GENMASK(3, 2)
 #define AIU_CLK_CTRL_AOCLK_INVERT	BIT(6)
@@ -37,49 +30,6 @@ static void aiu_encoder_i2s_divider_enable(struct snd_soc_component *component,
 				      enable ? AIU_CLK_CTRL_I2S_DIV_EN : 0);
 }
 
-static int aiu_encoder_i2s_setup_desc(struct snd_soc_component *component,
-				      struct snd_pcm_hw_params *params)
-{
-	/* Always operate in split (classic interleaved) mode */
-	unsigned int desc = AIU_I2S_SOURCE_DESC_MODE_SPLIT;
-
-	/* Reset required to update the pipeline */
-	snd_soc_component_write(component, AIU_RST_SOFT, AIU_RST_SOFT_I2S_FAST);
-	snd_soc_component_read(component, AIU_I2S_SYNC);
-
-	switch (params_physical_width(params)) {
-	case 16: /* Nothing to do */
-		break;
-
-	case 32:
-		desc |= (AIU_I2S_SOURCE_DESC_MODE_24BIT |
-			 AIU_I2S_SOURCE_DESC_MODE_32BIT);
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	switch (params_channels(params)) {
-	case 2: /* Nothing to do */
-		break;
-	case 8:
-		desc |= AIU_I2S_SOURCE_DESC_MODE_8CH;
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	snd_soc_component_update_bits(component, AIU_I2S_SOURCE_DESC,
-				      AIU_I2S_SOURCE_DESC_MODE_8CH |
-				      AIU_I2S_SOURCE_DESC_MODE_24BIT |
-				      AIU_I2S_SOURCE_DESC_MODE_32BIT |
-				      AIU_I2S_SOURCE_DESC_MODE_SPLIT,
-				      desc);
-
-	return 0;
-}
-
 static int aiu_encoder_i2s_set_legacy_div(struct snd_soc_component *component,
 					  struct gx_stream *ts,
 					  unsigned int bs)
@@ -194,12 +144,6 @@ static int aiu_encoder_i2s_hw_params(struct snd_pcm_substream *substream,
 	ts->width = params_width(params);
 	ts->channels = params_channels(params);
 
-	ret = aiu_encoder_i2s_setup_desc(component, params);
-	if (ret) {
-		dev_err(dai->dev, "setting i2s desc failed\n");
-		return ret;
-	}
-
 	ret = aiu_encoder_i2s_set_clocks(component, ts);
 	if (ret) {
 		dev_err(dai->dev, "setting i2s clocks failed\n");
sound/soc/meson/aiu.c +26 -4
index f2890111c1d2cfa2213bf01849957a796744b9ae..bb3e0364190766ab4ce9ea3ebd313eecf220a244 100644
@@ -29,13 +29,22 @@ static SOC_ENUM_SINGLE_DECL(aiu_spdif_encode_sel_enum, AIU_I2S_MISC,
 static const struct snd_kcontrol_new aiu_spdif_encode_mux =
 	SOC_DAPM_ENUM("SPDIF Buffer Src", aiu_spdif_encode_sel_enum);
 
-static const struct snd_soc_dapm_widget aiu_cpu_dapm_widgets[] = {
-	SND_SOC_DAPM_MUX("SPDIF SRC SEL", SND_SOC_NOPM, 0, 0,
-			 &aiu_spdif_encode_mux),
+#define AIU_WIDGET_SPDIF_SRC_SEL	0
+#define AIU_WIDGET_I2S_FORMATTER	1
+
+static struct snd_soc_dapm_widget aiu_cpu_dapm_widgets[] = {
+	[AIU_WIDGET_SPDIF_SRC_SEL] =
+		SND_SOC_DAPM_MUX("SPDIF SRC SEL", SND_SOC_NOPM, 0, 0,
+				 &aiu_spdif_encode_mux),
+	[AIU_WIDGET_I2S_FORMATTER] =
+		SND_SOC_DAPM_PGA_E("I2S Formatter", SND_SOC_NOPM, 0, 0, NULL, 0,
+				   gx_formatter_event,
+				   (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD)),
 };
 
 static const struct snd_soc_dapm_route aiu_cpu_dapm_routes[] = {
-	{ "I2S Encoder Playback", NULL, "I2S FIFO Playback" },
+	{ "I2S Formatter", NULL, "I2S FIFO Playback" },
+	{ "I2S Encoder Playback", NULL, "I2S Formatter" },
 	{ "SPDIF SRC SEL", "SPDIF", "SPDIF FIFO Playback" },
 	{ "SPDIF SRC SEL", "I2S", "I2S FIFO Playback" },
 	{ "SPDIF Encoder Playback", NULL, "SPDIF SRC SEL" },
@@ -172,6 +181,11 @@ static const struct regmap_config aiu_regmap_cfg = {
 	.max_register	= 0x2ac,
 };
 
+const struct gx_formatter_driver aiu_formatter_i2s_drv = {
+	.regmap_cfg	= &aiu_regmap_cfg,
+	.ops		= &aiu_formatter_i2s_ops,
+};
+
 static int aiu_clk_bulk_get(struct device *dev,
 			    const char * const *ids,
 			    unsigned int num,
@@ -291,6 +305,14 @@ static int aiu_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	/* Allocate the aiu-formatter into its widget */
+	ret = gx_formatter_create(dev, &aiu_cpu_dapm_widgets[AIU_WIDGET_I2S_FORMATTER],
+				  &aiu_formatter_i2s_drv, map);
+	if (ret) {
+		dev_err(dev, "Failed to allocate aiu formatter\n");
+		return ret;
+	}
+
 	/* Register the hdmi codec control component */
 	ret = aiu_hdmi_ctrl_register_component(dev);
 	if (ret) {
sound/soc/meson/aiu.h +1 -0
index 68310de0bdf7a97d8de2ff306c159248ee9b0ede..7d0b98c1f351b3c526ca06c43a4c04ee5f4b6dfa 100644
@@ -61,6 +61,7 @@ extern const struct snd_soc_dai_ops aiu_fifo_i2s_dai_ops;
 extern const struct snd_soc_dai_ops aiu_fifo_spdif_dai_ops;
 extern const struct snd_soc_dai_ops aiu_encoder_i2s_dai_ops;
 extern const struct snd_soc_dai_ops aiu_encoder_spdif_dai_ops;
+extern const struct gx_formatter_ops aiu_formatter_i2s_ops;
 
 #define AIU_IEC958_BPF			0x000
 #define AIU_958_MISC			0x010
Signature · 1 line
2.39.5
#10 lore raw

RFC PATCH v2 5/11 ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

In reply to Valerio Setti

Add schema for "amlogic,meson-gx-audin-decoder-i2s" and "amlogic,meson-gx-audin-fifo" modules which are used to provide I2S audio input support to the Meson GX platform.

---
 .../sound/amlogic,meson-gx-audin-decoder-i2s.yaml  | 49 +++++++++++++++++
 .../sound/amlogic,meson-gx-audin-fifo.yaml         | 63 ++++++++++++++++++++++
 2 files changed, 112 insertions(+)
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +49 -0
new file mode 100644
index 0000000000000000000000000000000000000000..eaf57603e1ecf5944ffdcf7a1b6146d1a0295696
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/amlogic,meson-gx-audin-decoder-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic GX AUDIN I2S Input Decoder
+
+maintainers:
+  - Valerio Setti <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  $nodename:
+    pattern: "^audio-controller@.*"
+
+  "#sound-dai-cells":
+    const: 0
+
+  compatible:
+    items:
+      - enum:
+          - amlogic,meson-gxbb-audin-decoder-i2s
+      - const: amlogic,meson-gx-audin-decoder-i2s
+
+  reg:
+    maxItems: 1
+
+  sound-name-prefix: true
+
+required:
+  - "#sound-dai-cells"
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    audio-controller@a040 {
+      compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+                   "amlogic,meson-gx-audin-decoder-i2s";
+      #sound-dai-cells = <0>;
+      sound-name-prefix = "AUDIN I2S Decoder";
+      reg = <0xa040 0x4>;
+      status = "disabled";
+    };
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-fifo.yaml new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.39.5
#11 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Quoted 23 lines · Valerio Setti

Add schema for "amlogic,meson-gx-audin-decoder-i2s" and "amlogic,meson-gx-audin-fifo" modules which are used to provide I2S audio input support to the Meson GX platform.

---
 .../sound/amlogic,meson-gx-audin-decoder-i2s.yaml  | 49 +++++++++++++++++
 .../sound/amlogic,meson-gx-audin-fifo.yaml         | 63 ++++++++++++++++++++++
 2 files changed, 112 insertions(+)
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +7 -0
new file mode 100644
index 0000000000000000000000000000000000000000..eaf57603e1ecf5944ffdcf7a1b6146d1a0295696
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/amlogic,meson-gx-audin-decoder-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic GX AUDIN I2S Input Decoder

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 17

Quoted 10 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +10 -0
+
+maintainers:
+  - Valerio Setti <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  $nodename:
+    pattern: "^audio-controller@.*"

Drop

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 26

Quoted 9 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +9 -0
+
+  "#sound-dai-cells":
+    const: 0
+
+  compatible:
+    items:
+      - enum:
+          - amlogic,meson-gxbb-audin-decoder-i2s
+      - const: amlogic,meson-gx-audin-decoder-i2s

Compatible is always the first property.

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 29

Quoted 3 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +3 -0
+
+  reg:
+    maxItems: 1

Reg follows. Please look at DTS coding style or other bindings.

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 31

Quoted 2 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +2 -0
+
+  sound-name-prefix: true

Drop

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 38

Quoted 7 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +7 -0
+
+required:
+  - "#sound-dai-cells"
+  - compatible
+  - reg
+
+additionalProperties: false

unevaluatedProperties

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 47

Quoted 9 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +9 -0
+
+examples:
+  - |
+    audio-controller@a040 {
+      compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+                   "amlogic,meson-gx-audin-decoder-i2s";
+      #sound-dai-cells = <0>;
+      sound-name-prefix = "AUDIN I2S Decoder";
+      reg = <0xa040 0x4>;

One register-wide block? I have doubts this is a separate device

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 48

Quoted 1 line
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +1 -0
+      status = "disabled";

Drop, examples must not be disabled.

Best regards,
Krzysztof

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

#12 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Hi,

thanks for your review and the feedbacks.

Quoted 10 lines

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 47

Quoted 8 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +8 -0
+examples:
+  - |
+    audio-controller@a040 {
+      compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+                   "amlogic,meson-gx-audin-decoder-i2s";
+      #sound-dai-cells = <0>;
+      sound-name-prefix = "AUDIN I2S Decoder";
+      reg = <0xa040 0x4>;

One register-wide block? I have doubts this is a separate device

I understand that this might look as weird configuration, so please let me explain what's going on here.

In this SoC the audio part is split into 2 blocks: AIU for the audio output (already supported in the kernel) and AUDIN for the input (which is what I'm trying to add with this patch series). Unfortunately from the clock management point of view the two of them are not indipendent and interface clocks are in AIU register range. Moreover the two systems are not in a continguous memory range, so creating a single audio component that implements both is not feasible (unless we want to add some dirty tricks with multiple regmaps, etc). This is where the AXG design comes into play: we use the backend DAI provided from AIU for both playback and capture and then we attach formatters (i.e. the audin-decoder-i2s we're discussing about) to properly format the data.
This explains why this is a relatively simple device with very few (1) register. To be noted that for example also similar component on the AXG platform (axg-tdmin.c) claims to have a larger register range, but in fact is almost entirely using the 1st register with only 2 occurences for the 2nd and 3rd. IMHO this is not that different from what I'm trying to achieve in this series for the GX platform.
Also looking at the implementation of "audin-decoder-i2s.c", even though it uses a single register, it really provides functionalities i.e. it's not a useless device and it can also be expanded in the future to support 24-bit sample format.

Then the question might be: why not merging this together with audin-fifo? Becuase these are 3 indipendent instances from the interface and each of which can receive data from the interface. Each of them has its own registers range (and optionally also an interrupt - which is not implemented due the documented limitations in the driver) so the most natural solution here is to implement them as 3 different devices. Of course then none of these should own the data formatter exclusively.

I apologize for the lengthy reply, but I tried to provide you a the full picture to answer your question.

Best regards,

Signature · 7 lines
Valerio


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
#13 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Quoted 15 lines · Valerio Setti

Hi,

thanks for your review and the feedbacks.

Quoted 10 lines

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 47

Quoted 8 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +8 -0
+examples:
+  - |
+    audio-controller@a040 {
+      compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+                   "amlogic,meson-gx-audin-decoder-i2s";
+      #sound-dai-cells = <0>;
+      sound-name-prefix = "AUDIN I2S Decoder";
+      reg = <0xa040 0x4>;

One register-wide block? I have doubts this is a separate device

Quoted 8 lines

I understand that this might look as weird configuration, so please let me explain what's going on here.

In this SoC the audio part is split into 2 blocks: AIU for the audio output (already supported in the kernel) and AUDIN for the input (which is what I'm trying to add with this patch series). Unfortunately from the clock management point of view the two of them are not indipendent and interface clocks are in AIU register range. Moreover the two systems

Two devices of one-register-interface having mixed clock management is a CLEAR sign these are one device.

Quoted 3 lines

are not in a continguous memory range, so creating a single audio component that implements both is not feasible (unless we want to add some dirty tricks with multiple regmaps, etc).

OK, but then what is between these? Again, register ranges ARE NOT 4-bytes wide on a SoC. On several SoCs they are aligned per page or 0x1000 or more. I have no clue how it is here, but 4 bytes is just plain warning sign.

Quoted 6 lines

This is where the AXG design comes into play: we use the backend DAI provided from AIU for both playback and capture and then we attach formatters (i.e. the audin-decoder-i2s we're discussing about) to properly format the data.
This explains why this is a relatively simple device with very few (1) register. To be noted that for example also similar component on the AXG

Quoted 8 lines

platform (axg-tdmin.c) claims to have a larger register range, but in fact is almost entirely using the 1st register with only 2 occurences for the 2nd and 3rd. IMHO this is not that different from what I'm trying to achieve in this series for the GX platform.
Also looking at the implementation of "audin-decoder-i2s.c", even though it uses a single register, it really provides functionalities i.e. it's not a useless device and it can also be expanded in the future to support 24-bit sample format.

I understand it is not useless. I claim this is writing bindings per driver. I claim this is not a correct representation of hardware, because hardware is not a device with 4 bytes of address space.

Quoted 5 lines

Then the question might be: why not merging this together with audin-fifo? Becuase these are 3 indipendent instances from the interface and each of which can receive data from the interface. Each of them has its own registers range (and optionally also an interrupt - which is not

4 bytes is not "registers range". It is one register of someone else's range.

Best regards,
Krzysztof

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

maintainer
#14 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Quoted 19 lines · Krzysztof Kozlowski
Quoted 18 lines · Valerio Setti

Hi,

thanks for your review and the feedbacks.

Quoted 10 lines

Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml line 47

Quoted 8 lines
Documentation/devicetree/bindings/sound/amlogic,meson-gx-audin-decoder-i2s.yaml new file +8 -0
+examples:
+  - |
+    audio-controller@a040 {
+      compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+                   "amlogic,meson-gx-audin-decoder-i2s";
+      #sound-dai-cells = <0>;
+      sound-name-prefix = "AUDIN I2S Decoder";
+      reg = <0xa040 0x4>;

One register-wide block? I have doubts this is a separate device

I understand that this might look as weird configuration, so please let me explain what's going on here.

Quoted 8 lines
Quoted 5 lines

In this SoC the audio part is split into 2 blocks: AIU for the audio output (already supported in the kernel) and AUDIN for the input (which is what I'm trying to add with this patch series). Unfortunately from the clock management point of view the two of them are not indipendent and interface clocks are in AIU register range. Moreover the two systems

Two devices of one-register-interface having mixed clock management is a CLEAR sign these are one device.

That's clear sign they belong to the same subsystem, nodoby has hidden the fact there is a subsystem called "audin", which provide a collection of devices.

Quoted 9 lines
Quoted 4 lines

are not in a continguous memory range, so creating a single audio component that implements both is not feasible (unless we want to add some dirty tricks with multiple regmaps, etc).

OK, but then what is between these? Again, register ranges ARE NOT 4-bytes wide on a SoC. On several SoCs they are aligned per page or 0x1000 or more. I have no clue how it is here, but 4 bytes is just plain warning sign.

On several SoC, more than 0x1000 ?? This is quite an arbitrary limit you are setting here. There is vast number of valid devices in the linux kernel or the bindings than have way less registers than that. We even have devices with no register at all.

I agree that SoC buses are usually at least that long, those are a class of devices, that is certainly not the case for *all* devices.

A device is something that has defined inputs, outputs and function and that can possibly be replicated for more instances.

Quoted 16 lines
Quoted 15 lines

This is where the AXG design comes into play: we use the backend DAI provided from AIU for both playback and capture and then we attach formatters (i.e. the audin-decoder-i2s we're discussing about) to properly format the data.
This explains why this is a relatively simple device with very few (1) register. To be noted that for example also similar component on the AXG platform (axg-tdmin.c) claims to have a larger register range, but in fact is almost entirely using the 1st register with only 2 occurences for the 2nd and 3rd. IMHO this is not that different from what I'm trying to achieve in this series for the GX platform.
Also looking at the implementation of "audin-decoder-i2s.c", even though it uses a single register, it really provides functionalities i.e. it's not a useless device and it can also be expanded in the future to support 24-bit sample format.

Quoted 3 lines

I understand it is not useless. I claim this is writing bindings per driver. I claim this is not a correct representation of hardware, because hardware is not a device with 4 bytes of address space.

This has nothing to do with driver consideration but proper abstraction of the HW tends to produce cleaner architecture, yes.

Quoted 9 lines
Quoted 6 lines

Then the question might be: why not merging this together with audin-fifo? Becuase these are 3 indipendent instances from the interface and each of which can receive data from the interface. Each of them has its own registers range (and optionally also an interrupt - which is not

4 bytes is not "registers range". It is one register of someone else's range.

Yes, exactly like the AXG family which had an "audio bus" with reg and ranges property of length 0x2000, like you are describing, and a collection of smaller devices with very specific and targeted functions, using the range in question.

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/arm64/boot/dts/amlogic/meson-axg.dtsi?h=v6.8#n1317

The registers length of devices in this examples are in then 0x10 to 0x40 length. I honestly do not see the fundamental difference between 1 and 10 regs to define what is a device and what is not.

Quoted 9 lines

Best regards,
Krzysztof

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

Signature · 6 lines
Jerome

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
#15 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Quoted 16 lines · Jerome Brunet
Quoted 10 lines
Quoted 7 lines

Then the question might be: why not merging this together with audin-fifo? Becuase these are 3 indipendent instances from the interface and each of which can receive data from the interface. Each of them has its own registers range (and optionally also an interrupt - which is not

4 bytes is not "registers range". It is one register of someone else's range.

Yes, exactly like the AXG family which had an "audio bus" with reg and ranges property of length 0x2000, like you are describing, and a collection of smaller devices with very specific and targeted functions, using the range in question.

Quoted 5 lines

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/arm64/boot/dts/amlogic/meson-axg.dtsi?h=v6.8#n1317

The registers length of devices in this examples are in then 0x10 to 0x40 length. I honestly do not see the fundamental difference between 1 and 10 regs to define what is a device and what is not.

And that example above is probably also not right if you only looked at register range, but the difference is that you have distinctive other resource - clocks.

And just to remind the old antipattern - each clock is also a "separate" device and there is even old SoC architecture which did it. One clock per device node. Since some years this is not allowed.

This device has no other distinctive resources. Only 4 bytes wide IO range. So let me a bit clarify my previous statements:

A device having only one resource - four bytes MMIO range - and nothing else, and being tightly coupled with other devices, almost certainly is not separate enough to be called a separate device node.

Just like individual clocks are not separate device nodes.

Best regards,
Krzysztof

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

#16 lore raw

Re: [PATCH RFC v2 05/11] ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr

Quoted 27 lines · Krzysztof Kozlowski
Quoted 13 lines
Quoted 7 lines
Quoted 4 lines

Then the question might be: why not merging this together with audin-fifo? Becuase these are 3 indipendent instances from the interface and each of which can receive data from the interface. Each of them has its own registers range (and optionally also an interrupt - which is not

4 bytes is not "registers range". It is one register of someone else's range.

Yes, exactly like the AXG family which had an "audio bus" with reg and ranges property of length 0x2000, like you are describing, and a collection of smaller devices with very specific and targeted functions, using the range in question.

Quoted 5 lines

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/arm64/boot/dts/amlogic/meson-axg.dtsi?h=v6.8#n1317

The registers length of devices in this examples are in then 0x10 to 0x40 length. I honestly do not see the fundamental difference between 1 and 10 regs to define what is a device and what is not.

And that example above is probably also not right if you only looked at register range, but the difference is that you have distinctive other resource - clocks.

And just to remind the old antipattern - each clock is also a "separate" device and there is even old SoC architecture which did it. One clock per device node. Since some years this is not allowed.

Quoted 6 lines

This device has no other distinctive resources. Only 4 bytes wide IO range. So let me a bit clarify my previous statements:

A device having only one resource - four bytes MMIO range - and nothing else, and being tightly coupled with other devices, almost certainly is not separate enough to be called a separate device node.

Wait, I re-checked the manual of this SoC and I realized that I missed a reset line for this formatter device. Sorry for that.
Also I was probably too conservative for the MMIO range because I limited it to cover only the features that I'm using in the driver. However I can extend it further to cover all formatting related registers: they are not used for now in the driver but they might be in the future. This should overcome the above mentioned limitations and qualify the formatter as a standalone device, right?

Signature · 7 lines
Valerio


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
#17 lore raw

RFC PATCH v2 6/11 ASoC: meson: gx: add AUDIN I2S Decoder driver

In reply to Valerio Setti

This driver takes care of formatting I2S data being captured from the I2S interface. Differently from aiu-formatter-i2s this driver implements all the functionalities of a gx_formatter and it fully follows the design proposed in the AXG platform (see axg-tdmin).

---
 sound/soc/meson/Kconfig             |   8 ++
 sound/soc/meson/Makefile            |   2 +
 sound/soc/meson/audin-decoder-i2s.c | 218 ++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
sound/soc/meson/Kconfig +8 -0
index d9a730994a2a2ad315a576981555203b379a212e..0a1d166bed3477efdaffa8538150f7aca33a29e6 100644
@@ -12,6 +12,13 @@ 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_GX_AUDIN_DECODER_I2S
+	tristate "Amlogic GX AUDIN I2S Decoder"
+	imply SND_MESON_AIU
+	help
+	  Select Y or M to add support for the I2S audio input decoder found
+	  in the Amlogic GX SoC family
+
 config SND_MESON_AXG_FIFO
 	tristate
 	select REGMAP_MMIO
@@ -108,6 +115,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_GX_AUDIN_DECODER_I2S
 	help
 	  Select Y or M to add support for the GXBB/GXL SoC sound card
 
sound/soc/meson/Makefile +2 -0
index f9ec0ebb01f048728b8f85fd8e58fb90df990470..a5a8e5b5a3bb8ca8ca0f27e1a29865e0dab64b73 100644
@@ -10,6 +10,7 @@ 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-audin-decoder-i2s-y := audin-decoder-i2s.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 +30,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_AUDIN_DECODER_I2S) += snd-soc-meson-gx-audin-decoder-i2s.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-decoder-i2s.c new file +218 -0

218 lines not on this page · raw message

Signature · 1 line
2.39.5
#18 lore raw

RFC PATCH v2 7/11 ASoC: meson: gx: add AUDIN FIFO driver

In reply to Valerio Setti

Add support for the frontend DAI of the capture interface which is in charge of receiving decoded data from "audin-decoder-i2s" and move them to an internal FIFO before they are block-transferring to RAM.

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.

---
 sound/soc/meson/Kconfig      |   9 +
 sound/soc/meson/Makefile     |   2 +
 sound/soc/meson/audin-fifo.c | 432 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 443 insertions(+)
sound/soc/meson/Kconfig +9 -0
index 0a1d166bed3477efdaffa8538150f7aca33a29e6..50307e54f96fda0f9c114c3bff6aae4094018934 100644
@@ -19,6 +19,14 @@ config SND_MESON_GX_AUDIN_DECODER_I2S
 	  Select Y or M to add support for the I2S audio input decoder found
 	  in the Amlogic GX SoC family
 
+config SND_MESON_GX_AUDIN_FIFO
+	tristate "Amlogic GX AUDIN FIFO"
+	select REGMAP_MMIO
+	imply SND_MESON_AIU
+	help
+	  Select Y or M to add support for the frontend capture interfaces
+	  embedded in the Amlogic GX SoC family
+
 config SND_MESON_AXG_FIFO
 	tristate
 	select REGMAP_MMIO
@@ -116,6 +124,7 @@ config SND_MESON_GX_SOUND_CARD
 	select SND_MESON_CARD_UTILS
 	imply SND_MESON_AIU
 	imply SND_MESON_GX_AUDIN_DECODER_I2S
+	imply SND_MESON_GX_AUDIN_FIFO
 	help
 	  Select Y or M to add support for the GXBB/GXL SoC sound card
 
sound/soc/meson/Makefile +2 -0
index a5a8e5b5a3bb8ca8ca0f27e1a29865e0dab64b73..085ddcdc87639d5d79aa39152eafc030f2643e2e 100644
@@ -11,6 +11,7 @@ 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-audin-decoder-i2s-y := audin-decoder-i2s.o
+snd-soc-meson-gx-audin-fifo-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
@@ -31,6 +32,7 @@ snd-soc-meson-t9015-y := t9015.o
 
 obj-$(CONFIG_SND_MESON_AIU) += snd-soc-meson-aiu.o
 obj-$(CONFIG_SND_MESON_GX_AUDIN_DECODER_I2S) += snd-soc-meson-gx-audin-decoder-i2s.o
+obj-$(CONFIG_SND_MESON_GX_AUDIN_FIFO) += snd-soc-meson-gx-audin-fifo.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 +432 -0

432 lines not on this page · raw message

Signature · 1 line
2.39.5
#19 lore raw

RFC PATCH v2 8/11 ASoC: meson: aiu: add I2S Capture DAI

In reply to Valerio Setti

Add capture stream to CPU_I2S_ENCODER. This is the final step to add support for I2S capture following the recent addition of "audin-decoder-i2s" and "audin-fifo".

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.

---
 sound/soc/meson/aiu.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/meson/aiu.c +7 -0
index bb3e0364190766ab4ce9ea3ebd313eecf220a244..2b6b94957b051976191d9b1e0dbdb4ca01ba2a94 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,
 	},
 	[CPU_SPDIF_ENCODER] = {
Signature · 1 line
2.39.5
#20 lore raw

RFC PATCH v2 9/11 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 "meson-gx-audin-fifo" with minimal changes.

---
 sound/soc/meson/gx-card.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
sound/soc/meson/gx-card.c +8 -6
index b408cc2bbc9193ae56d02b4fcd05af8df3f93d80..1e48dbbf7324dfa6ca66026d944422dadf4204c0 100644
@@ -65,10 +65,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)
+				char *compatible_match, 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;
 	}
 
@@ -94,21 +94,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"))
+	if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "aiu", "FIFO"))
 		return  meson_card_set_fe_link(card, dai_link, np, true);
+	else if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "meson-gx-audin-fifo", "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.39.5
#21 lore raw

RFC PATCH v2 10/11 arm64: dts: amlogic: gx: add nodes for AUDIN decoder and FIFO

In reply to Valerio Setti

Adding nodes for "amlogic,meson-gx-audin-decoder-i2s" and "amlogic,meson-gx-audin-fifo". These provide support for I2S capture on the GX platform.

---
 arch/arm64/boot/dts/amlogic/meson-gx.dtsi   | 32 +++++++++++++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 26 +++++++++++++++++++++++
 2 files changed, 58 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gx.dtsi +32 -0
index c1d8e81d95cb9b7758d8d12c230be13d4311e5e4..411b3e82f3ce1e535a23d9966ba82099d5be2282 100644
@@ -331,6 +331,38 @@ aiu: audio-controller@5400 {
 				status = "disabled";
 			};
 
+			audin_decoder_i2s: audio-controller@a040 {
+				compatible = "amlogic,meson-gx-audin-decoder-i2s";
+				#sound-dai-cells = <0>;
+				sound-name-prefix = "AUDIN I2S Decoder";
+				reg = <0x0 0xa040 0x0 0x4>;
+				status = "disabled";
+			};
+
+			audin_fifo0: audio-controller@a080 {
+				compatible = "amlogic,meson-gx-audin-fifo";
+				#sound-dai-cells = <0>;
+				sound-name-prefix = "AUDIN FIFO0";
+				reg = <0x0 0xa080 0x0 0x1c>;
+				status = "disabled";
+			};
+
+			audin_fifo1: audio-controller@a0cc {
+				compatible = "amlogic,meson-gx-audin-fifo";
+				#sound-dai-cells = <0>;
+				sound-name-prefix = "AUDIN FIFO1";
+				reg = <0x0 0xa0cc 0x0 0x1c>;
+				status = "disabled";
+			};
+
+			audin_fifo2: audio-controller@a114 {
+				compatible = "amlogic,meson-gx-audin-fifo";
+				#sound-dai-cells = <0>;
+				sound-name-prefix = "AUDIN FIFO2";
+				reg = <0x0 0xa114 0x0 0x1c>;
+				status = "disabled";
+			};
+
 			uart_A: serial@84c0 {
 				compatible = "amlogic,meson-gx-uart";
 				reg = <0x0 0x84c0 0x0 0x18>;
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +26 -0
index a9c830a570cc6cd2875553fa9b0e3ef72a2f6478..71a47aa4c2fc72195386a11c905723b3c6f6943c 100644
@@ -84,6 +84,32 @@ &aiu {
 	resets = <&reset RESET_AIU>;
 };
 
+&audin_decoder_i2s {
+	compatible = "amlogic,meson-gxbb-audin-decoder-i2s",
+		     "amlogic,meson-gx-audin-decoder-i2s";
+};
+
+&audin_fifo0 {
+	compatible = "amlogic,meson-gxbb-audin-fifo",
+		     "amlogic,meson-gx-audin-fifo";
+	clocks = <&clkc CLKID_I2S_SPDIF>;
+	clock-names = "i2s_input_clk";
+};
+
+&audin_fifo1 {
+	compatible = "amlogic,meson-gxbb-audin-fifo",
+		     "amlogic,meson-gx-audin-fifo";
+	clocks = <&clkc CLKID_I2S_SPDIF>;
+	clock-names = "i2s_input_clk";
+};
+
+&audin_fifo2 {
+	compatible = "amlogic,meson-gxbb-audin-fifo",
+		     "amlogic,meson-gx-audin-fifo";
+	clocks = <&clkc CLKID_I2S_SPDIF>;
+	clock-names = "i2s_input_clk";
+};
+
 &aobus {
 	pinctrl_aobus: pinctrl@14 {
 		compatible = "amlogic,meson-gxbb-aobus-pinctrl";
Signature · 1 line
2.39.5
#22 lore raw

RFC PATCH v2 11/11 arm64: dts: amlogic: odroid-c2: add support for I2S audio input

In reply to Valerio Setti

- Enable AUDIN I2S decoder and all FIFO components;
- Add AUDIN I2S Decoder as AUX device to the GX sound card;
- Add AUDIN Capture frontend DAIs in the GX sound card;
- Add I2S input data routing to the GX sound card.

Note: in the routing part, usage of "AIU I2S Encoder Capture" as source for "AUDIN I2S Decoder IN" is fine (despite the Encoder/Decoder mismatch). This belong to the fact that the interface is implemented by "AIU I2S Encoder", which was already existing (and named) before the AUDIN addition.

---
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +34 -0
index 5943bc810678edc81fe1a8e3eeae69786e27010c..54798e5b631fdc594cabc5876ab73a3a85944ab0 100644
@@ -188,6 +188,12 @@ sound {
 				       <270950400>,
 				       <393216000>;
 
+		audio-aux-devs = <&audin_decoder_i2s>;
+		audio-routing = "AUDIN I2S Decoder IN", "AIU I2S Encoder Capture",
+				"AUDIN FIFO0 I2S IN", "AUDIN I2S Decoder OUT",
+				"AUDIN FIFO1 I2S IN", "AUDIN I2S Decoder OUT",
+				"AUDIN FIFO2 I2S IN", "AUDIN I2S Decoder OUT";
+
 		dai-link-0 {
 			sound-dai = <&aiu AIU_CPU CPU_I2S_FIFO>;
 		};
@@ -209,6 +215,18 @@ codec-0 {
 				sound-dai = <&hdmi_tx>;
 			};
 		};
+
+		dai-link-3 {
+			sound-dai = <&audin_fifo0>;
+		};
+
+		dai-link-4 {
+			sound-dai = <&audin_fifo1>;
+		};
+
+		dai-link-5 {
+			sound-dai = <&audin_fifo2>;
+		};
 	};
 };
 
@@ -216,6 +234,22 @@ &aiu {
 	status = "okay";
 };
 
+&audin_decoder_i2s {
+	status = "okay";
+};
+
+&audin_fifo0 {
+	status = "okay";
+};
+
+&audin_fifo1 {
+	status = "okay";
+};
+
+&audin_fifo2 {
+	status = "okay";
+};
+
 &cec_AO {
 	status = "okay";
 	pinctrl-0 = <&ao_cec_pins>;
Signature · 1 line
2.39.5
maintainer Reviewed-by on the v2 series
#23 lore raw
In reply to Valerio Setti
Quoted 31 lines · Valerio Setti

This series adds support for I2S audio input (AUDIN) on the Amlogic GXBB platform.

It has been largely reshaped compared to what proposed in v1. Instead of adding an HACK commit to allow AIU to export its clock so that also AUDIN can control it, now the design closely follows what was implemented in the Meson AXG platform. "aiu-encoder-i2s" becomes the shared interface for playback/capture and it controls pins and clocks; data formatting is implemented in formatters which are named "aiu-formatter-i2s" and "audin-decoder-i2s" [1].
Formatters are DAPM widgets which are dynamically attached/detached to the streams when the latters starts/stop, respectively.

As of now only I2S input is supported, because it's the only one I could physically test in my setup, but other input sources (ex: SPDIF) are also allowed according to the SOC's manual and can be added in the future.
This series was tested on an OdroidC2 board (Amlogic S905 SOC) with an NXP SGTL5000 codec connected to its I2S input port.

Since this work brings GX platform very close to the AXG one, once this series is accepted, follow up work will be done in order to unify GX and AXG formatters so as to minimize the number of implementations.

The series a bit long and it includes changes to drivers, dt-bindings and device-tree. Of course this only happens because this is an RFC and I wanted to give a full overview of what will be the final design. If no objection is raised, this patch series will be split into 3: one for reshaping AIU and introducing formatters, one to add AUDIN driver and its dt-bindings, one for the device-tree changes.

Quoted 5 lines

[1]: Different naming for the aiu part is related to the fact that "aiu-encoder-i2s" is already used for the interface and the goal of this series was to introduce the minimum amount of changes that allow I2S capture to work. Renaming can be implemented in the future as follow up activity.

Thanks a lot for this awesome work Valerio. I know this was a lot of effort. With Mark and Krzysztof comments addressed

For the next revision, I think you can drop the RFC tag and split the series.

You have spent a lot of time studying the existing amlogic audio driver support. If you feel like it, you could add yourself as a reviewer or maintainer of the Amlogic audio drivers. :)

Quoted 45 lines

v1 -> v2:
- Reshaped design so that GX platforms will use the same design pattern of AXG ones. This helped removing the need for an HACK commit.

--
2.39.5

---
Valerio Setti (11):
ASoC: meson: gx: add gx-formatter and gx-interface
ASoC: meson: aiu-encoder-i2s: use gx_iface and gx_stream structures
ASoC: meson: aiu: introduce I2S output formatter
ASoC: meson: aiu: use aiu-formatter-i2s to format I2S output data
ASoC: dt-bindings: amlogic: add schema for audin-formatter and audin-toddr
ASoC: meson: gx: add AUDIN I2S Decoder driver
ASoC: meson: gx: add AUDIN FIFO driver
ASoC: meson: aiu: add I2S Capture DAI
ASoC: meson: gx-card: add support for AUDIN FIFO
arm64: dts: amlogic: gx: add nodes for AUDIN decoder and FIFO
arm64: dts: amlogic: odroid-c2: add support for I2S audio input

 .../sound/amlogic,meson-gx-audin-decoder-i2s.yaml  |  49 +++
 .../sound/amlogic,meson-gx-audin-fifo.yaml         |  63 +++
 arch/arm64/boot/dts/amlogic/meson-gx.dtsi          |  32 ++
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts |  34 ++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |  26 ++
 sound/soc/meson/Kconfig                            |  17 +
 sound/soc/meson/Makefile                           |   6 +
 sound/soc/meson/aiu-encoder-i2s.c                  | 219 +++++++----
 sound/soc/meson/aiu-formatter-i2s.c                | 106 +++++
 sound/soc/meson/aiu.c                              |  37 +-
 sound/soc/meson/aiu.h                              |   4 +
 sound/soc/meson/audin-decoder-i2s.c                | 218 +++++++++++
 sound/soc/meson/audin-fifo.c                       | 432 +++++++++++++++++++++
 sound/soc/meson/gx-card.c                          |  14 +-
 sound/soc/meson/gx-formatter.c                     | 304 +++++++++++++++
 sound/soc/meson/gx-formatter.h                     |  47 +++
 sound/soc/meson/gx-interface.h                     |  50 +++
 17 files changed, 1567 insertions(+), 91 deletions(-)

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260410-audin-rfc-243bcbf95e43

Best regards,

Signature · 1 line
Jerome
#24 lore raw
Quoted 33 lines · Jerome Brunet
Quoted 31 lines · Valerio Setti

This series adds support for I2S audio input (AUDIN) on the Amlogic GXBB platform.

It has been largely reshaped compared to what proposed in v1. Instead of adding an HACK commit to allow AIU to export its clock so that also AUDIN can control it, now the design closely follows what was implemented in the Meson AXG platform. "aiu-encoder-i2s" becomes the shared interface for playback/capture and it controls pins and clocks; data formatting is implemented in formatters which are named "aiu-formatter-i2s" and "audin-decoder-i2s" [1].
Formatters are DAPM widgets which are dynamically attached/detached to the streams when the latters starts/stop, respectively.

As of now only I2S input is supported, because it's the only one I could physically test in my setup, but other input sources (ex: SPDIF) are also allowed according to the SOC's manual and can be added in the future.
This series was tested on an OdroidC2 board (Amlogic S905 SOC) with an NXP SGTL5000 codec connected to its I2S input port.

Since this work brings GX platform very close to the AXG one, once this series is accepted, follow up work will be done in order to unify GX and AXG formatters so as to minimize the number of implementations.

The series a bit long and it includes changes to drivers, dt-bindings and device-tree. Of course this only happens because this is an RFC and I wanted to give a full overview of what will be the final design. If no objection is raised, this patch series will be split into 3: one for reshaping AIU and introducing formatters, one to add AUDIN driver and its dt-bindings, one for the device-tree changes.

Quoted 9 lines
Quoted 5 lines

[1]: Different naming for the aiu part is related to the fact that "aiu-encoder-i2s" is already used for the interface and the goal of this series was to introduce the minimum amount of changes that allow I2S capture to work. Renaming can be implemented in the future as follow up activity.

Thanks a lot for this awesome work Valerio. I know this was a lot of effort. With Mark and Krzysztof comments addressed

My comments are still unanswered. One of the devices looks like artificially split from some other, because one word register is not a device.

Best regards,
Krzysztof