summaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorMisael Lopez Cruz2014-03-21 16:27:25 +0100
committerMark Brown2014-04-14 21:37:25 +0200
commit12023a9af8f6602e09d9276d3476f6861ca0f127 (patch)
tree34a3289273aba7fdc6894221ac42432dd24a57a6 /sound/soc/soc-core.c
parentLinux 3.15-rc1 (diff)
downloadkernel-qcow2-linux-12023a9af8f6602e09d9276d3476f6861ca0f127.tar.gz
kernel-qcow2-linux-12023a9af8f6602e09d9276d3476f6861ca0f127.tar.xz
kernel-qcow2-linux-12023a9af8f6602e09d9276d3476f6861ca0f127.zip
ASoC: core: Add helpers for codec and codec_dai search
Add dedicated helpers for codec and codec_dai search in preparation for DAI-multicodec. It will help reducing the extra indentation that will be introduced by the iteration over multiple codecs. Previous implementation unnecessarily kept searching for a matching codec in the remaining register codecs even if it was already found. Fix that by returning in case of matching. Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com> [fparent@baylibre.com: Adapt to 3.14+] Signed-off-by: Fabien Parent <fparent@baylibre.com> Signed-off-by: Benoit Cousson <bcousson@baylibre.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c79
1 files changed, 47 insertions, 32 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 051c006281f5..674da7049db4 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -854,14 +854,47 @@ EXPORT_SYMBOL_GPL(snd_soc_resume);
static const struct snd_soc_dai_ops null_dai_ops = {
};
+static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node,
+ const char *codec_name)
+{
+ struct snd_soc_codec *codec;
+
+ 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->name, codec_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 NULL;
+}
+
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_codec *codec;
struct snd_soc_platform *platform;
- struct snd_soc_dai *codec_dai, *cpu_dai;
+ struct snd_soc_dai *cpu_dai;
const char *platform_name;
dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
@@ -889,42 +922,24 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
return -EPROBE_DEFER;
}
- /* Find CODEC from registered CODECs */
- list_for_each_entry(codec, &codec_list, list) {
- if (dai_link->codec_of_node) {
- if (codec->dev->of_node != dai_link->codec_of_node)
- continue;
- } else {
- if (strcmp(codec->name, dai_link->codec_name))
- continue;
- }
-
- rtd->codec = codec;
-
- /*
- * CODEC found, so find CODEC DAI from registered DAIs from
- * this CODEC
- */
- list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
- if (!strcmp(codec_dai->name, dai_link->codec_dai_name)) {
- rtd->codec_dai = codec_dai;
- break;
- }
- }
-
- if (!rtd->codec_dai) {
- dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
- dai_link->codec_dai_name);
- return -EPROBE_DEFER;
- }
- }
-
+ /* Find CODEC from registered list */
+ rtd->codec = soc_find_codec(dai_link->codec_of_node,
+ dai_link->codec_name);
if (!rtd->codec) {
dev_err(card->dev, "ASoC: CODEC %s not registered\n",
dai_link->codec_name);
return -EPROBE_DEFER;
}
+ /* Find CODEC DAI from registered list */
+ rtd->codec_dai = soc_find_codec_dai(rtd->codec,
+ dai_link->codec_dai_name);
+ if (!rtd->codec_dai) {
+ dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+ dai_link->codec_dai_name);
+ return -EPROBE_DEFER;
+ }
+
/* if there's no platform we match on the empty platform */
platform_name = dai_link->platform_name;
if (!platform_name && !dai_link->platform_of_node)