* [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
@ 2011-03-08 17:25 Mark Brown
2011-03-08 18:01 ` Liam Girdwood
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2011-03-08 17:25 UTC (permalink / raw)
To: Liam Girdwood; +Cc: alsa-devel, patches, Peter Ujfalusi, Mark Brown
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>
---
include/sound/soc.h | 3 ++-
sound/soc/soc-core.c | 45 +++++++++++++++++++++++++++++++--------------
sound/soc/soc-dapm.c | 16 ++++++++++++++--
3 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 8b097f7..876dd5a 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -341,7 +341,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
*Controls
*/
struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
- void *data, char *long_name);
+ void *data, char *long_name,
+ const char *prefix);
int snd_soc_add_controls(struct snd_soc_codec *codec,
const struct snd_kcontrol_new *controls, int num_controls);
int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index db3075d..17efacd 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);
* @_template: control template
* @data: control private data
* @long_name: control long name
+ * @prefix: control name prefix
*
* Create a new mixer control from a template control.
*
* Returns 0 for success, else error.
*/
struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
- void *data, char *long_name)
+ void *data, char *long_name,
+ const char *prefix)
{
struct snd_kcontrol_new template;
+ struct snd_kcontrol *kcontrol;
+ char *name = NULL;
+ int name_len;
memcpy(&template, _template, sizeof(template));
- if (long_name)
- template.name = long_name;
template.index = 0;
- return snd_ctl_new1(&template, data);
+ if (!long_name)
+ long_name = template.name;
+
+ if (prefix) {
+ name_len = strlen(long_name) + strlen(prefix) + 2;
+ name = kmalloc(name_len, GFP_ATOMIC);
+ if (!name)
+ return NULL;
+
+ snprintf(name, name_len, "%s %s", prefix, long_name);
+
+ template.name = name;
+ } else {
+ template.name = long_name;
+ }
+
+ kcontrol = snd_ctl_new1(&template, data);
+
+ kfree(name);
+
+ return kcontrol;
}
EXPORT_SYMBOL_GPL(snd_soc_cnew);
@@ -2378,22 +2401,16 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
const struct snd_kcontrol_new *controls, int num_controls)
{
struct snd_card *card = codec->card->snd_card;
- char prefixed_name[44], *name;
int err, i;
for (i = 0; i < num_controls; i++) {
const struct snd_kcontrol_new *control = &controls[i];
- if (codec->name_prefix) {
- snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
- codec->name_prefix, control->name);
- name = prefixed_name;
- } else {
- name = control->name;
- }
- err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
+ err = snd_ctl_add(card, snd_soc_cnew(control, codec,
+ control->name,
+ codec->name_prefix));
if (err < 0) {
dev_err(codec->dev, "%s: Failed to add %s: %d\n",
- codec->name, name, err);
+ codec->name, control->name, err);
return err;
}
}
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 570db88..a6fb85d 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,
size_t name_len;
struct snd_soc_dapm_path *path;
struct snd_card *card = dapm->card->snd_card;
+ const char *prefix;
+
+ if (dapm->codec)
+ prefix = dapm->codec->name_prefix;
+ else
+ prefix = NULL;
/* add kcontrol */
for (i = 0; i < w->num_kcontrols; i++) {
@@ -409,7 +415,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
path->long_name[name_len - 1] = '\0';
path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
- path->long_name);
+ path->long_name, prefix);
ret = snd_ctl_add(card, path->kcontrol);
if (ret < 0) {
dev_err(dapm->dev,
@@ -431,6 +437,7 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
struct snd_soc_dapm_path *path = NULL;
struct snd_kcontrol *kcontrol;
struct snd_card *card = dapm->card->snd_card;
+ const char *prefix;
int ret = 0;
if (!w->num_kcontrols) {
@@ -438,7 +445,12 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
return -EINVAL;
}
- kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
+ if (dapm->codec)
+ prefix = dapm->codec->name_prefix;
+ else
+ prefix = NULL;
+
+ kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name, prefix);
ret = snd_ctl_add(card, kcontrol);
if (ret < 0)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
2011-03-08 17:25 [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew() Mark Brown
@ 2011-03-08 18:01 ` Liam Girdwood
2011-03-09 8:19 ` Jarkko Nikula
0 siblings, 1 reply; 5+ messages in thread
From: Liam Girdwood @ 2011-03-08 18:01 UTC (permalink / raw)
To: Mark Brown; +Cc: alsa-devel, patches, Peter Ujfalusi
On Tue, 2011-03-08 at 17:25 +0000, Mark Brown wrote:
> 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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
2011-03-08 18:01 ` Liam Girdwood
@ 2011-03-09 8:19 ` Jarkko Nikula
2011-03-09 11:03 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Nikula @ 2011-03-09 8:19 UTC (permalink / raw)
To: Liam Girdwood; +Cc: alsa-devel, Mark Brown, Ujfalusi, patches, Peter
On Tue, 08 Mar 2011 18:01:21 +0000
Liam Girdwood <lrg@slimlogic.co.uk> wrote:
> On Tue, 2011-03-08 at 17:25 +0000, Mark Brown wrote:
> > 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>
>
Unfortunately this leads to double prefixing to mixer and mux controls
on Nokia RX-51/N900 in today's head. Reason there is that the
snd_soc_dapm_new_control has already added the prefix to widget name
and the dapm_new_mixer/mux takes this prefixed w->name and prefixes it
again.
codec driver or soc_probe_codec
-> snd_soc_dapm_new_controls
-> snd_soc_dapm_new_control: prefix added to w->name
soc_post_component_init
-> snd_soc_dapm_new_widgets
-> dapm_new_mixer/mux: prefix added again to w->name
--
Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
2011-03-09 8:19 ` Jarkko Nikula
@ 2011-03-09 11:03 ` Mark Brown
2011-03-09 11:35 ` Jarkko Nikula
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2011-03-09 11:03 UTC (permalink / raw)
To: Jarkko Nikula; +Cc: alsa-devel, patches, Peter Ujfalusi, Liam Girdwood
On Wed, Mar 09, 2011 at 10:19:51AM +0200, Jarkko Nikula wrote:
> Unfortunately this leads to double prefixing to mixer and mux controls
> on Nokia RX-51/N900 in today's head. Reason there is that the
> snd_soc_dapm_new_control has already added the prefix to widget name
> and the dapm_new_mixer/mux takes this prefixed w->name and prefixes it
> again.
The system I'm using isn't affected as there's no unnamed mixers in it.
I rather suspect this means that the old code is broken for named
mixers. Working on a fix just now.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew()
2011-03-09 11:03 ` Mark Brown
@ 2011-03-09 11:35 ` Jarkko Nikula
0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Nikula @ 2011-03-09 11:35 UTC (permalink / raw)
To: Mark Brown; +Cc: alsa-devel, patches, Peter Ujfalusi, Liam Girdwood
On Wed, 9 Mar 2011 11:03:14 +0000
Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:
> On Wed, Mar 09, 2011 at 10:19:51AM +0200, Jarkko Nikula wrote:
>
> > Unfortunately this leads to double prefixing to mixer and mux controls
> > on Nokia RX-51/N900 in today's head. Reason there is that the
> > snd_soc_dapm_new_control has already added the prefix to widget name
> > and the dapm_new_mixer/mux takes this prefixed w->name and prefixes it
> > again.
>
> The system I'm using isn't affected as there's no unnamed mixers in it.
> I rather suspect this means that the old code is broken for named
> mixers. Working on a fix just now.
Yeah, just realized the prefixing indeed was broken originally for named
mixers in sound/soc/soc-dapm.c: dapm_new_mixer as only w->name carried
the prefix and which is not included for snd_soc_dapm_mixer_named_ctl
case. My bad...
switch (w->id) {
default:
snprintf(path->long_name, name_len, "%s %s",
w->name, w->kcontrols[i].name);
break;
case snd_soc_dapm_mixer_named_ctl:
snprintf(path->long_name, name_len, "%s",
w->kcontrols[i].name);
break;
}
--
Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-03-09 11:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-08 17:25 [PATCH] ASoC: Fix prefixing of DAPM controls by factoring prefix into snd_soc_cnew() Mark Brown
2011-03-08 18:01 ` Liam Girdwood
2011-03-09 8:19 ` Jarkko Nikula
2011-03-09 11:03 ` Mark Brown
2011-03-09 11:35 ` Jarkko Nikula
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).