blob: c0ba0bfd7f570260600a1c6a8b6bb03fd111324b [file] [log] [blame]
Mark Brown22cb8392011-04-25 18:30:45 +01001/*
2 * Speyside with WM8962 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>
14#include <sound/jack.h>
15#include <linux/gpio.h>
16
17#include "../codecs/wm8962.h"
18
19static int speyside_wm8962_set_bias_level(struct snd_soc_card *card,
20 struct snd_soc_dapm_context *dapm,
21 enum snd_soc_bias_level level)
22{
23 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
24 int ret;
25
26 switch (level) {
27 case SND_SOC_BIAS_PREPARE:
28 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
29 ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
30 WM8962_FLL_MCLK, 32768,
31 44100 * 256);
32 if (ret < 0)
33 pr_err("Failed to start FLL\n");
34
35 ret = snd_soc_dai_set_sysclk(codec_dai,
36 WM8962_SYSCLK_FLL,
37 44100 * 256,
38 SND_SOC_CLOCK_IN);
39 if (ret < 0)
40 return ret;
41 }
42 break;
43
44 default:
45 break;
46 }
47
48 return 0;
49}
50
51static int speyside_wm8962_set_bias_level_post(struct snd_soc_card *card,
52 struct snd_soc_dapm_context *dapm,
53 enum snd_soc_bias_level level)
54{
55 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
56 int ret;
57
58 switch (level) {
59 case SND_SOC_BIAS_STANDBY:
60 ret = snd_soc_dai_set_sysclk(codec_dai, WM8962_SYSCLK_MCLK,
61 32768, SND_SOC_CLOCK_IN);
62 if (ret < 0)
63 return ret;
64
65 ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
66 0, 0, 0);
67 if (ret < 0) {
68 pr_err("Failed to stop FLL\n");
69 return ret;
70 }
71 break;
72
73 default:
74 break;
75 }
76
77 dapm->bias_level = level;
78
79 return 0;
80}
81
82static int speyside_wm8962_hw_params(struct snd_pcm_substream *substream,
83 struct snd_pcm_hw_params *params)
84{
85 struct snd_soc_pcm_runtime *rtd = substream->private_data;
86 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
87 struct snd_soc_dai *codec_dai = rtd->codec_dai;
88 int ret;
89
90 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
91 | SND_SOC_DAIFMT_NB_NF
92 | SND_SOC_DAIFMT_CBM_CFM);
93 if (ret < 0)
94 return ret;
95
96 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
97 | SND_SOC_DAIFMT_NB_NF
98 | SND_SOC_DAIFMT_CBM_CFM);
99 if (ret < 0)
100 return ret;
101
102 return 0;
103}
104
105static struct snd_soc_ops speyside_wm8962_ops = {
106 .hw_params = speyside_wm8962_hw_params,
107};
108
109static struct snd_soc_dai_link speyside_wm8962_dai[] = {
110 {
111 .name = "CPU",
112 .stream_name = "CPU",
113 .cpu_dai_name = "samsung-i2s.0",
114 .codec_dai_name = "wm8962",
115 .platform_name = "samsung-audio",
116 .codec_name = "wm8962.1-001a",
117 .ops = &speyside_wm8962_ops,
118 },
119};
120
121static const struct snd_kcontrol_new controls[] = {
122 SOC_DAPM_PIN_SWITCH("Main Speaker"),
123};
124
125static struct snd_soc_dapm_widget widgets[] = {
126 SND_SOC_DAPM_HP("Headphone", NULL),
127 SND_SOC_DAPM_MIC("Headset Mic", NULL),
128
129 SND_SOC_DAPM_MIC("DMIC", NULL),
130
131 SND_SOC_DAPM_SPK("Main Speaker", NULL),
132};
133
134static struct snd_soc_dapm_route audio_paths[] = {
135 { "Headphone", NULL, "HPOUTL" },
136 { "Headphone", NULL, "HPOUTR" },
137
138 { "Main Speaker", NULL, "SPKOUTL" },
139 { "Main Speaker", NULL, "SPKOUTR" },
140
141 { "MICBIAS", NULL, "Headset Mic" },
142 { "IN4L", NULL, "MICBIAS" },
143 { "IN4R", NULL, "MICBIAS" },
144
145 { "MICBIAS", NULL, "DMIC" },
146 { "DMICDAT", NULL, "MICBIAS" },
147};
148
149static struct snd_soc_jack speyside_wm8962_headset;
150
151/* Headset jack detection DAPM pins */
152static struct snd_soc_jack_pin speyside_wm8962_headset_pins[] = {
153 {
154 .pin = "Headset Mic",
155 .mask = SND_JACK_MICROPHONE,
156 },
157 {
158 .pin = "Headphone",
159 .mask = SND_JACK_MICROPHONE,
160 },
161};
162
163static int speyside_wm8962_late_probe(struct snd_soc_card *card)
164{
165 struct snd_soc_codec *codec = card->rtd[0].codec;
166 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
167 int ret;
168
169 ret = snd_soc_dai_set_sysclk(codec_dai, WM8962_SYSCLK_MCLK,
170 32768, SND_SOC_CLOCK_IN);
171 if (ret < 0)
172 return ret;
173
174 ret = snd_soc_jack_new(codec, "Headset",
175 SND_JACK_HEADSET | SND_JACK_BTN_0,
176 &speyside_wm8962_headset);
177 if (ret)
178 return ret;
179
180 ret = snd_soc_jack_add_pins(&speyside_wm8962_headset,
181 ARRAY_SIZE(speyside_wm8962_headset_pins),
182 speyside_wm8962_headset_pins);
183 if (ret)
184 return ret;
185
186 wm8962_mic_detect(codec, &speyside_wm8962_headset);
187
188 return 0;
189}
190
191static struct snd_soc_card speyside_wm8962 = {
192 .name = "Speyside WM8962",
193 .dai_link = speyside_wm8962_dai,
194 .num_links = ARRAY_SIZE(speyside_wm8962_dai),
195
196 .set_bias_level = speyside_wm8962_set_bias_level,
197 .set_bias_level_post = speyside_wm8962_set_bias_level_post,
198
199 .controls = controls,
200 .num_controls = ARRAY_SIZE(controls),
201 .dapm_widgets = widgets,
202 .num_dapm_widgets = ARRAY_SIZE(widgets),
203 .dapm_routes = audio_paths,
204 .num_dapm_routes = ARRAY_SIZE(audio_paths),
205
206 .late_probe = speyside_wm8962_late_probe,
207};
208
209static __devinit int speyside_wm8962_probe(struct platform_device *pdev)
210{
211 struct snd_soc_card *card = &speyside_wm8962;
212 int ret;
213
214 card->dev = &pdev->dev;
215
216 ret = snd_soc_register_card(card);
217 if (ret) {
218 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
219 ret);
220 return ret;
221 }
222
223 return 0;
224}
225
226static int __devexit speyside_wm8962_remove(struct platform_device *pdev)
227{
228 struct snd_soc_card *card = platform_get_drvdata(pdev);
229
230 snd_soc_unregister_card(card);
231
232 return 0;
233}
234
235static struct platform_driver speyside_wm8962_driver = {
236 .driver = {
237 .name = "speyside-wm8962",
238 .owner = THIS_MODULE,
239 .pm = &snd_soc_pm_ops,
240 },
241 .probe = speyside_wm8962_probe,
242 .remove = __devexit_p(speyside_wm8962_remove),
243};
244
245static int __init speyside_wm8962_audio_init(void)
246{
247 return platform_driver_register(&speyside_wm8962_driver);
248}
249module_init(speyside_wm8962_audio_init);
250
251static void __exit speyside_wm8962_audio_exit(void)
252{
253 platform_driver_unregister(&speyside_wm8962_driver);
254}
255module_exit(speyside_wm8962_audio_exit);
256
257MODULE_DESCRIPTION("Speyside WM8962 audio support");
258MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
259MODULE_LICENSE("GPL");
260MODULE_ALIAS("platform:speyside-wm8962");