blob: 2515dba9f4aad7da4a8eaabbdc0ea562c03c7624 [file] [log] [blame]
Mark Brown9b8dc662011-04-12 17:24:39 -07001/*
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>
Mark Brown68688e72011-04-12 00:00:36 -070014#include <sound/jack.h>
15#include <linux/gpio.h>
Mark Brown9b8dc662011-04-12 17:24:39 -070016
17#include "../codecs/wm8915.h"
Mark Brownea3e98e2011-04-11 23:42:25 -070018#include "../codecs/wm9081.h"
Mark Brown9b8dc662011-04-12 17:24:39 -070019
Mark Brown68688e72011-04-12 00:00:36 -070020#define WM8915_HPSEL_GPIO 214
21
Mark Brownea0a5912011-04-11 23:32:03 -070022static int speyside_set_bias_level(struct snd_soc_card *card,
Mark Brownd4c60052011-06-06 19:13:23 +010023 struct snd_soc_dapm_context *dapm,
Mark Brownea0a5912011-04-11 23:32:03 -070024 enum snd_soc_bias_level level)
25{
26 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
27 int ret;
28
Mark Brownd4c60052011-06-06 19:13:23 +010029 if (dapm->dev != codec_dai->dev)
30 return 0;
31
Mark Brownea0a5912011-04-11 23:32:03 -070032 switch (level) {
33 case SND_SOC_BIAS_STANDBY:
Mark Brown1e025a32011-06-01 19:32:22 +010034 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK2,
Mark Brownea0a5912011-04-11 23:32:03 -070035 32768, SND_SOC_CLOCK_IN);
36 if (ret < 0)
37 return ret;
38
Mark Brown1e025a32011-06-01 19:32:22 +010039 ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK2,
Mark Brownea0a5912011-04-11 23:32:03 -070040 0, 0, 0);
41 if (ret < 0) {
42 pr_err("Failed to stop FLL\n");
43 return ret;
44 }
Mark Brown85e9e762011-06-06 19:12:44 +010045 break;
Mark Brownea0a5912011-04-11 23:32:03 -070046
47 default:
48 break;
49 }
50
51 return 0;
52}
53
Mark Brown85e9e762011-06-06 19:12:44 +010054static int speyside_set_bias_level_post(struct snd_soc_card *card,
55 struct snd_soc_dapm_context *dapm,
56 enum snd_soc_bias_level level)
57{
58 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
59 int ret;
60
61 if (dapm->dev != codec_dai->dev)
62 return 0;
63
64 switch (level) {
65 case SND_SOC_BIAS_PREPARE:
66 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
67 ret = snd_soc_dai_set_pll(codec_dai, 0,
68 WM8915_FLL_MCLK2,
69 32768, 48000 * 256);
70 if (ret < 0) {
71 pr_err("Failed to start FLL\n");
72 return ret;
73 }
74
75 ret = snd_soc_dai_set_sysclk(codec_dai,
76 WM8915_SYSCLK_FLL,
77 48000 * 256,
78 SND_SOC_CLOCK_IN);
79 if (ret < 0)
80 return ret;
81 }
82 break;
83
84 default:
85 break;
86 }
87
88 card->dapm.bias_level = level;
89
90 return 0;
91}
92
Mark Brown9b8dc662011-04-12 17:24:39 -070093static int speyside_hw_params(struct snd_pcm_substream *substream,
94 struct snd_pcm_hw_params *params)
95{
96 struct snd_soc_pcm_runtime *rtd = substream->private_data;
97 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
98 struct snd_soc_dai *codec_dai = rtd->codec_dai;
99 int ret;
100
101 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
102 | SND_SOC_DAIFMT_NB_NF
103 | SND_SOC_DAIFMT_CBM_CFM);
104 if (ret < 0)
105 return ret;
106
107 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
108 | SND_SOC_DAIFMT_NB_NF
109 | SND_SOC_DAIFMT_CBM_CFM);
110 if (ret < 0)
111 return ret;
112
Mark Brown9b8dc662011-04-12 17:24:39 -0700113 return 0;
114}
115
116static struct snd_soc_ops speyside_ops = {
117 .hw_params = speyside_hw_params,
118};
119
Mark Brown68688e72011-04-12 00:00:36 -0700120static struct snd_soc_jack speyside_headset;
121
122/* Headset jack detection DAPM pins */
123static struct snd_soc_jack_pin speyside_headset_pins[] = {
124 {
125 .pin = "Headset Mic",
126 .mask = SND_JACK_MICROPHONE,
127 },
128 {
129 .pin = "Headphone",
130 .mask = SND_JACK_HEADPHONE,
131 },
132};
133
134/* Default the headphone selection to active high */
135static int speyside_jack_polarity;
136
137static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
138 struct snd_soc_dapm_widget *sink)
139{
140 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
141 return 1;
142 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
143 return 1;
144
145 return 0;
146}
147
148static void speyside_set_polarity(struct snd_soc_codec *codec,
149 int polarity)
150{
151 speyside_jack_polarity = !polarity;
152 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
153
154 /* Re-run DAPM to make sure we're using the correct mic bias */
155 snd_soc_dapm_sync(&codec->dapm);
156}
157
Mark Brownea0a5912011-04-11 23:32:03 -0700158static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
159{
160 struct snd_soc_dai *dai = rtd->codec_dai;
Mark Brown68688e72011-04-12 00:00:36 -0700161 struct snd_soc_codec *codec = rtd->codec;
162 int ret;
Mark Brownea0a5912011-04-11 23:32:03 -0700163
Mark Brown1e025a32011-06-01 19:32:22 +0100164 ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK2, 32768, 0);
Mark Brown68688e72011-04-12 00:00:36 -0700165 if (ret < 0)
166 return ret;
167
168 ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
169 if (ret != 0)
170 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
171 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
172
173 ret = snd_soc_jack_new(codec, "Headset",
174 SND_JACK_HEADSET | SND_JACK_BTN_0,
175 &speyside_headset);
176 if (ret)
177 return ret;
178
179 ret = snd_soc_jack_add_pins(&speyside_headset,
180 ARRAY_SIZE(speyside_headset_pins),
181 speyside_headset_pins);
182 if (ret)
183 return ret;
184
185 wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
186
187 return 0;
Mark Brownea0a5912011-04-11 23:32:03 -0700188}
189
Mark Brownb7a5d142011-04-12 17:37:52 -0700190static int speyside_late_probe(struct snd_soc_card *card)
191{
192 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
193 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
194 snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
195 snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
196 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
197 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
198 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
199
200 return 0;
201}
202
Mark Brown9b8dc662011-04-12 17:24:39 -0700203static struct snd_soc_dai_link speyside_dai[] = {
204 {
205 .name = "CPU",
206 .stream_name = "CPU",
207 .cpu_dai_name = "samsung-i2s.0",
208 .codec_dai_name = "wm8915-aif1",
209 .platform_name = "samsung-audio",
210 .codec_name = "wm8915.1-001a",
Mark Brownea0a5912011-04-11 23:32:03 -0700211 .init = speyside_wm8915_init,
Mark Brown9b8dc662011-04-12 17:24:39 -0700212 .ops = &speyside_ops,
213 },
Mark Brown556e4fb2011-04-12 14:15:10 -0700214 {
215 .name = "Baseband",
216 .stream_name = "Baseband",
217 .cpu_dai_name = "wm8915-aif2",
218 .codec_dai_name = "wm1250-ev1",
219 .codec_name = "wm1250-ev1.1-0027",
Mark Brown556e4fb2011-04-12 14:15:10 -0700220 .ops = &speyside_ops,
Mark Brownb7a5d142011-04-12 17:37:52 -0700221 .ignore_suspend = 1,
Mark Brown556e4fb2011-04-12 14:15:10 -0700222 },
Mark Brown9b8dc662011-04-12 17:24:39 -0700223};
224
Mark Brownea3e98e2011-04-11 23:42:25 -0700225static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
226{
227 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
228
229 /* At any time the WM9081 is active it will have this clock */
230 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
231 48000 * 256, 0);
232}
233
234static 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
242static struct snd_soc_codec_conf speyside_codec_conf[] = {
243 {
244 .dev_name = "wm9081.1-006c",
245 .name_prefix = "Sub",
246 },
247};
248
Mark Brownea0e60d2011-04-12 00:09:53 -0700249static 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"),
Mark Brown556e4fb2011-04-12 14:15:10 -0700253 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
254 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
Mark Brownea0e60d2011-04-12 00:09:53 -0700255};
256
Mark Brownecfb1ad2011-04-11 23:09:15 -0700257static struct snd_soc_dapm_widget widgets[] = {
258 SND_SOC_DAPM_HP("Headphone", NULL),
Mark Brown68688e72011-04-12 00:00:36 -0700259 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700260
261 SND_SOC_DAPM_SPK("Main Speaker", NULL),
262
263 SND_SOC_DAPM_MIC("Main AMIC", NULL),
264 SND_SOC_DAPM_MIC("Main DMIC", NULL),
265};
266
267static struct snd_soc_dapm_route audio_paths[] = {
Mark Brown68688e72011-04-12 00:00:36 -0700268 { "IN1RN", NULL, "MICB1" },
269 { "IN1RP", NULL, "MICB1" },
270 { "IN1RN", NULL, "MICB2" },
271 { "IN1RP", NULL, "MICB2" },
272 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
273 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
274
Mark Brownecfb1ad2011-04-11 23:09:15 -0700275 { "IN1LP", NULL, "MICB2" },
Mark Brown68688e72011-04-12 00:00:36 -0700276 { "IN1RN", NULL, "MICB1" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700277 { "MICB2", NULL, "Main AMIC" },
278
279 { "DMIC1DAT", NULL, "MICB1" },
280 { "DMIC2DAT", NULL, "MICB1" },
281 { "MICB1", NULL, "Main DMIC" },
282
283 { "Headphone", NULL, "HPOUT1L" },
284 { "Headphone", NULL, "HPOUT1R" },
285
Mark Brownea3e98e2011-04-11 23:42:25 -0700286 { "Sub IN1", NULL, "HPOUT2L" },
287 { "Sub IN2", NULL, "HPOUT2R" },
288
289 { "Main Speaker", NULL, "Sub SPKN" },
290 { "Main Speaker", NULL, "Sub SPKP" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700291 { "Main Speaker", NULL, "SPKDAT" },
292};
293
Mark Brown9b8dc662011-04-12 17:24:39 -0700294static struct snd_soc_card speyside = {
295 .name = "Speyside",
296 .dai_link = speyside_dai,
297 .num_links = ARRAY_SIZE(speyside_dai),
Mark Brownea3e98e2011-04-11 23:42:25 -0700298 .aux_dev = speyside_aux_dev,
299 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
300 .codec_conf = speyside_codec_conf,
301 .num_configs = ARRAY_SIZE(speyside_codec_conf),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700302
Mark Brownea0a5912011-04-11 23:32:03 -0700303 .set_bias_level = speyside_set_bias_level,
304
Mark Brownea0e60d2011-04-12 00:09:53 -0700305 .controls = controls,
306 .num_controls = ARRAY_SIZE(controls),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700307 .dapm_widgets = widgets,
308 .num_dapm_widgets = ARRAY_SIZE(widgets),
309 .dapm_routes = audio_paths,
310 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Mark Brownb7a5d142011-04-12 17:37:52 -0700311
312 .late_probe = speyside_late_probe,
Mark Brown9b8dc662011-04-12 17:24:39 -0700313};
314
315static __devinit int speyside_probe(struct platform_device *pdev)
316{
317 struct snd_soc_card *card = &speyside;
318 int ret;
319
320 card->dev = &pdev->dev;
321
322 ret = snd_soc_register_card(card);
323 if (ret) {
324 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
325 ret);
326 return ret;
327 }
328
329 return 0;
330}
331
332static int __devexit speyside_remove(struct platform_device *pdev)
333{
334 struct snd_soc_card *card = platform_get_drvdata(pdev);
335
336 snd_soc_unregister_card(card);
337
338 return 0;
339}
340
341static struct platform_driver speyside_driver = {
342 .driver = {
343 .name = "speyside",
344 .owner = THIS_MODULE,
345 .pm = &snd_soc_pm_ops,
346 },
347 .probe = speyside_probe,
348 .remove = __devexit_p(speyside_remove),
349};
350
351static int __init speyside_audio_init(void)
352{
353 return platform_driver_register(&speyside_driver);
354}
355module_init(speyside_audio_init);
356
357static void __exit speyside_audio_exit(void)
358{
359 platform_driver_unregister(&speyside_driver);
360}
361module_exit(speyside_audio_exit);
362
363MODULE_DESCRIPTION("Speyside audio support");
364MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
365MODULE_LICENSE("GPL");
366MODULE_ALIAS("platform:speyside");