blob: a0c14a87e23d8e215bcbb00b5b5fe91b8bb81915 [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,
23 enum snd_soc_bias_level level)
24{
25 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
26 int ret;
27
28 switch (level) {
29 case SND_SOC_BIAS_STANDBY:
30 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
31 32768, SND_SOC_CLOCK_IN);
32 if (ret < 0)
33 return ret;
34
35 ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
36 0, 0, 0);
37 if (ret < 0) {
38 pr_err("Failed to stop FLL\n");
39 return ret;
40 }
41
42 default:
43 break;
44 }
45
46 return 0;
47}
48
Mark Brown9b8dc662011-04-12 17:24:39 -070049static int speyside_hw_params(struct snd_pcm_substream *substream,
50 struct snd_pcm_hw_params *params)
51{
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
54 struct snd_soc_dai *codec_dai = rtd->codec_dai;
55 int ret;
56
57 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
58 | SND_SOC_DAIFMT_NB_NF
59 | SND_SOC_DAIFMT_CBM_CFM);
60 if (ret < 0)
61 return ret;
62
63 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
64 | SND_SOC_DAIFMT_NB_NF
65 | SND_SOC_DAIFMT_CBM_CFM);
66 if (ret < 0)
67 return ret;
68
69 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
70 32768, 256 * 48000);
71 if (ret < 0)
72 return ret;
73
74 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
75 256 * 48000, SND_SOC_CLOCK_IN);
76 if (ret < 0)
77 return ret;
78
79 return 0;
80}
81
82static struct snd_soc_ops speyside_ops = {
83 .hw_params = speyside_hw_params,
84};
85
Mark Brown68688e72011-04-12 00:00:36 -070086static struct snd_soc_jack speyside_headset;
87
88/* Headset jack detection DAPM pins */
89static struct snd_soc_jack_pin speyside_headset_pins[] = {
90 {
91 .pin = "Headset Mic",
92 .mask = SND_JACK_MICROPHONE,
93 },
94 {
95 .pin = "Headphone",
96 .mask = SND_JACK_HEADPHONE,
97 },
98};
99
100/* Default the headphone selection to active high */
101static int speyside_jack_polarity;
102
103static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
104 struct snd_soc_dapm_widget *sink)
105{
106 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
107 return 1;
108 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
109 return 1;
110
111 return 0;
112}
113
114static void speyside_set_polarity(struct snd_soc_codec *codec,
115 int polarity)
116{
117 speyside_jack_polarity = !polarity;
118 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
119
120 /* Re-run DAPM to make sure we're using the correct mic bias */
121 snd_soc_dapm_sync(&codec->dapm);
122}
123
Mark Brownea0a5912011-04-11 23:32:03 -0700124static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
125{
126 struct snd_soc_dai *dai = rtd->codec_dai;
Mark Brown68688e72011-04-12 00:00:36 -0700127 struct snd_soc_codec *codec = rtd->codec;
128 int ret;
Mark Brownea0a5912011-04-11 23:32:03 -0700129
Mark Brown68688e72011-04-12 00:00:36 -0700130 ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
131 if (ret < 0)
132 return ret;
133
134 ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
135 if (ret != 0)
136 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
137 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
138
139 ret = snd_soc_jack_new(codec, "Headset",
140 SND_JACK_HEADSET | SND_JACK_BTN_0,
141 &speyside_headset);
142 if (ret)
143 return ret;
144
145 ret = snd_soc_jack_add_pins(&speyside_headset,
146 ARRAY_SIZE(speyside_headset_pins),
147 speyside_headset_pins);
148 if (ret)
149 return ret;
150
151 wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
152
153 return 0;
Mark Brownea0a5912011-04-11 23:32:03 -0700154}
155
Mark Brown9b8dc662011-04-12 17:24:39 -0700156static struct snd_soc_dai_link speyside_dai[] = {
157 {
158 .name = "CPU",
159 .stream_name = "CPU",
160 .cpu_dai_name = "samsung-i2s.0",
161 .codec_dai_name = "wm8915-aif1",
162 .platform_name = "samsung-audio",
163 .codec_name = "wm8915.1-001a",
Mark Brownea0a5912011-04-11 23:32:03 -0700164 .init = speyside_wm8915_init,
Mark Brown9b8dc662011-04-12 17:24:39 -0700165 .ops = &speyside_ops,
166 },
Mark Brown556e4fb2011-04-12 14:15:10 -0700167 {
168 .name = "Baseband",
169 .stream_name = "Baseband",
170 .cpu_dai_name = "wm8915-aif2",
171 .codec_dai_name = "wm1250-ev1",
172 .codec_name = "wm1250-ev1.1-0027",
173 .platform_name = "samsung-audio",
174 .ops = &speyside_ops,
175 },
Mark Brown9b8dc662011-04-12 17:24:39 -0700176};
177
Mark Brownea3e98e2011-04-11 23:42:25 -0700178static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
179{
180 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
181
182 /* At any time the WM9081 is active it will have this clock */
183 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
184 48000 * 256, 0);
185}
186
187static struct snd_soc_aux_dev speyside_aux_dev[] = {
188 {
189 .name = "wm9081",
190 .codec_name = "wm9081.1-006c",
191 .init = speyside_wm9081_init,
192 },
193};
194
195static struct snd_soc_codec_conf speyside_codec_conf[] = {
196 {
197 .dev_name = "wm9081.1-006c",
198 .name_prefix = "Sub",
199 },
200};
201
Mark Brownea0e60d2011-04-12 00:09:53 -0700202static const struct snd_kcontrol_new controls[] = {
203 SOC_DAPM_PIN_SWITCH("Main Speaker"),
204 SOC_DAPM_PIN_SWITCH("Main DMIC"),
205 SOC_DAPM_PIN_SWITCH("Main AMIC"),
Mark Brown556e4fb2011-04-12 14:15:10 -0700206 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
207 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
Mark Brownea0e60d2011-04-12 00:09:53 -0700208};
209
Mark Brownecfb1ad2011-04-11 23:09:15 -0700210static struct snd_soc_dapm_widget widgets[] = {
211 SND_SOC_DAPM_HP("Headphone", NULL),
Mark Brown68688e72011-04-12 00:00:36 -0700212 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700213
214 SND_SOC_DAPM_SPK("Main Speaker", NULL),
215
216 SND_SOC_DAPM_MIC("Main AMIC", NULL),
217 SND_SOC_DAPM_MIC("Main DMIC", NULL),
218};
219
220static struct snd_soc_dapm_route audio_paths[] = {
Mark Brown68688e72011-04-12 00:00:36 -0700221 { "IN1RN", NULL, "MICB1" },
222 { "IN1RP", NULL, "MICB1" },
223 { "IN1RN", NULL, "MICB2" },
224 { "IN1RP", NULL, "MICB2" },
225 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
226 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
227
Mark Brownecfb1ad2011-04-11 23:09:15 -0700228 { "IN1LP", NULL, "MICB2" },
Mark Brown68688e72011-04-12 00:00:36 -0700229 { "IN1RN", NULL, "MICB1" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700230 { "MICB2", NULL, "Main AMIC" },
231
232 { "DMIC1DAT", NULL, "MICB1" },
233 { "DMIC2DAT", NULL, "MICB1" },
234 { "MICB1", NULL, "Main DMIC" },
235
236 { "Headphone", NULL, "HPOUT1L" },
237 { "Headphone", NULL, "HPOUT1R" },
238
Mark Brownea3e98e2011-04-11 23:42:25 -0700239 { "Sub IN1", NULL, "HPOUT2L" },
240 { "Sub IN2", NULL, "HPOUT2R" },
241
242 { "Main Speaker", NULL, "Sub SPKN" },
243 { "Main Speaker", NULL, "Sub SPKP" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700244 { "Main Speaker", NULL, "SPKDAT" },
245};
246
Mark Brown9b8dc662011-04-12 17:24:39 -0700247static struct snd_soc_card speyside = {
248 .name = "Speyside",
249 .dai_link = speyside_dai,
250 .num_links = ARRAY_SIZE(speyside_dai),
Mark Brownea3e98e2011-04-11 23:42:25 -0700251 .aux_dev = speyside_aux_dev,
252 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
253 .codec_conf = speyside_codec_conf,
254 .num_configs = ARRAY_SIZE(speyside_codec_conf),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700255
Mark Brownea0a5912011-04-11 23:32:03 -0700256 .set_bias_level = speyside_set_bias_level,
257
Mark Brownea0e60d2011-04-12 00:09:53 -0700258 .controls = controls,
259 .num_controls = ARRAY_SIZE(controls),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700260 .dapm_widgets = widgets,
261 .num_dapm_widgets = ARRAY_SIZE(widgets),
262 .dapm_routes = audio_paths,
263 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Mark Brown9b8dc662011-04-12 17:24:39 -0700264};
265
266static __devinit int speyside_probe(struct platform_device *pdev)
267{
268 struct snd_soc_card *card = &speyside;
269 int ret;
270
271 card->dev = &pdev->dev;
272
273 ret = snd_soc_register_card(card);
274 if (ret) {
275 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
276 ret);
277 return ret;
278 }
279
280 return 0;
281}
282
283static int __devexit speyside_remove(struct platform_device *pdev)
284{
285 struct snd_soc_card *card = platform_get_drvdata(pdev);
286
287 snd_soc_unregister_card(card);
288
289 return 0;
290}
291
292static struct platform_driver speyside_driver = {
293 .driver = {
294 .name = "speyside",
295 .owner = THIS_MODULE,
296 .pm = &snd_soc_pm_ops,
297 },
298 .probe = speyside_probe,
299 .remove = __devexit_p(speyside_remove),
300};
301
302static int __init speyside_audio_init(void)
303{
304 return platform_driver_register(&speyside_driver);
305}
306module_init(speyside_audio_init);
307
308static void __exit speyside_audio_exit(void)
309{
310 platform_driver_unregister(&speyside_driver);
311}
312module_exit(speyside_audio_exit);
313
314MODULE_DESCRIPTION("Speyside audio support");
315MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
316MODULE_LICENSE("GPL");
317MODULE_ALIAS("platform:speyside");