]>
Commit | Line | Data |
---|---|---|
a1eb4b3c LG |
1 | /* |
2 | * corgi.c -- SoC audio for Corgi | |
3 | * | |
4 | * Copyright 2005 Wolfson Microelectronics PLC. | |
5 | * Copyright 2005 Openedhand Ltd. | |
6 | * | |
d331124d | 7 | * Authors: Liam Girdwood <lrg@slimlogic.co.uk> |
a1eb4b3c LG |
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. | |
a1eb4b3c LG |
14 | */ |
15 | ||
16 | #include <linux/module.h> | |
17 | #include <linux/moduleparam.h> | |
18 | #include <linux/timer.h> | |
fc996757 | 19 | #include <linux/i2c.h> |
a1eb4b3c LG |
20 | #include <linux/interrupt.h> |
21 | #include <linux/platform_device.h> | |
6168cda9 | 22 | #include <linux/gpio.h> |
a1eb4b3c LG |
23 | #include <sound/core.h> |
24 | #include <sound/pcm.h> | |
25 | #include <sound/soc.h> | |
a1eb4b3c LG |
26 | |
27 | #include <asm/mach-types.h> | |
a09e64fb RK |
28 | #include <mach/corgi.h> |
29 | #include <mach/audio.h> | |
a1eb4b3c LG |
30 | |
31 | #include "../codecs/wm8731.h" | |
d928b25a | 32 | #include "pxa2xx-i2s.h" |
a1eb4b3c LG |
33 | |
34 | #define CORGI_HP 0 | |
35 | #define CORGI_MIC 1 | |
36 | #define CORGI_LINE 2 | |
37 | #define CORGI_HEADSET 3 | |
38 | #define CORGI_HP_OFF 4 | |
39 | #define CORGI_SPK_ON 0 | |
40 | #define CORGI_SPK_OFF 1 | |
41 | ||
42 | /* audio clock in Hz - rounded from 12.235MHz */ | |
43 | #define CORGI_AUDIO_CLOCK 12288000 | |
44 | ||
45 | static int corgi_jack_func; | |
46 | static int corgi_spk_func; | |
47 | ||
022658be | 48 | static void corgi_ext_control(struct snd_soc_dapm_context *dapm) |
a1eb4b3c | 49 | { |
a1eb4b3c LG |
50 | /* set up jack connection */ |
51 | switch (corgi_jack_func) { | |
52 | case CORGI_HP: | |
a1eb4b3c | 53 | /* set = unmute headphone */ |
6168cda9 EM |
54 | gpio_set_value(CORGI_GPIO_MUTE_L, 1); |
55 | gpio_set_value(CORGI_GPIO_MUTE_R, 1); | |
ce6120cc LG |
56 | snd_soc_dapm_disable_pin(dapm, "Mic Jack"); |
57 | snd_soc_dapm_disable_pin(dapm, "Line Jack"); | |
58 | snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); | |
59 | snd_soc_dapm_disable_pin(dapm, "Headset Jack"); | |
a1eb4b3c LG |
60 | break; |
61 | case CORGI_MIC: | |
a1eb4b3c | 62 | /* reset = mute headphone */ |
6168cda9 EM |
63 | gpio_set_value(CORGI_GPIO_MUTE_L, 0); |
64 | gpio_set_value(CORGI_GPIO_MUTE_R, 0); | |
ce6120cc LG |
65 | snd_soc_dapm_enable_pin(dapm, "Mic Jack"); |
66 | snd_soc_dapm_disable_pin(dapm, "Line Jack"); | |
67 | snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); | |
68 | snd_soc_dapm_disable_pin(dapm, "Headset Jack"); | |
a1eb4b3c LG |
69 | break; |
70 | case CORGI_LINE: | |
6168cda9 EM |
71 | gpio_set_value(CORGI_GPIO_MUTE_L, 0); |
72 | gpio_set_value(CORGI_GPIO_MUTE_R, 0); | |
ce6120cc LG |
73 | snd_soc_dapm_disable_pin(dapm, "Mic Jack"); |
74 | snd_soc_dapm_enable_pin(dapm, "Line Jack"); | |
75 | snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); | |
76 | snd_soc_dapm_disable_pin(dapm, "Headset Jack"); | |
a1eb4b3c LG |
77 | break; |
78 | case CORGI_HEADSET: | |
6168cda9 EM |
79 | gpio_set_value(CORGI_GPIO_MUTE_L, 0); |
80 | gpio_set_value(CORGI_GPIO_MUTE_R, 1); | |
ce6120cc LG |
81 | snd_soc_dapm_enable_pin(dapm, "Mic Jack"); |
82 | snd_soc_dapm_disable_pin(dapm, "Line Jack"); | |
83 | snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); | |
84 | snd_soc_dapm_enable_pin(dapm, "Headset Jack"); | |
a1eb4b3c LG |
85 | break; |
86 | } | |
87 | ||
88 | if (corgi_spk_func == CORGI_SPK_ON) | |
ce6120cc | 89 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); |
a5302181 | 90 | else |
ce6120cc | 91 | snd_soc_dapm_disable_pin(dapm, "Ext Spk"); |
a1eb4b3c LG |
92 | |
93 | /* signal a DAPM event */ | |
ce6120cc | 94 | snd_soc_dapm_sync(dapm); |
a1eb4b3c LG |
95 | } |
96 | ||
97 | static int corgi_startup(struct snd_pcm_substream *substream) | |
98 | { | |
99 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 100 | struct snd_soc_codec *codec = rtd->codec; |
a1eb4b3c LG |
101 | |
102 | /* check the jack status at stream startup */ | |
022658be | 103 | corgi_ext_control(&codec->dapm); |
71a29560 | 104 | |
a1eb4b3c LG |
105 | return 0; |
106 | } | |
107 | ||
108 | /* we need to unmute the HP at shutdown as the mute burns power on corgi */ | |
5220ed6b | 109 | static void corgi_shutdown(struct snd_pcm_substream *substream) |
a1eb4b3c | 110 | { |
a1eb4b3c | 111 | /* set = unmute headphone */ |
6168cda9 EM |
112 | gpio_set_value(CORGI_GPIO_MUTE_L, 1); |
113 | gpio_set_value(CORGI_GPIO_MUTE_R, 1); | |
a1eb4b3c LG |
114 | } |
115 | ||
d928b25a LG |
116 | static int corgi_hw_params(struct snd_pcm_substream *substream, |
117 | struct snd_pcm_hw_params *params) | |
118 | { | |
119 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
120 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
121 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
d928b25a LG |
122 | unsigned int clk = 0; |
123 | int ret = 0; | |
124 | ||
125 | switch (params_rate(params)) { | |
126 | case 8000: | |
127 | case 16000: | |
128 | case 48000: | |
129 | case 96000: | |
130 | clk = 12288000; | |
131 | break; | |
132 | case 11025: | |
133 | case 22050: | |
134 | case 44100: | |
135 | clk = 11289600; | |
136 | break; | |
137 | } | |
138 | ||
d928b25a | 139 | /* set the codec system clock for DAC and ADC */ |
9745e824 | 140 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, clk, |
d928b25a LG |
141 | SND_SOC_CLOCK_IN); |
142 | if (ret < 0) | |
143 | return ret; | |
144 | ||
145 | /* set the I2S system clock as input (unused) */ | |
64105cfd | 146 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0, |
d928b25a LG |
147 | SND_SOC_CLOCK_IN); |
148 | if (ret < 0) | |
149 | return ret; | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
a1eb4b3c LG |
154 | static struct snd_soc_ops corgi_ops = { |
155 | .startup = corgi_startup, | |
d928b25a | 156 | .hw_params = corgi_hw_params, |
a1eb4b3c LG |
157 | .shutdown = corgi_shutdown, |
158 | }; | |
159 | ||
160 | static int corgi_get_jack(struct snd_kcontrol *kcontrol, | |
161 | struct snd_ctl_elem_value *ucontrol) | |
162 | { | |
163 | ucontrol->value.integer.value[0] = corgi_jack_func; | |
164 | return 0; | |
165 | } | |
166 | ||
167 | static int corgi_set_jack(struct snd_kcontrol *kcontrol, | |
168 | struct snd_ctl_elem_value *ucontrol) | |
169 | { | |
022658be | 170 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
a1eb4b3c LG |
171 | |
172 | if (corgi_jack_func == ucontrol->value.integer.value[0]) | |
173 | return 0; | |
174 | ||
175 | corgi_jack_func = ucontrol->value.integer.value[0]; | |
022658be | 176 | corgi_ext_control(&card->dapm); |
a1eb4b3c LG |
177 | return 1; |
178 | } | |
179 | ||
180 | static int corgi_get_spk(struct snd_kcontrol *kcontrol, | |
181 | struct snd_ctl_elem_value *ucontrol) | |
182 | { | |
183 | ucontrol->value.integer.value[0] = corgi_spk_func; | |
184 | return 0; | |
185 | } | |
186 | ||
187 | static int corgi_set_spk(struct snd_kcontrol *kcontrol, | |
188 | struct snd_ctl_elem_value *ucontrol) | |
189 | { | |
022658be | 190 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
a1eb4b3c LG |
191 | |
192 | if (corgi_spk_func == ucontrol->value.integer.value[0]) | |
193 | return 0; | |
194 | ||
195 | corgi_spk_func = ucontrol->value.integer.value[0]; | |
022658be | 196 | corgi_ext_control(&card->dapm); |
a1eb4b3c LG |
197 | return 1; |
198 | } | |
199 | ||
338c7ed0 JN |
200 | static int corgi_amp_event(struct snd_soc_dapm_widget *w, |
201 | struct snd_kcontrol *k, int event) | |
a1eb4b3c | 202 | { |
6168cda9 | 203 | gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event)); |
a1eb4b3c LG |
204 | return 0; |
205 | } | |
206 | ||
338c7ed0 JN |
207 | static int corgi_mic_event(struct snd_soc_dapm_widget *w, |
208 | struct snd_kcontrol *k, int event) | |
a1eb4b3c | 209 | { |
6168cda9 | 210 | gpio_set_value(CORGI_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event)); |
a1eb4b3c LG |
211 | return 0; |
212 | } | |
213 | ||
214 | /* corgi machine dapm widgets */ | |
215 | static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = { | |
216 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
217 | SND_SOC_DAPM_MIC("Mic Jack", corgi_mic_event), | |
218 | SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event), | |
219 | SND_SOC_DAPM_LINE("Line Jack", NULL), | |
220 | SND_SOC_DAPM_HP("Headset Jack", NULL), | |
221 | }; | |
222 | ||
223 | /* Corgi machine audio map (connections to the codec pins) */ | |
32696af1 | 224 | static const struct snd_soc_dapm_route corgi_audio_map[] = { |
a1eb4b3c LG |
225 | |
226 | /* headset Jack - in = micin, out = LHPOUT*/ | |
227 | {"Headset Jack", NULL, "LHPOUT"}, | |
228 | ||
229 | /* headphone connected to LHPOUT1, RHPOUT1 */ | |
230 | {"Headphone Jack", NULL, "LHPOUT"}, | |
231 | {"Headphone Jack", NULL, "RHPOUT"}, | |
232 | ||
233 | /* speaker connected to LOUT, ROUT */ | |
234 | {"Ext Spk", NULL, "ROUT"}, | |
235 | {"Ext Spk", NULL, "LOUT"}, | |
236 | ||
237 | /* mic is connected to MICIN (via right channel of headphone jack) */ | |
238 | {"MICIN", NULL, "Mic Jack"}, | |
239 | ||
240 | /* Same as the above but no mic bias for line signals */ | |
241 | {"MICIN", NULL, "Line Jack"}, | |
a1eb4b3c LG |
242 | }; |
243 | ||
244 | static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset", | |
245 | "Off"}; | |
246 | static const char *spk_function[] = {"On", "Off"}; | |
247 | static const struct soc_enum corgi_enum[] = { | |
248 | SOC_ENUM_SINGLE_EXT(5, jack_function), | |
249 | SOC_ENUM_SINGLE_EXT(2, spk_function), | |
250 | }; | |
251 | ||
252 | static const struct snd_kcontrol_new wm8731_corgi_controls[] = { | |
253 | SOC_ENUM_EXT("Jack Function", corgi_enum[0], corgi_get_jack, | |
254 | corgi_set_jack), | |
255 | SOC_ENUM_EXT("Speaker Function", corgi_enum[1], corgi_get_spk, | |
256 | corgi_set_spk), | |
257 | }; | |
258 | ||
259 | /* | |
260 | * Logic for a wm8731 as connected on a Sharp SL-C7x0 Device | |
261 | */ | |
f0fba2ad | 262 | static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd) |
a1eb4b3c | 263 | { |
f0fba2ad | 264 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 265 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
a1eb4b3c | 266 | |
ce6120cc LG |
267 | snd_soc_dapm_nc_pin(dapm, "LLINEIN"); |
268 | snd_soc_dapm_nc_pin(dapm, "RLINEIN"); | |
a1eb4b3c | 269 | |
a1eb4b3c LG |
270 | return 0; |
271 | } | |
272 | ||
a1eb4b3c LG |
273 | /* corgi digital audio interface glue - connects codec <--> CPU */ |
274 | static struct snd_soc_dai_link corgi_dai = { | |
275 | .name = "WM8731", | |
276 | .stream_name = "WM8731", | |
a3adfa00 | 277 | .cpu_dai_name = "pxa2xx-i2s", |
f0fba2ad LG |
278 | .codec_dai_name = "wm8731-hifi", |
279 | .platform_name = "pxa-pcm-audio", | |
99b59f3c | 280 | .codec_name = "wm8731.0-001b", |
a1eb4b3c | 281 | .init = corgi_wm8731_init, |
74f4dd56 AL |
282 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
283 | SND_SOC_DAIFMT_CBS_CFS, | |
d928b25a | 284 | .ops = &corgi_ops, |
a1eb4b3c LG |
285 | }; |
286 | ||
287 | /* corgi audio machine driver */ | |
34be9244 | 288 | static struct snd_soc_card corgi = { |
a1eb4b3c | 289 | .name = "Corgi", |
561c6a17 | 290 | .owner = THIS_MODULE, |
a1eb4b3c LG |
291 | .dai_link = &corgi_dai, |
292 | .num_links = 1, | |
32696af1 AL |
293 | |
294 | .controls = wm8731_corgi_controls, | |
295 | .num_controls = ARRAY_SIZE(wm8731_corgi_controls), | |
296 | .dapm_widgets = wm8731_dapm_widgets, | |
297 | .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), | |
298 | .dapm_routes = corgi_audio_map, | |
299 | .num_dapm_routes = ARRAY_SIZE(corgi_audio_map), | |
a1eb4b3c LG |
300 | }; |
301 | ||
570f6fe1 | 302 | static int corgi_probe(struct platform_device *pdev) |
a1eb4b3c | 303 | { |
34be9244 | 304 | struct snd_soc_card *card = &corgi; |
a1eb4b3c LG |
305 | int ret; |
306 | ||
34be9244 | 307 | card->dev = &pdev->dev; |
a1eb4b3c | 308 | |
34be9244 | 309 | ret = snd_soc_register_card(card); |
a1eb4b3c | 310 | if (ret) |
34be9244 AL |
311 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
312 | ret); | |
a1eb4b3c LG |
313 | return ret; |
314 | } | |
315 | ||
570f6fe1 | 316 | static int corgi_remove(struct platform_device *pdev) |
a1eb4b3c | 317 | { |
34be9244 AL |
318 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
319 | ||
320 | snd_soc_unregister_card(card); | |
321 | return 0; | |
a1eb4b3c LG |
322 | } |
323 | ||
34be9244 AL |
324 | static struct platform_driver corgi_driver = { |
325 | .driver = { | |
326 | .name = "corgi-audio", | |
327 | .owner = THIS_MODULE, | |
7db1698f | 328 | .pm = &snd_soc_pm_ops, |
34be9244 AL |
329 | }, |
330 | .probe = corgi_probe, | |
570f6fe1 | 331 | .remove = corgi_remove, |
34be9244 AL |
332 | }; |
333 | ||
334 | module_platform_driver(corgi_driver); | |
a1eb4b3c LG |
335 | |
336 | /* Module information */ | |
337 | MODULE_AUTHOR("Richard Purdie"); | |
338 | MODULE_DESCRIPTION("ALSA SoC Corgi"); | |
339 | MODULE_LICENSE("GPL"); | |
34be9244 | 340 | MODULE_ALIAS("platform:corgi-audio"); |