Skip to content

Commit

Permalink
ASoC: Consolidate CPU and CODEC DAI lookup
Browse files Browse the repository at this point in the history
The lookup of CPU and CODEC DAIs is fairly similar and can easily be
consolidated into a single helper function.

There are two main differences in the current implementation of the CPU and
CODEC DAI lookup:
 1) CPU DAIs can be looked up by the DAI name alone and do not necessarily
   require a component name/of_node.
 2) The CODEC DAI search only considers DAIs from CODEC components.

For 1) the new helper function will allow to lookup DAIs without providing a
component name or of_node, but since snd_soc_register_card() already rejects
CODEC DAI link components without neither a of_node or a name we'll never get
into the situation where we try to lookup a CODEC DAI without a name/of_node.
For 2) the new helper function just always considers all components.
Componentization is now at a point where it is possible to register a CODEC as a
snd_soc_component rather than a snd_soc_codec, by considering DAIs from all
components it is possible to use such a CODEC in a DAI link.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Aug 19, 2014
1 parent e60cd14 commit 14621c7
Showing 1 changed file with 19 additions and 53 deletions.
72 changes: 19 additions & 53 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,35 +877,23 @@ static struct snd_soc_component *soc_find_component(
return NULL;
}

static struct snd_soc_codec *soc_find_codec(
const struct device_node *codec_of_node,
const char *codec_name)
static struct snd_soc_dai *snd_soc_find_dai(
const struct snd_soc_dai_link_component *dlc)
{
struct snd_soc_codec *codec;
struct snd_soc_component *component;
struct snd_soc_dai *dai;

list_for_each_entry(codec, &codec_list, list) {
if (codec_of_node) {
if (codec->dev->of_node != codec_of_node)
continue;
} else {
if (strcmp(codec->component.name, codec_name))
/* Find CPU DAI from registered DAIs*/
list_for_each_entry(component, &component_list, list) {
if (dlc->of_node && component->dev->of_node != dlc->of_node)
continue;
if (dlc->name && strcmp(dev_name(component->dev), dlc->name))
continue;
list_for_each_entry(dai, &component->dai_list, list) {
if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
continue;
}

return codec;
}

return NULL;
}

static struct snd_soc_dai *soc_find_codec_dai(struct snd_soc_codec *codec,
const char *codec_dai_name)
{
struct snd_soc_dai *codec_dai;

list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
if (!strcmp(codec_dai->name, codec_dai_name)) {
return codec_dai;
return dai;
}
}

Expand All @@ -916,33 +904,19 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
{
struct snd_soc_dai_link *dai_link = &card->dai_link[num];
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
struct snd_soc_component *component;
struct snd_soc_dai_link_component *codecs = dai_link->codecs;
struct snd_soc_dai_link_component cpu_dai_component;
struct snd_soc_dai **codec_dais = rtd->codec_dais;
struct snd_soc_platform *platform;
struct snd_soc_dai *cpu_dai;
const char *platform_name;
int i;

dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);

/* Find CPU DAI from registered DAIs*/
list_for_each_entry(component, &component_list, list) {
if (dai_link->cpu_of_node &&
component->dev->of_node != dai_link->cpu_of_node)
continue;
if (dai_link->cpu_name &&
strcmp(dev_name(component->dev), dai_link->cpu_name))
continue;
list_for_each_entry(cpu_dai, &component->dai_list, list) {
if (dai_link->cpu_dai_name &&
strcmp(cpu_dai->name, dai_link->cpu_dai_name))
continue;

rtd->cpu_dai = cpu_dai;
}
}

cpu_dai_component.name = dai_link->cpu_name;
cpu_dai_component.of_node = dai_link->cpu_of_node;
cpu_dai_component.dai_name = dai_link->cpu_dai_name;
rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
if (!rtd->cpu_dai) {
dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
dai_link->cpu_dai_name);
Expand All @@ -953,15 +927,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)

/* Find CODEC from registered CODECs */
for (i = 0; i < rtd->num_codecs; i++) {
struct snd_soc_codec *codec;
codec = soc_find_codec(codecs[i].of_node, codecs[i].name);
if (!codec) {
dev_err(card->dev, "ASoC: CODEC %s not registered\n",
codecs[i].name);
return -EPROBE_DEFER;
}

codec_dais[i] = soc_find_codec_dai(codec, codecs[i].dai_name);
codec_dais[i] = snd_soc_find_dai(&codecs[i]);
if (!codec_dais[i]) {
dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
codecs[i].dai_name);
Expand Down

0 comments on commit 14621c7

Please sign in to comment.