]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/soc/samsung/speyside.c
sound: Add module.h to the previously silent sound users
[mirror_ubuntu-bionic-kernel.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>
da155d5b 16#include <linux/module.h>
9b8dc66f 17
a9ba6151 18#include "../codecs/wm8996.h"
ea3e98e7 19#include "../codecs/wm9081.h"
9b8dc66f 20
a9ba6151 21#define WM8996_HPSEL_GPIO 214
68688e78 22
ea0a591a 23static int speyside_set_bias_level(struct snd_soc_card *card,
d4c6005f 24 struct snd_soc_dapm_context *dapm,
ea0a591a
MB
25 enum snd_soc_bias_level level)
26{
27 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
28 int ret;
29
d4c6005f
MB
30 if (dapm->dev != codec_dai->dev)
31 return 0;
32
ea0a591a
MB
33 switch (level) {
34 case SND_SOC_BIAS_STANDBY:
a9ba6151 35 ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2,
ea0a591a
MB
36 32768, SND_SOC_CLOCK_IN);
37 if (ret < 0)
38 return ret;
39
a9ba6151 40 ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2,
ea0a591a
MB
41 0, 0, 0);
42 if (ret < 0) {
43 pr_err("Failed to stop FLL\n");
44 return ret;
45 }
85e9e766
MB
46 break;
47
48 default:
49 break;
50 }
51
52 return 0;
53}
54
55static 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)
58{
59 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
60 int ret;
61
62 if (dapm->dev != codec_dai->dev)
63 return 0;
64
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,
a9ba6151 69 WM8996_FLL_MCLK2,
85e9e766
MB
70 32768, 48000 * 256);
71 if (ret < 0) {
72 pr_err("Failed to start FLL\n");
73 return ret;
74 }
75
76 ret = snd_soc_dai_set_sysclk(codec_dai,
a9ba6151 77 WM8996_SYSCLK_FLL,
85e9e766
MB
78 48000 * 256,
79 SND_SOC_CLOCK_IN);
80 if (ret < 0)
81 return ret;
82 }
83 break;
ea0a591a
MB
84
85 default:
86 break;
87 }
88
85e9e766
MB
89 card->dapm.bias_level = level;
90
ea0a591a
MB
91 return 0;
92}
93
9b8dc66f
MB
94static int speyside_hw_params(struct snd_pcm_substream *substream,
95 struct snd_pcm_hw_params *params)
96{
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;
101
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;
107
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;
113
9b8dc66f
MB
114 return 0;
115}
116
117static struct snd_soc_ops speyside_ops = {
118 .hw_params = speyside_hw_params,
119};
120
68688e78
MB
121static struct snd_soc_jack speyside_headset;
122
123/* Headset jack detection DAPM pins */
124static struct snd_soc_jack_pin speyside_headset_pins[] = {
125 {
126 .pin = "Headset Mic",
127 .mask = SND_JACK_MICROPHONE,
128 },
68688e78
MB
129};
130
131/* Default the headphone selection to active high */
132static int speyside_jack_polarity;
133
134static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
135 struct snd_soc_dapm_widget *sink)
136{
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;
141
142 return 0;
143}
144
145static void speyside_set_polarity(struct snd_soc_codec *codec,
146 int polarity)
147{
148 speyside_jack_polarity = !polarity;
a9ba6151 149 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
68688e78
MB
150
151 /* Re-run DAPM to make sure we're using the correct mic bias */
152 snd_soc_dapm_sync(&codec->dapm);
153}
154
a9ba6151 155static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
ea0a591a
MB
156{
157 struct snd_soc_dai *dai = rtd->codec_dai;
68688e78
MB
158 struct snd_soc_codec *codec = rtd->codec;
159 int ret;
160
a9ba6151 161 ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0);
68688e78
MB
162 if (ret < 0)
163 return ret;
164
a9ba6151 165 ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL");
68688e78
MB
166 if (ret != 0)
167 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
a9ba6151 168 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
ea0a591a 169
68688e78 170 ret = snd_soc_jack_new(codec, "Headset",
45cf367e
MB
171 SND_JACK_LINEOUT | SND_JACK_HEADSET |
172 SND_JACK_BTN_0,
68688e78
MB
173 &speyside_headset);
174 if (ret)
175 return ret;
176
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;
182
a9ba6151 183 wm8996_detect(codec, &speyside_headset, speyside_set_polarity);
68688e78
MB
184
185 return 0;
ea0a591a
MB
186}
187
b7a5d14c
MB
188static int speyside_late_probe(struct snd_soc_card *card)
189{
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");
197
198 return 0;
199}
200
9b8dc66f
MB
201static struct snd_soc_dai_link speyside_dai[] = {
202 {
203 .name = "CPU",
204 .stream_name = "CPU",
205 .cpu_dai_name = "samsung-i2s.0",
a9ba6151 206 .codec_dai_name = "wm8996-aif1",
9b8dc66f 207 .platform_name = "samsung-audio",
a9ba6151
MB
208 .codec_name = "wm8996.1-001a",
209 .init = speyside_wm8996_init,
9b8dc66f
MB
210 .ops = &speyside_ops,
211 },
556e4fb1
MB
212 {
213 .name = "Baseband",
214 .stream_name = "Baseband",
a9ba6151 215 .cpu_dai_name = "wm8996-aif2",
556e4fb1
MB
216 .codec_dai_name = "wm1250-ev1",
217 .codec_name = "wm1250-ev1.1-0027",
556e4fb1 218 .ops = &speyside_ops,
b7a5d14c 219 .ignore_suspend = 1,
556e4fb1 220 },
9b8dc66f
MB
221};
222
ea3e98e7
MB
223static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
224{
225 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
226
227 /* At any time the WM9081 is active it will have this clock */
da1c6ea6 228 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
ea3e98e7
MB
229 48000 * 256, 0);
230}
231
232static struct snd_soc_aux_dev speyside_aux_dev[] = {
233 {
234 .name = "wm9081",
235 .codec_name = "wm9081.1-006c",
236 .init = speyside_wm9081_init,
237 },
238};
239
240static struct snd_soc_codec_conf speyside_codec_conf[] = {
241 {
242 .dev_name = "wm9081.1-006c",
243 .name_prefix = "Sub",
244 },
245};
246
ea0e60de
MB
247static 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"),
556e4fb1
MB
251 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
252 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
68d5a59e 253 SOC_DAPM_PIN_SWITCH("Headphone"),
ea0e60de
MB
254};
255
ecfb1adf
MB
256static struct snd_soc_dapm_widget widgets[] = {
257 SND_SOC_DAPM_HP("Headphone", NULL),
68688e78 258 SND_SOC_DAPM_MIC("Headset Mic", NULL),
ecfb1adf
MB
259
260 SND_SOC_DAPM_SPK("Main Speaker", NULL),
261
262 SND_SOC_DAPM_MIC("Main AMIC", NULL),
263 SND_SOC_DAPM_MIC("Main DMIC", NULL),
264};
265
266static struct snd_soc_dapm_route audio_paths[] = {
68688e78
MB
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 },
273
ecfb1adf 274 { "IN1LP", NULL, "MICB2" },
68688e78 275 { "IN1RN", NULL, "MICB1" },
ecfb1adf
MB
276 { "MICB2", NULL, "Main AMIC" },
277
278 { "DMIC1DAT", NULL, "MICB1" },
279 { "DMIC2DAT", NULL, "MICB1" },
280 { "MICB1", NULL, "Main DMIC" },
281
282 { "Headphone", NULL, "HPOUT1L" },
283 { "Headphone", NULL, "HPOUT1R" },
284
ea3e98e7
MB
285 { "Sub IN1", NULL, "HPOUT2L" },
286 { "Sub IN2", NULL, "HPOUT2R" },
287
288 { "Main Speaker", NULL, "Sub SPKN" },
289 { "Main Speaker", NULL, "Sub SPKP" },
ecfb1adf
MB
290 { "Main Speaker", NULL, "SPKDAT" },
291};
292
9b8dc66f
MB
293static struct snd_soc_card speyside = {
294 .name = "Speyside",
295 .dai_link = speyside_dai,
296 .num_links = ARRAY_SIZE(speyside_dai),
ea3e98e7
MB
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),
ecfb1adf 301
ea0a591a 302 .set_bias_level = speyside_set_bias_level,
995e54f5 303 .set_bias_level_post = speyside_set_bias_level_post,
ea0a591a 304
ea0e60de
MB
305 .controls = controls,
306 .num_controls = ARRAY_SIZE(controls),
ecfb1adf
MB
307 .dapm_widgets = widgets,
308 .num_dapm_widgets = ARRAY_SIZE(widgets),
309 .dapm_routes = audio_paths,
310 .num_dapm_routes = ARRAY_SIZE(audio_paths),
b7a5d14c
MB
311
312 .late_probe = speyside_late_probe,
9b8dc66f
MB
313};
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");