mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/2] ASoC: prepare streams on codec-to-codec links
@ 2025-01-06 14:13 Martin Blumenstingl
  2025-01-06 14:13 ` [RFC PATCH v1 1/2] ASoC: soc-dai: add snd_soc_dai_prepare() and use it internally Martin Blumenstingl
  2025-01-06 14:13 ` [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams Martin Blumenstingl
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Blumenstingl @ 2025-01-06 14:13 UTC (permalink / raw)
  To: linux-sound, linux-amlogic
  Cc: s.nawrocki, lgirdwood, broonie, linux-kernel, jbrunet,
	Martin Blumenstingl

Hello,

the DRM subsystem has recently gained a HDMI audio codec framework [0].
This is already queued for Linux 6.14.

I want to implement a HDMI controller driver for the Amlogic
Meson8/8b/8m2 SoCs using the DRM HDMI audio codec framework. Internally
the DRM HDMI audio codec framework relies on hdmi-codec's .prepare
callback to be called. This unfortunately is not happening on Amlogic
Meson8/8b/8m2 platforms [1].

Jerome suggested that this may be because of the codec-to-codec link on
our Amlogic AIU audio driver [2]. He encouraged me to send this series
to allow hdmi-codec's .prepare() callback to be called - even on
platforms that connect it via a codec-to-codec link.

The reason why this series is marked as RFC is that I'm not familiar
with the ASoC subsystem and lot of the functionality and terminology
is new to me.

Also I Cc'ed Sylwester Nawrocki (Samsung maintainer) as codec-to-codec
links seem to be most heavily used on Samsung and Amlogic platforms.


[0] https://lore.kernel.org/dri-devel/20241224-drm-bridge-hdmi-connector-v10-0-dc89577cd438@linaro.org/
[1] https://lore.kernel.org/linux-amlogic/CAFBinCDdiJ3UNVUcShjq=7U2=oUwT3ciYdKSuZ5TdcrikxFBpg@mail.gmail.com/
[2] https://lore.kernel.org/linux-amlogic/1ja5c4b4rt.fsf@starbuckisacylon.baylibre.com/


Martin Blumenstingl (2):
  ASoC: soc-dai: add snd_soc_dai_prepare() and use it internally
  ASoC: dapm: add support for preparing streams

 include/sound/soc-dai.h |  3 +++
 sound/soc/soc-dai.c     | 27 +++++++++++++++++++--------
 sound/soc/soc-dapm.c    |  7 +++++++
 3 files changed, 29 insertions(+), 8 deletions(-)

-- 
2.47.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC PATCH v1 1/2] ASoC: soc-dai: add snd_soc_dai_prepare() and use it internally
  2025-01-06 14:13 [RFC PATCH v1 0/2] ASoC: prepare streams on codec-to-codec links Martin Blumenstingl
@ 2025-01-06 14:13 ` Martin Blumenstingl
  2025-01-06 14:13 ` [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams Martin Blumenstingl
  1 sibling, 0 replies; 7+ messages in thread
From: Martin Blumenstingl @ 2025-01-06 14:13 UTC (permalink / raw)
  To: linux-sound, linux-amlogic
  Cc: s.nawrocki, lgirdwood, broonie, linux-kernel, jbrunet,
	Martin Blumenstingl

Add a new snd_soc_dai_prepare() which can be used (in an upcoming patch)
by soc-dapm.c. Use this new function internally in
snd_soc_pcm_dai_prepare() to avoid duplicating code.

Suggested-by: Jerome Brunet <jbrunet@baylibre.com>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 include/sound/soc-dai.h |  3 +++
 sound/soc/soc-dai.c     | 27 +++++++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index aab57c19f62b..a11501752637 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -193,6 +193,9 @@ int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
 
 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
 
+int snd_soc_dai_prepare(struct snd_soc_dai *dai,
+			struct snd_pcm_substream *substream);
+
 /* Digital Audio Interface mute */
 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
 			     int direction);
diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c
index 34ba1a93a4c9..ca0308f6d41c 100644
--- a/sound/soc/soc-dai.c
+++ b/sound/soc/soc-dai.c
@@ -360,6 +360,22 @@ int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
 
+int snd_soc_dai_prepare(struct snd_soc_dai *dai,
+			struct snd_pcm_substream *substream)
+{
+	int ret = 0;
+
+	if (!snd_soc_dai_stream_valid(dai, substream->stream))
+		return 0;
+
+	if (dai->driver->ops &&
+	    dai->driver->ops->prepare)
+		ret = dai->driver->ops->prepare(substream, dai);
+
+	return soc_dai_ret(dai, ret);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_prepare);
+
 /**
  * snd_soc_dai_digital_mute - configure DAI system or master clock.
  * @dai: DAI
@@ -577,14 +593,9 @@ int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream)
 	int i, ret;
 
 	for_each_rtd_dais(rtd, i, dai) {
-		if (!snd_soc_dai_stream_valid(dai, substream->stream))
-			continue;
-		if (dai->driver->ops &&
-		    dai->driver->ops->prepare) {
-			ret = dai->driver->ops->prepare(substream, dai);
-			if (ret < 0)
-				return soc_dai_ret(dai, ret);
-		}
+		ret = snd_soc_dai_prepare(dai, substream);
+		if (ret < 0)
+			return ret;
 	}
 
 	return 0;
-- 
2.47.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams
  2025-01-06 14:13 [RFC PATCH v1 0/2] ASoC: prepare streams on codec-to-codec links Martin Blumenstingl
  2025-01-06 14:13 ` [RFC PATCH v1 1/2] ASoC: soc-dai: add snd_soc_dai_prepare() and use it internally Martin Blumenstingl
@ 2025-01-06 14:13 ` Martin Blumenstingl
  2025-01-06 14:28   ` Jerome Brunet
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Blumenstingl @ 2025-01-06 14:13 UTC (permalink / raw)
  To: linux-sound, linux-amlogic
  Cc: s.nawrocki, lgirdwood, broonie, linux-kernel, jbrunet,
	Martin Blumenstingl

Codec driver can implement .hw_params and/or .prepare from struct
snd_soc_dai_ops. For codec-to-codec links only the former (.hw_params)
callback has been called.

On platforms like Amlogic Meson8/8b/8m2 the SoC's sound card
(sound/soc/meson/gx-card.c) uses a codec-to-codec link for the HDMI
codec output because further digital routing is required after the
backend. The new DRM HDMI (audio) codec framework (which internally
uses sound/soc/codecs/hdmi-codec.c) relies on the .prepare callback
of the hdmi-codec to be called. Implement a call to
snd_soc_dai_prepare() so the .prepare callback of the hdmi-codec is
called on those platforms.

For platforms or sound cards without a codec-to-codec link with
additional parameters (which applies to most hardware) this changes
nothing as the .prepare callback is already called via
snd_pcm_do_prepare() (as well as dpcm_fe_dai_prepare() and
dpcm_be_dai_prepare()) on those.

Suggested-by: Jerome Brunet <jbrunet@baylibre.com>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 sound/soc/soc-dapm.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 99521c784a9b..ac8eef217dc4 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -4013,6 +4013,13 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 		break;
 
 	case SND_SOC_DAPM_POST_PMU:
+		snd_soc_dapm_widget_for_each_sink_path(w, path) {
+			sink = path->sink->priv;
+
+			snd_soc_dai_prepare(sink, substream);
+			ret = 0;
+		}
+
 		snd_soc_dapm_widget_for_each_sink_path(w, path) {
 			sink = path->sink->priv;
 
-- 
2.47.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams
  2025-01-06 14:13 ` [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams Martin Blumenstingl
@ 2025-01-06 14:28   ` Jerome Brunet
  2025-01-06 14:34     ` Jerome Brunet
  2025-01-06 20:17     ` Martin Blumenstingl
  0 siblings, 2 replies; 7+ messages in thread
From: Jerome Brunet @ 2025-01-06 14:28 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: linux-sound, linux-amlogic, s.nawrocki, lgirdwood, broonie, linux-kernel

On Mon 06 Jan 2025 at 15:13, Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:

> Codec driver can implement .hw_params and/or .prepare from struct
> snd_soc_dai_ops. For codec-to-codec links only the former (.hw_params)
> callback has been called.
>
> On platforms like Amlogic Meson8/8b/8m2 the SoC's sound card
> (sound/soc/meson/gx-card.c) uses a codec-to-codec link for the HDMI
> codec output because further digital routing is required after the
> backend. The new DRM HDMI (audio) codec framework (which internally
> uses sound/soc/codecs/hdmi-codec.c) relies on the .prepare callback
> of the hdmi-codec to be called. Implement a call to
> snd_soc_dai_prepare() so the .prepare callback of the hdmi-codec is
> called on those platforms.
>
> For platforms or sound cards without a codec-to-codec link with
> additional parameters (which applies to most hardware) this changes
> nothing as the .prepare callback is already called via
> snd_pcm_do_prepare() (as well as dpcm_fe_dai_prepare() and
> dpcm_be_dai_prepare()) on those.
>
> Suggested-by: Jerome Brunet <jbrunet@baylibre.com>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Thanks for working on this. Overall it looks good.

Not sure if the call the .prepare() should go at the beginning of
POST_PMU, as done here, or at the end of PRE_PMU ? 

> ---
>  sound/soc/soc-dapm.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index 99521c784a9b..ac8eef217dc4 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -4013,6 +4013,13 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
>  		break;
>  
>  	case SND_SOC_DAPM_POST_PMU:
> +		snd_soc_dapm_widget_for_each_sink_path(w, path) {
> +			sink = path->sink->priv;
> +
> +			snd_soc_dai_prepare(sink, substream);
> +			ret = 0;
> +		}
> +
>  		snd_soc_dapm_widget_for_each_sink_path(w, path) {
>  			sink = path->sink->priv;

-- 
Jerome

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams
  2025-01-06 14:28   ` Jerome Brunet
@ 2025-01-06 14:34     ` Jerome Brunet
  2025-01-06 15:25       ` Mark Brown
  2025-01-06 20:17     ` Martin Blumenstingl
  1 sibling, 1 reply; 7+ messages in thread
From: Jerome Brunet @ 2025-01-06 14:34 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: linux-sound, linux-amlogic, s.nawrocki, lgirdwood, broonie, linux-kernel

On Mon 06 Jan 2025 at 15:28, Jerome Brunet <jbrunet@baylibre.com> wrote:

> On Mon 06 Jan 2025 at 15:13, Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:
>
>> Codec driver can implement .hw_params and/or .prepare from struct
>> snd_soc_dai_ops. For codec-to-codec links only the former (.hw_params)
>> callback has been called.
>>
>> On platforms like Amlogic Meson8/8b/8m2 the SoC's sound card
>> (sound/soc/meson/gx-card.c) uses a codec-to-codec link for the HDMI
>> codec output because further digital routing is required after the
>> backend. The new DRM HDMI (audio) codec framework (which internally
>> uses sound/soc/codecs/hdmi-codec.c) relies on the .prepare callback
>> of the hdmi-codec to be called. Implement a call to
>> snd_soc_dai_prepare() so the .prepare callback of the hdmi-codec is
>> called on those platforms.
>>
>> For platforms or sound cards without a codec-to-codec link with
>> additional parameters (which applies to most hardware) this changes
>> nothing as the .prepare callback is already called via
>> snd_pcm_do_prepare() (as well as dpcm_fe_dai_prepare() and
>> dpcm_be_dai_prepare()) on those.
>>
>> Suggested-by: Jerome Brunet <jbrunet@baylibre.com>
>> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>
> Thanks for working on this. Overall it looks good.
>
> Not sure if the call the .prepare() should go at the beginning of
> POST_PMU, as done here, or at the end of PRE_PMU ? 
>
>> ---
>>  sound/soc/soc-dapm.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
>> index 99521c784a9b..ac8eef217dc4 100644
>> --- a/sound/soc/soc-dapm.c
>> +++ b/sound/soc/soc-dapm.c
>> @@ -4013,6 +4013,13 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
>>  		break;
>>  
>>  	case SND_SOC_DAPM_POST_PMU:
>> +		snd_soc_dapm_widget_for_each_sink_path(w, path) {
>> +			sink = path->sink->priv;
>> +
>> +			snd_soc_dai_prepare(sink, substream);

I initially missed it but I think you should do that on the source path
too

On Amlogic, the cpu side of the link does not have a .prepare() callback
but it would be incorrect to do the codec side only if it did.

>> +			ret = 0;
>> +		}
>> +
>>  		snd_soc_dapm_widget_for_each_sink_path(w, path) {
>>  			sink = path->sink->priv;

-- 
Jerome

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams
  2025-01-06 14:34     ` Jerome Brunet
@ 2025-01-06 15:25       ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2025-01-06 15:25 UTC (permalink / raw)
  To: Jerome Brunet
  Cc: Martin Blumenstingl, linux-sound, linux-amlogic, s.nawrocki,
	lgirdwood, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 670 bytes --]

On Mon, Jan 06, 2025 at 03:34:01PM +0100, Jerome Brunet wrote:
> On Mon 06 Jan 2025 at 15:28, Jerome Brunet <jbrunet@baylibre.com> wrote:
> > On Mon 06 Jan 2025 at 15:13, Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:

> >>  	case SND_SOC_DAPM_POST_PMU:
> >> +		snd_soc_dapm_widget_for_each_sink_path(w, path) {
> >> +			sink = path->sink->priv;
> >> +
> >> +			snd_soc_dai_prepare(sink, substream);

> I initially missed it but I think you should do that on the source path
> too

> On Amlogic, the cpu side of the link does not have a .prepare() callback
> but it would be incorrect to do the codec side only if it did.

Yes, symmetry seems sensible.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams
  2025-01-06 14:28   ` Jerome Brunet
  2025-01-06 14:34     ` Jerome Brunet
@ 2025-01-06 20:17     ` Martin Blumenstingl
  1 sibling, 0 replies; 7+ messages in thread
From: Martin Blumenstingl @ 2025-01-06 20:17 UTC (permalink / raw)
  To: Jerome Brunet, broonie
  Cc: linux-sound, linux-amlogic, s.nawrocki, lgirdwood, linux-kernel

On Mon, Jan 6, 2025 at 3:28 PM Jerome Brunet <jbrunet@baylibre.com> wrote:
>
> On Mon 06 Jan 2025 at 15:13, Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:
>
> > Codec driver can implement .hw_params and/or .prepare from struct
> > snd_soc_dai_ops. For codec-to-codec links only the former (.hw_params)
> > callback has been called.
> >
> > On platforms like Amlogic Meson8/8b/8m2 the SoC's sound card
> > (sound/soc/meson/gx-card.c) uses a codec-to-codec link for the HDMI
> > codec output because further digital routing is required after the
> > backend. The new DRM HDMI (audio) codec framework (which internally
> > uses sound/soc/codecs/hdmi-codec.c) relies on the .prepare callback
> > of the hdmi-codec to be called. Implement a call to
> > snd_soc_dai_prepare() so the .prepare callback of the hdmi-codec is
> > called on those platforms.
> >
> > For platforms or sound cards without a codec-to-codec link with
> > additional parameters (which applies to most hardware) this changes
> > nothing as the .prepare callback is already called via
> > snd_pcm_do_prepare() (as well as dpcm_fe_dai_prepare() and
> > dpcm_be_dai_prepare()) on those.
> >
> > Suggested-by: Jerome Brunet <jbrunet@baylibre.com>
> > Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>
> Thanks for working on this. Overall it looks good.
>
> Not sure if the call the .prepare() should go at the beginning of
> POST_PMU, as done here, or at the end of PRE_PMU ?
I only know that .prepare() should be called later than .hw_params()
so this is what I came up with.
Mark, do you have any preferences or suggestions here?

Regarding the call to snd_soc_dai_prepare(): I'll take care of that in
v2 once the above question has been clarified.


Best regards,
Martin

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-06 20:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-06 14:13 [RFC PATCH v1 0/2] ASoC: prepare streams on codec-to-codec links Martin Blumenstingl
2025-01-06 14:13 ` [RFC PATCH v1 1/2] ASoC: soc-dai: add snd_soc_dai_prepare() and use it internally Martin Blumenstingl
2025-01-06 14:13 ` [RFC PATCH v1 2/2] ASoC: dapm: add support for preparing streams Martin Blumenstingl
2025-01-06 14:28   ` Jerome Brunet
2025-01-06 14:34     ` Jerome Brunet
2025-01-06 15:25       ` Mark Brown
2025-01-06 20:17     ` Martin Blumenstingl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®