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