Commit | Line | Data |
---|---|---|
8f0dc655 RJ |
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> | |
8f0dc655 RJ |
53 | #include <sound/initval.h> |
54 | #include <sound/ac97_codec.h> | |
55 | ||
8f0dc655 RJ |
56 | #include "pxa2xx-ac97.h" |
57 | #include "../codecs/wm9713.h" | |
58 | ||
8f0dc655 RJ |
59 | #define AC97_GPIO_PULL 0x58 |
60 | ||
61 | /* Use GPIO8 for rear speaker amplifier */ | |
62 | static int rear_amp_power(struct snd_soc_codec *codec, int power) | |
63 | { | |
64 | unsigned short reg; | |
65 | ||
66 | if (power) { | |
67 | reg = snd_soc_read(codec, AC97_GPIO_CFG); | |
68 | snd_soc_write(codec, AC97_GPIO_CFG, reg | 0x0100); | |
69 | reg = snd_soc_read(codec, AC97_GPIO_PULL); | |
70 | snd_soc_write(codec, AC97_GPIO_PULL, reg | (1<<15)); | |
71 | } else { | |
72 | reg = snd_soc_read(codec, AC97_GPIO_CFG); | |
73 | snd_soc_write(codec, AC97_GPIO_CFG, reg & ~0x0100); | |
74 | reg = snd_soc_read(codec, AC97_GPIO_PULL); | |
75 | snd_soc_write(codec, AC97_GPIO_PULL, reg & ~(1<<15)); | |
76 | } | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static int rear_amp_event(struct snd_soc_dapm_widget *widget, | |
82 | struct snd_kcontrol *kctl, int event) | |
83 | { | |
84 | struct snd_soc_codec *codec = widget->codec; | |
85 | ||
86 | return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event)); | |
87 | } | |
88 | ||
89 | /* mioa701 machine dapm widgets */ | |
90 | static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = { | |
91 | SND_SOC_DAPM_SPK("Front Speaker", NULL), | |
92 | SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event), | |
93 | SND_SOC_DAPM_MIC("Headset", NULL), | |
94 | SND_SOC_DAPM_LINE("GSM Line Out", NULL), | |
95 | SND_SOC_DAPM_LINE("GSM Line In", NULL), | |
96 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | |
97 | SND_SOC_DAPM_MIC("Front Mic", NULL), | |
98 | }; | |
99 | ||
100 | static const struct snd_soc_dapm_route audio_map[] = { | |
101 | /* Call Mic */ | |
102 | {"Mic Bias", NULL, "Front Mic"}, | |
103 | {"MIC1", NULL, "Mic Bias"}, | |
104 | ||
105 | /* Headset Mic */ | |
106 | {"LINEL", NULL, "Headset Mic"}, | |
107 | {"LINER", NULL, "Headset Mic"}, | |
108 | ||
109 | /* GSM Module */ | |
110 | {"MONOIN", NULL, "GSM Line Out"}, | |
111 | {"PCBEEP", NULL, "GSM Line Out"}, | |
112 | {"GSM Line In", NULL, "MONO"}, | |
113 | ||
114 | /* headphone connected to HPL, HPR */ | |
115 | {"Headset", NULL, "HPL"}, | |
116 | {"Headset", NULL, "HPR"}, | |
117 | ||
118 | /* front speaker connected to HPL, OUT3 */ | |
119 | {"Front Speaker", NULL, "HPL"}, | |
120 | {"Front Speaker", NULL, "OUT3"}, | |
121 | ||
122 | /* rear speaker connected to SPKL, SPKR */ | |
123 | {"Rear Speaker", NULL, "SPKL"}, | |
124 | {"Rear Speaker", NULL, "SPKR"}, | |
125 | }; | |
126 | ||
f0fba2ad | 127 | static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd) |
8f0dc655 | 128 | { |
f0fba2ad | 129 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 130 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
8f0dc655 RJ |
131 | unsigned short reg; |
132 | ||
133 | /* Add mioa701 specific widgets */ | |
4edec9ea JL |
134 | snd_soc_dapm_new_controls(dapm, mioa701_dapm_widgets, |
135 | ARRAY_SIZE(mioa701_dapm_widgets)); | |
8f0dc655 RJ |
136 | |
137 | /* Set up mioa701 specific audio path audio_mapnects */ | |
4edec9ea | 138 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
8f0dc655 RJ |
139 | |
140 | /* Prepare GPIO8 for rear speaker amplifier */ | |
f0fba2ad LG |
141 | reg = codec->driver->read(codec, AC97_GPIO_CFG); |
142 | codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100); | |
8f0dc655 RJ |
143 | |
144 | /* Prepare MIC input */ | |
f0fba2ad LG |
145 | reg = codec->driver->read(codec, AC97_3D_CONTROL); |
146 | codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000); | |
8f0dc655 | 147 | |
ce6120cc LG |
148 | snd_soc_dapm_enable_pin(dapm, "Front Speaker"); |
149 | snd_soc_dapm_enable_pin(dapm, "Rear Speaker"); | |
150 | snd_soc_dapm_enable_pin(dapm, "Front Mic"); | |
151 | snd_soc_dapm_enable_pin(dapm, "GSM Line In"); | |
152 | snd_soc_dapm_enable_pin(dapm, "GSM Line Out"); | |
8f0dc655 RJ |
153 | |
154 | return 0; | |
155 | } | |
156 | ||
157 | static struct snd_soc_ops mioa701_ops; | |
158 | ||
159 | static struct snd_soc_dai_link mioa701_dai[] = { | |
160 | { | |
161 | .name = "AC97", | |
162 | .stream_name = "AC97 HiFi", | |
4bfc4e25 | 163 | .cpu_dai_name = "pxa2xx-ac97", |
f0fba2ad LG |
164 | .codec_dai_name = "wm9713-hifi", |
165 | .codec_name = "wm9713-codec", | |
8f0dc655 | 166 | .init = mioa701_wm9713_init, |
f0fba2ad | 167 | .platform_name = "pxa-pcm-audio", |
8f0dc655 RJ |
168 | .ops = &mioa701_ops, |
169 | }, | |
170 | { | |
171 | .name = "AC97 Aux", | |
172 | .stream_name = "AC97 Aux", | |
4bfc4e25 | 173 | .cpu_dai_name = "pxa2xx-ac97-aux", |
f0fba2ad LG |
174 | .codec_dai_name ="wm9713-aux", |
175 | .codec_name = "wm9713-codec", | |
176 | .platform_name = "pxa-pcm-audio", | |
8f0dc655 RJ |
177 | .ops = &mioa701_ops, |
178 | }, | |
179 | }; | |
180 | ||
181 | static struct snd_soc_card mioa701 = { | |
182 | .name = "MioA701", | |
561c6a17 | 183 | .owner = THIS_MODULE, |
8f0dc655 RJ |
184 | .dai_link = mioa701_dai, |
185 | .num_links = ARRAY_SIZE(mioa701_dai), | |
186 | }; | |
187 | ||
570f6fe1 | 188 | static int mioa701_wm9713_probe(struct platform_device *pdev) |
8f0dc655 | 189 | { |
890255e7 | 190 | int rc; |
8f0dc655 RJ |
191 | |
192 | if (!machine_is_mioa701()) | |
193 | return -ENODEV; | |
194 | ||
890255e7 RJ |
195 | mioa701.dev = &pdev->dev; |
196 | rc = snd_soc_register_card(&mioa701); | |
197 | if (!rc) | |
198 | dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will" | |
199 | "lead to overheating and possible destruction of your device." | |
200 | " Do not use without a good knowledge of mio's board design!\n"); | |
201 | return rc; | |
8f0dc655 RJ |
202 | } |
203 | ||
570f6fe1 | 204 | static int mioa701_wm9713_remove(struct platform_device *pdev) |
8f0dc655 | 205 | { |
890255e7 RJ |
206 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
207 | ||
208 | snd_soc_unregister_card(card); | |
8f0dc655 RJ |
209 | return 0; |
210 | } | |
211 | ||
212 | static struct platform_driver mioa701_wm9713_driver = { | |
213 | .probe = mioa701_wm9713_probe, | |
570f6fe1 | 214 | .remove = mioa701_wm9713_remove, |
8f0dc655 RJ |
215 | .driver = { |
216 | .name = "mioa701-wm9713", | |
217 | .owner = THIS_MODULE, | |
218 | }, | |
219 | }; | |
220 | ||
2f702a19 | 221 | module_platform_driver(mioa701_wm9713_driver); |
8f0dc655 RJ |
222 | |
223 | /* Module information */ | |
224 | MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)"); | |
225 | MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701"); | |
226 | MODULE_LICENSE("GPL"); |