Skip to content

Commit

Permalink
ASoC: soc-core: move snd_soc_runtime_set_dai_fmt() to upside
Browse files Browse the repository at this point in the history
This patch moves snd_soc_runtime_set_dai_fmt() to upside.
This is prepare to support snd_soc_runtime_get_dai_fmt().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87im34nc9r.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Kuninori Morimoto authored and Mark Brown committed Jun 7, 2021
1 parent ffb2df6 commit 4d1a98b
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,68 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);

/**
* snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
* @rtd: The runtime for which the DAI link format should be changed
* @dai_fmt: The new DAI link format
*
* This function updates the DAI link format for all DAIs connected to the DAI
* link for the specified runtime.
*
* Note: For setups with a static format set the dai_fmt field in the
* corresponding snd_dai_link struct instead of using this function.
*
* Returns 0 on success, otherwise a negative error code.
*/
int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
unsigned int dai_fmt)
{
struct snd_soc_dai *cpu_dai;
struct snd_soc_dai *codec_dai;
unsigned int inv_dai_fmt;
unsigned int i;
int ret;

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 a CODEC<->CODEC link
* the component which has non_legacy_dai_naming is Codec
*/
inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
case SND_SOC_DAIFMT_CBM_CFM:
inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
break;
case SND_SOC_DAIFMT_CBM_CFS:
inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
break;
case SND_SOC_DAIFMT_CBS_CFM:
inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
break;
case SND_SOC_DAIFMT_CBS_CFS:
inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
break;
}
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
unsigned int fmt = dai_fmt;

if (cpu_dai->component->driver->non_legacy_dai_naming)
fmt = inv_dai_fmt;

ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}

return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);

static int soc_init_pcm_runtime(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd)
{
Expand Down Expand Up @@ -1402,68 +1464,6 @@ static void soc_remove_aux_devices(struct snd_soc_card *card)
}
}

/**
* snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
* @rtd: The runtime for which the DAI link format should be changed
* @dai_fmt: The new DAI link format
*
* This function updates the DAI link format for all DAIs connected to the DAI
* link for the specified runtime.
*
* Note: For setups with a static format set the dai_fmt field in the
* corresponding snd_dai_link struct instead of using this function.
*
* Returns 0 on success, otherwise a negative error code.
*/
int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
unsigned int dai_fmt)
{
struct snd_soc_dai *cpu_dai;
struct snd_soc_dai *codec_dai;
unsigned int inv_dai_fmt;
unsigned int i;
int ret;

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 a CODEC<->CODEC link
* the component which has non_legacy_dai_naming is Codec
*/
inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
case SND_SOC_DAIFMT_CBM_CFM:
inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
break;
case SND_SOC_DAIFMT_CBM_CFS:
inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
break;
case SND_SOC_DAIFMT_CBS_CFM:
inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
break;
case SND_SOC_DAIFMT_CBS_CFS:
inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
break;
}
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
unsigned int fmt = dai_fmt;

if (cpu_dai->component->driver->non_legacy_dai_naming)
fmt = inv_dai_fmt;

ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}

return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);

#ifdef CONFIG_DMI
/*
* If a DMI filed contain strings in this blacklist (e.g.
Expand Down

0 comments on commit 4d1a98b

Please sign in to comment.