I2C: Add helper macro for i2c_driver boilerplate
[zen-stable.git] / sound / soc / samsung / speyside.c
blob85bf541a771d05226b761d6d274e7affd8cba6e2
1 /*
2 * Speyside audio support
4 * Copyright 2011 Wolfson Microelectronics
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.
12 #include <sound/soc.h>
13 #include <sound/soc-dapm.h>
14 #include <sound/jack.h>
15 #include <linux/gpio.h>
16 #include <linux/module.h>
18 #include "../codecs/wm8996.h"
19 #include "../codecs/wm9081.h"
21 #define WM8996_HPSEL_GPIO 214
23 static int speyside_set_bias_level(struct snd_soc_card *card,
24 struct snd_soc_dapm_context *dapm,
25 enum snd_soc_bias_level level)
27 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
28 int ret;
30 if (dapm->dev != codec_dai->dev)
31 return 0;
33 switch (level) {
34 case SND_SOC_BIAS_STANDBY:
35 ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2,
36 32768, SND_SOC_CLOCK_IN);
37 if (ret < 0)
38 return ret;
40 ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2,
41 0, 0, 0);
42 if (ret < 0) {
43 pr_err("Failed to stop FLL\n");
44 return ret;
46 break;
48 default:
49 break;
52 return 0;
55 static int speyside_set_bias_level_post(struct snd_soc_card *card,
56 struct snd_soc_dapm_context *dapm,
57 enum snd_soc_bias_level level)
59 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
60 int ret;
62 if (dapm->dev != codec_dai->dev)
63 return 0;
65 switch (level) {
66 case SND_SOC_BIAS_PREPARE:
67 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
68 ret = snd_soc_dai_set_pll(codec_dai, 0,
69 WM8996_FLL_MCLK2,
70 32768, 48000 * 256);
71 if (ret < 0) {
72 pr_err("Failed to start FLL\n");
73 return ret;
76 ret = snd_soc_dai_set_sysclk(codec_dai,
77 WM8996_SYSCLK_FLL,
78 48000 * 256,
79 SND_SOC_CLOCK_IN);
80 if (ret < 0)
81 return ret;
83 break;
85 default:
86 break;
89 card->dapm.bias_level = level;
91 return 0;
94 static int speyside_hw_params(struct snd_pcm_substream *substream,
95 struct snd_pcm_hw_params *params)
97 struct snd_soc_pcm_runtime *rtd = substream->private_data;
98 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
99 struct snd_soc_dai *codec_dai = rtd->codec_dai;
100 int ret;
102 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
103 | SND_SOC_DAIFMT_NB_NF
104 | SND_SOC_DAIFMT_CBM_CFM);
105 if (ret < 0)
106 return ret;
108 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
109 | SND_SOC_DAIFMT_NB_NF
110 | SND_SOC_DAIFMT_CBM_CFM);
111 if (ret < 0)
112 return ret;
114 return 0;
117 static struct snd_soc_ops speyside_ops = {
118 .hw_params = speyside_hw_params,
121 static struct snd_soc_jack speyside_headset;
123 /* Headset jack detection DAPM pins */
124 static struct snd_soc_jack_pin speyside_headset_pins[] = {
126 .pin = "Headset Mic",
127 .mask = SND_JACK_MICROPHONE,
131 /* Default the headphone selection to active high */
132 static int speyside_jack_polarity;
134 static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
135 struct snd_soc_dapm_widget *sink)
137 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
138 return 1;
139 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
140 return 1;
142 return 0;
145 static void speyside_set_polarity(struct snd_soc_codec *codec,
146 int polarity)
148 speyside_jack_polarity = !polarity;
149 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
151 /* Re-run DAPM to make sure we're using the correct mic bias */
152 snd_soc_dapm_sync(&codec->dapm);
155 static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
157 struct snd_soc_dai *dai = rtd->codec_dai;
158 struct snd_soc_codec *codec = rtd->codec;
159 int ret;
161 ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0);
162 if (ret < 0)
163 return ret;
165 ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL");
166 if (ret != 0)
167 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
168 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
170 ret = snd_soc_jack_new(codec, "Headset",
171 SND_JACK_LINEOUT | SND_JACK_HEADSET |
172 SND_JACK_BTN_0,
173 &speyside_headset);
174 if (ret)
175 return ret;
177 ret = snd_soc_jack_add_pins(&speyside_headset,
178 ARRAY_SIZE(speyside_headset_pins),
179 speyside_headset_pins);
180 if (ret)
181 return ret;
183 wm8996_detect(codec, &speyside_headset, speyside_set_polarity);
185 return 0;
188 static int speyside_late_probe(struct snd_soc_card *card)
190 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
191 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
192 snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
193 snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
194 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
195 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
196 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
198 return 0;
201 static struct snd_soc_dai_link speyside_dai[] = {
203 .name = "CPU",
204 .stream_name = "CPU",
205 .cpu_dai_name = "samsung-i2s.0",
206 .codec_dai_name = "wm8996-aif1",
207 .platform_name = "samsung-audio",
208 .codec_name = "wm8996.1-001a",
209 .init = speyside_wm8996_init,
210 .ops = &speyside_ops,
213 .name = "Baseband",
214 .stream_name = "Baseband",
215 .cpu_dai_name = "wm8996-aif2",
216 .codec_dai_name = "wm1250-ev1",
217 .codec_name = "wm1250-ev1.1-0027",
218 .ops = &speyside_ops,
219 .ignore_suspend = 1,
223 static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
225 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
227 /* At any time the WM9081 is active it will have this clock */
228 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
229 48000 * 256, 0);
232 static struct snd_soc_aux_dev speyside_aux_dev[] = {
234 .name = "wm9081",
235 .codec_name = "wm9081.1-006c",
236 .init = speyside_wm9081_init,
240 static struct snd_soc_codec_conf speyside_codec_conf[] = {
242 .dev_name = "wm9081.1-006c",
243 .name_prefix = "Sub",
247 static const struct snd_kcontrol_new controls[] = {
248 SOC_DAPM_PIN_SWITCH("Main Speaker"),
249 SOC_DAPM_PIN_SWITCH("Main DMIC"),
250 SOC_DAPM_PIN_SWITCH("Main AMIC"),
251 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
252 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
253 SOC_DAPM_PIN_SWITCH("Headphone"),
256 static struct snd_soc_dapm_widget widgets[] = {
257 SND_SOC_DAPM_HP("Headphone", NULL),
258 SND_SOC_DAPM_MIC("Headset Mic", NULL),
260 SND_SOC_DAPM_SPK("Main Speaker", NULL),
262 SND_SOC_DAPM_MIC("Main AMIC", NULL),
263 SND_SOC_DAPM_MIC("Main DMIC", NULL),
266 static struct snd_soc_dapm_route audio_paths[] = {
267 { "IN1RN", NULL, "MICB1" },
268 { "IN1RP", NULL, "MICB1" },
269 { "IN1RN", NULL, "MICB2" },
270 { "IN1RP", NULL, "MICB2" },
271 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
272 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
274 { "IN1LP", NULL, "MICB2" },
275 { "IN1RN", NULL, "MICB1" },
276 { "MICB2", NULL, "Main AMIC" },
278 { "DMIC1DAT", NULL, "MICB1" },
279 { "DMIC2DAT", NULL, "MICB1" },
280 { "MICB1", NULL, "Main DMIC" },
282 { "Headphone", NULL, "HPOUT1L" },
283 { "Headphone", NULL, "HPOUT1R" },
285 { "Sub IN1", NULL, "HPOUT2L" },
286 { "Sub IN2", NULL, "HPOUT2R" },
288 { "Main Speaker", NULL, "Sub SPKN" },
289 { "Main Speaker", NULL, "Sub SPKP" },
290 { "Main Speaker", NULL, "SPKDAT" },
293 static struct snd_soc_card speyside = {
294 .name = "Speyside",
295 .dai_link = speyside_dai,
296 .num_links = ARRAY_SIZE(speyside_dai),
297 .aux_dev = speyside_aux_dev,
298 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
299 .codec_conf = speyside_codec_conf,
300 .num_configs = ARRAY_SIZE(speyside_codec_conf),
302 .set_bias_level = speyside_set_bias_level,
303 .set_bias_level_post = speyside_set_bias_level_post,
305 .controls = controls,
306 .num_controls = ARRAY_SIZE(controls),
307 .dapm_widgets = widgets,
308 .num_dapm_widgets = ARRAY_SIZE(widgets),
309 .dapm_routes = audio_paths,
310 .num_dapm_routes = ARRAY_SIZE(audio_paths),
312 .late_probe = speyside_late_probe,
315 static __devinit int speyside_probe(struct platform_device *pdev)
317 struct snd_soc_card *card = &speyside;
318 int ret;
320 card->dev = &pdev->dev;
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;
329 return 0;
332 static int __devexit speyside_remove(struct platform_device *pdev)
334 struct snd_soc_card *card = platform_get_drvdata(pdev);
336 snd_soc_unregister_card(card);
338 return 0;
341 static struct platform_driver speyside_driver = {
342 .driver = {
343 .name = "speyside",
344 .owner = THIS_MODULE,
345 .pm = &snd_soc_pm_ops,
347 .probe = speyside_probe,
348 .remove = __devexit_p(speyside_remove),
351 static int __init speyside_audio_init(void)
353 return platform_driver_register(&speyside_driver);
355 module_init(speyside_audio_init);
357 static void __exit speyside_audio_exit(void)
359 platform_driver_unregister(&speyside_driver);
361 module_exit(speyside_audio_exit);
363 MODULE_DESCRIPTION("Speyside audio support");
364 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
365 MODULE_LICENSE("GPL");
366 MODULE_ALIAS("platform:speyside");