]>
Commit | Line | Data |
---|---|---|
1b49cb98 LG |
1 | /* |
2 | * tosa.c -- SoC audio for Tosa | |
3 | * | |
4 | * Copyright 2005 Wolfson Microelectronics PLC. | |
5 | * Copyright 2005 Openedhand Ltd. | |
6 | * | |
7 | * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com> | |
8 | * Richard Purdie <richard@openedhand.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2 of the License, or (at your | |
13 | * option) any later version. | |
14 | * | |
1b49cb98 LG |
15 | * GPIO's |
16 | * 1 - Jack Insertion | |
17 | * 5 - Hookswitch (headset answer/hang up switch) | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <linux/module.h> | |
22 | #include <linux/moduleparam.h> | |
23 | #include <linux/device.h> | |
24 | ||
1b49cb98 LG |
25 | #include <sound/core.h> |
26 | #include <sound/pcm.h> | |
27 | #include <sound/soc.h> | |
28 | #include <sound/soc-dapm.h> | |
29 | ||
30 | #include <asm/mach-types.h> | |
31 | #include <asm/hardware/tmio.h> | |
32 | #include <asm/arch/pxa-regs.h> | |
33 | #include <asm/arch/hardware.h> | |
34 | #include <asm/arch/audio.h> | |
35 | #include <asm/arch/tosa.h> | |
36 | ||
37 | #include "../codecs/wm9712.h" | |
38 | #include "pxa2xx-pcm.h" | |
cb4c048b | 39 | #include "pxa2xx-ac97.h" |
1b49cb98 LG |
40 | |
41 | static struct snd_soc_machine tosa; | |
42 | ||
43 | #define TOSA_HP 0 | |
44 | #define TOSA_MIC_INT 1 | |
45 | #define TOSA_HEADSET 2 | |
46 | #define TOSA_HP_OFF 3 | |
47 | #define TOSA_SPK_ON 0 | |
48 | #define TOSA_SPK_OFF 1 | |
49 | ||
50 | static int tosa_jack_func; | |
51 | static int tosa_spk_func; | |
52 | ||
53 | static void tosa_ext_control(struct snd_soc_codec *codec) | |
54 | { | |
1b49cb98 LG |
55 | /* set up jack connection */ |
56 | switch (tosa_jack_func) { | |
57 | case TOSA_HP: | |
a5302181 LG |
58 | snd_soc_dapm_disable_pin(codec, "Mic (Internal)"); |
59 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); | |
60 | snd_soc_dapm_disable_pin(codec, "Headset Jack"); | |
1b49cb98 LG |
61 | break; |
62 | case TOSA_MIC_INT: | |
a5302181 LG |
63 | snd_soc_dapm_enable_pin(codec, "Mic (Internal)"); |
64 | snd_soc_dapm_disable_pin(codec, "Headphone Jack"); | |
65 | snd_soc_dapm_disable_pin(codec, "Headset Jack"); | |
1b49cb98 LG |
66 | break; |
67 | case TOSA_HEADSET: | |
a5302181 LG |
68 | snd_soc_dapm_disable_pin(codec, "Mic (Internal)"); |
69 | snd_soc_dapm_disable_pin(codec, "Headphone Jack"); | |
70 | snd_soc_dapm_enable_pin(codec, "Headset Jack"); | |
1b49cb98 LG |
71 | break; |
72 | } | |
73 | ||
74 | if (tosa_spk_func == TOSA_SPK_ON) | |
a5302181 LG |
75 | snd_soc_dapm_enable_pin(codec, "Speaker"); |
76 | else | |
77 | snd_soc_dapm_disable_pin(codec, "Speaker"); | |
1b49cb98 | 78 | |
a5302181 | 79 | snd_soc_dapm_sync(codec); |
1b49cb98 LG |
80 | } |
81 | ||
82 | static int tosa_startup(struct snd_pcm_substream *substream) | |
83 | { | |
84 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
85 | struct snd_soc_codec *codec = rtd->socdev->codec; | |
86 | ||
87 | /* check the jack status at stream startup */ | |
88 | tosa_ext_control(codec); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | static struct snd_soc_ops tosa_ops = { | |
93 | .startup = tosa_startup, | |
94 | }; | |
95 | ||
96 | static int tosa_get_jack(struct snd_kcontrol *kcontrol, | |
97 | struct snd_ctl_elem_value *ucontrol) | |
98 | { | |
99 | ucontrol->value.integer.value[0] = tosa_jack_func; | |
100 | return 0; | |
101 | } | |
102 | ||
103 | static int tosa_set_jack(struct snd_kcontrol *kcontrol, | |
104 | struct snd_ctl_elem_value *ucontrol) | |
105 | { | |
106 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
107 | ||
108 | if (tosa_jack_func == ucontrol->value.integer.value[0]) | |
109 | return 0; | |
110 | ||
111 | tosa_jack_func = ucontrol->value.integer.value[0]; | |
112 | tosa_ext_control(codec); | |
113 | return 1; | |
114 | } | |
115 | ||
116 | static int tosa_get_spk(struct snd_kcontrol *kcontrol, | |
117 | struct snd_ctl_elem_value *ucontrol) | |
118 | { | |
119 | ucontrol->value.integer.value[0] = tosa_spk_func; | |
120 | return 0; | |
121 | } | |
122 | ||
123 | static int tosa_set_spk(struct snd_kcontrol *kcontrol, | |
124 | struct snd_ctl_elem_value *ucontrol) | |
125 | { | |
126 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
127 | ||
128 | if (tosa_spk_func == ucontrol->value.integer.value[0]) | |
129 | return 0; | |
130 | ||
131 | tosa_spk_func = ucontrol->value.integer.value[0]; | |
132 | tosa_ext_control(codec); | |
133 | return 1; | |
134 | } | |
135 | ||
136 | /* tosa dapm event handlers */ | |
338c7ed0 JN |
137 | static int tosa_hp_event(struct snd_soc_dapm_widget *w, |
138 | struct snd_kcontrol *k, int event) | |
1b49cb98 LG |
139 | { |
140 | if (SND_SOC_DAPM_EVENT_ON(event)) | |
141 | set_tc6393_gpio(&tc6393_device.dev,TOSA_TC6393_L_MUTE); | |
142 | else | |
143 | reset_tc6393_gpio(&tc6393_device.dev,TOSA_TC6393_L_MUTE); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | /* tosa machine dapm widgets */ | |
148 | static const struct snd_soc_dapm_widget tosa_dapm_widgets[] = { | |
149 | SND_SOC_DAPM_HP("Headphone Jack", tosa_hp_event), | |
150 | SND_SOC_DAPM_HP("Headset Jack", NULL), | |
151 | SND_SOC_DAPM_MIC("Mic (Internal)", NULL), | |
152 | SND_SOC_DAPM_SPK("Speaker", NULL), | |
153 | }; | |
154 | ||
155 | /* tosa audio map */ | |
25191c45 | 156 | static const snd_soc_dapm_route audio_map[] = { |
1b49cb98 LG |
157 | |
158 | /* headphone connected to HPOUTL, HPOUTR */ | |
159 | {"Headphone Jack", NULL, "HPOUTL"}, | |
160 | {"Headphone Jack", NULL, "HPOUTR"}, | |
161 | ||
162 | /* ext speaker connected to LOUT2, ROUT2 */ | |
163 | {"Speaker", NULL, "LOUT2"}, | |
164 | {"Speaker", NULL, "ROUT2"}, | |
165 | ||
166 | /* internal mic is connected to mic1, mic2 differential - with bias */ | |
167 | {"MIC1", NULL, "Mic Bias"}, | |
168 | {"MIC2", NULL, "Mic Bias"}, | |
169 | {"Mic Bias", NULL, "Mic (Internal)"}, | |
170 | ||
171 | /* headset is connected to HPOUTR, and LINEINR with bias */ | |
172 | {"Headset Jack", NULL, "HPOUTR"}, | |
173 | {"LINEINR", NULL, "Mic Bias"}, | |
174 | {"Mic Bias", NULL, "Headset Jack"}, | |
1b49cb98 LG |
175 | }; |
176 | ||
177 | static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset", | |
178 | "Off"}; | |
179 | static const char *spk_function[] = {"On", "Off"}; | |
180 | static const struct soc_enum tosa_enum[] = { | |
181 | SOC_ENUM_SINGLE_EXT(5, jack_function), | |
182 | SOC_ENUM_SINGLE_EXT(2, spk_function), | |
183 | }; | |
184 | ||
185 | static const struct snd_kcontrol_new tosa_controls[] = { | |
186 | SOC_ENUM_EXT("Jack Function", tosa_enum[0], tosa_get_jack, | |
187 | tosa_set_jack), | |
188 | SOC_ENUM_EXT("Speaker Function", tosa_enum[1], tosa_get_spk, | |
189 | tosa_set_spk), | |
190 | }; | |
191 | ||
192 | static int tosa_ac97_init(struct snd_soc_codec *codec) | |
193 | { | |
194 | int i, err; | |
195 | ||
a5302181 LG |
196 | snd_soc_dapm_disable_pin(codec, "OUT3"); |
197 | snd_soc_dapm_disable_pin(codec, "MONOOUT"); | |
1b49cb98 LG |
198 | |
199 | /* add tosa specific controls */ | |
200 | for (i = 0; i < ARRAY_SIZE(tosa_controls); i++) { | |
201 | err = snd_ctl_add(codec->card, | |
202 | snd_soc_cnew(&tosa_controls[i],codec, NULL)); | |
203 | if (err < 0) | |
204 | return err; | |
205 | } | |
206 | ||
207 | /* add tosa specific widgets */ | |
25191c45 MB |
208 | snd_soc_dapm_new_controls(codec, &tosa_dapm_widgets, |
209 | ARRAY_SIZE(tosa_dapm_widgets)); | |
1b49cb98 LG |
210 | |
211 | /* set up tosa specific audio path audio_map */ | |
25191c45 | 212 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
1b49cb98 | 213 | |
a5302181 | 214 | snd_soc_dapm_sync(codec); |
1b49cb98 LG |
215 | return 0; |
216 | } | |
217 | ||
218 | static struct snd_soc_dai_link tosa_dai[] = { | |
219 | { | |
220 | .name = "AC97", | |
221 | .stream_name = "AC97 HiFi", | |
222 | .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI], | |
223 | .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI], | |
224 | .init = tosa_ac97_init, | |
cb4c048b | 225 | .ops = &tosa_ops, |
1b49cb98 LG |
226 | }, |
227 | { | |
228 | .name = "AC97 Aux", | |
229 | .stream_name = "AC97 Aux", | |
230 | .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX], | |
231 | .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX], | |
cb4c048b | 232 | .ops = &tosa_ops, |
1b49cb98 LG |
233 | }, |
234 | }; | |
235 | ||
236 | static struct snd_soc_machine tosa = { | |
237 | .name = "Tosa", | |
238 | .dai_link = tosa_dai, | |
239 | .num_links = ARRAY_SIZE(tosa_dai), | |
1b49cb98 LG |
240 | }; |
241 | ||
242 | static struct snd_soc_device tosa_snd_devdata = { | |
243 | .machine = &tosa, | |
244 | .platform = &pxa2xx_soc_platform, | |
245 | .codec_dev = &soc_codec_dev_wm9712, | |
246 | }; | |
247 | ||
248 | static struct platform_device *tosa_snd_device; | |
249 | ||
250 | static int __init tosa_init(void) | |
251 | { | |
252 | int ret; | |
253 | ||
254 | if (!machine_is_tosa()) | |
255 | return -ENODEV; | |
256 | ||
257 | tosa_snd_device = platform_device_alloc("soc-audio", -1); | |
258 | if (!tosa_snd_device) | |
259 | return -ENOMEM; | |
260 | ||
261 | platform_set_drvdata(tosa_snd_device, &tosa_snd_devdata); | |
262 | tosa_snd_devdata.dev = &tosa_snd_device->dev; | |
263 | ret = platform_device_add(tosa_snd_device); | |
264 | ||
265 | if (ret) | |
266 | platform_device_put(tosa_snd_device); | |
267 | ||
268 | return ret; | |
269 | } | |
270 | ||
271 | static void __exit tosa_exit(void) | |
272 | { | |
273 | platform_device_unregister(tosa_snd_device); | |
274 | } | |
275 | ||
276 | module_init(tosa_init); | |
277 | module_exit(tosa_exit); | |
278 | ||
279 | /* Module information */ | |
280 | MODULE_AUTHOR("Richard Purdie"); | |
281 | MODULE_DESCRIPTION("ALSA SoC Tosa"); | |
282 | MODULE_LICENSE("GPL"); |