Merge tag 'regmap-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[linux-block.git] / sound / soc / pxa / e740_wm9705.c
1 /*
2  * e740-wm9705.c  --  SoC audio for e740
3  *
4  * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
5  *
6  *  This program is free software; you can redistribute  it and/or modify it
7  *  under  the terms of  the GNU General  Public License as published by the
8  *  Free Software Foundation; version 2 ONLY.
9  *
10  */
11
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/gpio.h>
15
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
19
20 #include <mach/audio.h>
21 #include <mach/eseries-gpio.h>
22
23 #include <asm/mach-types.h>
24
25 #include "pxa2xx-ac97.h"
26
27
28 #define E740_AUDIO_OUT 1
29 #define E740_AUDIO_IN  2
30
31 static int e740_audio_power;
32
33 static void e740_sync_audio_power(int status)
34 {
35         gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
36         gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
37         gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
38 }
39
40 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
41                                 struct snd_kcontrol *kcontrol, int event)
42 {
43         if (event & SND_SOC_DAPM_PRE_PMU)
44                 e740_audio_power |= E740_AUDIO_IN;
45         else if (event & SND_SOC_DAPM_POST_PMD)
46                 e740_audio_power &= ~E740_AUDIO_IN;
47
48         e740_sync_audio_power(e740_audio_power);
49
50         return 0;
51 }
52
53 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
54                                 struct snd_kcontrol *kcontrol, int event)
55 {
56         if (event & SND_SOC_DAPM_PRE_PMU)
57                 e740_audio_power |= E740_AUDIO_OUT;
58         else if (event & SND_SOC_DAPM_POST_PMD)
59                 e740_audio_power &= ~E740_AUDIO_OUT;
60
61         e740_sync_audio_power(e740_audio_power);
62
63         return 0;
64 }
65
66 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
67         SND_SOC_DAPM_HP("Headphone Jack", NULL),
68         SND_SOC_DAPM_SPK("Speaker", NULL),
69         SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
70         SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
71                         e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
72                         SND_SOC_DAPM_POST_PMD),
73         SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
74                         e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
75                         SND_SOC_DAPM_POST_PMD),
76 };
77
78 static const struct snd_soc_dapm_route audio_map[] = {
79         {"Output Amp", NULL, "LOUT"},
80         {"Output Amp", NULL, "ROUT"},
81         {"Output Amp", NULL, "MONOOUT"},
82
83         {"Speaker", NULL, "Output Amp"},
84         {"Headphone Jack", NULL, "Output Amp"},
85
86         {"MIC1", NULL, "Mic Amp"},
87         {"Mic Amp", NULL, "Mic (Internal)"},
88 };
89
90 static struct snd_soc_dai_link e740_dai[] = {
91         {
92                 .name = "AC97",
93                 .stream_name = "AC97 HiFi",
94                 .cpu_dai_name = "pxa2xx-ac97",
95                 .codec_dai_name = "wm9705-hifi",
96                 .platform_name = "pxa-pcm-audio",
97                 .codec_name = "wm9705-codec",
98         },
99         {
100                 .name = "AC97 Aux",
101                 .stream_name = "AC97 Aux",
102                 .cpu_dai_name = "pxa2xx-ac97-aux",
103                 .codec_dai_name = "wm9705-aux",
104                 .platform_name = "pxa-pcm-audio",
105                 .codec_name = "wm9705-codec",
106         },
107 };
108
109 static struct snd_soc_card e740 = {
110         .name = "Toshiba e740",
111         .owner = THIS_MODULE,
112         .dai_link = e740_dai,
113         .num_links = ARRAY_SIZE(e740_dai),
114
115         .dapm_widgets = e740_dapm_widgets,
116         .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
117         .dapm_routes = audio_map,
118         .num_dapm_routes = ARRAY_SIZE(audio_map),
119         .fully_routed = true,
120 };
121
122 static struct gpio e740_audio_gpios[] = {
123         { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" },
124         { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" },
125         { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" },
126 };
127
128 static int e740_probe(struct platform_device *pdev)
129 {
130         struct snd_soc_card *card = &e740;
131         int ret;
132
133         ret = gpio_request_array(e740_audio_gpios,
134                                  ARRAY_SIZE(e740_audio_gpios));
135         if (ret)
136                 return ret;
137
138         card->dev = &pdev->dev;
139
140         ret = devm_snd_soc_register_card(&pdev->dev, card);
141         if (ret) {
142                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
143                         ret);
144                 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
145         }
146         return ret;
147 }
148
149 static int e740_remove(struct platform_device *pdev)
150 {
151         gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
152         return 0;
153 }
154
155 static struct platform_driver e740_driver = {
156         .driver         = {
157                 .name   = "e740-audio",
158                 .pm     = &snd_soc_pm_ops,
159         },
160         .probe          = e740_probe,
161         .remove         = e740_remove,
162 };
163
164 module_platform_driver(e740_driver);
165
166 /* Module information */
167 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
168 MODULE_DESCRIPTION("ALSA SoC driver for e740");
169 MODULE_LICENSE("GPL v2");
170 MODULE_ALIAS("platform:e740-audio");