Commit | Line | Data |
---|---|---|
3782a528 CC |
1 | /* |
2 | * aquila_wm8994.c | |
3 | * | |
4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | |
5 | * Author: Chanwoo Choi <cw00.choi@samsung.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. | |
11 | * | |
12 | */ | |
13 | ||
14 | #include <linux/module.h> | |
15 | #include <linux/moduleparam.h> | |
16 | #include <linux/io.h> | |
17 | #include <linux/platform_device.h> | |
18 | #include <sound/soc.h> | |
19 | #include <sound/soc-dapm.h> | |
20 | #include <sound/jack.h> | |
21 | #include <asm/mach-types.h> | |
22 | #include <mach/gpio.h> | |
23 | #include <mach/regs-clock.h> | |
24 | ||
25 | #include <linux/mfd/wm8994/core.h> | |
26 | #include <linux/mfd/wm8994/registers.h> | |
27 | #include "../codecs/wm8994.h" | |
28 | #include "s3c-dma.h" | |
29 | #include "s3c64xx-i2s.h" | |
30 | ||
31 | static struct snd_soc_card aquila; | |
32 | static struct platform_device *aquila_snd_device; | |
33 | ||
34 | /* 3.5 pie jack */ | |
35 | static struct snd_soc_jack jack; | |
36 | ||
37 | /* 3.5 pie jack detection DAPM pins */ | |
38 | static struct snd_soc_jack_pin jack_pins[] = { | |
39 | { | |
40 | .pin = "Headset Mic", | |
41 | .mask = SND_JACK_MICROPHONE, | |
42 | }, { | |
43 | .pin = "Headset Stereophone", | |
44 | .mask = SND_JACK_HEADPHONE | SND_JACK_MECHANICAL | | |
45 | SND_JACK_AVOUT, | |
46 | }, | |
47 | }; | |
48 | ||
49 | /* 3.5 pie jack detection gpios */ | |
50 | static struct snd_soc_jack_gpio jack_gpios[] = { | |
51 | { | |
52 | .gpio = S5PV210_GPH0(6), | |
53 | .name = "DET_3.5", | |
54 | .report = SND_JACK_HEADSET | SND_JACK_MECHANICAL | | |
55 | SND_JACK_AVOUT, | |
56 | .debounce_time = 200, | |
57 | }, | |
58 | }; | |
59 | ||
60 | static const struct snd_soc_dapm_widget aquila_dapm_widgets[] = { | |
61 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | |
62 | SND_SOC_DAPM_SPK("Ext Rcv", NULL), | |
63 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | |
64 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | |
65 | SND_SOC_DAPM_MIC("Main Mic", NULL), | |
66 | SND_SOC_DAPM_MIC("2nd Mic", NULL), | |
67 | SND_SOC_DAPM_LINE("Radio In", NULL), | |
68 | }; | |
69 | ||
70 | static const struct snd_soc_dapm_route aquila_dapm_routes[] = { | |
71 | {"Ext Spk", NULL, "SPKOUTLP"}, | |
72 | {"Ext Spk", NULL, "SPKOUTLN"}, | |
73 | ||
74 | {"Ext Rcv", NULL, "HPOUT2N"}, | |
75 | {"Ext Rcv", NULL, "HPOUT2P"}, | |
76 | ||
77 | {"Headset Stereophone", NULL, "HPOUT1L"}, | |
78 | {"Headset Stereophone", NULL, "HPOUT1R"}, | |
79 | ||
80 | {"IN1RN", NULL, "Headset Mic"}, | |
81 | {"IN1RP", NULL, "Headset Mic"}, | |
82 | ||
83 | {"IN1RN", NULL, "2nd Mic"}, | |
84 | {"IN1RP", NULL, "2nd Mic"}, | |
85 | ||
86 | {"IN1LN", NULL, "Main Mic"}, | |
87 | {"IN1LP", NULL, "Main Mic"}, | |
88 | ||
89 | {"IN2LN", NULL, "Radio In"}, | |
90 | {"IN2RN", NULL, "Radio In"}, | |
91 | }; | |
92 | ||
93 | static int aquila_wm8994_init(struct snd_soc_pcm_runtime *rtd) | |
94 | { | |
95 | struct snd_soc_codec *codec = rtd->codec; | |
ce6120cc | 96 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
3782a528 CC |
97 | int ret; |
98 | ||
99 | /* add aquila specific widgets */ | |
ce6120cc | 100 | snd_soc_dapm_new_controls(dapm, aquila_dapm_widgets, |
3782a528 CC |
101 | ARRAY_SIZE(aquila_dapm_widgets)); |
102 | ||
103 | /* set up aquila specific audio routes */ | |
ce6120cc | 104 | snd_soc_dapm_add_routes(dapm, aquila_dapm_routes, |
3782a528 CC |
105 | ARRAY_SIZE(aquila_dapm_routes)); |
106 | ||
107 | /* set endpoints to not connected */ | |
ce6120cc LG |
108 | snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN"); |
109 | snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP"); | |
110 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1N"); | |
111 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1P"); | |
112 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2N"); | |
113 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2P"); | |
114 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRN"); | |
115 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRP"); | |
116 | ||
117 | snd_soc_dapm_sync(dapm); | |
3782a528 CC |
118 | |
119 | /* Headset jack detection */ | |
120 | ret = snd_soc_jack_new(&aquila, "Headset Jack", | |
121 | SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT, | |
122 | &jack); | |
123 | if (ret) | |
124 | return ret; | |
125 | ||
126 | ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins); | |
127 | if (ret) | |
128 | return ret; | |
129 | ||
130 | ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios); | |
131 | if (ret) | |
132 | return ret; | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | static int aquila_hifi_hw_params(struct snd_pcm_substream *substream, | |
138 | struct snd_pcm_hw_params *params) | |
139 | { | |
140 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
141 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
142 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
143 | unsigned int pll_out = 24000000; | |
144 | int ret = 0; | |
145 | ||
146 | /* set the cpu DAI configuration */ | |
147 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | | |
148 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM); | |
149 | if (ret < 0) | |
150 | return ret; | |
151 | ||
152 | /* set the cpu system clock */ | |
153 | ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK, | |
154 | 0, SND_SOC_CLOCK_IN); | |
155 | if (ret < 0) | |
156 | return ret; | |
157 | ||
158 | /* set codec DAI configuration */ | |
159 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | |
160 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM); | |
161 | if (ret < 0) | |
162 | return ret; | |
163 | ||
164 | /* set the codec FLL */ | |
165 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out, | |
166 | params_rate(params) * 256); | |
167 | if (ret < 0) | |
168 | return ret; | |
169 | ||
170 | /* set the codec system clock */ | |
171 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, | |
172 | params_rate(params) * 256, SND_SOC_CLOCK_IN); | |
173 | if (ret < 0) | |
174 | return ret; | |
175 | ||
176 | return 0; | |
177 | } | |
178 | ||
179 | static struct snd_soc_ops aquila_hifi_ops = { | |
180 | .hw_params = aquila_hifi_hw_params, | |
181 | }; | |
182 | ||
183 | static int aquila_voice_hw_params(struct snd_pcm_substream *substream, | |
184 | struct snd_pcm_hw_params *params) | |
185 | { | |
186 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
187 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
188 | unsigned int pll_out = 24000000; | |
189 | int ret = 0; | |
190 | ||
191 | if (params_rate(params) != 8000) | |
192 | return -EINVAL; | |
193 | ||
194 | /* set codec DAI configuration */ | |
195 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J | | |
196 | SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM); | |
197 | if (ret < 0) | |
198 | return ret; | |
199 | ||
200 | /* set the codec FLL */ | |
201 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out, | |
202 | params_rate(params) * 256); | |
203 | if (ret < 0) | |
204 | return ret; | |
205 | ||
206 | /* set the codec system clock */ | |
207 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2, | |
208 | params_rate(params) * 256, SND_SOC_CLOCK_IN); | |
209 | if (ret < 0) | |
210 | return ret; | |
211 | ||
212 | return 0; | |
213 | } | |
214 | ||
215 | static struct snd_soc_dai_driver voice_dai = { | |
216 | .name = "aquila-voice-dai", | |
217 | .playback = { | |
218 | .channels_min = 1, | |
219 | .channels_max = 2, | |
220 | .rates = SNDRV_PCM_RATE_8000, | |
221 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
222 | .capture = { | |
223 | .channels_min = 1, | |
224 | .channels_max = 2, | |
225 | .rates = SNDRV_PCM_RATE_8000, | |
226 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
227 | }; | |
228 | ||
229 | static struct snd_soc_ops aquila_voice_ops = { | |
230 | .hw_params = aquila_voice_hw_params, | |
231 | }; | |
232 | ||
233 | static struct snd_soc_dai_link aquila_dai[] = { | |
234 | { | |
235 | .name = "WM8994", | |
236 | .stream_name = "WM8994 HiFi", | |
237 | .cpu_dai_name = "s3c64xx-i2s-v4", | |
238 | .codec_dai_name = "wm8994-hifi", | |
239 | .platform_name = "s3c24xx-pcm-audio", | |
240 | .codec_name = "wm8994-codec.0-0x1a", | |
241 | .init = aquila_wm8994_init, | |
242 | .ops = &aquila_hifi_ops, | |
243 | }, { | |
244 | .name = "WM8994 Voice", | |
245 | .stream_name = "Voice", | |
246 | .cpu_dai_name = "aquila-voice-dai", | |
247 | .codec_dai_name = "wm8994-voice", | |
248 | .platform_name = "s3c24xx-pcm-audio", | |
249 | .codec_name = "wm8994-codec.0-0x1a", | |
250 | .ops = &aquila_voice_ops, | |
251 | }, | |
252 | }; | |
253 | ||
254 | static struct snd_soc_card aquila = { | |
255 | .name = "aquila", | |
256 | .dai_link = aquila_dai, | |
257 | .num_links = ARRAY_SIZE(aquila_dai), | |
258 | }; | |
259 | ||
260 | static int __init aquila_init(void) | |
261 | { | |
262 | int ret; | |
263 | ||
264 | if (!machine_is_aquila()) | |
265 | return -ENODEV; | |
266 | ||
267 | aquila_snd_device = platform_device_alloc("soc-audio", -1); | |
268 | if (!aquila_snd_device) | |
269 | return -ENOMEM; | |
270 | ||
271 | /* register voice DAI here */ | |
272 | ret = snd_soc_register_dai(&aquila_snd_device->dev, &voice_dai); | |
273 | if (ret) | |
274 | return ret; | |
275 | ||
276 | platform_set_drvdata(aquila_snd_device, &aquila); | |
277 | ret = platform_device_add(aquila_snd_device); | |
278 | ||
279 | if (ret) | |
280 | platform_device_put(aquila_snd_device); | |
281 | ||
282 | return ret; | |
283 | } | |
284 | ||
285 | static void __exit aquila_exit(void) | |
286 | { | |
287 | platform_device_unregister(aquila_snd_device); | |
288 | } | |
289 | ||
290 | module_init(aquila_init); | |
291 | module_exit(aquila_exit); | |
292 | ||
293 | /* Module information */ | |
294 | MODULE_DESCRIPTION("ALSA SoC WM8994 Aquila(S5PC110)"); | |
295 | MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); | |
296 | MODULE_LICENSE("GPL"); |