aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorJarkko Nikula <jhnikula@gmail.com>2010-11-13 13:40:44 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-11-15 10:24:58 -0500
commitead9b9199c09653dd9b889933c7af75f020c7286 (patch)
tree54ea7e4e8b8954236387f1131a9a09e305704c46 /sound/soc/soc-core.c
parent6ccd744123679c1f19fb6e414e3df717d9ed57f6 (diff)
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in an ASoC machine that has multiple codecs with conflicting names. The name collision would occur when codec drivers try to registering kcontrols with the same name or when building audio paths. This patch introduces optional prefix_map into struct snd_soc_card. With it machine drivers can specify a unique name prefix to each codec that have conflicting names with anothers. Prefix to codec is matched with codec name. Following example illustrates a machine that has two same codec instances. Name collision from kcontrol registration is avoided by specifying a name prefix "foo" for the second codec. As the codec widget names are prefixed then second audio map for that codec shows a prefixed widget name. static const struct snd_soc_dapm_route map0[] = { {"Spk", NULL, "MONO"}, }; static const struct snd_soc_dapm_route map1[] = { {"Vibra", NULL, "foo MONO"}, }; static struct snd_soc_prefix_map codec_prefix[] = { { .dev_name = "codec.2", .name_prefix = "foo", }, }; static struct snd_soc_card card = { ... .prefix_map = codec_prefix, .num_prefixes = ARRAY_SIZE(codec_prefix), }; Signed-off-by: Jarkko Nikula <jhnikula@gmail.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 3d70ce58d03c..2540efd67ee7 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1397,6 +1397,23 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1397 } 1397 }
1398} 1398}
1399 1399
1400static void soc_set_name_prefix(struct snd_soc_card *card,
1401 struct snd_soc_codec *codec)
1402{
1403 int i;
1404
1405 if (card->prefix_map == NULL)
1406 return;
1407
1408 for (i = 0; i < card->num_prefixes; i++) {
1409 struct snd_soc_prefix_map *map = &card->prefix_map[i];
1410 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1411 codec->name_prefix = map->name_prefix;
1412 break;
1413 }
1414 }
1415}
1416
1400static void rtd_release(struct device *dev) {} 1417static void rtd_release(struct device *dev) {}
1401 1418
1402static int soc_probe_dai_link(struct snd_soc_card *card, int num) 1419static int soc_probe_dai_link(struct snd_soc_card *card, int num)
@@ -1406,6 +1423,7 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1406 struct snd_soc_codec *codec = rtd->codec; 1423 struct snd_soc_codec *codec = rtd->codec;
1407 struct snd_soc_platform *platform = rtd->platform; 1424 struct snd_soc_platform *platform = rtd->platform;
1408 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1425 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1426 const char *temp;
1409 int ret; 1427 int ret;
1410 1428
1411 dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num); 1429 dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
@@ -1440,6 +1458,7 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1440 /* probe the CODEC */ 1458 /* probe the CODEC */
1441 if (!codec->probed) { 1459 if (!codec->probed) {
1442 codec->dapm.card = card; 1460 codec->dapm.card = card;
1461 soc_set_name_prefix(card, codec);
1443 if (codec->driver->probe) { 1462 if (codec->driver->probe) {
1444 ret = codec->driver->probe(codec); 1463 ret = codec->driver->probe(codec);
1445 if (ret < 0) { 1464 if (ret < 0) {
@@ -1492,11 +1511,15 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1492 1511
1493 /* now that all clients have probed, initialise the DAI link */ 1512 /* now that all clients have probed, initialise the DAI link */
1494 if (dai_link->init) { 1513 if (dai_link->init) {
1514 /* machine controls, routes and widgets are not prefixed */
1515 temp = rtd->codec->name_prefix;
1516 rtd->codec->name_prefix = NULL;
1495 ret = dai_link->init(rtd); 1517 ret = dai_link->init(rtd);
1496 if (ret < 0) { 1518 if (ret < 0) {
1497 printk(KERN_ERR "asoc: failed to init %s\n", dai_link->stream_name); 1519 printk(KERN_ERR "asoc: failed to init %s\n", dai_link->stream_name);
1498 return ret; 1520 return ret;
1499 } 1521 }
1522 rtd->codec->name_prefix = temp;
1500 } 1523 }
1501 1524
1502 /* Make sure all DAPM widgets are instantiated */ 1525 /* Make sure all DAPM widgets are instantiated */
@@ -2072,14 +2095,22 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
2072 const struct snd_kcontrol_new *controls, int num_controls) 2095 const struct snd_kcontrol_new *controls, int num_controls)
2073{ 2096{
2074 struct snd_card *card = codec->card->snd_card; 2097 struct snd_card *card = codec->card->snd_card;
2098 char prefixed_name[44], *name;
2075 int err, i; 2099 int err, i;
2076 2100
2077 for (i = 0; i < num_controls; i++) { 2101 for (i = 0; i < num_controls; i++) {
2078 const struct snd_kcontrol_new *control = &controls[i]; 2102 const struct snd_kcontrol_new *control = &controls[i];
2079 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL)); 2103 if (codec->name_prefix) {
2104 snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
2105 codec->name_prefix, control->name);
2106 name = prefixed_name;
2107 } else {
2108 name = control->name;
2109 }
2110 err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
2080 if (err < 0) { 2111 if (err < 0) {
2081 dev_err(codec->dev, "%s: Failed to add %s: %d\n", 2112 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2082 codec->name, control->name, err); 2113 codec->name, name, err);
2083 return err; 2114 return err;
2084 } 2115 }
2085 } 2116 }