diff mbox series

[RFC,v1,2/2] ASoC: dapm: add support for preparing streams

Message ID 20250106141316.375984-3-martin.blumenstingl@googlemail.com (mailing list archive)
State RFC
Headers show
Series ASoC: prepare streams on codec-to-codec links | expand

Commit Message

Martin Blumenstingl Jan. 6, 2025, 2:13 p.m. UTC
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(+)

Comments

Jerome Brunet Jan. 6, 2025, 2:28 p.m. UTC | #1
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 Brunet Jan. 6, 2025, 2:34 p.m. UTC | #2
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;
Mark Brown Jan. 6, 2025, 3:25 p.m. UTC | #3
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.
Martin Blumenstingl Jan. 6, 2025, 8:17 p.m. UTC | #4
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
diff mbox series

Patch

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;