blob: 3dd246fa0059db268bb5d035829c85f78315f65e [file] [log] [blame]
Mark Brownb545dd92012-08-07 20:03:02 +01001/*
2 * Bells audio support
3 *
4 * Copyright 2012 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#include <linux/module.h>
17
18#include "../codecs/wm5102.h"
19#include "../codecs/wm9081.h"
20
Mark Brownb545dd92012-08-07 20:03:02 +010021/* BCLK2 is fixed at this currently */
22#define BCLK2_RATE (64 * 8000)
23
24/*
25 * Expect a 24.576MHz crystal if one is fitted (the driver will function
26 * if this is not fitted).
27 */
28#define MCLK_RATE 24576000
29
Mark Brown344c5ed2012-09-25 21:24:30 +010030#define SYS_AUDIO_RATE 44100
Dimitris Papastamos208229e2012-11-15 13:56:35 +000031#define SYS_MCLK_RATE (SYS_AUDIO_RATE * 512)
Mark Brown344c5ed2012-09-25 21:24:30 +010032
33#define DAI_AP_DSP 0
34#define DAI_DSP_CODEC 1
35#define DAI_CODEC_CP 2
36#define DAI_CODEC_SUB 3
Mark Brownb545dd92012-08-07 20:03:02 +010037
Mark Brownb1387072012-10-02 15:47:44 +010038struct bells_drvdata {
39 int sysclk_rate;
40 int asyncclk_rate;
41};
42
Mark Brown8d47e8a2012-10-02 18:43:49 +010043static struct bells_drvdata wm2200_drvdata = {
44 .sysclk_rate = 22579200,
45};
46
Mark Brownb1387072012-10-02 15:47:44 +010047static struct bells_drvdata wm5102_drvdata = {
48 .sysclk_rate = 45158400,
49 .asyncclk_rate = 49152000,
50};
51
52static struct bells_drvdata wm5110_drvdata = {
53 .sysclk_rate = 135475200,
54 .asyncclk_rate = 147456000,
55};
56
Mark Brownb545dd92012-08-07 20:03:02 +010057static int bells_set_bias_level(struct snd_soc_card *card,
58 struct snd_soc_dapm_context *dapm,
59 enum snd_soc_bias_level level)
60{
Mengdong Lin50159202015-11-18 02:34:01 -050061 struct snd_soc_pcm_runtime *rtd;
62 struct snd_soc_dai *codec_dai;
63 struct snd_soc_codec *codec;
Mark Brownb1387072012-10-02 15:47:44 +010064 struct bells_drvdata *bells = card->drvdata;
Mark Brownb545dd92012-08-07 20:03:02 +010065 int ret;
66
Mengdong Lin50159202015-11-18 02:34:01 -050067 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_DSP_CODEC].name);
68 codec_dai = rtd->codec_dai;
69 codec = codec_dai->codec;
70
Mark Brownb545dd92012-08-07 20:03:02 +010071 if (dapm->dev != codec_dai->dev)
72 return 0;
73
74 switch (level) {
75 case SND_SOC_BIAS_PREPARE:
Mark Brownb1387072012-10-02 15:47:44 +010076 if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
77 break;
Mark Brownb545dd92012-08-07 20:03:02 +010078
Mark Brownb1387072012-10-02 15:47:44 +010079 ret = snd_soc_codec_set_pll(codec, WM5102_FLL1,
80 ARIZONA_FLL_SRC_MCLK1,
81 MCLK_RATE,
82 bells->sysclk_rate);
83 if (ret < 0)
84 pr_err("Failed to start FLL: %d\n", ret);
85
86 if (bells->asyncclk_rate) {
Mark Brownb545dd92012-08-07 20:03:02 +010087 ret = snd_soc_codec_set_pll(codec, WM5102_FLL2,
88 ARIZONA_FLL_SRC_AIF2BCLK,
89 BCLK2_RATE,
Mark Brownb1387072012-10-02 15:47:44 +010090 bells->asyncclk_rate);
Mark Brownb545dd92012-08-07 20:03:02 +010091 if (ret < 0)
92 pr_err("Failed to start FLL: %d\n", ret);
93 }
94 break;
95
96 default:
97 break;
98 }
99
100 return 0;
101}
102
103static int bells_set_bias_level_post(struct snd_soc_card *card,
104 struct snd_soc_dapm_context *dapm,
105 enum snd_soc_bias_level level)
106{
Mengdong Lin50159202015-11-18 02:34:01 -0500107 struct snd_soc_pcm_runtime *rtd;
108 struct snd_soc_dai *codec_dai;
109 struct snd_soc_codec *codec;
Mark Brownb1387072012-10-02 15:47:44 +0100110 struct bells_drvdata *bells = card->drvdata;
Mark Brownb545dd92012-08-07 20:03:02 +0100111 int ret;
112
Mengdong Lin50159202015-11-18 02:34:01 -0500113 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_DSP_CODEC].name);
114 codec_dai = rtd->codec_dai;
115 codec = codec_dai->codec;
116
Mark Brownb545dd92012-08-07 20:03:02 +0100117 if (dapm->dev != codec_dai->dev)
118 return 0;
119
120 switch (level) {
121 case SND_SOC_BIAS_STANDBY:
122 ret = snd_soc_codec_set_pll(codec, WM5102_FLL1, 0, 0, 0);
123 if (ret < 0) {
124 pr_err("Failed to stop FLL: %d\n", ret);
125 return ret;
126 }
127
Mark Brownb1387072012-10-02 15:47:44 +0100128 if (bells->asyncclk_rate) {
129 ret = snd_soc_codec_set_pll(codec, WM5102_FLL2,
130 0, 0, 0);
131 if (ret < 0) {
132 pr_err("Failed to stop FLL: %d\n", ret);
133 return ret;
134 }
Mark Brownb545dd92012-08-07 20:03:02 +0100135 }
136 break;
137
138 default:
139 break;
140 }
141
142 dapm->bias_level = level;
143
144 return 0;
145}
146
147static int bells_late_probe(struct snd_soc_card *card)
148{
Mark Brownb1387072012-10-02 15:47:44 +0100149 struct bells_drvdata *bells = card->drvdata;
Mengdong Lin50159202015-11-18 02:34:01 -0500150 struct snd_soc_pcm_runtime *rtd;
151 struct snd_soc_codec *wm0010;
152 struct snd_soc_codec *codec;
153 struct snd_soc_dai *aif1_dai;
Mark Brownb1387072012-10-02 15:47:44 +0100154 struct snd_soc_dai *aif2_dai;
155 struct snd_soc_dai *aif3_dai;
156 struct snd_soc_dai *wm9081_dai;
Mark Brownb545dd92012-08-07 20:03:02 +0100157 int ret;
158
Mengdong Lin50159202015-11-18 02:34:01 -0500159 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_AP_DSP].name);
160 wm0010 = rtd->codec;
161
162 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_DSP_CODEC].name);
163 codec = rtd->codec;
164 aif1_dai = rtd->codec_dai;
165
Mark Brownb1387072012-10-02 15:47:44 +0100166 ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_SYSCLK,
167 ARIZONA_CLK_SRC_FLL1,
168 bells->sysclk_rate,
169 SND_SOC_CLOCK_IN);
170 if (ret != 0) {
171 dev_err(codec->dev, "Failed to set SYSCLK: %d\n", ret);
172 return ret;
173 }
174
Mark Brown344c5ed2012-09-25 21:24:30 +0100175 ret = snd_soc_codec_set_sysclk(wm0010, 0, 0, SYS_MCLK_RATE, 0);
176 if (ret != 0) {
177 dev_err(wm0010->dev, "Failed to set WM0010 clock: %d\n", ret);
178 return ret;
179 }
180
Mark Brownb545dd92012-08-07 20:03:02 +0100181 ret = snd_soc_dai_set_sysclk(aif1_dai, ARIZONA_CLK_SYSCLK, 0, 0);
Mark Brownb1387072012-10-02 15:47:44 +0100182 if (ret != 0)
Mark Brownb545dd92012-08-07 20:03:02 +0100183 dev_err(aif1_dai->dev, "Failed to set AIF1 clock: %d\n", ret);
Mark Brownb1387072012-10-02 15:47:44 +0100184
185 ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_OPCLK, 0,
186 SYS_MCLK_RATE, SND_SOC_CLOCK_OUT);
187 if (ret != 0)
188 dev_err(codec->dev, "Failed to set OPCLK: %d\n", ret);
189
190 if (card->num_rtd == DAI_CODEC_CP)
191 return 0;
192
193 ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_ASYNCCLK,
194 ARIZONA_CLK_SRC_FLL2,
195 bells->asyncclk_rate,
196 SND_SOC_CLOCK_IN);
197 if (ret != 0) {
198 dev_err(codec->dev, "Failed to set ASYNCCLK: %d\n", ret);
Mark Brownb545dd92012-08-07 20:03:02 +0100199 return ret;
200 }
201
Mengdong Lin50159202015-11-18 02:34:01 -0500202 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_CODEC_CP].name);
203 aif2_dai = rtd->cpu_dai;
Mark Brownb1387072012-10-02 15:47:44 +0100204
Mark Brownb545dd92012-08-07 20:03:02 +0100205 ret = snd_soc_dai_set_sysclk(aif2_dai, ARIZONA_CLK_ASYNCCLK, 0, 0);
206 if (ret != 0) {
207 dev_err(aif2_dai->dev, "Failed to set AIF2 clock: %d\n", ret);
208 return ret;
209 }
210
Mark Brownb1387072012-10-02 15:47:44 +0100211 if (card->num_rtd == DAI_CODEC_SUB)
212 return 0;
213
Mengdong Lin50159202015-11-18 02:34:01 -0500214 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[DAI_CODEC_SUB].name);
215 aif3_dai = rtd->cpu_dai;
216 wm9081_dai = rtd->codec_dai;
Mark Brownb1387072012-10-02 15:47:44 +0100217
Mark Brownb545dd92012-08-07 20:03:02 +0100218 ret = snd_soc_dai_set_sysclk(aif3_dai, ARIZONA_CLK_SYSCLK, 0, 0);
219 if (ret != 0) {
220 dev_err(aif1_dai->dev, "Failed to set AIF1 clock: %d\n", ret);
221 return ret;
222 }
223
Mark Brownb545dd92012-08-07 20:03:02 +0100224 ret = snd_soc_codec_set_sysclk(wm9081_dai->codec, WM9081_SYSCLK_MCLK,
Mark Brown344c5ed2012-09-25 21:24:30 +0100225 0, SYS_MCLK_RATE, 0);
Mark Brownb545dd92012-08-07 20:03:02 +0100226 if (ret != 0) {
227 dev_err(wm9081_dai->dev, "Failed to set MCLK: %d\n", ret);
228 return ret;
229 }
230
231 return 0;
232}
233
234static const struct snd_soc_pcm_stream baseband_params = {
235 .formats = SNDRV_PCM_FMTBIT_S32_LE,
236 .rate_min = 8000,
237 .rate_max = 8000,
238 .channels_min = 2,
239 .channels_max = 2,
240};
241
242static const struct snd_soc_pcm_stream sub_params = {
243 .formats = SNDRV_PCM_FMTBIT_S32_LE,
Mark Brown344c5ed2012-09-25 21:24:30 +0100244 .rate_min = SYS_AUDIO_RATE,
245 .rate_max = SYS_AUDIO_RATE,
Mark Brownb545dd92012-08-07 20:03:02 +0100246 .channels_min = 2,
247 .channels_max = 2,
248};
249
Mark Brown8d47e8a2012-10-02 18:43:49 +0100250static struct snd_soc_dai_link bells_dai_wm2200[] = {
251 {
252 .name = "CPU-DSP",
253 .stream_name = "CPU-DSP",
254 .cpu_dai_name = "samsung-i2s.0",
255 .codec_dai_name = "wm0010-sdi1",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530256 .platform_name = "samsung-i2s.0",
Mark Brown8d47e8a2012-10-02 18:43:49 +0100257 .codec_name = "spi0.0",
258 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
259 | SND_SOC_DAIFMT_CBM_CFM,
260 },
261 {
262 .name = "DSP-CODEC",
263 .stream_name = "DSP-CODEC",
264 .cpu_dai_name = "wm0010-sdi2",
265 .codec_dai_name = "wm2200",
266 .codec_name = "wm2200.1-003a",
267 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
268 | SND_SOC_DAIFMT_CBM_CFM,
269 .params = &sub_params,
270 .ignore_suspend = 1,
271 },
272};
273
Mark Brownb545dd92012-08-07 20:03:02 +0100274static struct snd_soc_dai_link bells_dai_wm5102[] = {
275 {
Mark Brown344c5ed2012-09-25 21:24:30 +0100276 .name = "CPU-DSP",
277 .stream_name = "CPU-DSP",
Mark Brownb545dd92012-08-07 20:03:02 +0100278 .cpu_dai_name = "samsung-i2s.0",
Mark Brown344c5ed2012-09-25 21:24:30 +0100279 .codec_dai_name = "wm0010-sdi1",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530280 .platform_name = "samsung-i2s.0",
Mark Brown344c5ed2012-09-25 21:24:30 +0100281 .codec_name = "spi0.0",
282 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
283 | SND_SOC_DAIFMT_CBM_CFM,
284 },
285 {
286 .name = "DSP-CODEC",
287 .stream_name = "DSP-CODEC",
288 .cpu_dai_name = "wm0010-sdi2",
289 .codec_dai_name = "wm5102-aif1",
Mark Brownb545dd92012-08-07 20:03:02 +0100290 .codec_name = "wm5102-codec",
291 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
292 | SND_SOC_DAIFMT_CBM_CFM,
Mark Brown344c5ed2012-09-25 21:24:30 +0100293 .params = &sub_params,
294 .ignore_suspend = 1,
Mark Brownb545dd92012-08-07 20:03:02 +0100295 },
296 {
297 .name = "Baseband",
298 .stream_name = "Baseband",
299 .cpu_dai_name = "wm5102-aif2",
300 .codec_dai_name = "wm1250-ev1",
301 .codec_name = "wm1250-ev1.1-0027",
302 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
303 | SND_SOC_DAIFMT_CBM_CFM,
304 .ignore_suspend = 1,
305 .params = &baseband_params,
306 },
307 {
308 .name = "Sub",
309 .stream_name = "Sub",
310 .cpu_dai_name = "wm5102-aif3",
311 .codec_dai_name = "wm9081-hifi",
312 .codec_name = "wm9081.1-006c",
313 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
314 | SND_SOC_DAIFMT_CBS_CFS,
315 .ignore_suspend = 1,
316 .params = &sub_params,
317 },
318};
319
320static struct snd_soc_dai_link bells_dai_wm5110[] = {
321 {
Mark Brown344c5ed2012-09-25 21:24:30 +0100322 .name = "CPU-DSP",
323 .stream_name = "CPU-DSP",
Mark Brownb545dd92012-08-07 20:03:02 +0100324 .cpu_dai_name = "samsung-i2s.0",
Mark Brown344c5ed2012-09-25 21:24:30 +0100325 .codec_dai_name = "wm0010-sdi1",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530326 .platform_name = "samsung-i2s.0",
Mark Brown344c5ed2012-09-25 21:24:30 +0100327 .codec_name = "spi0.0",
328 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
329 | SND_SOC_DAIFMT_CBM_CFM,
330 },
331 {
332 .name = "DSP-CODEC",
333 .stream_name = "DSP-CODEC",
334 .cpu_dai_name = "wm0010-sdi2",
335 .codec_dai_name = "wm5110-aif1",
Mark Brownb545dd92012-08-07 20:03:02 +0100336 .codec_name = "wm5110-codec",
337 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
338 | SND_SOC_DAIFMT_CBM_CFM,
Mark Brown344c5ed2012-09-25 21:24:30 +0100339 .params = &sub_params,
340 .ignore_suspend = 1,
Mark Brownb545dd92012-08-07 20:03:02 +0100341 },
342 {
343 .name = "Baseband",
344 .stream_name = "Baseband",
345 .cpu_dai_name = "wm5110-aif2",
346 .codec_dai_name = "wm1250-ev1",
347 .codec_name = "wm1250-ev1.1-0027",
348 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
349 | SND_SOC_DAIFMT_CBM_CFM,
350 .ignore_suspend = 1,
351 .params = &baseband_params,
352 },
353 {
354 .name = "Sub",
355 .stream_name = "Sub",
Mark Brownffaa8392012-09-26 16:22:32 +0100356 .cpu_dai_name = "wm5110-aif3",
Mark Brownb545dd92012-08-07 20:03:02 +0100357 .codec_dai_name = "wm9081-hifi",
358 .codec_name = "wm9081.1-006c",
359 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
360 | SND_SOC_DAIFMT_CBS_CFS,
361 .ignore_suspend = 1,
362 .params = &sub_params,
363 },
364};
365
366static struct snd_soc_codec_conf bells_codec_conf[] = {
367 {
368 .dev_name = "wm9081.1-006c",
369 .name_prefix = "Sub",
370 },
371};
372
Charles Keepax939d3c62013-05-27 09:46:53 +0100373static struct snd_soc_dapm_widget bells_widgets[] = {
374 SND_SOC_DAPM_MIC("DMIC", NULL),
375};
376
Mark Brownb545dd92012-08-07 20:03:02 +0100377static struct snd_soc_dapm_route bells_routes[] = {
378 { "Sub CLK_SYS", NULL, "OPCLK" },
Charles Keepaxb3a60062013-09-16 15:38:15 +0100379 { "CLKIN", NULL, "OPCLK" },
Charles Keepax939d3c62013-05-27 09:46:53 +0100380
381 { "DMIC", NULL, "MICBIAS2" },
382 { "IN2L", NULL, "DMIC" },
383 { "IN2R", NULL, "DMIC" },
Mark Brownb545dd92012-08-07 20:03:02 +0100384};
385
386static struct snd_soc_card bells_cards[] = {
387 {
Mark Brown8d47e8a2012-10-02 18:43:49 +0100388 .name = "Bells WM2200",
389 .owner = THIS_MODULE,
390 .dai_link = bells_dai_wm2200,
391 .num_links = ARRAY_SIZE(bells_dai_wm2200),
392 .codec_conf = bells_codec_conf,
393 .num_configs = ARRAY_SIZE(bells_codec_conf),
394
395 .late_probe = bells_late_probe,
396
Charles Keepax939d3c62013-05-27 09:46:53 +0100397 .dapm_widgets = bells_widgets,
398 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
Mark Brown8d47e8a2012-10-02 18:43:49 +0100399 .dapm_routes = bells_routes,
400 .num_dapm_routes = ARRAY_SIZE(bells_routes),
401
402 .set_bias_level = bells_set_bias_level,
403 .set_bias_level_post = bells_set_bias_level_post,
404
405 .drvdata = &wm2200_drvdata,
406 },
407 {
Mark Brownb545dd92012-08-07 20:03:02 +0100408 .name = "Bells WM5102",
409 .owner = THIS_MODULE,
410 .dai_link = bells_dai_wm5102,
411 .num_links = ARRAY_SIZE(bells_dai_wm5102),
412 .codec_conf = bells_codec_conf,
413 .num_configs = ARRAY_SIZE(bells_codec_conf),
414
415 .late_probe = bells_late_probe,
416
Charles Keepax939d3c62013-05-27 09:46:53 +0100417 .dapm_widgets = bells_widgets,
418 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
Mark Brownb545dd92012-08-07 20:03:02 +0100419 .dapm_routes = bells_routes,
420 .num_dapm_routes = ARRAY_SIZE(bells_routes),
421
422 .set_bias_level = bells_set_bias_level,
423 .set_bias_level_post = bells_set_bias_level_post,
Mark Brownb1387072012-10-02 15:47:44 +0100424
425 .drvdata = &wm5102_drvdata,
Mark Brownb545dd92012-08-07 20:03:02 +0100426 },
427 {
428 .name = "Bells WM5110",
429 .owner = THIS_MODULE,
430 .dai_link = bells_dai_wm5110,
431 .num_links = ARRAY_SIZE(bells_dai_wm5110),
432 .codec_conf = bells_codec_conf,
433 .num_configs = ARRAY_SIZE(bells_codec_conf),
434
435 .late_probe = bells_late_probe,
436
Charles Keepax939d3c62013-05-27 09:46:53 +0100437 .dapm_widgets = bells_widgets,
438 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
Mark Brownb545dd92012-08-07 20:03:02 +0100439 .dapm_routes = bells_routes,
440 .num_dapm_routes = ARRAY_SIZE(bells_routes),
441
442 .set_bias_level = bells_set_bias_level,
443 .set_bias_level_post = bells_set_bias_level_post,
Mark Brownb1387072012-10-02 15:47:44 +0100444
445 .drvdata = &wm5110_drvdata,
Mark Brownb545dd92012-08-07 20:03:02 +0100446 },
447};
448
449
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500450static int bells_probe(struct platform_device *pdev)
Mark Brownb545dd92012-08-07 20:03:02 +0100451{
452 int ret;
453
454 bells_cards[pdev->id].dev = &pdev->dev;
455
Tushar Beherac5838832014-05-21 08:52:17 +0530456 ret = devm_snd_soc_register_card(&pdev->dev, &bells_cards[pdev->id]);
457 if (ret)
Mark Brownb545dd92012-08-07 20:03:02 +0100458 dev_err(&pdev->dev,
459 "snd_soc_register_card(%s) failed: %d\n",
460 bells_cards[pdev->id].name, ret);
Mark Brownb545dd92012-08-07 20:03:02 +0100461
Tushar Beherac5838832014-05-21 08:52:17 +0530462 return ret;
Mark Brownb545dd92012-08-07 20:03:02 +0100463}
464
465static struct platform_driver bells_driver = {
466 .driver = {
467 .name = "bells",
Mark Brownb545dd92012-08-07 20:03:02 +0100468 .pm = &snd_soc_pm_ops,
469 },
470 .probe = bells_probe,
Mark Brownb545dd92012-08-07 20:03:02 +0100471};
472
473module_platform_driver(bells_driver);
474
475MODULE_DESCRIPTION("Bells audio support");
476MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
477MODULE_LICENSE("GPL");
478MODULE_ALIAS("platform:bells");