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>
17 #include "../codecs/wm8915.h"
18 #include "../codecs/wm9081.h"
20 #define WM8915_HPSEL_GPIO 214
22 static int speyside_set_bias_level(struct snd_soc_card *card,
23 enum snd_soc_bias_level level)
25 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
29 case SND_SOC_BIAS_STANDBY:
30 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
31 32768, SND_SOC_CLOCK_IN);
35 ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
38 pr_err("Failed to stop FLL\n");
49 static int speyside_hw_params(struct snd_pcm_substream *substream,
50 struct snd_pcm_hw_params *params)
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
54 struct snd_soc_dai *codec_dai = rtd->codec_dai;
57 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
58 | SND_SOC_DAIFMT_NB_NF
59 | SND_SOC_DAIFMT_CBM_CFM);
63 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
64 | SND_SOC_DAIFMT_NB_NF
65 | SND_SOC_DAIFMT_CBM_CFM);
69 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
74 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
75 256 * 48000, SND_SOC_CLOCK_IN);
82 static struct snd_soc_ops speyside_ops = {
83 .hw_params = speyside_hw_params,
86 static struct snd_soc_jack speyside_headset;
88 /* Headset jack detection DAPM pins */
89 static struct snd_soc_jack_pin speyside_headset_pins[] = {
92 .mask = SND_JACK_MICROPHONE,
96 .mask = SND_JACK_HEADPHONE,
100 /* Default the headphone selection to active high */
101 static int speyside_jack_polarity;
103 static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
104 struct snd_soc_dapm_widget *sink)
106 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
108 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
114 static void speyside_set_polarity(struct snd_soc_codec *codec,
117 speyside_jack_polarity = !polarity;
118 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
120 /* Re-run DAPM to make sure we're using the correct mic bias */
121 snd_soc_dapm_sync(&codec->dapm);
124 static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
126 struct snd_soc_dai *dai = rtd->codec_dai;
127 struct snd_soc_codec *codec = rtd->codec;
130 ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
134 ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
136 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
137 gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
139 ret = snd_soc_jack_new(codec, "Headset",
140 SND_JACK_HEADSET | SND_JACK_BTN_0,
145 ret = snd_soc_jack_add_pins(&speyside_headset,
146 ARRAY_SIZE(speyside_headset_pins),
147 speyside_headset_pins);
151 wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
156 static struct snd_soc_dai_link speyside_dai[] = {
159 .stream_name = "CPU",
160 .cpu_dai_name = "samsung-i2s.0",
161 .codec_dai_name = "wm8915-aif1",
162 .platform_name = "samsung-audio",
163 .codec_name = "wm8915.1-001a",
164 .init = speyside_wm8915_init,
165 .ops = &speyside_ops,
169 static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
171 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
173 /* At any time the WM9081 is active it will have this clock */
174 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
178 static struct snd_soc_aux_dev speyside_aux_dev[] = {
181 .codec_name = "wm9081.1-006c",
182 .init = speyside_wm9081_init,
186 static struct snd_soc_codec_conf speyside_codec_conf[] = {
188 .dev_name = "wm9081.1-006c",
189 .name_prefix = "Sub",
193 static const struct snd_kcontrol_new controls[] = {
194 SOC_DAPM_PIN_SWITCH("Main Speaker"),
195 SOC_DAPM_PIN_SWITCH("Main DMIC"),
196 SOC_DAPM_PIN_SWITCH("Main AMIC"),
199 static struct snd_soc_dapm_widget widgets[] = {
200 SND_SOC_DAPM_HP("Headphone", NULL),
201 SND_SOC_DAPM_MIC("Headset Mic", NULL),
203 SND_SOC_DAPM_SPK("Main Speaker", NULL),
205 SND_SOC_DAPM_MIC("Main AMIC", NULL),
206 SND_SOC_DAPM_MIC("Main DMIC", NULL),
209 static struct snd_soc_dapm_route audio_paths[] = {
210 { "IN1RN", NULL, "MICB1" },
211 { "IN1RP", NULL, "MICB1" },
212 { "IN1RN", NULL, "MICB2" },
213 { "IN1RP", NULL, "MICB2" },
214 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
215 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
217 { "IN1LP", NULL, "MICB2" },
218 { "IN1RN", NULL, "MICB1" },
219 { "MICB2", NULL, "Main AMIC" },
221 { "DMIC1DAT", NULL, "MICB1" },
222 { "DMIC2DAT", NULL, "MICB1" },
223 { "MICB1", NULL, "Main DMIC" },
225 { "Headphone", NULL, "HPOUT1L" },
226 { "Headphone", NULL, "HPOUT1R" },
228 { "Sub IN1", NULL, "HPOUT2L" },
229 { "Sub IN2", NULL, "HPOUT2R" },
231 { "Main Speaker", NULL, "Sub SPKN" },
232 { "Main Speaker", NULL, "Sub SPKP" },
233 { "Main Speaker", NULL, "SPKDAT" },
236 static struct snd_soc_card speyside = {
238 .dai_link = speyside_dai,
239 .num_links = ARRAY_SIZE(speyside_dai),
240 .aux_dev = speyside_aux_dev,
241 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
242 .codec_conf = speyside_codec_conf,
243 .num_configs = ARRAY_SIZE(speyside_codec_conf),
245 .set_bias_level = speyside_set_bias_level,
247 .controls = controls,
248 .num_controls = ARRAY_SIZE(controls),
249 .dapm_widgets = widgets,
250 .num_dapm_widgets = ARRAY_SIZE(widgets),
251 .dapm_routes = audio_paths,
252 .num_dapm_routes = ARRAY_SIZE(audio_paths),
255 static __devinit int speyside_probe(struct platform_device *pdev)
257 struct snd_soc_card *card = &speyside;
260 card->dev = &pdev->dev;
262 ret = snd_soc_register_card(card);
264 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
272 static int __devexit speyside_remove(struct platform_device *pdev)
274 struct snd_soc_card *card = platform_get_drvdata(pdev);
276 snd_soc_unregister_card(card);
281 static struct platform_driver speyside_driver = {
284 .owner = THIS_MODULE,
285 .pm = &snd_soc_pm_ops,
287 .probe = speyside_probe,
288 .remove = __devexit_p(speyside_remove),
291 static int __init speyside_audio_init(void)
293 return platform_driver_register(&speyside_driver);
295 module_init(speyside_audio_init);
297 static void __exit speyside_audio_exit(void)
299 platform_driver_unregister(&speyside_driver);
301 module_exit(speyside_audio_exit);
303 MODULE_DESCRIPTION("Speyside audio support");
304 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
305 MODULE_LICENSE("GPL");
306 MODULE_ALIAS("platform:speyside");