aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-08-19 09:51:27 -0400
committerMark Brown <broonie@linaro.org>2014-08-19 11:59:47 -0400
commit14621c7e5e72200ec021a7580121130ce7f2ff22 (patch)
tree540850d538f6354541d898c00e010bf3176a3eca /sound/soc/soc-core.c
parente60cd14f0bf6c004cd7032a24a036ba32d56e08a (diff)
ASoC: Consolidate CPU and CODEC DAI lookup
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>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c72
1 files changed, 19 insertions, 53 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 5f6f97874ca2..140f43f91635 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -877,35 +877,23 @@ static struct snd_soc_component *soc_find_component(
877 return NULL; 877 return NULL;
878} 878}
879 879
880static struct snd_soc_codec *soc_find_codec( 880static struct snd_soc_dai *snd_soc_find_dai(
881 const struct device_node *codec_of_node, 881 const struct snd_soc_dai_link_component *dlc)
882 const char *codec_name)
883{ 882{
884 struct snd_soc_codec *codec; 883 struct snd_soc_component *component;
884 struct snd_soc_dai *dai;
885 885
886 list_for_each_entry(codec, &codec_list, list) { 886 /* Find CPU DAI from registered DAIs*/
887 if (codec_of_node) { 887 list_for_each_entry(component, &component_list, list) {
888 if (codec->dev->of_node != codec_of_node) 888 if (dlc->of_node && component->dev->of_node != dlc->of_node)
889 continue; 889 continue;
890 } else { 890 if (dlc->name && strcmp(dev_name(component->dev), dlc->name))
891 if (strcmp(codec->component.name, codec_name)) 891 continue;
892 list_for_each_entry(dai, &component->dai_list, list) {
893 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
892 continue; 894 continue;
893 }
894
895 return codec;
896 }
897
898 return NULL;
899}
900
901static struct snd_soc_dai *soc_find_codec_dai(struct snd_soc_codec *codec,
902 const char *codec_dai_name)
903{
904 struct snd_soc_dai *codec_dai;
905 895
906 list_for_each_entry(codec_dai, &codec->component.dai_list, list) { 896 return dai;
907 if (!strcmp(codec_dai->name, codec_dai_name)) {
908 return codec_dai;
909 } 897 }
910 } 898 }
911 899
@@ -916,33 +904,19 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
916{ 904{
917 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 905 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
918 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 906 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
919 struct snd_soc_component *component;
920 struct snd_soc_dai_link_component *codecs = dai_link->codecs; 907 struct snd_soc_dai_link_component *codecs = dai_link->codecs;
908 struct snd_soc_dai_link_component cpu_dai_component;
921 struct snd_soc_dai **codec_dais = rtd->codec_dais; 909 struct snd_soc_dai **codec_dais = rtd->codec_dais;
922 struct snd_soc_platform *platform; 910 struct snd_soc_platform *platform;
923 struct snd_soc_dai *cpu_dai;
924 const char *platform_name; 911 const char *platform_name;
925 int i; 912 int i;
926 913
927 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 914 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
928 915
929 /* Find CPU DAI from registered DAIs*/ 916 cpu_dai_component.name = dai_link->cpu_name;
930 list_for_each_entry(component, &component_list, list) { 917 cpu_dai_component.of_node = dai_link->cpu_of_node;
931 if (dai_link->cpu_of_node && 918 cpu_dai_component.dai_name = dai_link->cpu_dai_name;
932 component->dev->of_node != dai_link->cpu_of_node) 919 rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
933 continue;
934 if (dai_link->cpu_name &&
935 strcmp(dev_name(component->dev), dai_link->cpu_name))
936 continue;
937 list_for_each_entry(cpu_dai, &component->dai_list, list) {
938 if (dai_link->cpu_dai_name &&
939 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
940 continue;
941
942 rtd->cpu_dai = cpu_dai;
943 }
944 }
945
946 if (!rtd->cpu_dai) { 920 if (!rtd->cpu_dai) {
947 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", 921 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
948 dai_link->cpu_dai_name); 922 dai_link->cpu_dai_name);
@@ -953,15 +927,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
953 927
954 /* Find CODEC from registered CODECs */ 928 /* Find CODEC from registered CODECs */
955 for (i = 0; i < rtd->num_codecs; i++) { 929 for (i = 0; i < rtd->num_codecs; i++) {
956 struct snd_soc_codec *codec; 930 codec_dais[i] = snd_soc_find_dai(&codecs[i]);
957 codec = soc_find_codec(codecs[i].of_node, codecs[i].name);
958 if (!codec) {
959 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
960 codecs[i].name);
961 return -EPROBE_DEFER;
962 }
963
964 codec_dais[i] = soc_find_codec_dai(codec, codecs[i].dai_name);
965 if (!codec_dais[i]) { 931 if (!codec_dais[i]) {
966 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", 932 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
967 codecs[i].dai_name); 933 codecs[i].dai_name);