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