From: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>,
lrg@ti.com, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.de>,
Clemens Ladisch <clemens@ladisch.de>
Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
lrg@slimlogic.co.uk
Subject: [PATCH 2/2 v4] ASoC: soc-core: Add helper function to handle dynamic replace of controls
Date: Wed, 16 Mar 2011 12:16:40 +0000 [thread overview]
Message-ID: <1300277800-610-2-git-send-email-dp@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1300277800-610-1-git-send-email-dp@opensource.wolfsonmicro.com>
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
--
1.7.4.1
next prev parent reply other threads:[~2011-03-16 12:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-16 12:16 [PATCH 1/2 v4] ALSA: Add snd_ctl_replace() to dynamically replace a control Dimitris Papastamos
2011-03-16 12:16 ` Dimitris Papastamos [this message]
2011-03-17 14:26 ` Dimitris Papastamos
2011-03-17 15:07 ` Mark Brown
2011-03-17 15:28 ` Takashi Iwai
2011-03-22 15:17 ` Takashi Iwai
2011-03-22 15:35 ` Dimitris Papastamos
2011-03-22 15:49 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300277800-610-2-git-send-email-dp@opensource.wolfsonmicro.com \
--to=dp@opensource.wolfsonmicro.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=clemens@ladisch.de \
--cc=lrg@slimlogic.co.uk \
--cc=lrg@ti.com \
--cc=patches@opensource.wolfsonmicro.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).