This function can be used to replace or add controls at runtime. It will always try to add a given control if it does not already exist.
Signed-off-by: Dimitris Papastamos dp@opensource.wolfsonmicro.com --- include/sound/soc.h | 2 ++ sound/soc/soc-core.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index bfa4836..a5bb531 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -344,6 +344,8 @@ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 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_replace_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, struct snd_ctl_elem_info *uinfo); int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 17efacd..e2aa0b4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2420,6 +2420,39 @@ int snd_soc_add_controls(struct snd_soc_codec *codec, EXPORT_SYMBOL_GPL(snd_soc_add_controls);
/** + * snd_soc_replace_controls - replace an array of controls + * Convienience function to replace a list of controls. + * + * @codec: codec to replace controls of + * @controls: array of controls to replace + * @num_controls: number of elements in the array + * + * Return 0 for success, else error. + */ +int snd_soc_replace_controls(struct snd_soc_codec *codec, + const struct snd_kcontrol_new *controls, int num_controls) +{ + struct snd_card *card = codec->card->snd_card; + int err, i; + + for (i = 0; i < num_controls; i++) { + const struct snd_kcontrol_new *control = &controls[i]; + /* always add on replace if not already added */ + err = snd_ctl_replace(card, snd_soc_cnew(control, codec, + control->name, + codec->name_prefix), true); + if (err < 0) { + dev_err(codec->dev, "%s: Failed to replace %s: %d\n", + codec->name, control->name, err); + return err; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_replace_controls); + +/** * snd_soc_info_enum_double - enumerated double mixer info callback * @kcontrol: mixer control * @uinfo: control element information