Skip to content

Commit 24410f4

Browse files
morimotobroonie
authored andcommitted
ASoC: soc-core: Enable to use extra format on each DAI
Current ASoC is using dai_link->dai_fmt to set DAI format for both CPU/Codec. But because it is using same settings, and SND_SOC_DAIFMT_CLOCK_PROVIDER is flipped for CPU, we can't set both CPU/Codec as clock consumer, for example. To solve this issue, this patch enable to use extra format for each DAI which can keep compatibility with legacy system, 1. SND_SOC_DAIFMT_FORMAT_MASK 2. SND_SOC_DAIFMT_CLOCK 3. SND_SOC_DAIFMT_INV 4. SND_SOC_DAIFMT_CLOCK_PROVIDER Legacy dai_fmt includes 1, 2, 3, 4 New idea dai_fmt includes 1, 2, 3 ext_fmt includes 4 Signed-off-by: Kuninori Morimoto <[email protected]> Tested-by: Stephen Gordon <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 85dc053 commit 24410f4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

include/sound/soc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,17 @@ struct snd_soc_dai_link_component {
681681
struct device_node *of_node;
682682
const char *dai_name;
683683
const struct of_phandle_args *dai_args;
684+
685+
/*
686+
* Extra format = SND_SOC_DAIFMT_Bx_Fx
687+
*
688+
* [Note] it is Bx_Fx base, not CBx_CFx
689+
*
690+
* It will be used with dai_link->dai_fmt
691+
* see
692+
* snd_soc_runtime_set_dai_fmt()
693+
*/
694+
unsigned int ext_fmt;
684695
};
685696

686697
/*

sound/soc/soc-core.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,23 +1449,46 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
14491449
{
14501450
struct snd_soc_dai *cpu_dai;
14511451
struct snd_soc_dai *codec_dai;
1452+
unsigned int ext_fmt;
14521453
unsigned int i;
14531454
int ret;
14541455

14551456
if (!dai_fmt)
14561457
return 0;
14571458

1459+
/*
1460+
* dai_fmt has 4 types
1461+
* 1. SND_SOC_DAIFMT_FORMAT_MASK
1462+
* 2. SND_SOC_DAIFMT_CLOCK
1463+
* 3. SND_SOC_DAIFMT_INV
1464+
* 4. SND_SOC_DAIFMT_CLOCK_PROVIDER
1465+
*
1466+
* 4. CLOCK_PROVIDER is set from Codec perspective in dai_fmt. So it will be flipped
1467+
* when this function calls set_fmt() for CPU (CBx_CFx -> Bx_Cx). see below.
1468+
* This mean, we can't set CPU/Codec both are clock consumer for example.
1469+
* New idea handles 4. in each dai->ext_fmt. It can keep compatibility.
1470+
*
1471+
* Legacy
1472+
* dai_fmt includes 1, 2, 3, 4
1473+
*
1474+
* New idea
1475+
* dai_fmt includes 1, 2, 3
1476+
* ext_fmt includes 4
1477+
*/
14581478
for_each_rtd_codec_dais(rtd, i, codec_dai) {
1459-
ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1479+
ext_fmt = rtd->dai_link->codecs[i].ext_fmt;
1480+
ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt | ext_fmt);
14601481
if (ret != 0 && ret != -ENOTSUPP)
14611482
return ret;
14621483
}
14631484

14641485
/* Flip the polarity for the "CPU" end of link */
1486+
/* Will effect only for 4. SND_SOC_DAIFMT_CLOCK_PROVIDER */
14651487
dai_fmt = snd_soc_daifmt_clock_provider_flipped(dai_fmt);
14661488

14671489
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1468-
ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1490+
ext_fmt = rtd->dai_link->cpus[i].ext_fmt;
1491+
ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt | ext_fmt);
14691492
if (ret != 0 && ret != -ENOTSUPP)
14701493
return ret;
14711494
}

0 commit comments

Comments
 (0)