ASoC: Add context parameter to card DAPM callbacks
[deliverable/linux.git] / sound / soc / samsung / speyside.c
CommitLineData
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>
9b8dc66f
MB
16
17#include "../codecs/wm8915.h"
ea3e98e7 18#include "../codecs/wm9081.h"
9b8dc66f 19
68688e78
MB
20#define WM8915_HPSEL_GPIO 214
21
ea0a591a 22static int speyside_set_bias_level(struct snd_soc_card *card,
d4c6005f 23 struct snd_soc_dapm_context *dapm,
ea0a591a
MB
24 enum snd_soc_bias_level level)
25{
26 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
27 int ret;
28
d4c6005f
MB
29 if (dapm->dev != codec_dai->dev)
30 return 0;
31
ea0a591a
MB
32 switch (level) {
33 case SND_SOC_BIAS_STANDBY:
1e025a36 34 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK2,
ea0a591a
MB
35 32768, SND_SOC_CLOCK_IN);
36 if (ret < 0)
37 return ret;
38
1e025a36 39 ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK2,
ea0a591a
MB
40 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
9b8dc66f
MB
53static 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
1e025a36 73 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK2,
9b8dc66f
MB
74 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
68688e78
MB
90static 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
ea0a591a
MB
128static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
129{
130 struct snd_soc_dai *dai = rtd->codec_dai;
68688e78
MB
131 struct snd_soc_codec *codec = rtd->codec;
132 int ret;
133
1e025a36 134 ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK2, 32768, 0);
68688e78
MB
135 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);
ea0a591a 142
68688e78
MB
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;
ea0a591a
MB
158}
159
b7a5d14c
MB
160static 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
9b8dc66f
MB
173static 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",
ea0a591a 181 .init = speyside_wm8915_init,
9b8dc66f
MB
182 .ops = &speyside_ops,
183 },
556e4fb1
MB
184 {
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",
556e4fb1 190 .ops = &speyside_ops,
b7a5d14c 191 .ignore_suspend = 1,
556e4fb1 192 },
9b8dc66f
MB
193};
194
ea3e98e7
MB
195static 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
ea0e60de
MB
219static 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"),
556e4fb1
MB
223 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
224 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
ea0e60de
MB
225};
226
ecfb1adf
MB
227static struct snd_soc_dapm_widget widgets[] = {
228 SND_SOC_DAPM_HP("Headphone", NULL),
68688e78 229 SND_SOC_DAPM_MIC("Headset Mic", NULL),
ecfb1adf
MB
230
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[] = {
68688e78
MB
238 { "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
ecfb1adf 245 { "IN1LP", NULL, "MICB2" },
68688e78 246 { "IN1RN", NULL, "MICB1" },
ecfb1adf
MB
247 { "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
ea3e98e7
MB
256 { "Sub IN1", NULL, "HPOUT2L" },
257 { "Sub IN2", NULL, "HPOUT2R" },
258
259 { "Main Speaker", NULL, "Sub SPKN" },
260 { "Main Speaker", NULL, "Sub SPKP" },
ecfb1adf
MB
261 { "Main Speaker", NULL, "SPKDAT" },
262};
263
9b8dc66f
MB
264static struct snd_soc_card speyside = {
265 .name = "Speyside",
266 .dai_link = speyside_dai,
267 .num_links = ARRAY_SIZE(speyside_dai),
ea3e98e7
MB
268 .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),
ecfb1adf 272
ea0a591a
MB
273 .set_bias_level = speyside_set_bias_level,
274
ea0e60de
MB
275 .controls = controls,
276 .num_controls = ARRAY_SIZE(controls),
ecfb1adf
MB
277 .dapm_widgets = widgets,
278 .num_dapm_widgets = ARRAY_SIZE(widgets),
279 .dapm_routes = audio_paths,
280 .num_dapm_routes = ARRAY_SIZE(audio_paths),
b7a5d14c
MB
281
282 .late_probe = speyside_late_probe,
9b8dc66f
MB
283};
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");
This page took 0.042015 seconds and 5 git commands to generate.