blob: b7f3cfc74e98ba4f00050f2d48c2bc5fa0220711 [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);
688
Mark Brown28e33262012-03-03 00:10:02 +0000689 if (!wm8994->jackdet || !wm8994->jack_cb)
690 return;
691
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000692 if (wm8994->active_refcount)
693 mode = WM1811_JACKDET_MODE_AUDIO;
694
Mark Brown4752a882012-03-04 02:16:01 +0000695 if (mode == wm8994->jackdet_mode)
Mark Brown1defde22012-03-03 20:02:49 +0000696 return;
697
Mark Brown4752a882012-03-04 02:16:01 +0000698 wm8994->jackdet_mode = mode;
699
700 /* Always use audio mode to detect while the system is active */
701 if (mode != WM1811_JACKDET_MODE_NONE)
702 mode = WM1811_JACKDET_MODE_AUDIO;
703
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000704 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
705 WM1811_JACKDET_MODE_MASK, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000706}
707
708static void active_reference(struct snd_soc_codec *codec)
709{
710 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
711
712 mutex_lock(&wm8994->accdet_lock);
713
714 wm8994->active_refcount++;
715
716 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
717 wm8994->active_refcount);
718
Mark Brown1defde22012-03-03 20:02:49 +0000719 /* If we're using jack detection go into audio mode */
720 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000721
722 mutex_unlock(&wm8994->accdet_lock);
723}
724
725static void active_dereference(struct snd_soc_codec *codec)
726{
727 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
728 u16 mode;
729
730 mutex_lock(&wm8994->accdet_lock);
731
732 wm8994->active_refcount--;
733
734 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
735 wm8994->active_refcount);
736
737 if (wm8994->active_refcount == 0) {
738 /* Go into appropriate detection only mode */
Mark Brown1defde22012-03-03 20:02:49 +0000739 if (wm8994->jack_mic || wm8994->mic_detecting)
740 mode = WM1811_JACKDET_MODE_MIC;
741 else
742 mode = WM1811_JACKDET_MODE_JACK;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000743
Mark Brown1defde22012-03-03 20:02:49 +0000744 wm1811_jackdet_set_mode(codec, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000745 }
746
747 mutex_unlock(&wm8994->accdet_lock);
748}
749
Mark Brown9e6e96a2010-01-29 17:47:12 +0000750static int clk_sys_event(struct snd_soc_dapm_widget *w,
751 struct snd_kcontrol *kcontrol, int event)
752{
753 struct snd_soc_codec *codec = w->codec;
754
755 switch (event) {
756 case SND_SOC_DAPM_PRE_PMU:
757 return configure_clock(codec);
758
759 case SND_SOC_DAPM_POST_PMD:
760 configure_clock(codec);
761 break;
762 }
763
764 return 0;
765}
766
Mark Brown4b7ed832011-08-10 17:47:33 +0900767static void vmid_reference(struct snd_soc_codec *codec)
768{
769 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
770
Mark Browndb966f82012-02-06 12:07:08 +0000771 pm_runtime_get_sync(codec->dev);
772
Mark Brown4b7ed832011-08-10 17:47:33 +0900773 wm8994->vmid_refcount++;
774
775 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
776 wm8994->vmid_refcount);
777
778 if (wm8994->vmid_refcount == 1) {
Mark Browncc6d5a82012-02-11 23:09:53 +0000779 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
780 WM8994_LINEOUT_VMID_BUF_ENA |
781 WM8994_LINEOUT1_DISCH |
782 WM8994_LINEOUT2_DISCH,
783 WM8994_LINEOUT_VMID_BUF_ENA);
784
Mark Brownf7085642012-02-21 16:24:00 +0000785 wm_hubs_vmid_ena(codec);
786
Mark Brown4b7ed832011-08-10 17:47:33 +0900787 /* Startup bias, VMID ramp & buffer */
788 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
Mark Browncc6d5a82012-02-11 23:09:53 +0000789 WM8994_BIAS_SRC |
790 WM8994_VMID_DISCH |
Mark Brown4b7ed832011-08-10 17:47:33 +0900791 WM8994_STARTUP_BIAS_ENA |
792 WM8994_VMID_BUF_ENA |
793 WM8994_VMID_RAMP_MASK,
Mark Browncc6d5a82012-02-11 23:09:53 +0000794 WM8994_BIAS_SRC |
Mark Brown4b7ed832011-08-10 17:47:33 +0900795 WM8994_STARTUP_BIAS_ENA |
796 WM8994_VMID_BUF_ENA |
Mark Brown65f01ef2012-02-14 17:53:55 -0800797 (0x2 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900798
799 /* Main bias enable, VMID=2x40k */
800 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
801 WM8994_BIAS_ENA |
802 WM8994_VMID_SEL_MASK,
803 WM8994_BIAS_ENA | 0x2);
804
Mark Browncc6d5a82012-02-11 23:09:53 +0000805 msleep(50);
806
807 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
808 WM8994_VMID_RAMP_MASK | WM8994_BIAS_SRC,
809 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900810 }
811}
812
813static void vmid_dereference(struct snd_soc_codec *codec)
814{
815 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
816
817 wm8994->vmid_refcount--;
818
819 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
820 wm8994->vmid_refcount);
821
822 if (wm8994->vmid_refcount == 0) {
823 /* Switch over to startup biases */
824 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
825 WM8994_BIAS_SRC |
826 WM8994_STARTUP_BIAS_ENA |
827 WM8994_VMID_BUF_ENA |
828 WM8994_VMID_RAMP_MASK,
829 WM8994_BIAS_SRC |
830 WM8994_STARTUP_BIAS_ENA |
831 WM8994_VMID_BUF_ENA |
832 (1 << WM8994_VMID_RAMP_SHIFT));
833
834 /* Disable main biases */
835 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
836 WM8994_BIAS_ENA |
837 WM8994_VMID_SEL_MASK, 0);
838
Mark Browne85b26c2012-02-11 23:10:30 +0000839 /* Discharge VMID */
840 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
841 WM8994_VMID_DISCH, WM8994_VMID_DISCH);
842
Mark Brown4b7ed832011-08-10 17:47:33 +0900843 /* Discharge line */
844 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
845 WM8994_LINEOUT1_DISCH |
846 WM8994_LINEOUT2_DISCH,
847 WM8994_LINEOUT1_DISCH |
848 WM8994_LINEOUT2_DISCH);
849
850 msleep(5);
851
852 /* Switch off startup biases */
853 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
854 WM8994_BIAS_SRC |
855 WM8994_STARTUP_BIAS_ENA |
856 WM8994_VMID_BUF_ENA |
857 WM8994_VMID_RAMP_MASK, 0);
858 }
Mark Browndb966f82012-02-06 12:07:08 +0000859
860 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900861}
862
863static int vmid_event(struct snd_soc_dapm_widget *w,
864 struct snd_kcontrol *kcontrol, int event)
865{
866 struct snd_soc_codec *codec = w->codec;
867
868 switch (event) {
869 case SND_SOC_DAPM_PRE_PMU:
870 vmid_reference(codec);
871 break;
872
873 case SND_SOC_DAPM_POST_PMD:
874 vmid_dereference(codec);
875 break;
876 }
877
878 return 0;
879}
880
Mark Brown9e6e96a2010-01-29 17:47:12 +0000881static void wm8994_update_class_w(struct snd_soc_codec *codec)
882{
Mark Brownfec6dd82010-10-27 13:48:36 -0700883 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000884 int enable = 1;
885 int source = 0; /* GCC flow analysis can't track enable */
886 int reg, reg_r;
887
888 /* Only support direct DAC->headphone paths */
889 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
890 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900891 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000892 enable = 0;
893 }
894
895 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
896 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900897 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000898 enable = 0;
899 }
900
901 /* We also need the same setting for L/R and only one path */
902 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
903 switch (reg) {
904 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900905 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000906 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
907 break;
908 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900909 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000910 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
911 break;
912 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900913 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000914 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
915 break;
916 default:
Mark Brownee839a22010-04-20 13:57:08 +0900917 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000918 enable = 0;
919 break;
920 }
921
922 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
923 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900924 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000925 enable = 0;
926 }
927
928 if (enable) {
929 dev_dbg(codec->dev, "Class W enabled\n");
930 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
931 WM8994_CP_DYN_PWR |
932 WM8994_CP_DYN_SRC_SEL_MASK,
933 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700934 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000935
936 } else {
937 dev_dbg(codec->dev, "Class W disabled\n");
938 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
939 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700940 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000941 }
942}
943
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000944static int late_enable_ev(struct snd_soc_dapm_widget *w,
945 struct snd_kcontrol *kcontrol, int event)
946{
947 struct snd_soc_codec *codec = w->codec;
948 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
949
950 switch (event) {
951 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000952 if (wm8994->aif1clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000953 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
954 WM8994_AIF1CLK_ENA_MASK,
955 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000956 wm8994->aif1clk_enable = 0;
957 }
958 if (wm8994->aif2clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000959 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
960 WM8994_AIF2CLK_ENA_MASK,
961 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000962 wm8994->aif2clk_enable = 0;
963 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000964 break;
965 }
966
Mark Brownc6b7b572011-03-11 18:13:12 +0000967 /* We may also have postponed startup of DSP, handle that. */
968 wm8958_aif_ev(w, kcontrol, event);
969
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000970 return 0;
971}
972
973static int late_disable_ev(struct snd_soc_dapm_widget *w,
974 struct snd_kcontrol *kcontrol, int event)
975{
976 struct snd_soc_codec *codec = w->codec;
977 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
978
979 switch (event) {
980 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000981 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000982 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
983 WM8994_AIF1CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000984 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000985 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000986 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000987 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
988 WM8994_AIF2CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000989 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000990 }
991 break;
992 }
993
994 return 0;
995}
996
997static int aif1clk_ev(struct snd_soc_dapm_widget *w,
998 struct snd_kcontrol *kcontrol, int event)
999{
1000 struct snd_soc_codec *codec = w->codec;
1001 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1002
1003 switch (event) {
1004 case SND_SOC_DAPM_PRE_PMU:
1005 wm8994->aif1clk_enable = 1;
1006 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001007 case SND_SOC_DAPM_POST_PMD:
1008 wm8994->aif1clk_disable = 1;
1009 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001010 }
1011
1012 return 0;
1013}
1014
1015static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1016 struct snd_kcontrol *kcontrol, int event)
1017{
1018 struct snd_soc_codec *codec = w->codec;
1019 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1020
1021 switch (event) {
1022 case SND_SOC_DAPM_PRE_PMU:
1023 wm8994->aif2clk_enable = 1;
1024 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001025 case SND_SOC_DAPM_POST_PMD:
1026 wm8994->aif2clk_disable = 1;
1027 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001028 }
1029
1030 return 0;
1031}
1032
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001033static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1034 struct snd_kcontrol *kcontrol, int event)
1035{
1036 late_enable_ev(w, kcontrol, event);
1037 return 0;
1038}
1039
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001040static int micbias_ev(struct snd_soc_dapm_widget *w,
1041 struct snd_kcontrol *kcontrol, int event)
1042{
1043 late_enable_ev(w, kcontrol, event);
1044 return 0;
1045}
1046
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001047static int dac_ev(struct snd_soc_dapm_widget *w,
1048 struct snd_kcontrol *kcontrol, int event)
1049{
1050 struct snd_soc_codec *codec = w->codec;
1051 unsigned int mask = 1 << w->shift;
1052
1053 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1054 mask, mask);
1055 return 0;
1056}
1057
Mark Brown9e6e96a2010-01-29 17:47:12 +00001058static const char *hp_mux_text[] = {
1059 "Mixer",
1060 "DAC",
1061};
1062
1063#define WM8994_HP_ENUM(xname, xenum) \
1064{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1065 .info = snd_soc_info_enum_double, \
1066 .get = snd_soc_dapm_get_enum_double, \
1067 .put = wm8994_put_hp_enum, \
1068 .private_value = (unsigned long)&xenum }
1069
1070static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1071 struct snd_ctl_elem_value *ucontrol)
1072{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001073 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1074 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001075 struct snd_soc_codec *codec = w->codec;
1076 int ret;
1077
1078 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1079
1080 wm8994_update_class_w(codec);
1081
1082 return ret;
1083}
1084
1085static const struct soc_enum hpl_enum =
1086 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1087
1088static const struct snd_kcontrol_new hpl_mux =
1089 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1090
1091static const struct soc_enum hpr_enum =
1092 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1093
1094static const struct snd_kcontrol_new hpr_mux =
1095 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1096
1097static const char *adc_mux_text[] = {
1098 "ADC",
1099 "DMIC",
1100};
1101
1102static const struct soc_enum adc_enum =
1103 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1104
1105static const struct snd_kcontrol_new adcl_mux =
1106 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1107
1108static const struct snd_kcontrol_new adcr_mux =
1109 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1110
1111static const struct snd_kcontrol_new left_speaker_mixer[] = {
1112SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1113SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1114SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1115SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1116SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1117};
1118
1119static const struct snd_kcontrol_new right_speaker_mixer[] = {
1120SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1121SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1122SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1123SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1124SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1125};
1126
1127/* Debugging; dump chip status after DAPM transitions */
1128static int post_ev(struct snd_soc_dapm_widget *w,
1129 struct snd_kcontrol *kcontrol, int event)
1130{
1131 struct snd_soc_codec *codec = w->codec;
1132 dev_dbg(codec->dev, "SRC status: %x\n",
1133 snd_soc_read(codec,
1134 WM8994_RATE_STATUS));
1135 return 0;
1136}
1137
1138static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1139SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1140 1, 1, 0),
1141SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1142 0, 1, 0),
1143};
1144
1145static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1146SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1147 1, 1, 0),
1148SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1149 0, 1, 0),
1150};
1151
Mark Browna3257ba2010-07-19 14:02:34 +01001152static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1153SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1154 1, 1, 0),
1155SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1156 0, 1, 0),
1157};
1158
1159static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1160SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1161 1, 1, 0),
1162SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1163 0, 1, 0),
1164};
1165
Mark Brown9e6e96a2010-01-29 17:47:12 +00001166static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1167SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1168 5, 1, 0),
1169SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1170 4, 1, 0),
1171SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1172 2, 1, 0),
1173SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1174 1, 1, 0),
1175SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1176 0, 1, 0),
1177};
1178
1179static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1180SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1181 5, 1, 0),
1182SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1183 4, 1, 0),
1184SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1185 2, 1, 0),
1186SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1187 1, 1, 0),
1188SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1189 0, 1, 0),
1190};
1191
1192#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1193{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1194 .info = snd_soc_info_volsw, \
1195 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1196 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1197
1198static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1199 struct snd_ctl_elem_value *ucontrol)
1200{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001201 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1202 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001203 struct snd_soc_codec *codec = w->codec;
1204 int ret;
1205
1206 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1207
1208 wm8994_update_class_w(codec);
1209
1210 return ret;
1211}
1212
1213static const struct snd_kcontrol_new dac1l_mix[] = {
1214WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1215 5, 1, 0),
1216WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1217 4, 1, 0),
1218WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1219 2, 1, 0),
1220WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1221 1, 1, 0),
1222WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1223 0, 1, 0),
1224};
1225
1226static const struct snd_kcontrol_new dac1r_mix[] = {
1227WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1228 5, 1, 0),
1229WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1230 4, 1, 0),
1231WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1232 2, 1, 0),
1233WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1234 1, 1, 0),
1235WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1236 0, 1, 0),
1237};
1238
1239static const char *sidetone_text[] = {
1240 "ADC/DMIC1", "DMIC2",
1241};
1242
1243static const struct soc_enum sidetone1_enum =
1244 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1245
1246static const struct snd_kcontrol_new sidetone1_mux =
1247 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1248
1249static const struct soc_enum sidetone2_enum =
1250 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1251
1252static const struct snd_kcontrol_new sidetone2_mux =
1253 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1254
1255static const char *aif1dac_text[] = {
1256 "AIF1DACDAT", "AIF3DACDAT",
1257};
1258
1259static const struct soc_enum aif1dac_enum =
1260 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1261
1262static const struct snd_kcontrol_new aif1dac_mux =
1263 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1264
1265static const char *aif2dac_text[] = {
1266 "AIF2DACDAT", "AIF3DACDAT",
1267};
1268
1269static const struct soc_enum aif2dac_enum =
1270 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1271
1272static const struct snd_kcontrol_new aif2dac_mux =
1273 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1274
1275static const char *aif2adc_text[] = {
1276 "AIF2ADCDAT", "AIF3DACDAT",
1277};
1278
1279static const struct soc_enum aif2adc_enum =
1280 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1281
1282static const struct snd_kcontrol_new aif2adc_mux =
1283 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1284
1285static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001286 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001287};
1288
Mark Brownc4431df2010-11-26 15:21:07 +00001289static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001290 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1291
Mark Brownc4431df2010-11-26 15:21:07 +00001292static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1293 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1294
1295static const struct soc_enum wm8958_aif3adc_enum =
1296 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1297
1298static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1299 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1300
1301static const char *mono_pcm_out_text[] = {
1302 "None", "AIF2ADCL", "AIF2ADCR",
1303};
1304
1305static const struct soc_enum mono_pcm_out_enum =
1306 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1307
1308static const struct snd_kcontrol_new mono_pcm_out_mux =
1309 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1310
1311static const char *aif2dac_src_text[] = {
1312 "AIF2", "AIF3",
1313};
1314
1315/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1316static const struct soc_enum aif2dacl_src_enum =
1317 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1318
1319static const struct snd_kcontrol_new aif2dacl_src_mux =
1320 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1321
1322static const struct soc_enum aif2dacr_src_enum =
1323 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1324
1325static const struct snd_kcontrol_new aif2dacr_src_mux =
1326 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001327
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001328static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1329SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1330 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1331SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1332 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1333
1334SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1335 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1336SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1337 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1338SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1339 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1340SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1341 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001342SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1343 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1344
1345SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1346 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1347 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1348SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1349 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1350 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1351SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1352 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1353SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1354 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001355
1356SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1357};
1358
1359static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1360SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
Mark Brownb70a51b2011-06-29 00:21:09 -07001361SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
1362SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1363SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1364 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1365SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1366 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1367SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1368SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001369};
1370
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001371static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1372SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1373 dac_ev, SND_SOC_DAPM_PRE_PMU),
1374SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1375 dac_ev, SND_SOC_DAPM_PRE_PMU),
1376SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1377 dac_ev, SND_SOC_DAPM_PRE_PMU),
1378SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1379 dac_ev, SND_SOC_DAPM_PRE_PMU),
1380};
1381
1382static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1383SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001384SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001385SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1386SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1387};
1388
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001389static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001390SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1391 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1392SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1393 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001394};
1395
1396static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001397SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1398SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001399};
1400
Mark Brown9e6e96a2010-01-29 17:47:12 +00001401static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1402SND_SOC_DAPM_INPUT("DMIC1DAT"),
1403SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001404SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001405
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001406SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1407 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001408SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1409 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001410
Mark Brown9e6e96a2010-01-29 17:47:12 +00001411SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1412 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1413
1414SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1415SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1416SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1417
Mark Brown7f94de42011-02-03 16:27:34 +00001418SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001419 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001420SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001421 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001422SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1423 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001424 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001425SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1426 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001427 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001428
Mark Brown7f94de42011-02-03 16:27:34 +00001429SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001430 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001431SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001432 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001433SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1434 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001435 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001436SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1437 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001438 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001439
1440SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1441 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1442SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1443 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1444
Mark Browna3257ba2010-07-19 14:02:34 +01001445SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1446 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1447SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1448 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1449
Mark Brown9e6e96a2010-01-29 17:47:12 +00001450SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1451 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1452SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1453 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1454
1455SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1456SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1457
1458SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1459 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1460SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1461 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1462
1463SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1464 WM8994_POWER_MANAGEMENT_4, 13, 0),
1465SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1466 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001467SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1468 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1469 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1470SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1471 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1472 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001473
Mark Brown5567d8c2012-02-16 21:43:29 -08001474SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1475SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1476SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1477SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001478
1479SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1480SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1481SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001482
Mark Brown5567d8c2012-02-16 21:43:29 -08001483SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1484SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001485
1486SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1487
1488SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1489SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1490SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1491SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1492
1493/* Power is done with the muxes since the ADC power also controls the
1494 * downsampling chain, the chip will automatically manage the analogue
1495 * specific portions.
1496 */
1497SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1498SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1499
Mark Brown9e6e96a2010-01-29 17:47:12 +00001500SND_SOC_DAPM_POST("Debug log", post_ev),
1501};
1502
Mark Brownc4431df2010-11-26 15:21:07 +00001503static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1504SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1505};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001506
Mark Brownc4431df2010-11-26 15:21:07 +00001507static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1508SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1509SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1510SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1511SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1512};
1513
1514static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001515 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1516 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1517
1518 { "DSP1CLK", NULL, "CLK_SYS" },
1519 { "DSP2CLK", NULL, "CLK_SYS" },
1520 { "DSPINTCLK", NULL, "CLK_SYS" },
1521
1522 { "AIF1ADC1L", NULL, "AIF1CLK" },
1523 { "AIF1ADC1L", NULL, "DSP1CLK" },
1524 { "AIF1ADC1R", NULL, "AIF1CLK" },
1525 { "AIF1ADC1R", NULL, "DSP1CLK" },
1526 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1527
1528 { "AIF1DAC1L", NULL, "AIF1CLK" },
1529 { "AIF1DAC1L", NULL, "DSP1CLK" },
1530 { "AIF1DAC1R", NULL, "AIF1CLK" },
1531 { "AIF1DAC1R", NULL, "DSP1CLK" },
1532 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1533
1534 { "AIF1ADC2L", NULL, "AIF1CLK" },
1535 { "AIF1ADC2L", NULL, "DSP1CLK" },
1536 { "AIF1ADC2R", NULL, "AIF1CLK" },
1537 { "AIF1ADC2R", NULL, "DSP1CLK" },
1538 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1539
1540 { "AIF1DAC2L", NULL, "AIF1CLK" },
1541 { "AIF1DAC2L", NULL, "DSP1CLK" },
1542 { "AIF1DAC2R", NULL, "AIF1CLK" },
1543 { "AIF1DAC2R", NULL, "DSP1CLK" },
1544 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1545
1546 { "AIF2ADCL", NULL, "AIF2CLK" },
1547 { "AIF2ADCL", NULL, "DSP2CLK" },
1548 { "AIF2ADCR", NULL, "AIF2CLK" },
1549 { "AIF2ADCR", NULL, "DSP2CLK" },
1550 { "AIF2ADCR", NULL, "DSPINTCLK" },
1551
1552 { "AIF2DACL", NULL, "AIF2CLK" },
1553 { "AIF2DACL", NULL, "DSP2CLK" },
1554 { "AIF2DACR", NULL, "AIF2CLK" },
1555 { "AIF2DACR", NULL, "DSP2CLK" },
1556 { "AIF2DACR", NULL, "DSPINTCLK" },
1557
1558 { "DMIC1L", NULL, "DMIC1DAT" },
1559 { "DMIC1L", NULL, "CLK_SYS" },
1560 { "DMIC1R", NULL, "DMIC1DAT" },
1561 { "DMIC1R", NULL, "CLK_SYS" },
1562 { "DMIC2L", NULL, "DMIC2DAT" },
1563 { "DMIC2L", NULL, "CLK_SYS" },
1564 { "DMIC2R", NULL, "DMIC2DAT" },
1565 { "DMIC2R", NULL, "CLK_SYS" },
1566
1567 { "ADCL", NULL, "AIF1CLK" },
1568 { "ADCL", NULL, "DSP1CLK" },
1569 { "ADCL", NULL, "DSPINTCLK" },
1570
1571 { "ADCR", NULL, "AIF1CLK" },
1572 { "ADCR", NULL, "DSP1CLK" },
1573 { "ADCR", NULL, "DSPINTCLK" },
1574
1575 { "ADCL Mux", "ADC", "ADCL" },
1576 { "ADCL Mux", "DMIC", "DMIC1L" },
1577 { "ADCR Mux", "ADC", "ADCR" },
1578 { "ADCR Mux", "DMIC", "DMIC1R" },
1579
1580 { "DAC1L", NULL, "AIF1CLK" },
1581 { "DAC1L", NULL, "DSP1CLK" },
1582 { "DAC1L", NULL, "DSPINTCLK" },
1583
1584 { "DAC1R", NULL, "AIF1CLK" },
1585 { "DAC1R", NULL, "DSP1CLK" },
1586 { "DAC1R", NULL, "DSPINTCLK" },
1587
1588 { "DAC2L", NULL, "AIF2CLK" },
1589 { "DAC2L", NULL, "DSP2CLK" },
1590 { "DAC2L", NULL, "DSPINTCLK" },
1591
1592 { "DAC2R", NULL, "AIF2DACR" },
1593 { "DAC2R", NULL, "AIF2CLK" },
1594 { "DAC2R", NULL, "DSP2CLK" },
1595 { "DAC2R", NULL, "DSPINTCLK" },
1596
1597 { "TOCLK", NULL, "CLK_SYS" },
1598
Mark Brown5567d8c2012-02-16 21:43:29 -08001599 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1600 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1601 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1602
1603 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1604 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1605 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1606
Mark Brown9e6e96a2010-01-29 17:47:12 +00001607 /* AIF1 outputs */
1608 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1609 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1610 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1611
1612 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1613 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1614 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1615
Mark Browna3257ba2010-07-19 14:02:34 +01001616 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1617 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1618 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1619
1620 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1621 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1622 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1623
Mark Brown9e6e96a2010-01-29 17:47:12 +00001624 /* Pin level routing for AIF3 */
1625 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1626 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1627 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1628 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1629
Mark Brown9e6e96a2010-01-29 17:47:12 +00001630 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1631 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1632 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1633 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1634 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1635 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1636 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1637
1638 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001639 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1640 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1641 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1642 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1643 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1644
Mark Brown9e6e96a2010-01-29 17:47:12 +00001645 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1646 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1647 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1648 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1649 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1650
1651 /* DAC2/AIF2 outputs */
1652 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001653 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1654 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1655 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1656 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1657 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1658
1659 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001660 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1661 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1662 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1663 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1664 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1665
Mark Brown7f94de42011-02-03 16:27:34 +00001666 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1667 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1668 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1669 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1670
Mark Brown9e6e96a2010-01-29 17:47:12 +00001671 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1672
1673 /* AIF3 output */
1674 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1675 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1676 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1677 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1678 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1679 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1680 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1681 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1682
1683 /* Sidetone */
1684 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1685 { "Left Sidetone", "DMIC2", "DMIC2L" },
1686 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1687 { "Right Sidetone", "DMIC2", "DMIC2R" },
1688
1689 /* Output stages */
1690 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1691 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1692
1693 { "SPKL", "DAC1 Switch", "DAC1L" },
1694 { "SPKL", "DAC2 Switch", "DAC2L" },
1695
1696 { "SPKR", "DAC1 Switch", "DAC1R" },
1697 { "SPKR", "DAC2 Switch", "DAC2R" },
1698
1699 { "Left Headphone Mux", "DAC", "DAC1L" },
1700 { "Right Headphone Mux", "DAC", "DAC1R" },
1701};
1702
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001703static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1704 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1705 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1706 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1707 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1708 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1709 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1710 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1711 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1712};
1713
1714static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1715 { "DAC1L", NULL, "DAC1L Mixer" },
1716 { "DAC1R", NULL, "DAC1R Mixer" },
1717 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1718 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1719};
1720
Mark Brown6ed8f142011-02-03 16:27:35 +00001721static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1722 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1723 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1724 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1725 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001726 { "MICBIAS1", NULL, "CLK_SYS" },
1727 { "MICBIAS1", NULL, "MICBIAS Supply" },
1728 { "MICBIAS2", NULL, "CLK_SYS" },
1729 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001730};
1731
Mark Brownc4431df2010-11-26 15:21:07 +00001732static const struct snd_soc_dapm_route wm8994_intercon[] = {
1733 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1734 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001735 { "MICBIAS1", NULL, "VMID" },
1736 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001737};
1738
1739static const struct snd_soc_dapm_route wm8958_intercon[] = {
1740 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1741 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1742
1743 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1744 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1745 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1746 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1747
1748 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1749 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1750
1751 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1752};
1753
Mark Brown9e6e96a2010-01-29 17:47:12 +00001754/* The size in bits of the FLL divide multiplied by 10
1755 * to allow rounding later */
1756#define FIXED_FLL_SIZE ((1 << 16) * 10)
1757
1758struct fll_div {
1759 u16 outdiv;
1760 u16 n;
1761 u16 k;
1762 u16 clk_ref_div;
1763 u16 fll_fratio;
1764};
1765
1766static int wm8994_get_fll_config(struct fll_div *fll,
1767 int freq_in, int freq_out)
1768{
1769 u64 Kpart;
1770 unsigned int K, Ndiv, Nmod;
1771
1772 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1773
1774 /* Scale the input frequency down to <= 13.5MHz */
1775 fll->clk_ref_div = 0;
1776 while (freq_in > 13500000) {
1777 fll->clk_ref_div++;
1778 freq_in /= 2;
1779
1780 if (fll->clk_ref_div > 3)
1781 return -EINVAL;
1782 }
1783 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1784
1785 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1786 fll->outdiv = 3;
1787 while (freq_out * (fll->outdiv + 1) < 90000000) {
1788 fll->outdiv++;
1789 if (fll->outdiv > 63)
1790 return -EINVAL;
1791 }
1792 freq_out *= fll->outdiv + 1;
1793 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1794
1795 if (freq_in > 1000000) {
1796 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001797 } else if (freq_in > 256000) {
1798 fll->fll_fratio = 1;
1799 freq_in *= 2;
1800 } else if (freq_in > 128000) {
1801 fll->fll_fratio = 2;
1802 freq_in *= 4;
1803 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001804 fll->fll_fratio = 3;
1805 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001806 } else {
1807 fll->fll_fratio = 4;
1808 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001809 }
1810 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1811
1812 /* Now, calculate N.K */
1813 Ndiv = freq_out / freq_in;
1814
1815 fll->n = Ndiv;
1816 Nmod = freq_out % freq_in;
1817 pr_debug("Nmod=%d\n", Nmod);
1818
1819 /* Calculate fractional part - scale up so we can round. */
1820 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1821
1822 do_div(Kpart, freq_in);
1823
1824 K = Kpart & 0xFFFFFFFF;
1825
1826 if ((K % 10) >= 5)
1827 K += 5;
1828
1829 /* Move down to proper range now rounding is done */
1830 fll->k = K / 10;
1831
1832 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1833
1834 return 0;
1835}
1836
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001837static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001838 unsigned int freq_in, unsigned int freq_out)
1839{
Mark Brownb2c812e2010-04-14 15:35:19 +09001840 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01001841 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001842 int reg_offset, ret;
1843 struct fll_div fll;
1844 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001845 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001846 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001847
1848 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1849 & WM8994_AIF1CLK_ENA;
1850
1851 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1852 & WM8994_AIF2CLK_ENA;
1853
1854 switch (id) {
1855 case WM8994_FLL1:
1856 reg_offset = 0;
1857 id = 0;
1858 break;
1859 case WM8994_FLL2:
1860 reg_offset = 0x20;
1861 id = 1;
1862 break;
1863 default:
1864 return -EINVAL;
1865 }
1866
Mark Brown4b7ed832011-08-10 17:47:33 +09001867 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1868 was_enabled = reg & WM8994_FLL1_ENA;
1869
Mark Brown136ff2a2010-04-20 12:56:18 +09001870 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001871 case 0:
1872 /* Allow no source specification when stopping */
1873 if (freq_out)
1874 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001875 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001876 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001877 case WM8994_FLL_SRC_MCLK1:
1878 case WM8994_FLL_SRC_MCLK2:
1879 case WM8994_FLL_SRC_LRCLK:
1880 case WM8994_FLL_SRC_BCLK:
1881 break;
1882 default:
1883 return -EINVAL;
1884 }
1885
Mark Brown9e6e96a2010-01-29 17:47:12 +00001886 /* Are we changing anything? */
1887 if (wm8994->fll[id].src == src &&
1888 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1889 return 0;
1890
1891 /* If we're stopping the FLL redo the old config - no
1892 * registers will actually be written but we avoid GCC flow
1893 * analysis bugs spewing warnings.
1894 */
1895 if (freq_out)
1896 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1897 else
1898 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1899 wm8994->fll[id].out);
1900 if (ret < 0)
1901 return ret;
1902
1903 /* Gate the AIF clocks while we reclock */
1904 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1905 WM8994_AIF1CLK_ENA, 0);
1906 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1907 WM8994_AIF2CLK_ENA, 0);
1908
1909 /* We always need to disable the FLL while reconfiguring */
1910 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1911 WM8994_FLL1_ENA, 0);
1912
1913 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1914 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1915 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1916 WM8994_FLL1_OUTDIV_MASK |
1917 WM8994_FLL1_FRATIO_MASK, reg);
1918
Mark Brownb16db742012-03-03 15:33:23 +00001919 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
1920 WM8994_FLL1_K_MASK, fll.k);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001921
1922 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1923 WM8994_FLL1_N_MASK,
1924 fll.n << WM8994_FLL1_N_SHIFT);
1925
1926 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001927 WM8994_FLL1_REFCLK_DIV_MASK |
1928 WM8994_FLL1_REFCLK_SRC_MASK,
1929 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1930 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001931
Mark Brownf0f50392011-07-16 03:12:18 +09001932 /* Clear any pending completion from a previous failure */
1933 try_wait_for_completion(&wm8994->fll_locked[id]);
1934
Mark Brown9e6e96a2010-01-29 17:47:12 +00001935 /* Enable (with fractional mode if required) */
1936 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001937 /* Enable VMID if we need it */
1938 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001939 active_reference(codec);
1940
Mark Brown4b7ed832011-08-10 17:47:33 +09001941 switch (control->type) {
1942 case WM8994:
1943 vmid_reference(codec);
1944 break;
1945 case WM8958:
1946 if (wm8994->revision < 1)
1947 vmid_reference(codec);
1948 break;
1949 default:
1950 break;
1951 }
1952 }
1953
Mark Brown9e6e96a2010-01-29 17:47:12 +00001954 if (fll.k)
1955 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1956 else
1957 reg = WM8994_FLL1_ENA;
1958 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1959 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1960 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001961
Mark Brownc7ebf932011-07-12 19:47:59 +09001962 if (wm8994->fll_locked_irq) {
1963 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1964 msecs_to_jiffies(10));
1965 if (timeout == 0)
1966 dev_warn(codec->dev,
1967 "Timed out waiting for FLL lock\n");
1968 } else {
1969 msleep(5);
1970 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001971 } else {
1972 if (was_enabled) {
1973 switch (control->type) {
1974 case WM8994:
1975 vmid_dereference(codec);
1976 break;
1977 case WM8958:
1978 if (wm8994->revision < 1)
1979 vmid_dereference(codec);
1980 break;
1981 default:
1982 break;
1983 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001984
1985 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001986 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00001987 }
1988
1989 wm8994->fll[id].in = freq_in;
1990 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001991 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001992
1993 /* Enable any gated AIF clocks */
1994 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1995 WM8994_AIF1CLK_ENA, aif1);
1996 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1997 WM8994_AIF2CLK_ENA, aif2);
1998
1999 configure_clock(codec);
2000
2001 return 0;
2002}
2003
Mark Brownc7ebf932011-07-12 19:47:59 +09002004static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2005{
2006 struct completion *completion = data;
2007
2008 complete(completion);
2009
2010 return IRQ_HANDLED;
2011}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002012
Mark Brown66b47fd2010-07-08 11:25:43 +09002013static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2014
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002015static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2016 unsigned int freq_in, unsigned int freq_out)
2017{
2018 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2019}
2020
Mark Brown9e6e96a2010-01-29 17:47:12 +00002021static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2022 int clk_id, unsigned int freq, int dir)
2023{
2024 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002025 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002026 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002027
2028 switch (dai->id) {
2029 case 1:
2030 case 2:
2031 break;
2032
2033 default:
2034 /* AIF3 shares clocking with AIF1/2 */
2035 return -EINVAL;
2036 }
2037
2038 switch (clk_id) {
2039 case WM8994_SYSCLK_MCLK1:
2040 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2041 wm8994->mclk[0] = freq;
2042 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2043 dai->id, freq);
2044 break;
2045
2046 case WM8994_SYSCLK_MCLK2:
2047 /* TODO: Set GPIO AF */
2048 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2049 wm8994->mclk[1] = freq;
2050 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2051 dai->id, freq);
2052 break;
2053
2054 case WM8994_SYSCLK_FLL1:
2055 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2056 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2057 break;
2058
2059 case WM8994_SYSCLK_FLL2:
2060 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2061 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2062 break;
2063
Mark Brown66b47fd2010-07-08 11:25:43 +09002064 case WM8994_SYSCLK_OPCLK:
2065 /* Special case - a division (times 10) is given and
2066 * no effect on main clocking.
2067 */
2068 if (freq) {
2069 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2070 if (opclk_divs[i] == freq)
2071 break;
2072 if (i == ARRAY_SIZE(opclk_divs))
2073 return -EINVAL;
2074 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2075 WM8994_OPCLK_DIV_MASK, i);
2076 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2077 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2078 } else {
2079 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2080 WM8994_OPCLK_ENA, 0);
2081 }
2082
Mark Brown9e6e96a2010-01-29 17:47:12 +00002083 default:
2084 return -EINVAL;
2085 }
2086
2087 configure_clock(codec);
2088
2089 return 0;
2090}
2091
2092static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2093 enum snd_soc_bias_level level)
2094{
Mark Brownb6b05692010-08-13 12:58:20 +01002095 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002096 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002097
Mark Brown5f2f3892012-02-08 18:51:42 +00002098 wm_hubs_set_bias_level(codec, level);
2099
Mark Brown9e6e96a2010-01-29 17:47:12 +00002100 switch (level) {
2101 case SND_SOC_BIAS_ON:
2102 break;
2103
2104 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002105 /* MICBIAS into regulating mode */
2106 switch (control->type) {
2107 case WM8958:
2108 case WM1811:
2109 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2110 WM8958_MICB1_MODE, 0);
2111 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2112 WM8958_MICB2_MODE, 0);
2113 break;
2114 default:
2115 break;
2116 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002117
2118 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2119 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002120 break;
2121
2122 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002123 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002124 switch (control->type) {
2125 case WM8994:
2126 if (wm8994->revision < 4) {
2127 /* Tweak DC servo and DSP
2128 * configuration for improved
2129 * performance. */
2130 snd_soc_write(codec, 0x102, 0x3);
2131 snd_soc_write(codec, 0x56, 0x3);
2132 snd_soc_write(codec, 0x817, 0);
2133 snd_soc_write(codec, 0x102, 0);
2134 }
2135 break;
2136
2137 case WM8958:
2138 if (wm8994->revision == 0) {
2139 /* Optimise performance for rev A */
2140 snd_soc_write(codec, 0x102, 0x3);
2141 snd_soc_write(codec, 0xcb, 0x81);
2142 snd_soc_write(codec, 0x817, 0);
2143 snd_soc_write(codec, 0x102, 0);
2144
2145 snd_soc_update_bits(codec,
2146 WM8958_CHARGE_PUMP_2,
2147 WM8958_CP_DISCH,
2148 WM8958_CP_DISCH);
2149 }
2150 break;
Mark Brown81204c82011-05-24 17:35:53 +08002151
2152 case WM1811:
2153 if (wm8994->revision < 2) {
2154 snd_soc_write(codec, 0x102, 0x3);
2155 snd_soc_write(codec, 0x5d, 0x7e);
2156 snd_soc_write(codec, 0x5e, 0x0);
2157 snd_soc_write(codec, 0x102, 0x0);
2158 }
2159 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002160 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002161
2162 /* Discharge LINEOUT1 & 2 */
2163 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2164 WM8994_LINEOUT1_DISCH |
2165 WM8994_LINEOUT2_DISCH,
2166 WM8994_LINEOUT1_DISCH |
2167 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002168 }
2169
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002170 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2171 active_dereference(codec);
2172
Mark Brown500fa302011-11-29 19:58:19 +00002173 /* MICBIAS into bypass mode on newer devices */
2174 switch (control->type) {
2175 case WM8958:
2176 case WM1811:
2177 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2178 WM8958_MICB1_MODE,
2179 WM8958_MICB1_MODE);
2180 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2181 WM8958_MICB2_MODE,
2182 WM8958_MICB2_MODE);
2183 break;
2184 default:
2185 break;
2186 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002187 break;
2188
2189 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002190 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002191 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002192 break;
2193 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002194
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002195 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002196
Mark Brown9e6e96a2010-01-29 17:47:12 +00002197 return 0;
2198}
2199
2200static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2201{
2202 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002203 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2204 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002205 int ms_reg;
2206 int aif1_reg;
2207 int ms = 0;
2208 int aif1 = 0;
2209
2210 switch (dai->id) {
2211 case 1:
2212 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2213 aif1_reg = WM8994_AIF1_CONTROL_1;
2214 break;
2215 case 2:
2216 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2217 aif1_reg = WM8994_AIF2_CONTROL_1;
2218 break;
2219 default:
2220 return -EINVAL;
2221 }
2222
2223 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2224 case SND_SOC_DAIFMT_CBS_CFS:
2225 break;
2226 case SND_SOC_DAIFMT_CBM_CFM:
2227 ms = WM8994_AIF1_MSTR;
2228 break;
2229 default:
2230 return -EINVAL;
2231 }
2232
2233 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2234 case SND_SOC_DAIFMT_DSP_B:
2235 aif1 |= WM8994_AIF1_LRCLK_INV;
2236 case SND_SOC_DAIFMT_DSP_A:
2237 aif1 |= 0x18;
2238 break;
2239 case SND_SOC_DAIFMT_I2S:
2240 aif1 |= 0x10;
2241 break;
2242 case SND_SOC_DAIFMT_RIGHT_J:
2243 break;
2244 case SND_SOC_DAIFMT_LEFT_J:
2245 aif1 |= 0x8;
2246 break;
2247 default:
2248 return -EINVAL;
2249 }
2250
2251 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2252 case SND_SOC_DAIFMT_DSP_A:
2253 case SND_SOC_DAIFMT_DSP_B:
2254 /* frame inversion not valid for DSP modes */
2255 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2256 case SND_SOC_DAIFMT_NB_NF:
2257 break;
2258 case SND_SOC_DAIFMT_IB_NF:
2259 aif1 |= WM8994_AIF1_BCLK_INV;
2260 break;
2261 default:
2262 return -EINVAL;
2263 }
2264 break;
2265
2266 case SND_SOC_DAIFMT_I2S:
2267 case SND_SOC_DAIFMT_RIGHT_J:
2268 case SND_SOC_DAIFMT_LEFT_J:
2269 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2270 case SND_SOC_DAIFMT_NB_NF:
2271 break;
2272 case SND_SOC_DAIFMT_IB_IF:
2273 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2274 break;
2275 case SND_SOC_DAIFMT_IB_NF:
2276 aif1 |= WM8994_AIF1_BCLK_INV;
2277 break;
2278 case SND_SOC_DAIFMT_NB_IF:
2279 aif1 |= WM8994_AIF1_LRCLK_INV;
2280 break;
2281 default:
2282 return -EINVAL;
2283 }
2284 break;
2285 default:
2286 return -EINVAL;
2287 }
2288
Mark Brownc4431df2010-11-26 15:21:07 +00002289 /* The AIF2 format configuration needs to be mirrored to AIF3
2290 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002291 switch (control->type) {
2292 case WM1811:
2293 case WM8958:
2294 if (dai->id == 2)
2295 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2296 WM8994_AIF1_LRCLK_INV |
2297 WM8958_AIF3_FMT_MASK, aif1);
2298 break;
2299
2300 default:
2301 break;
2302 }
Mark Brownc4431df2010-11-26 15:21:07 +00002303
Mark Brown9e6e96a2010-01-29 17:47:12 +00002304 snd_soc_update_bits(codec, aif1_reg,
2305 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2306 WM8994_AIF1_FMT_MASK,
2307 aif1);
2308 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2309 ms);
2310
2311 return 0;
2312}
2313
2314static struct {
2315 int val, rate;
2316} srs[] = {
2317 { 0, 8000 },
2318 { 1, 11025 },
2319 { 2, 12000 },
2320 { 3, 16000 },
2321 { 4, 22050 },
2322 { 5, 24000 },
2323 { 6, 32000 },
2324 { 7, 44100 },
2325 { 8, 48000 },
2326 { 9, 88200 },
2327 { 10, 96000 },
2328};
2329
2330static int fs_ratios[] = {
2331 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2332};
2333
2334static int bclk_divs[] = {
2335 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2336 640, 880, 960, 1280, 1760, 1920
2337};
2338
2339static int wm8994_hw_params(struct snd_pcm_substream *substream,
2340 struct snd_pcm_hw_params *params,
2341 struct snd_soc_dai *dai)
2342{
2343 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002344 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002345 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002346 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002347 int bclk_reg;
2348 int lrclk_reg;
2349 int rate_reg;
2350 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002351 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002352 int bclk = 0;
2353 int lrclk = 0;
2354 int rate_val = 0;
2355 int id = dai->id - 1;
2356
2357 int i, cur_val, best_val, bclk_rate, best;
2358
2359 switch (dai->id) {
2360 case 1:
2361 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002362 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002363 bclk_reg = WM8994_AIF1_BCLK;
2364 rate_reg = WM8994_AIF1_RATE;
2365 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002366 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002367 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002368 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002369 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002370 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2371 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002372 break;
2373 case 2:
2374 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002375 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002376 bclk_reg = WM8994_AIF2_BCLK;
2377 rate_reg = WM8994_AIF2_RATE;
2378 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002379 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002380 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002381 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002382 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002383 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2384 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002385 break;
2386 default:
2387 return -EINVAL;
2388 }
2389
2390 bclk_rate = params_rate(params) * 2;
2391 switch (params_format(params)) {
2392 case SNDRV_PCM_FORMAT_S16_LE:
2393 bclk_rate *= 16;
2394 break;
2395 case SNDRV_PCM_FORMAT_S20_3LE:
2396 bclk_rate *= 20;
2397 aif1 |= 0x20;
2398 break;
2399 case SNDRV_PCM_FORMAT_S24_LE:
2400 bclk_rate *= 24;
2401 aif1 |= 0x40;
2402 break;
2403 case SNDRV_PCM_FORMAT_S32_LE:
2404 bclk_rate *= 32;
2405 aif1 |= 0x60;
2406 break;
2407 default:
2408 return -EINVAL;
2409 }
2410
2411 /* Try to find an appropriate sample rate; look for an exact match. */
2412 for (i = 0; i < ARRAY_SIZE(srs); i++)
2413 if (srs[i].rate == params_rate(params))
2414 break;
2415 if (i == ARRAY_SIZE(srs))
2416 return -EINVAL;
2417 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2418
2419 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2420 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2421 dai->id, wm8994->aifclk[id], bclk_rate);
2422
Mark Brownb1e43d92010-12-07 17:14:56 +00002423 if (params_channels(params) == 1 &&
2424 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2425 aif2 |= WM8994_AIF1_MONO;
2426
Mark Brown9e6e96a2010-01-29 17:47:12 +00002427 if (wm8994->aifclk[id] == 0) {
2428 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2429 return -EINVAL;
2430 }
2431
2432 /* AIFCLK/fs ratio; look for a close match in either direction */
2433 best = 0;
2434 best_val = abs((fs_ratios[0] * params_rate(params))
2435 - wm8994->aifclk[id]);
2436 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2437 cur_val = abs((fs_ratios[i] * params_rate(params))
2438 - wm8994->aifclk[id]);
2439 if (cur_val >= best_val)
2440 continue;
2441 best = i;
2442 best_val = cur_val;
2443 }
2444 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2445 dai->id, fs_ratios[best]);
2446 rate_val |= best;
2447
2448 /* We may not get quite the right frequency if using
2449 * approximate clocks so look for the closest match that is
2450 * higher than the target (we need to ensure that there enough
2451 * BCLKs to clock out the samples).
2452 */
2453 best = 0;
2454 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002455 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002456 if (cur_val < 0) /* BCLK table is sorted */
2457 break;
2458 best = i;
2459 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002460 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002461 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2462 bclk_divs[best], bclk_rate);
2463 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2464
2465 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002466 if (!lrclk) {
2467 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2468 bclk_rate);
2469 return -EINVAL;
2470 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002471 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2472 lrclk, bclk_rate / lrclk);
2473
2474 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002475 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002476 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2477 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2478 lrclk);
2479 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2480 WM8994_AIF1CLK_RATE_MASK, rate_val);
2481
2482 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2483 switch (dai->id) {
2484 case 1:
2485 wm8994->dac_rates[0] = params_rate(params);
2486 wm8994_set_retune_mobile(codec, 0);
2487 wm8994_set_retune_mobile(codec, 1);
2488 break;
2489 case 2:
2490 wm8994->dac_rates[1] = params_rate(params);
2491 wm8994_set_retune_mobile(codec, 2);
2492 break;
2493 }
2494 }
2495
2496 return 0;
2497}
2498
Mark Brownc4431df2010-11-26 15:21:07 +00002499static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2500 struct snd_pcm_hw_params *params,
2501 struct snd_soc_dai *dai)
2502{
2503 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002504 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2505 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002506 int aif1_reg;
2507 int aif1 = 0;
2508
2509 switch (dai->id) {
2510 case 3:
2511 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002512 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002513 case WM8958:
2514 aif1_reg = WM8958_AIF3_CONTROL_1;
2515 break;
2516 default:
2517 return 0;
2518 }
2519 default:
2520 return 0;
2521 }
2522
2523 switch (params_format(params)) {
2524 case SNDRV_PCM_FORMAT_S16_LE:
2525 break;
2526 case SNDRV_PCM_FORMAT_S20_3LE:
2527 aif1 |= 0x20;
2528 break;
2529 case SNDRV_PCM_FORMAT_S24_LE:
2530 aif1 |= 0x40;
2531 break;
2532 case SNDRV_PCM_FORMAT_S32_LE:
2533 aif1 |= 0x60;
2534 break;
2535 default:
2536 return -EINVAL;
2537 }
2538
2539 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2540}
2541
Mark Brown7d021732011-07-14 17:11:38 +09002542static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2543 struct snd_soc_dai *dai)
2544{
2545 struct snd_soc_codec *codec = dai->codec;
2546 int rate_reg = 0;
2547
2548 switch (dai->id) {
2549 case 1:
2550 rate_reg = WM8994_AIF1_RATE;
2551 break;
2552 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002553 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002554 break;
2555 default:
2556 break;
2557 }
2558
2559 /* If the DAI is idle then configure the divider tree for the
2560 * lowest output rate to save a little power if the clock is
2561 * still active (eg, because it is system clock).
2562 */
2563 if (rate_reg && !dai->playback_active && !dai->capture_active)
2564 snd_soc_update_bits(codec, rate_reg,
2565 WM8994_AIF1_SR_MASK |
2566 WM8994_AIF1CLK_RATE_MASK, 0x9);
2567}
2568
Mark Brown9e6e96a2010-01-29 17:47:12 +00002569static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2570{
2571 struct snd_soc_codec *codec = codec_dai->codec;
2572 int mute_reg;
2573 int reg;
2574
2575 switch (codec_dai->id) {
2576 case 1:
2577 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2578 break;
2579 case 2:
2580 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2581 break;
2582 default:
2583 return -EINVAL;
2584 }
2585
2586 if (mute)
2587 reg = WM8994_AIF1DAC1_MUTE;
2588 else
2589 reg = 0;
2590
2591 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2592
2593 return 0;
2594}
2595
Mark Brown778a76e2010-03-22 22:05:10 +00002596static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2597{
2598 struct snd_soc_codec *codec = codec_dai->codec;
2599 int reg, val, mask;
2600
2601 switch (codec_dai->id) {
2602 case 1:
2603 reg = WM8994_AIF1_MASTER_SLAVE;
2604 mask = WM8994_AIF1_TRI;
2605 break;
2606 case 2:
2607 reg = WM8994_AIF2_MASTER_SLAVE;
2608 mask = WM8994_AIF2_TRI;
2609 break;
2610 case 3:
2611 reg = WM8994_POWER_MANAGEMENT_6;
2612 mask = WM8994_AIF3_TRI;
2613 break;
2614 default:
2615 return -EINVAL;
2616 }
2617
2618 if (tristate)
2619 val = mask;
2620 else
2621 val = 0;
2622
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002623 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002624}
2625
Mark Brownd09f3ec2011-08-15 11:01:02 +09002626static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2627{
2628 struct snd_soc_codec *codec = dai->codec;
2629
2630 /* Disable the pulls on the AIF if we're using it to save power. */
2631 snd_soc_update_bits(codec, WM8994_GPIO_3,
2632 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2633 snd_soc_update_bits(codec, WM8994_GPIO_4,
2634 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2635 snd_soc_update_bits(codec, WM8994_GPIO_5,
2636 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2637
2638 return 0;
2639}
2640
Mark Brown9e6e96a2010-01-29 17:47:12 +00002641#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2642
2643#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002644 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002645
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002646static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002647 .set_sysclk = wm8994_set_dai_sysclk,
2648 .set_fmt = wm8994_set_dai_fmt,
2649 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002650 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002651 .digital_mute = wm8994_aif_mute,
2652 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002653 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002654};
2655
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002656static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002657 .set_sysclk = wm8994_set_dai_sysclk,
2658 .set_fmt = wm8994_set_dai_fmt,
2659 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002660 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002661 .digital_mute = wm8994_aif_mute,
2662 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002663 .set_tristate = wm8994_set_tristate,
2664};
2665
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002666static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002667 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002668 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002669};
2670
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002671static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002672 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002673 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002674 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002675 .playback = {
2676 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002677 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002678 .channels_max = 2,
2679 .rates = WM8994_RATES,
2680 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002681 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002682 },
2683 .capture = {
2684 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002685 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002686 .channels_max = 2,
2687 .rates = WM8994_RATES,
2688 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002689 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002690 },
2691 .ops = &wm8994_aif1_dai_ops,
2692 },
2693 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002694 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002695 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002696 .playback = {
2697 .stream_name = "AIF2 Playback",
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 .capture = {
2705 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002706 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002707 .channels_max = 2,
2708 .rates = WM8994_RATES,
2709 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002710 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002711 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002712 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002713 .ops = &wm8994_aif2_dai_ops,
2714 },
2715 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002716 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002717 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002718 .playback = {
2719 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002720 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002721 .channels_max = 2,
2722 .rates = WM8994_RATES,
2723 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002724 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002725 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002726 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002727 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002728 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002729 .channels_max = 2,
2730 .rates = WM8994_RATES,
2731 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002732 .sig_bits = 24,
2733 },
Mark Brown778a76e2010-03-22 22:05:10 +00002734 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002735 }
2736};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002737
2738#ifdef CONFIG_PM
Mark Brown4752a882012-03-04 02:16:01 +00002739static int wm8994_codec_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002740{
Mark Brownb2c812e2010-04-14 15:35:19 +09002741 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002742 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002743 int i, ret;
2744
Mark Brownca629922011-05-11 14:34:53 +02002745 switch (control->type) {
2746 case WM8994:
2747 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2748 break;
Mark Brown81204c82011-05-24 17:35:53 +08002749 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002750 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2751 WM1811_JACKDET_MODE_MASK, 0);
2752 /* Fall through */
Mark Brownca629922011-05-11 14:34:53 +02002753 case WM8958:
2754 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2755 WM8958_MICD_ENA, 0);
2756 break;
2757 }
2758
Mark Brown9e6e96a2010-01-29 17:47:12 +00002759 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2760 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002761 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002762 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002763 if (ret < 0)
2764 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2765 i + 1, ret);
2766 }
2767
2768 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2769
2770 return 0;
2771}
2772
Mark Brown4752a882012-03-04 02:16:01 +00002773static int wm8994_codec_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002774{
Mark Brownb2c812e2010-04-14 15:35:19 +09002775 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002776 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002777 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002778 unsigned int val, mask;
2779
2780 if (wm8994->revision < 4) {
2781 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01002782 ret = regmap_read(control->regmap,
2783 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002784
2785 /* modify the cache only */
2786 codec->cache_only = 1;
2787 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2788 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2789 val &= mask;
2790 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2791 mask, val);
2792 codec->cache_only = 0;
2793 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002794
Mark Brown9e6e96a2010-01-29 17:47:12 +00002795 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002796 if (!wm8994->fll_suspend[i].out)
2797 continue;
2798
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002799 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002800 wm8994->fll_suspend[i].src,
2801 wm8994->fll_suspend[i].in,
2802 wm8994->fll_suspend[i].out);
2803 if (ret < 0)
2804 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2805 i + 1, ret);
2806 }
2807
Mark Brownca629922011-05-11 14:34:53 +02002808 switch (control->type) {
2809 case WM8994:
2810 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2811 snd_soc_update_bits(codec, WM8994_MICBIAS,
2812 WM8994_MICD_ENA, WM8994_MICD_ENA);
2813 break;
Mark Brown81204c82011-05-24 17:35:53 +08002814 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002815 if (wm8994->jackdet && wm8994->jack_cb) {
2816 /* Restart from idle */
2817 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2818 WM1811_JACKDET_MODE_MASK,
2819 WM1811_JACKDET_MODE_JACK);
2820 break;
2821 }
Mark Brown6f8270c2012-03-03 13:06:25 +00002822 break;
Mark Brownca629922011-05-11 14:34:53 +02002823 case WM8958:
2824 if (wm8994->jack_cb)
2825 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2826 WM8958_MICD_ENA, WM8958_MICD_ENA);
2827 break;
2828 }
2829
Mark Brown9e6e96a2010-01-29 17:47:12 +00002830 return 0;
2831}
2832#else
Mark Brown4752a882012-03-04 02:16:01 +00002833#define wm8994_codec_suspend NULL
2834#define wm8994_codec_resume NULL
Mark Brown9e6e96a2010-01-29 17:47:12 +00002835#endif
2836
2837static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2838{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002839 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002840 struct wm8994_pdata *pdata = wm8994->pdata;
2841 struct snd_kcontrol_new controls[] = {
2842 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2843 wm8994->retune_mobile_enum,
2844 wm8994_get_retune_mobile_enum,
2845 wm8994_put_retune_mobile_enum),
2846 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2847 wm8994->retune_mobile_enum,
2848 wm8994_get_retune_mobile_enum,
2849 wm8994_put_retune_mobile_enum),
2850 SOC_ENUM_EXT("AIF2 EQ Mode",
2851 wm8994->retune_mobile_enum,
2852 wm8994_get_retune_mobile_enum,
2853 wm8994_put_retune_mobile_enum),
2854 };
2855 int ret, i, j;
2856 const char **t;
2857
2858 /* We need an array of texts for the enum API but the number
2859 * of texts is likely to be less than the number of
2860 * configurations due to the sample rate dependency of the
2861 * configurations. */
2862 wm8994->num_retune_mobile_texts = 0;
2863 wm8994->retune_mobile_texts = NULL;
2864 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2865 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2866 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2867 wm8994->retune_mobile_texts[j]) == 0)
2868 break;
2869 }
2870
2871 if (j != wm8994->num_retune_mobile_texts)
2872 continue;
2873
2874 /* Expand the array... */
2875 t = krealloc(wm8994->retune_mobile_texts,
2876 sizeof(char *) *
2877 (wm8994->num_retune_mobile_texts + 1),
2878 GFP_KERNEL);
2879 if (t == NULL)
2880 continue;
2881
2882 /* ...store the new entry... */
2883 t[wm8994->num_retune_mobile_texts] =
2884 pdata->retune_mobile_cfgs[i].name;
2885
2886 /* ...and remember the new version. */
2887 wm8994->num_retune_mobile_texts++;
2888 wm8994->retune_mobile_texts = t;
2889 }
2890
2891 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2892 wm8994->num_retune_mobile_texts);
2893
2894 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2895 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2896
Liam Girdwood022658b2012-02-03 17:43:09 +00002897 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002898 ARRAY_SIZE(controls));
2899 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002900 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002901 "Failed to add ReTune Mobile controls: %d\n", ret);
2902}
2903
2904static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2905{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002906 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002907 struct wm8994_pdata *pdata = wm8994->pdata;
2908 int ret, i;
2909
2910 if (!pdata)
2911 return;
2912
2913 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2914 pdata->lineout2_diff,
2915 pdata->lineout1fb,
2916 pdata->lineout2fb,
2917 pdata->jd_scthr,
2918 pdata->jd_thr,
2919 pdata->micbias1_lvl,
2920 pdata->micbias2_lvl);
2921
2922 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2923
2924 if (pdata->num_drc_cfgs) {
2925 struct snd_kcontrol_new controls[] = {
2926 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2927 wm8994_get_drc_enum, wm8994_put_drc_enum),
2928 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2929 wm8994_get_drc_enum, wm8994_put_drc_enum),
2930 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2931 wm8994_get_drc_enum, wm8994_put_drc_enum),
2932 };
2933
2934 /* We need an array of texts for the enum API */
Mark Brown7270ceb2011-12-01 14:00:19 +00002935 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
2936 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002937 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002938 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002939 "Failed to allocate %d DRC config texts\n",
2940 pdata->num_drc_cfgs);
2941 return;
2942 }
2943
2944 for (i = 0; i < pdata->num_drc_cfgs; i++)
2945 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2946
2947 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2948 wm8994->drc_enum.texts = wm8994->drc_texts;
2949
Liam Girdwood022658b2012-02-03 17:43:09 +00002950 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002951 ARRAY_SIZE(controls));
2952 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002953 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002954 "Failed to add DRC mode controls: %d\n", ret);
2955
2956 for (i = 0; i < WM8994_NUM_DRC; i++)
2957 wm8994_set_drc(codec, i);
2958 }
2959
2960 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2961 pdata->num_retune_mobile_cfgs);
2962
2963 if (pdata->num_retune_mobile_cfgs)
2964 wm8994_handle_retune_mobile_pdata(wm8994);
2965 else
Liam Girdwood022658b2012-02-03 17:43:09 +00002966 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002967 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002968
2969 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2970 if (pdata->micbias[i]) {
2971 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2972 pdata->micbias[i] & 0xffff);
2973 }
2974 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002975}
2976
Mark Brown88766982010-03-29 20:57:12 +01002977/**
2978 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2979 *
2980 * @codec: WM8994 codec
2981 * @jack: jack to report detection events on
2982 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01002983 *
2984 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2985 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002986 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002987 * be configured using snd_soc_jack_add_gpios() instead.
2988 *
2989 * Configuration of detection levels is available via the micbias1_lvl
2990 * and micbias2_lvl platform data members.
2991 */
2992int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00002993 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01002994{
Mark Brownb2c812e2010-04-14 15:35:19 +09002995 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002996 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01002997 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00002998 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01002999
Mark Brown87092e32012-02-06 18:50:39 +00003000 if (control->type != WM8994) {
3001 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003002 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003003 }
Mark Brown3a423152010-11-26 15:21:06 +00003004
Mark Brown88766982010-03-29 20:57:12 +01003005 switch (micbias) {
3006 case 1:
3007 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003008 if (jack)
3009 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3010 "MICBIAS1");
3011 else
3012 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3013 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003014 break;
3015 case 2:
3016 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003017 if (jack)
3018 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3019 "MICBIAS1");
3020 else
3021 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3022 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003023 break;
3024 default:
Mark Brown87092e32012-02-06 18:50:39 +00003025 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003026 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003027 }
Mark Brown88766982010-03-29 20:57:12 +01003028
Mark Brown87092e32012-02-06 18:50:39 +00003029 if (ret != 0)
3030 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3031 micbias, ret);
3032
3033 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3034 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003035
3036 /* Store the configuration */
3037 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003038 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003039
3040 /* If either of the jacks is set up then enable detection */
3041 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3042 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003043 else
Mark Brown88766982010-03-29 20:57:12 +01003044 reg = 0;
3045
3046 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3047
Mark Brown87092e32012-02-06 18:50:39 +00003048 snd_soc_dapm_sync(&codec->dapm);
3049
Mark Brown88766982010-03-29 20:57:12 +01003050 return 0;
3051}
3052EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3053
3054static irqreturn_t wm8994_mic_irq(int irq, void *data)
3055{
3056 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003057 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01003058 int reg;
3059 int report;
3060
Mark Brown7116f452010-12-29 13:05:21 +00003061#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003062 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003063#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003064
Mark Brown88766982010-03-29 20:57:12 +01003065 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3066 if (reg < 0) {
3067 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3068 reg);
3069 return IRQ_HANDLED;
3070 }
3071
3072 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
3073
3074 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003075 if (reg & WM8994_MIC1_DET_STS) {
3076 if (priv->micdet[0].detecting)
3077 report = SND_JACK_HEADSET;
3078 }
3079 if (reg & WM8994_MIC1_SHRT_STS) {
3080 if (priv->micdet[0].detecting)
3081 report = SND_JACK_HEADPHONE;
3082 else
3083 report |= SND_JACK_BTN_0;
3084 }
3085 if (report)
3086 priv->micdet[0].detecting = false;
3087 else
3088 priv->micdet[0].detecting = true;
3089
Mark Brown88766982010-03-29 20:57:12 +01003090 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003091 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003092
3093 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003094 if (reg & WM8994_MIC2_DET_STS) {
3095 if (priv->micdet[1].detecting)
3096 report = SND_JACK_HEADSET;
3097 }
3098 if (reg & WM8994_MIC2_SHRT_STS) {
3099 if (priv->micdet[1].detecting)
3100 report = SND_JACK_HEADPHONE;
3101 else
3102 report |= SND_JACK_BTN_0;
3103 }
3104 if (report)
3105 priv->micdet[1].detecting = false;
3106 else
3107 priv->micdet[1].detecting = true;
3108
Mark Brown88766982010-03-29 20:57:12 +01003109 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003110 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003111
3112 return IRQ_HANDLED;
3113}
3114
Mark Brown821edd22010-11-26 15:21:09 +00003115/* Default microphone detection handler for WM8958 - the user can
3116 * override this if they wish.
3117 */
3118static void wm8958_default_micdet(u16 status, void *data)
3119{
3120 struct snd_soc_codec *codec = data;
3121 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003122 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003123
Mark Browna1691342011-11-30 14:56:40 +00003124 dev_dbg(codec->dev, "MICDET %x\n", status);
3125
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003126 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003127 if (!(status & WM8958_MICD_STS)) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003128 if (!wm8994->jackdet) {
3129 /* If nothing present then clear our statuses */
3130 dev_dbg(codec->dev, "Detected open circuit\n");
3131 wm8994->jack_mic = false;
3132 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003133
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003134 wm8958_micd_set_rate(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003135
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003136 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3137 wm8994->btn_mask |
3138 SND_JACK_HEADSET);
3139 }
Mark Brownb00adf72011-08-13 11:57:18 +09003140 return;
3141 }
3142
3143 /* If the measurement is showing a high impedence we've got a
3144 * microphone.
3145 */
Mark Brown157a75e2011-11-30 13:43:51 +00003146 if (wm8994->mic_detecting && (status & 0x600)) {
Mark Brownb00adf72011-08-13 11:57:18 +09003147 dev_dbg(codec->dev, "Detected microphone\n");
3148
Mark Brown157a75e2011-11-30 13:43:51 +00003149 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003150 wm8994->jack_mic = true;
3151
3152 wm8958_micd_set_rate(codec);
3153
3154 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3155 SND_JACK_HEADSET);
3156 }
3157
3158
Mark Brown7c08b512012-01-26 18:33:24 +00003159 if (wm8994->mic_detecting && status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003160 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003161 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003162
3163 wm8958_micd_set_rate(codec);
3164
3165 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3166 SND_JACK_HEADSET);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003167
3168 /* If we have jackdet that will detect removal */
3169 if (wm8994->jackdet) {
Mark Brownc9865642012-03-12 16:31:50 +00003170 mutex_lock(&wm8994->accdet_lock);
3171
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003172 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3173 WM8958_MICD_ENA, 0);
3174
Mark Brownc9865642012-03-12 16:31:50 +00003175 wm1811_jackdet_set_mode(codec,
3176 WM1811_JACKDET_MODE_JACK);
3177
3178 mutex_unlock(&wm8994->accdet_lock);
3179
Mark Brown07fb9d92012-02-21 16:23:35 +00003180 if (wm8994->pdata->jd_ext_cap) {
3181 mutex_lock(&codec->mutex);
3182 snd_soc_dapm_disable_pin(&codec->dapm,
3183 "MICBIAS2");
3184 snd_soc_dapm_sync(&codec->dapm);
3185 mutex_unlock(&codec->mutex);
3186 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003187 }
Mark Brownb00adf72011-08-13 11:57:18 +09003188 }
3189
3190 /* Report short circuit as a button */
3191 if (wm8994->jack_mic) {
Mark Brown4585790d2011-11-30 10:55:14 +00003192 report = 0;
Mark Brownb00adf72011-08-13 11:57:18 +09003193 if (status & 0x4)
Mark Brown4585790d2011-11-30 10:55:14 +00003194 report |= SND_JACK_BTN_0;
3195
3196 if (status & 0x8)
3197 report |= SND_JACK_BTN_1;
3198
3199 if (status & 0x10)
3200 report |= SND_JACK_BTN_2;
3201
3202 if (status & 0x20)
3203 report |= SND_JACK_BTN_3;
3204
3205 if (status & 0x40)
3206 report |= SND_JACK_BTN_4;
3207
3208 if (status & 0x80)
3209 report |= SND_JACK_BTN_5;
3210
3211 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3212 wm8994->btn_mask);
Mark Brownb00adf72011-08-13 11:57:18 +09003213 }
Mark Brown821edd22010-11-26 15:21:09 +00003214}
3215
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003216static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3217{
3218 struct wm8994_priv *wm8994 = data;
3219 struct snd_soc_codec *codec = wm8994->codec;
3220 int reg;
Mark Brownc9865642012-03-12 16:31:50 +00003221 bool present;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003222
3223 mutex_lock(&wm8994->accdet_lock);
3224
3225 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3226 if (reg < 0) {
3227 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3228 mutex_unlock(&wm8994->accdet_lock);
3229 return IRQ_NONE;
3230 }
3231
3232 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3233
Mark Brownc9865642012-03-12 16:31:50 +00003234 present = reg & WM1811_JACKDET_LVL;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003235
Mark Brownc9865642012-03-12 16:31:50 +00003236 if (present) {
3237 dev_dbg(codec->dev, "Jack detected\n");
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003238
Mark Brown55a27782012-02-21 13:45:53 +00003239 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3240 WM8958_MICB2_DISCH, 0);
3241
Mark Brown378ec0c2012-03-01 19:01:43 +00003242 /* Disable debounce while inserted */
3243 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3244 WM1811_JACKDET_DB, 0);
3245
Mark Brownb9e67e5e2012-02-28 19:03:37 +00003246 /*
3247 * Start off measument of microphone impedence to find
3248 * out what's actually there.
3249 */
3250 wm8994->mic_detecting = true;
3251 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3252
3253 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3254 WM8958_MICD_ENA, WM8958_MICD_ENA);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003255 } else {
3256 dev_dbg(codec->dev, "Jack not detected\n");
3257
Mark Brown55a27782012-02-21 13:45:53 +00003258 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3259 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3260
Mark Brown378ec0c2012-03-01 19:01:43 +00003261 /* Enable debounce while removed */
3262 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3263 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3264
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003265 wm8994->mic_detecting = false;
3266 wm8994->jack_mic = false;
3267 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3268 WM8958_MICD_ENA, 0);
3269 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3270 }
3271
3272 mutex_unlock(&wm8994->accdet_lock);
3273
Mark Brownc9865642012-03-12 16:31:50 +00003274 /* If required for an external cap force MICBIAS on */
3275 if (wm8994->pdata->jd_ext_cap) {
3276 mutex_lock(&codec->mutex);
3277
3278 if (present)
3279 snd_soc_dapm_force_enable_pin(&codec->dapm,
3280 "MICBIAS2");
3281 else
3282 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3283
3284 snd_soc_dapm_sync(&codec->dapm);
3285 mutex_unlock(&codec->mutex);
3286 }
3287
3288 if (present)
3289 snd_soc_jack_report(wm8994->micdet[0].jack,
3290 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3291 else
3292 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3293 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3294 wm8994->btn_mask);
3295
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003296 return IRQ_HANDLED;
3297}
3298
Mark Brown821edd22010-11-26 15:21:09 +00003299/**
3300 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3301 *
3302 * @codec: WM8958 codec
3303 * @jack: jack to report detection events on
3304 *
3305 * Enable microphone detection functionality for the WM8958. By
3306 * default simple detection which supports the detection of up to 6
3307 * buttons plus video and microphone functionality is supported.
3308 *
3309 * The WM8958 has an advanced jack detection facility which is able to
3310 * support complex accessory detection, especially when used in
3311 * conjunction with external circuitry. In order to provide maximum
3312 * flexiblity a callback is provided which allows a completely custom
3313 * detection algorithm.
3314 */
3315int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3316 wm8958_micdet_cb cb, void *cb_data)
3317{
3318 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003319 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003320 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003321
Mark Brown81204c82011-05-24 17:35:53 +08003322 switch (control->type) {
3323 case WM1811:
3324 case WM8958:
3325 break;
3326 default:
Mark Brown821edd22010-11-26 15:21:09 +00003327 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003328 }
Mark Brown821edd22010-11-26 15:21:09 +00003329
3330 if (jack) {
3331 if (!cb) {
3332 dev_dbg(codec->dev, "Using default micdet callback\n");
3333 cb = wm8958_default_micdet;
3334 cb_data = codec;
3335 }
3336
Mark Brown4cdf5e42011-11-29 14:36:17 +00003337 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003338 snd_soc_dapm_sync(&codec->dapm);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003339
Mark Brown821edd22010-11-26 15:21:09 +00003340 wm8994->micdet[0].jack = jack;
3341 wm8994->jack_cb = cb;
3342 wm8994->jack_cb_data = cb_data;
3343
Mark Brown157a75e2011-11-30 13:43:51 +00003344 wm8994->mic_detecting = true;
Mark Brownb00adf72011-08-13 11:57:18 +09003345 wm8994->jack_mic = false;
3346
3347 wm8958_micd_set_rate(codec);
3348
Mark Brown4585790d2011-11-30 10:55:14 +00003349 /* Detect microphones and short circuits by default */
3350 if (wm8994->pdata->micd_lvl_sel)
3351 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3352 else
3353 micd_lvl_sel = 0x41;
3354
3355 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3356 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3357 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3358
Mark Brownb00adf72011-08-13 11:57:18 +09003359 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003360 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003361
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003362 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3363
3364 /*
3365 * If we can use jack detection start off with that,
3366 * otherwise jump straight to microphone detection.
3367 */
3368 if (wm8994->jackdet) {
Mark Brown55a27782012-02-21 13:45:53 +00003369 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3370 WM8958_MICB2_DISCH,
3371 WM8958_MICB2_DISCH);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003372 snd_soc_update_bits(codec, WM8994_LDO_1,
3373 WM8994_LDO1_DISCH, 0);
3374 wm1811_jackdet_set_mode(codec,
3375 WM1811_JACKDET_MODE_JACK);
3376 } else {
3377 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3378 WM8958_MICD_ENA, WM8958_MICD_ENA);
3379 }
3380
Mark Brown821edd22010-11-26 15:21:09 +00003381 } else {
3382 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3383 WM8958_MICD_ENA, 0);
Mark Brownafaf1592012-03-03 18:46:36 +00003384 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003385 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003386 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003387 }
3388
3389 return 0;
3390}
3391EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3392
3393static irqreturn_t wm8958_mic_irq(int irq, void *data)
3394{
3395 struct wm8994_priv *wm8994 = data;
3396 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003397 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003398
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003399 /*
3400 * Jack detection may have detected a removal simulataneously
3401 * with an update of the MICDET status; if so it will have
3402 * stopped detection and we can ignore this interrupt.
3403 */
Mark Brownc9865642012-03-12 16:31:50 +00003404 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003405 return IRQ_HANDLED;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003406
Mark Brown19940b32011-08-19 18:05:05 +09003407 /* We may occasionally read a detection without an impedence
3408 * range being provided - if that happens loop again.
3409 */
3410 count = 10;
3411 do {
3412 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3413 if (reg < 0) {
3414 dev_err(codec->dev,
3415 "Failed to read mic detect status: %d\n",
3416 reg);
3417 return IRQ_NONE;
3418 }
Mark Brown821edd22010-11-26 15:21:09 +00003419
Mark Brown19940b32011-08-19 18:05:05 +09003420 if (!(reg & WM8958_MICD_VALID)) {
3421 dev_dbg(codec->dev, "Mic detect data not valid\n");
3422 goto out;
3423 }
3424
3425 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3426 break;
3427
3428 msleep(1);
3429 } while (count--);
3430
3431 if (count == 0)
3432 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003433
Mark Brown7116f452010-12-29 13:05:21 +00003434#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003435 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003436#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003437
Mark Brown821edd22010-11-26 15:21:09 +00003438 if (wm8994->jack_cb)
3439 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3440 else
3441 dev_warn(codec->dev, "Accessory detection with no callback\n");
3442
3443out:
3444 return IRQ_HANDLED;
3445}
3446
Mark Brown3b1af3f2011-07-14 12:38:18 +09003447static irqreturn_t wm8994_fifo_error(int irq, void *data)
3448{
3449 struct snd_soc_codec *codec = data;
3450
3451 dev_err(codec->dev, "FIFO error\n");
3452
3453 return IRQ_HANDLED;
3454}
3455
Mark Brownf0b182b2011-08-16 12:01:27 +09003456static irqreturn_t wm8994_temp_warn(int irq, void *data)
3457{
3458 struct snd_soc_codec *codec = data;
3459
3460 dev_err(codec->dev, "Thermal warning\n");
3461
3462 return IRQ_HANDLED;
3463}
3464
3465static irqreturn_t wm8994_temp_shut(int irq, void *data)
3466{
3467 struct snd_soc_codec *codec = data;
3468
3469 dev_crit(codec->dev, "Thermal shutdown\n");
3470
3471 return IRQ_HANDLED;
3472}
3473
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003474static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003475{
Mark Brownd9a76662011-07-24 12:49:52 +01003476 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00003477 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003478 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003479 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003480 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003481
Mark Brown2bc16ed2012-03-03 23:24:39 +00003482 wm8994->codec = codec;
Mark Brownd9a76662011-07-24 12:49:52 +01003483 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003484
Mark Brownd9a76662011-07-24 12:49:52 +01003485 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003486
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003487 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003488
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003489 mutex_init(&wm8994->accdet_lock);
3490
Mark Brownc7ebf932011-07-12 19:47:59 +09003491 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3492 init_completion(&wm8994->fll_locked[i]);
3493
Mark Brown9b7c5252011-02-17 20:05:44 -08003494 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3495 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3496 else if (wm8994->pdata && wm8994->pdata->irq_base)
3497 wm8994->micdet_irq = wm8994->pdata->irq_base +
3498 WM8994_IRQ_MIC1_DET;
3499
Mark Brown39fb51a2010-11-26 17:23:43 +00003500 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003501 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003502
Mark Brownf959dee2012-01-31 16:16:47 +00003503 /* By default use idle_bias_off, will override for WM8994 */
3504 codec->dapm.idle_bias_off = 1;
3505
Mark Brown9e6e96a2010-01-29 17:47:12 +00003506 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003507 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003508 switch (control->type) {
3509 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003510 /* Single ended line outputs should have VMID on. */
3511 if (!wm8994->pdata->lineout1_diff ||
3512 !wm8994->pdata->lineout2_diff)
3513 codec->dapm.idle_bias_off = 0;
3514
Mark Brown3a423152010-11-26 15:21:06 +00003515 switch (wm8994->revision) {
3516 case 2:
3517 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003518 wm8994->hubs.dcs_codes_l = -5;
3519 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003520 wm8994->hubs.hp_startup_mode = 1;
3521 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003522 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003523 break;
3524 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003525 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003526 break;
3527 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003528 break;
Mark Brown3a423152010-11-26 15:21:06 +00003529
3530 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003531 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003532 wm8994->hubs.hp_startup_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003533 break;
Mark Brown3a423152010-11-26 15:21:06 +00003534
Mark Brown81204c82011-05-24 17:35:53 +08003535 case WM1811:
3536 wm8994->hubs.dcs_readback_mode = 2;
3537 wm8994->hubs.no_series_update = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003538 wm8994->hubs.hp_startup_mode = 1;
Mark Brown67109cb2012-02-29 16:40:08 +00003539 wm8994->hubs.no_cache_class_w = true;
Mark Brown81204c82011-05-24 17:35:53 +08003540
3541 switch (wm8994->revision) {
3542 case 0:
3543 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003544 case 2:
3545 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003546 wm8994->hubs.dcs_codes_l = -9;
3547 wm8994->hubs.dcs_codes_r = -5;
Mark Brown81204c82011-05-24 17:35:53 +08003548 break;
3549 default:
3550 break;
3551 }
3552
3553 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3554 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3555 break;
3556
Mark Brown9e6e96a2010-01-29 17:47:12 +00003557 default:
3558 break;
3559 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003560
Mark Brown2a8a8562011-07-24 12:20:41 +01003561 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003562 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003563 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003564 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003565 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003566 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003567
Mark Brown2a8a8562011-07-24 12:20:41 +01003568 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003569 wm_hubs_dcs_done, "DC servo done",
3570 &wm8994->hubs);
3571 if (ret == 0)
3572 wm8994->hubs.dcs_done_irq = true;
3573
Mark Brown3a423152010-11-26 15:21:06 +00003574 switch (control->type) {
3575 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003576 if (wm8994->micdet_irq) {
3577 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3578 wm8994_mic_irq,
3579 IRQF_TRIGGER_RISING,
3580 "Mic1 detect",
3581 wm8994);
3582 if (ret != 0)
3583 dev_warn(codec->dev,
3584 "Failed to request Mic1 detect IRQ: %d\n",
3585 ret);
3586 }
Mark Brown88766982010-03-29 20:57:12 +01003587
Mark Brown2a8a8562011-07-24 12:20:41 +01003588 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003589 WM8994_IRQ_MIC1_SHRT,
3590 wm8994_mic_irq, "Mic 1 short",
3591 wm8994);
3592 if (ret != 0)
3593 dev_warn(codec->dev,
3594 "Failed to request Mic1 short IRQ: %d\n",
3595 ret);
Mark Brown88766982010-03-29 20:57:12 +01003596
Mark Brown2a8a8562011-07-24 12:20:41 +01003597 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003598 WM8994_IRQ_MIC2_DET,
3599 wm8994_mic_irq, "Mic 2 detect",
3600 wm8994);
3601 if (ret != 0)
3602 dev_warn(codec->dev,
3603 "Failed to request Mic2 detect IRQ: %d\n",
3604 ret);
Mark Brown88766982010-03-29 20:57:12 +01003605
Mark Brown2a8a8562011-07-24 12:20:41 +01003606 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003607 WM8994_IRQ_MIC2_SHRT,
3608 wm8994_mic_irq, "Mic 2 short",
3609 wm8994);
3610 if (ret != 0)
3611 dev_warn(codec->dev,
3612 "Failed to request Mic2 short IRQ: %d\n",
3613 ret);
3614 break;
Mark Brown821edd22010-11-26 15:21:09 +00003615
3616 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003617 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003618 if (wm8994->micdet_irq) {
3619 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3620 wm8958_mic_irq,
3621 IRQF_TRIGGER_RISING,
3622 "Mic detect",
3623 wm8994);
3624 if (ret != 0)
3625 dev_warn(codec->dev,
3626 "Failed to request Mic detect IRQ: %d\n",
3627 ret);
3628 }
Mark Brown3a423152010-11-26 15:21:06 +00003629 }
Mark Brown88766982010-03-29 20:57:12 +01003630
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003631 switch (control->type) {
3632 case WM1811:
3633 if (wm8994->revision > 1) {
3634 ret = wm8994_request_irq(wm8994->wm8994,
3635 WM8994_IRQ_GPIO(6),
3636 wm1811_jackdet_irq, "JACKDET",
3637 wm8994);
3638 if (ret == 0)
3639 wm8994->jackdet = true;
3640 }
3641 break;
3642 default:
3643 break;
3644 }
3645
Mark Brownc7ebf932011-07-12 19:47:59 +09003646 wm8994->fll_locked_irq = true;
3647 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01003648 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09003649 WM8994_IRQ_FLL1_LOCK + i,
3650 wm8994_fll_locked_irq, "FLL lock",
3651 &wm8994->fll_locked[i]);
3652 if (ret != 0)
3653 wm8994->fll_locked_irq = false;
3654 }
3655
Mark Brown27060b3c2012-02-06 18:42:14 +00003656 /* Make sure we can read from the GPIOs if they're inputs */
3657 pm_runtime_get_sync(codec->dev);
3658
Mark Brown9e6e96a2010-01-29 17:47:12 +00003659 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3660 * configured on init - if a system wants to do this dynamically
3661 * at runtime we can deal with that then.
3662 */
Mark Brownd9a76662011-07-24 12:49:52 +01003663 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003664 if (ret < 0) {
3665 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003666 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003667 }
Mark Brownd9a76662011-07-24 12:49:52 +01003668 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003669 wm8994->lrclk_shared[0] = 1;
3670 wm8994_dai[0].symmetric_rates = 1;
3671 } else {
3672 wm8994->lrclk_shared[0] = 0;
3673 }
3674
Mark Brownd9a76662011-07-24 12:49:52 +01003675 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003676 if (ret < 0) {
3677 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003678 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003679 }
Mark Brownd9a76662011-07-24 12:49:52 +01003680 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003681 wm8994->lrclk_shared[1] = 1;
3682 wm8994_dai[1].symmetric_rates = 1;
3683 } else {
3684 wm8994->lrclk_shared[1] = 0;
3685 }
3686
Mark Brown27060b3c2012-02-06 18:42:14 +00003687 pm_runtime_put(codec->dev);
3688
Mark Brown9e6e96a2010-01-29 17:47:12 +00003689 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003690 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3691 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003692 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3693 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003694 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3695 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003696 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3697 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003698 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3699 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003700 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3701 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003702 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3703 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003704 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3705 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003706 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3707 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003708 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3709 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003710 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3711 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003712 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3713 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003714 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3715 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003716 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3717 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003718 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3719 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003720 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3721 WM8994_DAC2_VU, WM8994_DAC2_VU);
3722
3723 /* Set the low bit of the 3D stereo depth so TLV matches */
3724 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3725 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3726 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3727 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3728 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3729 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3730 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3731 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3732 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3733
Mark Brown5b739672011-07-06 00:08:43 -07003734 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3735 * use this; it only affects behaviour on idle TDM clock
3736 * cycles. */
3737 switch (control->type) {
3738 case WM8994:
3739 case WM8958:
3740 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3741 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3742 break;
3743 default:
3744 break;
3745 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003746
Mark Brown500fa302011-11-29 19:58:19 +00003747 /* Put MICBIAS into bypass mode by default on newer devices */
3748 switch (control->type) {
3749 case WM8958:
3750 case WM1811:
3751 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3752 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3753 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3754 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3755 break;
3756 default:
3757 break;
3758 }
3759
Mark Brown9e6e96a2010-01-29 17:47:12 +00003760 wm8994_update_class_w(codec);
3761
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003762 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003763
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003764 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00003765 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003766 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003767 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003768 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003769
3770 switch (control->type) {
3771 case WM8994:
3772 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3773 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003774 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003775 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3776 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003777 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3778 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003779 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3780 ARRAY_SIZE(wm8994_dac_revd_widgets));
3781 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003782 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3783 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003784 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3785 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003786 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3787 ARRAY_SIZE(wm8994_dac_widgets));
3788 }
Mark Brownc4431df2010-11-26 15:21:07 +00003789 break;
3790 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00003791 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00003792 ARRAY_SIZE(wm8958_snd_controls));
3793 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3794 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003795 if (wm8994->revision < 1) {
3796 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3797 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3798 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3799 ARRAY_SIZE(wm8994_adc_revd_widgets));
3800 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3801 ARRAY_SIZE(wm8994_dac_revd_widgets));
3802 } else {
3803 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3804 ARRAY_SIZE(wm8994_lateclk_widgets));
3805 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3806 ARRAY_SIZE(wm8994_adc_widgets));
3807 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3808 ARRAY_SIZE(wm8994_dac_widgets));
3809 }
Mark Brownc4431df2010-11-26 15:21:07 +00003810 break;
Mark Brown81204c82011-05-24 17:35:53 +08003811
3812 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00003813 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08003814 ARRAY_SIZE(wm8958_snd_controls));
3815 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3816 ARRAY_SIZE(wm8958_dapm_widgets));
3817 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3818 ARRAY_SIZE(wm8994_lateclk_widgets));
3819 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3820 ARRAY_SIZE(wm8994_adc_widgets));
3821 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3822 ARRAY_SIZE(wm8994_dac_widgets));
3823 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003824 }
3825
3826
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003827 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003828 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003829
Mark Brownc4431df2010-11-26 15:21:07 +00003830 switch (control->type) {
3831 case WM8994:
3832 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3833 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003834
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003835 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003836 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3837 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003838 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3839 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3840 } else {
3841 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3842 ARRAY_SIZE(wm8994_lateclk_intercon));
3843 }
Mark Brownc4431df2010-11-26 15:21:07 +00003844 break;
3845 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003846 if (wm8994->revision < 1) {
3847 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3848 ARRAY_SIZE(wm8994_revd_intercon));
3849 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3850 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3851 } else {
3852 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3853 ARRAY_SIZE(wm8994_lateclk_intercon));
3854 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3855 ARRAY_SIZE(wm8958_intercon));
3856 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003857
3858 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003859 break;
Mark Brown81204c82011-05-24 17:35:53 +08003860 case WM1811:
3861 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3862 ARRAY_SIZE(wm8994_lateclk_intercon));
3863 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3864 ARRAY_SIZE(wm8958_intercon));
3865 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003866 }
3867
Mark Brown9e6e96a2010-01-29 17:47:12 +00003868 return 0;
3869
Mark Brown88766982010-03-29 20:57:12 +01003870err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003871 if (wm8994->jackdet)
3872 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003873 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
3874 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
3875 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003876 if (wm8994->micdet_irq)
3877 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003878 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003879 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003880 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01003881 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003882 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003883 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3884 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3885 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00003886
Mark Brown9e6e96a2010-01-29 17:47:12 +00003887 return ret;
3888}
3889
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003890static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003891{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003892 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003893 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09003894 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003895
3896 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003897
Mark Brown39fb51a2010-11-26 17:23:43 +00003898 pm_runtime_disable(codec->dev);
3899
Mark Brownc7ebf932011-07-12 19:47:59 +09003900 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003901 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003902 &wm8994->fll_locked[i]);
3903
Mark Brown2a8a8562011-07-24 12:20:41 +01003904 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003905 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003906 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3907 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3908 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003909
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003910 if (wm8994->jackdet)
3911 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
3912
Mark Brown3a423152010-11-26 15:21:06 +00003913 switch (control->type) {
3914 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003915 if (wm8994->micdet_irq)
3916 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003917 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003918 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003919 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00003920 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003921 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003922 wm8994);
3923 break;
Mark Brown821edd22010-11-26 15:21:09 +00003924
Mark Brown81204c82011-05-24 17:35:53 +08003925 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00003926 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003927 if (wm8994->micdet_irq)
3928 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003929 break;
Mark Brown3a423152010-11-26 15:21:06 +00003930 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003931 if (wm8994->mbc)
3932 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003933 if (wm8994->mbc_vss)
3934 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003935 if (wm8994->enh_eq)
3936 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003937 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003938
3939 return 0;
3940}
3941
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003942static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3943 .probe = wm8994_codec_probe,
3944 .remove = wm8994_codec_remove,
Mark Brown4752a882012-03-04 02:16:01 +00003945 .suspend = wm8994_codec_suspend,
3946 .resume = wm8994_codec_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003947 .set_bias_level = wm8994_set_bias_level,
3948};
3949
3950static int __devinit wm8994_probe(struct platform_device *pdev)
3951{
Mark Brown2bc16ed2012-03-03 23:24:39 +00003952 struct wm8994_priv *wm8994;
3953
3954 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
3955 GFP_KERNEL);
3956 if (wm8994 == NULL)
3957 return -ENOMEM;
3958 platform_set_drvdata(pdev, wm8994);
3959
3960 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
3961 wm8994->pdata = dev_get_platdata(pdev->dev.parent);
3962
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003963 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3964 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3965}
3966
3967static int __devexit wm8994_remove(struct platform_device *pdev)
3968{
3969 snd_soc_unregister_codec(&pdev->dev);
3970 return 0;
3971}
3972
Mark Brown4752a882012-03-04 02:16:01 +00003973#ifdef CONFIG_PM_SLEEP
3974static int wm8994_suspend(struct device *dev)
3975{
3976 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
3977
3978 /* Drop down to power saving mode when system is suspended */
3979 if (wm8994->jackdet && !wm8994->active_refcount)
3980 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
3981 WM1811_JACKDET_MODE_MASK,
3982 wm8994->jackdet_mode);
3983
3984 return 0;
3985}
3986
3987static int wm8994_resume(struct device *dev)
3988{
3989 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
3990
3991 if (wm8994->jackdet && wm8994->jack_cb)
3992 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
3993 WM1811_JACKDET_MODE_MASK,
3994 WM1811_JACKDET_MODE_AUDIO);
3995
3996 return 0;
3997}
3998#endif
3999
4000static const struct dev_pm_ops wm8994_pm_ops = {
4001 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4002};
4003
Mark Brown9e6e96a2010-01-29 17:47:12 +00004004static struct platform_driver wm8994_codec_driver = {
4005 .driver = {
Mark Brown4752a882012-03-04 02:16:01 +00004006 .name = "wm8994-codec",
4007 .owner = THIS_MODULE,
4008 .pm = &wm8994_pm_ops,
4009 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004010 .probe = wm8994_probe,
4011 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00004012};
4013
Mark Brown5bbcc3c2011-11-23 22:52:08 +00004014module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004015
4016MODULE_DESCRIPTION("ASoC WM8994 driver");
4017MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4018MODULE_LICENSE("GPL");
4019MODULE_ALIAS("platform:wm8994-codec");