aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2009-11-03 17:13:13 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-11-03 17:14:43 -0500
commitfe3e78e073d25308756f38019956061153267769 (patch)
tree6590150d5c67f8a5889f3d254fe82e5abf46f83a /sound/soc/soc-core.c
parent2624d5fa67a5d3d720613a4ab0672e8c387ba806 (diff)
ASoC: Factor out snd_soc_init_card()
snd_soc_init_card() is always called as the last part of the CODEC probe function so we can factor it out into the core card setup rather than have each CODEC replicate the code to do the initialiastation. This will be required to support multiple CODECs per card. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c141
1 files changed, 64 insertions, 77 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index d81a16187769..e2b6d75f16e3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -970,6 +970,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
970 struct platform_device, 970 struct platform_device,
971 dev); 971 dev);
972 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev; 972 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
973 struct snd_soc_codec *codec;
973 struct snd_soc_platform *platform; 974 struct snd_soc_platform *platform;
974 struct snd_soc_dai *dai; 975 struct snd_soc_dai *dai;
975 int i, found, ret, ac97; 976 int i, found, ret, ac97;
@@ -1058,6 +1059,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1058 if (ret < 0) 1059 if (ret < 0)
1059 goto cpu_dai_err; 1060 goto cpu_dai_err;
1060 } 1061 }
1062 codec = card->codec;
1061 1063
1062 if (platform->probe) { 1064 if (platform->probe) {
1063 ret = platform->probe(pdev); 1065 ret = platform->probe(pdev);
@@ -1072,10 +1074,72 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1072 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 1074 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1073#endif 1075#endif
1074 1076
1077 for (i = 0; i < card->num_links; i++) {
1078 if (card->dai_link[i].init) {
1079 ret = card->dai_link[i].init(codec);
1080 if (ret < 0) {
1081 printk(KERN_ERR "asoc: failed to init %s\n",
1082 card->dai_link[i].stream_name);
1083 continue;
1084 }
1085 }
1086 if (card->dai_link[i].codec_dai->ac97_control) {
1087 ac97 = 1;
1088 snd_ac97_dev_add_pdata(codec->ac97,
1089 card->dai_link[i].cpu_dai->ac97_pdata);
1090 }
1091 }
1092
1093 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1094 "%s", card->name);
1095 snprintf(codec->card->longname, sizeof(codec->card->longname),
1096 "%s (%s)", card->name, codec->name);
1097
1098 /* Make sure all DAPM widgets are instantiated */
1099 snd_soc_dapm_new_widgets(codec);
1100
1101 ret = snd_card_register(codec->card);
1102 if (ret < 0) {
1103 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1104 codec->name);
1105 goto card_err;
1106 }
1107
1108 mutex_lock(&codec->mutex);
1109#ifdef CONFIG_SND_SOC_AC97_BUS
1110 /* Only instantiate AC97 if not already done by the adaptor
1111 * for the generic AC97 subsystem.
1112 */
1113 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1114 ret = soc_ac97_dev_register(codec);
1115 if (ret < 0) {
1116 printk(KERN_ERR "asoc: AC97 device register failed\n");
1117 snd_card_free(codec->card);
1118 mutex_unlock(&codec->mutex);
1119 goto card_err;
1120 }
1121 }
1122#endif
1123
1124 ret = snd_soc_dapm_sys_add(card->socdev->dev);
1125 if (ret < 0)
1126 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1127
1128 ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg);
1129 if (ret < 0)
1130 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1131
1132 soc_init_codec_debugfs(codec);
1133 mutex_unlock(&codec->mutex);
1134
1075 card->instantiated = 1; 1135 card->instantiated = 1;
1076 1136
1077 return; 1137 return;
1078 1138
1139card_err:
1140 if (platform->remove)
1141 platform->remove(pdev);
1142
1079platform_err: 1143platform_err:
1080 if (codec_dev->remove) 1144 if (codec_dev->remove)
1081 codec_dev->remove(pdev); 1145 codec_dev->remove(pdev);
@@ -1454,83 +1518,6 @@ int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1454EXPORT_SYMBOL_GPL(snd_soc_new_pcms); 1518EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1455 1519
1456/** 1520/**
1457 * snd_soc_init_card - register sound card
1458 * @socdev: the SoC audio device
1459 *
1460 * Register a SoC sound card. Also registers an AC97 device if the
1461 * codec is AC97 for ad hoc devices.
1462 *
1463 * Returns 0 for success, else error.
1464 */
1465int snd_soc_init_card(struct snd_soc_device *socdev)
1466{
1467 struct snd_soc_card *card = socdev->card;
1468 struct snd_soc_codec *codec = card->codec;
1469 int ret = 0, i, ac97 = 0, err = 0;
1470
1471 for (i = 0; i < card->num_links; i++) {
1472 if (card->dai_link[i].init) {
1473 err = card->dai_link[i].init(codec);
1474 if (err < 0) {
1475 printk(KERN_ERR "asoc: failed to init %s\n",
1476 card->dai_link[i].stream_name);
1477 continue;
1478 }
1479 }
1480 if (card->dai_link[i].codec_dai->ac97_control) {
1481 ac97 = 1;
1482 snd_ac97_dev_add_pdata(codec->ac97,
1483 card->dai_link[i].cpu_dai->ac97_pdata);
1484 }
1485 }
1486 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1487 "%s", card->name);
1488 snprintf(codec->card->longname, sizeof(codec->card->longname),
1489 "%s (%s)", card->name, codec->name);
1490
1491 /* Make sure all DAPM widgets are instantiated */
1492 snd_soc_dapm_new_widgets(codec);
1493
1494 ret = snd_card_register(codec->card);
1495 if (ret < 0) {
1496 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1497 codec->name);
1498 goto out;
1499 }
1500
1501 mutex_lock(&codec->mutex);
1502#ifdef CONFIG_SND_SOC_AC97_BUS
1503 /* Only instantiate AC97 if not already done by the adaptor
1504 * for the generic AC97 subsystem.
1505 */
1506 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1507 ret = soc_ac97_dev_register(codec);
1508 if (ret < 0) {
1509 printk(KERN_ERR "asoc: AC97 device register failed\n");
1510 snd_card_free(codec->card);
1511 mutex_unlock(&codec->mutex);
1512 goto out;
1513 }
1514 }
1515#endif
1516
1517 err = snd_soc_dapm_sys_add(socdev->dev);
1518 if (err < 0)
1519 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1520
1521 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1522 if (err < 0)
1523 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1524
1525 soc_init_codec_debugfs(codec);
1526 mutex_unlock(&codec->mutex);
1527
1528out:
1529 return ret;
1530}
1531EXPORT_SYMBOL_GPL(snd_soc_init_card);
1532
1533/**
1534 * snd_soc_free_pcms - free sound card and pcms 1521 * snd_soc_free_pcms - free sound card and pcms
1535 * @socdev: the SoC audio device 1522 * @socdev: the SoC audio device
1536 * 1523 *