Commit efb7ac3f authored by Mark Brown's avatar Mark Brown

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: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@ti.com>
parent c4ef8786
...@@ -340,7 +340,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec); ...@@ -340,7 +340,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
*Controls *Controls
*/ */
struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 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, int snd_soc_add_controls(struct snd_soc_codec *codec,
const struct snd_kcontrol_new *controls, int num_controls); const struct snd_kcontrol_new *controls, int num_controls);
int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
......
...@@ -2344,22 +2344,45 @@ EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); ...@@ -2344,22 +2344,45 @@ EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
* @_template: control template * @_template: control template
* @data: control private data * @data: control private data
* @long_name: control long name * @long_name: control long name
* @prefix: control name prefix
* *
* Create a new mixer control from a template control. * Create a new mixer control from a template control.
* *
* Returns 0 for success, else error. * Returns 0 for success, else error.
*/ */
struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 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_new template;
struct snd_kcontrol *kcontrol;
char *name = NULL;
int name_len;
memcpy(&template, _template, sizeof(template)); memcpy(&template, _template, sizeof(template));
if (long_name)
template.name = long_name;
template.index = 0; 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); EXPORT_SYMBOL_GPL(snd_soc_cnew);
...@@ -2378,22 +2401,16 @@ int snd_soc_add_controls(struct snd_soc_codec *codec, ...@@ -2378,22 +2401,16 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
const struct snd_kcontrol_new *controls, int num_controls) const struct snd_kcontrol_new *controls, int num_controls)
{ {
struct snd_card *card = codec->card->snd_card; struct snd_card *card = codec->card->snd_card;
char prefixed_name[44], *name;
int err, i; int err, i;
for (i = 0; i < num_controls; i++) { for (i = 0; i < num_controls; i++) {
const struct snd_kcontrol_new *control = &controls[i]; const struct snd_kcontrol_new *control = &controls[i];
if (codec->name_prefix) { err = snd_ctl_add(card, snd_soc_cnew(control, codec,
snprintf(prefixed_name, sizeof(prefixed_name), "%s %s", control->name,
codec->name_prefix, control->name); codec->name_prefix));
name = prefixed_name;
} else {
name = control->name;
}
err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
if (err < 0) { if (err < 0) {
dev_err(codec->dev, "%s: Failed to add %s: %d\n", dev_err(codec->dev, "%s: Failed to add %s: %d\n",
codec->name, name, err); codec->name, control->name, err);
return err; return err;
} }
} }
......
...@@ -369,6 +369,12 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm, ...@@ -369,6 +369,12 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
size_t name_len; size_t name_len;
struct snd_soc_dapm_path *path; struct snd_soc_dapm_path *path;
struct snd_card *card = dapm->card->snd_card; struct snd_card *card = dapm->card->snd_card;
const char *prefix;
if (dapm->codec)
prefix = dapm->codec->name_prefix;
else
prefix = NULL;
/* add kcontrol */ /* add kcontrol */
for (i = 0; i < w->num_kcontrols; i++) { for (i = 0; i < w->num_kcontrols; i++) {
...@@ -409,7 +415,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm, ...@@ -409,7 +415,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
path->long_name[name_len - 1] = '\0'; path->long_name[name_len - 1] = '\0';
path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
path->long_name); path->long_name, prefix);
ret = snd_ctl_add(card, path->kcontrol); ret = snd_ctl_add(card, path->kcontrol);
if (ret < 0) { if (ret < 0) {
dev_err(dapm->dev, dev_err(dapm->dev,
...@@ -431,6 +437,7 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm, ...@@ -431,6 +437,7 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
struct snd_soc_dapm_path *path = NULL; struct snd_soc_dapm_path *path = NULL;
struct snd_kcontrol *kcontrol; struct snd_kcontrol *kcontrol;
struct snd_card *card = dapm->card->snd_card; struct snd_card *card = dapm->card->snd_card;
const char *prefix;
int ret = 0; int ret = 0;
if (!w->num_kcontrols) { if (!w->num_kcontrols) {
...@@ -438,7 +445,12 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm, ...@@ -438,7 +445,12 @@ static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
return -EINVAL; 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); ret = snd_ctl_add(card, kcontrol);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment