aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-07-01 16:13:48 -0400
committerMark Brown <broonie@linaro.org>2014-07-02 16:24:13 -0400
commit5f3484ac8775a183f855fd213907c4221d2fb11f (patch)
treefe4e7dd1b0d203b4843ff49684730c7d0539b830
parent44c69bb13905c3b2281a920c0b44059e88819993 (diff)
ASoC: core: Move non-shared code paths out of snd_soc_post_component_init()
There are two call sites for snd_soc_post_component_init(), one passes 0 and the other 1 for the 'dailess' parameter of snd_soc_post_component_init(). Depending on whether 'dailess' is 0 or 1 snd_soc_post_component_init() runs different code at the beginning and the end of the function. The patch moves this conditional code out of snd_soc_post_component_init() and into the call sites. This removes the need for snd_soc_post_component_init() to know whether it is called for a DAI link or a aux dev. Also do the initialization of rtd->card when the rtd struct is allocated. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--sound/soc/soc-core.c121
1 files changed, 46 insertions, 75 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b1600cdcdc14..c4db07f01d10 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1286,74 +1286,17 @@ static void rtd_release(struct device *dev)
1286 kfree(dev); 1286 kfree(dev);
1287} 1287}
1288 1288
1289static int soc_aux_dev_init(struct snd_soc_card *card, int num) 1289static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1290 const char *name)
1290{ 1291{
1291 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1292 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1293 int ret;
1294
1295 rtd->card = card;
1296
1297 /* do machine specific initialization */
1298 if (aux_dev->init) {
1299 ret = aux_dev->init(&rtd->codec->dapm);
1300 if (ret < 0)
1301 return ret;
1302 }
1303
1304 return 0;
1305}
1306
1307static int soc_dai_link_init(struct snd_soc_card *card, int num)
1308{
1309 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1310 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1311 int ret;
1312
1313 rtd->card = card;
1314
1315 /* do machine specific initialization */
1316 if (dai_link->init) {
1317 ret = dai_link->init(rtd);
1318 if (ret < 0)
1319 return ret;
1320 }
1321
1322 return 0;
1323}
1324
1325static int soc_post_component_init(struct snd_soc_card *card,
1326 int num, int dailess)
1327{
1328 struct snd_soc_dai_link *dai_link = NULL;
1329 struct snd_soc_aux_dev *aux_dev = NULL;
1330 struct snd_soc_pcm_runtime *rtd;
1331 const char *name;
1332 int ret = 0; 1292 int ret = 0;
1333 1293
1334 if (!dailess) {
1335 dai_link = &card->dai_link[num];
1336 rtd = &card->rtd[num];
1337 name = dai_link->name;
1338 ret = soc_dai_link_init(card, num);
1339 } else {
1340 aux_dev = &card->aux_dev[num];
1341 rtd = &card->rtd_aux[num];
1342 name = aux_dev->name;
1343 ret = soc_aux_dev_init(card, num);
1344 }
1345
1346 if (ret < 0) {
1347 dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
1348 return ret;
1349 }
1350
1351 /* register the rtd device */ 1294 /* register the rtd device */
1352 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 1295 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1353 if (!rtd->dev) 1296 if (!rtd->dev)
1354 return -ENOMEM; 1297 return -ENOMEM;
1355 device_initialize(rtd->dev); 1298 device_initialize(rtd->dev);
1356 rtd->dev->parent = card->dev; 1299 rtd->dev->parent = rtd->card->dev;
1357 rtd->dev->release = rtd_release; 1300 rtd->dev->release = rtd_release;
1358 rtd->dev->init_name = name; 1301 rtd->dev->init_name = name;
1359 dev_set_drvdata(rtd->dev, rtd); 1302 dev_set_drvdata(rtd->dev, rtd);
@@ -1366,7 +1309,7 @@ static int soc_post_component_init(struct snd_soc_card *card,
1366 if (ret < 0) { 1309 if (ret < 0) {
1367 /* calling put_device() here to free the rtd->dev */ 1310 /* calling put_device() here to free the rtd->dev */
1368 put_device(rtd->dev); 1311 put_device(rtd->dev);
1369 dev_err(card->dev, 1312 dev_err(rtd->card->dev,
1370 "ASoC: failed to register runtime device: %d\n", ret); 1313 "ASoC: failed to register runtime device: %d\n", ret);
1371 return ret; 1314 return ret;
1372 } 1315 }
@@ -1384,17 +1327,6 @@ static int soc_post_component_init(struct snd_soc_card *card,
1384 dev_err(rtd->dev, 1327 dev_err(rtd->dev,
1385 "ASoC: failed to add codec sysfs files: %d\n", ret); 1328 "ASoC: failed to add codec sysfs files: %d\n", ret);
1386 1329
1387#ifdef CONFIG_DEBUG_FS
1388 /* add DPCM sysfs entries */
1389 if (!dailess && !dai_link->dynamic)
1390 goto out;
1391
1392 ret = soc_dpcm_debugfs_add(rtd);
1393 if (ret < 0)
1394 dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
1395
1396out:
1397#endif
1398 return 0; 1330 return 0;
1399} 1331}
1400 1332
@@ -1546,10 +1478,33 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1546 if (order != SND_SOC_COMP_ORDER_LAST) 1478 if (order != SND_SOC_COMP_ORDER_LAST)
1547 return 0; 1479 return 0;
1548 1480
1549 ret = soc_post_component_init(card, num, 0); 1481 /* do machine specific initialization */
1482 if (dai_link->init) {
1483 ret = dai_link->init(rtd);
1484 if (ret < 0) {
1485 dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1486 dai_link->name, ret);
1487 return ret;
1488 }
1489 }
1490
1491 ret = soc_post_component_init(rtd, dai_link->name);
1550 if (ret) 1492 if (ret)
1551 return ret; 1493 return ret;
1552 1494
1495#ifdef CONFIG_DEBUG_FS
1496 /* add DPCM sysfs entries */
1497 if (dai_link->dynamic) {
1498 ret = soc_dpcm_debugfs_add(rtd);
1499 if (ret < 0) {
1500 dev_err(rtd->dev,
1501 "ASoC: failed to add dpcm sysfs entries: %d\n",
1502 ret);
1503 return ret;
1504 }
1505 }
1506#endif
1507
1553 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); 1508 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1554 if (ret < 0) 1509 if (ret < 0)
1555 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", 1510 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
@@ -1665,6 +1620,7 @@ static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1665static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 1620static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1666{ 1621{
1667 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 1622 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1623 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1668 int ret; 1624 int ret;
1669 1625
1670 if (rtd->codec->probed) { 1626 if (rtd->codec->probed) {
@@ -1676,7 +1632,17 @@ static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1676 if (ret < 0) 1632 if (ret < 0)
1677 return ret; 1633 return ret;
1678 1634
1679 return soc_post_component_init(card, num, 1); 1635 /* do machine specific initialization */
1636 if (aux_dev->init) {
1637 ret = aux_dev->init(&rtd->codec->dapm);
1638 if (ret < 0) {
1639 dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1640 aux_dev->name, ret);
1641 return ret;
1642 }
1643 }
1644
1645 return soc_post_component_init(rtd, aux_dev->name);
1680} 1646}
1681 1647
1682static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 1648static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
@@ -3775,8 +3741,13 @@ int snd_soc_register_card(struct snd_soc_card *card)
3775 card->num_rtd = 0; 3741 card->num_rtd = 0;
3776 card->rtd_aux = &card->rtd[card->num_links]; 3742 card->rtd_aux = &card->rtd[card->num_links];
3777 3743
3778 for (i = 0; i < card->num_links; i++) 3744 for (i = 0; i < card->num_links; i++) {
3745 card->rtd[i].card = card;
3779 card->rtd[i].dai_link = &card->dai_link[i]; 3746 card->rtd[i].dai_link = &card->dai_link[i];
3747 }
3748
3749 for (i = 0; i < card->num_aux_devs; i++)
3750 card->rtd_aux[i].card = card;
3780 3751
3781 INIT_LIST_HEAD(&card->dapm_dirty); 3752 INIT_LIST_HEAD(&card->dapm_dirty);
3782 card->instantiated = 0; 3753 card->instantiated = 0;