Commit | Line | Data |
---|---|---|
9b8dc66f MB |
1 | /* |
2 | * Speyside audio support | |
3 | * | |
4 | * Copyright 2011 Wolfson Microelectronics | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2 of the License, or (at your | |
9 | * option) any later version. | |
10 | */ | |
11 | ||
12 | #include <sound/soc.h> | |
13 | #include <sound/soc-dapm.h> | |
68688e78 MB |
14 | #include <sound/jack.h> |
15 | #include <linux/gpio.h> | |
da155d5b | 16 | #include <linux/module.h> |
9b8dc66f | 17 | |
a9ba6151 | 18 | #include "../codecs/wm8996.h" |
ea3e98e7 | 19 | #include "../codecs/wm9081.h" |
9b8dc66f | 20 | |
a9ba6151 | 21 | #define WM8996_HPSEL_GPIO 214 |
68688e78 | 22 | |
ea0a591a | 23 | static int speyside_set_bias_level(struct snd_soc_card *card, |
d4c6005f | 24 | struct snd_soc_dapm_context *dapm, |
ea0a591a MB |
25 | enum snd_soc_bias_level level) |
26 | { | |
27 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; | |
28 | int ret; | |
29 | ||
d4c6005f MB |
30 | if (dapm->dev != codec_dai->dev) |
31 | return 0; | |
32 | ||
ea0a591a MB |
33 | switch (level) { |
34 | case SND_SOC_BIAS_STANDBY: | |
a9ba6151 | 35 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2, |
ea0a591a MB |
36 | 32768, SND_SOC_CLOCK_IN); |
37 | if (ret < 0) | |
38 | return ret; | |
39 | ||
a9ba6151 | 40 | ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2, |
ea0a591a MB |
41 | 0, 0, 0); |
42 | if (ret < 0) { | |
43 | pr_err("Failed to stop FLL\n"); | |
44 | return ret; | |
45 | } | |
85e9e766 MB |
46 | break; |
47 | ||
48 | default: | |
49 | break; | |
50 | } | |
51 | ||
52 | return 0; | |
53 | } | |
54 | ||
55 | static int speyside_set_bias_level_post(struct snd_soc_card *card, | |
56 | struct snd_soc_dapm_context *dapm, | |
57 | enum snd_soc_bias_level level) | |
58 | { | |
59 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; | |
60 | int ret; | |
61 | ||
62 | if (dapm->dev != codec_dai->dev) | |
63 | return 0; | |
64 | ||
65 | switch (level) { | |
66 | case SND_SOC_BIAS_PREPARE: | |
67 | if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) { | |
68 | ret = snd_soc_dai_set_pll(codec_dai, 0, | |
a9ba6151 | 69 | WM8996_FLL_MCLK2, |
85e9e766 MB |
70 | 32768, 48000 * 256); |
71 | if (ret < 0) { | |
72 | pr_err("Failed to start FLL\n"); | |
73 | return ret; | |
74 | } | |
75 | ||
76 | ret = snd_soc_dai_set_sysclk(codec_dai, | |
a9ba6151 | 77 | WM8996_SYSCLK_FLL, |
85e9e766 MB |
78 | 48000 * 256, |
79 | SND_SOC_CLOCK_IN); | |
80 | if (ret < 0) | |
81 | return ret; | |
82 | } | |
83 | break; | |
ea0a591a MB |
84 | |
85 | default: | |
86 | break; | |
87 | } | |
88 | ||
85e9e766 MB |
89 | card->dapm.bias_level = level; |
90 | ||
ea0a591a MB |
91 | return 0; |
92 | } | |
93 | ||
9b8dc66f MB |
94 | static int speyside_hw_params(struct snd_pcm_substream *substream, |
95 | struct snd_pcm_hw_params *params) | |
96 | { | |
97 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
98 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
99 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
100 | int ret; | |
101 | ||
102 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
103 | | SND_SOC_DAIFMT_NB_NF | |
104 | | SND_SOC_DAIFMT_CBM_CFM); | |
105 | if (ret < 0) | |
106 | return ret; | |
107 | ||
108 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
109 | | SND_SOC_DAIFMT_NB_NF | |
110 | | SND_SOC_DAIFMT_CBM_CFM); | |
111 | if (ret < 0) | |
112 | return ret; | |
113 | ||
9b8dc66f MB |
114 | return 0; |
115 | } | |
116 | ||
117 | static struct snd_soc_ops speyside_ops = { | |
118 | .hw_params = speyside_hw_params, | |
119 | }; | |
120 | ||
68688e78 MB |
121 | static struct snd_soc_jack speyside_headset; |
122 | ||
123 | /* Headset jack detection DAPM pins */ | |
124 | static struct snd_soc_jack_pin speyside_headset_pins[] = { | |
125 | { | |
126 | .pin = "Headset Mic", | |
127 | .mask = SND_JACK_MICROPHONE, | |
128 | }, | |
68688e78 MB |
129 | }; |
130 | ||
131 | /* Default the headphone selection to active high */ | |
132 | static int speyside_jack_polarity; | |
133 | ||
134 | static int speyside_get_micbias(struct snd_soc_dapm_widget *source, | |
135 | struct snd_soc_dapm_widget *sink) | |
136 | { | |
137 | if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0)) | |
138 | return 1; | |
139 | if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0)) | |
140 | return 1; | |
141 | ||
142 | return 0; | |
143 | } | |
144 | ||
145 | static void speyside_set_polarity(struct snd_soc_codec *codec, | |
146 | int polarity) | |
147 | { | |
148 | speyside_jack_polarity = !polarity; | |
a9ba6151 | 149 | gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity); |
68688e78 MB |
150 | |
151 | /* Re-run DAPM to make sure we're using the correct mic bias */ | |
152 | snd_soc_dapm_sync(&codec->dapm); | |
153 | } | |
154 | ||
a9ba6151 | 155 | static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd) |
ea0a591a MB |
156 | { |
157 | struct snd_soc_dai *dai = rtd->codec_dai; | |
68688e78 MB |
158 | struct snd_soc_codec *codec = rtd->codec; |
159 | int ret; | |
160 | ||
a9ba6151 | 161 | ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0); |
68688e78 MB |
162 | if (ret < 0) |
163 | return ret; | |
164 | ||
a9ba6151 | 165 | ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL"); |
68688e78 MB |
166 | if (ret != 0) |
167 | pr_err("Failed to request HP_SEL GPIO: %d\n", ret); | |
a9ba6151 | 168 | gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity); |
ea0a591a | 169 | |
68688e78 | 170 | ret = snd_soc_jack_new(codec, "Headset", |
45cf367e MB |
171 | SND_JACK_LINEOUT | SND_JACK_HEADSET | |
172 | SND_JACK_BTN_0, | |
68688e78 MB |
173 | &speyside_headset); |
174 | if (ret) | |
175 | return ret; | |
176 | ||
177 | ret = snd_soc_jack_add_pins(&speyside_headset, | |
178 | ARRAY_SIZE(speyside_headset_pins), | |
179 | speyside_headset_pins); | |
180 | if (ret) | |
181 | return ret; | |
182 | ||
a9ba6151 | 183 | wm8996_detect(codec, &speyside_headset, speyside_set_polarity); |
68688e78 MB |
184 | |
185 | return 0; | |
ea0a591a MB |
186 | } |
187 | ||
b7a5d14c MB |
188 | static int speyside_late_probe(struct snd_soc_card *card) |
189 | { | |
190 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); | |
191 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic"); | |
192 | snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC"); | |
193 | snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC"); | |
194 | snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); | |
195 | snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output"); | |
196 | snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input"); | |
197 | ||
198 | return 0; | |
199 | } | |
200 | ||
9b8dc66f MB |
201 | static struct snd_soc_dai_link speyside_dai[] = { |
202 | { | |
203 | .name = "CPU", | |
204 | .stream_name = "CPU", | |
205 | .cpu_dai_name = "samsung-i2s.0", | |
a9ba6151 | 206 | .codec_dai_name = "wm8996-aif1", |
9b8dc66f | 207 | .platform_name = "samsung-audio", |
a9ba6151 MB |
208 | .codec_name = "wm8996.1-001a", |
209 | .init = speyside_wm8996_init, | |
9b8dc66f MB |
210 | .ops = &speyside_ops, |
211 | }, | |
556e4fb1 MB |
212 | { |
213 | .name = "Baseband", | |
214 | .stream_name = "Baseband", | |
a9ba6151 | 215 | .cpu_dai_name = "wm8996-aif2", |
556e4fb1 MB |
216 | .codec_dai_name = "wm1250-ev1", |
217 | .codec_name = "wm1250-ev1.1-0027", | |
556e4fb1 | 218 | .ops = &speyside_ops, |
b7a5d14c | 219 | .ignore_suspend = 1, |
556e4fb1 | 220 | }, |
9b8dc66f MB |
221 | }; |
222 | ||
ea3e98e7 MB |
223 | static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm) |
224 | { | |
ea3e98e7 | 225 | /* At any time the WM9081 is active it will have this clock */ |
da1c6ea6 | 226 | return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0, |
ea3e98e7 MB |
227 | 48000 * 256, 0); |
228 | } | |
229 | ||
230 | static struct snd_soc_aux_dev speyside_aux_dev[] = { | |
231 | { | |
232 | .name = "wm9081", | |
233 | .codec_name = "wm9081.1-006c", | |
234 | .init = speyside_wm9081_init, | |
235 | }, | |
236 | }; | |
237 | ||
238 | static struct snd_soc_codec_conf speyside_codec_conf[] = { | |
239 | { | |
240 | .dev_name = "wm9081.1-006c", | |
241 | .name_prefix = "Sub", | |
242 | }, | |
243 | }; | |
244 | ||
ea0e60de MB |
245 | static const struct snd_kcontrol_new controls[] = { |
246 | SOC_DAPM_PIN_SWITCH("Main Speaker"), | |
247 | SOC_DAPM_PIN_SWITCH("Main DMIC"), | |
248 | SOC_DAPM_PIN_SWITCH("Main AMIC"), | |
556e4fb1 MB |
249 | SOC_DAPM_PIN_SWITCH("WM1250 Input"), |
250 | SOC_DAPM_PIN_SWITCH("WM1250 Output"), | |
68d5a59e | 251 | SOC_DAPM_PIN_SWITCH("Headphone"), |
ea0e60de MB |
252 | }; |
253 | ||
ecfb1adf MB |
254 | static struct snd_soc_dapm_widget widgets[] = { |
255 | SND_SOC_DAPM_HP("Headphone", NULL), | |
68688e78 | 256 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
ecfb1adf MB |
257 | |
258 | SND_SOC_DAPM_SPK("Main Speaker", NULL), | |
259 | ||
260 | SND_SOC_DAPM_MIC("Main AMIC", NULL), | |
261 | SND_SOC_DAPM_MIC("Main DMIC", NULL), | |
262 | }; | |
263 | ||
264 | static struct snd_soc_dapm_route audio_paths[] = { | |
68688e78 MB |
265 | { "IN1RN", NULL, "MICB1" }, |
266 | { "IN1RP", NULL, "MICB1" }, | |
267 | { "IN1RN", NULL, "MICB2" }, | |
268 | { "IN1RP", NULL, "MICB2" }, | |
269 | { "MICB1", NULL, "Headset Mic", speyside_get_micbias }, | |
270 | { "MICB2", NULL, "Headset Mic", speyside_get_micbias }, | |
271 | ||
ecfb1adf | 272 | { "IN1LP", NULL, "MICB2" }, |
68688e78 | 273 | { "IN1RN", NULL, "MICB1" }, |
ecfb1adf MB |
274 | { "MICB2", NULL, "Main AMIC" }, |
275 | ||
276 | { "DMIC1DAT", NULL, "MICB1" }, | |
277 | { "DMIC2DAT", NULL, "MICB1" }, | |
278 | { "MICB1", NULL, "Main DMIC" }, | |
279 | ||
280 | { "Headphone", NULL, "HPOUT1L" }, | |
281 | { "Headphone", NULL, "HPOUT1R" }, | |
282 | ||
ea3e98e7 MB |
283 | { "Sub IN1", NULL, "HPOUT2L" }, |
284 | { "Sub IN2", NULL, "HPOUT2R" }, | |
285 | ||
286 | { "Main Speaker", NULL, "Sub SPKN" }, | |
287 | { "Main Speaker", NULL, "Sub SPKP" }, | |
ecfb1adf MB |
288 | { "Main Speaker", NULL, "SPKDAT" }, |
289 | }; | |
290 | ||
9b8dc66f MB |
291 | static struct snd_soc_card speyside = { |
292 | .name = "Speyside", | |
293 | .dai_link = speyside_dai, | |
294 | .num_links = ARRAY_SIZE(speyside_dai), | |
ea3e98e7 MB |
295 | .aux_dev = speyside_aux_dev, |
296 | .num_aux_devs = ARRAY_SIZE(speyside_aux_dev), | |
297 | .codec_conf = speyside_codec_conf, | |
298 | .num_configs = ARRAY_SIZE(speyside_codec_conf), | |
ecfb1adf | 299 | |
ea0a591a | 300 | .set_bias_level = speyside_set_bias_level, |
995e54f5 | 301 | .set_bias_level_post = speyside_set_bias_level_post, |
ea0a591a | 302 | |
ea0e60de MB |
303 | .controls = controls, |
304 | .num_controls = ARRAY_SIZE(controls), | |
ecfb1adf MB |
305 | .dapm_widgets = widgets, |
306 | .num_dapm_widgets = ARRAY_SIZE(widgets), | |
307 | .dapm_routes = audio_paths, | |
308 | .num_dapm_routes = ARRAY_SIZE(audio_paths), | |
39afd66c | 309 | .fully_routed = true, |
b7a5d14c MB |
310 | |
311 | .late_probe = speyside_late_probe, | |
9b8dc66f MB |
312 | }; |
313 | ||
314 | static __devinit int speyside_probe(struct platform_device *pdev) | |
315 | { | |
316 | struct snd_soc_card *card = &speyside; | |
317 | int ret; | |
318 | ||
319 | card->dev = &pdev->dev; | |
320 | ||
321 | ret = snd_soc_register_card(card); | |
322 | if (ret) { | |
323 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", | |
324 | ret); | |
325 | return ret; | |
326 | } | |
327 | ||
328 | return 0; | |
329 | } | |
330 | ||
331 | static int __devexit speyside_remove(struct platform_device *pdev) | |
332 | { | |
333 | struct snd_soc_card *card = platform_get_drvdata(pdev); | |
334 | ||
335 | snd_soc_unregister_card(card); | |
336 | ||
337 | return 0; | |
338 | } | |
339 | ||
340 | static struct platform_driver speyside_driver = { | |
341 | .driver = { | |
342 | .name = "speyside", | |
343 | .owner = THIS_MODULE, | |
344 | .pm = &snd_soc_pm_ops, | |
345 | }, | |
346 | .probe = speyside_probe, | |
347 | .remove = __devexit_p(speyside_remove), | |
348 | }; | |
349 | ||
350 | static int __init speyside_audio_init(void) | |
351 | { | |
352 | return platform_driver_register(&speyside_driver); | |
353 | } | |
354 | module_init(speyside_audio_init); | |
355 | ||
356 | static void __exit speyside_audio_exit(void) | |
357 | { | |
358 | platform_driver_unregister(&speyside_driver); | |
359 | } | |
360 | module_exit(speyside_audio_exit); | |
361 | ||
362 | MODULE_DESCRIPTION("Speyside audio support"); | |
363 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | |
364 | MODULE_LICENSE("GPL"); | |
365 | MODULE_ALIAS("platform:speyside"); |