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
22 #define MCLK_AUDIO_RATE (512 * 48000)
24 static int speyside_set_bias_level(struct snd_soc_card *card,
25 struct snd_soc_dapm_context *dapm,
26 enum snd_soc_bias_level level)
28 struct snd_soc_pcm_runtime *rtd;
29 struct snd_soc_dai *codec_dai;
32 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
33 codec_dai = rtd->codec_dai;
35 if (dapm->dev != codec_dai->dev)
39 case SND_SOC_BIAS_STANDBY:
40 ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2,
41 32768, SND_SOC_CLOCK_IN);
45 ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2,
48 pr_err("Failed to stop FLL\n");
60 static 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)
64 struct snd_soc_pcm_runtime *rtd;
65 struct snd_soc_dai *codec_dai;
68 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
69 codec_dai = rtd->codec_dai;
71 if (dapm->dev != codec_dai->dev)
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,
79 32768, MCLK_AUDIO_RATE);
81 pr_err("Failed to start FLL\n");
85 ret = snd_soc_dai_set_sysclk(codec_dai,
98 card->dapm.bias_level = level;
103 static struct snd_soc_jack speyside_headset;
105 /* Headset jack detection DAPM pins */
106 static struct snd_soc_jack_pin speyside_headset_pins[] = {
108 .pin = "Headset Mic",
109 .mask = SND_JACK_MICROPHONE,
113 /* Default the headphone selection to active high */
114 static int speyside_jack_polarity;
116 static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
117 struct snd_soc_dapm_widget *sink)
119 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
121 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
127 static void speyside_set_polarity(struct snd_soc_component *component,
130 speyside_jack_polarity = !polarity;
131 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
133 /* Re-run DAPM to make sure we're using the correct mic bias */
134 snd_soc_dapm_sync(snd_soc_component_get_dapm(component));
137 static int speyside_wm0010_init(struct snd_soc_pcm_runtime *rtd)
139 struct snd_soc_dai *dai = rtd->codec_dai;
142 ret = snd_soc_dai_set_sysclk(dai, 0, MCLK_AUDIO_RATE, 0);
149 static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
151 struct snd_soc_dai *dai = rtd->codec_dai;
152 struct snd_soc_component *component = dai->component;
155 ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0);
159 ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL");
161 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
162 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
164 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));
171 wm8996_detect(component, &speyside_headset, speyside_set_polarity);
176 static int speyside_late_probe(struct snd_soc_card *card)
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");
182 snd_soc_dapm_ignore_suspend(&card->dapm, "Main Speaker");
183 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
184 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
189 static const struct snd_soc_pcm_stream dsp_codec_params = {
190 .formats = SNDRV_PCM_FMTBIT_S32_LE,
197 static struct snd_soc_dai_link speyside_dai[] = {
200 .stream_name = "CPU-DSP",
201 .cpu_dai_name = "samsung-i2s.0",
202 .codec_dai_name = "wm0010-sdi1",
203 .platform_name = "samsung-i2s.0",
204 .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,
211 .stream_name = "DSP-CODEC",
212 .cpu_dai_name = "wm0010-sdi2",
213 .codec_dai_name = "wm8996-aif1",
214 .codec_name = "wm8996.1-001a",
215 .init = speyside_wm8996_init,
216 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
217 | SND_SOC_DAIFMT_CBM_CFM,
218 .params = &dsp_codec_params,
223 .stream_name = "Baseband",
224 .cpu_dai_name = "wm8996-aif2",
225 .codec_dai_name = "wm1250-ev1",
226 .codec_name = "wm1250-ev1.1-0027",
227 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
228 | SND_SOC_DAIFMT_CBM_CFM,
233 static int speyside_wm9081_init(struct snd_soc_component *component)
235 /* At any time the WM9081 is active it will have this clock */
236 return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
240 static struct snd_soc_aux_dev speyside_aux_dev[] = {
243 .codec_name = "wm9081.1-006c",
244 .init = speyside_wm9081_init,
248 static struct snd_soc_codec_conf speyside_codec_conf[] = {
250 .dev_name = "wm9081.1-006c",
251 .name_prefix = "Sub",
255 static 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"),
259 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
260 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
261 SOC_DAPM_PIN_SWITCH("Headphone"),
264 static struct snd_soc_dapm_widget widgets[] = {
265 SND_SOC_DAPM_HP("Headphone", NULL),
266 SND_SOC_DAPM_MIC("Headset Mic", NULL),
268 SND_SOC_DAPM_SPK("Main Speaker", NULL),
270 SND_SOC_DAPM_MIC("Main AMIC", NULL),
271 SND_SOC_DAPM_MIC("Main DMIC", NULL),
274 static struct snd_soc_dapm_route audio_paths[] = {
275 { "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 },
282 { "IN1LP", NULL, "MICB2" },
283 { "IN1RN", NULL, "MICB1" },
284 { "MICB2", NULL, "Main AMIC" },
286 { "DMIC1DAT", NULL, "MICB1" },
287 { "DMIC2DAT", NULL, "MICB1" },
288 { "MICB1", NULL, "Main DMIC" },
290 { "Headphone", NULL, "HPOUT1L" },
291 { "Headphone", NULL, "HPOUT1R" },
293 { "Sub IN1", NULL, "HPOUT2L" },
294 { "Sub IN2", NULL, "HPOUT2R" },
296 { "Main Speaker", NULL, "Sub SPKN" },
297 { "Main Speaker", NULL, "Sub SPKP" },
298 { "Main Speaker", NULL, "SPKDAT" },
301 static struct snd_soc_card speyside = {
303 .owner = THIS_MODULE,
304 .dai_link = speyside_dai,
305 .num_links = ARRAY_SIZE(speyside_dai),
306 .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),
311 .set_bias_level = speyside_set_bias_level,
312 .set_bias_level_post = speyside_set_bias_level_post,
314 .controls = controls,
315 .num_controls = ARRAY_SIZE(controls),
316 .dapm_widgets = widgets,
317 .num_dapm_widgets = ARRAY_SIZE(widgets),
318 .dapm_routes = audio_paths,
319 .num_dapm_routes = ARRAY_SIZE(audio_paths),
320 .fully_routed = true,
322 .late_probe = speyside_late_probe,
325 static int speyside_probe(struct platform_device *pdev)
327 struct snd_soc_card *card = &speyside;
330 card->dev = &pdev->dev;
332 ret = devm_snd_soc_register_card(&pdev->dev, card);
334 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
340 static struct platform_driver speyside_driver = {
343 .pm = &snd_soc_pm_ops,
345 .probe = speyside_probe,
348 module_platform_driver(speyside_driver);
350 MODULE_DESCRIPTION("Speyside audio support");
351 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
352 MODULE_LICENSE("GPL");
353 MODULE_ALIAS("platform:speyside");