blob: 4b4147d078047800883712eb37e458bdb6542ef1 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040016#include <linux/module.h>
Mark Brown9b8dc662011-04-12 17:24:39 -070017
Mark Browna9ba6152011-06-24 12:10:44 +010018#include "../codecs/wm8996.h"
Mark Brownea3e98e2011-04-11 23:42:25 -070019#include "../codecs/wm9081.h"
Mark Brown9b8dc662011-04-12 17:24:39 -070020
Mark Browna9ba6152011-06-24 12:10:44 +010021#define WM8996_HPSEL_GPIO 214
Mark Brown36281372011-12-11 11:31:22 +080022#define MCLK_AUDIO_RATE (512 * 48000)
Mark Brown68688e72011-04-12 00:00:36 -070023
Mark Brownea0a5912011-04-11 23:32:03 -070024static int speyside_set_bias_level(struct snd_soc_card *card,
Mark Brownd4c60052011-06-06 19:13:23 +010025 struct snd_soc_dapm_context *dapm,
Mark Brownea0a5912011-04-11 23:32:03 -070026 enum snd_soc_bias_level level)
27{
Mengdong Lin50159202015-11-18 02:34:01 -050028 struct snd_soc_pcm_runtime *rtd;
29 struct snd_soc_dai *codec_dai;
Mark Brownea0a5912011-04-11 23:32:03 -070030 int ret;
31
Mengdong Lin50159202015-11-18 02:34:01 -050032 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
33 codec_dai = rtd->codec_dai;
34
Mark Brownd4c60052011-06-06 19:13:23 +010035 if (dapm->dev != codec_dai->dev)
36 return 0;
37
Mark Brownea0a5912011-04-11 23:32:03 -070038 switch (level) {
39 case SND_SOC_BIAS_STANDBY:
Mark Browna9ba6152011-06-24 12:10:44 +010040 ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2,
Mark Brownea0a5912011-04-11 23:32:03 -070041 32768, SND_SOC_CLOCK_IN);
42 if (ret < 0)
43 return ret;
44
Mark Browna9ba6152011-06-24 12:10:44 +010045 ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2,
Mark Brownea0a5912011-04-11 23:32:03 -070046 0, 0, 0);
47 if (ret < 0) {
48 pr_err("Failed to stop FLL\n");
49 return ret;
50 }
Mark Brown85e9e762011-06-06 19:12:44 +010051 break;
Mark Brownea0a5912011-04-11 23:32:03 -070052
53 default:
54 break;
55 }
56
57 return 0;
58}
59
Mark Brown85e9e762011-06-06 19:12:44 +010060static int speyside_set_bias_level_post(struct snd_soc_card *card,
61 struct snd_soc_dapm_context *dapm,
62 enum snd_soc_bias_level level)
63{
Mengdong Lin50159202015-11-18 02:34:01 -050064 struct snd_soc_pcm_runtime *rtd;
65 struct snd_soc_dai *codec_dai;
Mark Brown85e9e762011-06-06 19:12:44 +010066 int ret;
67
Mengdong Lin50159202015-11-18 02:34:01 -050068 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
69 codec_dai = rtd->codec_dai;
70
Mark Brown85e9e762011-06-06 19:12:44 +010071 if (dapm->dev != codec_dai->dev)
72 return 0;
73
74 switch (level) {
75 case SND_SOC_BIAS_PREPARE:
76 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
77 ret = snd_soc_dai_set_pll(codec_dai, 0,
Mark Browna9ba6152011-06-24 12:10:44 +010078 WM8996_FLL_MCLK2,
Mark Brown36281372011-12-11 11:31:22 +080079 32768, MCLK_AUDIO_RATE);
Mark Brown85e9e762011-06-06 19:12:44 +010080 if (ret < 0) {
81 pr_err("Failed to start FLL\n");
82 return ret;
83 }
84
85 ret = snd_soc_dai_set_sysclk(codec_dai,
Mark Browna9ba6152011-06-24 12:10:44 +010086 WM8996_SYSCLK_FLL,
Mark Brown36281372011-12-11 11:31:22 +080087 MCLK_AUDIO_RATE,
Mark Brown85e9e762011-06-06 19:12:44 +010088 SND_SOC_CLOCK_IN);
89 if (ret < 0)
90 return ret;
91 }
92 break;
93
94 default:
95 break;
96 }
97
98 card->dapm.bias_level = level;
99
100 return 0;
101}
102
Mark Brown68688e72011-04-12 00:00:36 -0700103static struct snd_soc_jack speyside_headset;
104
105/* Headset jack detection DAPM pins */
106static struct snd_soc_jack_pin speyside_headset_pins[] = {
107 {
108 .pin = "Headset Mic",
109 .mask = SND_JACK_MICROPHONE,
110 },
Mark Brown68688e72011-04-12 00:00:36 -0700111};
112
113/* Default the headphone selection to active high */
114static int speyside_jack_polarity;
115
116static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
117 struct snd_soc_dapm_widget *sink)
118{
119 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
120 return 1;
121 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
122 return 1;
123
124 return 0;
125}
126
Kuninori Morimoto5d61ef82018-01-29 03:08:15 +0000127static void speyside_set_polarity(struct snd_soc_component *component,
Mark Brown68688e72011-04-12 00:00:36 -0700128 int polarity)
129{
130 speyside_jack_polarity = !polarity;
Mark Browna9ba6152011-06-24 12:10:44 +0100131 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
Mark Brown68688e72011-04-12 00:00:36 -0700132
133 /* Re-run DAPM to make sure we're using the correct mic bias */
Kuninori Morimoto5d61ef82018-01-29 03:08:15 +0000134 snd_soc_dapm_sync(snd_soc_component_get_dapm(component));
Mark Brown68688e72011-04-12 00:00:36 -0700135}
136
Mark Brownf9372c92012-08-23 17:05:48 +0100137static int speyside_wm0010_init(struct snd_soc_pcm_runtime *rtd)
138{
139 struct snd_soc_dai *dai = rtd->codec_dai;
140 int ret;
141
142 ret = snd_soc_dai_set_sysclk(dai, 0, MCLK_AUDIO_RATE, 0);
143 if (ret < 0)
144 return ret;
145
146 return 0;
147}
148
Mark Browna9ba6152011-06-24 12:10:44 +0100149static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
Mark Brownea0a5912011-04-11 23:32:03 -0700150{
151 struct snd_soc_dai *dai = rtd->codec_dai;
Kuninori Morimoto5d61ef82018-01-29 03:08:15 +0000152 struct snd_soc_component *component = dai->component;
Mark Brown68688e72011-04-12 00:00:36 -0700153 int ret;
Mark Brownea0a5912011-04-11 23:32:03 -0700154
Mark Browna9ba6152011-06-24 12:10:44 +0100155 ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0);
Mark Brown68688e72011-04-12 00:00:36 -0700156 if (ret < 0)
157 return ret;
158
Mark Browna9ba6152011-06-24 12:10:44 +0100159 ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL");
Mark Brown68688e72011-04-12 00:00:36 -0700160 if (ret != 0)
161 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
Mark Browna9ba6152011-06-24 12:10:44 +0100162 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
Mark Brown68688e72011-04-12 00:00:36 -0700163
Lars-Peter Clausen663976a2015-03-04 10:33:38 +0100164 ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
165 SND_JACK_HEADSET | SND_JACK_BTN_0,
166 &speyside_headset, speyside_headset_pins,
167 ARRAY_SIZE(speyside_headset_pins));
Mark Brown68688e72011-04-12 00:00:36 -0700168 if (ret)
169 return ret;
170
Kuninori Morimoto5d61ef82018-01-29 03:08:15 +0000171 wm8996_detect(component, &speyside_headset, speyside_set_polarity);
Mark Brown68688e72011-04-12 00:00:36 -0700172
173 return 0;
Mark Brownea0a5912011-04-11 23:32:03 -0700174}
175
Mark Brownb7a5d142011-04-12 17:37:52 -0700176static int speyside_late_probe(struct snd_soc_card *card)
177{
178 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
179 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
180 snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
181 snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
Mark Brown5b895ee2011-11-27 15:54:49 +0000182 snd_soc_dapm_ignore_suspend(&card->dapm, "Main Speaker");
Mark Brownb7a5d142011-04-12 17:37:52 -0700183 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
184 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
185
186 return 0;
187}
188
Mark Brownf9372c92012-08-23 17:05:48 +0100189static const struct snd_soc_pcm_stream dsp_codec_params = {
190 .formats = SNDRV_PCM_FMTBIT_S32_LE,
191 .rate_min = 48000,
192 .rate_max = 48000,
193 .channels_min = 2,
194 .channels_max = 2,
195};
196
Mark Brown9b8dc662011-04-12 17:24:39 -0700197static struct snd_soc_dai_link speyside_dai[] = {
198 {
Mark Brownf9372c92012-08-23 17:05:48 +0100199 .name = "CPU-DSP",
200 .stream_name = "CPU-DSP",
Mark Brown9b8dc662011-04-12 17:24:39 -0700201 .cpu_dai_name = "samsung-i2s.0",
Mark Brownf9372c92012-08-23 17:05:48 +0100202 .codec_dai_name = "wm0010-sdi1",
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530203 .platform_name = "samsung-i2s.0",
Mark Brownf9372c92012-08-23 17:05:48 +0100204 .codec_name = "spi0.0",
205 .init = speyside_wm0010_init,
206 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
207 | SND_SOC_DAIFMT_CBM_CFM,
208 },
209 {
210 .name = "DSP-CODEC",
211 .stream_name = "DSP-CODEC",
212 .cpu_dai_name = "wm0010-sdi2",
213 .codec_dai_name = "wm8996-aif1",
Mark Browna9ba6152011-06-24 12:10:44 +0100214 .codec_name = "wm8996.1-001a",
215 .init = speyside_wm8996_init,
Mark Brown26e67812011-09-27 16:48:49 +0100216 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
217 | SND_SOC_DAIFMT_CBM_CFM,
Mark Brownf9372c92012-08-23 17:05:48 +0100218 .params = &dsp_codec_params,
219 .ignore_suspend = 1,
Mark Brown9b8dc662011-04-12 17:24:39 -0700220 },
Mark Brown556e4fb2011-04-12 14:15:10 -0700221 {
222 .name = "Baseband",
223 .stream_name = "Baseband",
Mark Browna9ba6152011-06-24 12:10:44 +0100224 .cpu_dai_name = "wm8996-aif2",
Mark Brown556e4fb2011-04-12 14:15:10 -0700225 .codec_dai_name = "wm1250-ev1",
226 .codec_name = "wm1250-ev1.1-0027",
Mark Brown26e67812011-09-27 16:48:49 +0100227 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
228 | SND_SOC_DAIFMT_CBM_CFM,
Mark Brownb7a5d142011-04-12 17:37:52 -0700229 .ignore_suspend = 1,
Mark Brown556e4fb2011-04-12 14:15:10 -0700230 },
Mark Brown9b8dc662011-04-12 17:24:39 -0700231};
232
Lars-Peter Clausen57bf7722014-08-19 15:51:23 +0200233static int speyside_wm9081_init(struct snd_soc_component *component)
Mark Brownea3e98e2011-04-11 23:42:25 -0700234{
Mark Brownea3e98e2011-04-11 23:42:25 -0700235 /* At any time the WM9081 is active it will have this clock */
Kuninori Morimoto5d61ef82018-01-29 03:08:15 +0000236 return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
Mark Brown36281372011-12-11 11:31:22 +0800237 MCLK_AUDIO_RATE, 0);
Mark Brownea3e98e2011-04-11 23:42:25 -0700238}
239
240static struct snd_soc_aux_dev speyside_aux_dev[] = {
241 {
242 .name = "wm9081",
243 .codec_name = "wm9081.1-006c",
244 .init = speyside_wm9081_init,
245 },
246};
247
248static struct snd_soc_codec_conf speyside_codec_conf[] = {
249 {
250 .dev_name = "wm9081.1-006c",
251 .name_prefix = "Sub",
252 },
253};
254
Mark Brownea0e60d2011-04-12 00:09:53 -0700255static const struct snd_kcontrol_new controls[] = {
256 SOC_DAPM_PIN_SWITCH("Main Speaker"),
257 SOC_DAPM_PIN_SWITCH("Main DMIC"),
258 SOC_DAPM_PIN_SWITCH("Main AMIC"),
Mark Brown556e4fb2011-04-12 14:15:10 -0700259 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
260 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
Mark Brown68d5a592011-08-04 18:13:45 +0900261 SOC_DAPM_PIN_SWITCH("Headphone"),
Mark Brownea0e60d2011-04-12 00:09:53 -0700262};
263
Mark Brownecfb1ad2011-04-11 23:09:15 -0700264static struct snd_soc_dapm_widget widgets[] = {
265 SND_SOC_DAPM_HP("Headphone", NULL),
Mark Brown68688e72011-04-12 00:00:36 -0700266 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700267
268 SND_SOC_DAPM_SPK("Main Speaker", NULL),
269
270 SND_SOC_DAPM_MIC("Main AMIC", NULL),
271 SND_SOC_DAPM_MIC("Main DMIC", NULL),
272};
273
274static struct snd_soc_dapm_route audio_paths[] = {
Mark Brown68688e72011-04-12 00:00:36 -0700275 { "IN1RN", NULL, "MICB1" },
276 { "IN1RP", NULL, "MICB1" },
277 { "IN1RN", NULL, "MICB2" },
278 { "IN1RP", NULL, "MICB2" },
279 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
280 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
281
Mark Brownecfb1ad2011-04-11 23:09:15 -0700282 { "IN1LP", NULL, "MICB2" },
Mark Brown68688e72011-04-12 00:00:36 -0700283 { "IN1RN", NULL, "MICB1" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700284 { "MICB2", NULL, "Main AMIC" },
285
286 { "DMIC1DAT", NULL, "MICB1" },
287 { "DMIC2DAT", NULL, "MICB1" },
288 { "MICB1", NULL, "Main DMIC" },
289
290 { "Headphone", NULL, "HPOUT1L" },
291 { "Headphone", NULL, "HPOUT1R" },
292
Mark Brownea3e98e2011-04-11 23:42:25 -0700293 { "Sub IN1", NULL, "HPOUT2L" },
294 { "Sub IN2", NULL, "HPOUT2R" },
295
296 { "Main Speaker", NULL, "Sub SPKN" },
297 { "Main Speaker", NULL, "Sub SPKP" },
Mark Brownecfb1ad2011-04-11 23:09:15 -0700298 { "Main Speaker", NULL, "SPKDAT" },
299};
300
Mark Brown9b8dc662011-04-12 17:24:39 -0700301static struct snd_soc_card speyside = {
302 .name = "Speyside",
Axel Lin095d79d2011-12-22 10:53:15 +0800303 .owner = THIS_MODULE,
Mark Brown9b8dc662011-04-12 17:24:39 -0700304 .dai_link = speyside_dai,
305 .num_links = ARRAY_SIZE(speyside_dai),
Mark Brownea3e98e2011-04-11 23:42:25 -0700306 .aux_dev = speyside_aux_dev,
307 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
308 .codec_conf = speyside_codec_conf,
309 .num_configs = ARRAY_SIZE(speyside_codec_conf),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700310
Mark Brownea0a5912011-04-11 23:32:03 -0700311 .set_bias_level = speyside_set_bias_level,
Mark Brown995e54f2011-06-08 16:11:18 +0100312 .set_bias_level_post = speyside_set_bias_level_post,
Mark Brownea0a5912011-04-11 23:32:03 -0700313
Mark Brownea0e60d2011-04-12 00:09:53 -0700314 .controls = controls,
315 .num_controls = ARRAY_SIZE(controls),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700316 .dapm_widgets = widgets,
317 .num_dapm_widgets = ARRAY_SIZE(widgets),
318 .dapm_routes = audio_paths,
319 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Mark Brown39afd662011-11-23 21:33:07 +0000320 .fully_routed = true,
Mark Brownb7a5d142011-04-12 17:37:52 -0700321
322 .late_probe = speyside_late_probe,
Mark Brown9b8dc662011-04-12 17:24:39 -0700323};
324
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500325static int speyside_probe(struct platform_device *pdev)
Mark Brown9b8dc662011-04-12 17:24:39 -0700326{
327 struct snd_soc_card *card = &speyside;
328 int ret;
329
330 card->dev = &pdev->dev;
331
Tushar Beherac5838832014-05-21 08:52:17 +0530332 ret = devm_snd_soc_register_card(&pdev->dev, card);
333 if (ret)
Mark Brown9b8dc662011-04-12 17:24:39 -0700334 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
335 ret);
Mark Brown9b8dc662011-04-12 17:24:39 -0700336
Tushar Beherac5838832014-05-21 08:52:17 +0530337 return ret;
Mark Brown9b8dc662011-04-12 17:24:39 -0700338}
339
340static struct platform_driver speyside_driver = {
341 .driver = {
342 .name = "speyside",
Mark Brown9b8dc662011-04-12 17:24:39 -0700343 .pm = &snd_soc_pm_ops,
344 },
345 .probe = speyside_probe,
Mark Brown9b8dc662011-04-12 17:24:39 -0700346};
347
Mark Browne00c3f52011-11-23 15:20:13 +0000348module_platform_driver(speyside_driver);
Mark Brown9b8dc662011-04-12 17:24:39 -0700349
350MODULE_DESCRIPTION("Speyside audio support");
351MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
352MODULE_LICENSE("GPL");
353MODULE_ALIAS("platform:speyside");