aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-08 12:23:24 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-08 13:56:35 -0500
commitefb7ac3f9c28fcb379c51f987b63174f727b7453 (patch)
tree0da50b269bc9f6fc9832144d9cc8ea4a64bc7b9f /sound/soc
parentc4ef87867b42bd1fa7d6dacaa28bf07cf741a724 (diff)
ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
Currently will ignore prefixes when creating DAPM controls. Since currently all control creation goes through snd_soc_cnew() we can fix this by factoring the prefixing into that function. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@ti.com>
Diffstat (limited to 'sound/soc')
-rw-r--r--sound/soc/soc-core.c45
-rw-r--r--sound/soc/soc-dapm.c16
2 files changed, 45 insertions, 16 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index db3075dd11f..17efacdb248 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2344,22 +2344,45 @@ EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
2344 * @_template: control template 2344 * @_template: control template
2345 * @data: control private data 2345 * @data: control private data
2346 * @long_name: control long name 2346 * @long_name: control long name
2347 * @prefix: control name prefix
2347 * 2348 *
2348 * Create a new mixer control from a template control. 2349 * Create a new mixer control from a template control.
2349 * 2350 *
2350 * Returns 0 for success, else error. 2351 * Returns 0 for success, else error.
2351 */ 2352 */
2352struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 2353struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2353 void *data, char *long_name) 2354 void *data, char *long_name,
2355 const char *prefix)
2354{ 2356{
2355 struct snd_kcontrol_new template; 2357 struct snd_kcontrol_new template;
2358 struct snd_kcontrol *kcontrol;
2359 char *name = NULL;
2360 int name_len;
2356 2361
2357 memcpy(&template, _template, sizeof(template)); 2362 memcpy(&template, _template, sizeof(template));
2358 if (long_name)
2359 template.name = long_name;
2360 template.index = 0; 2363 template.index = 0;
2361 2364
2362 return snd_ctl_new1(&template, data); 2365 if (!long_name)
2366 long_name = template.name;
2367
2368 if (prefix) {
2369 name_len = strlen(long_name) + strlen(prefix) + 2;
2370 name = kmalloc(name_len, GFP_ATOMIC);
2371 if (!name)
2372 return NULL;
2373
2374 snprintf(name, name_len, "%s %s", prefix, long_name);
2375
2376 template.name = name;
2377 } else {
2378 template.name = long_name;
2379 }
2380
2381 kcontrol = snd_ctl_new1(&template, data);
2382
2383 kfree(name);
2384
2385 return kcontrol;
2363} 2386}
2364EXPORT_SYMBOL_GPL(snd_soc_cnew); 2387EXPORT_SYMBOL_GPL(snd_soc_cnew);
2365 2388
@@ -2378,22 +2401,16 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
2378 const struct snd_kcontrol_new *controls, int num_controls) 2401 const struct snd_kcontrol_new *controls, int num_controls)
2379{ 2402{
2380 struct snd_card *card = codec->card->snd_card; 2403 struct snd_card *card = codec->card->snd_card;
2381 char prefixed_name[44], *name;
2382 int err, i; 2404 int err, i;
2383 2405
2384 for (i = 0; i < num_controls; i++) { 2406 for (i = 0; i < num_controls; i++) {
2385 const struct snd_kcontrol_new *control = &controls[i]; 2407 const struct snd_kcontrol_new *control = &controls[i];
2386 if (codec->name_prefix) { 2408 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2387 snprintf(prefixed_name, sizeof(prefixed_name), "%s %s", 2409 control->name,
2388 codec->name_prefix, control->name); 2410 codec->name_prefix));
2389 name = prefixed_name;
2390 } else {
2391 name = control->name;
2392 }
2393 err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
2394 if (err < 0) { 2411 if (err < 0) {
2395 dev_err(codec->dev, "%s: Failed to add %s: %d\n", 2412 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2396 codec->name, name, err); 2413 codec->name, control->name, err);
2397 return err; 2414 return err;
2398 } 2415 }
2399 } 2416 }
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 570db8819d9..a6fb85d4641 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -369,6 +369,12 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
369 size_t name_len; 369 size_t name_len;
370 struct snd_soc_dapm_path *path; 370 struct snd_soc_dapm_path *path;
371 struct snd_card *card = dapm->card->snd_card; 371 struct snd_card *card = dapm->card->snd_card;
372 const char *prefix;
373
374 if (dapm->codec)
375 prefix = dapm->codec->name_prefix;
376 else
377 prefix = NULL;
372 378
373 /* add kcontrol */ 379 /* add kcontrol */
374 for (i = 0; i < w->num_kcontrols; i++) { 380 for (i = 0; i < w->num_kcontrols; i++) {
@@ -409,7 +415,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
409 path->long_name[name_len - 1] = '\0'; 415 path->long_name[name_len - 1] = '\0';
410 416
411 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, 417 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
412 path->long_name); 418 path->long_name, prefix);
413 ret = snd_ctl_add(card, path->kcontrol); 419 ret = snd_ctl_add(card, path->kcontrol);
414 if (ret < 0) { 420 if (ret < 0) {
415 dev_err(dapm->dev, 421 dev_err(dapm->dev,
@@ -431,6 +437,7 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
431 struct snd_soc_dapm_path *path = NULL; 437 struct snd_soc_dapm_path *path = NULL;
432 struct snd_kcontrol *kcontrol; 438 struct snd_kcontrol *kcontrol;
433 struct snd_card *card = dapm->card->snd_card; 439 struct snd_card *card = dapm->card->snd_card;
440 const char *prefix;
434 int ret = 0; 441 int ret = 0;
435 442
436 if (!w->num_kcontrols) { 443 if (!w->num_kcontrols) {
@@ -438,7 +445,12 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
438 return -EINVAL; 445 return -EINVAL;
439 } 446 }
440 447
441 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name); 448 if (dapm->codec)
449 prefix = dapm->codec->name_prefix;
450 else
451 prefix = NULL;
452
453 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name, prefix);
442 ret = snd_ctl_add(card, kcontrol); 454 ret = snd_ctl_add(card, kcontrol);
443 455
444 if (ret < 0) 456 if (ret < 0)