2 * Littlemill 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/wm8994.h"
20 static int sample_rate = 44100;
22 static int littlemill_set_bias_level(struct snd_soc_card *card,
23 struct snd_soc_dapm_context *dapm,
24 enum snd_soc_bias_level level)
26 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
29 if (dapm->dev != aif1_dai->dev)
33 case SND_SOC_BIAS_PREPARE:
35 * If we've not already clocked things via hw_params()
36 * then do so now, otherwise these are noops.
38 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
39 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
40 WM8994_FLL_SRC_MCLK2, 32768,
43 pr_err("Failed to start FLL: %d\n", ret);
47 ret = snd_soc_dai_set_sysclk(aif1_dai,
52 pr_err("Failed to set SYSCLK: %d\n", ret);
65 static int littlemill_set_bias_level_post(struct snd_soc_card *card,
66 struct snd_soc_dapm_context *dapm,
67 enum snd_soc_bias_level level)
69 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
72 if (dapm->dev != aif1_dai->dev)
76 case SND_SOC_BIAS_STANDBY:
77 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
78 32768, SND_SOC_CLOCK_IN);
80 pr_err("Failed to switch away from FLL1: %d\n", ret);
84 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
87 pr_err("Failed to stop FLL1: %d\n", ret);
96 dapm->bias_level = level;
101 static int littlemill_hw_params(struct snd_pcm_substream *substream,
102 struct snd_pcm_hw_params *params)
104 struct snd_soc_pcm_runtime *rtd = substream->private_data;
105 struct snd_soc_dai *codec_dai = rtd->codec_dai;
108 sample_rate = params_rate(params);
110 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
111 WM8994_FLL_SRC_MCLK2, 32768,
114 pr_err("Failed to start FLL: %d\n", ret);
118 ret = snd_soc_dai_set_sysclk(codec_dai,
123 pr_err("Failed to set SYSCLK: %d\n", ret);
130 static struct snd_soc_ops littlemill_ops = {
131 .hw_params = littlemill_hw_params,
134 static const struct snd_soc_pcm_stream baseband_params = {
135 .formats = SNDRV_PCM_FMTBIT_S32_LE,
142 static struct snd_soc_dai_link littlemill_dai[] = {
145 .stream_name = "CPU",
146 .cpu_dai_name = "samsung-i2s.0",
147 .codec_dai_name = "wm8994-aif1",
148 .platform_name = "samsung-i2s.0",
149 .codec_name = "wm8994-codec",
150 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
151 | SND_SOC_DAIFMT_CBM_CFM,
152 .ops = &littlemill_ops,
156 .stream_name = "Baseband",
157 .cpu_dai_name = "wm8994-aif2",
158 .codec_dai_name = "wm1250-ev1",
159 .codec_name = "wm1250-ev1.1-0027",
160 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
161 | SND_SOC_DAIFMT_CBM_CFM,
163 .params = &baseband_params,
167 static int bbclk_ev(struct snd_soc_dapm_widget *w,
168 struct snd_kcontrol *kcontrol, int event)
170 struct snd_soc_card *card = w->dapm->card;
171 struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai;
175 case SND_SOC_DAPM_PRE_PMU:
176 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
177 WM8994_FLL_SRC_BCLK, 64 * 8000,
180 pr_err("Failed to start FLL: %d\n", ret);
184 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_FLL2,
188 pr_err("Failed to set SYSCLK: %d\n", ret);
192 case SND_SOC_DAPM_POST_PMD:
193 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2,
194 32768, SND_SOC_CLOCK_IN);
196 pr_err("Failed to switch away from FLL2: %d\n", ret);
200 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
203 pr_err("Failed to stop FLL2: %d\n", ret);
214 static const struct snd_kcontrol_new controls[] = {
215 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
216 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
219 static struct snd_soc_dapm_widget widgets[] = {
220 SND_SOC_DAPM_HP("Headphone", NULL),
222 SND_SOC_DAPM_MIC("AMIC", NULL),
223 SND_SOC_DAPM_MIC("DMIC", NULL),
225 SND_SOC_DAPM_SUPPLY_S("Baseband Clock", -1, SND_SOC_NOPM, 0, 0,
227 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
230 static struct snd_soc_dapm_route audio_paths[] = {
231 { "Headphone", NULL, "HPOUT1L" },
232 { "Headphone", NULL, "HPOUT1R" },
234 { "AMIC", NULL, "MICBIAS1" }, /* Default for AMICBIAS jumper */
235 { "IN1LN", NULL, "AMIC" },
237 { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */
238 { "DMIC1DAT", NULL, "DMIC" },
239 { "DMIC2DAT", NULL, "DMIC" },
241 { "AIF2CLK", NULL, "Baseband Clock" },
244 static struct snd_soc_jack littlemill_headset;
246 static int littlemill_late_probe(struct snd_soc_card *card)
248 struct snd_soc_codec *codec = card->rtd[0].codec;
249 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
250 struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai;
253 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
254 32768, SND_SOC_CLOCK_IN);
258 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2,
259 32768, SND_SOC_CLOCK_IN);
263 ret = snd_soc_jack_new(codec, "Headset",
264 SND_JACK_HEADSET | SND_JACK_MECHANICAL |
265 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
266 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
267 SND_JACK_BTN_4 | SND_JACK_BTN_5,
268 &littlemill_headset);
272 /* This will check device compatibility itself */
273 wm8958_mic_detect(codec, &littlemill_headset, NULL, NULL, NULL, NULL);
276 wm8994_mic_detect(codec, &littlemill_headset, 1);
281 static struct snd_soc_card littlemill = {
282 .name = "Littlemill",
283 .owner = THIS_MODULE,
284 .dai_link = littlemill_dai,
285 .num_links = ARRAY_SIZE(littlemill_dai),
287 .set_bias_level = littlemill_set_bias_level,
288 .set_bias_level_post = littlemill_set_bias_level_post,
290 .controls = controls,
291 .num_controls = ARRAY_SIZE(controls),
292 .dapm_widgets = widgets,
293 .num_dapm_widgets = ARRAY_SIZE(widgets),
294 .dapm_routes = audio_paths,
295 .num_dapm_routes = ARRAY_SIZE(audio_paths),
297 .late_probe = littlemill_late_probe,
300 static int littlemill_probe(struct platform_device *pdev)
302 struct snd_soc_card *card = &littlemill;
305 card->dev = &pdev->dev;
307 ret = snd_soc_register_card(card);
309 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
317 static int littlemill_remove(struct platform_device *pdev)
319 struct snd_soc_card *card = platform_get_drvdata(pdev);
321 snd_soc_unregister_card(card);
326 static struct platform_driver littlemill_driver = {
328 .name = "littlemill",
329 .owner = THIS_MODULE,
330 .pm = &snd_soc_pm_ops,
332 .probe = littlemill_probe,
333 .remove = littlemill_remove,
336 module_platform_driver(littlemill_driver);
338 MODULE_DESCRIPTION("Littlemill audio support");
339 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
340 MODULE_LICENSE("GPL");
341 MODULE_ALIAS("platform:littlemill");