Re: [PATCH 3/4] ASoC: audio-graph-card2: parse symmetric-clock-roles property

From: Alvin Šipraga
Date: Mon Jun 05 2023 - 06:59:17 EST


Hi Kuninori,

On Mon, Jun 05, 2023 at 12:35:56AM +0000, Kuninori Morimoto wrote:
>
> Hi Alvin
>
> > --- a/sound/soc/generic/audio-graph-card2.c
> > +++ b/sound/soc/generic/audio-graph-card2.c
> (snip)
> > /*
> > * convert bit_frame
> > * We need to flip clock_provider if it was CPU node,
> > * because it is Codec base.
> > */
> > daiclk = snd_soc_daifmt_clock_provider_from_bitmap(bit_frame);
> > - if (is_cpu_node)
> > + if (is_cpu_node && !dai_link->symmetric_clock_roles)
> > daiclk = snd_soc_daifmt_clock_provider_flipped(daiclk);
> >
> > dai_link->dai_fmt = daifmt | daiclk;
>
> Hmm ? I'm confusing
> [2/4] patch handling fliping, and [3/4] also handling fliping.
> Nothing changed ?

Yes, I agree it seems wrong. Let me try and explain what is going on.

First take a look at the original snd_soc_runtime_set_dai_fmt:

int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
unsigned int dai_fmt)
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *cpu_dai;
struct snd_soc_dai *codec_dai;
unsigned int i;
int ret;

if (!dai_fmt)
return 0;

for_each_rtd_codec_dais(rtd, i, codec_dai) {
ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}

/* Flip the polarity for the "CPU" end of link */
dai_fmt = snd_soc_daifmt_clock_provider_flipped(dai_fmt);

for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}

return 0;
}

... which is called by the core in soc_init_pcm_runtime:

static int soc_init_pcm_runtime(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
/* ... */

snd_soc_runtime_get_dai_fmt(rtd);
ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
if (ret)
return ret;

/* ... */
}

From the above I conclude that the clock role expressed by dai_link->dai_fmt is
"as applied to the codec", i.e. snd_soc_runtime_set_dai_fmt does not flip the
value before applying it on the codec side. When applying it to the CPU side,
the roles are flipped.

>
> Current SND_SOC_DAIFMT_xx_xx are very confusable,
> framework and driver are different (flipped).
> and also, audio-graph-card2 is using intuitive DT settings
> (need flip for CPU).

Now consider audio-graph-card2. Except for DPCM backends, it always parses the
DAI format on the CPU side. Since dai_link->dai_fmt is flipped by the ASoC core
when applying format to the CPU, card2 is flipping the parsed value before
storing it in dai_link->dai_fmt so that it is correct.

audio-graph-card2 -.
v

-1 * -1 = 1

^
'- ASoC core

But with patch 2/4 of this series, symmetric_clock_roles == 1 means that the
ASoC core doesn't flip it. In fact, it means that the role is the same both "as
applied to the codec" and "as applied to the CPU". So no flipping should happen,
neither in card2 nor in ASoC core. CPU and codec clock consumer/provider roles
are symmetric. e.g. if CPU is a bitclock consumer then so is the codec, and
nothing needs flipping.

I hope that is clear now.

Kind regards,
Alvin