aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-dapm.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-dapm.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-dapm.c')
-rw-r--r--sound/soc/soc-dapm.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index bc2ec06943c0..60c8dec49480 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1295,6 +1295,7 @@ static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1295 1295
1296 list_for_each_entry_safe(w, next_w, &dapm->widgets, list) { 1296 list_for_each_entry_safe(w, next_w, &dapm->widgets, list) {
1297 list_del(&w->list); 1297 list_del(&w->list);
1298 kfree(w->name);
1298 kfree(w); 1299 kfree(w);
1299 } 1300 }
1300 1301
@@ -1346,11 +1347,25 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1346{ 1347{
1347 struct snd_soc_dapm_path *path; 1348 struct snd_soc_dapm_path *path;
1348 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; 1349 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1349 const char *sink = route->sink; 1350 const char *sink;
1350 const char *control = route->control; 1351 const char *control = route->control;
1351 const char *source = route->source; 1352 const char *source;
1353 char prefixed_sink[80];
1354 char prefixed_source[80];
1352 int ret = 0; 1355 int ret = 0;
1353 1356
1357 if (dapm->codec->name_prefix) {
1358 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1359 dapm->codec->name_prefix, route->sink);
1360 sink = prefixed_sink;
1361 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1362 dapm->codec->name_prefix, route->source);
1363 source = prefixed_source;
1364 } else {
1365 sink = route->sink;
1366 source = route->source;
1367 }
1368
1354 /* find src and dest widgets */ 1369 /* find src and dest widgets */
1355 list_for_each_entry(w, &dapm->widgets, list) { 1370 list_for_each_entry(w, &dapm->widgets, list) {
1356 1371
@@ -1978,10 +1993,25 @@ int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
1978 const struct snd_soc_dapm_widget *widget) 1993 const struct snd_soc_dapm_widget *widget)
1979{ 1994{
1980 struct snd_soc_dapm_widget *w; 1995 struct snd_soc_dapm_widget *w;
1996 size_t name_len;
1981 1997
1982 if ((w = dapm_cnew_widget(widget)) == NULL) 1998 if ((w = dapm_cnew_widget(widget)) == NULL)
1983 return -ENOMEM; 1999 return -ENOMEM;
1984 2000
2001 name_len = strlen(widget->name) + 1;
2002 if (dapm->codec->name_prefix)
2003 name_len += 1 + strlen(dapm->codec->name_prefix);
2004 w->name = kmalloc(name_len, GFP_KERNEL);
2005 if (w->name == NULL) {
2006 kfree(w);
2007 return -ENOMEM;
2008 }
2009 if (dapm->codec->name_prefix)
2010 snprintf(w->name, name_len, "%s %s",
2011 dapm->codec->name_prefix, widget->name);
2012 else
2013 snprintf(w->name, name_len, "%s", widget->name);
2014
1985 w->dapm = dapm; 2015 w->dapm = dapm;
1986 w->codec = dapm->codec; 2016 w->codec = dapm->codec;
1987 INIT_LIST_HEAD(&w->sources); 2017 INIT_LIST_HEAD(&w->sources);