blob: 2417ef9316ed70a92b29e350f26dd44e85b8a028 [file] [log] [blame]
Mark Brown9e6e96a2010-01-29 17:47:12 +00001/*
2 * wm8994.c -- WM8994 ALSA SoC Audio driver
3 *
4 * Copyright 2009 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/pm.h>
19#include <linux/i2c.h>
20#include <linux/platform_device.h>
Mark Brown39fb51a2010-11-26 17:23:43 +000021#include <linux/pm_runtime.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000022#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000024#include <sound/core.h>
Mark Brown821edd22010-11-26 15:21:09 +000025#include <sound/jack.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000026#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000029#include <sound/initval.h>
30#include <sound/tlv.h>
Mark Brown2bbb5d62010-12-05 12:50:12 +000031#include <trace/events/asoc.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000032
33#include <linux/mfd/wm8994/core.h>
34#include <linux/mfd/wm8994/registers.h>
35#include <linux/mfd/wm8994/pdata.h>
36#include <linux/mfd/wm8994/gpio.h>
37
38#include "wm8994.h"
39#include "wm_hubs.h"
40
Mark Brownaf6b6fe2011-11-30 20:32:05 +000041#define WM1811_JACKDET_MODE_NONE 0x0000
42#define WM1811_JACKDET_MODE_JACK 0x0100
43#define WM1811_JACKDET_MODE_MIC 0x0080
44#define WM1811_JACKDET_MODE_AUDIO 0x0180
45
Mark Brown9e6e96a2010-01-29 17:47:12 +000046#define WM8994_NUM_DRC 3
47#define WM8994_NUM_EQ 3
48
49static int wm8994_drc_base[] = {
50 WM8994_AIF1_DRC1_1,
51 WM8994_AIF1_DRC2_1,
52 WM8994_AIF2_DRC_1,
53};
54
55static int wm8994_retune_mobile_base[] = {
56 WM8994_AIF1_DAC1_EQ_GAINS_1,
57 WM8994_AIF1_DAC2_EQ_GAINS_1,
58 WM8994_AIF2_EQ_GAINS_1,
59};
60
Mark Brownb00adf72011-08-13 11:57:18 +090061static void wm8958_default_micdet(u16 status, void *data);
62
Mark Brownaf6b6fe2011-11-30 20:32:05 +000063static const struct wm8958_micd_rate micdet_rates[] = {
Mark Brownb00adf72011-08-13 11:57:18 +090064 { 32768, true, 1, 4 },
65 { 32768, false, 1, 1 },
Mark Brown604533d2011-12-01 12:51:25 +000066 { 44100 * 256, true, 7, 10 },
67 { 44100 * 256, false, 7, 10 },
Mark Brownb00adf72011-08-13 11:57:18 +090068};
69
Mark Brownaf6b6fe2011-11-30 20:32:05 +000070static const struct wm8958_micd_rate jackdet_rates[] = {
71 { 32768, true, 0, 1 },
72 { 32768, false, 0, 1 },
73 { 44100 * 256, true, 7, 10 },
74 { 44100 * 256, false, 7, 10 },
75};
76
Mark Brownb00adf72011-08-13 11:57:18 +090077static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
78{
79 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
80 int best, i, sysclk, val;
81 bool idle;
Mark Brownaf6b6fe2011-11-30 20:32:05 +000082 const struct wm8958_micd_rate *rates;
83 int num_rates;
Mark Brownb00adf72011-08-13 11:57:18 +090084
85 if (wm8994->jack_cb != wm8958_default_micdet)
86 return;
87
88 idle = !wm8994->jack_mic;
89
90 sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
91 if (sysclk & WM8994_SYSCLK_SRC)
92 sysclk = wm8994->aifclk[1];
93 else
94 sysclk = wm8994->aifclk[0];
95
Mark Browncd1707a2011-12-01 13:44:25 +000096 if (wm8994->pdata && wm8994->pdata->micd_rates) {
97 rates = wm8994->pdata->micd_rates;
98 num_rates = wm8994->pdata->num_micd_rates;
99 } else if (wm8994->jackdet) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000100 rates = jackdet_rates;
101 num_rates = ARRAY_SIZE(jackdet_rates);
102 } else {
103 rates = micdet_rates;
104 num_rates = ARRAY_SIZE(micdet_rates);
105 }
106
Mark Brownb00adf72011-08-13 11:57:18 +0900107 best = 0;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000108 for (i = 0; i < num_rates; i++) {
109 if (rates[i].idle != idle)
Mark Brownb00adf72011-08-13 11:57:18 +0900110 continue;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000111 if (abs(rates[i].sysclk - sysclk) <
112 abs(rates[best].sysclk - sysclk))
Mark Brownb00adf72011-08-13 11:57:18 +0900113 best = i;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000114 else if (rates[best].idle != idle)
Mark Brownb00adf72011-08-13 11:57:18 +0900115 best = i;
116 }
117
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000118 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
119 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
Mark Brownb00adf72011-08-13 11:57:18 +0900120
121 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
122 WM8958_MICD_BIAS_STARTTIME_MASK |
123 WM8958_MICD_RATE_MASK, val);
124}
125
Mark Brown9e6e96a2010-01-29 17:47:12 +0000126static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
127{
Mark Brownb2c812e2010-04-14 15:35:19 +0900128 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000129 int rate;
130 int reg1 = 0;
131 int offset;
132
133 if (aif)
134 offset = 4;
135 else
136 offset = 0;
137
138 switch (wm8994->sysclk[aif]) {
139 case WM8994_SYSCLK_MCLK1:
140 rate = wm8994->mclk[0];
141 break;
142
143 case WM8994_SYSCLK_MCLK2:
144 reg1 |= 0x8;
145 rate = wm8994->mclk[1];
146 break;
147
148 case WM8994_SYSCLK_FLL1:
149 reg1 |= 0x10;
150 rate = wm8994->fll[0].out;
151 break;
152
153 case WM8994_SYSCLK_FLL2:
154 reg1 |= 0x18;
155 rate = wm8994->fll[1].out;
156 break;
157
158 default:
159 return -EINVAL;
160 }
161
162 if (rate >= 13500000) {
163 rate /= 2;
164 reg1 |= WM8994_AIF1CLK_DIV;
165
166 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
167 aif + 1, rate);
168 }
Mark Brown5e5e2be2010-04-25 12:20:30 +0100169
Mark Brown9e6e96a2010-01-29 17:47:12 +0000170 wm8994->aifclk[aif] = rate;
171
172 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
173 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
174 reg1);
175
176 return 0;
177}
178
179static int configure_clock(struct snd_soc_codec *codec)
180{
Mark Brownb2c812e2010-04-14 15:35:19 +0900181 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Axel Lin04f45c42011-10-04 20:07:03 +0800182 int change, new;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000183
184 /* Bring up the AIF clocks first */
185 configure_aif_clock(codec, 0);
186 configure_aif_clock(codec, 1);
187
188 /* Then switch CLK_SYS over to the higher of them; a change
189 * can only happen as a result of a clocking change which can
190 * only be made outside of DAPM so we can safely redo the
191 * clocking.
192 */
193
194 /* If they're equal it doesn't matter which is used */
Mark Brownb00adf72011-08-13 11:57:18 +0900195 if (wm8994->aifclk[0] == wm8994->aifclk[1]) {
196 wm8958_micd_set_rate(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000197 return 0;
Mark Brownb00adf72011-08-13 11:57:18 +0900198 }
Mark Brown9e6e96a2010-01-29 17:47:12 +0000199
200 if (wm8994->aifclk[0] < wm8994->aifclk[1])
201 new = WM8994_SYSCLK_SRC;
202 else
203 new = 0;
204
Axel Lin04f45c42011-10-04 20:07:03 +0800205 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
206 WM8994_SYSCLK_SRC, new);
Mark Brown52ac7ab2011-12-01 12:43:26 +0000207 if (change)
208 snd_soc_dapm_sync(&codec->dapm);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000209
Mark Brownb00adf72011-08-13 11:57:18 +0900210 wm8958_micd_set_rate(codec);
211
Mark Brown9e6e96a2010-01-29 17:47:12 +0000212 return 0;
213}
214
215static int check_clk_sys(struct snd_soc_dapm_widget *source,
216 struct snd_soc_dapm_widget *sink)
217{
218 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
219 const char *clk;
220
221 /* Check what we're currently using for CLK_SYS */
222 if (reg & WM8994_SYSCLK_SRC)
223 clk = "AIF2CLK";
224 else
225 clk = "AIF1CLK";
226
227 return strcmp(source->name, clk) == 0;
228}
229
230static const char *sidetone_hpf_text[] = {
231 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
232};
233
234static const struct soc_enum sidetone_hpf =
235 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
236
Uk Kim146fd572010-12-07 13:58:40 +0000237static const char *adc_hpf_text[] = {
238 "HiFi", "Voice 1", "Voice 2", "Voice 3"
239};
240
241static const struct soc_enum aif1adc1_hpf =
242 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
243
244static const struct soc_enum aif1adc2_hpf =
245 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
246
247static const struct soc_enum aif2adc_hpf =
248 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
249
Mark Brown9e6e96a2010-01-29 17:47:12 +0000250static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
251static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
252static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
253static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
254static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
Mark Brown1ddc07d2011-08-16 10:08:48 +0900255static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
Mark Brown81204c82011-05-24 17:35:53 +0800256static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000257
258#define WM8994_DRC_SWITCH(xname, reg, shift) \
259{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
260 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
261 .put = wm8994_put_drc_sw, \
262 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
263
264static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol)
266{
267 struct soc_mixer_control *mc =
268 (struct soc_mixer_control *)kcontrol->private_value;
269 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
270 int mask, ret;
271
272 /* Can't enable both ADC and DAC paths simultaneously */
273 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
274 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
275 WM8994_AIF1ADC1R_DRC_ENA_MASK;
276 else
277 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
278
279 ret = snd_soc_read(codec, mc->reg);
280 if (ret < 0)
281 return ret;
282 if (ret & mask)
283 return -EINVAL;
284
285 return snd_soc_put_volsw(kcontrol, ucontrol);
286}
287
Mark Brown9e6e96a2010-01-29 17:47:12 +0000288static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
289{
Mark Brownb2c812e2010-04-14 15:35:19 +0900290 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000291 struct wm8994_pdata *pdata = wm8994->pdata;
292 int base = wm8994_drc_base[drc];
293 int cfg = wm8994->drc_cfg[drc];
294 int save, i;
295
296 /* Save any enables; the configuration should clear them. */
297 save = snd_soc_read(codec, base);
298 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
299 WM8994_AIF1ADC1R_DRC_ENA;
300
301 for (i = 0; i < WM8994_DRC_REGS; i++)
302 snd_soc_update_bits(codec, base + i, 0xffff,
303 pdata->drc_cfgs[cfg].regs[i]);
304
305 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
306 WM8994_AIF1ADC1L_DRC_ENA |
307 WM8994_AIF1ADC1R_DRC_ENA, save);
308}
309
310/* Icky as hell but saves code duplication */
311static int wm8994_get_drc(const char *name)
312{
313 if (strcmp(name, "AIF1DRC1 Mode") == 0)
314 return 0;
315 if (strcmp(name, "AIF1DRC2 Mode") == 0)
316 return 1;
317 if (strcmp(name, "AIF2DRC Mode") == 0)
318 return 2;
319 return -EINVAL;
320}
321
322static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol)
324{
325 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000326 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000327 struct wm8994_pdata *pdata = wm8994->pdata;
328 int drc = wm8994_get_drc(kcontrol->id.name);
329 int value = ucontrol->value.integer.value[0];
330
331 if (drc < 0)
332 return drc;
333
334 if (value >= pdata->num_drc_cfgs)
335 return -EINVAL;
336
337 wm8994->drc_cfg[drc] = value;
338
339 wm8994_set_drc(codec, drc);
340
341 return 0;
342}
343
344static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_value *ucontrol)
346{
347 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900348 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000349 int drc = wm8994_get_drc(kcontrol->id.name);
350
351 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
352
353 return 0;
354}
355
356static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
357{
Mark Brownb2c812e2010-04-14 15:35:19 +0900358 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000359 struct wm8994_pdata *pdata = wm8994->pdata;
360 int base = wm8994_retune_mobile_base[block];
361 int iface, best, best_val, save, i, cfg;
362
363 if (!pdata || !wm8994->num_retune_mobile_texts)
364 return;
365
366 switch (block) {
367 case 0:
368 case 1:
369 iface = 0;
370 break;
371 case 2:
372 iface = 1;
373 break;
374 default:
375 return;
376 }
377
378 /* Find the version of the currently selected configuration
379 * with the nearest sample rate. */
380 cfg = wm8994->retune_mobile_cfg[block];
381 best = 0;
382 best_val = INT_MAX;
383 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
384 if (strcmp(pdata->retune_mobile_cfgs[i].name,
385 wm8994->retune_mobile_texts[cfg]) == 0 &&
386 abs(pdata->retune_mobile_cfgs[i].rate
387 - wm8994->dac_rates[iface]) < best_val) {
388 best = i;
389 best_val = abs(pdata->retune_mobile_cfgs[i].rate
390 - wm8994->dac_rates[iface]);
391 }
392 }
393
394 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
395 block,
396 pdata->retune_mobile_cfgs[best].name,
397 pdata->retune_mobile_cfgs[best].rate,
398 wm8994->dac_rates[iface]);
399
400 /* The EQ will be disabled while reconfiguring it, remember the
401 * current configuration.
402 */
403 save = snd_soc_read(codec, base);
404 save &= WM8994_AIF1DAC1_EQ_ENA;
405
406 for (i = 0; i < WM8994_EQ_REGS; i++)
407 snd_soc_update_bits(codec, base + i, 0xffff,
408 pdata->retune_mobile_cfgs[best].regs[i]);
409
410 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
411}
412
413/* Icky as hell but saves code duplication */
414static int wm8994_get_retune_mobile_block(const char *name)
415{
416 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
417 return 0;
418 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
419 return 1;
420 if (strcmp(name, "AIF2 EQ Mode") == 0)
421 return 2;
422 return -EINVAL;
423}
424
425static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
426 struct snd_ctl_elem_value *ucontrol)
427{
428 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000429 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000430 struct wm8994_pdata *pdata = wm8994->pdata;
431 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
432 int value = ucontrol->value.integer.value[0];
433
434 if (block < 0)
435 return block;
436
437 if (value >= pdata->num_retune_mobile_cfgs)
438 return -EINVAL;
439
440 wm8994->retune_mobile_cfg[block] = value;
441
442 wm8994_set_retune_mobile(codec, block);
443
444 return 0;
445}
446
447static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
448 struct snd_ctl_elem_value *ucontrol)
449{
450 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800451 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000452 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
453
454 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
455
456 return 0;
457}
458
Mark Brown96b101e2010-11-18 15:49:38 +0000459static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100460 "Left", "Right"
461};
462
Mark Brown96b101e2010-11-18 15:49:38 +0000463static const struct soc_enum aif1adcl_src =
464 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
465
466static const struct soc_enum aif1adcr_src =
467 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
468
469static const struct soc_enum aif2adcl_src =
470 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
471
472static const struct soc_enum aif2adcr_src =
473 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
474
Mark Brownf5548852010-08-31 19:39:48 +0100475static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000476 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100477
478static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000479 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100480
481static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000482 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100483
484static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000485 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100486
Mark Brown154b26a2010-12-09 12:07:44 +0000487static const char *osr_text[] = {
488 "Low Power", "High Performance",
489};
490
491static const struct soc_enum dac_osr =
492 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
493
494static const struct soc_enum adc_osr =
495 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
496
Mark Brown9e6e96a2010-01-29 17:47:12 +0000497static const struct snd_kcontrol_new wm8994_snd_controls[] = {
498SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
499 WM8994_AIF1_ADC1_RIGHT_VOLUME,
500 1, 119, 0, digital_tlv),
501SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
502 WM8994_AIF1_ADC2_RIGHT_VOLUME,
503 1, 119, 0, digital_tlv),
504SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
505 WM8994_AIF2_ADC_RIGHT_VOLUME,
506 1, 119, 0, digital_tlv),
507
Mark Brown96b101e2010-11-18 15:49:38 +0000508SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
509SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000510SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
511SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000512
Mark Brownf5548852010-08-31 19:39:48 +0100513SOC_ENUM("AIF1DACL Source", aif1dacl_src),
514SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000515SOC_ENUM("AIF2DACL Source", aif2dacl_src),
516SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100517
Mark Brown9e6e96a2010-01-29 17:47:12 +0000518SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
519 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
520SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
521 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
522SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
523 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
524
525SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
526SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
527
528SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
529SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
530SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
531
532WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
533WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
534WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
535
536WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
537WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
538WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
539
540WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
541WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
542WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
543
544SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
545 5, 12, 0, st_tlv),
546SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
547 0, 12, 0, st_tlv),
548SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
549 5, 12, 0, st_tlv),
550SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
551 0, 12, 0, st_tlv),
552SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
553SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
554
Uk Kim146fd572010-12-07 13:58:40 +0000555SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
556SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
557
558SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
559SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
560
561SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
562SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
563
Mark Brown154b26a2010-12-09 12:07:44 +0000564SOC_ENUM("ADC OSR", adc_osr),
565SOC_ENUM("DAC OSR", dac_osr),
566
Mark Brown9e6e96a2010-01-29 17:47:12 +0000567SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
568 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
569SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
570 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
571
572SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
573 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
574SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
575 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
576
577SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
578 6, 1, 1, wm_hubs_spkmix_tlv),
579SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
580 2, 1, 1, wm_hubs_spkmix_tlv),
581
582SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
583 6, 1, 1, wm_hubs_spkmix_tlv),
584SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
585 2, 1, 1, wm_hubs_spkmix_tlv),
586
587SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
588 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000589SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000590 8, 1, 0),
591SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
592 10, 15, 0, wm8994_3d_tlv),
593SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
594 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000595SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000596 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000597SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000598 8, 1, 0),
599};
600
601static const struct snd_kcontrol_new wm8994_eq_controls[] = {
602SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
603 eq_tlv),
604SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
605 eq_tlv),
606SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
607 eq_tlv),
608SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
609 eq_tlv),
610SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
611 eq_tlv),
612
613SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
614 eq_tlv),
615SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
616 eq_tlv),
617SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
618 eq_tlv),
619SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
620 eq_tlv),
621SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
622 eq_tlv),
623
624SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
625 eq_tlv),
626SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
627 eq_tlv),
628SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
629 eq_tlv),
630SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
631 eq_tlv),
632SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
633 eq_tlv),
634};
635
Mark Brown1ddc07d2011-08-16 10:08:48 +0900636static const char *wm8958_ng_text[] = {
637 "30ms", "125ms", "250ms", "500ms",
638};
639
640static const struct soc_enum wm8958_aif1dac1_ng_hold =
641 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
642 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
643
644static const struct soc_enum wm8958_aif1dac2_ng_hold =
645 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
646 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
647
648static const struct soc_enum wm8958_aif2dac_ng_hold =
649 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
650 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
651
Mark Brownc4431df2010-11-26 15:21:07 +0000652static const struct snd_kcontrol_new wm8958_snd_controls[] = {
653SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brown1ddc07d2011-08-16 10:08:48 +0900654
655SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
656 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
657SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
658SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
659 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
660 7, 1, ng_tlv),
661
662SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
663 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
664SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
665SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
666 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
667 7, 1, ng_tlv),
668
669SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
670 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
671SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
672SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
673 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
674 7, 1, ng_tlv),
Mark Brownc4431df2010-11-26 15:21:07 +0000675};
676
Mark Brown81204c82011-05-24 17:35:53 +0800677static const struct snd_kcontrol_new wm1811_snd_controls[] = {
678SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
679 mixin_boost_tlv),
680SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
681 mixin_boost_tlv),
682};
683
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000684/* We run all mode setting through a function to enforce audio mode */
685static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
686{
687 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown1defde22012-03-03 20:02:49 +0000688 u16 old = snd_soc_read(codec, WM8994_ANTIPOP_2)
689 & WM1811_JACKDET_MODE_MASK;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000690
Mark Brown28e33262012-03-03 00:10:02 +0000691 if (!wm8994->jackdet || !wm8994->jack_cb)
692 return;
693
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000694 if (wm8994->active_refcount)
695 mode = WM1811_JACKDET_MODE_AUDIO;
696
Mark Brown1defde22012-03-03 20:02:49 +0000697 if (mode == old)
698 return;
699
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000700 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
701 WM1811_JACKDET_MODE_MASK, mode);
702
Mark Brown1defde22012-03-03 20:02:49 +0000703 switch (mode) {
704 case WM1811_JACKDET_MODE_MIC:
705 case WM1811_JACKDET_MODE_AUDIO:
706 switch (old) {
707 case WM1811_JACKDET_MODE_MIC:
708 case WM1811_JACKDET_MODE_AUDIO:
709 break;
710 default:
711 msleep(2);
712 break;
713 }
714
715 default:
716 break;
717 }
718
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000719}
720
721static void active_reference(struct snd_soc_codec *codec)
722{
723 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
724
725 mutex_lock(&wm8994->accdet_lock);
726
727 wm8994->active_refcount++;
728
729 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
730 wm8994->active_refcount);
731
Mark Brown1defde22012-03-03 20:02:49 +0000732 /* If we're using jack detection go into audio mode */
733 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000734
735 mutex_unlock(&wm8994->accdet_lock);
736}
737
738static void active_dereference(struct snd_soc_codec *codec)
739{
740 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
741 u16 mode;
742
743 mutex_lock(&wm8994->accdet_lock);
744
745 wm8994->active_refcount--;
746
747 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
748 wm8994->active_refcount);
749
750 if (wm8994->active_refcount == 0) {
751 /* Go into appropriate detection only mode */
Mark Brown1defde22012-03-03 20:02:49 +0000752 if (wm8994->jack_mic || wm8994->mic_detecting)
753 mode = WM1811_JACKDET_MODE_MIC;
754 else
755 mode = WM1811_JACKDET_MODE_JACK;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000756
Mark Brown1defde22012-03-03 20:02:49 +0000757 wm1811_jackdet_set_mode(codec, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000758 }
759
760 mutex_unlock(&wm8994->accdet_lock);
761}
762
Mark Brown9e6e96a2010-01-29 17:47:12 +0000763static int clk_sys_event(struct snd_soc_dapm_widget *w,
764 struct snd_kcontrol *kcontrol, int event)
765{
766 struct snd_soc_codec *codec = w->codec;
767
768 switch (event) {
769 case SND_SOC_DAPM_PRE_PMU:
770 return configure_clock(codec);
771
772 case SND_SOC_DAPM_POST_PMD:
773 configure_clock(codec);
774 break;
775 }
776
777 return 0;
778}
779
Mark Brown4b7ed832011-08-10 17:47:33 +0900780static void vmid_reference(struct snd_soc_codec *codec)
781{
782 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
783
Mark Browndb966f82012-02-06 12:07:08 +0000784 pm_runtime_get_sync(codec->dev);
785
Mark Brown4b7ed832011-08-10 17:47:33 +0900786 wm8994->vmid_refcount++;
787
788 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
789 wm8994->vmid_refcount);
790
791 if (wm8994->vmid_refcount == 1) {
Mark Browncc6d5a82012-02-11 23:09:53 +0000792 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
793 WM8994_LINEOUT_VMID_BUF_ENA |
794 WM8994_LINEOUT1_DISCH |
795 WM8994_LINEOUT2_DISCH,
796 WM8994_LINEOUT_VMID_BUF_ENA);
797
Mark Brownf7085642012-02-21 16:24:00 +0000798 wm_hubs_vmid_ena(codec);
799
Mark Brown4b7ed832011-08-10 17:47:33 +0900800 /* Startup bias, VMID ramp & buffer */
801 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
Mark Browncc6d5a82012-02-11 23:09:53 +0000802 WM8994_BIAS_SRC |
803 WM8994_VMID_DISCH |
Mark Brown4b7ed832011-08-10 17:47:33 +0900804 WM8994_STARTUP_BIAS_ENA |
805 WM8994_VMID_BUF_ENA |
806 WM8994_VMID_RAMP_MASK,
Mark Browncc6d5a82012-02-11 23:09:53 +0000807 WM8994_BIAS_SRC |
Mark Brown4b7ed832011-08-10 17:47:33 +0900808 WM8994_STARTUP_BIAS_ENA |
809 WM8994_VMID_BUF_ENA |
Mark Brown65f01ef2012-02-14 17:53:55 -0800810 (0x2 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900811
812 /* Main bias enable, VMID=2x40k */
813 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
814 WM8994_BIAS_ENA |
815 WM8994_VMID_SEL_MASK,
816 WM8994_BIAS_ENA | 0x2);
817
Mark Browncc6d5a82012-02-11 23:09:53 +0000818 msleep(50);
819
820 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
821 WM8994_VMID_RAMP_MASK | WM8994_BIAS_SRC,
822 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900823 }
824}
825
826static void vmid_dereference(struct snd_soc_codec *codec)
827{
828 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
829
830 wm8994->vmid_refcount--;
831
832 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
833 wm8994->vmid_refcount);
834
835 if (wm8994->vmid_refcount == 0) {
836 /* Switch over to startup biases */
837 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
838 WM8994_BIAS_SRC |
839 WM8994_STARTUP_BIAS_ENA |
840 WM8994_VMID_BUF_ENA |
841 WM8994_VMID_RAMP_MASK,
842 WM8994_BIAS_SRC |
843 WM8994_STARTUP_BIAS_ENA |
844 WM8994_VMID_BUF_ENA |
845 (1 << WM8994_VMID_RAMP_SHIFT));
846
847 /* Disable main biases */
848 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
849 WM8994_BIAS_ENA |
850 WM8994_VMID_SEL_MASK, 0);
851
Mark Browne85b26c2012-02-11 23:10:30 +0000852 /* Discharge VMID */
853 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
854 WM8994_VMID_DISCH, WM8994_VMID_DISCH);
855
Mark Brown4b7ed832011-08-10 17:47:33 +0900856 /* Discharge line */
857 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
858 WM8994_LINEOUT1_DISCH |
859 WM8994_LINEOUT2_DISCH,
860 WM8994_LINEOUT1_DISCH |
861 WM8994_LINEOUT2_DISCH);
862
863 msleep(5);
864
865 /* Switch off startup biases */
866 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
867 WM8994_BIAS_SRC |
868 WM8994_STARTUP_BIAS_ENA |
869 WM8994_VMID_BUF_ENA |
870 WM8994_VMID_RAMP_MASK, 0);
871 }
Mark Browndb966f82012-02-06 12:07:08 +0000872
873 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900874}
875
876static int vmid_event(struct snd_soc_dapm_widget *w,
877 struct snd_kcontrol *kcontrol, int event)
878{
879 struct snd_soc_codec *codec = w->codec;
880
881 switch (event) {
882 case SND_SOC_DAPM_PRE_PMU:
883 vmid_reference(codec);
884 break;
885
886 case SND_SOC_DAPM_POST_PMD:
887 vmid_dereference(codec);
888 break;
889 }
890
891 return 0;
892}
893
Mark Brown9e6e96a2010-01-29 17:47:12 +0000894static void wm8994_update_class_w(struct snd_soc_codec *codec)
895{
Mark Brownfec6dd82010-10-27 13:48:36 -0700896 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000897 int enable = 1;
898 int source = 0; /* GCC flow analysis can't track enable */
899 int reg, reg_r;
900
901 /* Only support direct DAC->headphone paths */
902 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
903 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900904 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000905 enable = 0;
906 }
907
908 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
909 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900910 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000911 enable = 0;
912 }
913
914 /* We also need the same setting for L/R and only one path */
915 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
916 switch (reg) {
917 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900918 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000919 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
920 break;
921 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900922 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000923 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
924 break;
925 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900926 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000927 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
928 break;
929 default:
Mark Brownee839a22010-04-20 13:57:08 +0900930 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000931 enable = 0;
932 break;
933 }
934
935 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
936 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900937 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000938 enable = 0;
939 }
940
941 if (enable) {
942 dev_dbg(codec->dev, "Class W enabled\n");
943 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
944 WM8994_CP_DYN_PWR |
945 WM8994_CP_DYN_SRC_SEL_MASK,
946 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700947 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000948
949 } else {
950 dev_dbg(codec->dev, "Class W disabled\n");
951 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
952 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700953 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000954 }
955}
956
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000957static int late_enable_ev(struct snd_soc_dapm_widget *w,
958 struct snd_kcontrol *kcontrol, int event)
959{
960 struct snd_soc_codec *codec = w->codec;
961 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
962
963 switch (event) {
964 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000965 if (wm8994->aif1clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000966 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
967 WM8994_AIF1CLK_ENA_MASK,
968 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000969 wm8994->aif1clk_enable = 0;
970 }
971 if (wm8994->aif2clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000972 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
973 WM8994_AIF2CLK_ENA_MASK,
974 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000975 wm8994->aif2clk_enable = 0;
976 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000977 break;
978 }
979
Mark Brownc6b7b572011-03-11 18:13:12 +0000980 /* We may also have postponed startup of DSP, handle that. */
981 wm8958_aif_ev(w, kcontrol, event);
982
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000983 return 0;
984}
985
986static int late_disable_ev(struct snd_soc_dapm_widget *w,
987 struct snd_kcontrol *kcontrol, int event)
988{
989 struct snd_soc_codec *codec = w->codec;
990 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
991
992 switch (event) {
993 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000994 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000995 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
996 WM8994_AIF1CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000997 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000998 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000999 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001000 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1001 WM8994_AIF2CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001002 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001003 }
1004 break;
1005 }
1006
1007 return 0;
1008}
1009
1010static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1011 struct snd_kcontrol *kcontrol, int event)
1012{
1013 struct snd_soc_codec *codec = w->codec;
1014 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1015
1016 switch (event) {
1017 case SND_SOC_DAPM_PRE_PMU:
1018 wm8994->aif1clk_enable = 1;
1019 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001020 case SND_SOC_DAPM_POST_PMD:
1021 wm8994->aif1clk_disable = 1;
1022 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001023 }
1024
1025 return 0;
1026}
1027
1028static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1029 struct snd_kcontrol *kcontrol, int event)
1030{
1031 struct snd_soc_codec *codec = w->codec;
1032 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1033
1034 switch (event) {
1035 case SND_SOC_DAPM_PRE_PMU:
1036 wm8994->aif2clk_enable = 1;
1037 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001038 case SND_SOC_DAPM_POST_PMD:
1039 wm8994->aif2clk_disable = 1;
1040 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001041 }
1042
1043 return 0;
1044}
1045
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001046static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1047 struct snd_kcontrol *kcontrol, int event)
1048{
1049 late_enable_ev(w, kcontrol, event);
1050 return 0;
1051}
1052
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001053static int micbias_ev(struct snd_soc_dapm_widget *w,
1054 struct snd_kcontrol *kcontrol, int event)
1055{
1056 late_enable_ev(w, kcontrol, event);
1057 return 0;
1058}
1059
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001060static int dac_ev(struct snd_soc_dapm_widget *w,
1061 struct snd_kcontrol *kcontrol, int event)
1062{
1063 struct snd_soc_codec *codec = w->codec;
1064 unsigned int mask = 1 << w->shift;
1065
1066 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1067 mask, mask);
1068 return 0;
1069}
1070
Mark Brown9e6e96a2010-01-29 17:47:12 +00001071static const char *hp_mux_text[] = {
1072 "Mixer",
1073 "DAC",
1074};
1075
1076#define WM8994_HP_ENUM(xname, xenum) \
1077{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1078 .info = snd_soc_info_enum_double, \
1079 .get = snd_soc_dapm_get_enum_double, \
1080 .put = wm8994_put_hp_enum, \
1081 .private_value = (unsigned long)&xenum }
1082
1083static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1084 struct snd_ctl_elem_value *ucontrol)
1085{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001086 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1087 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001088 struct snd_soc_codec *codec = w->codec;
1089 int ret;
1090
1091 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1092
1093 wm8994_update_class_w(codec);
1094
1095 return ret;
1096}
1097
1098static const struct soc_enum hpl_enum =
1099 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1100
1101static const struct snd_kcontrol_new hpl_mux =
1102 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1103
1104static const struct soc_enum hpr_enum =
1105 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1106
1107static const struct snd_kcontrol_new hpr_mux =
1108 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1109
1110static const char *adc_mux_text[] = {
1111 "ADC",
1112 "DMIC",
1113};
1114
1115static const struct soc_enum adc_enum =
1116 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1117
1118static const struct snd_kcontrol_new adcl_mux =
1119 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1120
1121static const struct snd_kcontrol_new adcr_mux =
1122 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1123
1124static const struct snd_kcontrol_new left_speaker_mixer[] = {
1125SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1126SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1127SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1128SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1129SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1130};
1131
1132static const struct snd_kcontrol_new right_speaker_mixer[] = {
1133SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1134SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1135SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1136SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1137SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1138};
1139
1140/* Debugging; dump chip status after DAPM transitions */
1141static int post_ev(struct snd_soc_dapm_widget *w,
1142 struct snd_kcontrol *kcontrol, int event)
1143{
1144 struct snd_soc_codec *codec = w->codec;
1145 dev_dbg(codec->dev, "SRC status: %x\n",
1146 snd_soc_read(codec,
1147 WM8994_RATE_STATUS));
1148 return 0;
1149}
1150
1151static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1152SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1153 1, 1, 0),
1154SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1155 0, 1, 0),
1156};
1157
1158static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1159SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1160 1, 1, 0),
1161SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1162 0, 1, 0),
1163};
1164
Mark Browna3257ba2010-07-19 14:02:34 +01001165static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1166SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1167 1, 1, 0),
1168SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1169 0, 1, 0),
1170};
1171
1172static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1173SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1174 1, 1, 0),
1175SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1176 0, 1, 0),
1177};
1178
Mark Brown9e6e96a2010-01-29 17:47:12 +00001179static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1180SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1181 5, 1, 0),
1182SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1183 4, 1, 0),
1184SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1185 2, 1, 0),
1186SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1187 1, 1, 0),
1188SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1189 0, 1, 0),
1190};
1191
1192static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1193SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1194 5, 1, 0),
1195SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1196 4, 1, 0),
1197SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1198 2, 1, 0),
1199SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1200 1, 1, 0),
1201SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1202 0, 1, 0),
1203};
1204
1205#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1206{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1207 .info = snd_soc_info_volsw, \
1208 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1209 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1210
1211static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1212 struct snd_ctl_elem_value *ucontrol)
1213{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001214 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1215 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001216 struct snd_soc_codec *codec = w->codec;
1217 int ret;
1218
1219 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1220
1221 wm8994_update_class_w(codec);
1222
1223 return ret;
1224}
1225
1226static const struct snd_kcontrol_new dac1l_mix[] = {
1227WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1228 5, 1, 0),
1229WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1230 4, 1, 0),
1231WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1232 2, 1, 0),
1233WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1234 1, 1, 0),
1235WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1236 0, 1, 0),
1237};
1238
1239static const struct snd_kcontrol_new dac1r_mix[] = {
1240WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1241 5, 1, 0),
1242WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1243 4, 1, 0),
1244WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1245 2, 1, 0),
1246WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1247 1, 1, 0),
1248WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1249 0, 1, 0),
1250};
1251
1252static const char *sidetone_text[] = {
1253 "ADC/DMIC1", "DMIC2",
1254};
1255
1256static const struct soc_enum sidetone1_enum =
1257 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1258
1259static const struct snd_kcontrol_new sidetone1_mux =
1260 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1261
1262static const struct soc_enum sidetone2_enum =
1263 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1264
1265static const struct snd_kcontrol_new sidetone2_mux =
1266 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1267
1268static const char *aif1dac_text[] = {
1269 "AIF1DACDAT", "AIF3DACDAT",
1270};
1271
1272static const struct soc_enum aif1dac_enum =
1273 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1274
1275static const struct snd_kcontrol_new aif1dac_mux =
1276 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1277
1278static const char *aif2dac_text[] = {
1279 "AIF2DACDAT", "AIF3DACDAT",
1280};
1281
1282static const struct soc_enum aif2dac_enum =
1283 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1284
1285static const struct snd_kcontrol_new aif2dac_mux =
1286 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1287
1288static const char *aif2adc_text[] = {
1289 "AIF2ADCDAT", "AIF3DACDAT",
1290};
1291
1292static const struct soc_enum aif2adc_enum =
1293 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1294
1295static const struct snd_kcontrol_new aif2adc_mux =
1296 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1297
1298static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001299 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001300};
1301
Mark Brownc4431df2010-11-26 15:21:07 +00001302static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001303 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1304
Mark Brownc4431df2010-11-26 15:21:07 +00001305static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1306 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1307
1308static const struct soc_enum wm8958_aif3adc_enum =
1309 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1310
1311static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1312 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1313
1314static const char *mono_pcm_out_text[] = {
1315 "None", "AIF2ADCL", "AIF2ADCR",
1316};
1317
1318static const struct soc_enum mono_pcm_out_enum =
1319 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1320
1321static const struct snd_kcontrol_new mono_pcm_out_mux =
1322 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1323
1324static const char *aif2dac_src_text[] = {
1325 "AIF2", "AIF3",
1326};
1327
1328/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1329static const struct soc_enum aif2dacl_src_enum =
1330 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1331
1332static const struct snd_kcontrol_new aif2dacl_src_mux =
1333 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1334
1335static const struct soc_enum aif2dacr_src_enum =
1336 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1337
1338static const struct snd_kcontrol_new aif2dacr_src_mux =
1339 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001340
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001341static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1342SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1343 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1344SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1345 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1346
1347SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1348 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1349SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1350 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1351SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1352 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1353SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1354 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001355SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1356 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1357
1358SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1359 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1360 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1361SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1362 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1363 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1364SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1365 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1366SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1367 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001368
1369SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1370};
1371
1372static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1373SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
Mark Brownb70a51b2011-06-29 00:21:09 -07001374SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
1375SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1376SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1377 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1378SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1379 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1380SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1381SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001382};
1383
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001384static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1385SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1386 dac_ev, SND_SOC_DAPM_PRE_PMU),
1387SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1388 dac_ev, SND_SOC_DAPM_PRE_PMU),
1389SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1390 dac_ev, SND_SOC_DAPM_PRE_PMU),
1391SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1392 dac_ev, SND_SOC_DAPM_PRE_PMU),
1393};
1394
1395static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1396SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001397SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001398SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1399SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1400};
1401
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001402static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001403SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1404 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1405SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1406 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001407};
1408
1409static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001410SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1411SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001412};
1413
Mark Brown9e6e96a2010-01-29 17:47:12 +00001414static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1415SND_SOC_DAPM_INPUT("DMIC1DAT"),
1416SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001417SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001418
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001419SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1420 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001421SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1422 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001423
Mark Brown9e6e96a2010-01-29 17:47:12 +00001424SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1425 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1426
1427SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1428SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1429SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1430
Mark Brown7f94de42011-02-03 16:27:34 +00001431SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001432 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001433SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001434 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001435SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1436 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001437 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001438SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1439 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001440 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001441
Mark Brown7f94de42011-02-03 16:27:34 +00001442SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001443 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001444SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001445 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001446SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1447 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001448 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001449SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1450 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001451 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001452
1453SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1454 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1455SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1456 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1457
Mark Browna3257ba2010-07-19 14:02:34 +01001458SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1459 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1460SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1461 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1462
Mark Brown9e6e96a2010-01-29 17:47:12 +00001463SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1464 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1465SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1466 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1467
1468SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1469SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1470
1471SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1472 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1473SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1474 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1475
1476SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1477 WM8994_POWER_MANAGEMENT_4, 13, 0),
1478SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1479 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001480SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1481 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1482 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1483SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1484 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1485 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001486
Mark Brown5567d8c2012-02-16 21:43:29 -08001487SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1488SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1489SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1490SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001491
1492SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1493SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1494SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001495
Mark Brown5567d8c2012-02-16 21:43:29 -08001496SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1497SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001498
1499SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1500
1501SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1502SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1503SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1504SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1505
1506/* Power is done with the muxes since the ADC power also controls the
1507 * downsampling chain, the chip will automatically manage the analogue
1508 * specific portions.
1509 */
1510SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1511SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1512
Mark Brown9e6e96a2010-01-29 17:47:12 +00001513SND_SOC_DAPM_POST("Debug log", post_ev),
1514};
1515
Mark Brownc4431df2010-11-26 15:21:07 +00001516static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1517SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1518};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001519
Mark Brownc4431df2010-11-26 15:21:07 +00001520static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1521SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1522SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1523SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1524SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1525};
1526
1527static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001528 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1529 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1530
1531 { "DSP1CLK", NULL, "CLK_SYS" },
1532 { "DSP2CLK", NULL, "CLK_SYS" },
1533 { "DSPINTCLK", NULL, "CLK_SYS" },
1534
1535 { "AIF1ADC1L", NULL, "AIF1CLK" },
1536 { "AIF1ADC1L", NULL, "DSP1CLK" },
1537 { "AIF1ADC1R", NULL, "AIF1CLK" },
1538 { "AIF1ADC1R", NULL, "DSP1CLK" },
1539 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1540
1541 { "AIF1DAC1L", NULL, "AIF1CLK" },
1542 { "AIF1DAC1L", NULL, "DSP1CLK" },
1543 { "AIF1DAC1R", NULL, "AIF1CLK" },
1544 { "AIF1DAC1R", NULL, "DSP1CLK" },
1545 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1546
1547 { "AIF1ADC2L", NULL, "AIF1CLK" },
1548 { "AIF1ADC2L", NULL, "DSP1CLK" },
1549 { "AIF1ADC2R", NULL, "AIF1CLK" },
1550 { "AIF1ADC2R", NULL, "DSP1CLK" },
1551 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1552
1553 { "AIF1DAC2L", NULL, "AIF1CLK" },
1554 { "AIF1DAC2L", NULL, "DSP1CLK" },
1555 { "AIF1DAC2R", NULL, "AIF1CLK" },
1556 { "AIF1DAC2R", NULL, "DSP1CLK" },
1557 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1558
1559 { "AIF2ADCL", NULL, "AIF2CLK" },
1560 { "AIF2ADCL", NULL, "DSP2CLK" },
1561 { "AIF2ADCR", NULL, "AIF2CLK" },
1562 { "AIF2ADCR", NULL, "DSP2CLK" },
1563 { "AIF2ADCR", NULL, "DSPINTCLK" },
1564
1565 { "AIF2DACL", NULL, "AIF2CLK" },
1566 { "AIF2DACL", NULL, "DSP2CLK" },
1567 { "AIF2DACR", NULL, "AIF2CLK" },
1568 { "AIF2DACR", NULL, "DSP2CLK" },
1569 { "AIF2DACR", NULL, "DSPINTCLK" },
1570
1571 { "DMIC1L", NULL, "DMIC1DAT" },
1572 { "DMIC1L", NULL, "CLK_SYS" },
1573 { "DMIC1R", NULL, "DMIC1DAT" },
1574 { "DMIC1R", NULL, "CLK_SYS" },
1575 { "DMIC2L", NULL, "DMIC2DAT" },
1576 { "DMIC2L", NULL, "CLK_SYS" },
1577 { "DMIC2R", NULL, "DMIC2DAT" },
1578 { "DMIC2R", NULL, "CLK_SYS" },
1579
1580 { "ADCL", NULL, "AIF1CLK" },
1581 { "ADCL", NULL, "DSP1CLK" },
1582 { "ADCL", NULL, "DSPINTCLK" },
1583
1584 { "ADCR", NULL, "AIF1CLK" },
1585 { "ADCR", NULL, "DSP1CLK" },
1586 { "ADCR", NULL, "DSPINTCLK" },
1587
1588 { "ADCL Mux", "ADC", "ADCL" },
1589 { "ADCL Mux", "DMIC", "DMIC1L" },
1590 { "ADCR Mux", "ADC", "ADCR" },
1591 { "ADCR Mux", "DMIC", "DMIC1R" },
1592
1593 { "DAC1L", NULL, "AIF1CLK" },
1594 { "DAC1L", NULL, "DSP1CLK" },
1595 { "DAC1L", NULL, "DSPINTCLK" },
1596
1597 { "DAC1R", NULL, "AIF1CLK" },
1598 { "DAC1R", NULL, "DSP1CLK" },
1599 { "DAC1R", NULL, "DSPINTCLK" },
1600
1601 { "DAC2L", NULL, "AIF2CLK" },
1602 { "DAC2L", NULL, "DSP2CLK" },
1603 { "DAC2L", NULL, "DSPINTCLK" },
1604
1605 { "DAC2R", NULL, "AIF2DACR" },
1606 { "DAC2R", NULL, "AIF2CLK" },
1607 { "DAC2R", NULL, "DSP2CLK" },
1608 { "DAC2R", NULL, "DSPINTCLK" },
1609
1610 { "TOCLK", NULL, "CLK_SYS" },
1611
Mark Brown5567d8c2012-02-16 21:43:29 -08001612 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1613 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1614 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1615
1616 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1617 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1618 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1619
Mark Brown9e6e96a2010-01-29 17:47:12 +00001620 /* AIF1 outputs */
1621 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1622 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1623 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1624
1625 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1626 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1627 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1628
Mark Browna3257ba2010-07-19 14:02:34 +01001629 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1630 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1631 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1632
1633 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1634 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1635 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1636
Mark Brown9e6e96a2010-01-29 17:47:12 +00001637 /* Pin level routing for AIF3 */
1638 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1639 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1640 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1641 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1642
Mark Brown9e6e96a2010-01-29 17:47:12 +00001643 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1644 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1645 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1646 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1647 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1648 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1649 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1650
1651 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001652 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1653 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1654 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1655 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1656 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1657
Mark Brown9e6e96a2010-01-29 17:47:12 +00001658 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1659 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1660 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1661 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1662 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1663
1664 /* DAC2/AIF2 outputs */
1665 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001666 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1667 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1668 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1669 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1670 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1671
1672 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001673 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1674 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1675 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1676 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1677 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1678
Mark Brown7f94de42011-02-03 16:27:34 +00001679 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1680 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1681 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1682 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1683
Mark Brown9e6e96a2010-01-29 17:47:12 +00001684 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1685
1686 /* AIF3 output */
1687 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1688 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1689 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1690 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1691 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1692 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1693 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1694 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1695
1696 /* Sidetone */
1697 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1698 { "Left Sidetone", "DMIC2", "DMIC2L" },
1699 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1700 { "Right Sidetone", "DMIC2", "DMIC2R" },
1701
1702 /* Output stages */
1703 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1704 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1705
1706 { "SPKL", "DAC1 Switch", "DAC1L" },
1707 { "SPKL", "DAC2 Switch", "DAC2L" },
1708
1709 { "SPKR", "DAC1 Switch", "DAC1R" },
1710 { "SPKR", "DAC2 Switch", "DAC2R" },
1711
1712 { "Left Headphone Mux", "DAC", "DAC1L" },
1713 { "Right Headphone Mux", "DAC", "DAC1R" },
1714};
1715
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001716static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1717 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1718 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1719 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1720 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1721 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1722 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1723 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1724 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1725};
1726
1727static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1728 { "DAC1L", NULL, "DAC1L Mixer" },
1729 { "DAC1R", NULL, "DAC1R Mixer" },
1730 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1731 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1732};
1733
Mark Brown6ed8f142011-02-03 16:27:35 +00001734static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1735 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1736 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1737 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1738 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001739 { "MICBIAS1", NULL, "CLK_SYS" },
1740 { "MICBIAS1", NULL, "MICBIAS Supply" },
1741 { "MICBIAS2", NULL, "CLK_SYS" },
1742 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001743};
1744
Mark Brownc4431df2010-11-26 15:21:07 +00001745static const struct snd_soc_dapm_route wm8994_intercon[] = {
1746 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1747 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001748 { "MICBIAS1", NULL, "VMID" },
1749 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001750};
1751
1752static const struct snd_soc_dapm_route wm8958_intercon[] = {
1753 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1754 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1755
1756 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1757 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1758 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1759 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1760
1761 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1762 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1763
1764 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1765};
1766
Mark Brown9e6e96a2010-01-29 17:47:12 +00001767/* The size in bits of the FLL divide multiplied by 10
1768 * to allow rounding later */
1769#define FIXED_FLL_SIZE ((1 << 16) * 10)
1770
1771struct fll_div {
1772 u16 outdiv;
1773 u16 n;
1774 u16 k;
1775 u16 clk_ref_div;
1776 u16 fll_fratio;
1777};
1778
1779static int wm8994_get_fll_config(struct fll_div *fll,
1780 int freq_in, int freq_out)
1781{
1782 u64 Kpart;
1783 unsigned int K, Ndiv, Nmod;
1784
1785 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1786
1787 /* Scale the input frequency down to <= 13.5MHz */
1788 fll->clk_ref_div = 0;
1789 while (freq_in > 13500000) {
1790 fll->clk_ref_div++;
1791 freq_in /= 2;
1792
1793 if (fll->clk_ref_div > 3)
1794 return -EINVAL;
1795 }
1796 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1797
1798 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1799 fll->outdiv = 3;
1800 while (freq_out * (fll->outdiv + 1) < 90000000) {
1801 fll->outdiv++;
1802 if (fll->outdiv > 63)
1803 return -EINVAL;
1804 }
1805 freq_out *= fll->outdiv + 1;
1806 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1807
1808 if (freq_in > 1000000) {
1809 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001810 } else if (freq_in > 256000) {
1811 fll->fll_fratio = 1;
1812 freq_in *= 2;
1813 } else if (freq_in > 128000) {
1814 fll->fll_fratio = 2;
1815 freq_in *= 4;
1816 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001817 fll->fll_fratio = 3;
1818 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001819 } else {
1820 fll->fll_fratio = 4;
1821 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001822 }
1823 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1824
1825 /* Now, calculate N.K */
1826 Ndiv = freq_out / freq_in;
1827
1828 fll->n = Ndiv;
1829 Nmod = freq_out % freq_in;
1830 pr_debug("Nmod=%d\n", Nmod);
1831
1832 /* Calculate fractional part - scale up so we can round. */
1833 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1834
1835 do_div(Kpart, freq_in);
1836
1837 K = Kpart & 0xFFFFFFFF;
1838
1839 if ((K % 10) >= 5)
1840 K += 5;
1841
1842 /* Move down to proper range now rounding is done */
1843 fll->k = K / 10;
1844
1845 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1846
1847 return 0;
1848}
1849
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001850static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001851 unsigned int freq_in, unsigned int freq_out)
1852{
Mark Brownb2c812e2010-04-14 15:35:19 +09001853 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01001854 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001855 int reg_offset, ret;
1856 struct fll_div fll;
1857 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001858 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001859 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001860
1861 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1862 & WM8994_AIF1CLK_ENA;
1863
1864 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1865 & WM8994_AIF2CLK_ENA;
1866
1867 switch (id) {
1868 case WM8994_FLL1:
1869 reg_offset = 0;
1870 id = 0;
1871 break;
1872 case WM8994_FLL2:
1873 reg_offset = 0x20;
1874 id = 1;
1875 break;
1876 default:
1877 return -EINVAL;
1878 }
1879
Mark Brown4b7ed832011-08-10 17:47:33 +09001880 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1881 was_enabled = reg & WM8994_FLL1_ENA;
1882
Mark Brown136ff2a2010-04-20 12:56:18 +09001883 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001884 case 0:
1885 /* Allow no source specification when stopping */
1886 if (freq_out)
1887 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001888 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001889 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001890 case WM8994_FLL_SRC_MCLK1:
1891 case WM8994_FLL_SRC_MCLK2:
1892 case WM8994_FLL_SRC_LRCLK:
1893 case WM8994_FLL_SRC_BCLK:
1894 break;
1895 default:
1896 return -EINVAL;
1897 }
1898
Mark Brown9e6e96a2010-01-29 17:47:12 +00001899 /* Are we changing anything? */
1900 if (wm8994->fll[id].src == src &&
1901 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1902 return 0;
1903
1904 /* If we're stopping the FLL redo the old config - no
1905 * registers will actually be written but we avoid GCC flow
1906 * analysis bugs spewing warnings.
1907 */
1908 if (freq_out)
1909 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1910 else
1911 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1912 wm8994->fll[id].out);
1913 if (ret < 0)
1914 return ret;
1915
1916 /* Gate the AIF clocks while we reclock */
1917 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1918 WM8994_AIF1CLK_ENA, 0);
1919 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1920 WM8994_AIF2CLK_ENA, 0);
1921
1922 /* We always need to disable the FLL while reconfiguring */
1923 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1924 WM8994_FLL1_ENA, 0);
1925
1926 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1927 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1928 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1929 WM8994_FLL1_OUTDIV_MASK |
1930 WM8994_FLL1_FRATIO_MASK, reg);
1931
Mark Brownb16db742012-03-03 15:33:23 +00001932 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
1933 WM8994_FLL1_K_MASK, fll.k);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001934
1935 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1936 WM8994_FLL1_N_MASK,
1937 fll.n << WM8994_FLL1_N_SHIFT);
1938
1939 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001940 WM8994_FLL1_REFCLK_DIV_MASK |
1941 WM8994_FLL1_REFCLK_SRC_MASK,
1942 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1943 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001944
Mark Brownf0f50392011-07-16 03:12:18 +09001945 /* Clear any pending completion from a previous failure */
1946 try_wait_for_completion(&wm8994->fll_locked[id]);
1947
Mark Brown9e6e96a2010-01-29 17:47:12 +00001948 /* Enable (with fractional mode if required) */
1949 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001950 /* Enable VMID if we need it */
1951 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001952 active_reference(codec);
1953
Mark Brown4b7ed832011-08-10 17:47:33 +09001954 switch (control->type) {
1955 case WM8994:
1956 vmid_reference(codec);
1957 break;
1958 case WM8958:
1959 if (wm8994->revision < 1)
1960 vmid_reference(codec);
1961 break;
1962 default:
1963 break;
1964 }
1965 }
1966
Mark Brown9e6e96a2010-01-29 17:47:12 +00001967 if (fll.k)
1968 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1969 else
1970 reg = WM8994_FLL1_ENA;
1971 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1972 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1973 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001974
Mark Brownc7ebf932011-07-12 19:47:59 +09001975 if (wm8994->fll_locked_irq) {
1976 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1977 msecs_to_jiffies(10));
1978 if (timeout == 0)
1979 dev_warn(codec->dev,
1980 "Timed out waiting for FLL lock\n");
1981 } else {
1982 msleep(5);
1983 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001984 } else {
1985 if (was_enabled) {
1986 switch (control->type) {
1987 case WM8994:
1988 vmid_dereference(codec);
1989 break;
1990 case WM8958:
1991 if (wm8994->revision < 1)
1992 vmid_dereference(codec);
1993 break;
1994 default:
1995 break;
1996 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001997
1998 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001999 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002000 }
2001
2002 wm8994->fll[id].in = freq_in;
2003 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09002004 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002005
2006 /* Enable any gated AIF clocks */
2007 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
2008 WM8994_AIF1CLK_ENA, aif1);
2009 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
2010 WM8994_AIF2CLK_ENA, aif2);
2011
2012 configure_clock(codec);
2013
2014 return 0;
2015}
2016
Mark Brownc7ebf932011-07-12 19:47:59 +09002017static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2018{
2019 struct completion *completion = data;
2020
2021 complete(completion);
2022
2023 return IRQ_HANDLED;
2024}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002025
Mark Brown66b47fd2010-07-08 11:25:43 +09002026static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2027
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002028static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2029 unsigned int freq_in, unsigned int freq_out)
2030{
2031 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2032}
2033
Mark Brown9e6e96a2010-01-29 17:47:12 +00002034static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2035 int clk_id, unsigned int freq, int dir)
2036{
2037 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002038 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002039 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002040
2041 switch (dai->id) {
2042 case 1:
2043 case 2:
2044 break;
2045
2046 default:
2047 /* AIF3 shares clocking with AIF1/2 */
2048 return -EINVAL;
2049 }
2050
2051 switch (clk_id) {
2052 case WM8994_SYSCLK_MCLK1:
2053 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2054 wm8994->mclk[0] = freq;
2055 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2056 dai->id, freq);
2057 break;
2058
2059 case WM8994_SYSCLK_MCLK2:
2060 /* TODO: Set GPIO AF */
2061 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2062 wm8994->mclk[1] = freq;
2063 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2064 dai->id, freq);
2065 break;
2066
2067 case WM8994_SYSCLK_FLL1:
2068 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2069 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2070 break;
2071
2072 case WM8994_SYSCLK_FLL2:
2073 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2074 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2075 break;
2076
Mark Brown66b47fd2010-07-08 11:25:43 +09002077 case WM8994_SYSCLK_OPCLK:
2078 /* Special case - a division (times 10) is given and
2079 * no effect on main clocking.
2080 */
2081 if (freq) {
2082 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2083 if (opclk_divs[i] == freq)
2084 break;
2085 if (i == ARRAY_SIZE(opclk_divs))
2086 return -EINVAL;
2087 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2088 WM8994_OPCLK_DIV_MASK, i);
2089 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2090 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2091 } else {
2092 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2093 WM8994_OPCLK_ENA, 0);
2094 }
2095
Mark Brown9e6e96a2010-01-29 17:47:12 +00002096 default:
2097 return -EINVAL;
2098 }
2099
2100 configure_clock(codec);
2101
2102 return 0;
2103}
2104
2105static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2106 enum snd_soc_bias_level level)
2107{
Mark Brownb6b05692010-08-13 12:58:20 +01002108 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002109 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002110
Mark Brown5f2f3892012-02-08 18:51:42 +00002111 wm_hubs_set_bias_level(codec, level);
2112
Mark Brown9e6e96a2010-01-29 17:47:12 +00002113 switch (level) {
2114 case SND_SOC_BIAS_ON:
2115 break;
2116
2117 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002118 /* MICBIAS into regulating mode */
2119 switch (control->type) {
2120 case WM8958:
2121 case WM1811:
2122 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2123 WM8958_MICB1_MODE, 0);
2124 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2125 WM8958_MICB2_MODE, 0);
2126 break;
2127 default:
2128 break;
2129 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002130
2131 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2132 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002133 break;
2134
2135 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002136 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002137 switch (control->type) {
2138 case WM8994:
2139 if (wm8994->revision < 4) {
2140 /* Tweak DC servo and DSP
2141 * configuration for improved
2142 * performance. */
2143 snd_soc_write(codec, 0x102, 0x3);
2144 snd_soc_write(codec, 0x56, 0x3);
2145 snd_soc_write(codec, 0x817, 0);
2146 snd_soc_write(codec, 0x102, 0);
2147 }
2148 break;
2149
2150 case WM8958:
2151 if (wm8994->revision == 0) {
2152 /* Optimise performance for rev A */
2153 snd_soc_write(codec, 0x102, 0x3);
2154 snd_soc_write(codec, 0xcb, 0x81);
2155 snd_soc_write(codec, 0x817, 0);
2156 snd_soc_write(codec, 0x102, 0);
2157
2158 snd_soc_update_bits(codec,
2159 WM8958_CHARGE_PUMP_2,
2160 WM8958_CP_DISCH,
2161 WM8958_CP_DISCH);
2162 }
2163 break;
Mark Brown81204c82011-05-24 17:35:53 +08002164
2165 case WM1811:
2166 if (wm8994->revision < 2) {
2167 snd_soc_write(codec, 0x102, 0x3);
2168 snd_soc_write(codec, 0x5d, 0x7e);
2169 snd_soc_write(codec, 0x5e, 0x0);
2170 snd_soc_write(codec, 0x102, 0x0);
2171 }
2172 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002173 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002174
2175 /* Discharge LINEOUT1 & 2 */
2176 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2177 WM8994_LINEOUT1_DISCH |
2178 WM8994_LINEOUT2_DISCH,
2179 WM8994_LINEOUT1_DISCH |
2180 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002181 }
2182
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002183 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2184 active_dereference(codec);
2185
Mark Brown500fa302011-11-29 19:58:19 +00002186 /* MICBIAS into bypass mode on newer devices */
2187 switch (control->type) {
2188 case WM8958:
2189 case WM1811:
2190 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2191 WM8958_MICB1_MODE,
2192 WM8958_MICB1_MODE);
2193 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2194 WM8958_MICB2_MODE,
2195 WM8958_MICB2_MODE);
2196 break;
2197 default:
2198 break;
2199 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002200 break;
2201
2202 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002203 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002204 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002205 break;
2206 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002207
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002208 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002209
Mark Brown9e6e96a2010-01-29 17:47:12 +00002210 return 0;
2211}
2212
2213static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2214{
2215 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002216 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2217 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002218 int ms_reg;
2219 int aif1_reg;
2220 int ms = 0;
2221 int aif1 = 0;
2222
2223 switch (dai->id) {
2224 case 1:
2225 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2226 aif1_reg = WM8994_AIF1_CONTROL_1;
2227 break;
2228 case 2:
2229 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2230 aif1_reg = WM8994_AIF2_CONTROL_1;
2231 break;
2232 default:
2233 return -EINVAL;
2234 }
2235
2236 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2237 case SND_SOC_DAIFMT_CBS_CFS:
2238 break;
2239 case SND_SOC_DAIFMT_CBM_CFM:
2240 ms = WM8994_AIF1_MSTR;
2241 break;
2242 default:
2243 return -EINVAL;
2244 }
2245
2246 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2247 case SND_SOC_DAIFMT_DSP_B:
2248 aif1 |= WM8994_AIF1_LRCLK_INV;
2249 case SND_SOC_DAIFMT_DSP_A:
2250 aif1 |= 0x18;
2251 break;
2252 case SND_SOC_DAIFMT_I2S:
2253 aif1 |= 0x10;
2254 break;
2255 case SND_SOC_DAIFMT_RIGHT_J:
2256 break;
2257 case SND_SOC_DAIFMT_LEFT_J:
2258 aif1 |= 0x8;
2259 break;
2260 default:
2261 return -EINVAL;
2262 }
2263
2264 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2265 case SND_SOC_DAIFMT_DSP_A:
2266 case SND_SOC_DAIFMT_DSP_B:
2267 /* frame inversion not valid for DSP modes */
2268 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2269 case SND_SOC_DAIFMT_NB_NF:
2270 break;
2271 case SND_SOC_DAIFMT_IB_NF:
2272 aif1 |= WM8994_AIF1_BCLK_INV;
2273 break;
2274 default:
2275 return -EINVAL;
2276 }
2277 break;
2278
2279 case SND_SOC_DAIFMT_I2S:
2280 case SND_SOC_DAIFMT_RIGHT_J:
2281 case SND_SOC_DAIFMT_LEFT_J:
2282 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2283 case SND_SOC_DAIFMT_NB_NF:
2284 break;
2285 case SND_SOC_DAIFMT_IB_IF:
2286 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2287 break;
2288 case SND_SOC_DAIFMT_IB_NF:
2289 aif1 |= WM8994_AIF1_BCLK_INV;
2290 break;
2291 case SND_SOC_DAIFMT_NB_IF:
2292 aif1 |= WM8994_AIF1_LRCLK_INV;
2293 break;
2294 default:
2295 return -EINVAL;
2296 }
2297 break;
2298 default:
2299 return -EINVAL;
2300 }
2301
Mark Brownc4431df2010-11-26 15:21:07 +00002302 /* The AIF2 format configuration needs to be mirrored to AIF3
2303 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002304 switch (control->type) {
2305 case WM1811:
2306 case WM8958:
2307 if (dai->id == 2)
2308 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2309 WM8994_AIF1_LRCLK_INV |
2310 WM8958_AIF3_FMT_MASK, aif1);
2311 break;
2312
2313 default:
2314 break;
2315 }
Mark Brownc4431df2010-11-26 15:21:07 +00002316
Mark Brown9e6e96a2010-01-29 17:47:12 +00002317 snd_soc_update_bits(codec, aif1_reg,
2318 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2319 WM8994_AIF1_FMT_MASK,
2320 aif1);
2321 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2322 ms);
2323
2324 return 0;
2325}
2326
2327static struct {
2328 int val, rate;
2329} srs[] = {
2330 { 0, 8000 },
2331 { 1, 11025 },
2332 { 2, 12000 },
2333 { 3, 16000 },
2334 { 4, 22050 },
2335 { 5, 24000 },
2336 { 6, 32000 },
2337 { 7, 44100 },
2338 { 8, 48000 },
2339 { 9, 88200 },
2340 { 10, 96000 },
2341};
2342
2343static int fs_ratios[] = {
2344 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2345};
2346
2347static int bclk_divs[] = {
2348 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2349 640, 880, 960, 1280, 1760, 1920
2350};
2351
2352static int wm8994_hw_params(struct snd_pcm_substream *substream,
2353 struct snd_pcm_hw_params *params,
2354 struct snd_soc_dai *dai)
2355{
2356 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002357 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002358 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002359 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002360 int bclk_reg;
2361 int lrclk_reg;
2362 int rate_reg;
2363 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002364 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002365 int bclk = 0;
2366 int lrclk = 0;
2367 int rate_val = 0;
2368 int id = dai->id - 1;
2369
2370 int i, cur_val, best_val, bclk_rate, best;
2371
2372 switch (dai->id) {
2373 case 1:
2374 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002375 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002376 bclk_reg = WM8994_AIF1_BCLK;
2377 rate_reg = WM8994_AIF1_RATE;
2378 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002379 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002380 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002381 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002382 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002383 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2384 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002385 break;
2386 case 2:
2387 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002388 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002389 bclk_reg = WM8994_AIF2_BCLK;
2390 rate_reg = WM8994_AIF2_RATE;
2391 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002392 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002393 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002394 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002395 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002396 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2397 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002398 break;
2399 default:
2400 return -EINVAL;
2401 }
2402
2403 bclk_rate = params_rate(params) * 2;
2404 switch (params_format(params)) {
2405 case SNDRV_PCM_FORMAT_S16_LE:
2406 bclk_rate *= 16;
2407 break;
2408 case SNDRV_PCM_FORMAT_S20_3LE:
2409 bclk_rate *= 20;
2410 aif1 |= 0x20;
2411 break;
2412 case SNDRV_PCM_FORMAT_S24_LE:
2413 bclk_rate *= 24;
2414 aif1 |= 0x40;
2415 break;
2416 case SNDRV_PCM_FORMAT_S32_LE:
2417 bclk_rate *= 32;
2418 aif1 |= 0x60;
2419 break;
2420 default:
2421 return -EINVAL;
2422 }
2423
2424 /* Try to find an appropriate sample rate; look for an exact match. */
2425 for (i = 0; i < ARRAY_SIZE(srs); i++)
2426 if (srs[i].rate == params_rate(params))
2427 break;
2428 if (i == ARRAY_SIZE(srs))
2429 return -EINVAL;
2430 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2431
2432 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2433 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2434 dai->id, wm8994->aifclk[id], bclk_rate);
2435
Mark Brownb1e43d92010-12-07 17:14:56 +00002436 if (params_channels(params) == 1 &&
2437 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2438 aif2 |= WM8994_AIF1_MONO;
2439
Mark Brown9e6e96a2010-01-29 17:47:12 +00002440 if (wm8994->aifclk[id] == 0) {
2441 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2442 return -EINVAL;
2443 }
2444
2445 /* AIFCLK/fs ratio; look for a close match in either direction */
2446 best = 0;
2447 best_val = abs((fs_ratios[0] * params_rate(params))
2448 - wm8994->aifclk[id]);
2449 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2450 cur_val = abs((fs_ratios[i] * params_rate(params))
2451 - wm8994->aifclk[id]);
2452 if (cur_val >= best_val)
2453 continue;
2454 best = i;
2455 best_val = cur_val;
2456 }
2457 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2458 dai->id, fs_ratios[best]);
2459 rate_val |= best;
2460
2461 /* We may not get quite the right frequency if using
2462 * approximate clocks so look for the closest match that is
2463 * higher than the target (we need to ensure that there enough
2464 * BCLKs to clock out the samples).
2465 */
2466 best = 0;
2467 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002468 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002469 if (cur_val < 0) /* BCLK table is sorted */
2470 break;
2471 best = i;
2472 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002473 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002474 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2475 bclk_divs[best], bclk_rate);
2476 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2477
2478 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002479 if (!lrclk) {
2480 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2481 bclk_rate);
2482 return -EINVAL;
2483 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002484 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2485 lrclk, bclk_rate / lrclk);
2486
2487 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002488 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002489 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2490 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2491 lrclk);
2492 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2493 WM8994_AIF1CLK_RATE_MASK, rate_val);
2494
2495 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2496 switch (dai->id) {
2497 case 1:
2498 wm8994->dac_rates[0] = params_rate(params);
2499 wm8994_set_retune_mobile(codec, 0);
2500 wm8994_set_retune_mobile(codec, 1);
2501 break;
2502 case 2:
2503 wm8994->dac_rates[1] = params_rate(params);
2504 wm8994_set_retune_mobile(codec, 2);
2505 break;
2506 }
2507 }
2508
2509 return 0;
2510}
2511
Mark Brownc4431df2010-11-26 15:21:07 +00002512static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2513 struct snd_pcm_hw_params *params,
2514 struct snd_soc_dai *dai)
2515{
2516 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002517 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2518 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002519 int aif1_reg;
2520 int aif1 = 0;
2521
2522 switch (dai->id) {
2523 case 3:
2524 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002525 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002526 case WM8958:
2527 aif1_reg = WM8958_AIF3_CONTROL_1;
2528 break;
2529 default:
2530 return 0;
2531 }
2532 default:
2533 return 0;
2534 }
2535
2536 switch (params_format(params)) {
2537 case SNDRV_PCM_FORMAT_S16_LE:
2538 break;
2539 case SNDRV_PCM_FORMAT_S20_3LE:
2540 aif1 |= 0x20;
2541 break;
2542 case SNDRV_PCM_FORMAT_S24_LE:
2543 aif1 |= 0x40;
2544 break;
2545 case SNDRV_PCM_FORMAT_S32_LE:
2546 aif1 |= 0x60;
2547 break;
2548 default:
2549 return -EINVAL;
2550 }
2551
2552 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2553}
2554
Mark Brown7d021732011-07-14 17:11:38 +09002555static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2556 struct snd_soc_dai *dai)
2557{
2558 struct snd_soc_codec *codec = dai->codec;
2559 int rate_reg = 0;
2560
2561 switch (dai->id) {
2562 case 1:
2563 rate_reg = WM8994_AIF1_RATE;
2564 break;
2565 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002566 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002567 break;
2568 default:
2569 break;
2570 }
2571
2572 /* If the DAI is idle then configure the divider tree for the
2573 * lowest output rate to save a little power if the clock is
2574 * still active (eg, because it is system clock).
2575 */
2576 if (rate_reg && !dai->playback_active && !dai->capture_active)
2577 snd_soc_update_bits(codec, rate_reg,
2578 WM8994_AIF1_SR_MASK |
2579 WM8994_AIF1CLK_RATE_MASK, 0x9);
2580}
2581
Mark Brown9e6e96a2010-01-29 17:47:12 +00002582static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2583{
2584 struct snd_soc_codec *codec = codec_dai->codec;
2585 int mute_reg;
2586 int reg;
2587
2588 switch (codec_dai->id) {
2589 case 1:
2590 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2591 break;
2592 case 2:
2593 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2594 break;
2595 default:
2596 return -EINVAL;
2597 }
2598
2599 if (mute)
2600 reg = WM8994_AIF1DAC1_MUTE;
2601 else
2602 reg = 0;
2603
2604 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2605
2606 return 0;
2607}
2608
Mark Brown778a76e2010-03-22 22:05:10 +00002609static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2610{
2611 struct snd_soc_codec *codec = codec_dai->codec;
2612 int reg, val, mask;
2613
2614 switch (codec_dai->id) {
2615 case 1:
2616 reg = WM8994_AIF1_MASTER_SLAVE;
2617 mask = WM8994_AIF1_TRI;
2618 break;
2619 case 2:
2620 reg = WM8994_AIF2_MASTER_SLAVE;
2621 mask = WM8994_AIF2_TRI;
2622 break;
2623 case 3:
2624 reg = WM8994_POWER_MANAGEMENT_6;
2625 mask = WM8994_AIF3_TRI;
2626 break;
2627 default:
2628 return -EINVAL;
2629 }
2630
2631 if (tristate)
2632 val = mask;
2633 else
2634 val = 0;
2635
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002636 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002637}
2638
Mark Brownd09f3ec2011-08-15 11:01:02 +09002639static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2640{
2641 struct snd_soc_codec *codec = dai->codec;
2642
2643 /* Disable the pulls on the AIF if we're using it to save power. */
2644 snd_soc_update_bits(codec, WM8994_GPIO_3,
2645 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2646 snd_soc_update_bits(codec, WM8994_GPIO_4,
2647 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2648 snd_soc_update_bits(codec, WM8994_GPIO_5,
2649 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2650
2651 return 0;
2652}
2653
Mark Brown9e6e96a2010-01-29 17:47:12 +00002654#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2655
2656#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002657 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002658
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002659static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002660 .set_sysclk = wm8994_set_dai_sysclk,
2661 .set_fmt = wm8994_set_dai_fmt,
2662 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002663 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002664 .digital_mute = wm8994_aif_mute,
2665 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002666 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002667};
2668
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002669static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002670 .set_sysclk = wm8994_set_dai_sysclk,
2671 .set_fmt = wm8994_set_dai_fmt,
2672 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002673 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002674 .digital_mute = wm8994_aif_mute,
2675 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002676 .set_tristate = wm8994_set_tristate,
2677};
2678
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002679static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002680 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002681 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002682};
2683
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002684static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002685 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002686 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002687 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002688 .playback = {
2689 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002690 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002691 .channels_max = 2,
2692 .rates = WM8994_RATES,
2693 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002694 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002695 },
2696 .capture = {
2697 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002698 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002699 .channels_max = 2,
2700 .rates = WM8994_RATES,
2701 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002702 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002703 },
2704 .ops = &wm8994_aif1_dai_ops,
2705 },
2706 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002707 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002708 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002709 .playback = {
2710 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002711 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002712 .channels_max = 2,
2713 .rates = WM8994_RATES,
2714 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002715 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002716 },
2717 .capture = {
2718 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002719 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002720 .channels_max = 2,
2721 .rates = WM8994_RATES,
2722 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002723 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002724 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002725 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002726 .ops = &wm8994_aif2_dai_ops,
2727 },
2728 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002729 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002730 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002731 .playback = {
2732 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002733 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002734 .channels_max = 2,
2735 .rates = WM8994_RATES,
2736 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002737 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002738 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002739 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002740 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002741 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002742 .channels_max = 2,
2743 .rates = WM8994_RATES,
2744 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002745 .sig_bits = 24,
2746 },
Mark Brown778a76e2010-03-22 22:05:10 +00002747 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002748 }
2749};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002750
2751#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01002752static int wm8994_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002753{
Mark Brownb2c812e2010-04-14 15:35:19 +09002754 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002755 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002756 int i, ret;
2757
Mark Brownca629922011-05-11 14:34:53 +02002758 switch (control->type) {
2759 case WM8994:
2760 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2761 break;
Mark Brown81204c82011-05-24 17:35:53 +08002762 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002763 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2764 WM1811_JACKDET_MODE_MASK, 0);
2765 /* Fall through */
Mark Brownca629922011-05-11 14:34:53 +02002766 case WM8958:
2767 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2768 WM8958_MICD_ENA, 0);
2769 break;
2770 }
2771
Mark Brown9e6e96a2010-01-29 17:47:12 +00002772 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2773 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002774 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002775 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002776 if (ret < 0)
2777 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2778 i + 1, ret);
2779 }
2780
2781 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2782
2783 return 0;
2784}
2785
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002786static int wm8994_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002787{
Mark Brownb2c812e2010-04-14 15:35:19 +09002788 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002789 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002790 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002791 unsigned int val, mask;
2792
2793 if (wm8994->revision < 4) {
2794 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01002795 ret = regmap_read(control->regmap,
2796 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002797
2798 /* modify the cache only */
2799 codec->cache_only = 1;
2800 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2801 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2802 val &= mask;
2803 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2804 mask, val);
2805 codec->cache_only = 0;
2806 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002807
Mark Brown9e6e96a2010-01-29 17:47:12 +00002808 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002809 if (!wm8994->fll_suspend[i].out)
2810 continue;
2811
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002812 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002813 wm8994->fll_suspend[i].src,
2814 wm8994->fll_suspend[i].in,
2815 wm8994->fll_suspend[i].out);
2816 if (ret < 0)
2817 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2818 i + 1, ret);
2819 }
2820
Mark Brownca629922011-05-11 14:34:53 +02002821 switch (control->type) {
2822 case WM8994:
2823 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2824 snd_soc_update_bits(codec, WM8994_MICBIAS,
2825 WM8994_MICD_ENA, WM8994_MICD_ENA);
2826 break;
Mark Brown81204c82011-05-24 17:35:53 +08002827 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002828 if (wm8994->jackdet && wm8994->jack_cb) {
2829 /* Restart from idle */
2830 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2831 WM1811_JACKDET_MODE_MASK,
2832 WM1811_JACKDET_MODE_JACK);
2833 break;
2834 }
Mark Brownca629922011-05-11 14:34:53 +02002835 case WM8958:
2836 if (wm8994->jack_cb)
2837 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2838 WM8958_MICD_ENA, WM8958_MICD_ENA);
2839 break;
2840 }
2841
Mark Brown9e6e96a2010-01-29 17:47:12 +00002842 return 0;
2843}
2844#else
2845#define wm8994_suspend NULL
2846#define wm8994_resume NULL
2847#endif
2848
2849static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2850{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002851 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002852 struct wm8994_pdata *pdata = wm8994->pdata;
2853 struct snd_kcontrol_new controls[] = {
2854 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2855 wm8994->retune_mobile_enum,
2856 wm8994_get_retune_mobile_enum,
2857 wm8994_put_retune_mobile_enum),
2858 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2859 wm8994->retune_mobile_enum,
2860 wm8994_get_retune_mobile_enum,
2861 wm8994_put_retune_mobile_enum),
2862 SOC_ENUM_EXT("AIF2 EQ Mode",
2863 wm8994->retune_mobile_enum,
2864 wm8994_get_retune_mobile_enum,
2865 wm8994_put_retune_mobile_enum),
2866 };
2867 int ret, i, j;
2868 const char **t;
2869
2870 /* We need an array of texts for the enum API but the number
2871 * of texts is likely to be less than the number of
2872 * configurations due to the sample rate dependency of the
2873 * configurations. */
2874 wm8994->num_retune_mobile_texts = 0;
2875 wm8994->retune_mobile_texts = NULL;
2876 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2877 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2878 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2879 wm8994->retune_mobile_texts[j]) == 0)
2880 break;
2881 }
2882
2883 if (j != wm8994->num_retune_mobile_texts)
2884 continue;
2885
2886 /* Expand the array... */
2887 t = krealloc(wm8994->retune_mobile_texts,
2888 sizeof(char *) *
2889 (wm8994->num_retune_mobile_texts + 1),
2890 GFP_KERNEL);
2891 if (t == NULL)
2892 continue;
2893
2894 /* ...store the new entry... */
2895 t[wm8994->num_retune_mobile_texts] =
2896 pdata->retune_mobile_cfgs[i].name;
2897
2898 /* ...and remember the new version. */
2899 wm8994->num_retune_mobile_texts++;
2900 wm8994->retune_mobile_texts = t;
2901 }
2902
2903 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2904 wm8994->num_retune_mobile_texts);
2905
2906 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2907 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2908
Liam Girdwood022658b2012-02-03 17:43:09 +00002909 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002910 ARRAY_SIZE(controls));
2911 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002912 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002913 "Failed to add ReTune Mobile controls: %d\n", ret);
2914}
2915
2916static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2917{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002918 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002919 struct wm8994_pdata *pdata = wm8994->pdata;
2920 int ret, i;
2921
2922 if (!pdata)
2923 return;
2924
2925 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2926 pdata->lineout2_diff,
2927 pdata->lineout1fb,
2928 pdata->lineout2fb,
2929 pdata->jd_scthr,
2930 pdata->jd_thr,
2931 pdata->micbias1_lvl,
2932 pdata->micbias2_lvl);
2933
2934 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2935
2936 if (pdata->num_drc_cfgs) {
2937 struct snd_kcontrol_new controls[] = {
2938 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2939 wm8994_get_drc_enum, wm8994_put_drc_enum),
2940 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2941 wm8994_get_drc_enum, wm8994_put_drc_enum),
2942 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2943 wm8994_get_drc_enum, wm8994_put_drc_enum),
2944 };
2945
2946 /* We need an array of texts for the enum API */
Mark Brown7270ceb2011-12-01 14:00:19 +00002947 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
2948 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002949 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002950 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002951 "Failed to allocate %d DRC config texts\n",
2952 pdata->num_drc_cfgs);
2953 return;
2954 }
2955
2956 for (i = 0; i < pdata->num_drc_cfgs; i++)
2957 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2958
2959 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2960 wm8994->drc_enum.texts = wm8994->drc_texts;
2961
Liam Girdwood022658b2012-02-03 17:43:09 +00002962 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002963 ARRAY_SIZE(controls));
2964 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002965 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002966 "Failed to add DRC mode controls: %d\n", ret);
2967
2968 for (i = 0; i < WM8994_NUM_DRC; i++)
2969 wm8994_set_drc(codec, i);
2970 }
2971
2972 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2973 pdata->num_retune_mobile_cfgs);
2974
2975 if (pdata->num_retune_mobile_cfgs)
2976 wm8994_handle_retune_mobile_pdata(wm8994);
2977 else
Liam Girdwood022658b2012-02-03 17:43:09 +00002978 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002979 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002980
2981 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2982 if (pdata->micbias[i]) {
2983 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2984 pdata->micbias[i] & 0xffff);
2985 }
2986 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002987}
2988
Mark Brown88766982010-03-29 20:57:12 +01002989/**
2990 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2991 *
2992 * @codec: WM8994 codec
2993 * @jack: jack to report detection events on
2994 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01002995 *
2996 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2997 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002998 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002999 * be configured using snd_soc_jack_add_gpios() instead.
3000 *
3001 * Configuration of detection levels is available via the micbias1_lvl
3002 * and micbias2_lvl platform data members.
3003 */
3004int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00003005 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01003006{
Mark Brownb2c812e2010-04-14 15:35:19 +09003007 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01003008 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01003009 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00003010 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01003011
Mark Brown87092e32012-02-06 18:50:39 +00003012 if (control->type != WM8994) {
3013 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003014 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003015 }
Mark Brown3a423152010-11-26 15:21:06 +00003016
Mark Brown88766982010-03-29 20:57:12 +01003017 switch (micbias) {
3018 case 1:
3019 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003020 if (jack)
3021 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3022 "MICBIAS1");
3023 else
3024 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3025 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003026 break;
3027 case 2:
3028 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003029 if (jack)
3030 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3031 "MICBIAS1");
3032 else
3033 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3034 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003035 break;
3036 default:
Mark Brown87092e32012-02-06 18:50:39 +00003037 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003038 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003039 }
Mark Brown88766982010-03-29 20:57:12 +01003040
Mark Brown87092e32012-02-06 18:50:39 +00003041 if (ret != 0)
3042 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3043 micbias, ret);
3044
3045 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3046 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003047
3048 /* Store the configuration */
3049 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003050 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003051
3052 /* If either of the jacks is set up then enable detection */
3053 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3054 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003055 else
Mark Brown88766982010-03-29 20:57:12 +01003056 reg = 0;
3057
3058 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3059
Mark Brown87092e32012-02-06 18:50:39 +00003060 snd_soc_dapm_sync(&codec->dapm);
3061
Mark Brown88766982010-03-29 20:57:12 +01003062 return 0;
3063}
3064EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3065
3066static irqreturn_t wm8994_mic_irq(int irq, void *data)
3067{
3068 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003069 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01003070 int reg;
3071 int report;
3072
Mark Brown7116f452010-12-29 13:05:21 +00003073#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003074 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003075#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003076
Mark Brown88766982010-03-29 20:57:12 +01003077 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3078 if (reg < 0) {
3079 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3080 reg);
3081 return IRQ_HANDLED;
3082 }
3083
3084 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
3085
3086 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003087 if (reg & WM8994_MIC1_DET_STS) {
3088 if (priv->micdet[0].detecting)
3089 report = SND_JACK_HEADSET;
3090 }
3091 if (reg & WM8994_MIC1_SHRT_STS) {
3092 if (priv->micdet[0].detecting)
3093 report = SND_JACK_HEADPHONE;
3094 else
3095 report |= SND_JACK_BTN_0;
3096 }
3097 if (report)
3098 priv->micdet[0].detecting = false;
3099 else
3100 priv->micdet[0].detecting = true;
3101
Mark Brown88766982010-03-29 20:57:12 +01003102 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003103 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003104
3105 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003106 if (reg & WM8994_MIC2_DET_STS) {
3107 if (priv->micdet[1].detecting)
3108 report = SND_JACK_HEADSET;
3109 }
3110 if (reg & WM8994_MIC2_SHRT_STS) {
3111 if (priv->micdet[1].detecting)
3112 report = SND_JACK_HEADPHONE;
3113 else
3114 report |= SND_JACK_BTN_0;
3115 }
3116 if (report)
3117 priv->micdet[1].detecting = false;
3118 else
3119 priv->micdet[1].detecting = true;
3120
Mark Brown88766982010-03-29 20:57:12 +01003121 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003122 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003123
3124 return IRQ_HANDLED;
3125}
3126
Mark Brown821edd22010-11-26 15:21:09 +00003127/* Default microphone detection handler for WM8958 - the user can
3128 * override this if they wish.
3129 */
3130static void wm8958_default_micdet(u16 status, void *data)
3131{
3132 struct snd_soc_codec *codec = data;
3133 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown45857902011-11-30 10:55:14 +00003134 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003135
Mark Browna1691342011-11-30 14:56:40 +00003136 dev_dbg(codec->dev, "MICDET %x\n", status);
3137
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003138 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003139 if (!(status & WM8958_MICD_STS)) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003140 if (!wm8994->jackdet) {
3141 /* If nothing present then clear our statuses */
3142 dev_dbg(codec->dev, "Detected open circuit\n");
3143 wm8994->jack_mic = false;
3144 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003145
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003146 wm8958_micd_set_rate(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003147
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003148 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3149 wm8994->btn_mask |
3150 SND_JACK_HEADSET);
3151 }
Mark Brownb00adf72011-08-13 11:57:18 +09003152 return;
3153 }
3154
3155 /* If the measurement is showing a high impedence we've got a
3156 * microphone.
3157 */
Mark Brown157a75e2011-11-30 13:43:51 +00003158 if (wm8994->mic_detecting && (status & 0x600)) {
Mark Brownb00adf72011-08-13 11:57:18 +09003159 dev_dbg(codec->dev, "Detected microphone\n");
3160
Mark Brown157a75e2011-11-30 13:43:51 +00003161 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003162 wm8994->jack_mic = true;
3163
3164 wm8958_micd_set_rate(codec);
3165
3166 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3167 SND_JACK_HEADSET);
3168 }
3169
3170
Mark Brown7c08b512012-01-26 18:33:24 +00003171 if (wm8994->mic_detecting && status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003172 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003173 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003174
3175 wm8958_micd_set_rate(codec);
3176
3177 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3178 SND_JACK_HEADSET);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003179
3180 /* If we have jackdet that will detect removal */
3181 if (wm8994->jackdet) {
3182 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3183 WM8958_MICD_ENA, 0);
3184
Mark Brown07fb9d92012-02-21 16:23:35 +00003185 if (wm8994->pdata->jd_ext_cap) {
3186 mutex_lock(&codec->mutex);
3187 snd_soc_dapm_disable_pin(&codec->dapm,
3188 "MICBIAS2");
3189 snd_soc_dapm_sync(&codec->dapm);
3190 mutex_unlock(&codec->mutex);
3191 }
Mark Brownb9e67e52012-02-28 19:03:37 +00003192
3193 wm1811_jackdet_set_mode(codec,
3194 WM1811_JACKDET_MODE_JACK);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003195 }
Mark Brownb00adf72011-08-13 11:57:18 +09003196 }
3197
3198 /* Report short circuit as a button */
3199 if (wm8994->jack_mic) {
Mark Brown45857902011-11-30 10:55:14 +00003200 report = 0;
Mark Brownb00adf72011-08-13 11:57:18 +09003201 if (status & 0x4)
Mark Brown45857902011-11-30 10:55:14 +00003202 report |= SND_JACK_BTN_0;
3203
3204 if (status & 0x8)
3205 report |= SND_JACK_BTN_1;
3206
3207 if (status & 0x10)
3208 report |= SND_JACK_BTN_2;
3209
3210 if (status & 0x20)
3211 report |= SND_JACK_BTN_3;
3212
3213 if (status & 0x40)
3214 report |= SND_JACK_BTN_4;
3215
3216 if (status & 0x80)
3217 report |= SND_JACK_BTN_5;
3218
3219 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3220 wm8994->btn_mask);
Mark Brownb00adf72011-08-13 11:57:18 +09003221 }
Mark Brown821edd22010-11-26 15:21:09 +00003222}
3223
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003224static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3225{
3226 struct wm8994_priv *wm8994 = data;
3227 struct snd_soc_codec *codec = wm8994->codec;
3228 int reg;
3229
3230 mutex_lock(&wm8994->accdet_lock);
3231
3232 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3233 if (reg < 0) {
3234 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3235 mutex_unlock(&wm8994->accdet_lock);
3236 return IRQ_NONE;
3237 }
3238
3239 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3240
3241 if (reg & WM1811_JACKDET_LVL) {
3242 dev_dbg(codec->dev, "Jack detected\n");
3243
3244 snd_soc_jack_report(wm8994->micdet[0].jack,
3245 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3246
Mark Brown55a27782012-02-21 13:45:53 +00003247 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3248 WM8958_MICB2_DISCH, 0);
3249
Mark Brown378ec0c2012-03-01 19:01:43 +00003250 /* Disable debounce while inserted */
3251 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3252 WM1811_JACKDET_DB, 0);
3253
Mark Brownb9e67e52012-02-28 19:03:37 +00003254 /*
3255 * Start off measument of microphone impedence to find
3256 * out what's actually there.
3257 */
3258 wm8994->mic_detecting = true;
3259 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3260
3261 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3262 WM8958_MICD_ENA, WM8958_MICD_ENA);
3263
Mark Brown07fb9d92012-02-21 16:23:35 +00003264 /* If required for an external cap force MICBIAS on */
3265 if (wm8994->pdata->jd_ext_cap) {
3266 mutex_lock(&codec->mutex);
3267 snd_soc_dapm_force_enable_pin(&codec->dapm,
3268 "MICBIAS2");
3269 snd_soc_dapm_sync(&codec->dapm);
3270 mutex_unlock(&codec->mutex);
3271 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003272 } else {
3273 dev_dbg(codec->dev, "Jack not detected\n");
3274
Mark Brown55a27782012-02-21 13:45:53 +00003275 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3276 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3277
Mark Brown07fb9d92012-02-21 16:23:35 +00003278 if (wm8994->pdata->jd_ext_cap) {
3279 mutex_lock(&codec->mutex);
3280 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3281 snd_soc_dapm_sync(&codec->dapm);
3282 mutex_unlock(&codec->mutex);
3283 }
3284
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003285 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3286 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3287 wm8994->btn_mask);
3288
Mark Brown378ec0c2012-03-01 19:01:43 +00003289 /* Enable debounce while removed */
3290 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3291 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3292
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003293 wm8994->mic_detecting = false;
3294 wm8994->jack_mic = false;
3295 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3296 WM8958_MICD_ENA, 0);
3297 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3298 }
3299
3300 mutex_unlock(&wm8994->accdet_lock);
3301
3302 return IRQ_HANDLED;
3303}
3304
Mark Brown821edd22010-11-26 15:21:09 +00003305/**
3306 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3307 *
3308 * @codec: WM8958 codec
3309 * @jack: jack to report detection events on
3310 *
3311 * Enable microphone detection functionality for the WM8958. By
3312 * default simple detection which supports the detection of up to 6
3313 * buttons plus video and microphone functionality is supported.
3314 *
3315 * The WM8958 has an advanced jack detection facility which is able to
3316 * support complex accessory detection, especially when used in
3317 * conjunction with external circuitry. In order to provide maximum
3318 * flexiblity a callback is provided which allows a completely custom
3319 * detection algorithm.
3320 */
3321int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3322 wm8958_micdet_cb cb, void *cb_data)
3323{
3324 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003325 struct wm8994 *control = wm8994->wm8994;
Mark Brown45857902011-11-30 10:55:14 +00003326 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003327
Mark Brown81204c82011-05-24 17:35:53 +08003328 switch (control->type) {
3329 case WM1811:
3330 case WM8958:
3331 break;
3332 default:
Mark Brown821edd22010-11-26 15:21:09 +00003333 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003334 }
Mark Brown821edd22010-11-26 15:21:09 +00003335
3336 if (jack) {
3337 if (!cb) {
3338 dev_dbg(codec->dev, "Using default micdet callback\n");
3339 cb = wm8958_default_micdet;
3340 cb_data = codec;
3341 }
3342
Mark Brown4cdf5e42011-11-29 14:36:17 +00003343 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003344 snd_soc_dapm_sync(&codec->dapm);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003345
Mark Brown821edd22010-11-26 15:21:09 +00003346 wm8994->micdet[0].jack = jack;
3347 wm8994->jack_cb = cb;
3348 wm8994->jack_cb_data = cb_data;
3349
Mark Brown157a75e2011-11-30 13:43:51 +00003350 wm8994->mic_detecting = true;
Mark Brownb00adf72011-08-13 11:57:18 +09003351 wm8994->jack_mic = false;
3352
3353 wm8958_micd_set_rate(codec);
3354
Mark Brown45857902011-11-30 10:55:14 +00003355 /* Detect microphones and short circuits by default */
3356 if (wm8994->pdata->micd_lvl_sel)
3357 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3358 else
3359 micd_lvl_sel = 0x41;
3360
3361 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3362 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3363 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3364
Mark Brownb00adf72011-08-13 11:57:18 +09003365 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown45857902011-11-30 10:55:14 +00003366 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003367
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003368 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3369
3370 /*
3371 * If we can use jack detection start off with that,
3372 * otherwise jump straight to microphone detection.
3373 */
3374 if (wm8994->jackdet) {
Mark Brown55a27782012-02-21 13:45:53 +00003375 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3376 WM8958_MICB2_DISCH,
3377 WM8958_MICB2_DISCH);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003378 snd_soc_update_bits(codec, WM8994_LDO_1,
3379 WM8994_LDO1_DISCH, 0);
3380 wm1811_jackdet_set_mode(codec,
3381 WM1811_JACKDET_MODE_JACK);
3382 } else {
3383 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3384 WM8958_MICD_ENA, WM8958_MICD_ENA);
3385 }
3386
Mark Brown821edd22010-11-26 15:21:09 +00003387 } else {
3388 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3389 WM8958_MICD_ENA, 0);
Mark Brownafaf1592012-03-03 18:46:36 +00003390 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003391 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003392 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003393 }
3394
3395 return 0;
3396}
3397EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3398
3399static irqreturn_t wm8958_mic_irq(int irq, void *data)
3400{
3401 struct wm8994_priv *wm8994 = data;
3402 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003403 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003404
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003405 mutex_lock(&wm8994->accdet_lock);
3406
3407 /*
3408 * Jack detection may have detected a removal simulataneously
3409 * with an update of the MICDET status; if so it will have
3410 * stopped detection and we can ignore this interrupt.
3411 */
3412 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA)) {
3413 mutex_unlock(&wm8994->accdet_lock);
3414 return IRQ_HANDLED;
3415 }
3416
Mark Brown19940b32011-08-19 18:05:05 +09003417 /* We may occasionally read a detection without an impedence
3418 * range being provided - if that happens loop again.
3419 */
3420 count = 10;
3421 do {
3422 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3423 if (reg < 0) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003424 mutex_unlock(&wm8994->accdet_lock);
Mark Brown19940b32011-08-19 18:05:05 +09003425 dev_err(codec->dev,
3426 "Failed to read mic detect status: %d\n",
3427 reg);
3428 return IRQ_NONE;
3429 }
Mark Brown821edd22010-11-26 15:21:09 +00003430
Mark Brown19940b32011-08-19 18:05:05 +09003431 if (!(reg & WM8958_MICD_VALID)) {
3432 dev_dbg(codec->dev, "Mic detect data not valid\n");
3433 goto out;
3434 }
3435
3436 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3437 break;
3438
3439 msleep(1);
3440 } while (count--);
3441
3442 if (count == 0)
3443 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003444
Mark Brown7116f452010-12-29 13:05:21 +00003445#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003446 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003447#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003448
Mark Brown821edd22010-11-26 15:21:09 +00003449 if (wm8994->jack_cb)
3450 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3451 else
3452 dev_warn(codec->dev, "Accessory detection with no callback\n");
3453
3454out:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003455 mutex_unlock(&wm8994->accdet_lock);
3456
Mark Brown821edd22010-11-26 15:21:09 +00003457 return IRQ_HANDLED;
3458}
3459
Mark Brown3b1af3f2011-07-14 12:38:18 +09003460static irqreturn_t wm8994_fifo_error(int irq, void *data)
3461{
3462 struct snd_soc_codec *codec = data;
3463
3464 dev_err(codec->dev, "FIFO error\n");
3465
3466 return IRQ_HANDLED;
3467}
3468
Mark Brownf0b182b2011-08-16 12:01:27 +09003469static irqreturn_t wm8994_temp_warn(int irq, void *data)
3470{
3471 struct snd_soc_codec *codec = data;
3472
3473 dev_err(codec->dev, "Thermal warning\n");
3474
3475 return IRQ_HANDLED;
3476}
3477
3478static irqreturn_t wm8994_temp_shut(int irq, void *data)
3479{
3480 struct snd_soc_codec *codec = data;
3481
3482 dev_crit(codec->dev, "Thermal shutdown\n");
3483
3484 return IRQ_HANDLED;
3485}
3486
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003487static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003488{
Mark Brownd9a76662011-07-24 12:49:52 +01003489 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00003490 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003491 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003492 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003493 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003494
Mark Brown2bc16ed2012-03-03 23:24:39 +00003495 wm8994->codec = codec;
Mark Brownd9a76662011-07-24 12:49:52 +01003496 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003497
Mark Brownd9a76662011-07-24 12:49:52 +01003498 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003499
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003500 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003501
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003502 mutex_init(&wm8994->accdet_lock);
3503
Mark Brownc7ebf932011-07-12 19:47:59 +09003504 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3505 init_completion(&wm8994->fll_locked[i]);
3506
Mark Brown9b7c5252011-02-17 20:05:44 -08003507 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3508 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3509 else if (wm8994->pdata && wm8994->pdata->irq_base)
3510 wm8994->micdet_irq = wm8994->pdata->irq_base +
3511 WM8994_IRQ_MIC1_DET;
3512
Mark Brown39fb51a2010-11-26 17:23:43 +00003513 pm_runtime_enable(codec->dev);
Mark Brown5fab5172012-02-06 18:37:08 +00003514 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003515
Mark Brownf959dee2012-01-31 16:16:47 +00003516 /* By default use idle_bias_off, will override for WM8994 */
3517 codec->dapm.idle_bias_off = 1;
3518
Mark Brown9e6e96a2010-01-29 17:47:12 +00003519 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003520 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003521 switch (control->type) {
3522 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003523 /* Single ended line outputs should have VMID on. */
3524 if (!wm8994->pdata->lineout1_diff ||
3525 !wm8994->pdata->lineout2_diff)
3526 codec->dapm.idle_bias_off = 0;
3527
Mark Brown3a423152010-11-26 15:21:06 +00003528 switch (wm8994->revision) {
3529 case 2:
3530 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003531 wm8994->hubs.dcs_codes_l = -5;
3532 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003533 wm8994->hubs.hp_startup_mode = 1;
3534 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003535 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003536 break;
3537 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003538 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003539 break;
3540 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003541 break;
Mark Brown3a423152010-11-26 15:21:06 +00003542
3543 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003544 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003545 wm8994->hubs.hp_startup_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003546 break;
Mark Brown3a423152010-11-26 15:21:06 +00003547
Mark Brown81204c82011-05-24 17:35:53 +08003548 case WM1811:
3549 wm8994->hubs.dcs_readback_mode = 2;
3550 wm8994->hubs.no_series_update = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003551 wm8994->hubs.hp_startup_mode = 1;
Mark Brown67109cb2012-02-29 16:40:08 +00003552 wm8994->hubs.no_cache_class_w = true;
Mark Brown81204c82011-05-24 17:35:53 +08003553
3554 switch (wm8994->revision) {
3555 case 0:
3556 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003557 case 2:
3558 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003559 wm8994->hubs.dcs_codes_l = -9;
3560 wm8994->hubs.dcs_codes_r = -5;
Mark Brown81204c82011-05-24 17:35:53 +08003561 break;
3562 default:
3563 break;
3564 }
3565
3566 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3567 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3568 break;
3569
Mark Brown9e6e96a2010-01-29 17:47:12 +00003570 default:
3571 break;
3572 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003573
Mark Brown2a8a8562011-07-24 12:20:41 +01003574 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003575 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003576 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003577 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003578 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003579 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003580
Mark Brown2a8a8562011-07-24 12:20:41 +01003581 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003582 wm_hubs_dcs_done, "DC servo done",
3583 &wm8994->hubs);
3584 if (ret == 0)
3585 wm8994->hubs.dcs_done_irq = true;
3586
Mark Brown3a423152010-11-26 15:21:06 +00003587 switch (control->type) {
3588 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003589 if (wm8994->micdet_irq) {
3590 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3591 wm8994_mic_irq,
3592 IRQF_TRIGGER_RISING,
3593 "Mic1 detect",
3594 wm8994);
3595 if (ret != 0)
3596 dev_warn(codec->dev,
3597 "Failed to request Mic1 detect IRQ: %d\n",
3598 ret);
3599 }
Mark Brown88766982010-03-29 20:57:12 +01003600
Mark Brown2a8a8562011-07-24 12:20:41 +01003601 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003602 WM8994_IRQ_MIC1_SHRT,
3603 wm8994_mic_irq, "Mic 1 short",
3604 wm8994);
3605 if (ret != 0)
3606 dev_warn(codec->dev,
3607 "Failed to request Mic1 short IRQ: %d\n",
3608 ret);
Mark Brown88766982010-03-29 20:57:12 +01003609
Mark Brown2a8a8562011-07-24 12:20:41 +01003610 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003611 WM8994_IRQ_MIC2_DET,
3612 wm8994_mic_irq, "Mic 2 detect",
3613 wm8994);
3614 if (ret != 0)
3615 dev_warn(codec->dev,
3616 "Failed to request Mic2 detect IRQ: %d\n",
3617 ret);
Mark Brown88766982010-03-29 20:57:12 +01003618
Mark Brown2a8a8562011-07-24 12:20:41 +01003619 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003620 WM8994_IRQ_MIC2_SHRT,
3621 wm8994_mic_irq, "Mic 2 short",
3622 wm8994);
3623 if (ret != 0)
3624 dev_warn(codec->dev,
3625 "Failed to request Mic2 short IRQ: %d\n",
3626 ret);
3627 break;
Mark Brown821edd22010-11-26 15:21:09 +00003628
3629 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003630 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003631 if (wm8994->micdet_irq) {
3632 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3633 wm8958_mic_irq,
3634 IRQF_TRIGGER_RISING,
3635 "Mic detect",
3636 wm8994);
3637 if (ret != 0)
3638 dev_warn(codec->dev,
3639 "Failed to request Mic detect IRQ: %d\n",
3640 ret);
3641 }
Mark Brown3a423152010-11-26 15:21:06 +00003642 }
Mark Brown88766982010-03-29 20:57:12 +01003643
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003644 switch (control->type) {
3645 case WM1811:
3646 if (wm8994->revision > 1) {
3647 ret = wm8994_request_irq(wm8994->wm8994,
3648 WM8994_IRQ_GPIO(6),
3649 wm1811_jackdet_irq, "JACKDET",
3650 wm8994);
3651 if (ret == 0)
3652 wm8994->jackdet = true;
3653 }
3654 break;
3655 default:
3656 break;
3657 }
3658
Mark Brownc7ebf932011-07-12 19:47:59 +09003659 wm8994->fll_locked_irq = true;
3660 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01003661 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09003662 WM8994_IRQ_FLL1_LOCK + i,
3663 wm8994_fll_locked_irq, "FLL lock",
3664 &wm8994->fll_locked[i]);
3665 if (ret != 0)
3666 wm8994->fll_locked_irq = false;
3667 }
3668
Mark Brown27060b3c2012-02-06 18:42:14 +00003669 /* Make sure we can read from the GPIOs if they're inputs */
3670 pm_runtime_get_sync(codec->dev);
3671
Mark Brown9e6e96a2010-01-29 17:47:12 +00003672 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3673 * configured on init - if a system wants to do this dynamically
3674 * at runtime we can deal with that then.
3675 */
Mark Brownd9a76662011-07-24 12:49:52 +01003676 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003677 if (ret < 0) {
3678 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003679 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003680 }
Mark Brownd9a76662011-07-24 12:49:52 +01003681 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003682 wm8994->lrclk_shared[0] = 1;
3683 wm8994_dai[0].symmetric_rates = 1;
3684 } else {
3685 wm8994->lrclk_shared[0] = 0;
3686 }
3687
Mark Brownd9a76662011-07-24 12:49:52 +01003688 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003689 if (ret < 0) {
3690 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003691 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003692 }
Mark Brownd9a76662011-07-24 12:49:52 +01003693 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003694 wm8994->lrclk_shared[1] = 1;
3695 wm8994_dai[1].symmetric_rates = 1;
3696 } else {
3697 wm8994->lrclk_shared[1] = 0;
3698 }
3699
Mark Brown27060b3c2012-02-06 18:42:14 +00003700 pm_runtime_put(codec->dev);
3701
Mark Brown9e6e96a2010-01-29 17:47:12 +00003702 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003703 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3704 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003705 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3706 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003707 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3708 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003709 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3710 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003711 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3712 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003713 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3714 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003715 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3716 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003717 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3718 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003719 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3720 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003721 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3722 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003723 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3724 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003725 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3726 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003727 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3728 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003729 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3730 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003731 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3732 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003733 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3734 WM8994_DAC2_VU, WM8994_DAC2_VU);
3735
3736 /* Set the low bit of the 3D stereo depth so TLV matches */
3737 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3738 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3739 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3740 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3741 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3742 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3743 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3744 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3745 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3746
Mark Brown5b739672011-07-06 00:08:43 -07003747 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3748 * use this; it only affects behaviour on idle TDM clock
3749 * cycles. */
3750 switch (control->type) {
3751 case WM8994:
3752 case WM8958:
3753 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3754 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3755 break;
3756 default:
3757 break;
3758 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003759
Mark Brown500fa302011-11-29 19:58:19 +00003760 /* Put MICBIAS into bypass mode by default on newer devices */
3761 switch (control->type) {
3762 case WM8958:
3763 case WM1811:
3764 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3765 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3766 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3767 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3768 break;
3769 default:
3770 break;
3771 }
3772
Mark Brown9e6e96a2010-01-29 17:47:12 +00003773 wm8994_update_class_w(codec);
3774
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003775 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003776
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003777 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00003778 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003779 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003780 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003781 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003782
3783 switch (control->type) {
3784 case WM8994:
3785 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3786 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003787 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003788 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3789 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003790 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3791 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003792 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3793 ARRAY_SIZE(wm8994_dac_revd_widgets));
3794 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003795 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3796 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003797 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3798 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003799 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3800 ARRAY_SIZE(wm8994_dac_widgets));
3801 }
Mark Brownc4431df2010-11-26 15:21:07 +00003802 break;
3803 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00003804 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00003805 ARRAY_SIZE(wm8958_snd_controls));
3806 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3807 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003808 if (wm8994->revision < 1) {
3809 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3810 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3811 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3812 ARRAY_SIZE(wm8994_adc_revd_widgets));
3813 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3814 ARRAY_SIZE(wm8994_dac_revd_widgets));
3815 } else {
3816 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3817 ARRAY_SIZE(wm8994_lateclk_widgets));
3818 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3819 ARRAY_SIZE(wm8994_adc_widgets));
3820 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3821 ARRAY_SIZE(wm8994_dac_widgets));
3822 }
Mark Brownc4431df2010-11-26 15:21:07 +00003823 break;
Mark Brown81204c82011-05-24 17:35:53 +08003824
3825 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00003826 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08003827 ARRAY_SIZE(wm8958_snd_controls));
3828 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3829 ARRAY_SIZE(wm8958_dapm_widgets));
3830 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3831 ARRAY_SIZE(wm8994_lateclk_widgets));
3832 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3833 ARRAY_SIZE(wm8994_adc_widgets));
3834 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3835 ARRAY_SIZE(wm8994_dac_widgets));
3836 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003837 }
3838
3839
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003840 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003841 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003842
Mark Brownc4431df2010-11-26 15:21:07 +00003843 switch (control->type) {
3844 case WM8994:
3845 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3846 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003847
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003848 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003849 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3850 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003851 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3852 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3853 } else {
3854 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3855 ARRAY_SIZE(wm8994_lateclk_intercon));
3856 }
Mark Brownc4431df2010-11-26 15:21:07 +00003857 break;
3858 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003859 if (wm8994->revision < 1) {
3860 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3861 ARRAY_SIZE(wm8994_revd_intercon));
3862 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3863 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3864 } else {
3865 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3866 ARRAY_SIZE(wm8994_lateclk_intercon));
3867 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3868 ARRAY_SIZE(wm8958_intercon));
3869 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003870
3871 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003872 break;
Mark Brown81204c82011-05-24 17:35:53 +08003873 case WM1811:
3874 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3875 ARRAY_SIZE(wm8994_lateclk_intercon));
3876 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3877 ARRAY_SIZE(wm8958_intercon));
3878 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003879 }
3880
Mark Brown9e6e96a2010-01-29 17:47:12 +00003881 return 0;
3882
Mark Brown88766982010-03-29 20:57:12 +01003883err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003884 if (wm8994->jackdet)
3885 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003886 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
3887 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
3888 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003889 if (wm8994->micdet_irq)
3890 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003891 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003892 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003893 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01003894 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003895 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003896 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3897 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3898 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00003899
Mark Brown9e6e96a2010-01-29 17:47:12 +00003900 return ret;
3901}
3902
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003903static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003904{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003905 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003906 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09003907 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003908
3909 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003910
Mark Brown39fb51a2010-11-26 17:23:43 +00003911 pm_runtime_disable(codec->dev);
3912
Mark Brownc7ebf932011-07-12 19:47:59 +09003913 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003914 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003915 &wm8994->fll_locked[i]);
3916
Mark Brown2a8a8562011-07-24 12:20:41 +01003917 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003918 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003919 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3920 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3921 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003922
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003923 if (wm8994->jackdet)
3924 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
3925
Mark Brown3a423152010-11-26 15:21:06 +00003926 switch (control->type) {
3927 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003928 if (wm8994->micdet_irq)
3929 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003930 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003931 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003932 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00003933 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003934 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003935 wm8994);
3936 break;
Mark Brown821edd22010-11-26 15:21:09 +00003937
Mark Brown81204c82011-05-24 17:35:53 +08003938 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00003939 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003940 if (wm8994->micdet_irq)
3941 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003942 break;
Mark Brown3a423152010-11-26 15:21:06 +00003943 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003944 if (wm8994->mbc)
3945 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003946 if (wm8994->mbc_vss)
3947 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003948 if (wm8994->enh_eq)
3949 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003950 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003951
3952 return 0;
3953}
3954
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003955static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3956 .probe = wm8994_codec_probe,
3957 .remove = wm8994_codec_remove,
3958 .suspend = wm8994_suspend,
3959 .resume = wm8994_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003960 .set_bias_level = wm8994_set_bias_level,
3961};
3962
3963static int __devinit wm8994_probe(struct platform_device *pdev)
3964{
Mark Brown2bc16ed2012-03-03 23:24:39 +00003965 struct wm8994_priv *wm8994;
3966
3967 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
3968 GFP_KERNEL);
3969 if (wm8994 == NULL)
3970 return -ENOMEM;
3971 platform_set_drvdata(pdev, wm8994);
3972
3973 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
3974 wm8994->pdata = dev_get_platdata(pdev->dev.parent);
3975
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003976 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3977 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3978}
3979
3980static int __devexit wm8994_remove(struct platform_device *pdev)
3981{
3982 snd_soc_unregister_codec(&pdev->dev);
3983 return 0;
3984}
3985
Mark Brown9e6e96a2010-01-29 17:47:12 +00003986static struct platform_driver wm8994_codec_driver = {
3987 .driver = {
3988 .name = "wm8994-codec",
3989 .owner = THIS_MODULE,
3990 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003991 .probe = wm8994_probe,
3992 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003993};
3994
Mark Brown5bbcc3c2011-11-23 22:52:08 +00003995module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003996
3997MODULE_DESCRIPTION("ASoC WM8994 driver");
3998MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3999MODULE_LICENSE("GPL");
4000MODULE_ALIAS("platform:wm8994-codec");