blob: 99fb0337ba5de1e15e167e6ffd26055f63847220 [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 }
45
46 default:
47 break;
48 }
49
50 return 0;
51}
52
Mark Brown9b8dc662011-04-12 17:24:39 -070053static int speyside_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params)
55{
56 struct snd_soc_pcm_runtime *rtd = substream->private_data;
57 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
58 struct snd_soc_dai *codec_dai = rtd->codec_dai;
59 int ret;
60
61 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
62 | SND_SOC_DAIFMT_NB_NF
63 | SND_SOC_DAIFMT_CBM_CFM);
64 if (ret < 0)
65 return ret;
66
67 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
68 | SND_SOC_DAIFMT_NB_NF
69 | SND_SOC_DAIFMT_CBM_CFM);
70 if (ret < 0)
71 return ret;
72
Mark Brown1e025a32011-06-01 19:32:22 +010073 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK2,
Mark Brown9b8dc662011-04-12 17:24:39 -070074 32768, 256 * 48000);
75 if (ret < 0)
76 return ret;
77
78 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
79 256 * 48000, SND_SOC_CLOCK_IN);
80 if (ret < 0)
81 return ret;
82
83 return 0;
84}
85
86static struct snd_soc_ops speyside_ops = {
87 .hw_params = speyside_hw_params,
88};
89
Mark Brown68688e72011-04-12 00:00:36 -070090static struct snd_soc_jack speyside_headset;
91
92/* Headset jack detection DAPM pins */
93static struct snd_soc_jack_pin speyside_headset_pins[] = {
94 {
95 .pin = "Headset Mic",
96 .mask = SND_JACK_MICROPHONE,
97 },
98 {
99 .pin = "Headphone",
100 .mask = SND_JACK_HEADPHONE,
101 },
102};
103
104/* Default the headphone selection to active high */
105static int speyside_jack_polarity;
106
107static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
108 struct snd_soc_dapm_widget *sink)
109{
110 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
111 return 1;
112 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
113 return 1;
114
115 return 0;
116}
117
118static void speyside_set_polarity(struct snd_soc_codec *codec,
119 int polarity)
120{
121 speyside_jack_polarity = !polarity;
122 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
123
124 /* Re-run DAPM to make sure we're using the correct mic bias */
125 snd_soc_dapm_sync(&codec->dapm);
126}
127
Mark Brownea0a5912011-04-11 23:32:03 -0700128static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
129{
130 struct snd_soc_dai *dai = rtd->codec_dai;
Mark Brown68688e72011-04-12 00:00:36 -0700131 struct snd_soc_codec *codec = rtd->codec;
132 int ret;
Mark Brownea0a5912011-04-11 23:32:03 -0700133
Mark Brown1e025a32011-06-01 19:32:22 +0100134 ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK2, 32768, 0);
Mark Brown68688e72011-04-12 00:00:36 -0700135 if (ret < 0)
136 return ret;
137
138 ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
139 if (ret != 0)
140 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
141 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
142
143 ret = snd_soc_jack_new(codec, "Headset",
144 SND_JACK_HEADSET | SND_JACK_BTN_0,
145 &speyside_headset);
146 if (ret)
147 return ret;
148
149 ret = snd_soc_jack_add_pins(&speyside_headset,
150 ARRAY_SIZE(speyside_headset_pins),
151 speyside_headset_pins);
152 if (ret)
153 return ret;
154
155 wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
156
157 return 0;
Mark Brownea0a5912011-04-11 23:32:03 -0700158}
159
Mark Brownb7a5d142011-04-12 17:37:52 -0700160static int speyside_late_probe(struct snd_soc_card *card)
161{
162 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
163 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
164 snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
165 snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
166 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
167 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
168 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
169
170 return 0;
171}
172
Mark Brown9b8dc662011-04-12 17:24:39 -0700173static struct snd_soc_dai_link speyside_dai[] = {
174 {
175 .name = "CPU",
176 .stream_name = "CPU",
177 .cpu_dai_name = "samsung-i2s.0",
178 .codec_dai_name = "wm8915-aif1",
179 .platform_name = "samsung-audio",
180 .codec_name = "wm8915.1-001a",
Mark Brownea0a5912011-04-11 23:32:03 -0700181 .init = speyside_wm8915_init,
Mark Brown9b8dc662011-04-12 17:24:39 -0700182 .ops = &speyside_ops,
183 },
Mark Brown556e4fb2011-04-12 14:15:10 -0700184 {
185 .name = "Baseband",
186 .stream_name = "Baseband",
187 .cpu_dai_name = "wm8915-aif2",
188 .codec_dai_name = "wm1250-ev1",
189 .codec_name = "wm1250-ev1.1-0027",
Mark Brown556e4fb2011-04-12 14:15:10 -0700190 .ops = &speyside_ops,
Mark Brownb7a5d142011-04-12 17:37:52 -0700191 .ignore_suspend = 1,
Mark Brown556e4fb2011-04-12 14:15:10 -0700192 },
Mark Brown9b8dc662011-04-12 17:24:39 -0700193};
194
Mark Brownea3e98e2011-04-11 23:42:25 -0700195static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
196{
197 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
198
199 /* At any time the WM9081 is active it will have this clock */
200 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
201 48000 * 256, 0);
202}
203
204static struct snd_soc_aux_dev speyside_aux_dev[] = {
205 {
206 .name = "wm9081",
207 .codec_name = "wm9081.1-006c",
208 .init = speyside_wm9081_init,
209 },
210};
211
212static struct snd_soc_codec_conf speyside_codec_conf[] = {
213 {
214 .dev_name = "wm9081.1-006c",
215 .name_prefix = "Sub",
216 },
217};
218
Mark Brownea0e60d2011-04-12 00:09:53 -0700219static const struct snd_kcontrol_new controls[] = {
220 SOC_DAPM_PIN_SWITCH("Main Speaker"),
221 SOC_DAPM_PIN_SWITCH("Main DMIC"),
222 SOC_DAPM_PIN_SWITCH("Main AMIC"),
Mark Brown556e4fb2011-04-12 14:15:10 -0700223 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
224 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
Mark Brownea0e60d2011-04-12 00:09:53 -0700225};
226
Mark Brownecfb1ad2011-04-11 23:09:15 -0700227static struct snd_soc_dapm_widget widgets[] = {
228 SND_SOC_DAPM_HP("Headphone", NULL),
Mark Brown68688e72011-04-12 00:00:36 -0700229 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700230
231 SND_SOC_DAPM_SPK("Main Speaker", NULL),
232
233 SND_SOC_DAPM_MIC("Main AMIC", NULL),
234 SND_SOC_DAPM_MIC("Main DMIC", NULL),
235};
236
237static struct snd_soc_dapm_route audio_paths[] = {
Mark Brown68688e72011-04-12 00:00:36 -0700238 { "IN1RN", NULL, "MICB1" },
239 { "IN1RP", NULL, "MICB1" },
240 { "IN1RN", NULL, "MICB2" },
241 { "IN1RP", NULL, "MICB2" },
242 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
243 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
244
Mark Brownecfb1ad2011-04-11 23:09:15 -0700245 { "IN1LP", NULL, "MICB2" },
Mark Brown68688e72011-04-12 00:00:36 -0700246 { "IN1RN", NULL, "MICB1" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700247 { "MICB2", NULL, "Main AMIC" },
248
249 { "DMIC1DAT", NULL, "MICB1" },
250 { "DMIC2DAT", NULL, "MICB1" },
251 { "MICB1", NULL, "Main DMIC" },
252
253 { "Headphone", NULL, "HPOUT1L" },
254 { "Headphone", NULL, "HPOUT1R" },
255
Mark Brownea3e98e2011-04-11 23:42:25 -0700256 { "Sub IN1", NULL, "HPOUT2L" },
257 { "Sub IN2", NULL, "HPOUT2R" },
258
259 { "Main Speaker", NULL, "Sub SPKN" },
260 { "Main Speaker", NULL, "Sub SPKP" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700261 { "Main Speaker", NULL, "SPKDAT" },
262};
263
Mark Brown9b8dc662011-04-12 17:24:39 -0700264static struct snd_soc_card speyside = {
265 .name = "Speyside",
266 .dai_link = speyside_dai,
267 .num_links = ARRAY_SIZE(speyside_dai),
Mark Brownea3e98e2011-04-11 23:42:25 -0700268 .aux_dev = speyside_aux_dev,
269 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
270 .codec_conf = speyside_codec_conf,
271 .num_configs = ARRAY_SIZE(speyside_codec_conf),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700272
Mark Brownea0a5912011-04-11 23:32:03 -0700273 .set_bias_level = speyside_set_bias_level,
274
Mark Brownea0e60d2011-04-12 00:09:53 -0700275 .controls = controls,
276 .num_controls = ARRAY_SIZE(controls),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700277 .dapm_widgets = widgets,
278 .num_dapm_widgets = ARRAY_SIZE(widgets),
279 .dapm_routes = audio_paths,
280 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Mark Brownb7a5d142011-04-12 17:37:52 -0700281
282 .late_probe = speyside_late_probe,
Mark Brown9b8dc662011-04-12 17:24:39 -0700283};
284
285static __devinit int speyside_probe(struct platform_device *pdev)
286{
287 struct snd_soc_card *card = &speyside;
288 int ret;
289
290 card->dev = &pdev->dev;
291
292 ret = snd_soc_register_card(card);
293 if (ret) {
294 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
295 ret);
296 return ret;
297 }
298
299 return 0;
300}
301
302static int __devexit speyside_remove(struct platform_device *pdev)
303{
304 struct snd_soc_card *card = platform_get_drvdata(pdev);
305
306 snd_soc_unregister_card(card);
307
308 return 0;
309}
310
311static struct platform_driver speyside_driver = {
312 .driver = {
313 .name = "speyside",
314 .owner = THIS_MODULE,
315 .pm = &snd_soc_pm_ops,
316 },
317 .probe = speyside_probe,
318 .remove = __devexit_p(speyside_remove),
319};
320
321static int __init speyside_audio_init(void)
322{
323 return platform_driver_register(&speyside_driver);
324}
325module_init(speyside_audio_init);
326
327static void __exit speyside_audio_exit(void)
328{
329 platform_driver_unregister(&speyside_driver);
330}
331module_exit(speyside_audio_exit);
332
333MODULE_DESCRIPTION("Speyside audio support");
334MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
335MODULE_LICENSE("GPL");
336MODULE_ALIAS("platform:speyside");