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
*codec_dai
= card
->rtd
[0].codec_dai
;
29 if (dapm
->dev
!= codec_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(codec_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(codec_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
*codec_dai
= card
->rtd
[0].codec_dai
;
72 if (dapm
->dev
!= codec_dai
->dev
)
76 case SND_SOC_BIAS_STANDBY
:
77 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_MCLK2
,
78 32768, SND_SOC_CLOCK_IN
);
80 pr_err("Failed to switch away from FLL: %d\n", ret
);
84 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL1
,
87 pr_err("Failed to stop FLL: %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 struct snd_soc_dai_link littlemill_dai
[] = {
137 .stream_name
= "CPU",
138 .cpu_dai_name
= "samsung-i2s.0",
139 .codec_dai_name
= "wm8994-aif1",
140 .platform_name
= "samsung-audio",
141 .codec_name
= "wm8994-codec",
142 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
143 | SND_SOC_DAIFMT_CBM_CFM
,
144 .ops
= &littlemill_ops
,
148 static struct snd_soc_dapm_widget widgets
[] = {
149 SND_SOC_DAPM_HP("Headphone", NULL
),
151 SND_SOC_DAPM_MIC("AMIC", NULL
),
152 SND_SOC_DAPM_MIC("DMIC", NULL
),
155 static struct snd_soc_dapm_route audio_paths
[] = {
156 { "Headphone", NULL
, "HPOUT1L" },
157 { "Headphone", NULL
, "HPOUT1R" },
159 { "AMIC", NULL
, "MICBIAS1" }, /* Default for AMICBIAS jumper */
160 { "IN1LN", NULL
, "AMIC" },
162 { "DMIC", NULL
, "MICBIAS2" }, /* Default for DMICBIAS jumper */
163 { "DMIC1DAT", NULL
, "DMIC" },
164 { "DMIC2DAT", NULL
, "DMIC" },
167 static struct snd_soc_jack littlemill_headset
;
169 static int littlemill_late_probe(struct snd_soc_card
*card
)
171 struct snd_soc_codec
*codec
= card
->rtd
[0].codec
;
172 struct snd_soc_dai
*codec_dai
= card
->rtd
[0].codec_dai
;
175 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_MCLK2
,
176 32768, SND_SOC_CLOCK_IN
);
180 ret
= snd_soc_jack_new(codec
, "Headset",
181 SND_JACK_HEADSET
| SND_JACK_MECHANICAL
|
182 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
183 SND_JACK_BTN_2
| SND_JACK_BTN_3
|
184 SND_JACK_BTN_4
| SND_JACK_BTN_5
,
185 &littlemill_headset
);
189 /* This will check device compatibility itself */
190 wm8958_mic_detect(codec
, &littlemill_headset
, NULL
, NULL
);
195 static struct snd_soc_card littlemill
= {
196 .name
= "Littlemill",
197 .owner
= THIS_MODULE
,
198 .dai_link
= littlemill_dai
,
199 .num_links
= ARRAY_SIZE(littlemill_dai
),
201 .set_bias_level
= littlemill_set_bias_level
,
202 .set_bias_level_post
= littlemill_set_bias_level_post
,
204 .dapm_widgets
= widgets
,
205 .num_dapm_widgets
= ARRAY_SIZE(widgets
),
206 .dapm_routes
= audio_paths
,
207 .num_dapm_routes
= ARRAY_SIZE(audio_paths
),
209 .late_probe
= littlemill_late_probe
,
212 static __devinit
int littlemill_probe(struct platform_device
*pdev
)
214 struct snd_soc_card
*card
= &littlemill
;
217 card
->dev
= &pdev
->dev
;
219 ret
= snd_soc_register_card(card
);
221 dev_err(&pdev
->dev
, "snd_soc_register_card() failed: %d\n",
229 static int __devexit
littlemill_remove(struct platform_device
*pdev
)
231 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
233 snd_soc_unregister_card(card
);
238 static struct platform_driver littlemill_driver
= {
240 .name
= "littlemill",
241 .owner
= THIS_MODULE
,
242 .pm
= &snd_soc_pm_ops
,
244 .probe
= littlemill_probe
,
245 .remove
= __devexit_p(littlemill_remove
),
248 module_platform_driver(littlemill_driver
);
250 MODULE_DESCRIPTION("Littlemill audio support");
251 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
252 MODULE_LICENSE("GPL");
253 MODULE_ALIAS("platform:littlemill");