blob: 6c1fe3afd4b59311686ce3c9e2940cf5d223b1ed [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,
Mark Browncc6d5a82012-02-11 23:09:53 +0000780 WM8994_LINEOUT1_DISCH |
Mark Brown22f8d052012-03-19 17:32:06 +0000781 WM8994_LINEOUT2_DISCH, 0);
Mark Browncc6d5a82012-02-11 23:09:53 +0000782
Mark Brownf7085642012-02-21 16:24:00 +0000783 wm_hubs_vmid_ena(codec);
784
Mark Brown22f8d052012-03-19 17:32:06 +0000785 switch (wm8994->vmid_mode) {
786 default:
787 WARN_ON(0 == "Invalid VMID mode");
788 case WM8994_VMID_NORMAL:
789 /* Startup bias, VMID ramp & buffer */
790 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
791 WM8994_BIAS_SRC |
792 WM8994_VMID_DISCH |
793 WM8994_STARTUP_BIAS_ENA |
794 WM8994_VMID_BUF_ENA |
795 WM8994_VMID_RAMP_MASK,
796 WM8994_BIAS_SRC |
797 WM8994_STARTUP_BIAS_ENA |
798 WM8994_VMID_BUF_ENA |
799 (0x3 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900800
Mark Brown22f8d052012-03-19 17:32:06 +0000801 /* Main bias enable, VMID=2x40k */
802 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
803 WM8994_BIAS_ENA |
804 WM8994_VMID_SEL_MASK,
805 WM8994_BIAS_ENA | 0x2);
Mark Brown4b7ed832011-08-10 17:47:33 +0900806
Mark Brown22f8d052012-03-19 17:32:06 +0000807 msleep(50);
Mark Browncc6d5a82012-02-11 23:09:53 +0000808
Mark Brown22f8d052012-03-19 17:32:06 +0000809 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
810 WM8994_VMID_RAMP_MASK |
811 WM8994_BIAS_SRC,
812 0);
813 break;
814
815 case WM8994_VMID_FORCE:
816 /* Startup bias, slow VMID ramp & buffer */
817 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
818 WM8994_BIAS_SRC |
819 WM8994_VMID_DISCH |
820 WM8994_STARTUP_BIAS_ENA |
821 WM8994_VMID_BUF_ENA |
822 WM8994_VMID_RAMP_MASK,
823 WM8994_BIAS_SRC |
824 WM8994_STARTUP_BIAS_ENA |
825 WM8994_VMID_BUF_ENA |
826 (0x2 << WM8994_VMID_RAMP_SHIFT));
827
828 /* Main bias enable, VMID=2x40k */
829 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
830 WM8994_BIAS_ENA |
831 WM8994_VMID_SEL_MASK,
832 WM8994_BIAS_ENA | 0x2);
833
834 msleep(400);
835
836 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
837 WM8994_VMID_RAMP_MASK |
838 WM8994_BIAS_SRC,
839 0);
840 break;
841 }
Mark Brown4b7ed832011-08-10 17:47:33 +0900842 }
843}
844
845static void vmid_dereference(struct snd_soc_codec *codec)
846{
847 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
848
849 wm8994->vmid_refcount--;
850
851 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
852 wm8994->vmid_refcount);
853
854 if (wm8994->vmid_refcount == 0) {
Mark Brown22f8d052012-03-19 17:32:06 +0000855 if (wm8994->hubs.lineout1_se)
856 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
857 WM8994_LINEOUT1N_ENA |
858 WM8994_LINEOUT1P_ENA,
859 WM8994_LINEOUT1N_ENA |
860 WM8994_LINEOUT1P_ENA);
861
862 if (wm8994->hubs.lineout2_se)
863 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
864 WM8994_LINEOUT2N_ENA |
865 WM8994_LINEOUT2P_ENA,
866 WM8994_LINEOUT2N_ENA |
867 WM8994_LINEOUT2P_ENA);
868
869 /* Start discharging VMID */
Mark Brown4b7ed832011-08-10 17:47:33 +0900870 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
871 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000872 WM8994_VMID_DISCH,
Mark Brown4b7ed832011-08-10 17:47:33 +0900873 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000874 WM8994_VMID_DISCH);
Mark Brown4b7ed832011-08-10 17:47:33 +0900875
Mark Brown22f8d052012-03-19 17:32:06 +0000876 switch (wm8994->vmid_mode) {
877 case WM8994_VMID_FORCE:
878 msleep(350);
879 break;
880 default:
881 break;
882 }
Mark Brown4b7ed832011-08-10 17:47:33 +0900883
Mark Brown22f8d052012-03-19 17:32:06 +0000884 snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
885 WM8994_VROI, WM8994_VROI);
Mark Browne85b26c2012-02-11 23:10:30 +0000886
Mark Brown22f8d052012-03-19 17:32:06 +0000887 /* Active discharge */
Mark Brown4b7ed832011-08-10 17:47:33 +0900888 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
889 WM8994_LINEOUT1_DISCH |
890 WM8994_LINEOUT2_DISCH,
891 WM8994_LINEOUT1_DISCH |
892 WM8994_LINEOUT2_DISCH);
893
Mark Brown22f8d052012-03-19 17:32:06 +0000894 msleep(150);
895
896 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
897 WM8994_LINEOUT1N_ENA |
898 WM8994_LINEOUT1P_ENA |
899 WM8994_LINEOUT2N_ENA |
900 WM8994_LINEOUT2P_ENA, 0);
901
902 snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
903 WM8994_VROI, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900904
905 /* Switch off startup biases */
906 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
907 WM8994_BIAS_SRC |
908 WM8994_STARTUP_BIAS_ENA |
909 WM8994_VMID_BUF_ENA |
910 WM8994_VMID_RAMP_MASK, 0);
Mark Brown22f8d052012-03-19 17:32:06 +0000911
912 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
913 WM8994_BIAS_ENA | WM8994_VMID_SEL_MASK, 0);
914
915 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
916 WM8994_VMID_RAMP_MASK, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900917 }
Mark Browndb966f82012-02-06 12:07:08 +0000918
919 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900920}
921
922static int vmid_event(struct snd_soc_dapm_widget *w,
923 struct snd_kcontrol *kcontrol, int event)
924{
925 struct snd_soc_codec *codec = w->codec;
926
927 switch (event) {
928 case SND_SOC_DAPM_PRE_PMU:
929 vmid_reference(codec);
930 break;
931
932 case SND_SOC_DAPM_POST_PMD:
933 vmid_dereference(codec);
934 break;
935 }
936
937 return 0;
938}
939
Mark Brown9e6e96a2010-01-29 17:47:12 +0000940static void wm8994_update_class_w(struct snd_soc_codec *codec)
941{
Mark Brownfec6dd82010-10-27 13:48:36 -0700942 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000943 int enable = 1;
944 int source = 0; /* GCC flow analysis can't track enable */
945 int reg, reg_r;
946
947 /* Only support direct DAC->headphone paths */
948 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
949 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900950 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000951 enable = 0;
952 }
953
954 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
955 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900956 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000957 enable = 0;
958 }
959
960 /* We also need the same setting for L/R and only one path */
961 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
962 switch (reg) {
963 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900964 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000965 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
966 break;
967 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900968 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000969 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
970 break;
971 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900972 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000973 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
974 break;
975 default:
Mark Brownee839a22010-04-20 13:57:08 +0900976 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000977 enable = 0;
978 break;
979 }
980
981 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
982 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900983 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000984 enable = 0;
985 }
986
987 if (enable) {
988 dev_dbg(codec->dev, "Class W enabled\n");
989 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
990 WM8994_CP_DYN_PWR |
991 WM8994_CP_DYN_SRC_SEL_MASK,
992 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700993 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000994
995 } else {
996 dev_dbg(codec->dev, "Class W disabled\n");
997 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
998 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700999 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001000 }
1001}
1002
Mark Brown1a383362012-04-12 19:47:11 +01001003static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1004 struct snd_kcontrol *kcontrol, int event)
1005{
1006 struct snd_soc_codec *codec = w->codec;
1007 struct wm8994 *control = codec->control_data;
1008 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
1009 int dac;
1010 int adc;
1011 int val;
1012
1013 switch (control->type) {
1014 case WM8994:
1015 case WM8958:
1016 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1017 break;
1018 default:
1019 break;
1020 }
1021
1022 switch (event) {
1023 case SND_SOC_DAPM_PRE_PMU:
1024 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
1025 if ((val & WM8994_AIF1ADCL_SRC) &&
1026 (val & WM8994_AIF1ADCR_SRC))
1027 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1028 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1029 !(val & WM8994_AIF1ADCR_SRC))
1030 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1031 else
1032 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1033 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1034
1035 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
1036 if ((val & WM8994_AIF1DACL_SRC) &&
1037 (val & WM8994_AIF1DACR_SRC))
1038 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1039 else if (!(val & WM8994_AIF1DACL_SRC) &&
1040 !(val & WM8994_AIF1DACR_SRC))
1041 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1042 else
1043 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1044 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1045
1046 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1047 mask, adc);
1048 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1049 mask, dac);
1050 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1051 WM8994_AIF1DSPCLK_ENA |
1052 WM8994_SYSDSPCLK_ENA,
1053 WM8994_AIF1DSPCLK_ENA |
1054 WM8994_SYSDSPCLK_ENA);
1055 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
1056 WM8994_AIF1ADC1R_ENA |
1057 WM8994_AIF1ADC1L_ENA |
1058 WM8994_AIF1ADC2R_ENA |
1059 WM8994_AIF1ADC2L_ENA);
1060 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
1061 WM8994_AIF1DAC1R_ENA |
1062 WM8994_AIF1DAC1L_ENA |
1063 WM8994_AIF1DAC2R_ENA |
1064 WM8994_AIF1DAC2L_ENA);
1065 break;
1066
1067 case SND_SOC_DAPM_PRE_PMD:
1068 case SND_SOC_DAPM_POST_PMD:
1069 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1070 mask, 0);
1071 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1072 mask, 0);
1073
1074 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1075 if (val & WM8994_AIF2DSPCLK_ENA)
1076 val = WM8994_SYSDSPCLK_ENA;
1077 else
1078 val = 0;
1079 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1080 WM8994_SYSDSPCLK_ENA |
1081 WM8994_AIF1DSPCLK_ENA, val);
1082 break;
1083 }
1084
1085 return 0;
1086}
1087
1088static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1089 struct snd_kcontrol *kcontrol, int event)
1090{
1091 struct snd_soc_codec *codec = w->codec;
1092 int dac;
1093 int adc;
1094 int val;
1095
1096 switch (event) {
1097 case SND_SOC_DAPM_PRE_PMU:
1098 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
1099 if ((val & WM8994_AIF2ADCL_SRC) &&
1100 (val & WM8994_AIF2ADCR_SRC))
1101 adc = WM8994_AIF2ADCR_ENA;
1102 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1103 !(val & WM8994_AIF2ADCR_SRC))
1104 adc = WM8994_AIF2ADCL_ENA;
1105 else
1106 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1107
1108
1109 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
1110 if ((val & WM8994_AIF2DACL_SRC) &&
1111 (val & WM8994_AIF2DACR_SRC))
1112 dac = WM8994_AIF2DACR_ENA;
1113 else if (!(val & WM8994_AIF2DACL_SRC) &&
1114 !(val & WM8994_AIF2DACR_SRC))
1115 dac = WM8994_AIF2DACL_ENA;
1116 else
1117 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1118
1119 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1120 WM8994_AIF2ADCL_ENA |
1121 WM8994_AIF2ADCR_ENA, adc);
1122 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1123 WM8994_AIF2DACL_ENA |
1124 WM8994_AIF2DACR_ENA, dac);
1125 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1126 WM8994_AIF2DSPCLK_ENA |
1127 WM8994_SYSDSPCLK_ENA,
1128 WM8994_AIF2DSPCLK_ENA |
1129 WM8994_SYSDSPCLK_ENA);
1130 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1131 WM8994_AIF2ADCL_ENA |
1132 WM8994_AIF2ADCR_ENA,
1133 WM8994_AIF2ADCL_ENA |
1134 WM8994_AIF2ADCR_ENA);
1135 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1136 WM8994_AIF2DACL_ENA |
1137 WM8994_AIF2DACR_ENA,
1138 WM8994_AIF2DACL_ENA |
1139 WM8994_AIF2DACR_ENA);
1140 break;
1141
1142 case SND_SOC_DAPM_PRE_PMD:
1143 case SND_SOC_DAPM_POST_PMD:
1144 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1145 WM8994_AIF2DACL_ENA |
1146 WM8994_AIF2DACR_ENA, 0);
1147 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1148 WM8994_AIF2ADCL_ENA |
1149 WM8994_AIF2ADCR_ENA, 0);
1150
1151 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1152 if (val & WM8994_AIF1DSPCLK_ENA)
1153 val = WM8994_SYSDSPCLK_ENA;
1154 else
1155 val = 0;
1156 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1157 WM8994_SYSDSPCLK_ENA |
1158 WM8994_AIF2DSPCLK_ENA, val);
1159 break;
1160 }
1161
1162 return 0;
1163}
1164
1165static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1166 struct snd_kcontrol *kcontrol, int event)
1167{
1168 struct snd_soc_codec *codec = w->codec;
1169 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1170
1171 switch (event) {
1172 case SND_SOC_DAPM_PRE_PMU:
1173 wm8994->aif1clk_enable = 1;
1174 break;
1175 case SND_SOC_DAPM_POST_PMD:
1176 wm8994->aif1clk_disable = 1;
1177 break;
1178 }
1179
1180 return 0;
1181}
1182
1183static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1184 struct snd_kcontrol *kcontrol, int event)
1185{
1186 struct snd_soc_codec *codec = w->codec;
1187 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1188
1189 switch (event) {
1190 case SND_SOC_DAPM_PRE_PMU:
1191 wm8994->aif2clk_enable = 1;
1192 break;
1193 case SND_SOC_DAPM_POST_PMD:
1194 wm8994->aif2clk_disable = 1;
1195 break;
1196 }
1197
1198 return 0;
1199}
1200
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001201static int late_enable_ev(struct snd_soc_dapm_widget *w,
1202 struct snd_kcontrol *kcontrol, int event)
1203{
1204 struct snd_soc_codec *codec = w->codec;
1205 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1206
1207 switch (event) {
1208 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001209 if (wm8994->aif1clk_enable) {
Mark Brown1a383362012-04-12 19:47:11 +01001210 aif1clk_ev(w, kcontrol, event);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001211 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1212 WM8994_AIF1CLK_ENA_MASK,
1213 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001214 wm8994->aif1clk_enable = 0;
1215 }
1216 if (wm8994->aif2clk_enable) {
Mark Brown1a383362012-04-12 19:47:11 +01001217 aif2clk_ev(w, kcontrol, event);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001218 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1219 WM8994_AIF2CLK_ENA_MASK,
1220 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001221 wm8994->aif2clk_enable = 0;
1222 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001223 break;
1224 }
1225
Mark Brownc6b7b572011-03-11 18:13:12 +00001226 /* We may also have postponed startup of DSP, handle that. */
1227 wm8958_aif_ev(w, kcontrol, event);
1228
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001229 return 0;
1230}
1231
1232static int late_disable_ev(struct snd_soc_dapm_widget *w,
1233 struct snd_kcontrol *kcontrol, int event)
1234{
1235 struct snd_soc_codec *codec = w->codec;
1236 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1237
1238 switch (event) {
1239 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001240 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001241 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1242 WM8994_AIF1CLK_ENA_MASK, 0);
Mark Brown1a383362012-04-12 19:47:11 +01001243 aif1clk_ev(w, kcontrol, event);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001244 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001245 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001246 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001247 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1248 WM8994_AIF2CLK_ENA_MASK, 0);
Mark Brown1a383362012-04-12 19:47:11 +01001249 aif2clk_ev(w, kcontrol, event);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001250 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001251 }
1252 break;
1253 }
1254
1255 return 0;
1256}
1257
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001258static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1259 struct snd_kcontrol *kcontrol, int event)
1260{
1261 late_enable_ev(w, kcontrol, event);
1262 return 0;
1263}
1264
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001265static int micbias_ev(struct snd_soc_dapm_widget *w,
1266 struct snd_kcontrol *kcontrol, int event)
1267{
1268 late_enable_ev(w, kcontrol, event);
1269 return 0;
1270}
1271
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001272static int dac_ev(struct snd_soc_dapm_widget *w,
1273 struct snd_kcontrol *kcontrol, int event)
1274{
1275 struct snd_soc_codec *codec = w->codec;
1276 unsigned int mask = 1 << w->shift;
1277
1278 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1279 mask, mask);
1280 return 0;
1281}
1282
Mark Brown9e6e96a2010-01-29 17:47:12 +00001283static const char *hp_mux_text[] = {
1284 "Mixer",
1285 "DAC",
1286};
1287
1288#define WM8994_HP_ENUM(xname, xenum) \
1289{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1290 .info = snd_soc_info_enum_double, \
1291 .get = snd_soc_dapm_get_enum_double, \
1292 .put = wm8994_put_hp_enum, \
1293 .private_value = (unsigned long)&xenum }
1294
1295static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1296 struct snd_ctl_elem_value *ucontrol)
1297{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001298 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1299 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001300 struct snd_soc_codec *codec = w->codec;
1301 int ret;
1302
1303 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1304
1305 wm8994_update_class_w(codec);
1306
1307 return ret;
1308}
1309
1310static const struct soc_enum hpl_enum =
1311 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1312
1313static const struct snd_kcontrol_new hpl_mux =
1314 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1315
1316static const struct soc_enum hpr_enum =
1317 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1318
1319static const struct snd_kcontrol_new hpr_mux =
1320 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1321
1322static const char *adc_mux_text[] = {
1323 "ADC",
1324 "DMIC",
1325};
1326
1327static const struct soc_enum adc_enum =
1328 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1329
1330static const struct snd_kcontrol_new adcl_mux =
1331 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1332
1333static const struct snd_kcontrol_new adcr_mux =
1334 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1335
1336static const struct snd_kcontrol_new left_speaker_mixer[] = {
1337SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1338SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1339SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1340SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1341SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1342};
1343
1344static const struct snd_kcontrol_new right_speaker_mixer[] = {
1345SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1346SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1347SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1348SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1349SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1350};
1351
1352/* Debugging; dump chip status after DAPM transitions */
1353static int post_ev(struct snd_soc_dapm_widget *w,
1354 struct snd_kcontrol *kcontrol, int event)
1355{
1356 struct snd_soc_codec *codec = w->codec;
1357 dev_dbg(codec->dev, "SRC status: %x\n",
1358 snd_soc_read(codec,
1359 WM8994_RATE_STATUS));
1360 return 0;
1361}
1362
1363static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1364SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1365 1, 1, 0),
1366SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1367 0, 1, 0),
1368};
1369
1370static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1371SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1372 1, 1, 0),
1373SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1374 0, 1, 0),
1375};
1376
Mark Browna3257ba2010-07-19 14:02:34 +01001377static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1378SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1379 1, 1, 0),
1380SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1381 0, 1, 0),
1382};
1383
1384static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1385SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1386 1, 1, 0),
1387SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1388 0, 1, 0),
1389};
1390
Mark Brown9e6e96a2010-01-29 17:47:12 +00001391static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1392SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1393 5, 1, 0),
1394SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1395 4, 1, 0),
1396SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1397 2, 1, 0),
1398SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1399 1, 1, 0),
1400SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1401 0, 1, 0),
1402};
1403
1404static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1405SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1406 5, 1, 0),
1407SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1408 4, 1, 0),
1409SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1410 2, 1, 0),
1411SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1412 1, 1, 0),
1413SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1414 0, 1, 0),
1415};
1416
1417#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1418{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1419 .info = snd_soc_info_volsw, \
1420 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1421 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1422
1423static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1424 struct snd_ctl_elem_value *ucontrol)
1425{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001426 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1427 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001428 struct snd_soc_codec *codec = w->codec;
1429 int ret;
1430
1431 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1432
1433 wm8994_update_class_w(codec);
1434
1435 return ret;
1436}
1437
1438static const struct snd_kcontrol_new dac1l_mix[] = {
1439WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1440 5, 1, 0),
1441WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1442 4, 1, 0),
1443WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1444 2, 1, 0),
1445WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1446 1, 1, 0),
1447WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1448 0, 1, 0),
1449};
1450
1451static const struct snd_kcontrol_new dac1r_mix[] = {
1452WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1453 5, 1, 0),
1454WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1455 4, 1, 0),
1456WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1457 2, 1, 0),
1458WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1459 1, 1, 0),
1460WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1461 0, 1, 0),
1462};
1463
1464static const char *sidetone_text[] = {
1465 "ADC/DMIC1", "DMIC2",
1466};
1467
1468static const struct soc_enum sidetone1_enum =
1469 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1470
1471static const struct snd_kcontrol_new sidetone1_mux =
1472 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1473
1474static const struct soc_enum sidetone2_enum =
1475 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1476
1477static const struct snd_kcontrol_new sidetone2_mux =
1478 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1479
1480static const char *aif1dac_text[] = {
1481 "AIF1DACDAT", "AIF3DACDAT",
1482};
1483
1484static const struct soc_enum aif1dac_enum =
1485 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1486
1487static const struct snd_kcontrol_new aif1dac_mux =
1488 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1489
1490static const char *aif2dac_text[] = {
1491 "AIF2DACDAT", "AIF3DACDAT",
1492};
1493
1494static const struct soc_enum aif2dac_enum =
1495 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1496
1497static const struct snd_kcontrol_new aif2dac_mux =
1498 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1499
1500static const char *aif2adc_text[] = {
1501 "AIF2ADCDAT", "AIF3DACDAT",
1502};
1503
1504static const struct soc_enum aif2adc_enum =
1505 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1506
1507static const struct snd_kcontrol_new aif2adc_mux =
1508 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1509
1510static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001511 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001512};
1513
Mark Brownc4431df2010-11-26 15:21:07 +00001514static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001515 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1516
Mark Brownc4431df2010-11-26 15:21:07 +00001517static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1518 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1519
1520static const struct soc_enum wm8958_aif3adc_enum =
1521 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1522
1523static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1524 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1525
1526static const char *mono_pcm_out_text[] = {
1527 "None", "AIF2ADCL", "AIF2ADCR",
1528};
1529
1530static const struct soc_enum mono_pcm_out_enum =
1531 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1532
1533static const struct snd_kcontrol_new mono_pcm_out_mux =
1534 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1535
1536static const char *aif2dac_src_text[] = {
1537 "AIF2", "AIF3",
1538};
1539
1540/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1541static const struct soc_enum aif2dacl_src_enum =
1542 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1543
1544static const struct snd_kcontrol_new aif2dacl_src_mux =
1545 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1546
1547static const struct soc_enum aif2dacr_src_enum =
1548 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1549
1550static const struct snd_kcontrol_new aif2dacr_src_mux =
1551 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001552
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001553static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001554SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001555 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown1a383362012-04-12 19:47:11 +01001556SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001557 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1558
1559SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1560 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1561SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1562 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1563SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1564 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1565SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1566 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001567SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1568 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1569
1570SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1571 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1572 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1573SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1574 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1575 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1576SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1577 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1578SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1579 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001580
1581SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1582};
1583
1584static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001585SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
1586 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
1587SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
1588 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brownb70a51b2011-06-29 00:21:09 -07001589SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1590SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1591 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1592SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1593 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1594SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1595SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001596};
1597
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001598static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1599SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1600 dac_ev, SND_SOC_DAPM_PRE_PMU),
1601SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1602 dac_ev, SND_SOC_DAPM_PRE_PMU),
1603SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1604 dac_ev, SND_SOC_DAPM_PRE_PMU),
1605SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1606 dac_ev, SND_SOC_DAPM_PRE_PMU),
1607};
1608
1609static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1610SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001611SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001612SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1613SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1614};
1615
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001616static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001617SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1618 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1619SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1620 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001621};
1622
1623static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001624SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1625SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001626};
1627
Mark Brown9e6e96a2010-01-29 17:47:12 +00001628static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1629SND_SOC_DAPM_INPUT("DMIC1DAT"),
1630SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001631SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001632
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001633SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1634 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001635SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1636 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001637
Mark Brown9e6e96a2010-01-29 17:47:12 +00001638SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1639 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1640
Mark Brown1a383362012-04-12 19:47:11 +01001641SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1642SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1643SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001644
Mark Brown7f94de42011-02-03 16:27:34 +00001645SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001646 0, SND_SOC_NOPM, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001647SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001648 0, SND_SOC_NOPM, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001649SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001650 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001651 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001652SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001653 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001654 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001655
Mark Brown7f94de42011-02-03 16:27:34 +00001656SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001657 0, SND_SOC_NOPM, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001658SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001659 0, SND_SOC_NOPM, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001660SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001661 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001662 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001663SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001664 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001665 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001666
1667SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1668 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1669SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1670 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1671
Mark Browna3257ba2010-07-19 14:02:34 +01001672SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1673 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1674SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1675 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1676
Mark Brown9e6e96a2010-01-29 17:47:12 +00001677SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1678 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1679SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1680 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1681
1682SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1683SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1684
1685SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1686 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1687SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1688 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1689
1690SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001691 SND_SOC_NOPM, 13, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001692SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001693 SND_SOC_NOPM, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001694SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001695 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001696 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1697SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001698 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001699 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001700
Mark Brown5567d8c2012-02-16 21:43:29 -08001701SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1702SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1703SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1704SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001705
1706SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1707SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1708SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001709
Mark Brown5567d8c2012-02-16 21:43:29 -08001710SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1711SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001712
1713SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1714
1715SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1716SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1717SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1718SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1719
1720/* Power is done with the muxes since the ADC power also controls the
1721 * downsampling chain, the chip will automatically manage the analogue
1722 * specific portions.
1723 */
1724SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1725SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1726
Mark Brown9e6e96a2010-01-29 17:47:12 +00001727SND_SOC_DAPM_POST("Debug log", post_ev),
1728};
1729
Mark Brownc4431df2010-11-26 15:21:07 +00001730static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1731SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1732};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001733
Mark Brownc4431df2010-11-26 15:21:07 +00001734static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1735SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1736SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1737SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1738SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1739};
1740
1741static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001742 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1743 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1744
1745 { "DSP1CLK", NULL, "CLK_SYS" },
1746 { "DSP2CLK", NULL, "CLK_SYS" },
1747 { "DSPINTCLK", NULL, "CLK_SYS" },
1748
1749 { "AIF1ADC1L", NULL, "AIF1CLK" },
1750 { "AIF1ADC1L", NULL, "DSP1CLK" },
1751 { "AIF1ADC1R", NULL, "AIF1CLK" },
1752 { "AIF1ADC1R", NULL, "DSP1CLK" },
1753 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1754
1755 { "AIF1DAC1L", NULL, "AIF1CLK" },
1756 { "AIF1DAC1L", NULL, "DSP1CLK" },
1757 { "AIF1DAC1R", NULL, "AIF1CLK" },
1758 { "AIF1DAC1R", NULL, "DSP1CLK" },
1759 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1760
1761 { "AIF1ADC2L", NULL, "AIF1CLK" },
1762 { "AIF1ADC2L", NULL, "DSP1CLK" },
1763 { "AIF1ADC2R", NULL, "AIF1CLK" },
1764 { "AIF1ADC2R", NULL, "DSP1CLK" },
1765 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1766
1767 { "AIF1DAC2L", NULL, "AIF1CLK" },
1768 { "AIF1DAC2L", NULL, "DSP1CLK" },
1769 { "AIF1DAC2R", NULL, "AIF1CLK" },
1770 { "AIF1DAC2R", NULL, "DSP1CLK" },
1771 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1772
1773 { "AIF2ADCL", NULL, "AIF2CLK" },
1774 { "AIF2ADCL", NULL, "DSP2CLK" },
1775 { "AIF2ADCR", NULL, "AIF2CLK" },
1776 { "AIF2ADCR", NULL, "DSP2CLK" },
1777 { "AIF2ADCR", NULL, "DSPINTCLK" },
1778
1779 { "AIF2DACL", NULL, "AIF2CLK" },
1780 { "AIF2DACL", NULL, "DSP2CLK" },
1781 { "AIF2DACR", NULL, "AIF2CLK" },
1782 { "AIF2DACR", NULL, "DSP2CLK" },
1783 { "AIF2DACR", NULL, "DSPINTCLK" },
1784
1785 { "DMIC1L", NULL, "DMIC1DAT" },
1786 { "DMIC1L", NULL, "CLK_SYS" },
1787 { "DMIC1R", NULL, "DMIC1DAT" },
1788 { "DMIC1R", NULL, "CLK_SYS" },
1789 { "DMIC2L", NULL, "DMIC2DAT" },
1790 { "DMIC2L", NULL, "CLK_SYS" },
1791 { "DMIC2R", NULL, "DMIC2DAT" },
1792 { "DMIC2R", NULL, "CLK_SYS" },
1793
1794 { "ADCL", NULL, "AIF1CLK" },
1795 { "ADCL", NULL, "DSP1CLK" },
1796 { "ADCL", NULL, "DSPINTCLK" },
1797
1798 { "ADCR", NULL, "AIF1CLK" },
1799 { "ADCR", NULL, "DSP1CLK" },
1800 { "ADCR", NULL, "DSPINTCLK" },
1801
1802 { "ADCL Mux", "ADC", "ADCL" },
1803 { "ADCL Mux", "DMIC", "DMIC1L" },
1804 { "ADCR Mux", "ADC", "ADCR" },
1805 { "ADCR Mux", "DMIC", "DMIC1R" },
1806
1807 { "DAC1L", NULL, "AIF1CLK" },
1808 { "DAC1L", NULL, "DSP1CLK" },
1809 { "DAC1L", NULL, "DSPINTCLK" },
1810
1811 { "DAC1R", NULL, "AIF1CLK" },
1812 { "DAC1R", NULL, "DSP1CLK" },
1813 { "DAC1R", NULL, "DSPINTCLK" },
1814
1815 { "DAC2L", NULL, "AIF2CLK" },
1816 { "DAC2L", NULL, "DSP2CLK" },
1817 { "DAC2L", NULL, "DSPINTCLK" },
1818
1819 { "DAC2R", NULL, "AIF2DACR" },
1820 { "DAC2R", NULL, "AIF2CLK" },
1821 { "DAC2R", NULL, "DSP2CLK" },
1822 { "DAC2R", NULL, "DSPINTCLK" },
1823
1824 { "TOCLK", NULL, "CLK_SYS" },
1825
Mark Brown5567d8c2012-02-16 21:43:29 -08001826 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1827 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1828 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1829
1830 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1831 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1832 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1833
Mark Brown9e6e96a2010-01-29 17:47:12 +00001834 /* AIF1 outputs */
1835 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1836 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1837 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1838
1839 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1840 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1841 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1842
Mark Browna3257ba2010-07-19 14:02:34 +01001843 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1844 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1845 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1846
1847 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1848 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1849 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1850
Mark Brown9e6e96a2010-01-29 17:47:12 +00001851 /* Pin level routing for AIF3 */
1852 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1853 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1854 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1855 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1856
Mark Brown9e6e96a2010-01-29 17:47:12 +00001857 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1858 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1859 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1860 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1861 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1862 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1863 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1864
1865 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001866 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1867 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1868 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1869 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1870 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1871
Mark Brown9e6e96a2010-01-29 17:47:12 +00001872 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1873 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1874 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1875 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1876 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1877
1878 /* DAC2/AIF2 outputs */
1879 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001880 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1881 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1882 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1883 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1884 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1885
1886 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001887 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1888 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1889 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1890 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1891 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1892
Mark Brown7f94de42011-02-03 16:27:34 +00001893 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1894 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1895 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1896 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1897
Mark Brown9e6e96a2010-01-29 17:47:12 +00001898 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1899
1900 /* AIF3 output */
1901 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1902 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1903 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1904 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1905 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1906 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1907 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1908 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1909
1910 /* Sidetone */
1911 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1912 { "Left Sidetone", "DMIC2", "DMIC2L" },
1913 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1914 { "Right Sidetone", "DMIC2", "DMIC2R" },
1915
1916 /* Output stages */
1917 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1918 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1919
1920 { "SPKL", "DAC1 Switch", "DAC1L" },
1921 { "SPKL", "DAC2 Switch", "DAC2L" },
1922
1923 { "SPKR", "DAC1 Switch", "DAC1R" },
1924 { "SPKR", "DAC2 Switch", "DAC2R" },
1925
1926 { "Left Headphone Mux", "DAC", "DAC1L" },
1927 { "Right Headphone Mux", "DAC", "DAC1R" },
1928};
1929
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001930static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1931 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1932 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1933 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1934 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1935 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1936 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1937 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1938 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1939};
1940
1941static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1942 { "DAC1L", NULL, "DAC1L Mixer" },
1943 { "DAC1R", NULL, "DAC1R Mixer" },
1944 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1945 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1946};
1947
Mark Brown6ed8f142011-02-03 16:27:35 +00001948static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1949 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1950 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1951 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1952 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001953 { "MICBIAS1", NULL, "CLK_SYS" },
1954 { "MICBIAS1", NULL, "MICBIAS Supply" },
1955 { "MICBIAS2", NULL, "CLK_SYS" },
1956 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001957};
1958
Mark Brownc4431df2010-11-26 15:21:07 +00001959static const struct snd_soc_dapm_route wm8994_intercon[] = {
1960 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1961 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001962 { "MICBIAS1", NULL, "VMID" },
1963 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001964};
1965
1966static const struct snd_soc_dapm_route wm8958_intercon[] = {
1967 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1968 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1969
1970 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1971 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1972 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1973 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1974
1975 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1976 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1977
1978 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1979};
1980
Mark Brown9e6e96a2010-01-29 17:47:12 +00001981/* The size in bits of the FLL divide multiplied by 10
1982 * to allow rounding later */
1983#define FIXED_FLL_SIZE ((1 << 16) * 10)
1984
1985struct fll_div {
1986 u16 outdiv;
1987 u16 n;
1988 u16 k;
1989 u16 clk_ref_div;
1990 u16 fll_fratio;
1991};
1992
1993static int wm8994_get_fll_config(struct fll_div *fll,
1994 int freq_in, int freq_out)
1995{
1996 u64 Kpart;
1997 unsigned int K, Ndiv, Nmod;
1998
1999 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2000
2001 /* Scale the input frequency down to <= 13.5MHz */
2002 fll->clk_ref_div = 0;
2003 while (freq_in > 13500000) {
2004 fll->clk_ref_div++;
2005 freq_in /= 2;
2006
2007 if (fll->clk_ref_div > 3)
2008 return -EINVAL;
2009 }
2010 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2011
2012 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2013 fll->outdiv = 3;
2014 while (freq_out * (fll->outdiv + 1) < 90000000) {
2015 fll->outdiv++;
2016 if (fll->outdiv > 63)
2017 return -EINVAL;
2018 }
2019 freq_out *= fll->outdiv + 1;
2020 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2021
2022 if (freq_in > 1000000) {
2023 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002024 } else if (freq_in > 256000) {
2025 fll->fll_fratio = 1;
2026 freq_in *= 2;
2027 } else if (freq_in > 128000) {
2028 fll->fll_fratio = 2;
2029 freq_in *= 4;
2030 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002031 fll->fll_fratio = 3;
2032 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002033 } else {
2034 fll->fll_fratio = 4;
2035 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002036 }
2037 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2038
2039 /* Now, calculate N.K */
2040 Ndiv = freq_out / freq_in;
2041
2042 fll->n = Ndiv;
2043 Nmod = freq_out % freq_in;
2044 pr_debug("Nmod=%d\n", Nmod);
2045
2046 /* Calculate fractional part - scale up so we can round. */
2047 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2048
2049 do_div(Kpart, freq_in);
2050
2051 K = Kpart & 0xFFFFFFFF;
2052
2053 if ((K % 10) >= 5)
2054 K += 5;
2055
2056 /* Move down to proper range now rounding is done */
2057 fll->k = K / 10;
2058
2059 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2060
2061 return 0;
2062}
2063
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002064static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002065 unsigned int freq_in, unsigned int freq_out)
2066{
Mark Brownb2c812e2010-04-14 15:35:19 +09002067 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002068 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002069 int reg_offset, ret;
2070 struct fll_div fll;
2071 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09002072 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09002073 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002074
2075 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
2076 & WM8994_AIF1CLK_ENA;
2077
2078 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
2079 & WM8994_AIF2CLK_ENA;
2080
2081 switch (id) {
2082 case WM8994_FLL1:
2083 reg_offset = 0;
2084 id = 0;
2085 break;
2086 case WM8994_FLL2:
2087 reg_offset = 0x20;
2088 id = 1;
2089 break;
2090 default:
2091 return -EINVAL;
2092 }
2093
Mark Brown4b7ed832011-08-10 17:47:33 +09002094 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
2095 was_enabled = reg & WM8994_FLL1_ENA;
2096
Mark Brown136ff2a2010-04-20 12:56:18 +09002097 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09002098 case 0:
2099 /* Allow no source specification when stopping */
2100 if (freq_out)
2101 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00002102 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09002103 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09002104 case WM8994_FLL_SRC_MCLK1:
2105 case WM8994_FLL_SRC_MCLK2:
2106 case WM8994_FLL_SRC_LRCLK:
2107 case WM8994_FLL_SRC_BCLK:
2108 break;
2109 default:
2110 return -EINVAL;
2111 }
2112
Mark Brown9e6e96a2010-01-29 17:47:12 +00002113 /* Are we changing anything? */
2114 if (wm8994->fll[id].src == src &&
2115 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2116 return 0;
2117
2118 /* If we're stopping the FLL redo the old config - no
2119 * registers will actually be written but we avoid GCC flow
2120 * analysis bugs spewing warnings.
2121 */
2122 if (freq_out)
2123 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
2124 else
2125 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
2126 wm8994->fll[id].out);
2127 if (ret < 0)
2128 return ret;
2129
2130 /* Gate the AIF clocks while we reclock */
2131 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
2132 WM8994_AIF1CLK_ENA, 0);
2133 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
2134 WM8994_AIF2CLK_ENA, 0);
2135
2136 /* We always need to disable the FLL while reconfiguring */
2137 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2138 WM8994_FLL1_ENA, 0);
2139
2140 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2141 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2142 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
2143 WM8994_FLL1_OUTDIV_MASK |
2144 WM8994_FLL1_FRATIO_MASK, reg);
2145
Mark Brownb16db742012-03-03 15:33:23 +00002146 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
2147 WM8994_FLL1_K_MASK, fll.k);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002148
2149 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
2150 WM8994_FLL1_N_MASK,
2151 fll.n << WM8994_FLL1_N_SHIFT);
2152
2153 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09002154 WM8994_FLL1_REFCLK_DIV_MASK |
2155 WM8994_FLL1_REFCLK_SRC_MASK,
2156 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2157 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00002158
Mark Brownf0f50392011-07-16 03:12:18 +09002159 /* Clear any pending completion from a previous failure */
2160 try_wait_for_completion(&wm8994->fll_locked[id]);
2161
Mark Brown9e6e96a2010-01-29 17:47:12 +00002162 /* Enable (with fractional mode if required) */
2163 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09002164 /* Enable VMID if we need it */
2165 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002166 active_reference(codec);
2167
Mark Brown4b7ed832011-08-10 17:47:33 +09002168 switch (control->type) {
2169 case WM8994:
2170 vmid_reference(codec);
2171 break;
2172 case WM8958:
2173 if (wm8994->revision < 1)
2174 vmid_reference(codec);
2175 break;
2176 default:
2177 break;
2178 }
2179 }
2180
Mark Brown9e6e96a2010-01-29 17:47:12 +00002181 if (fll.k)
2182 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
2183 else
2184 reg = WM8994_FLL1_ENA;
2185 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2186 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
2187 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07002188
Mark Brownc7ebf932011-07-12 19:47:59 +09002189 if (wm8994->fll_locked_irq) {
2190 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2191 msecs_to_jiffies(10));
2192 if (timeout == 0)
2193 dev_warn(codec->dev,
2194 "Timed out waiting for FLL lock\n");
2195 } else {
2196 msleep(5);
2197 }
Mark Brown4b7ed832011-08-10 17:47:33 +09002198 } else {
2199 if (was_enabled) {
2200 switch (control->type) {
2201 case WM8994:
2202 vmid_dereference(codec);
2203 break;
2204 case WM8958:
2205 if (wm8994->revision < 1)
2206 vmid_dereference(codec);
2207 break;
2208 default:
2209 break;
2210 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002211
2212 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09002213 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002214 }
2215
2216 wm8994->fll[id].in = freq_in;
2217 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09002218 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002219
2220 /* Enable any gated AIF clocks */
2221 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
2222 WM8994_AIF1CLK_ENA, aif1);
2223 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
2224 WM8994_AIF2CLK_ENA, aif2);
2225
2226 configure_clock(codec);
2227
2228 return 0;
2229}
2230
Mark Brownc7ebf932011-07-12 19:47:59 +09002231static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2232{
2233 struct completion *completion = data;
2234
2235 complete(completion);
2236
2237 return IRQ_HANDLED;
2238}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002239
Mark Brown66b47fd2010-07-08 11:25:43 +09002240static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2241
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002242static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2243 unsigned int freq_in, unsigned int freq_out)
2244{
2245 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2246}
2247
Mark Brown9e6e96a2010-01-29 17:47:12 +00002248static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2249 int clk_id, unsigned int freq, int dir)
2250{
2251 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002252 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002253 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002254
2255 switch (dai->id) {
2256 case 1:
2257 case 2:
2258 break;
2259
2260 default:
2261 /* AIF3 shares clocking with AIF1/2 */
2262 return -EINVAL;
2263 }
2264
2265 switch (clk_id) {
2266 case WM8994_SYSCLK_MCLK1:
2267 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2268 wm8994->mclk[0] = freq;
2269 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2270 dai->id, freq);
2271 break;
2272
2273 case WM8994_SYSCLK_MCLK2:
2274 /* TODO: Set GPIO AF */
2275 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2276 wm8994->mclk[1] = freq;
2277 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2278 dai->id, freq);
2279 break;
2280
2281 case WM8994_SYSCLK_FLL1:
2282 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2283 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2284 break;
2285
2286 case WM8994_SYSCLK_FLL2:
2287 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2288 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2289 break;
2290
Mark Brown66b47fd2010-07-08 11:25:43 +09002291 case WM8994_SYSCLK_OPCLK:
2292 /* Special case - a division (times 10) is given and
2293 * no effect on main clocking.
2294 */
2295 if (freq) {
2296 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2297 if (opclk_divs[i] == freq)
2298 break;
2299 if (i == ARRAY_SIZE(opclk_divs))
2300 return -EINVAL;
2301 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2302 WM8994_OPCLK_DIV_MASK, i);
2303 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2304 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2305 } else {
2306 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2307 WM8994_OPCLK_ENA, 0);
2308 }
2309
Mark Brown9e6e96a2010-01-29 17:47:12 +00002310 default:
2311 return -EINVAL;
2312 }
2313
2314 configure_clock(codec);
2315
2316 return 0;
2317}
2318
2319static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2320 enum snd_soc_bias_level level)
2321{
Mark Brownb6b05692010-08-13 12:58:20 +01002322 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002323 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002324
Mark Brown5f2f38902012-02-08 18:51:42 +00002325 wm_hubs_set_bias_level(codec, level);
2326
Mark Brown9e6e96a2010-01-29 17:47:12 +00002327 switch (level) {
2328 case SND_SOC_BIAS_ON:
2329 break;
2330
2331 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002332 /* MICBIAS into regulating mode */
2333 switch (control->type) {
2334 case WM8958:
2335 case WM1811:
2336 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2337 WM8958_MICB1_MODE, 0);
2338 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2339 WM8958_MICB2_MODE, 0);
2340 break;
2341 default:
2342 break;
2343 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002344
2345 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2346 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002347 break;
2348
2349 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002350 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002351 switch (control->type) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002352 case WM8958:
2353 if (wm8994->revision == 0) {
2354 /* Optimise performance for rev A */
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002355 snd_soc_update_bits(codec,
2356 WM8958_CHARGE_PUMP_2,
2357 WM8958_CP_DISCH,
2358 WM8958_CP_DISCH);
2359 }
2360 break;
Mark Brown81204c82011-05-24 17:35:53 +08002361
Mark Brown462835e2012-01-21 12:11:53 +00002362 default:
Mark Brown81204c82011-05-24 17:35:53 +08002363 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002364 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002365
2366 /* Discharge LINEOUT1 & 2 */
2367 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2368 WM8994_LINEOUT1_DISCH |
2369 WM8994_LINEOUT2_DISCH,
2370 WM8994_LINEOUT1_DISCH |
2371 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002372 }
2373
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002374 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2375 active_dereference(codec);
2376
Mark Brown500fa302011-11-29 19:58:19 +00002377 /* MICBIAS into bypass mode on newer devices */
2378 switch (control->type) {
2379 case WM8958:
2380 case WM1811:
2381 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2382 WM8958_MICB1_MODE,
2383 WM8958_MICB1_MODE);
2384 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2385 WM8958_MICB2_MODE,
2386 WM8958_MICB2_MODE);
2387 break;
2388 default:
2389 break;
2390 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002391 break;
2392
2393 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002394 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002395 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002396 break;
2397 }
Mark Brown5f2f38902012-02-08 18:51:42 +00002398
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002399 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002400
Mark Brown9e6e96a2010-01-29 17:47:12 +00002401 return 0;
2402}
2403
Mark Brown22f8d052012-03-19 17:32:06 +00002404int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2405{
2406 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2407
2408 switch (mode) {
2409 case WM8994_VMID_NORMAL:
2410 if (wm8994->hubs.lineout1_se) {
2411 snd_soc_dapm_disable_pin(&codec->dapm,
2412 "LINEOUT1N Driver");
2413 snd_soc_dapm_disable_pin(&codec->dapm,
2414 "LINEOUT1P Driver");
2415 }
2416 if (wm8994->hubs.lineout2_se) {
2417 snd_soc_dapm_disable_pin(&codec->dapm,
2418 "LINEOUT2N Driver");
2419 snd_soc_dapm_disable_pin(&codec->dapm,
2420 "LINEOUT2P Driver");
2421 }
2422
2423 /* Do the sync with the old mode to allow it to clean up */
2424 snd_soc_dapm_sync(&codec->dapm);
2425 wm8994->vmid_mode = mode;
2426 break;
2427
2428 case WM8994_VMID_FORCE:
2429 if (wm8994->hubs.lineout1_se) {
2430 snd_soc_dapm_force_enable_pin(&codec->dapm,
2431 "LINEOUT1N Driver");
2432 snd_soc_dapm_force_enable_pin(&codec->dapm,
2433 "LINEOUT1P Driver");
2434 }
2435 if (wm8994->hubs.lineout2_se) {
2436 snd_soc_dapm_force_enable_pin(&codec->dapm,
2437 "LINEOUT2N Driver");
2438 snd_soc_dapm_force_enable_pin(&codec->dapm,
2439 "LINEOUT2P Driver");
2440 }
2441
2442 wm8994->vmid_mode = mode;
2443 snd_soc_dapm_sync(&codec->dapm);
2444 break;
2445
2446 default:
2447 return -EINVAL;
2448 }
2449
2450 return 0;
2451}
2452
Mark Brown9e6e96a2010-01-29 17:47:12 +00002453static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2454{
2455 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002456 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2457 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002458 int ms_reg;
2459 int aif1_reg;
2460 int ms = 0;
2461 int aif1 = 0;
2462
2463 switch (dai->id) {
2464 case 1:
2465 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2466 aif1_reg = WM8994_AIF1_CONTROL_1;
2467 break;
2468 case 2:
2469 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2470 aif1_reg = WM8994_AIF2_CONTROL_1;
2471 break;
2472 default:
2473 return -EINVAL;
2474 }
2475
2476 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2477 case SND_SOC_DAIFMT_CBS_CFS:
2478 break;
2479 case SND_SOC_DAIFMT_CBM_CFM:
2480 ms = WM8994_AIF1_MSTR;
2481 break;
2482 default:
2483 return -EINVAL;
2484 }
2485
2486 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2487 case SND_SOC_DAIFMT_DSP_B:
2488 aif1 |= WM8994_AIF1_LRCLK_INV;
2489 case SND_SOC_DAIFMT_DSP_A:
2490 aif1 |= 0x18;
2491 break;
2492 case SND_SOC_DAIFMT_I2S:
2493 aif1 |= 0x10;
2494 break;
2495 case SND_SOC_DAIFMT_RIGHT_J:
2496 break;
2497 case SND_SOC_DAIFMT_LEFT_J:
2498 aif1 |= 0x8;
2499 break;
2500 default:
2501 return -EINVAL;
2502 }
2503
2504 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2505 case SND_SOC_DAIFMT_DSP_A:
2506 case SND_SOC_DAIFMT_DSP_B:
2507 /* frame inversion not valid for DSP modes */
2508 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2509 case SND_SOC_DAIFMT_NB_NF:
2510 break;
2511 case SND_SOC_DAIFMT_IB_NF:
2512 aif1 |= WM8994_AIF1_BCLK_INV;
2513 break;
2514 default:
2515 return -EINVAL;
2516 }
2517 break;
2518
2519 case SND_SOC_DAIFMT_I2S:
2520 case SND_SOC_DAIFMT_RIGHT_J:
2521 case SND_SOC_DAIFMT_LEFT_J:
2522 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2523 case SND_SOC_DAIFMT_NB_NF:
2524 break;
2525 case SND_SOC_DAIFMT_IB_IF:
2526 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2527 break;
2528 case SND_SOC_DAIFMT_IB_NF:
2529 aif1 |= WM8994_AIF1_BCLK_INV;
2530 break;
2531 case SND_SOC_DAIFMT_NB_IF:
2532 aif1 |= WM8994_AIF1_LRCLK_INV;
2533 break;
2534 default:
2535 return -EINVAL;
2536 }
2537 break;
2538 default:
2539 return -EINVAL;
2540 }
2541
Mark Brownc4431df2010-11-26 15:21:07 +00002542 /* The AIF2 format configuration needs to be mirrored to AIF3
2543 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002544 switch (control->type) {
2545 case WM1811:
2546 case WM8958:
2547 if (dai->id == 2)
2548 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2549 WM8994_AIF1_LRCLK_INV |
2550 WM8958_AIF3_FMT_MASK, aif1);
2551 break;
2552
2553 default:
2554 break;
2555 }
Mark Brownc4431df2010-11-26 15:21:07 +00002556
Mark Brown9e6e96a2010-01-29 17:47:12 +00002557 snd_soc_update_bits(codec, aif1_reg,
2558 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2559 WM8994_AIF1_FMT_MASK,
2560 aif1);
2561 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2562 ms);
2563
2564 return 0;
2565}
2566
2567static struct {
2568 int val, rate;
2569} srs[] = {
2570 { 0, 8000 },
2571 { 1, 11025 },
2572 { 2, 12000 },
2573 { 3, 16000 },
2574 { 4, 22050 },
2575 { 5, 24000 },
2576 { 6, 32000 },
2577 { 7, 44100 },
2578 { 8, 48000 },
2579 { 9, 88200 },
2580 { 10, 96000 },
2581};
2582
2583static int fs_ratios[] = {
2584 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2585};
2586
2587static int bclk_divs[] = {
2588 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2589 640, 880, 960, 1280, 1760, 1920
2590};
2591
2592static int wm8994_hw_params(struct snd_pcm_substream *substream,
2593 struct snd_pcm_hw_params *params,
2594 struct snd_soc_dai *dai)
2595{
2596 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002597 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002598 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002599 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002600 int bclk_reg;
2601 int lrclk_reg;
2602 int rate_reg;
2603 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002604 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002605 int bclk = 0;
2606 int lrclk = 0;
2607 int rate_val = 0;
2608 int id = dai->id - 1;
2609
2610 int i, cur_val, best_val, bclk_rate, best;
2611
2612 switch (dai->id) {
2613 case 1:
2614 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002615 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002616 bclk_reg = WM8994_AIF1_BCLK;
2617 rate_reg = WM8994_AIF1_RATE;
2618 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002619 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002620 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002621 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002622 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002623 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2624 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002625 break;
2626 case 2:
2627 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002628 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002629 bclk_reg = WM8994_AIF2_BCLK;
2630 rate_reg = WM8994_AIF2_RATE;
2631 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002632 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002633 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002634 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002635 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002636 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2637 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002638 break;
2639 default:
2640 return -EINVAL;
2641 }
2642
2643 bclk_rate = params_rate(params) * 2;
2644 switch (params_format(params)) {
2645 case SNDRV_PCM_FORMAT_S16_LE:
2646 bclk_rate *= 16;
2647 break;
2648 case SNDRV_PCM_FORMAT_S20_3LE:
2649 bclk_rate *= 20;
2650 aif1 |= 0x20;
2651 break;
2652 case SNDRV_PCM_FORMAT_S24_LE:
2653 bclk_rate *= 24;
2654 aif1 |= 0x40;
2655 break;
2656 case SNDRV_PCM_FORMAT_S32_LE:
2657 bclk_rate *= 32;
2658 aif1 |= 0x60;
2659 break;
2660 default:
2661 return -EINVAL;
2662 }
2663
2664 /* Try to find an appropriate sample rate; look for an exact match. */
2665 for (i = 0; i < ARRAY_SIZE(srs); i++)
2666 if (srs[i].rate == params_rate(params))
2667 break;
2668 if (i == ARRAY_SIZE(srs))
2669 return -EINVAL;
2670 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2671
2672 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2673 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2674 dai->id, wm8994->aifclk[id], bclk_rate);
2675
Mark Brownb1e43d92010-12-07 17:14:56 +00002676 if (params_channels(params) == 1 &&
2677 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2678 aif2 |= WM8994_AIF1_MONO;
2679
Mark Brown9e6e96a2010-01-29 17:47:12 +00002680 if (wm8994->aifclk[id] == 0) {
2681 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2682 return -EINVAL;
2683 }
2684
2685 /* AIFCLK/fs ratio; look for a close match in either direction */
2686 best = 0;
2687 best_val = abs((fs_ratios[0] * params_rate(params))
2688 - wm8994->aifclk[id]);
2689 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2690 cur_val = abs((fs_ratios[i] * params_rate(params))
2691 - wm8994->aifclk[id]);
2692 if (cur_val >= best_val)
2693 continue;
2694 best = i;
2695 best_val = cur_val;
2696 }
2697 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2698 dai->id, fs_ratios[best]);
2699 rate_val |= best;
2700
2701 /* We may not get quite the right frequency if using
2702 * approximate clocks so look for the closest match that is
2703 * higher than the target (we need to ensure that there enough
2704 * BCLKs to clock out the samples).
2705 */
2706 best = 0;
2707 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002708 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002709 if (cur_val < 0) /* BCLK table is sorted */
2710 break;
2711 best = i;
2712 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002713 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002714 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2715 bclk_divs[best], bclk_rate);
2716 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2717
2718 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002719 if (!lrclk) {
2720 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2721 bclk_rate);
2722 return -EINVAL;
2723 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002724 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2725 lrclk, bclk_rate / lrclk);
2726
2727 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002728 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002729 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2730 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2731 lrclk);
2732 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2733 WM8994_AIF1CLK_RATE_MASK, rate_val);
2734
2735 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2736 switch (dai->id) {
2737 case 1:
2738 wm8994->dac_rates[0] = params_rate(params);
2739 wm8994_set_retune_mobile(codec, 0);
2740 wm8994_set_retune_mobile(codec, 1);
2741 break;
2742 case 2:
2743 wm8994->dac_rates[1] = params_rate(params);
2744 wm8994_set_retune_mobile(codec, 2);
2745 break;
2746 }
2747 }
2748
2749 return 0;
2750}
2751
Mark Brownc4431df2010-11-26 15:21:07 +00002752static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2753 struct snd_pcm_hw_params *params,
2754 struct snd_soc_dai *dai)
2755{
2756 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002757 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2758 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002759 int aif1_reg;
2760 int aif1 = 0;
2761
2762 switch (dai->id) {
2763 case 3:
2764 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002765 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002766 case WM8958:
2767 aif1_reg = WM8958_AIF3_CONTROL_1;
2768 break;
2769 default:
2770 return 0;
2771 }
2772 default:
2773 return 0;
2774 }
2775
2776 switch (params_format(params)) {
2777 case SNDRV_PCM_FORMAT_S16_LE:
2778 break;
2779 case SNDRV_PCM_FORMAT_S20_3LE:
2780 aif1 |= 0x20;
2781 break;
2782 case SNDRV_PCM_FORMAT_S24_LE:
2783 aif1 |= 0x40;
2784 break;
2785 case SNDRV_PCM_FORMAT_S32_LE:
2786 aif1 |= 0x60;
2787 break;
2788 default:
2789 return -EINVAL;
2790 }
2791
2792 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2793}
2794
Mark Brown7d021732011-07-14 17:11:38 +09002795static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2796 struct snd_soc_dai *dai)
2797{
2798 struct snd_soc_codec *codec = dai->codec;
2799 int rate_reg = 0;
2800
2801 switch (dai->id) {
2802 case 1:
2803 rate_reg = WM8994_AIF1_RATE;
2804 break;
2805 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002806 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002807 break;
2808 default:
2809 break;
2810 }
2811
2812 /* If the DAI is idle then configure the divider tree for the
2813 * lowest output rate to save a little power if the clock is
2814 * still active (eg, because it is system clock).
2815 */
2816 if (rate_reg && !dai->playback_active && !dai->capture_active)
2817 snd_soc_update_bits(codec, rate_reg,
2818 WM8994_AIF1_SR_MASK |
2819 WM8994_AIF1CLK_RATE_MASK, 0x9);
2820}
2821
Mark Brown9e6e96a2010-01-29 17:47:12 +00002822static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2823{
2824 struct snd_soc_codec *codec = codec_dai->codec;
2825 int mute_reg;
2826 int reg;
2827
2828 switch (codec_dai->id) {
2829 case 1:
2830 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2831 break;
2832 case 2:
2833 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2834 break;
2835 default:
2836 return -EINVAL;
2837 }
2838
2839 if (mute)
2840 reg = WM8994_AIF1DAC1_MUTE;
2841 else
2842 reg = 0;
2843
2844 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2845
2846 return 0;
2847}
2848
Mark Brown778a76e2010-03-22 22:05:10 +00002849static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2850{
2851 struct snd_soc_codec *codec = codec_dai->codec;
2852 int reg, val, mask;
2853
2854 switch (codec_dai->id) {
2855 case 1:
2856 reg = WM8994_AIF1_MASTER_SLAVE;
2857 mask = WM8994_AIF1_TRI;
2858 break;
2859 case 2:
2860 reg = WM8994_AIF2_MASTER_SLAVE;
2861 mask = WM8994_AIF2_TRI;
2862 break;
2863 case 3:
2864 reg = WM8994_POWER_MANAGEMENT_6;
2865 mask = WM8994_AIF3_TRI;
2866 break;
2867 default:
2868 return -EINVAL;
2869 }
2870
2871 if (tristate)
2872 val = mask;
2873 else
2874 val = 0;
2875
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002876 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002877}
2878
Mark Brownd09f3ec2011-08-15 11:01:02 +09002879static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2880{
2881 struct snd_soc_codec *codec = dai->codec;
2882
2883 /* Disable the pulls on the AIF if we're using it to save power. */
2884 snd_soc_update_bits(codec, WM8994_GPIO_3,
2885 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2886 snd_soc_update_bits(codec, WM8994_GPIO_4,
2887 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2888 snd_soc_update_bits(codec, WM8994_GPIO_5,
2889 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2890
2891 return 0;
2892}
2893
Mark Brown9e6e96a2010-01-29 17:47:12 +00002894#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2895
2896#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002897 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002898
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002899static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002900 .set_sysclk = wm8994_set_dai_sysclk,
2901 .set_fmt = wm8994_set_dai_fmt,
2902 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002903 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002904 .digital_mute = wm8994_aif_mute,
2905 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002906 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002907};
2908
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002909static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002910 .set_sysclk = wm8994_set_dai_sysclk,
2911 .set_fmt = wm8994_set_dai_fmt,
2912 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002913 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002914 .digital_mute = wm8994_aif_mute,
2915 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002916 .set_tristate = wm8994_set_tristate,
2917};
2918
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002919static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002920 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002921 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002922};
2923
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002924static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002925 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002926 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002927 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002928 .playback = {
2929 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002930 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002931 .channels_max = 2,
2932 .rates = WM8994_RATES,
2933 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002934 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002935 },
2936 .capture = {
2937 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002938 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002939 .channels_max = 2,
2940 .rates = WM8994_RATES,
2941 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002942 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002943 },
2944 .ops = &wm8994_aif1_dai_ops,
2945 },
2946 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002947 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002948 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002949 .playback = {
2950 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002951 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002952 .channels_max = 2,
2953 .rates = WM8994_RATES,
2954 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002955 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002956 },
2957 .capture = {
2958 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002959 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002960 .channels_max = 2,
2961 .rates = WM8994_RATES,
2962 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002963 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002964 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002965 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002966 .ops = &wm8994_aif2_dai_ops,
2967 },
2968 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002969 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002970 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002971 .playback = {
2972 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002973 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002974 .channels_max = 2,
2975 .rates = WM8994_RATES,
2976 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002977 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002978 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002979 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002980 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002981 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002982 .channels_max = 2,
2983 .rates = WM8994_RATES,
2984 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002985 .sig_bits = 24,
2986 },
Mark Brown778a76e2010-03-22 22:05:10 +00002987 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002988 }
2989};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002990
2991#ifdef CONFIG_PM
Mark Brown4752a882012-03-04 02:16:01 +00002992static int wm8994_codec_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002993{
Mark Brownb2c812e2010-04-14 15:35:19 +09002994 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002995 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002996 int i, ret;
2997
Mark Brownca629922011-05-11 14:34:53 +02002998 switch (control->type) {
2999 case WM8994:
3000 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
3001 break;
Mark Brown81204c82011-05-24 17:35:53 +08003002 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003003 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
3004 WM1811_JACKDET_MODE_MASK, 0);
3005 /* Fall through */
Mark Brownca629922011-05-11 14:34:53 +02003006 case WM8958:
3007 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3008 WM8958_MICD_ENA, 0);
3009 break;
3010 }
3011
Mark Brown9e6e96a2010-01-29 17:47:12 +00003012 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3013 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00003014 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003015 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003016 if (ret < 0)
3017 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
3018 i + 1, ret);
3019 }
3020
3021 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
3022
3023 return 0;
3024}
3025
Mark Brown4752a882012-03-04 02:16:01 +00003026static int wm8994_codec_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003027{
Mark Brownb2c812e2010-04-14 15:35:19 +09003028 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003029 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003030 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003031 unsigned int val, mask;
3032
3033 if (wm8994->revision < 4) {
3034 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01003035 ret = regmap_read(control->regmap,
3036 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003037
3038 /* modify the cache only */
3039 codec->cache_only = 1;
3040 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
3041 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
3042 val &= mask;
3043 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
3044 mask, val);
3045 codec->cache_only = 0;
3046 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003047
Mark Brown9e6e96a2010-01-29 17:47:12 +00003048 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01003049 if (!wm8994->fll_suspend[i].out)
3050 continue;
3051
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003052 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003053 wm8994->fll_suspend[i].src,
3054 wm8994->fll_suspend[i].in,
3055 wm8994->fll_suspend[i].out);
3056 if (ret < 0)
3057 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
3058 i + 1, ret);
3059 }
3060
Mark Brownca629922011-05-11 14:34:53 +02003061 switch (control->type) {
3062 case WM8994:
3063 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3064 snd_soc_update_bits(codec, WM8994_MICBIAS,
3065 WM8994_MICD_ENA, WM8994_MICD_ENA);
3066 break;
Mark Brown81204c82011-05-24 17:35:53 +08003067 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003068 if (wm8994->jackdet && wm8994->jack_cb) {
3069 /* Restart from idle */
3070 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
3071 WM1811_JACKDET_MODE_MASK,
3072 WM1811_JACKDET_MODE_JACK);
3073 break;
3074 }
Mark Brown6f8270c2012-03-03 13:06:25 +00003075 break;
Mark Brownca629922011-05-11 14:34:53 +02003076 case WM8958:
3077 if (wm8994->jack_cb)
3078 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3079 WM8958_MICD_ENA, WM8958_MICD_ENA);
3080 break;
3081 }
3082
Mark Brown9e6e96a2010-01-29 17:47:12 +00003083 return 0;
3084}
3085#else
Mark Brown4752a882012-03-04 02:16:01 +00003086#define wm8994_codec_suspend NULL
3087#define wm8994_codec_resume NULL
Mark Brown9e6e96a2010-01-29 17:47:12 +00003088#endif
3089
3090static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3091{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003092 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003093 struct wm8994_pdata *pdata = wm8994->pdata;
3094 struct snd_kcontrol_new controls[] = {
3095 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3096 wm8994->retune_mobile_enum,
3097 wm8994_get_retune_mobile_enum,
3098 wm8994_put_retune_mobile_enum),
3099 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3100 wm8994->retune_mobile_enum,
3101 wm8994_get_retune_mobile_enum,
3102 wm8994_put_retune_mobile_enum),
3103 SOC_ENUM_EXT("AIF2 EQ Mode",
3104 wm8994->retune_mobile_enum,
3105 wm8994_get_retune_mobile_enum,
3106 wm8994_put_retune_mobile_enum),
3107 };
3108 int ret, i, j;
3109 const char **t;
3110
3111 /* We need an array of texts for the enum API but the number
3112 * of texts is likely to be less than the number of
3113 * configurations due to the sample rate dependency of the
3114 * configurations. */
3115 wm8994->num_retune_mobile_texts = 0;
3116 wm8994->retune_mobile_texts = NULL;
3117 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3118 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3119 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3120 wm8994->retune_mobile_texts[j]) == 0)
3121 break;
3122 }
3123
3124 if (j != wm8994->num_retune_mobile_texts)
3125 continue;
3126
3127 /* Expand the array... */
3128 t = krealloc(wm8994->retune_mobile_texts,
3129 sizeof(char *) *
3130 (wm8994->num_retune_mobile_texts + 1),
3131 GFP_KERNEL);
3132 if (t == NULL)
3133 continue;
3134
3135 /* ...store the new entry... */
3136 t[wm8994->num_retune_mobile_texts] =
3137 pdata->retune_mobile_cfgs[i].name;
3138
3139 /* ...and remember the new version. */
3140 wm8994->num_retune_mobile_texts++;
3141 wm8994->retune_mobile_texts = t;
3142 }
3143
3144 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
3145 wm8994->num_retune_mobile_texts);
3146
3147 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
3148 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3149
Liam Girdwood022658b2012-02-03 17:43:09 +00003150 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003151 ARRAY_SIZE(controls));
3152 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003153 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003154 "Failed to add ReTune Mobile controls: %d\n", ret);
3155}
3156
3157static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3158{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003159 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003160 struct wm8994_pdata *pdata = wm8994->pdata;
3161 int ret, i;
3162
3163 if (!pdata)
3164 return;
3165
3166 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
3167 pdata->lineout2_diff,
3168 pdata->lineout1fb,
3169 pdata->lineout2fb,
3170 pdata->jd_scthr,
3171 pdata->jd_thr,
3172 pdata->micbias1_lvl,
3173 pdata->micbias2_lvl);
3174
3175 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3176
3177 if (pdata->num_drc_cfgs) {
3178 struct snd_kcontrol_new controls[] = {
3179 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3180 wm8994_get_drc_enum, wm8994_put_drc_enum),
3181 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3182 wm8994_get_drc_enum, wm8994_put_drc_enum),
3183 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3184 wm8994_get_drc_enum, wm8994_put_drc_enum),
3185 };
3186
3187 /* We need an array of texts for the enum API */
Mark Brown7270ceb2011-12-01 14:00:19 +00003188 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
3189 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003190 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003191 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003192 "Failed to allocate %d DRC config texts\n",
3193 pdata->num_drc_cfgs);
3194 return;
3195 }
3196
3197 for (i = 0; i < pdata->num_drc_cfgs; i++)
3198 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3199
3200 wm8994->drc_enum.max = pdata->num_drc_cfgs;
3201 wm8994->drc_enum.texts = wm8994->drc_texts;
3202
Liam Girdwood022658b2012-02-03 17:43:09 +00003203 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003204 ARRAY_SIZE(controls));
3205 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003206 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003207 "Failed to add DRC mode controls: %d\n", ret);
3208
3209 for (i = 0; i < WM8994_NUM_DRC; i++)
3210 wm8994_set_drc(codec, i);
3211 }
3212
3213 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
3214 pdata->num_retune_mobile_cfgs);
3215
3216 if (pdata->num_retune_mobile_cfgs)
3217 wm8994_handle_retune_mobile_pdata(wm8994);
3218 else
Liam Girdwood022658b2012-02-03 17:43:09 +00003219 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003220 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08003221
3222 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3223 if (pdata->micbias[i]) {
3224 snd_soc_write(codec, WM8958_MICBIAS1 + i,
3225 pdata->micbias[i] & 0xffff);
3226 }
3227 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003228}
3229
Mark Brown88766982010-03-29 20:57:12 +01003230/**
3231 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3232 *
3233 * @codec: WM8994 codec
3234 * @jack: jack to report detection events on
3235 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01003236 *
3237 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3238 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01003239 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01003240 * be configured using snd_soc_jack_add_gpios() instead.
3241 *
3242 * Configuration of detection levels is available via the micbias1_lvl
3243 * and micbias2_lvl platform data members.
3244 */
3245int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00003246 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01003247{
Mark Brownb2c812e2010-04-14 15:35:19 +09003248 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01003249 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01003250 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00003251 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01003252
Mark Brown87092e32012-02-06 18:50:39 +00003253 if (control->type != WM8994) {
3254 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003255 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003256 }
Mark Brown3a423152010-11-26 15:21:06 +00003257
Mark Brown88766982010-03-29 20:57:12 +01003258 switch (micbias) {
3259 case 1:
3260 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003261 if (jack)
3262 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3263 "MICBIAS1");
3264 else
3265 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3266 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003267 break;
3268 case 2:
3269 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003270 if (jack)
3271 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3272 "MICBIAS1");
3273 else
3274 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3275 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003276 break;
3277 default:
Mark Brown87092e32012-02-06 18:50:39 +00003278 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003279 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003280 }
Mark Brown88766982010-03-29 20:57:12 +01003281
Mark Brown87092e32012-02-06 18:50:39 +00003282 if (ret != 0)
3283 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3284 micbias, ret);
3285
3286 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3287 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003288
3289 /* Store the configuration */
3290 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003291 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003292
3293 /* If either of the jacks is set up then enable detection */
3294 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3295 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003296 else
Mark Brown88766982010-03-29 20:57:12 +01003297 reg = 0;
3298
3299 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3300
Mark Brown87092e32012-02-06 18:50:39 +00003301 snd_soc_dapm_sync(&codec->dapm);
3302
Mark Brown88766982010-03-29 20:57:12 +01003303 return 0;
3304}
3305EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3306
3307static irqreturn_t wm8994_mic_irq(int irq, void *data)
3308{
3309 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003310 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01003311 int reg;
3312 int report;
3313
Mark Brown7116f452010-12-29 13:05:21 +00003314#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003315 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003316#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003317
Mark Brown88766982010-03-29 20:57:12 +01003318 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3319 if (reg < 0) {
3320 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3321 reg);
3322 return IRQ_HANDLED;
3323 }
3324
3325 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
3326
3327 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003328 if (reg & WM8994_MIC1_DET_STS) {
3329 if (priv->micdet[0].detecting)
3330 report = SND_JACK_HEADSET;
3331 }
3332 if (reg & WM8994_MIC1_SHRT_STS) {
3333 if (priv->micdet[0].detecting)
3334 report = SND_JACK_HEADPHONE;
3335 else
3336 report |= SND_JACK_BTN_0;
3337 }
3338 if (report)
3339 priv->micdet[0].detecting = false;
3340 else
3341 priv->micdet[0].detecting = true;
3342
Mark Brown88766982010-03-29 20:57:12 +01003343 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003344 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003345
3346 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003347 if (reg & WM8994_MIC2_DET_STS) {
3348 if (priv->micdet[1].detecting)
3349 report = SND_JACK_HEADSET;
3350 }
3351 if (reg & WM8994_MIC2_SHRT_STS) {
3352 if (priv->micdet[1].detecting)
3353 report = SND_JACK_HEADPHONE;
3354 else
3355 report |= SND_JACK_BTN_0;
3356 }
3357 if (report)
3358 priv->micdet[1].detecting = false;
3359 else
3360 priv->micdet[1].detecting = true;
3361
Mark Brown88766982010-03-29 20:57:12 +01003362 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003363 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003364
3365 return IRQ_HANDLED;
3366}
3367
Mark Brown821edd22010-11-26 15:21:09 +00003368/* Default microphone detection handler for WM8958 - the user can
3369 * override this if they wish.
3370 */
3371static void wm8958_default_micdet(u16 status, void *data)
3372{
3373 struct snd_soc_codec *codec = data;
3374 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003375 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003376
Mark Browna1691342011-11-30 14:56:40 +00003377 dev_dbg(codec->dev, "MICDET %x\n", status);
3378
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003379 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003380 if (!(status & WM8958_MICD_STS)) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003381 if (!wm8994->jackdet) {
3382 /* If nothing present then clear our statuses */
3383 dev_dbg(codec->dev, "Detected open circuit\n");
3384 wm8994->jack_mic = false;
3385 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003386
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003387 wm8958_micd_set_rate(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003388
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003389 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3390 wm8994->btn_mask |
3391 SND_JACK_HEADSET);
3392 }
Mark Brownb00adf72011-08-13 11:57:18 +09003393 return;
3394 }
3395
3396 /* If the measurement is showing a high impedence we've got a
3397 * microphone.
3398 */
Mark Brown157a75e2011-11-30 13:43:51 +00003399 if (wm8994->mic_detecting && (status & 0x600)) {
Mark Brownb00adf72011-08-13 11:57:18 +09003400 dev_dbg(codec->dev, "Detected microphone\n");
3401
Mark Brown157a75e2011-11-30 13:43:51 +00003402 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003403 wm8994->jack_mic = true;
3404
3405 wm8958_micd_set_rate(codec);
3406
3407 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3408 SND_JACK_HEADSET);
3409 }
3410
3411
Mark Brown7c08b512012-01-26 18:33:24 +00003412 if (wm8994->mic_detecting && status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003413 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003414 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003415
3416 wm8958_micd_set_rate(codec);
3417
3418 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3419 SND_JACK_HEADSET);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003420
3421 /* If we have jackdet that will detect removal */
3422 if (wm8994->jackdet) {
Mark Brownc9865642012-03-12 16:31:50 +00003423 mutex_lock(&wm8994->accdet_lock);
3424
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003425 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3426 WM8958_MICD_ENA, 0);
3427
Mark Brownc9865642012-03-12 16:31:50 +00003428 wm1811_jackdet_set_mode(codec,
3429 WM1811_JACKDET_MODE_JACK);
3430
3431 mutex_unlock(&wm8994->accdet_lock);
3432
Mark Brown07fb9d92012-02-21 16:23:35 +00003433 if (wm8994->pdata->jd_ext_cap) {
3434 mutex_lock(&codec->mutex);
3435 snd_soc_dapm_disable_pin(&codec->dapm,
3436 "MICBIAS2");
3437 snd_soc_dapm_sync(&codec->dapm);
3438 mutex_unlock(&codec->mutex);
3439 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003440 }
Mark Brownb00adf72011-08-13 11:57:18 +09003441 }
3442
3443 /* Report short circuit as a button */
3444 if (wm8994->jack_mic) {
Mark Brown4585790d2011-11-30 10:55:14 +00003445 report = 0;
Mark Brownb00adf72011-08-13 11:57:18 +09003446 if (status & 0x4)
Mark Brown4585790d2011-11-30 10:55:14 +00003447 report |= SND_JACK_BTN_0;
3448
3449 if (status & 0x8)
3450 report |= SND_JACK_BTN_1;
3451
3452 if (status & 0x10)
3453 report |= SND_JACK_BTN_2;
3454
3455 if (status & 0x20)
3456 report |= SND_JACK_BTN_3;
3457
3458 if (status & 0x40)
3459 report |= SND_JACK_BTN_4;
3460
3461 if (status & 0x80)
3462 report |= SND_JACK_BTN_5;
3463
3464 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3465 wm8994->btn_mask);
Mark Brownb00adf72011-08-13 11:57:18 +09003466 }
Mark Brown821edd22010-11-26 15:21:09 +00003467}
3468
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003469static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3470{
3471 struct wm8994_priv *wm8994 = data;
3472 struct snd_soc_codec *codec = wm8994->codec;
3473 int reg;
Mark Brownc9865642012-03-12 16:31:50 +00003474 bool present;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003475
3476 mutex_lock(&wm8994->accdet_lock);
3477
3478 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3479 if (reg < 0) {
3480 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3481 mutex_unlock(&wm8994->accdet_lock);
3482 return IRQ_NONE;
3483 }
3484
3485 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3486
Mark Brownc9865642012-03-12 16:31:50 +00003487 present = reg & WM1811_JACKDET_LVL;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003488
Mark Brownc9865642012-03-12 16:31:50 +00003489 if (present) {
3490 dev_dbg(codec->dev, "Jack detected\n");
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003491
Mark Brown55a27782012-02-21 13:45:53 +00003492 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3493 WM8958_MICB2_DISCH, 0);
3494
Mark Brown378ec0c2012-03-01 19:01:43 +00003495 /* Disable debounce while inserted */
3496 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3497 WM1811_JACKDET_DB, 0);
3498
Mark Brownb9e67e52012-02-28 19:03:37 +00003499 /*
3500 * Start off measument of microphone impedence to find
3501 * out what's actually there.
3502 */
3503 wm8994->mic_detecting = true;
3504 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3505
3506 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3507 WM8958_MICD_ENA, WM8958_MICD_ENA);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003508 } else {
3509 dev_dbg(codec->dev, "Jack not detected\n");
3510
Mark Brown55a27782012-02-21 13:45:53 +00003511 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3512 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3513
Mark Brown378ec0c2012-03-01 19:01:43 +00003514 /* Enable debounce while removed */
3515 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3516 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3517
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003518 wm8994->mic_detecting = false;
3519 wm8994->jack_mic = false;
3520 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3521 WM8958_MICD_ENA, 0);
3522 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3523 }
3524
3525 mutex_unlock(&wm8994->accdet_lock);
3526
Mark Brownc9865642012-03-12 16:31:50 +00003527 /* If required for an external cap force MICBIAS on */
3528 if (wm8994->pdata->jd_ext_cap) {
3529 mutex_lock(&codec->mutex);
3530
3531 if (present)
3532 snd_soc_dapm_force_enable_pin(&codec->dapm,
3533 "MICBIAS2");
3534 else
3535 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3536
3537 snd_soc_dapm_sync(&codec->dapm);
3538 mutex_unlock(&codec->mutex);
3539 }
3540
3541 if (present)
3542 snd_soc_jack_report(wm8994->micdet[0].jack,
3543 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3544 else
3545 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3546 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3547 wm8994->btn_mask);
3548
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003549 return IRQ_HANDLED;
3550}
3551
Mark Brown821edd22010-11-26 15:21:09 +00003552/**
3553 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3554 *
3555 * @codec: WM8958 codec
3556 * @jack: jack to report detection events on
3557 *
3558 * Enable microphone detection functionality for the WM8958. By
3559 * default simple detection which supports the detection of up to 6
3560 * buttons plus video and microphone functionality is supported.
3561 *
3562 * The WM8958 has an advanced jack detection facility which is able to
3563 * support complex accessory detection, especially when used in
3564 * conjunction with external circuitry. In order to provide maximum
3565 * flexiblity a callback is provided which allows a completely custom
3566 * detection algorithm.
3567 */
3568int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3569 wm8958_micdet_cb cb, void *cb_data)
3570{
3571 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003572 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003573 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003574
Mark Brown81204c82011-05-24 17:35:53 +08003575 switch (control->type) {
3576 case WM1811:
3577 case WM8958:
3578 break;
3579 default:
Mark Brown821edd22010-11-26 15:21:09 +00003580 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003581 }
Mark Brown821edd22010-11-26 15:21:09 +00003582
3583 if (jack) {
3584 if (!cb) {
3585 dev_dbg(codec->dev, "Using default micdet callback\n");
3586 cb = wm8958_default_micdet;
3587 cb_data = codec;
3588 }
3589
Mark Brown4cdf5e42011-11-29 14:36:17 +00003590 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003591 snd_soc_dapm_sync(&codec->dapm);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003592
Mark Brown821edd22010-11-26 15:21:09 +00003593 wm8994->micdet[0].jack = jack;
3594 wm8994->jack_cb = cb;
3595 wm8994->jack_cb_data = cb_data;
3596
Mark Brown157a75e2011-11-30 13:43:51 +00003597 wm8994->mic_detecting = true;
Mark Brownb00adf72011-08-13 11:57:18 +09003598 wm8994->jack_mic = false;
3599
3600 wm8958_micd_set_rate(codec);
3601
Mark Brown4585790d2011-11-30 10:55:14 +00003602 /* Detect microphones and short circuits by default */
3603 if (wm8994->pdata->micd_lvl_sel)
3604 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3605 else
3606 micd_lvl_sel = 0x41;
3607
3608 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3609 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3610 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3611
Mark Brownb00adf72011-08-13 11:57:18 +09003612 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003613 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003614
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003615 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3616
3617 /*
3618 * If we can use jack detection start off with that,
3619 * otherwise jump straight to microphone detection.
3620 */
3621 if (wm8994->jackdet) {
Mark Brown55a27782012-02-21 13:45:53 +00003622 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3623 WM8958_MICB2_DISCH,
3624 WM8958_MICB2_DISCH);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003625 snd_soc_update_bits(codec, WM8994_LDO_1,
3626 WM8994_LDO1_DISCH, 0);
3627 wm1811_jackdet_set_mode(codec,
3628 WM1811_JACKDET_MODE_JACK);
3629 } else {
3630 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3631 WM8958_MICD_ENA, WM8958_MICD_ENA);
3632 }
3633
Mark Brown821edd22010-11-26 15:21:09 +00003634 } else {
3635 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3636 WM8958_MICD_ENA, 0);
Mark Brownafaf1592012-03-03 18:46:36 +00003637 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003638 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003639 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003640 }
3641
3642 return 0;
3643}
3644EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3645
3646static irqreturn_t wm8958_mic_irq(int irq, void *data)
3647{
3648 struct wm8994_priv *wm8994 = data;
3649 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003650 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003651
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003652 /*
3653 * Jack detection may have detected a removal simulataneously
3654 * with an update of the MICDET status; if so it will have
3655 * stopped detection and we can ignore this interrupt.
3656 */
Mark Brownc9865642012-03-12 16:31:50 +00003657 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003658 return IRQ_HANDLED;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003659
Mark Brown19940b32011-08-19 18:05:05 +09003660 /* We may occasionally read a detection without an impedence
3661 * range being provided - if that happens loop again.
3662 */
3663 count = 10;
3664 do {
3665 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3666 if (reg < 0) {
3667 dev_err(codec->dev,
3668 "Failed to read mic detect status: %d\n",
3669 reg);
3670 return IRQ_NONE;
3671 }
Mark Brown821edd22010-11-26 15:21:09 +00003672
Mark Brown19940b32011-08-19 18:05:05 +09003673 if (!(reg & WM8958_MICD_VALID)) {
3674 dev_dbg(codec->dev, "Mic detect data not valid\n");
3675 goto out;
3676 }
3677
3678 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3679 break;
3680
3681 msleep(1);
3682 } while (count--);
3683
3684 if (count == 0)
3685 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003686
Mark Brown7116f452010-12-29 13:05:21 +00003687#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003688 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003689#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003690
Mark Brown821edd22010-11-26 15:21:09 +00003691 if (wm8994->jack_cb)
3692 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3693 else
3694 dev_warn(codec->dev, "Accessory detection with no callback\n");
3695
3696out:
3697 return IRQ_HANDLED;
3698}
3699
Mark Brown3b1af3f2011-07-14 12:38:18 +09003700static irqreturn_t wm8994_fifo_error(int irq, void *data)
3701{
3702 struct snd_soc_codec *codec = data;
3703
3704 dev_err(codec->dev, "FIFO error\n");
3705
3706 return IRQ_HANDLED;
3707}
3708
Mark Brownf0b182b2011-08-16 12:01:27 +09003709static irqreturn_t wm8994_temp_warn(int irq, void *data)
3710{
3711 struct snd_soc_codec *codec = data;
3712
3713 dev_err(codec->dev, "Thermal warning\n");
3714
3715 return IRQ_HANDLED;
3716}
3717
3718static irqreturn_t wm8994_temp_shut(int irq, void *data)
3719{
3720 struct snd_soc_codec *codec = data;
3721
3722 dev_crit(codec->dev, "Thermal shutdown\n");
3723
3724 return IRQ_HANDLED;
3725}
3726
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003727static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003728{
Mark Brownd9a76662011-07-24 12:49:52 +01003729 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00003730 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003731 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003732 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003733 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003734
Mark Brown2bc16ed2012-03-03 23:24:39 +00003735 wm8994->codec = codec;
Mark Brownd9a76662011-07-24 12:49:52 +01003736 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003737
Mark Brownd9a76662011-07-24 12:49:52 +01003738 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003739
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003740 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003741
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003742 mutex_init(&wm8994->accdet_lock);
3743
Mark Brownc7ebf932011-07-12 19:47:59 +09003744 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3745 init_completion(&wm8994->fll_locked[i]);
3746
Mark Brown9b7c5252011-02-17 20:05:44 -08003747 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3748 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3749 else if (wm8994->pdata && wm8994->pdata->irq_base)
3750 wm8994->micdet_irq = wm8994->pdata->irq_base +
3751 WM8994_IRQ_MIC1_DET;
3752
Mark Brown39fb51a2010-11-26 17:23:43 +00003753 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003754 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003755
Mark Brownf959dee2012-01-31 16:16:47 +00003756 /* By default use idle_bias_off, will override for WM8994 */
3757 codec->dapm.idle_bias_off = 1;
3758
Mark Brown9e6e96a2010-01-29 17:47:12 +00003759 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003760 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003761 switch (control->type) {
3762 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003763 /* Single ended line outputs should have VMID on. */
3764 if (!wm8994->pdata->lineout1_diff ||
3765 !wm8994->pdata->lineout2_diff)
3766 codec->dapm.idle_bias_off = 0;
3767
Mark Brown3a423152010-11-26 15:21:06 +00003768 switch (wm8994->revision) {
3769 case 2:
3770 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003771 wm8994->hubs.dcs_codes_l = -5;
3772 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003773 wm8994->hubs.hp_startup_mode = 1;
3774 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003775 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003776 break;
3777 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003778 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003779 break;
3780 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003781 break;
Mark Brown3a423152010-11-26 15:21:06 +00003782
3783 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003784 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003785 wm8994->hubs.hp_startup_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003786 break;
Mark Brown3a423152010-11-26 15:21:06 +00003787
Mark Brown81204c82011-05-24 17:35:53 +08003788 case WM1811:
3789 wm8994->hubs.dcs_readback_mode = 2;
3790 wm8994->hubs.no_series_update = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003791 wm8994->hubs.hp_startup_mode = 1;
Mark Brown67109cb2012-02-29 16:40:08 +00003792 wm8994->hubs.no_cache_class_w = true;
Mark Brown81204c82011-05-24 17:35:53 +08003793
3794 switch (wm8994->revision) {
3795 case 0:
3796 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003797 case 2:
3798 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003799 wm8994->hubs.dcs_codes_l = -9;
Mark Browne1660582012-03-21 13:22:40 +00003800 wm8994->hubs.dcs_codes_r = -7;
Mark Brown81204c82011-05-24 17:35:53 +08003801 break;
3802 default:
3803 break;
3804 }
3805
3806 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3807 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3808 break;
3809
Mark Brown9e6e96a2010-01-29 17:47:12 +00003810 default:
3811 break;
3812 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003813
Mark Brown2a8a8562011-07-24 12:20:41 +01003814 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003815 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003816 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003817 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003818 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003819 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003820
Mark Brown2a8a8562011-07-24 12:20:41 +01003821 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003822 wm_hubs_dcs_done, "DC servo done",
3823 &wm8994->hubs);
3824 if (ret == 0)
3825 wm8994->hubs.dcs_done_irq = true;
3826
Mark Brown3a423152010-11-26 15:21:06 +00003827 switch (control->type) {
3828 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003829 if (wm8994->micdet_irq) {
3830 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3831 wm8994_mic_irq,
3832 IRQF_TRIGGER_RISING,
3833 "Mic1 detect",
3834 wm8994);
3835 if (ret != 0)
3836 dev_warn(codec->dev,
3837 "Failed to request Mic1 detect IRQ: %d\n",
3838 ret);
3839 }
Mark Brown88766982010-03-29 20:57:12 +01003840
Mark Brown2a8a8562011-07-24 12:20:41 +01003841 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003842 WM8994_IRQ_MIC1_SHRT,
3843 wm8994_mic_irq, "Mic 1 short",
3844 wm8994);
3845 if (ret != 0)
3846 dev_warn(codec->dev,
3847 "Failed to request Mic1 short IRQ: %d\n",
3848 ret);
Mark Brown88766982010-03-29 20:57:12 +01003849
Mark Brown2a8a8562011-07-24 12:20:41 +01003850 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003851 WM8994_IRQ_MIC2_DET,
3852 wm8994_mic_irq, "Mic 2 detect",
3853 wm8994);
3854 if (ret != 0)
3855 dev_warn(codec->dev,
3856 "Failed to request Mic2 detect IRQ: %d\n",
3857 ret);
Mark Brown88766982010-03-29 20:57:12 +01003858
Mark Brown2a8a8562011-07-24 12:20:41 +01003859 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003860 WM8994_IRQ_MIC2_SHRT,
3861 wm8994_mic_irq, "Mic 2 short",
3862 wm8994);
3863 if (ret != 0)
3864 dev_warn(codec->dev,
3865 "Failed to request Mic2 short IRQ: %d\n",
3866 ret);
3867 break;
Mark Brown821edd22010-11-26 15:21:09 +00003868
3869 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003870 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003871 if (wm8994->micdet_irq) {
3872 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3873 wm8958_mic_irq,
3874 IRQF_TRIGGER_RISING,
3875 "Mic detect",
3876 wm8994);
3877 if (ret != 0)
3878 dev_warn(codec->dev,
3879 "Failed to request Mic detect IRQ: %d\n",
3880 ret);
3881 }
Mark Brown3a423152010-11-26 15:21:06 +00003882 }
Mark Brown88766982010-03-29 20:57:12 +01003883
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003884 switch (control->type) {
3885 case WM1811:
3886 if (wm8994->revision > 1) {
3887 ret = wm8994_request_irq(wm8994->wm8994,
3888 WM8994_IRQ_GPIO(6),
3889 wm1811_jackdet_irq, "JACKDET",
3890 wm8994);
3891 if (ret == 0)
3892 wm8994->jackdet = true;
3893 }
3894 break;
3895 default:
3896 break;
3897 }
3898
Mark Brownc7ebf932011-07-12 19:47:59 +09003899 wm8994->fll_locked_irq = true;
3900 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01003901 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09003902 WM8994_IRQ_FLL1_LOCK + i,
3903 wm8994_fll_locked_irq, "FLL lock",
3904 &wm8994->fll_locked[i]);
3905 if (ret != 0)
3906 wm8994->fll_locked_irq = false;
3907 }
3908
Mark Brown27060b3c2012-02-06 18:42:14 +00003909 /* Make sure we can read from the GPIOs if they're inputs */
3910 pm_runtime_get_sync(codec->dev);
3911
Mark Brown9e6e96a2010-01-29 17:47:12 +00003912 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3913 * configured on init - if a system wants to do this dynamically
3914 * at runtime we can deal with that then.
3915 */
Mark Brownd9a76662011-07-24 12:49:52 +01003916 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003917 if (ret < 0) {
3918 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003919 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003920 }
Mark Brownd9a76662011-07-24 12:49:52 +01003921 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003922 wm8994->lrclk_shared[0] = 1;
3923 wm8994_dai[0].symmetric_rates = 1;
3924 } else {
3925 wm8994->lrclk_shared[0] = 0;
3926 }
3927
Mark Brownd9a76662011-07-24 12:49:52 +01003928 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003929 if (ret < 0) {
3930 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003931 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003932 }
Mark Brownd9a76662011-07-24 12:49:52 +01003933 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003934 wm8994->lrclk_shared[1] = 1;
3935 wm8994_dai[1].symmetric_rates = 1;
3936 } else {
3937 wm8994->lrclk_shared[1] = 0;
3938 }
3939
Mark Brown27060b3c2012-02-06 18:42:14 +00003940 pm_runtime_put(codec->dev);
3941
Mark Brown9e6e96a2010-01-29 17:47:12 +00003942 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003943 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3944 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003945 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3946 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003947 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3948 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003949 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3950 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003951 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3952 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003953 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3954 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003955 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3956 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003957 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3958 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003959 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3960 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003961 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3962 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003963 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3964 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003965 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3966 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003967 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3968 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003969 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3970 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003971 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3972 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003973 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3974 WM8994_DAC2_VU, WM8994_DAC2_VU);
3975
3976 /* Set the low bit of the 3D stereo depth so TLV matches */
3977 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3978 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3979 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3980 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3981 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3982 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3983 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3984 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3985 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3986
Mark Brown5b739672011-07-06 00:08:43 -07003987 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3988 * use this; it only affects behaviour on idle TDM clock
3989 * cycles. */
3990 switch (control->type) {
3991 case WM8994:
3992 case WM8958:
3993 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3994 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3995 break;
3996 default:
3997 break;
3998 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003999
Mark Brown500fa302011-11-29 19:58:19 +00004000 /* Put MICBIAS into bypass mode by default on newer devices */
4001 switch (control->type) {
4002 case WM8958:
4003 case WM1811:
4004 snd_soc_update_bits(codec, WM8958_MICBIAS1,
4005 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
4006 snd_soc_update_bits(codec, WM8958_MICBIAS2,
4007 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
4008 break;
4009 default:
4010 break;
4011 }
4012
Mark Brown9e6e96a2010-01-29 17:47:12 +00004013 wm8994_update_class_w(codec);
4014
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004015 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004016
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004017 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00004018 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004019 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004020 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004021 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00004022
4023 switch (control->type) {
4024 case WM8994:
4025 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
4026 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004027 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004028 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4029 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004030 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4031 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004032 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4033 ARRAY_SIZE(wm8994_dac_revd_widgets));
4034 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004035 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4036 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004037 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4038 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004039 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4040 ARRAY_SIZE(wm8994_dac_widgets));
4041 }
Mark Brownc4431df2010-11-26 15:21:07 +00004042 break;
4043 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00004044 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00004045 ARRAY_SIZE(wm8958_snd_controls));
4046 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4047 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00004048 if (wm8994->revision < 1) {
4049 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4050 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4051 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4052 ARRAY_SIZE(wm8994_adc_revd_widgets));
4053 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4054 ARRAY_SIZE(wm8994_dac_revd_widgets));
4055 } else {
4056 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4057 ARRAY_SIZE(wm8994_lateclk_widgets));
4058 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4059 ARRAY_SIZE(wm8994_adc_widgets));
4060 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4061 ARRAY_SIZE(wm8994_dac_widgets));
4062 }
Mark Brownc4431df2010-11-26 15:21:07 +00004063 break;
Mark Brown81204c82011-05-24 17:35:53 +08004064
4065 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00004066 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08004067 ARRAY_SIZE(wm8958_snd_controls));
4068 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4069 ARRAY_SIZE(wm8958_dapm_widgets));
4070 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4071 ARRAY_SIZE(wm8994_lateclk_widgets));
4072 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4073 ARRAY_SIZE(wm8994_adc_widgets));
4074 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4075 ARRAY_SIZE(wm8994_dac_widgets));
4076 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004077 }
4078
4079
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004080 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004081 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00004082
Mark Brownc4431df2010-11-26 15:21:07 +00004083 switch (control->type) {
4084 case WM8994:
4085 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4086 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00004087
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004088 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00004089 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4090 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004091 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4092 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4093 } else {
4094 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4095 ARRAY_SIZE(wm8994_lateclk_intercon));
4096 }
Mark Brownc4431df2010-11-26 15:21:07 +00004097 break;
4098 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00004099 if (wm8994->revision < 1) {
4100 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4101 ARRAY_SIZE(wm8994_revd_intercon));
4102 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4103 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4104 } else {
4105 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4106 ARRAY_SIZE(wm8994_lateclk_intercon));
4107 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4108 ARRAY_SIZE(wm8958_intercon));
4109 }
Mark Brownf701a2e2011-03-09 19:31:01 +00004110
4111 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00004112 break;
Mark Brown81204c82011-05-24 17:35:53 +08004113 case WM1811:
4114 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4115 ARRAY_SIZE(wm8994_lateclk_intercon));
4116 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4117 ARRAY_SIZE(wm8958_intercon));
4118 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004119 }
4120
Mark Brown9e6e96a2010-01-29 17:47:12 +00004121 return 0;
4122
Mark Brown88766982010-03-29 20:57:12 +01004123err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004124 if (wm8994->jackdet)
4125 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004126 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4127 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4128 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08004129 if (wm8994->micdet_irq)
4130 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09004131 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004132 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004133 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01004134 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004135 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004136 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4137 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4138 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00004139
Mark Brown9e6e96a2010-01-29 17:47:12 +00004140 return ret;
4141}
4142
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004143static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00004144{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004145 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01004146 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09004147 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004148
4149 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004150
Mark Brown39fb51a2010-11-26 17:23:43 +00004151 pm_runtime_disable(codec->dev);
4152
Mark Brownc7ebf932011-07-12 19:47:59 +09004153 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004154 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004155 &wm8994->fll_locked[i]);
4156
Mark Brown2a8a8562011-07-24 12:20:41 +01004157 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004158 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004159 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4160 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4161 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09004162
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004163 if (wm8994->jackdet)
4164 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4165
Mark Brown3a423152010-11-26 15:21:06 +00004166 switch (control->type) {
4167 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08004168 if (wm8994->micdet_irq)
4169 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004170 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004171 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004172 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00004173 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004174 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004175 wm8994);
4176 break;
Mark Brown821edd22010-11-26 15:21:09 +00004177
Mark Brown81204c82011-05-24 17:35:53 +08004178 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00004179 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08004180 if (wm8994->micdet_irq)
4181 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00004182 break;
Mark Brown3a423152010-11-26 15:21:06 +00004183 }
Mark Brownfbbf5922011-03-11 18:09:04 +00004184 if (wm8994->mbc)
4185 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00004186 if (wm8994->mbc_vss)
4187 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00004188 if (wm8994->enh_eq)
4189 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08004190 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004191
4192 return 0;
4193}
4194
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004195static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4196 .probe = wm8994_codec_probe,
4197 .remove = wm8994_codec_remove,
Mark Brown4752a882012-03-04 02:16:01 +00004198 .suspend = wm8994_codec_suspend,
4199 .resume = wm8994_codec_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004200 .set_bias_level = wm8994_set_bias_level,
4201};
4202
4203static int __devinit wm8994_probe(struct platform_device *pdev)
4204{
Mark Brown2bc16ed2012-03-03 23:24:39 +00004205 struct wm8994_priv *wm8994;
4206
4207 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4208 GFP_KERNEL);
4209 if (wm8994 == NULL)
4210 return -ENOMEM;
4211 platform_set_drvdata(pdev, wm8994);
4212
4213 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
4214 wm8994->pdata = dev_get_platdata(pdev->dev.parent);
4215
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004216 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
4217 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4218}
4219
4220static int __devexit wm8994_remove(struct platform_device *pdev)
4221{
4222 snd_soc_unregister_codec(&pdev->dev);
4223 return 0;
4224}
4225
Mark Brown4752a882012-03-04 02:16:01 +00004226#ifdef CONFIG_PM_SLEEP
4227static int wm8994_suspend(struct device *dev)
4228{
4229 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4230
4231 /* Drop down to power saving mode when system is suspended */
4232 if (wm8994->jackdet && !wm8994->active_refcount)
4233 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4234 WM1811_JACKDET_MODE_MASK,
4235 wm8994->jackdet_mode);
4236
4237 return 0;
4238}
4239
4240static int wm8994_resume(struct device *dev)
4241{
4242 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4243
4244 if (wm8994->jackdet && wm8994->jack_cb)
4245 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4246 WM1811_JACKDET_MODE_MASK,
4247 WM1811_JACKDET_MODE_AUDIO);
4248
4249 return 0;
4250}
4251#endif
4252
4253static const struct dev_pm_ops wm8994_pm_ops = {
4254 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4255};
4256
Mark Brown9e6e96a2010-01-29 17:47:12 +00004257static struct platform_driver wm8994_codec_driver = {
4258 .driver = {
Mark Brown4752a882012-03-04 02:16:01 +00004259 .name = "wm8994-codec",
4260 .owner = THIS_MODULE,
4261 .pm = &wm8994_pm_ops,
4262 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004263 .probe = wm8994_probe,
4264 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00004265};
4266
Mark Brown5bbcc3c2011-11-23 22:52:08 +00004267module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004268
4269MODULE_DESCRIPTION("ASoC WM8994 driver");
4270MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4271MODULE_LICENSE("GPL");
4272MODULE_ALIAS("platform:wm8994-codec");