From: Xiubo Li <Li.Xiubo@freescale.com>
To: <broonie@kernel.org>, <lgirdwood@gmail.com>,
<kuninori.morimoto.gx@renesas.com>
Cc: <rob@landley.net>, <perex@perex.cz>, <moinejf@free.fr>,
<linux-kernel@vger.kernel.org>, <alsa-devel@alsa-project.org>,
Xiubo Li <Li.Xiubo@freescale.com>
Subject: [PATCH v2 5/7] ASoC: add snd_soc_of_parse_audio_simple_widgets for DT
Date: Fri, 24 Jan 2014 15:43:04 +0800 [thread overview]
Message-ID: <1390549386-4702-6-git-send-email-Li.Xiubo@freescale.com> (raw)
In-Reply-To: <1390549386-4702-1-git-send-email-Li.Xiubo@freescale.com>
This patch adds snd_soc_of_parse_audio_simple_widgets() and supports
below style of widgets name on DT:
"template-wname", "user supplied wname"
The "template-wname" includes: "Mic", "Line", "Hp", "Spk"...
For instance:
simple-audio-widgets =
"Mic", "Microphone Jack",
"Line", "Line In Jack",
"Line", "Line Out Jack",
"Hp", "Headphone Jack",
"Spk", "Speaker External";
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
include/sound/soc.h | 2 ++
sound/soc/soc-core.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 9a00147..465dc6e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1173,6 +1173,8 @@ void snd_soc_util_exit(void);
int snd_soc_of_parse_card_name(struct snd_soc_card *card,
const char *propname);
+int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
+ const char *propname);
int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
const char *propname);
unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe1df50..73fdf18 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -4417,6 +4417,93 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
+static const struct snd_soc_dapm_widget simple_widgets[] = {
+ SND_SOC_DAPM_MIC("Mic", NULL),
+ SND_SOC_DAPM_LINE("Line", NULL),
+ SND_SOC_DAPM_HP("Hp", NULL),
+ SND_SOC_DAPM_SPK("Spk", NULL),
+};
+
+int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
+ const char *propname)
+{
+ struct device_node *np = card->dev->of_node;
+ struct snd_soc_dapm_widget *widgets;
+ const char *template, *wname;
+ int i, j, num_widgets, ret;
+
+ num_widgets = of_property_count_strings(np, propname);
+ if (num_widgets < 0) {
+ dev_err(card->dev,
+ "ASoC: Property '%s' does not exist\n", propname);
+ return -EINVAL;
+ }
+ if (num_widgets & 1) {
+ dev_err(card->dev,
+ "ASoC: Property '%s' length is not even\n", propname);
+ return -EINVAL;
+ }
+
+ num_widgets /= 2;
+ if (!num_widgets) {
+ dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
+ propname);
+ return -EINVAL;
+ }
+
+ widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
+ GFP_KERNEL);
+ if (!widgets) {
+ dev_err(card->dev,
+ "ASoC: Could not allocate memory for widgets\n");
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < num_widgets; i++) {
+ ret = of_property_read_string_index(np, propname,
+ 2 * i, &template);
+ if (ret) {
+ dev_err(card->dev,
+ "ASoC: Property '%s' index %d read error:%d\n",
+ propname, 2 * i, ret);
+ return -EINVAL;
+ }
+
+ for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
+ if (!strncmp(template, simple_widgets[j].name,
+ strlen(simple_widgets[j].name))) {
+ widgets[i] = simple_widgets[j];
+ break;
+ }
+ }
+
+ if (j >= ARRAY_SIZE(simple_widgets)) {
+ dev_err(card->dev,
+ "ASoC: DAPM widget '%s' is not supported\n",
+ template);
+ return -EINVAL;
+ }
+
+ ret = of_property_read_string_index(np, propname,
+ (2 * i) + 1,
+ &wname);
+ if (ret) {
+ dev_err(card->dev,
+ "ASoC: Property '%s' index %d read error:%d\n",
+ propname, (2 * i) + 1, ret);
+ return -EINVAL;
+ }
+
+ widgets[i].name = wname;
+ }
+
+ card->dapm_widgets = widgets;
+ card->num_dapm_widgets = num_widgets;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
+
int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
const char *propname)
{
--
1.8.4
next prev parent reply other threads:[~2014-01-24 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-24 7:42 [PATCH v2 0/7] simple card Xiubo Li
2014-01-24 7:43 ` [PATCH v2 1/7] ASoC: simple-card: fix __asoc_simple_card_dai_init Xiubo Li
2014-01-27 19:50 ` Mark Brown
2014-01-24 7:43 ` [PATCH v2 2/7] ASoC: simple-card: simplify the daifmt code Xiubo Li
2014-01-27 19:50 ` Mark Brown
2014-01-24 7:43 ` [PATCH v2 3/7] ASoC: simple-card: Add snd_card's name parsing from DT node support Xiubo Li
2014-01-27 19:50 ` Mark Brown
2014-01-24 7:43 ` [PATCH v2 4/7] ASoC: simple-card: add tdm slot supports Xiubo Li
2014-01-27 19:53 ` Mark Brown
2014-01-24 7:43 ` Xiubo Li [this message]
2014-01-27 19:55 ` [PATCH v2 5/7] ASoC: add snd_soc_of_parse_audio_simple_widgets for DT Mark Brown
2014-01-29 11:52 ` Li.Xiubo
2014-01-24 7:43 ` [PATCH v2 6/7] ASoC: simple-card: add off-codec widgets supports Xiubo Li
2014-01-27 19:56 ` Mark Brown
2014-01-24 7:43 ` [PATCH v2 7/7] ASoC: binding: for new properties documenting and usage Xiubo Li
2014-01-27 19:58 ` Mark Brown
2014-02-08 8:20 ` Li.Xiubo
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=1390549386-4702-6-git-send-email-Li.Xiubo@freescale.com \
--to=li.xiubo@freescale.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=moinejf@free.fr \
--cc=perex@perex.cz \
--cc=rob@landley.net \
/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
all inboxes | Powered by JetHome®