aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Cousson <bcousson@baylibre.com>2014-07-08 17:19:34 -0400
committerMark Brown <broonie@linaro.org>2014-07-16 17:58:49 -0400
commit88bd870f02dff5c9445286e185f21873f25a977f (patch)
tree329d25b67e687f6905e51b989db62c7268986fb1
parentf7acb3694a999fdf04dc3096e8416a0bfdabd590 (diff)
ASoC: core: Add initial support for DAI multicodec
DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card. The current ASoC implementation does not allow such setup. Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name). Multi-codec links are not supported in the case of CODEC to CODEC links. Just print a warning if it happens. Based on an original code done by Misael. Signed-off-by: Benoit Cousson <bcousson@baylibre.com> Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com> Signed-off-by: Fabien Parent <fparent@baylibre.com> Tested-by: Lars-Peter Clausen <lars@metafoo.de> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc-dai.h4
-rw-r--r--include/sound/soc.h13
-rw-r--r--sound/soc/soc-core.c293
3 files changed, 220 insertions, 90 deletions
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 031be2ab75d0..e8b3080d196a 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -272,6 +272,10 @@ struct snd_soc_dai {
272 struct snd_soc_codec *codec; 272 struct snd_soc_codec *codec;
273 struct snd_soc_component *component; 273 struct snd_soc_component *component;
274 274
275 /* CODEC TDM slot masks and params (for fixup) */
276 unsigned int tx_mask;
277 unsigned int rx_mask;
278
275 struct snd_soc_card *card; 279 struct snd_soc_card *card;
276 280
277 struct list_head list; 281 struct list_head list;
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 9a5b4f6fe847..f2142cf3f243 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -846,6 +846,12 @@ struct snd_soc_platform_driver {
846 int (*bespoke_trigger)(struct snd_pcm_substream *, int); 846 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
847}; 847};
848 848
849struct snd_soc_dai_link_component {
850 const char *name;
851 const struct device_node *of_node;
852 const char *dai_name;
853};
854
849struct snd_soc_platform { 855struct snd_soc_platform {
850 struct device *dev; 856 struct device *dev;
851 const struct snd_soc_platform_driver *driver; 857 const struct snd_soc_platform_driver *driver;
@@ -891,6 +897,10 @@ struct snd_soc_dai_link {
891 const struct device_node *codec_of_node; 897 const struct device_node *codec_of_node;
892 /* You MUST specify the DAI name within the codec */ 898 /* You MUST specify the DAI name within the codec */
893 const char *codec_dai_name; 899 const char *codec_dai_name;
900
901 struct snd_soc_dai_link_component *codecs;
902 unsigned int num_codecs;
903
894 /* 904 /*
895 * You MAY specify the link's platform/PCM/DMA driver, either by 905 * You MAY specify the link's platform/PCM/DMA driver, either by
896 * device name, or by DT/OF node, but not both. Some forms of link 906 * device name, or by DT/OF node, but not both. Some forms of link
@@ -1089,6 +1099,9 @@ struct snd_soc_pcm_runtime {
1089 struct snd_soc_dai *codec_dai; 1099 struct snd_soc_dai *codec_dai;
1090 struct snd_soc_dai *cpu_dai; 1100 struct snd_soc_dai *cpu_dai;
1091 1101
1102 struct snd_soc_dai **codec_dais;
1103 unsigned int num_codecs;
1104
1092 struct delayed_work delayed_work; 1105 struct delayed_work delayed_work;
1093#ifdef CONFIG_DEBUG_FS 1106#ifdef CONFIG_DEBUG_FS
1094 struct dentry *debugfs_dpcm_root; 1107 struct dentry *debugfs_dpcm_root;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c32d8399e770..6e47610f73a0 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -576,7 +576,7 @@ int snd_soc_suspend(struct device *dev)
576{ 576{
577 struct snd_soc_card *card = dev_get_drvdata(dev); 577 struct snd_soc_card *card = dev_get_drvdata(dev);
578 struct snd_soc_codec *codec; 578 struct snd_soc_codec *codec;
579 int i; 579 int i, j;
580 580
581 /* If the initialization of this soc device failed, there is no codec 581 /* If the initialization of this soc device failed, there is no codec
582 * associated with it. Just bail out in this case. 582 * associated with it. Just bail out in this case.
@@ -596,14 +596,17 @@ int snd_soc_suspend(struct device *dev)
596 596
597 /* mute any active DACs */ 597 /* mute any active DACs */
598 for (i = 0; i < card->num_rtd; i++) { 598 for (i = 0; i < card->num_rtd; i++) {
599 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
600 struct snd_soc_dai_driver *drv = dai->driver;
601 599
602 if (card->rtd[i].dai_link->ignore_suspend) 600 if (card->rtd[i].dai_link->ignore_suspend)
603 continue; 601 continue;
604 602
605 if (drv->ops->digital_mute && dai->playback_active) 603 for (j = 0; j < card->rtd[i].num_codecs; j++) {
606 drv->ops->digital_mute(dai, 1); 604 struct snd_soc_dai *dai = card->rtd[i].codec_dais[j];
605 struct snd_soc_dai_driver *drv = dai->driver;
606
607 if (drv->ops->digital_mute && dai->playback_active)
608 drv->ops->digital_mute(dai, 1);
609 }
607 } 610 }
608 611
609 /* suspend all pcms */ 612 /* suspend all pcms */
@@ -634,8 +637,12 @@ int snd_soc_suspend(struct device *dev)
634 637
635 /* close any waiting streams and save state */ 638 /* close any waiting streams and save state */
636 for (i = 0; i < card->num_rtd; i++) { 639 for (i = 0; i < card->num_rtd; i++) {
640 struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais;
637 flush_delayed_work(&card->rtd[i].delayed_work); 641 flush_delayed_work(&card->rtd[i].delayed_work);
638 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; 642 for (j = 0; j < card->rtd[i].num_codecs; j++) {
643 codec_dais[j]->codec->dapm.suspend_bias_level =
644 codec_dais[j]->codec->dapm.bias_level;
645 }
639 } 646 }
640 647
641 for (i = 0; i < card->num_rtd; i++) { 648 for (i = 0; i < card->num_rtd; i++) {
@@ -719,7 +726,7 @@ static void soc_resume_deferred(struct work_struct *work)
719 struct snd_soc_card *card = 726 struct snd_soc_card *card =
720 container_of(work, struct snd_soc_card, deferred_resume_work); 727 container_of(work, struct snd_soc_card, deferred_resume_work);
721 struct snd_soc_codec *codec; 728 struct snd_soc_codec *codec;
722 int i; 729 int i, j;
723 730
724 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 731 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
725 * so userspace apps are blocked from touching us 732 * so userspace apps are blocked from touching us
@@ -780,14 +787,17 @@ static void soc_resume_deferred(struct work_struct *work)
780 787
781 /* unmute any active DACs */ 788 /* unmute any active DACs */
782 for (i = 0; i < card->num_rtd; i++) { 789 for (i = 0; i < card->num_rtd; i++) {
783 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
784 struct snd_soc_dai_driver *drv = dai->driver;
785 790
786 if (card->rtd[i].dai_link->ignore_suspend) 791 if (card->rtd[i].dai_link->ignore_suspend)
787 continue; 792 continue;
788 793
789 if (drv->ops->digital_mute && dai->playback_active) 794 for (j = 0; j < card->rtd[i].num_codecs; j++) {
790 drv->ops->digital_mute(dai, 0); 795 struct snd_soc_dai *dai = card->rtd[i].codec_dais[j];
796 struct snd_soc_dai_driver *drv = dai->driver;
797
798 if (drv->ops->digital_mute && dai->playback_active)
799 drv->ops->digital_mute(dai, 0);
800 }
791 } 801 }
792 802
793 for (i = 0; i < card->num_rtd; i++) { 803 for (i = 0; i < card->num_rtd; i++) {
@@ -832,12 +842,19 @@ int snd_soc_resume(struct device *dev)
832 842
833 /* activate pins from sleep state */ 843 /* activate pins from sleep state */
834 for (i = 0; i < card->num_rtd; i++) { 844 for (i = 0; i < card->num_rtd; i++) {
835 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 845 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
836 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; 846 struct snd_soc_dai **codec_dais = rtd->codec_dais;
847 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
848 int j;
849
837 if (cpu_dai->active) 850 if (cpu_dai->active)
838 pinctrl_pm_select_default_state(cpu_dai->dev); 851 pinctrl_pm_select_default_state(cpu_dai->dev);
839 if (codec_dai->active) 852
840 pinctrl_pm_select_default_state(codec_dai->dev); 853 for (j = 0; j < rtd->num_codecs; j++) {
854 struct snd_soc_dai *codec_dai = codec_dais[j];
855 if (codec_dai->active)
856 pinctrl_pm_select_default_state(codec_dai->dev);
857 }
841 } 858 }
842 859
843 /* AC97 devices might have other drivers hanging off them so 860 /* AC97 devices might have other drivers hanging off them so
@@ -869,8 +886,9 @@ EXPORT_SYMBOL_GPL(snd_soc_resume);
869static const struct snd_soc_dai_ops null_dai_ops = { 886static const struct snd_soc_dai_ops null_dai_ops = {
870}; 887};
871 888
872static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node, 889static struct snd_soc_codec *soc_find_codec(
873 const char *codec_name) 890 const struct device_node *codec_of_node,
891 const char *codec_name)
874{ 892{
875 struct snd_soc_codec *codec; 893 struct snd_soc_codec *codec;
876 894
@@ -908,9 +926,12 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
908 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 926 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
909 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 927 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
910 struct snd_soc_component *component; 928 struct snd_soc_component *component;
929 struct snd_soc_dai_link_component *codecs = dai_link->codecs;
930 struct snd_soc_dai **codec_dais = rtd->codec_dais;
911 struct snd_soc_platform *platform; 931 struct snd_soc_platform *platform;
912 struct snd_soc_dai *cpu_dai; 932 struct snd_soc_dai *cpu_dai;
913 const char *platform_name; 933 const char *platform_name;
934 int i;
914 935
915 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 936 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
916 937
@@ -937,24 +958,30 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
937 return -EPROBE_DEFER; 958 return -EPROBE_DEFER;
938 } 959 }
939 960
940 /* Find CODEC from registered list */ 961 rtd->num_codecs = dai_link->num_codecs;
941 rtd->codec = soc_find_codec(dai_link->codec_of_node,
942 dai_link->codec_name);
943 if (!rtd->codec) {
944 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
945 dai_link->codec_name);
946 return -EPROBE_DEFER;
947 }
948 962
949 /* Find CODEC DAI from registered list */ 963 /* Find CODEC from registered CODECs */
950 rtd->codec_dai = soc_find_codec_dai(rtd->codec, 964 for (i = 0; i < rtd->num_codecs; i++) {
951 dai_link->codec_dai_name); 965 struct snd_soc_codec *codec;
952 if (!rtd->codec_dai) { 966 codec = soc_find_codec(codecs[i].of_node, codecs[i].name);
953 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", 967 if (!codec) {
954 dai_link->codec_dai_name); 968 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
955 return -EPROBE_DEFER; 969 codecs[i].name);
970 return -EPROBE_DEFER;
971 }
972
973 codec_dais[i] = soc_find_codec_dai(codec, codecs[i].dai_name);
974 if (!codec_dais[i]) {
975 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
976 codecs[i].dai_name);
977 return -EPROBE_DEFER;
978 }
956 } 979 }
957 980
981 /* Single codec links expect codec and codec_dai in runtime data */
982 rtd->codec_dai = codec_dais[0];
983 rtd->codec = rtd->codec_dai->codec;
984
958 /* if there's no platform we match on the empty platform */ 985 /* if there's no platform we match on the empty platform */
959 platform_name = dai_link->platform_name; 986 platform_name = dai_link->platform_name;
960 if (!platform_name && !dai_link->platform_of_node) 987 if (!platform_name && !dai_link->platform_of_node)
@@ -1045,8 +1072,8 @@ static void soc_remove_codec_dai(struct snd_soc_dai *codec_dai, int order)
1045static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) 1072static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
1046{ 1073{
1047 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1074 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1048 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1075 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1049 int err; 1076 int i, err;
1050 1077
1051 /* unregister the rtd device */ 1078 /* unregister the rtd device */
1052 if (rtd->dev_registered) { 1079 if (rtd->dev_registered) {
@@ -1057,7 +1084,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
1057 } 1084 }
1058 1085
1059 /* remove the CODEC DAI */ 1086 /* remove the CODEC DAI */
1060 soc_remove_codec_dai(codec_dai, order); 1087 for (i = 0; i < rtd->num_codecs; i++)
1088 soc_remove_codec_dai(rtd->codec_dais[i], order);
1061 1089
1062 /* remove the cpu_dai */ 1090 /* remove the cpu_dai */
1063 if (cpu_dai && cpu_dai->probed && 1091 if (cpu_dai && cpu_dai->probed &&
@@ -1080,9 +1108,9 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num,
1080{ 1108{
1081 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1109 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1082 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1110 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1083 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1084 struct snd_soc_platform *platform = rtd->platform; 1111 struct snd_soc_platform *platform = rtd->platform;
1085 struct snd_soc_codec *codec; 1112 struct snd_soc_codec *codec;
1113 int i;
1086 1114
1087 /* remove the platform */ 1115 /* remove the platform */
1088 if (platform && platform->probed && 1116 if (platform && platform->probed &&
@@ -1091,8 +1119,8 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num,
1091 } 1119 }
1092 1120
1093 /* remove the CODEC-side CODEC */ 1121 /* remove the CODEC-side CODEC */
1094 if (codec_dai) { 1122 for (i = 0; i < rtd->num_codecs; i++) {
1095 codec = codec_dai->codec; 1123 codec = rtd->codec_dais[i]->codec;
1096 if (codec && codec->probed && 1124 if (codec && codec->probed &&
1097 codec->driver->remove_order == order) 1125 codec->driver->remove_order == order)
1098 soc_remove_codec(codec); 1126 soc_remove_codec(codec);
@@ -1335,9 +1363,8 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
1335{ 1363{
1336 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1364 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1337 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1365 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1338 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1339 struct snd_soc_platform *platform = rtd->platform; 1366 struct snd_soc_platform *platform = rtd->platform;
1340 int ret; 1367 int i, ret;
1341 1368
1342 /* probe the CPU-side component, if it is a CODEC */ 1369 /* probe the CPU-side component, if it is a CODEC */
1343 if (cpu_dai->codec && 1370 if (cpu_dai->codec &&
@@ -1348,12 +1375,14 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
1348 return ret; 1375 return ret;
1349 } 1376 }
1350 1377
1351 /* probe the CODEC-side component */ 1378 /* probe the CODEC-side components */
1352 if (!codec_dai->codec->probed && 1379 for (i = 0; i < rtd->num_codecs; i++) {
1353 codec_dai->codec->driver->probe_order == order) { 1380 if (!rtd->codec_dais[i]->codec->probed &&
1354 ret = soc_probe_codec(card, codec_dai->codec); 1381 rtd->codec_dais[i]->codec->driver->probe_order == order) {
1355 if (ret < 0) 1382 ret = soc_probe_codec(card, rtd->codec_dais[i]->codec);
1356 return ret; 1383 if (ret < 0)
1384 return ret;
1385 }
1357 } 1386 }
1358 1387
1359 /* probe the platform */ 1388 /* probe the platform */
@@ -1400,6 +1429,9 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
1400 struct snd_soc_dapm_widget *play_w, *capture_w; 1429 struct snd_soc_dapm_widget *play_w, *capture_w;
1401 int ret; 1430 int ret;
1402 1431
1432 if (rtd->num_codecs > 1)
1433 dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
1434
1403 /* link the DAI widgets */ 1435 /* link the DAI widgets */
1404 play_w = codec_dai->playback_widget; 1436 play_w = codec_dai->playback_widget;
1405 capture_w = cpu_dai->capture_widget; 1437 capture_w = cpu_dai->capture_widget;
@@ -1432,19 +1464,18 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1432{ 1464{
1433 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1465 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1434 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1466 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1435 struct snd_soc_codec *codec = rtd->codec;
1436 struct snd_soc_platform *platform = rtd->platform; 1467 struct snd_soc_platform *platform = rtd->platform;
1437 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1438 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1468 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1439 int ret; 1469 int i, ret;
1440 1470
1441 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", 1471 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1442 card->name, num, order); 1472 card->name, num, order);
1443 1473
1444 /* config components */ 1474 /* config components */
1445 cpu_dai->platform = platform; 1475 cpu_dai->platform = platform;
1446 codec_dai->card = card;
1447 cpu_dai->card = card; 1476 cpu_dai->card = card;
1477 for (i = 0; i < rtd->num_codecs; i++)
1478 rtd->codec_dais[i]->card = card;
1448 1479
1449 /* set default power off timeout */ 1480 /* set default power off timeout */
1450 rtd->pmdown_time = pmdown_time; 1481 rtd->pmdown_time = pmdown_time;
@@ -1471,9 +1502,11 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1471 } 1502 }
1472 1503
1473 /* probe the CODEC DAI */ 1504 /* probe the CODEC DAI */
1474 ret = soc_probe_codec_dai(card, codec_dai, order); 1505 for (i = 0; i < rtd->num_codecs; i++) {
1475 if (ret) 1506 ret = soc_probe_codec_dai(card, rtd->codec_dais[i], order);
1476 return ret; 1507 if (ret)
1508 return ret;
1509 }
1477 1510
1478 /* complete DAI probe during last probe */ 1511 /* complete DAI probe during last probe */
1479 if (order != SND_SOC_COMP_ORDER_LAST) 1512 if (order != SND_SOC_COMP_ORDER_LAST)
@@ -1541,8 +1574,11 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1541 } 1574 }
1542 1575
1543 /* add platform data for AC97 devices */ 1576 /* add platform data for AC97 devices */
1544 if (rtd->codec_dai->driver->ac97_control) 1577 for (i = 0; i < rtd->num_codecs; i++) {
1545 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); 1578 if (rtd->codec_dais[i]->driver->ac97_control)
1579 snd_ac97_dev_add_pdata(rtd->codec_dais[i]->codec->ac97,
1580 rtd->cpu_dai->ac97_pdata);
1581 }
1546 1582
1547 return 0; 1583 return 0;
1548} 1584}
@@ -1580,11 +1616,6 @@ static int soc_register_ac97_codec(struct snd_soc_codec *codec,
1580 return 0; 1616 return 0;
1581} 1617}
1582 1618
1583static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1584{
1585 return soc_register_ac97_codec(rtd->codec, rtd->codec_dai);
1586}
1587
1588static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) 1619static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
1589{ 1620{
1590 if (codec->ac97_registered) { 1621 if (codec->ac97_registered) {
@@ -1593,9 +1624,30 @@ static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
1593 } 1624 }
1594} 1625}
1595 1626
1627static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1628{
1629 int i, ret;
1630
1631 for (i = 0; i < rtd->num_codecs; i++) {
1632 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
1633
1634 ret = soc_register_ac97_codec(codec_dai->codec, codec_dai);
1635 if (ret) {
1636 while (--i >= 0)
1637 soc_unregister_ac97_codec(codec_dai->codec);
1638 return ret;
1639 }
1640 }
1641
1642 return 0;
1643}
1644
1596static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) 1645static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1597{ 1646{
1598 soc_unregister_ac97_codec(rtd->codec); 1647 int i;
1648
1649 for (i = 0; i < rtd->num_codecs; i++)
1650 soc_unregister_ac97_codec(rtd->codec_dais[i]->codec);
1599} 1651}
1600#endif 1652#endif
1601 1653
@@ -1794,16 +1846,23 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1794 card->num_dapm_routes); 1846 card->num_dapm_routes);
1795 1847
1796 for (i = 0; i < card->num_links; i++) { 1848 for (i = 0; i < card->num_links; i++) {
1849 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1797 dai_link = &card->dai_link[i]; 1850 dai_link = &card->dai_link[i];
1798 dai_fmt = dai_link->dai_fmt; 1851 dai_fmt = dai_link->dai_fmt;
1799 1852
1800 if (dai_fmt) { 1853 if (dai_fmt) {
1801 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, 1854 struct snd_soc_dai **codec_dais = rtd->codec_dais;
1802 dai_fmt); 1855 int j;
1803 if (ret != 0 && ret != -ENOTSUPP) 1856
1804 dev_warn(card->rtd[i].codec_dai->dev, 1857 for (j = 0; j < rtd->num_codecs; j++) {
1805 "ASoC: Failed to set DAI format: %d\n", 1858 struct snd_soc_dai *codec_dai = codec_dais[j];
1806 ret); 1859
1860 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1861 if (ret != 0 && ret != -ENOTSUPP)
1862 dev_warn(codec_dai->dev,
1863 "ASoC: Failed to set DAI format: %d\n",
1864 ret);
1865 }
1807 } 1866 }
1808 1867
1809 /* If this is a regular CPU link there will be a platform */ 1868 /* If this is a regular CPU link there will be a platform */
@@ -2002,10 +2061,15 @@ int snd_soc_poweroff(struct device *dev)
2002 2061
2003 /* deactivate pins to sleep state */ 2062 /* deactivate pins to sleep state */
2004 for (i = 0; i < card->num_rtd; i++) { 2063 for (i = 0; i < card->num_rtd; i++) {
2005 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 2064 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
2006 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; 2065 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2007 pinctrl_pm_select_sleep_state(codec_dai->dev); 2066 int j;
2067
2008 pinctrl_pm_select_sleep_state(cpu_dai->dev); 2068 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2069 for (j = 0; j < rtd->num_codecs; j++) {
2070 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
2071 pinctrl_pm_select_sleep_state(codec_dai->dev);
2072 }
2009 } 2073 }
2010 2074
2011 return 0; 2075 return 0;
@@ -3585,6 +3649,9 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
3585 else 3649 else
3586 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); 3650 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
3587 3651
3652 dai->tx_mask = tx_mask;
3653 dai->rx_mask = rx_mask;
3654
3588 if (dai->driver && dai->driver->ops->set_tdm_slot) 3655 if (dai->driver && dai->driver->ops->set_tdm_slot)
3589 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 3656 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
3590 slots, slot_width); 3657 slots, slot_width);
@@ -3657,6 +3724,33 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
3657} 3724}
3658EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 3725EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3659 3726
3727static int snd_soc_init_multicodec(struct snd_soc_card *card,
3728 struct snd_soc_dai_link *dai_link)
3729{
3730 /* Legacy codec/codec_dai link is a single entry in multicodec */
3731 if (dai_link->codec_name || dai_link->codec_of_node ||
3732 dai_link->codec_dai_name) {
3733 dai_link->num_codecs = 1;
3734
3735 dai_link->codecs = devm_kzalloc(card->dev,
3736 sizeof(struct snd_soc_dai_link_component),
3737 GFP_KERNEL);
3738 if (!dai_link->codecs)
3739 return -ENOMEM;
3740
3741 dai_link->codecs[0].name = dai_link->codec_name;
3742 dai_link->codecs[0].of_node = dai_link->codec_of_node;
3743 dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
3744 }
3745
3746 if (!dai_link->codecs) {
3747 dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
3748 return -EINVAL;
3749 }
3750
3751 return 0;
3752}
3753
3660/** 3754/**
3661 * snd_soc_register_card - Register a card with the ASoC core 3755 * snd_soc_register_card - Register a card with the ASoC core
3662 * 3756 *
@@ -3665,7 +3759,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3665 */ 3759 */
3666int snd_soc_register_card(struct snd_soc_card *card) 3760int snd_soc_register_card(struct snd_soc_card *card)
3667{ 3761{
3668 int i, ret; 3762 int i, j, ret;
3669 3763
3670 if (!card->name || !card->dev) 3764 if (!card->name || !card->dev)
3671 return -EINVAL; 3765 return -EINVAL;
@@ -3673,22 +3767,29 @@ int snd_soc_register_card(struct snd_soc_card *card)
3673 for (i = 0; i < card->num_links; i++) { 3767 for (i = 0; i < card->num_links; i++) {
3674 struct snd_soc_dai_link *link = &card->dai_link[i]; 3768 struct snd_soc_dai_link *link = &card->dai_link[i];
3675 3769
3676 /* 3770 ret = snd_soc_init_multicodec(card, link);
3677 * Codec must be specified by 1 of name or OF node, 3771 if (ret) {
3678 * not both or neither. 3772 dev_err(card->dev, "ASoC: failed to init multicodec\n");
3679 */ 3773 return ret;
3680 if (!!link->codec_name == !!link->codec_of_node) {
3681 dev_err(card->dev,
3682 "ASoC: Neither/both codec name/of_node are set for %s\n",
3683 link->name);
3684 return -EINVAL;
3685 } 3774 }
3686 /* Codec DAI name must be specified */ 3775
3687 if (!link->codec_dai_name) { 3776 for (j = 0; j < link->num_codecs; j++) {
3688 dev_err(card->dev, 3777 /*
3689 "ASoC: codec_dai_name not set for %s\n", 3778 * Codec must be specified by 1 of name or OF node,
3690 link->name); 3779 * not both or neither.
3691 return -EINVAL; 3780 */
3781 if (!!link->codecs[j].name ==
3782 !!link->codecs[j].of_node) {
3783 dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
3784 link->name);
3785 return -EINVAL;
3786 }
3787 /* Codec DAI name must be specified */
3788 if (!link->codecs[j].dai_name) {
3789 dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
3790 link->name);
3791 return -EINVAL;
3792 }
3692 } 3793 }
3693 3794
3694 /* 3795 /*
@@ -3744,6 +3845,12 @@ int snd_soc_register_card(struct snd_soc_card *card)
3744 for (i = 0; i < card->num_links; i++) { 3845 for (i = 0; i < card->num_links; i++) {
3745 card->rtd[i].card = card; 3846 card->rtd[i].card = card;
3746 card->rtd[i].dai_link = &card->dai_link[i]; 3847 card->rtd[i].dai_link = &card->dai_link[i];
3848 card->rtd[i].codec_dais = devm_kzalloc(card->dev,
3849 sizeof(struct snd_soc_dai *) *
3850 (card->rtd[i].dai_link->num_codecs),
3851 GFP_KERNEL);
3852 if (card->rtd[i].codec_dais == NULL)
3853 return -ENOMEM;
3747 } 3854 }
3748 3855
3749 for (i = 0; i < card->num_aux_devs; i++) 3856 for (i = 0; i < card->num_aux_devs; i++)
@@ -3760,10 +3867,16 @@ int snd_soc_register_card(struct snd_soc_card *card)
3760 3867
3761 /* deactivate pins to sleep state */ 3868 /* deactivate pins to sleep state */
3762 for (i = 0; i < card->num_rtd; i++) { 3869 for (i = 0; i < card->num_rtd; i++) {
3763 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 3870 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
3764 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; 3871 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3765 if (!codec_dai->active) 3872 int j;
3766 pinctrl_pm_select_sleep_state(codec_dai->dev); 3873
3874 for (j = 0; j < rtd->num_codecs; j++) {
3875 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
3876 if (!codec_dai->active)
3877 pinctrl_pm_select_sleep_state(codec_dai->dev);
3878 }
3879
3767 if (!cpu_dai->active) 3880 if (!cpu_dai->active)
3768 pinctrl_pm_select_sleep_state(cpu_dai->dev); 3881 pinctrl_pm_select_sleep_state(cpu_dai->dev);
3769 } 3882 }