diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2017-06-29 09:26:38 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-06-30 07:37:08 -0400 |
commit | f986907c9225cf48e9a55233b086039152bb5b99 (patch) | |
tree | 318aaeeef390f794398034af2b7c4cecb8980b04 | |
parent | a0c683d734e0b3589892c17d0e1187f20d2c3a54 (diff) |
ASoC: audio-graph-card: add widgets and routing for external amplifier support
It's very common that audio card has a machine level amplifier which is
controlled by GPIO. The patch adds DAPM widgets and routing support
into audio-graph-card driver, and creates an output driver widget with
event to control the amplifier via GPIO.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/generic/audio-graph-card.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index ee752f62d89d..105ec3a6e30d 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/clk.h> | 13 | #include <linux/clk.h> |
14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
15 | #include <linux/gpio.h> | 15 | #include <linux/gpio.h> |
16 | #include <linux/gpio/consumer.h> | ||
16 | #include <linux/module.h> | 17 | #include <linux/module.h> |
17 | #include <linux/of.h> | 18 | #include <linux/of.h> |
18 | #include <linux/of_device.h> | 19 | #include <linux/of_device.h> |
@@ -30,6 +31,34 @@ struct graph_card_data { | |||
30 | struct asoc_simple_dai codec_dai; | 31 | struct asoc_simple_dai codec_dai; |
31 | } *dai_props; | 32 | } *dai_props; |
32 | struct snd_soc_dai_link *dai_link; | 33 | struct snd_soc_dai_link *dai_link; |
34 | struct gpio_desc *pa_gpio; | ||
35 | }; | ||
36 | |||
37 | static int asoc_graph_card_outdrv_event(struct snd_soc_dapm_widget *w, | ||
38 | struct snd_kcontrol *kcontrol, | ||
39 | int event) | ||
40 | { | ||
41 | struct snd_soc_dapm_context *dapm = w->dapm; | ||
42 | struct graph_card_data *priv = snd_soc_card_get_drvdata(dapm->card); | ||
43 | |||
44 | switch (event) { | ||
45 | case SND_SOC_DAPM_POST_PMU: | ||
46 | gpiod_set_value_cansleep(priv->pa_gpio, 1); | ||
47 | break; | ||
48 | case SND_SOC_DAPM_PRE_PMD: | ||
49 | gpiod_set_value_cansleep(priv->pa_gpio, 0); | ||
50 | break; | ||
51 | default: | ||
52 | return -EINVAL; | ||
53 | } | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static const struct snd_soc_dapm_widget asoc_graph_card_dapm_widgets[] = { | ||
59 | SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM, | ||
60 | 0, 0, NULL, 0, asoc_graph_card_outdrv_event, | ||
61 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
33 | }; | 62 | }; |
34 | 63 | ||
35 | #define graph_priv_to_card(priv) (&(priv)->snd_card) | 64 | #define graph_priv_to_card(priv) (&(priv)->snd_card) |
@@ -180,8 +209,16 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv) | |||
180 | int rc, idx = 0; | 209 | int rc, idx = 0; |
181 | int ret; | 210 | int ret; |
182 | 211 | ||
212 | ret = asoc_simple_card_of_parse_widgets(card, NULL); | ||
213 | if (ret < 0) | ||
214 | return ret; | ||
215 | |||
216 | ret = asoc_simple_card_of_parse_routing(card, NULL, 1); | ||
217 | if (ret < 0) | ||
218 | return ret; | ||
219 | |||
183 | /* | 220 | /* |
184 | * we need to consider "widgets", "routing", "mclk-fs" around here | 221 | * we need to consider "mclk-fs" around here |
185 | * see simple-card | 222 | * see simple-card |
186 | */ | 223 | */ |
187 | 224 | ||
@@ -233,6 +270,13 @@ static int asoc_graph_card_probe(struct platform_device *pdev) | |||
233 | if (!dai_props || !dai_link) | 270 | if (!dai_props || !dai_link) |
234 | return -ENOMEM; | 271 | return -ENOMEM; |
235 | 272 | ||
273 | priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); | ||
274 | if (IS_ERR(priv->pa_gpio)) { | ||
275 | ret = PTR_ERR(priv->pa_gpio); | ||
276 | dev_err(dev, "failed to get amplifier gpio: %d\n", ret); | ||
277 | return ret; | ||
278 | } | ||
279 | |||
236 | priv->dai_props = dai_props; | 280 | priv->dai_props = dai_props; |
237 | priv->dai_link = dai_link; | 281 | priv->dai_link = dai_link; |
238 | 282 | ||
@@ -242,6 +286,8 @@ static int asoc_graph_card_probe(struct platform_device *pdev) | |||
242 | card->dev = dev; | 286 | card->dev = dev; |
243 | card->dai_link = dai_link; | 287 | card->dai_link = dai_link; |
244 | card->num_links = num; | 288 | card->num_links = num; |
289 | card->dapm_widgets = asoc_graph_card_dapm_widgets; | ||
290 | card->num_dapm_widgets = ARRAY_SIZE(asoc_graph_card_dapm_widgets); | ||
245 | 291 | ||
246 | ret = asoc_graph_card_parse_of(priv); | 292 | ret = asoc_graph_card_parse_of(priv); |
247 | if (ret < 0) { | 293 | if (ret < 0) { |