[alsa-devel] [PATCH 2/2 v4] ASoC: soc-core: Add helper function to handle dynamic replace of controls
Dimitris Papastamos
dp at opensource.wolfsonmicro.com
Wed Mar 16 13:16:40 CET 2011
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 at 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
--
1.7.4.1
More information about the Alsa-devel
mailing list