aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorXiubo Li <Li.Xiubo@freescale.com>2014-02-08 02:59:52 -0500
committerMark Brown <broonie@linaro.org>2014-02-10 08:29:55 -0500
commit9a6d48605e632e84db2895cf752c65b3c908cd09 (patch)
tree0e9ae55984b97166018998b7dabea59b12e256ae /sound
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
ASoC: add snd_soc_of_parse_audio_simple_widgets for DT
This patch adds snd_soc_of_parse_audio_simple_widgets() and supports below style of widgets name on DT: "template-wname", "user supplied wname" For instance: simple-audio-widgets = "Microphone", "Microphone Jack", "Line", "Line In Jack", "Line", "Line Out Jack", "Headphone", "Headphone Jack", "Speaker", "Speaker External"; The "template-wname" currently includes: "Microphone", "Line", "Headphone" and "Speaker". Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/soc-core.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe1df50805a3..0540cb08e0ea 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,
4417} 4417}
4418EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 4418EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4419 4419
4420static const struct snd_soc_dapm_widget simple_widgets[] = {
4421 SND_SOC_DAPM_MIC("Microphone", NULL),
4422 SND_SOC_DAPM_LINE("Line", NULL),
4423 SND_SOC_DAPM_HP("Headphone", NULL),
4424 SND_SOC_DAPM_SPK("Speaker", NULL),
4425};
4426
4427int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
4428 const char *propname)
4429{
4430 struct device_node *np = card->dev->of_node;
4431 struct snd_soc_dapm_widget *widgets;
4432 const char *template, *wname;
4433 int i, j, num_widgets, ret;
4434
4435 num_widgets = of_property_count_strings(np, propname);
4436 if (num_widgets < 0) {
4437 dev_err(card->dev,
4438 "ASoC: Property '%s' does not exist\n", propname);
4439 return -EINVAL;
4440 }
4441 if (num_widgets & 1) {
4442 dev_err(card->dev,
4443 "ASoC: Property '%s' length is not even\n", propname);
4444 return -EINVAL;
4445 }
4446
4447 num_widgets /= 2;
4448 if (!num_widgets) {
4449 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
4450 propname);
4451 return -EINVAL;
4452 }
4453
4454 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
4455 GFP_KERNEL);
4456 if (!widgets) {
4457 dev_err(card->dev,
4458 "ASoC: Could not allocate memory for widgets\n");
4459 return -ENOMEM;
4460 }
4461
4462 for (i = 0; i < num_widgets; i++) {
4463 ret = of_property_read_string_index(np, propname,
4464 2 * i, &template);
4465 if (ret) {
4466 dev_err(card->dev,
4467 "ASoC: Property '%s' index %d read error:%d\n",
4468 propname, 2 * i, ret);
4469 return -EINVAL;
4470 }
4471
4472 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
4473 if (!strncmp(template, simple_widgets[j].name,
4474 strlen(simple_widgets[j].name))) {
4475 widgets[i] = simple_widgets[j];
4476 break;
4477 }
4478 }
4479
4480 if (j >= ARRAY_SIZE(simple_widgets)) {
4481 dev_err(card->dev,
4482 "ASoC: DAPM widget '%s' is not supported\n",
4483 template);
4484 return -EINVAL;
4485 }
4486
4487 ret = of_property_read_string_index(np, propname,
4488 (2 * i) + 1,
4489 &wname);
4490 if (ret) {
4491 dev_err(card->dev,
4492 "ASoC: Property '%s' index %d read error:%d\n",
4493 propname, (2 * i) + 1, ret);
4494 return -EINVAL;
4495 }
4496
4497 widgets[i].name = wname;
4498 }
4499
4500 card->dapm_widgets = widgets;
4501 card->num_dapm_widgets = num_widgets;
4502
4503 return 0;
4504}
4505EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
4506
4420int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 4507int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4421 const char *propname) 4508 const char *propname)
4422{ 4509{