]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/soc/pxa/mioa701_wm9713.c
ASoC: Decouple DAPM from CODECs
[mv-sheeva.git] / sound / soc / pxa / mioa701_wm9713.c
1 /*
2  * Handles the Mitac mioa701 SoC system
3  *
4  * Copyright (C) 2008 Robert Jarzmik
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation in version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * This is a little schema of the sound interconnections :
20  *
21  *    Sagem X200                 Wolfson WM9713
22  *    +--------+             +-------------------+      Rear Speaker
23  *    |        |             |                   |           /-+
24  *    |        +--->----->---+MONOIN         SPKL+--->----+-+  |
25  *    |  GSM   |             |                   |        | |  |
26  *    |        +--->----->---+PCBEEP         SPKR+--->----+-+  |
27  *    |  CHIP  |             |                   |           \-+
28  *    |        +---<-----<---+MONO               |
29  *    |        |             |                   |      Front Speaker
30  *    +--------+             |                   |           /-+
31  *                           |                HPL+--->----+-+  |
32  *                           |                   |        | |  |
33  *                           |               OUT3+--->----+-+  |
34  *                           |                   |           \-+
35  *                           |                   |
36  *                           |                   |     Front Micro
37  *                           |                   |         +
38  *                           |               MIC1+-----<--+o+
39  *                           |                   |         +
40  *                           +-------------------+        ---
41  */
42
43 #include <linux/module.h>
44 #include <linux/moduleparam.h>
45 #include <linux/platform_device.h>
46
47 #include <asm/mach-types.h>
48 #include <mach/audio.h>
49
50 #include <sound/core.h>
51 #include <sound/pcm.h>
52 #include <sound/soc.h>
53 #include <sound/soc-dapm.h>
54 #include <sound/initval.h>
55 #include <sound/ac97_codec.h>
56
57 #include "pxa2xx-ac97.h"
58 #include "../codecs/wm9713.h"
59
60 #define ARRAY_AND_SIZE(x)       (x), ARRAY_SIZE(x)
61
62 #define AC97_GPIO_PULL          0x58
63
64 /* Use GPIO8 for rear speaker amplifier */
65 static int rear_amp_power(struct snd_soc_codec *codec, int power)
66 {
67         unsigned short reg;
68
69         if (power) {
70                 reg = snd_soc_read(codec, AC97_GPIO_CFG);
71                 snd_soc_write(codec, AC97_GPIO_CFG, reg | 0x0100);
72                 reg = snd_soc_read(codec, AC97_GPIO_PULL);
73                 snd_soc_write(codec, AC97_GPIO_PULL, reg | (1<<15));
74         } else {
75                 reg = snd_soc_read(codec, AC97_GPIO_CFG);
76                 snd_soc_write(codec, AC97_GPIO_CFG, reg & ~0x0100);
77                 reg = snd_soc_read(codec, AC97_GPIO_PULL);
78                 snd_soc_write(codec, AC97_GPIO_PULL, reg & ~(1<<15));
79         }
80
81         return 0;
82 }
83
84 static int rear_amp_event(struct snd_soc_dapm_widget *widget,
85                           struct snd_kcontrol *kctl, int event)
86 {
87         struct snd_soc_codec *codec = widget->codec;
88
89         return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event));
90 }
91
92 /* mioa701 machine dapm widgets */
93 static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
94         SND_SOC_DAPM_SPK("Front Speaker", NULL),
95         SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
96         SND_SOC_DAPM_MIC("Headset", NULL),
97         SND_SOC_DAPM_LINE("GSM Line Out", NULL),
98         SND_SOC_DAPM_LINE("GSM Line In", NULL),
99         SND_SOC_DAPM_MIC("Headset Mic", NULL),
100         SND_SOC_DAPM_MIC("Front Mic", NULL),
101 };
102
103 static const struct snd_soc_dapm_route audio_map[] = {
104         /* Call Mic */
105         {"Mic Bias", NULL, "Front Mic"},
106         {"MIC1", NULL, "Mic Bias"},
107
108         /* Headset Mic */
109         {"LINEL", NULL, "Headset Mic"},
110         {"LINER", NULL, "Headset Mic"},
111
112         /* GSM Module */
113         {"MONOIN", NULL, "GSM Line Out"},
114         {"PCBEEP", NULL, "GSM Line Out"},
115         {"GSM Line In", NULL, "MONO"},
116
117         /* headphone connected to HPL, HPR */
118         {"Headset", NULL, "HPL"},
119         {"Headset", NULL, "HPR"},
120
121         /* front speaker connected to HPL, OUT3 */
122         {"Front Speaker", NULL, "HPL"},
123         {"Front Speaker", NULL, "OUT3"},
124
125         /* rear speaker connected to SPKL, SPKR */
126         {"Rear Speaker", NULL, "SPKL"},
127         {"Rear Speaker", NULL, "SPKR"},
128 };
129
130 static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
131 {
132         struct snd_soc_codec *codec = rtd->codec;
133         struct snd_soc_dapm_context *dapm = &codec->dapm;
134         unsigned short reg;
135
136         /* Add mioa701 specific widgets */
137         snd_soc_dapm_new_controls(dapm, ARRAY_AND_SIZE(mioa701_dapm_widgets));
138
139         /* Set up mioa701 specific audio path audio_mapnects */
140         snd_soc_dapm_add_routes(dapm, ARRAY_AND_SIZE(audio_map));
141
142         /* Prepare GPIO8 for rear speaker amplifier */
143         reg = codec->driver->read(codec, AC97_GPIO_CFG);
144         codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100);
145
146         /* Prepare MIC input */
147         reg = codec->driver->read(codec, AC97_3D_CONTROL);
148         codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000);
149
150         snd_soc_dapm_enable_pin(dapm, "Front Speaker");
151         snd_soc_dapm_enable_pin(dapm, "Rear Speaker");
152         snd_soc_dapm_enable_pin(dapm, "Front Mic");
153         snd_soc_dapm_enable_pin(dapm, "GSM Line In");
154         snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
155         snd_soc_dapm_sync(dapm);
156
157         return 0;
158 }
159
160 static struct snd_soc_ops mioa701_ops;
161
162 static struct snd_soc_dai_link mioa701_dai[] = {
163         {
164                 .name = "AC97",
165                 .stream_name = "AC97 HiFi",
166                 .cpu_dai_name = "pxa-ac97.0",
167                 .codec_dai_name = "wm9713-hifi",
168                 .codec_name = "wm9713-codec",
169                 .init = mioa701_wm9713_init,
170                 .platform_name = "pxa-pcm-audio",
171                 .ops = &mioa701_ops,
172         },
173         {
174                 .name = "AC97 Aux",
175                 .stream_name = "AC97 Aux",
176                 .cpu_dai_name = "pxa-ac97.1",
177                 .codec_dai_name ="wm9713-aux",
178                 .codec_name = "wm9713-codec",
179                 .platform_name = "pxa-pcm-audio",
180                 .ops = &mioa701_ops,
181         },
182 };
183
184 static struct snd_soc_card mioa701 = {
185         .name = "MioA701",
186         .dai_link = mioa701_dai,
187         .num_links = ARRAY_SIZE(mioa701_dai),
188 };
189
190 static struct platform_device *mioa701_snd_device;
191
192 static int mioa701_wm9713_probe(struct platform_device *pdev)
193 {
194         int ret;
195
196         if (!machine_is_mioa701())
197                 return -ENODEV;
198
199         dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will"
200                  "lead to overheating and possible destruction of your device."
201                  "Do not use without a good knowledge of mio's board design!\n");
202
203         mioa701_snd_device = platform_device_alloc("soc-audio", -1);
204         if (!mioa701_snd_device)
205                 return -ENOMEM;
206
207         platform_set_drvdata(mioa701_snd_device, &mioa701);
208
209         ret = platform_device_add(mioa701_snd_device);
210         if (!ret)
211                 return 0;
212
213         platform_device_put(mioa701_snd_device);
214         return ret;
215 }
216
217 static int __devexit mioa701_wm9713_remove(struct platform_device *pdev)
218 {
219         platform_device_unregister(mioa701_snd_device);
220         return 0;
221 }
222
223 static struct platform_driver mioa701_wm9713_driver = {
224         .probe          = mioa701_wm9713_probe,
225         .remove         = __devexit_p(mioa701_wm9713_remove),
226         .driver         = {
227                 .name           = "mioa701-wm9713",
228                 .owner          = THIS_MODULE,
229         },
230 };
231
232 static int __init mioa701_asoc_init(void)
233 {
234         return platform_driver_register(&mioa701_wm9713_driver);
235 }
236
237 static void __exit mioa701_asoc_exit(void)
238 {
239         platform_driver_unregister(&mioa701_wm9713_driver);
240 }
241
242 module_init(mioa701_asoc_init);
243 module_exit(mioa701_asoc_exit);
244
245 /* Module information */
246 MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
247 MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
248 MODULE_LICENSE("GPL");