blob: 18c99cda7cc9cad1c571bf71ebc273a566174328 [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
689 if (wm8994->active_refcount)
690 mode = WM1811_JACKDET_MODE_AUDIO;
691
692 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
693 WM1811_JACKDET_MODE_MASK, mode);
694
695 if (mode == WM1811_JACKDET_MODE_MIC)
696 msleep(2);
697}
698
699static void active_reference(struct snd_soc_codec *codec)
700{
701 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
702
703 mutex_lock(&wm8994->accdet_lock);
704
705 wm8994->active_refcount++;
706
707 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
708 wm8994->active_refcount);
709
710 if (wm8994->active_refcount == 1) {
711 /* If we're using jack detection go into audio mode */
712 if (wm8994->jackdet && wm8994->jack_cb) {
713 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
714 WM1811_JACKDET_MODE_MASK,
715 WM1811_JACKDET_MODE_AUDIO);
716 msleep(2);
717 }
718 }
719
720 mutex_unlock(&wm8994->accdet_lock);
721}
722
723static void active_dereference(struct snd_soc_codec *codec)
724{
725 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
726 u16 mode;
727
728 mutex_lock(&wm8994->accdet_lock);
729
730 wm8994->active_refcount--;
731
732 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
733 wm8994->active_refcount);
734
735 if (wm8994->active_refcount == 0) {
736 /* Go into appropriate detection only mode */
737 if (wm8994->jackdet && wm8994->jack_cb) {
738 if (wm8994->jack_mic || wm8994->mic_detecting)
739 mode = WM1811_JACKDET_MODE_MIC;
740 else
741 mode = WM1811_JACKDET_MODE_JACK;
742
743 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
744 WM1811_JACKDET_MODE_MASK,
745 mode);
746 }
747 }
748
749 mutex_unlock(&wm8994->accdet_lock);
750}
751
Mark Brown9e6e96a2010-01-29 17:47:12 +0000752static int clk_sys_event(struct snd_soc_dapm_widget *w,
753 struct snd_kcontrol *kcontrol, int event)
754{
755 struct snd_soc_codec *codec = w->codec;
756
757 switch (event) {
758 case SND_SOC_DAPM_PRE_PMU:
759 return configure_clock(codec);
760
761 case SND_SOC_DAPM_POST_PMD:
762 configure_clock(codec);
763 break;
764 }
765
766 return 0;
767}
768
Mark Brown4b7ed832011-08-10 17:47:33 +0900769static void vmid_reference(struct snd_soc_codec *codec)
770{
771 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
772
Mark Browndb966f82012-02-06 12:07:08 +0000773 pm_runtime_get_sync(codec->dev);
774
Mark Brown4b7ed832011-08-10 17:47:33 +0900775 wm8994->vmid_refcount++;
776
777 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
778 wm8994->vmid_refcount);
779
780 if (wm8994->vmid_refcount == 1) {
Mark Browncc6d5a82012-02-11 23:09:53 +0000781 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
782 WM8994_LINEOUT_VMID_BUF_ENA |
783 WM8994_LINEOUT1_DISCH |
784 WM8994_LINEOUT2_DISCH,
785 WM8994_LINEOUT_VMID_BUF_ENA);
786
Mark Brown4b7ed832011-08-10 17:47:33 +0900787 /* Startup bias, VMID ramp & buffer */
788 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
Mark Browncc6d5a82012-02-11 23:09:53 +0000789 WM8994_BIAS_SRC |
790 WM8994_VMID_DISCH |
Mark Brown4b7ed832011-08-10 17:47:33 +0900791 WM8994_STARTUP_BIAS_ENA |
792 WM8994_VMID_BUF_ENA |
793 WM8994_VMID_RAMP_MASK,
Mark Browncc6d5a82012-02-11 23:09:53 +0000794 WM8994_BIAS_SRC |
Mark Brown4b7ed832011-08-10 17:47:33 +0900795 WM8994_STARTUP_BIAS_ENA |
796 WM8994_VMID_BUF_ENA |
Mark Brown65f01ef2012-02-14 17:53:55 -0800797 (0x2 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900798
Mark Brown5f2f3892012-02-08 18:51:42 +0000799 wm_hubs_vmid_ena(codec);
800
Mark Brown4b7ed832011-08-10 17:47:33 +0900801 /* 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);
806
Mark Browncc6d5a82012-02-11 23:09:53 +0000807 msleep(50);
808
809 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
810 WM8994_VMID_RAMP_MASK | WM8994_BIAS_SRC,
811 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900812 }
813}
814
815static void vmid_dereference(struct snd_soc_codec *codec)
816{
817 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
818
819 wm8994->vmid_refcount--;
820
821 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
822 wm8994->vmid_refcount);
823
824 if (wm8994->vmid_refcount == 0) {
825 /* Switch over to startup biases */
826 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
827 WM8994_BIAS_SRC |
828 WM8994_STARTUP_BIAS_ENA |
829 WM8994_VMID_BUF_ENA |
830 WM8994_VMID_RAMP_MASK,
831 WM8994_BIAS_SRC |
832 WM8994_STARTUP_BIAS_ENA |
833 WM8994_VMID_BUF_ENA |
834 (1 << WM8994_VMID_RAMP_SHIFT));
835
836 /* Disable main biases */
837 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
838 WM8994_BIAS_ENA |
839 WM8994_VMID_SEL_MASK, 0);
840
Mark Browne85b26c2012-02-11 23:10:30 +0000841 /* Discharge VMID */
842 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
843 WM8994_VMID_DISCH, WM8994_VMID_DISCH);
844
Mark Brown4b7ed832011-08-10 17:47:33 +0900845 /* Discharge line */
846 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
847 WM8994_LINEOUT1_DISCH |
848 WM8994_LINEOUT2_DISCH,
849 WM8994_LINEOUT1_DISCH |
850 WM8994_LINEOUT2_DISCH);
851
852 msleep(5);
853
854 /* Switch off startup biases */
855 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
856 WM8994_BIAS_SRC |
857 WM8994_STARTUP_BIAS_ENA |
858 WM8994_VMID_BUF_ENA |
859 WM8994_VMID_RAMP_MASK, 0);
860 }
Mark Browndb966f82012-02-06 12:07:08 +0000861
862 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900863}
864
865static int vmid_event(struct snd_soc_dapm_widget *w,
866 struct snd_kcontrol *kcontrol, int event)
867{
868 struct snd_soc_codec *codec = w->codec;
869
870 switch (event) {
871 case SND_SOC_DAPM_PRE_PMU:
872 vmid_reference(codec);
873 break;
874
875 case SND_SOC_DAPM_POST_PMD:
876 vmid_dereference(codec);
877 break;
878 }
879
880 return 0;
881}
882
Mark Brown9e6e96a2010-01-29 17:47:12 +0000883static void wm8994_update_class_w(struct snd_soc_codec *codec)
884{
Mark Brownfec6dd82010-10-27 13:48:36 -0700885 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000886 int enable = 1;
887 int source = 0; /* GCC flow analysis can't track enable */
888 int reg, reg_r;
889
890 /* Only support direct DAC->headphone paths */
891 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
892 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900893 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000894 enable = 0;
895 }
896
897 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
898 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900899 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000900 enable = 0;
901 }
902
903 /* We also need the same setting for L/R and only one path */
904 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
905 switch (reg) {
906 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900907 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000908 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
909 break;
910 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900911 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000912 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
913 break;
914 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900915 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000916 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
917 break;
918 default:
Mark Brownee839a22010-04-20 13:57:08 +0900919 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000920 enable = 0;
921 break;
922 }
923
924 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
925 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900926 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000927 enable = 0;
928 }
929
930 if (enable) {
931 dev_dbg(codec->dev, "Class W enabled\n");
932 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
933 WM8994_CP_DYN_PWR |
934 WM8994_CP_DYN_SRC_SEL_MASK,
935 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700936 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000937
938 } else {
939 dev_dbg(codec->dev, "Class W disabled\n");
940 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
941 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700942 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000943 }
944}
945
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000946static int late_enable_ev(struct snd_soc_dapm_widget *w,
947 struct snd_kcontrol *kcontrol, int event)
948{
949 struct snd_soc_codec *codec = w->codec;
950 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
951
952 switch (event) {
953 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000954 if (wm8994->aif1clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000955 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
956 WM8994_AIF1CLK_ENA_MASK,
957 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000958 wm8994->aif1clk_enable = 0;
959 }
960 if (wm8994->aif2clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000961 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
962 WM8994_AIF2CLK_ENA_MASK,
963 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000964 wm8994->aif2clk_enable = 0;
965 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000966 break;
967 }
968
Mark Brownc6b7b572011-03-11 18:13:12 +0000969 /* We may also have postponed startup of DSP, handle that. */
970 wm8958_aif_ev(w, kcontrol, event);
971
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000972 return 0;
973}
974
975static int late_disable_ev(struct snd_soc_dapm_widget *w,
976 struct snd_kcontrol *kcontrol, int event)
977{
978 struct snd_soc_codec *codec = w->codec;
979 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
980
981 switch (event) {
982 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000983 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000984 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
985 WM8994_AIF1CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000986 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000987 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000988 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000989 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
990 WM8994_AIF2CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000991 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000992 }
993 break;
994 }
995
996 return 0;
997}
998
999static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1000 struct snd_kcontrol *kcontrol, int event)
1001{
1002 struct snd_soc_codec *codec = w->codec;
1003 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1004
1005 switch (event) {
1006 case SND_SOC_DAPM_PRE_PMU:
1007 wm8994->aif1clk_enable = 1;
1008 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001009 case SND_SOC_DAPM_POST_PMD:
1010 wm8994->aif1clk_disable = 1;
1011 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001012 }
1013
1014 return 0;
1015}
1016
1017static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1018 struct snd_kcontrol *kcontrol, int event)
1019{
1020 struct snd_soc_codec *codec = w->codec;
1021 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1022
1023 switch (event) {
1024 case SND_SOC_DAPM_PRE_PMU:
1025 wm8994->aif2clk_enable = 1;
1026 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001027 case SND_SOC_DAPM_POST_PMD:
1028 wm8994->aif2clk_disable = 1;
1029 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001030 }
1031
1032 return 0;
1033}
1034
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001035static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1036 struct snd_kcontrol *kcontrol, int event)
1037{
1038 late_enable_ev(w, kcontrol, event);
1039 return 0;
1040}
1041
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001042static int micbias_ev(struct snd_soc_dapm_widget *w,
1043 struct snd_kcontrol *kcontrol, int event)
1044{
1045 late_enable_ev(w, kcontrol, event);
1046 return 0;
1047}
1048
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001049static int dac_ev(struct snd_soc_dapm_widget *w,
1050 struct snd_kcontrol *kcontrol, int event)
1051{
1052 struct snd_soc_codec *codec = w->codec;
1053 unsigned int mask = 1 << w->shift;
1054
1055 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1056 mask, mask);
1057 return 0;
1058}
1059
Mark Brown9e6e96a2010-01-29 17:47:12 +00001060static const char *hp_mux_text[] = {
1061 "Mixer",
1062 "DAC",
1063};
1064
1065#define WM8994_HP_ENUM(xname, xenum) \
1066{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1067 .info = snd_soc_info_enum_double, \
1068 .get = snd_soc_dapm_get_enum_double, \
1069 .put = wm8994_put_hp_enum, \
1070 .private_value = (unsigned long)&xenum }
1071
1072static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1073 struct snd_ctl_elem_value *ucontrol)
1074{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001075 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1076 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001077 struct snd_soc_codec *codec = w->codec;
1078 int ret;
1079
1080 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1081
1082 wm8994_update_class_w(codec);
1083
1084 return ret;
1085}
1086
1087static const struct soc_enum hpl_enum =
1088 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1089
1090static const struct snd_kcontrol_new hpl_mux =
1091 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1092
1093static const struct soc_enum hpr_enum =
1094 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1095
1096static const struct snd_kcontrol_new hpr_mux =
1097 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1098
1099static const char *adc_mux_text[] = {
1100 "ADC",
1101 "DMIC",
1102};
1103
1104static const struct soc_enum adc_enum =
1105 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1106
1107static const struct snd_kcontrol_new adcl_mux =
1108 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1109
1110static const struct snd_kcontrol_new adcr_mux =
1111 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1112
1113static const struct snd_kcontrol_new left_speaker_mixer[] = {
1114SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1115SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1116SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1117SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1118SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1119};
1120
1121static const struct snd_kcontrol_new right_speaker_mixer[] = {
1122SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1123SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1124SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1125SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1126SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1127};
1128
1129/* Debugging; dump chip status after DAPM transitions */
1130static int post_ev(struct snd_soc_dapm_widget *w,
1131 struct snd_kcontrol *kcontrol, int event)
1132{
1133 struct snd_soc_codec *codec = w->codec;
1134 dev_dbg(codec->dev, "SRC status: %x\n",
1135 snd_soc_read(codec,
1136 WM8994_RATE_STATUS));
1137 return 0;
1138}
1139
1140static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1141SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1142 1, 1, 0),
1143SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1144 0, 1, 0),
1145};
1146
1147static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1148SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1149 1, 1, 0),
1150SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1151 0, 1, 0),
1152};
1153
Mark Browna3257ba2010-07-19 14:02:34 +01001154static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1155SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1156 1, 1, 0),
1157SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1158 0, 1, 0),
1159};
1160
1161static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1162SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1163 1, 1, 0),
1164SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1165 0, 1, 0),
1166};
1167
Mark Brown9e6e96a2010-01-29 17:47:12 +00001168static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1169SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1170 5, 1, 0),
1171SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1172 4, 1, 0),
1173SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1174 2, 1, 0),
1175SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1176 1, 1, 0),
1177SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1178 0, 1, 0),
1179};
1180
1181static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1182SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1183 5, 1, 0),
1184SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1185 4, 1, 0),
1186SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1187 2, 1, 0),
1188SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1189 1, 1, 0),
1190SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1191 0, 1, 0),
1192};
1193
1194#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1195{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1196 .info = snd_soc_info_volsw, \
1197 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1198 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1199
1200static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1201 struct snd_ctl_elem_value *ucontrol)
1202{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001203 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1204 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001205 struct snd_soc_codec *codec = w->codec;
1206 int ret;
1207
1208 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1209
1210 wm8994_update_class_w(codec);
1211
1212 return ret;
1213}
1214
1215static const struct snd_kcontrol_new dac1l_mix[] = {
1216WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1217 5, 1, 0),
1218WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1219 4, 1, 0),
1220WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1221 2, 1, 0),
1222WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1223 1, 1, 0),
1224WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1225 0, 1, 0),
1226};
1227
1228static const struct snd_kcontrol_new dac1r_mix[] = {
1229WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1230 5, 1, 0),
1231WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1232 4, 1, 0),
1233WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1234 2, 1, 0),
1235WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1236 1, 1, 0),
1237WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1238 0, 1, 0),
1239};
1240
1241static const char *sidetone_text[] = {
1242 "ADC/DMIC1", "DMIC2",
1243};
1244
1245static const struct soc_enum sidetone1_enum =
1246 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1247
1248static const struct snd_kcontrol_new sidetone1_mux =
1249 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1250
1251static const struct soc_enum sidetone2_enum =
1252 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1253
1254static const struct snd_kcontrol_new sidetone2_mux =
1255 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1256
1257static const char *aif1dac_text[] = {
1258 "AIF1DACDAT", "AIF3DACDAT",
1259};
1260
1261static const struct soc_enum aif1dac_enum =
1262 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1263
1264static const struct snd_kcontrol_new aif1dac_mux =
1265 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1266
1267static const char *aif2dac_text[] = {
1268 "AIF2DACDAT", "AIF3DACDAT",
1269};
1270
1271static const struct soc_enum aif2dac_enum =
1272 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1273
1274static const struct snd_kcontrol_new aif2dac_mux =
1275 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1276
1277static const char *aif2adc_text[] = {
1278 "AIF2ADCDAT", "AIF3DACDAT",
1279};
1280
1281static const struct soc_enum aif2adc_enum =
1282 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1283
1284static const struct snd_kcontrol_new aif2adc_mux =
1285 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1286
1287static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001288 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001289};
1290
Mark Brownc4431df2010-11-26 15:21:07 +00001291static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001292 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1293
Mark Brownc4431df2010-11-26 15:21:07 +00001294static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1295 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1296
1297static const struct soc_enum wm8958_aif3adc_enum =
1298 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1299
1300static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1301 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1302
1303static const char *mono_pcm_out_text[] = {
1304 "None", "AIF2ADCL", "AIF2ADCR",
1305};
1306
1307static const struct soc_enum mono_pcm_out_enum =
1308 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1309
1310static const struct snd_kcontrol_new mono_pcm_out_mux =
1311 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1312
1313static const char *aif2dac_src_text[] = {
1314 "AIF2", "AIF3",
1315};
1316
1317/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1318static const struct soc_enum aif2dacl_src_enum =
1319 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1320
1321static const struct snd_kcontrol_new aif2dacl_src_mux =
1322 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1323
1324static const struct soc_enum aif2dacr_src_enum =
1325 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1326
1327static const struct snd_kcontrol_new aif2dacr_src_mux =
1328 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001329
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001330static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1331SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1332 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1333SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1334 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1335
1336SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1337 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1338SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1339 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1340SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1341 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1342SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1343 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001344SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1345 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1346
1347SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1348 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1349 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1350SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1351 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1352 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1353SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1354 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1355SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1356 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001357
1358SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1359};
1360
1361static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1362SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
Mark Brownb70a51b2011-06-29 00:21:09 -07001363SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
1364SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1365SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1366 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1367SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1368 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1369SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1370SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001371};
1372
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001373static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1374SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1375 dac_ev, SND_SOC_DAPM_PRE_PMU),
1376SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1377 dac_ev, SND_SOC_DAPM_PRE_PMU),
1378SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1379 dac_ev, SND_SOC_DAPM_PRE_PMU),
1380SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1381 dac_ev, SND_SOC_DAPM_PRE_PMU),
1382};
1383
1384static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1385SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001386SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001387SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1388SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1389};
1390
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001391static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001392SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1393 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1394SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1395 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001396};
1397
1398static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001399SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1400SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001401};
1402
Mark Brown9e6e96a2010-01-29 17:47:12 +00001403static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1404SND_SOC_DAPM_INPUT("DMIC1DAT"),
1405SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001406SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001407
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001408SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1409 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001410SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1411 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001412
Mark Brown9e6e96a2010-01-29 17:47:12 +00001413SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1414 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1415
1416SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1417SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1418SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1419
Mark Brown7f94de42011-02-03 16:27:34 +00001420SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001421 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001422SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001423 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001424SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1425 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001426 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001427SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1428 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001429 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001430
Mark Brown7f94de42011-02-03 16:27:34 +00001431SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001432 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001433SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001434 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001435SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1436 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001437 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001438SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1439 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001440 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001441
1442SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1443 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1444SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1445 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1446
Mark Browna3257ba2010-07-19 14:02:34 +01001447SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1448 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1449SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1450 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1451
Mark Brown9e6e96a2010-01-29 17:47:12 +00001452SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1453 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1454SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1455 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1456
1457SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1458SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1459
1460SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1461 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1462SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1463 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1464
1465SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1466 WM8994_POWER_MANAGEMENT_4, 13, 0),
1467SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1468 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001469SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1470 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1471 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1472SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1473 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1474 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001475
Mark Brown5567d8c2012-02-16 21:43:29 -08001476SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1477SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1478SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1479SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001480
1481SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1482SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1483SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001484
Mark Brown5567d8c2012-02-16 21:43:29 -08001485SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1486SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001487
1488SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1489
1490SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1491SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1492SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1493SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1494
1495/* Power is done with the muxes since the ADC power also controls the
1496 * downsampling chain, the chip will automatically manage the analogue
1497 * specific portions.
1498 */
1499SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1500SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1501
Mark Brown9e6e96a2010-01-29 17:47:12 +00001502SND_SOC_DAPM_POST("Debug log", post_ev),
1503};
1504
Mark Brownc4431df2010-11-26 15:21:07 +00001505static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1506SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1507};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001508
Mark Brownc4431df2010-11-26 15:21:07 +00001509static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1510SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1511SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1512SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1513SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1514};
1515
1516static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001517 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1518 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1519
1520 { "DSP1CLK", NULL, "CLK_SYS" },
1521 { "DSP2CLK", NULL, "CLK_SYS" },
1522 { "DSPINTCLK", NULL, "CLK_SYS" },
1523
1524 { "AIF1ADC1L", NULL, "AIF1CLK" },
1525 { "AIF1ADC1L", NULL, "DSP1CLK" },
1526 { "AIF1ADC1R", NULL, "AIF1CLK" },
1527 { "AIF1ADC1R", NULL, "DSP1CLK" },
1528 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1529
1530 { "AIF1DAC1L", NULL, "AIF1CLK" },
1531 { "AIF1DAC1L", NULL, "DSP1CLK" },
1532 { "AIF1DAC1R", NULL, "AIF1CLK" },
1533 { "AIF1DAC1R", NULL, "DSP1CLK" },
1534 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1535
1536 { "AIF1ADC2L", NULL, "AIF1CLK" },
1537 { "AIF1ADC2L", NULL, "DSP1CLK" },
1538 { "AIF1ADC2R", NULL, "AIF1CLK" },
1539 { "AIF1ADC2R", NULL, "DSP1CLK" },
1540 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1541
1542 { "AIF1DAC2L", NULL, "AIF1CLK" },
1543 { "AIF1DAC2L", NULL, "DSP1CLK" },
1544 { "AIF1DAC2R", NULL, "AIF1CLK" },
1545 { "AIF1DAC2R", NULL, "DSP1CLK" },
1546 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1547
1548 { "AIF2ADCL", NULL, "AIF2CLK" },
1549 { "AIF2ADCL", NULL, "DSP2CLK" },
1550 { "AIF2ADCR", NULL, "AIF2CLK" },
1551 { "AIF2ADCR", NULL, "DSP2CLK" },
1552 { "AIF2ADCR", NULL, "DSPINTCLK" },
1553
1554 { "AIF2DACL", NULL, "AIF2CLK" },
1555 { "AIF2DACL", NULL, "DSP2CLK" },
1556 { "AIF2DACR", NULL, "AIF2CLK" },
1557 { "AIF2DACR", NULL, "DSP2CLK" },
1558 { "AIF2DACR", NULL, "DSPINTCLK" },
1559
1560 { "DMIC1L", NULL, "DMIC1DAT" },
1561 { "DMIC1L", NULL, "CLK_SYS" },
1562 { "DMIC1R", NULL, "DMIC1DAT" },
1563 { "DMIC1R", NULL, "CLK_SYS" },
1564 { "DMIC2L", NULL, "DMIC2DAT" },
1565 { "DMIC2L", NULL, "CLK_SYS" },
1566 { "DMIC2R", NULL, "DMIC2DAT" },
1567 { "DMIC2R", NULL, "CLK_SYS" },
1568
1569 { "ADCL", NULL, "AIF1CLK" },
1570 { "ADCL", NULL, "DSP1CLK" },
1571 { "ADCL", NULL, "DSPINTCLK" },
1572
1573 { "ADCR", NULL, "AIF1CLK" },
1574 { "ADCR", NULL, "DSP1CLK" },
1575 { "ADCR", NULL, "DSPINTCLK" },
1576
1577 { "ADCL Mux", "ADC", "ADCL" },
1578 { "ADCL Mux", "DMIC", "DMIC1L" },
1579 { "ADCR Mux", "ADC", "ADCR" },
1580 { "ADCR Mux", "DMIC", "DMIC1R" },
1581
1582 { "DAC1L", NULL, "AIF1CLK" },
1583 { "DAC1L", NULL, "DSP1CLK" },
1584 { "DAC1L", NULL, "DSPINTCLK" },
1585
1586 { "DAC1R", NULL, "AIF1CLK" },
1587 { "DAC1R", NULL, "DSP1CLK" },
1588 { "DAC1R", NULL, "DSPINTCLK" },
1589
1590 { "DAC2L", NULL, "AIF2CLK" },
1591 { "DAC2L", NULL, "DSP2CLK" },
1592 { "DAC2L", NULL, "DSPINTCLK" },
1593
1594 { "DAC2R", NULL, "AIF2DACR" },
1595 { "DAC2R", NULL, "AIF2CLK" },
1596 { "DAC2R", NULL, "DSP2CLK" },
1597 { "DAC2R", NULL, "DSPINTCLK" },
1598
1599 { "TOCLK", NULL, "CLK_SYS" },
1600
Mark Brown5567d8c2012-02-16 21:43:29 -08001601 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1602 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1603 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1604
1605 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1606 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1607 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1608
Mark Brown9e6e96a2010-01-29 17:47:12 +00001609 /* AIF1 outputs */
1610 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1611 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1612 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1613
1614 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1615 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1616 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1617
Mark Browna3257ba2010-07-19 14:02:34 +01001618 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1619 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1620 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1621
1622 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1623 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1624 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1625
Mark Brown9e6e96a2010-01-29 17:47:12 +00001626 /* Pin level routing for AIF3 */
1627 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1628 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1629 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1630 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1631
Mark Brown9e6e96a2010-01-29 17:47:12 +00001632 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1633 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1634 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1635 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1636 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1637 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1638 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1639
1640 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001641 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1642 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1643 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1644 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1645 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1646
Mark Brown9e6e96a2010-01-29 17:47:12 +00001647 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1648 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1649 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1650 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1651 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1652
1653 /* DAC2/AIF2 outputs */
1654 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001655 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1656 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1657 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1658 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1659 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1660
1661 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001662 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1663 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1664 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1665 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1666 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1667
Mark Brown7f94de42011-02-03 16:27:34 +00001668 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1669 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1670 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1671 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1672
Mark Brown9e6e96a2010-01-29 17:47:12 +00001673 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1674
1675 /* AIF3 output */
1676 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1677 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1678 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1679 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1680 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1681 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1682 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1683 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1684
1685 /* Sidetone */
1686 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1687 { "Left Sidetone", "DMIC2", "DMIC2L" },
1688 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1689 { "Right Sidetone", "DMIC2", "DMIC2R" },
1690
1691 /* Output stages */
1692 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1693 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1694
1695 { "SPKL", "DAC1 Switch", "DAC1L" },
1696 { "SPKL", "DAC2 Switch", "DAC2L" },
1697
1698 { "SPKR", "DAC1 Switch", "DAC1R" },
1699 { "SPKR", "DAC2 Switch", "DAC2R" },
1700
1701 { "Left Headphone Mux", "DAC", "DAC1L" },
1702 { "Right Headphone Mux", "DAC", "DAC1R" },
1703};
1704
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001705static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1706 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1707 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1708 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1709 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1710 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1711 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1712 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1713 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1714};
1715
1716static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1717 { "DAC1L", NULL, "DAC1L Mixer" },
1718 { "DAC1R", NULL, "DAC1R Mixer" },
1719 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1720 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1721};
1722
Mark Brown6ed8f142011-02-03 16:27:35 +00001723static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1724 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1725 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1726 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1727 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001728 { "MICBIAS1", NULL, "CLK_SYS" },
1729 { "MICBIAS1", NULL, "MICBIAS Supply" },
1730 { "MICBIAS2", NULL, "CLK_SYS" },
1731 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001732};
1733
Mark Brownc4431df2010-11-26 15:21:07 +00001734static const struct snd_soc_dapm_route wm8994_intercon[] = {
1735 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1736 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001737 { "MICBIAS1", NULL, "VMID" },
1738 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001739};
1740
1741static const struct snd_soc_dapm_route wm8958_intercon[] = {
1742 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1743 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1744
1745 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1746 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1747 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1748 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1749
1750 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1751 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1752
1753 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1754};
1755
Mark Brown9e6e96a2010-01-29 17:47:12 +00001756/* The size in bits of the FLL divide multiplied by 10
1757 * to allow rounding later */
1758#define FIXED_FLL_SIZE ((1 << 16) * 10)
1759
1760struct fll_div {
1761 u16 outdiv;
1762 u16 n;
1763 u16 k;
1764 u16 clk_ref_div;
1765 u16 fll_fratio;
1766};
1767
1768static int wm8994_get_fll_config(struct fll_div *fll,
1769 int freq_in, int freq_out)
1770{
1771 u64 Kpart;
1772 unsigned int K, Ndiv, Nmod;
1773
1774 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1775
1776 /* Scale the input frequency down to <= 13.5MHz */
1777 fll->clk_ref_div = 0;
1778 while (freq_in > 13500000) {
1779 fll->clk_ref_div++;
1780 freq_in /= 2;
1781
1782 if (fll->clk_ref_div > 3)
1783 return -EINVAL;
1784 }
1785 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1786
1787 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1788 fll->outdiv = 3;
1789 while (freq_out * (fll->outdiv + 1) < 90000000) {
1790 fll->outdiv++;
1791 if (fll->outdiv > 63)
1792 return -EINVAL;
1793 }
1794 freq_out *= fll->outdiv + 1;
1795 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1796
1797 if (freq_in > 1000000) {
1798 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001799 } else if (freq_in > 256000) {
1800 fll->fll_fratio = 1;
1801 freq_in *= 2;
1802 } else if (freq_in > 128000) {
1803 fll->fll_fratio = 2;
1804 freq_in *= 4;
1805 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001806 fll->fll_fratio = 3;
1807 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001808 } else {
1809 fll->fll_fratio = 4;
1810 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001811 }
1812 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1813
1814 /* Now, calculate N.K */
1815 Ndiv = freq_out / freq_in;
1816
1817 fll->n = Ndiv;
1818 Nmod = freq_out % freq_in;
1819 pr_debug("Nmod=%d\n", Nmod);
1820
1821 /* Calculate fractional part - scale up so we can round. */
1822 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1823
1824 do_div(Kpart, freq_in);
1825
1826 K = Kpart & 0xFFFFFFFF;
1827
1828 if ((K % 10) >= 5)
1829 K += 5;
1830
1831 /* Move down to proper range now rounding is done */
1832 fll->k = K / 10;
1833
1834 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1835
1836 return 0;
1837}
1838
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001839static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001840 unsigned int freq_in, unsigned int freq_out)
1841{
Mark Brownb2c812e2010-04-14 15:35:19 +09001842 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01001843 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001844 int reg_offset, ret;
1845 struct fll_div fll;
1846 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001847 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001848 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001849
1850 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1851 & WM8994_AIF1CLK_ENA;
1852
1853 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1854 & WM8994_AIF2CLK_ENA;
1855
1856 switch (id) {
1857 case WM8994_FLL1:
1858 reg_offset = 0;
1859 id = 0;
1860 break;
1861 case WM8994_FLL2:
1862 reg_offset = 0x20;
1863 id = 1;
1864 break;
1865 default:
1866 return -EINVAL;
1867 }
1868
Mark Brown4b7ed832011-08-10 17:47:33 +09001869 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1870 was_enabled = reg & WM8994_FLL1_ENA;
1871
Mark Brown136ff2a2010-04-20 12:56:18 +09001872 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001873 case 0:
1874 /* Allow no source specification when stopping */
1875 if (freq_out)
1876 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001877 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001878 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001879 case WM8994_FLL_SRC_MCLK1:
1880 case WM8994_FLL_SRC_MCLK2:
1881 case WM8994_FLL_SRC_LRCLK:
1882 case WM8994_FLL_SRC_BCLK:
1883 break;
1884 default:
1885 return -EINVAL;
1886 }
1887
Mark Brown9e6e96a2010-01-29 17:47:12 +00001888 /* Are we changing anything? */
1889 if (wm8994->fll[id].src == src &&
1890 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1891 return 0;
1892
1893 /* If we're stopping the FLL redo the old config - no
1894 * registers will actually be written but we avoid GCC flow
1895 * analysis bugs spewing warnings.
1896 */
1897 if (freq_out)
1898 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1899 else
1900 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1901 wm8994->fll[id].out);
1902 if (ret < 0)
1903 return ret;
1904
1905 /* Gate the AIF clocks while we reclock */
1906 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1907 WM8994_AIF1CLK_ENA, 0);
1908 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1909 WM8994_AIF2CLK_ENA, 0);
1910
1911 /* We always need to disable the FLL while reconfiguring */
1912 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1913 WM8994_FLL1_ENA, 0);
1914
1915 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1916 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1917 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1918 WM8994_FLL1_OUTDIV_MASK |
1919 WM8994_FLL1_FRATIO_MASK, reg);
1920
1921 snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
1922
1923 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1924 WM8994_FLL1_N_MASK,
1925 fll.n << WM8994_FLL1_N_SHIFT);
1926
1927 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001928 WM8994_FLL1_REFCLK_DIV_MASK |
1929 WM8994_FLL1_REFCLK_SRC_MASK,
1930 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1931 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001932
Mark Brownf0f50392011-07-16 03:12:18 +09001933 /* Clear any pending completion from a previous failure */
1934 try_wait_for_completion(&wm8994->fll_locked[id]);
1935
Mark Brown9e6e96a2010-01-29 17:47:12 +00001936 /* Enable (with fractional mode if required) */
1937 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001938 /* Enable VMID if we need it */
1939 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001940 active_reference(codec);
1941
Mark Brown4b7ed832011-08-10 17:47:33 +09001942 switch (control->type) {
1943 case WM8994:
1944 vmid_reference(codec);
1945 break;
1946 case WM8958:
1947 if (wm8994->revision < 1)
1948 vmid_reference(codec);
1949 break;
1950 default:
1951 break;
1952 }
1953 }
1954
Mark Brown9e6e96a2010-01-29 17:47:12 +00001955 if (fll.k)
1956 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1957 else
1958 reg = WM8994_FLL1_ENA;
1959 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1960 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1961 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001962
Mark Brownc7ebf932011-07-12 19:47:59 +09001963 if (wm8994->fll_locked_irq) {
1964 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1965 msecs_to_jiffies(10));
1966 if (timeout == 0)
1967 dev_warn(codec->dev,
1968 "Timed out waiting for FLL lock\n");
1969 } else {
1970 msleep(5);
1971 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001972 } else {
1973 if (was_enabled) {
1974 switch (control->type) {
1975 case WM8994:
1976 vmid_dereference(codec);
1977 break;
1978 case WM8958:
1979 if (wm8994->revision < 1)
1980 vmid_dereference(codec);
1981 break;
1982 default:
1983 break;
1984 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001985
1986 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001987 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00001988 }
1989
1990 wm8994->fll[id].in = freq_in;
1991 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001992 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001993
1994 /* Enable any gated AIF clocks */
1995 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1996 WM8994_AIF1CLK_ENA, aif1);
1997 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1998 WM8994_AIF2CLK_ENA, aif2);
1999
2000 configure_clock(codec);
2001
2002 return 0;
2003}
2004
Mark Brownc7ebf932011-07-12 19:47:59 +09002005static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2006{
2007 struct completion *completion = data;
2008
2009 complete(completion);
2010
2011 return IRQ_HANDLED;
2012}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002013
Mark Brown66b47fd2010-07-08 11:25:43 +09002014static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2015
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002016static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2017 unsigned int freq_in, unsigned int freq_out)
2018{
2019 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2020}
2021
Mark Brown9e6e96a2010-01-29 17:47:12 +00002022static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2023 int clk_id, unsigned int freq, int dir)
2024{
2025 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002026 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002027 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002028
2029 switch (dai->id) {
2030 case 1:
2031 case 2:
2032 break;
2033
2034 default:
2035 /* AIF3 shares clocking with AIF1/2 */
2036 return -EINVAL;
2037 }
2038
2039 switch (clk_id) {
2040 case WM8994_SYSCLK_MCLK1:
2041 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2042 wm8994->mclk[0] = freq;
2043 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2044 dai->id, freq);
2045 break;
2046
2047 case WM8994_SYSCLK_MCLK2:
2048 /* TODO: Set GPIO AF */
2049 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2050 wm8994->mclk[1] = freq;
2051 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2052 dai->id, freq);
2053 break;
2054
2055 case WM8994_SYSCLK_FLL1:
2056 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2057 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2058 break;
2059
2060 case WM8994_SYSCLK_FLL2:
2061 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2062 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2063 break;
2064
Mark Brown66b47fd2010-07-08 11:25:43 +09002065 case WM8994_SYSCLK_OPCLK:
2066 /* Special case - a division (times 10) is given and
2067 * no effect on main clocking.
2068 */
2069 if (freq) {
2070 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2071 if (opclk_divs[i] == freq)
2072 break;
2073 if (i == ARRAY_SIZE(opclk_divs))
2074 return -EINVAL;
2075 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2076 WM8994_OPCLK_DIV_MASK, i);
2077 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2078 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2079 } else {
2080 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2081 WM8994_OPCLK_ENA, 0);
2082 }
2083
Mark Brown9e6e96a2010-01-29 17:47:12 +00002084 default:
2085 return -EINVAL;
2086 }
2087
2088 configure_clock(codec);
2089
2090 return 0;
2091}
2092
2093static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2094 enum snd_soc_bias_level level)
2095{
Mark Brownb6b05692010-08-13 12:58:20 +01002096 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002097 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002098
Mark Brown5f2f3892012-02-08 18:51:42 +00002099 wm_hubs_set_bias_level(codec, level);
2100
Mark Brown9e6e96a2010-01-29 17:47:12 +00002101 switch (level) {
2102 case SND_SOC_BIAS_ON:
2103 break;
2104
2105 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002106 /* MICBIAS into regulating mode */
2107 switch (control->type) {
2108 case WM8958:
2109 case WM1811:
2110 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2111 WM8958_MICB1_MODE, 0);
2112 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2113 WM8958_MICB2_MODE, 0);
2114 break;
2115 default:
2116 break;
2117 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002118
2119 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2120 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002121 break;
2122
2123 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002124 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002125 switch (control->type) {
2126 case WM8994:
2127 if (wm8994->revision < 4) {
2128 /* Tweak DC servo and DSP
2129 * configuration for improved
2130 * performance. */
2131 snd_soc_write(codec, 0x102, 0x3);
2132 snd_soc_write(codec, 0x56, 0x3);
2133 snd_soc_write(codec, 0x817, 0);
2134 snd_soc_write(codec, 0x102, 0);
2135 }
2136 break;
2137
2138 case WM8958:
2139 if (wm8994->revision == 0) {
2140 /* Optimise performance for rev A */
2141 snd_soc_write(codec, 0x102, 0x3);
2142 snd_soc_write(codec, 0xcb, 0x81);
2143 snd_soc_write(codec, 0x817, 0);
2144 snd_soc_write(codec, 0x102, 0);
2145
2146 snd_soc_update_bits(codec,
2147 WM8958_CHARGE_PUMP_2,
2148 WM8958_CP_DISCH,
2149 WM8958_CP_DISCH);
2150 }
2151 break;
Mark Brown81204c82011-05-24 17:35:53 +08002152
2153 case WM1811:
2154 if (wm8994->revision < 2) {
2155 snd_soc_write(codec, 0x102, 0x3);
2156 snd_soc_write(codec, 0x5d, 0x7e);
2157 snd_soc_write(codec, 0x5e, 0x0);
2158 snd_soc_write(codec, 0x102, 0x0);
2159 }
2160 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002161 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002162
2163 /* Discharge LINEOUT1 & 2 */
2164 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2165 WM8994_LINEOUT1_DISCH |
2166 WM8994_LINEOUT2_DISCH,
2167 WM8994_LINEOUT1_DISCH |
2168 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002169 }
2170
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002171 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2172 active_dereference(codec);
2173
Mark Brown500fa302011-11-29 19:58:19 +00002174 /* MICBIAS into bypass mode on newer devices */
2175 switch (control->type) {
2176 case WM8958:
2177 case WM1811:
2178 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2179 WM8958_MICB1_MODE,
2180 WM8958_MICB1_MODE);
2181 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2182 WM8958_MICB2_MODE,
2183 WM8958_MICB2_MODE);
2184 break;
2185 default:
2186 break;
2187 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002188 break;
2189
2190 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002191 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002192 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002193 break;
2194 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002195
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002196 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002197
Mark Brown9e6e96a2010-01-29 17:47:12 +00002198 return 0;
2199}
2200
2201static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2202{
2203 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002204 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2205 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002206 int ms_reg;
2207 int aif1_reg;
2208 int ms = 0;
2209 int aif1 = 0;
2210
2211 switch (dai->id) {
2212 case 1:
2213 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2214 aif1_reg = WM8994_AIF1_CONTROL_1;
2215 break;
2216 case 2:
2217 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2218 aif1_reg = WM8994_AIF2_CONTROL_1;
2219 break;
2220 default:
2221 return -EINVAL;
2222 }
2223
2224 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2225 case SND_SOC_DAIFMT_CBS_CFS:
2226 break;
2227 case SND_SOC_DAIFMT_CBM_CFM:
2228 ms = WM8994_AIF1_MSTR;
2229 break;
2230 default:
2231 return -EINVAL;
2232 }
2233
2234 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2235 case SND_SOC_DAIFMT_DSP_B:
2236 aif1 |= WM8994_AIF1_LRCLK_INV;
2237 case SND_SOC_DAIFMT_DSP_A:
2238 aif1 |= 0x18;
2239 break;
2240 case SND_SOC_DAIFMT_I2S:
2241 aif1 |= 0x10;
2242 break;
2243 case SND_SOC_DAIFMT_RIGHT_J:
2244 break;
2245 case SND_SOC_DAIFMT_LEFT_J:
2246 aif1 |= 0x8;
2247 break;
2248 default:
2249 return -EINVAL;
2250 }
2251
2252 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2253 case SND_SOC_DAIFMT_DSP_A:
2254 case SND_SOC_DAIFMT_DSP_B:
2255 /* frame inversion not valid for DSP modes */
2256 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2257 case SND_SOC_DAIFMT_NB_NF:
2258 break;
2259 case SND_SOC_DAIFMT_IB_NF:
2260 aif1 |= WM8994_AIF1_BCLK_INV;
2261 break;
2262 default:
2263 return -EINVAL;
2264 }
2265 break;
2266
2267 case SND_SOC_DAIFMT_I2S:
2268 case SND_SOC_DAIFMT_RIGHT_J:
2269 case SND_SOC_DAIFMT_LEFT_J:
2270 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2271 case SND_SOC_DAIFMT_NB_NF:
2272 break;
2273 case SND_SOC_DAIFMT_IB_IF:
2274 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2275 break;
2276 case SND_SOC_DAIFMT_IB_NF:
2277 aif1 |= WM8994_AIF1_BCLK_INV;
2278 break;
2279 case SND_SOC_DAIFMT_NB_IF:
2280 aif1 |= WM8994_AIF1_LRCLK_INV;
2281 break;
2282 default:
2283 return -EINVAL;
2284 }
2285 break;
2286 default:
2287 return -EINVAL;
2288 }
2289
Mark Brownc4431df2010-11-26 15:21:07 +00002290 /* The AIF2 format configuration needs to be mirrored to AIF3
2291 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002292 switch (control->type) {
2293 case WM1811:
2294 case WM8958:
2295 if (dai->id == 2)
2296 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2297 WM8994_AIF1_LRCLK_INV |
2298 WM8958_AIF3_FMT_MASK, aif1);
2299 break;
2300
2301 default:
2302 break;
2303 }
Mark Brownc4431df2010-11-26 15:21:07 +00002304
Mark Brown9e6e96a2010-01-29 17:47:12 +00002305 snd_soc_update_bits(codec, aif1_reg,
2306 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2307 WM8994_AIF1_FMT_MASK,
2308 aif1);
2309 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2310 ms);
2311
2312 return 0;
2313}
2314
2315static struct {
2316 int val, rate;
2317} srs[] = {
2318 { 0, 8000 },
2319 { 1, 11025 },
2320 { 2, 12000 },
2321 { 3, 16000 },
2322 { 4, 22050 },
2323 { 5, 24000 },
2324 { 6, 32000 },
2325 { 7, 44100 },
2326 { 8, 48000 },
2327 { 9, 88200 },
2328 { 10, 96000 },
2329};
2330
2331static int fs_ratios[] = {
2332 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2333};
2334
2335static int bclk_divs[] = {
2336 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2337 640, 880, 960, 1280, 1760, 1920
2338};
2339
2340static int wm8994_hw_params(struct snd_pcm_substream *substream,
2341 struct snd_pcm_hw_params *params,
2342 struct snd_soc_dai *dai)
2343{
2344 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002345 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002346 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002347 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002348 int bclk_reg;
2349 int lrclk_reg;
2350 int rate_reg;
2351 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002352 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002353 int bclk = 0;
2354 int lrclk = 0;
2355 int rate_val = 0;
2356 int id = dai->id - 1;
2357
2358 int i, cur_val, best_val, bclk_rate, best;
2359
2360 switch (dai->id) {
2361 case 1:
2362 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002363 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002364 bclk_reg = WM8994_AIF1_BCLK;
2365 rate_reg = WM8994_AIF1_RATE;
2366 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002367 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002368 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002369 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002370 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002371 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2372 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002373 break;
2374 case 2:
2375 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002376 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002377 bclk_reg = WM8994_AIF2_BCLK;
2378 rate_reg = WM8994_AIF2_RATE;
2379 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002380 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002381 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002382 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002383 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002384 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2385 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002386 break;
2387 default:
2388 return -EINVAL;
2389 }
2390
2391 bclk_rate = params_rate(params) * 2;
2392 switch (params_format(params)) {
2393 case SNDRV_PCM_FORMAT_S16_LE:
2394 bclk_rate *= 16;
2395 break;
2396 case SNDRV_PCM_FORMAT_S20_3LE:
2397 bclk_rate *= 20;
2398 aif1 |= 0x20;
2399 break;
2400 case SNDRV_PCM_FORMAT_S24_LE:
2401 bclk_rate *= 24;
2402 aif1 |= 0x40;
2403 break;
2404 case SNDRV_PCM_FORMAT_S32_LE:
2405 bclk_rate *= 32;
2406 aif1 |= 0x60;
2407 break;
2408 default:
2409 return -EINVAL;
2410 }
2411
2412 /* Try to find an appropriate sample rate; look for an exact match. */
2413 for (i = 0; i < ARRAY_SIZE(srs); i++)
2414 if (srs[i].rate == params_rate(params))
2415 break;
2416 if (i == ARRAY_SIZE(srs))
2417 return -EINVAL;
2418 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2419
2420 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2421 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2422 dai->id, wm8994->aifclk[id], bclk_rate);
2423
Mark Brownb1e43d92010-12-07 17:14:56 +00002424 if (params_channels(params) == 1 &&
2425 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2426 aif2 |= WM8994_AIF1_MONO;
2427
Mark Brown9e6e96a2010-01-29 17:47:12 +00002428 if (wm8994->aifclk[id] == 0) {
2429 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2430 return -EINVAL;
2431 }
2432
2433 /* AIFCLK/fs ratio; look for a close match in either direction */
2434 best = 0;
2435 best_val = abs((fs_ratios[0] * params_rate(params))
2436 - wm8994->aifclk[id]);
2437 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2438 cur_val = abs((fs_ratios[i] * params_rate(params))
2439 - wm8994->aifclk[id]);
2440 if (cur_val >= best_val)
2441 continue;
2442 best = i;
2443 best_val = cur_val;
2444 }
2445 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2446 dai->id, fs_ratios[best]);
2447 rate_val |= best;
2448
2449 /* We may not get quite the right frequency if using
2450 * approximate clocks so look for the closest match that is
2451 * higher than the target (we need to ensure that there enough
2452 * BCLKs to clock out the samples).
2453 */
2454 best = 0;
2455 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002456 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002457 if (cur_val < 0) /* BCLK table is sorted */
2458 break;
2459 best = i;
2460 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002461 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002462 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2463 bclk_divs[best], bclk_rate);
2464 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2465
2466 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002467 if (!lrclk) {
2468 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2469 bclk_rate);
2470 return -EINVAL;
2471 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002472 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2473 lrclk, bclk_rate / lrclk);
2474
2475 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002476 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002477 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2478 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2479 lrclk);
2480 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2481 WM8994_AIF1CLK_RATE_MASK, rate_val);
2482
2483 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2484 switch (dai->id) {
2485 case 1:
2486 wm8994->dac_rates[0] = params_rate(params);
2487 wm8994_set_retune_mobile(codec, 0);
2488 wm8994_set_retune_mobile(codec, 1);
2489 break;
2490 case 2:
2491 wm8994->dac_rates[1] = params_rate(params);
2492 wm8994_set_retune_mobile(codec, 2);
2493 break;
2494 }
2495 }
2496
2497 return 0;
2498}
2499
Mark Brownc4431df2010-11-26 15:21:07 +00002500static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2501 struct snd_pcm_hw_params *params,
2502 struct snd_soc_dai *dai)
2503{
2504 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002505 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2506 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002507 int aif1_reg;
2508 int aif1 = 0;
2509
2510 switch (dai->id) {
2511 case 3:
2512 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002513 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002514 case WM8958:
2515 aif1_reg = WM8958_AIF3_CONTROL_1;
2516 break;
2517 default:
2518 return 0;
2519 }
2520 default:
2521 return 0;
2522 }
2523
2524 switch (params_format(params)) {
2525 case SNDRV_PCM_FORMAT_S16_LE:
2526 break;
2527 case SNDRV_PCM_FORMAT_S20_3LE:
2528 aif1 |= 0x20;
2529 break;
2530 case SNDRV_PCM_FORMAT_S24_LE:
2531 aif1 |= 0x40;
2532 break;
2533 case SNDRV_PCM_FORMAT_S32_LE:
2534 aif1 |= 0x60;
2535 break;
2536 default:
2537 return -EINVAL;
2538 }
2539
2540 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2541}
2542
Mark Brown7d021732011-07-14 17:11:38 +09002543static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2544 struct snd_soc_dai *dai)
2545{
2546 struct snd_soc_codec *codec = dai->codec;
2547 int rate_reg = 0;
2548
2549 switch (dai->id) {
2550 case 1:
2551 rate_reg = WM8994_AIF1_RATE;
2552 break;
2553 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002554 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002555 break;
2556 default:
2557 break;
2558 }
2559
2560 /* If the DAI is idle then configure the divider tree for the
2561 * lowest output rate to save a little power if the clock is
2562 * still active (eg, because it is system clock).
2563 */
2564 if (rate_reg && !dai->playback_active && !dai->capture_active)
2565 snd_soc_update_bits(codec, rate_reg,
2566 WM8994_AIF1_SR_MASK |
2567 WM8994_AIF1CLK_RATE_MASK, 0x9);
2568}
2569
Mark Brown9e6e96a2010-01-29 17:47:12 +00002570static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2571{
2572 struct snd_soc_codec *codec = codec_dai->codec;
2573 int mute_reg;
2574 int reg;
2575
2576 switch (codec_dai->id) {
2577 case 1:
2578 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2579 break;
2580 case 2:
2581 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2582 break;
2583 default:
2584 return -EINVAL;
2585 }
2586
2587 if (mute)
2588 reg = WM8994_AIF1DAC1_MUTE;
2589 else
2590 reg = 0;
2591
2592 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2593
2594 return 0;
2595}
2596
Mark Brown778a76e2010-03-22 22:05:10 +00002597static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2598{
2599 struct snd_soc_codec *codec = codec_dai->codec;
2600 int reg, val, mask;
2601
2602 switch (codec_dai->id) {
2603 case 1:
2604 reg = WM8994_AIF1_MASTER_SLAVE;
2605 mask = WM8994_AIF1_TRI;
2606 break;
2607 case 2:
2608 reg = WM8994_AIF2_MASTER_SLAVE;
2609 mask = WM8994_AIF2_TRI;
2610 break;
2611 case 3:
2612 reg = WM8994_POWER_MANAGEMENT_6;
2613 mask = WM8994_AIF3_TRI;
2614 break;
2615 default:
2616 return -EINVAL;
2617 }
2618
2619 if (tristate)
2620 val = mask;
2621 else
2622 val = 0;
2623
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002624 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002625}
2626
Mark Brownd09f3ec2011-08-15 11:01:02 +09002627static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2628{
2629 struct snd_soc_codec *codec = dai->codec;
2630
2631 /* Disable the pulls on the AIF if we're using it to save power. */
2632 snd_soc_update_bits(codec, WM8994_GPIO_3,
2633 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2634 snd_soc_update_bits(codec, WM8994_GPIO_4,
2635 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2636 snd_soc_update_bits(codec, WM8994_GPIO_5,
2637 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2638
2639 return 0;
2640}
2641
Mark Brown9e6e96a2010-01-29 17:47:12 +00002642#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2643
2644#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002645 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002646
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002647static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002648 .set_sysclk = wm8994_set_dai_sysclk,
2649 .set_fmt = wm8994_set_dai_fmt,
2650 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002651 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002652 .digital_mute = wm8994_aif_mute,
2653 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002654 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002655};
2656
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002657static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002658 .set_sysclk = wm8994_set_dai_sysclk,
2659 .set_fmt = wm8994_set_dai_fmt,
2660 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002661 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002662 .digital_mute = wm8994_aif_mute,
2663 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002664 .set_tristate = wm8994_set_tristate,
2665};
2666
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002667static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002668 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002669 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002670};
2671
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002672static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002673 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002674 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002675 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002676 .playback = {
2677 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002678 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002679 .channels_max = 2,
2680 .rates = WM8994_RATES,
2681 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002682 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002683 },
2684 .capture = {
2685 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002686 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002687 .channels_max = 2,
2688 .rates = WM8994_RATES,
2689 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002690 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002691 },
2692 .ops = &wm8994_aif1_dai_ops,
2693 },
2694 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002695 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002696 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002697 .playback = {
2698 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002699 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002700 .channels_max = 2,
2701 .rates = WM8994_RATES,
2702 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002703 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002704 },
2705 .capture = {
2706 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002707 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002708 .channels_max = 2,
2709 .rates = WM8994_RATES,
2710 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002711 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002712 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002713 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002714 .ops = &wm8994_aif2_dai_ops,
2715 },
2716 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002717 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002718 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002719 .playback = {
2720 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002721 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002722 .channels_max = 2,
2723 .rates = WM8994_RATES,
2724 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002725 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002726 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002727 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002728 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002729 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002730 .channels_max = 2,
2731 .rates = WM8994_RATES,
2732 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002733 .sig_bits = 24,
2734 },
Mark Brown778a76e2010-03-22 22:05:10 +00002735 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002736 }
2737};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002738
2739#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01002740static int wm8994_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002741{
Mark Brownb2c812e2010-04-14 15:35:19 +09002742 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002743 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002744 int i, ret;
2745
Mark Brownca629922011-05-11 14:34:53 +02002746 switch (control->type) {
2747 case WM8994:
2748 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2749 break;
Mark Brown81204c82011-05-24 17:35:53 +08002750 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002751 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2752 WM1811_JACKDET_MODE_MASK, 0);
2753 /* Fall through */
Mark Brownca629922011-05-11 14:34:53 +02002754 case WM8958:
2755 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2756 WM8958_MICD_ENA, 0);
2757 break;
2758 }
2759
Mark Brown9e6e96a2010-01-29 17:47:12 +00002760 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2761 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002762 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002763 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002764 if (ret < 0)
2765 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2766 i + 1, ret);
2767 }
2768
2769 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2770
2771 return 0;
2772}
2773
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002774static int wm8994_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002775{
Mark Brownb2c812e2010-04-14 15:35:19 +09002776 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002777 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002778 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002779 unsigned int val, mask;
2780
2781 if (wm8994->revision < 4) {
2782 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01002783 ret = regmap_read(control->regmap,
2784 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002785
2786 /* modify the cache only */
2787 codec->cache_only = 1;
2788 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2789 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2790 val &= mask;
2791 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2792 mask, val);
2793 codec->cache_only = 0;
2794 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002795
Mark Brown9e6e96a2010-01-29 17:47:12 +00002796 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002797 if (!wm8994->fll_suspend[i].out)
2798 continue;
2799
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002800 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002801 wm8994->fll_suspend[i].src,
2802 wm8994->fll_suspend[i].in,
2803 wm8994->fll_suspend[i].out);
2804 if (ret < 0)
2805 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2806 i + 1, ret);
2807 }
2808
Mark Brownca629922011-05-11 14:34:53 +02002809 switch (control->type) {
2810 case WM8994:
2811 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2812 snd_soc_update_bits(codec, WM8994_MICBIAS,
2813 WM8994_MICD_ENA, WM8994_MICD_ENA);
2814 break;
Mark Brown81204c82011-05-24 17:35:53 +08002815 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002816 if (wm8994->jackdet && wm8994->jack_cb) {
2817 /* Restart from idle */
2818 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2819 WM1811_JACKDET_MODE_MASK,
2820 WM1811_JACKDET_MODE_JACK);
2821 break;
2822 }
Mark Brownca629922011-05-11 14:34:53 +02002823 case WM8958:
2824 if (wm8994->jack_cb)
2825 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2826 WM8958_MICD_ENA, WM8958_MICD_ENA);
2827 break;
2828 }
2829
Mark Brown9e6e96a2010-01-29 17:47:12 +00002830 return 0;
2831}
2832#else
2833#define wm8994_suspend NULL
2834#define wm8994_resume NULL
2835#endif
2836
2837static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2838{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002839 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002840 struct wm8994_pdata *pdata = wm8994->pdata;
2841 struct snd_kcontrol_new controls[] = {
2842 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2843 wm8994->retune_mobile_enum,
2844 wm8994_get_retune_mobile_enum,
2845 wm8994_put_retune_mobile_enum),
2846 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2847 wm8994->retune_mobile_enum,
2848 wm8994_get_retune_mobile_enum,
2849 wm8994_put_retune_mobile_enum),
2850 SOC_ENUM_EXT("AIF2 EQ Mode",
2851 wm8994->retune_mobile_enum,
2852 wm8994_get_retune_mobile_enum,
2853 wm8994_put_retune_mobile_enum),
2854 };
2855 int ret, i, j;
2856 const char **t;
2857
2858 /* We need an array of texts for the enum API but the number
2859 * of texts is likely to be less than the number of
2860 * configurations due to the sample rate dependency of the
2861 * configurations. */
2862 wm8994->num_retune_mobile_texts = 0;
2863 wm8994->retune_mobile_texts = NULL;
2864 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2865 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2866 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2867 wm8994->retune_mobile_texts[j]) == 0)
2868 break;
2869 }
2870
2871 if (j != wm8994->num_retune_mobile_texts)
2872 continue;
2873
2874 /* Expand the array... */
2875 t = krealloc(wm8994->retune_mobile_texts,
2876 sizeof(char *) *
2877 (wm8994->num_retune_mobile_texts + 1),
2878 GFP_KERNEL);
2879 if (t == NULL)
2880 continue;
2881
2882 /* ...store the new entry... */
2883 t[wm8994->num_retune_mobile_texts] =
2884 pdata->retune_mobile_cfgs[i].name;
2885
2886 /* ...and remember the new version. */
2887 wm8994->num_retune_mobile_texts++;
2888 wm8994->retune_mobile_texts = t;
2889 }
2890
2891 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2892 wm8994->num_retune_mobile_texts);
2893
2894 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2895 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2896
Liam Girdwood022658b2012-02-03 17:43:09 +00002897 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002898 ARRAY_SIZE(controls));
2899 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002900 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002901 "Failed to add ReTune Mobile controls: %d\n", ret);
2902}
2903
2904static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2905{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002906 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002907 struct wm8994_pdata *pdata = wm8994->pdata;
2908 int ret, i;
2909
2910 if (!pdata)
2911 return;
2912
2913 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2914 pdata->lineout2_diff,
2915 pdata->lineout1fb,
2916 pdata->lineout2fb,
2917 pdata->jd_scthr,
2918 pdata->jd_thr,
2919 pdata->micbias1_lvl,
2920 pdata->micbias2_lvl);
2921
2922 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2923
2924 if (pdata->num_drc_cfgs) {
2925 struct snd_kcontrol_new controls[] = {
2926 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2927 wm8994_get_drc_enum, wm8994_put_drc_enum),
2928 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2929 wm8994_get_drc_enum, wm8994_put_drc_enum),
2930 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2931 wm8994_get_drc_enum, wm8994_put_drc_enum),
2932 };
2933
2934 /* We need an array of texts for the enum API */
Mark Brown7270ceb2011-12-01 14:00:19 +00002935 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
2936 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002937 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002938 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002939 "Failed to allocate %d DRC config texts\n",
2940 pdata->num_drc_cfgs);
2941 return;
2942 }
2943
2944 for (i = 0; i < pdata->num_drc_cfgs; i++)
2945 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2946
2947 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2948 wm8994->drc_enum.texts = wm8994->drc_texts;
2949
Liam Girdwood022658b2012-02-03 17:43:09 +00002950 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002951 ARRAY_SIZE(controls));
2952 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002953 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002954 "Failed to add DRC mode controls: %d\n", ret);
2955
2956 for (i = 0; i < WM8994_NUM_DRC; i++)
2957 wm8994_set_drc(codec, i);
2958 }
2959
2960 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2961 pdata->num_retune_mobile_cfgs);
2962
2963 if (pdata->num_retune_mobile_cfgs)
2964 wm8994_handle_retune_mobile_pdata(wm8994);
2965 else
Liam Girdwood022658b2012-02-03 17:43:09 +00002966 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002967 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002968
2969 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2970 if (pdata->micbias[i]) {
2971 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2972 pdata->micbias[i] & 0xffff);
2973 }
2974 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002975}
2976
Mark Brown88766982010-03-29 20:57:12 +01002977/**
2978 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2979 *
2980 * @codec: WM8994 codec
2981 * @jack: jack to report detection events on
2982 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01002983 *
2984 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2985 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002986 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002987 * be configured using snd_soc_jack_add_gpios() instead.
2988 *
2989 * Configuration of detection levels is available via the micbias1_lvl
2990 * and micbias2_lvl platform data members.
2991 */
2992int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00002993 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01002994{
Mark Brownb2c812e2010-04-14 15:35:19 +09002995 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002996 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01002997 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00002998 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01002999
Mark Brown87092e32012-02-06 18:50:39 +00003000 if (control->type != WM8994) {
3001 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003002 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003003 }
Mark Brown3a423152010-11-26 15:21:06 +00003004
Mark Brown88766982010-03-29 20:57:12 +01003005 switch (micbias) {
3006 case 1:
3007 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003008 if (jack)
3009 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3010 "MICBIAS1");
3011 else
3012 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3013 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003014 break;
3015 case 2:
3016 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003017 if (jack)
3018 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3019 "MICBIAS1");
3020 else
3021 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3022 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003023 break;
3024 default:
Mark Brown87092e32012-02-06 18:50:39 +00003025 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003026 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003027 }
Mark Brown88766982010-03-29 20:57:12 +01003028
Mark Brown87092e32012-02-06 18:50:39 +00003029 if (ret != 0)
3030 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3031 micbias, ret);
3032
3033 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3034 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003035
3036 /* Store the configuration */
3037 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003038 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003039
3040 /* If either of the jacks is set up then enable detection */
3041 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3042 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003043 else
Mark Brown88766982010-03-29 20:57:12 +01003044 reg = 0;
3045
3046 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3047
Mark Brown87092e32012-02-06 18:50:39 +00003048 snd_soc_dapm_sync(&codec->dapm);
3049
Mark Brown88766982010-03-29 20:57:12 +01003050 return 0;
3051}
3052EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3053
3054static irqreturn_t wm8994_mic_irq(int irq, void *data)
3055{
3056 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003057 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01003058 int reg;
3059 int report;
3060
Mark Brown7116f452010-12-29 13:05:21 +00003061#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003062 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003063#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003064
Mark Brown88766982010-03-29 20:57:12 +01003065 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3066 if (reg < 0) {
3067 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3068 reg);
3069 return IRQ_HANDLED;
3070 }
3071
3072 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
3073
3074 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003075 if (reg & WM8994_MIC1_DET_STS) {
3076 if (priv->micdet[0].detecting)
3077 report = SND_JACK_HEADSET;
3078 }
3079 if (reg & WM8994_MIC1_SHRT_STS) {
3080 if (priv->micdet[0].detecting)
3081 report = SND_JACK_HEADPHONE;
3082 else
3083 report |= SND_JACK_BTN_0;
3084 }
3085 if (report)
3086 priv->micdet[0].detecting = false;
3087 else
3088 priv->micdet[0].detecting = true;
3089
Mark Brown88766982010-03-29 20:57:12 +01003090 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003091 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003092
3093 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003094 if (reg & WM8994_MIC2_DET_STS) {
3095 if (priv->micdet[1].detecting)
3096 report = SND_JACK_HEADSET;
3097 }
3098 if (reg & WM8994_MIC2_SHRT_STS) {
3099 if (priv->micdet[1].detecting)
3100 report = SND_JACK_HEADPHONE;
3101 else
3102 report |= SND_JACK_BTN_0;
3103 }
3104 if (report)
3105 priv->micdet[1].detecting = false;
3106 else
3107 priv->micdet[1].detecting = true;
3108
Mark Brown88766982010-03-29 20:57:12 +01003109 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003110 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003111
3112 return IRQ_HANDLED;
3113}
3114
Mark Brown821edd22010-11-26 15:21:09 +00003115/* Default microphone detection handler for WM8958 - the user can
3116 * override this if they wish.
3117 */
3118static void wm8958_default_micdet(u16 status, void *data)
3119{
3120 struct snd_soc_codec *codec = data;
3121 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003122 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003123
Mark Browna1691342011-11-30 14:56:40 +00003124 dev_dbg(codec->dev, "MICDET %x\n", status);
3125
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003126 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003127 if (!(status & WM8958_MICD_STS)) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003128 if (!wm8994->jackdet) {
3129 /* If nothing present then clear our statuses */
3130 dev_dbg(codec->dev, "Detected open circuit\n");
3131 wm8994->jack_mic = false;
3132 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003133
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003134 wm8958_micd_set_rate(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003135
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003136 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3137 wm8994->btn_mask |
3138 SND_JACK_HEADSET);
3139 }
Mark Brownb00adf72011-08-13 11:57:18 +09003140 return;
3141 }
3142
3143 /* If the measurement is showing a high impedence we've got a
3144 * microphone.
3145 */
Mark Brown157a75e2011-11-30 13:43:51 +00003146 if (wm8994->mic_detecting && (status & 0x600)) {
Mark Brownb00adf72011-08-13 11:57:18 +09003147 dev_dbg(codec->dev, "Detected microphone\n");
3148
Mark Brown157a75e2011-11-30 13:43:51 +00003149 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003150 wm8994->jack_mic = true;
3151
3152 wm8958_micd_set_rate(codec);
3153
3154 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3155 SND_JACK_HEADSET);
3156 }
3157
3158
Mark Brown7c08b512012-01-26 18:33:24 +00003159 if (wm8994->mic_detecting && status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003160 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003161 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003162
3163 wm8958_micd_set_rate(codec);
3164
3165 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3166 SND_JACK_HEADSET);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003167
3168 /* If we have jackdet that will detect removal */
3169 if (wm8994->jackdet) {
3170 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3171 WM8958_MICD_ENA, 0);
3172
3173 wm1811_jackdet_set_mode(codec,
3174 WM1811_JACKDET_MODE_JACK);
3175 }
Mark Brownb00adf72011-08-13 11:57:18 +09003176 }
3177
3178 /* Report short circuit as a button */
3179 if (wm8994->jack_mic) {
Mark Brown4585790d2011-11-30 10:55:14 +00003180 report = 0;
Mark Brownb00adf72011-08-13 11:57:18 +09003181 if (status & 0x4)
Mark Brown4585790d2011-11-30 10:55:14 +00003182 report |= SND_JACK_BTN_0;
3183
3184 if (status & 0x8)
3185 report |= SND_JACK_BTN_1;
3186
3187 if (status & 0x10)
3188 report |= SND_JACK_BTN_2;
3189
3190 if (status & 0x20)
3191 report |= SND_JACK_BTN_3;
3192
3193 if (status & 0x40)
3194 report |= SND_JACK_BTN_4;
3195
3196 if (status & 0x80)
3197 report |= SND_JACK_BTN_5;
3198
3199 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3200 wm8994->btn_mask);
Mark Brownb00adf72011-08-13 11:57:18 +09003201 }
Mark Brown821edd22010-11-26 15:21:09 +00003202}
3203
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003204static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3205{
3206 struct wm8994_priv *wm8994 = data;
3207 struct snd_soc_codec *codec = wm8994->codec;
3208 int reg;
3209
3210 mutex_lock(&wm8994->accdet_lock);
3211
3212 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3213 if (reg < 0) {
3214 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3215 mutex_unlock(&wm8994->accdet_lock);
3216 return IRQ_NONE;
3217 }
3218
3219 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3220
3221 if (reg & WM1811_JACKDET_LVL) {
3222 dev_dbg(codec->dev, "Jack detected\n");
3223
3224 snd_soc_jack_report(wm8994->micdet[0].jack,
3225 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3226
3227 /*
3228 * Start off measument of microphone impedence to find
3229 * out what's actually there.
3230 */
3231 wm8994->mic_detecting = true;
3232 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3233 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3234 WM8958_MICD_ENA, WM8958_MICD_ENA);
3235 } else {
3236 dev_dbg(codec->dev, "Jack not detected\n");
3237
3238 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3239 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3240 wm8994->btn_mask);
3241
3242 wm8994->mic_detecting = false;
3243 wm8994->jack_mic = false;
3244 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3245 WM8958_MICD_ENA, 0);
3246 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3247 }
3248
3249 mutex_unlock(&wm8994->accdet_lock);
3250
3251 return IRQ_HANDLED;
3252}
3253
Mark Brown821edd22010-11-26 15:21:09 +00003254/**
3255 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3256 *
3257 * @codec: WM8958 codec
3258 * @jack: jack to report detection events on
3259 *
3260 * Enable microphone detection functionality for the WM8958. By
3261 * default simple detection which supports the detection of up to 6
3262 * buttons plus video and microphone functionality is supported.
3263 *
3264 * The WM8958 has an advanced jack detection facility which is able to
3265 * support complex accessory detection, especially when used in
3266 * conjunction with external circuitry. In order to provide maximum
3267 * flexiblity a callback is provided which allows a completely custom
3268 * detection algorithm.
3269 */
3270int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3271 wm8958_micdet_cb cb, void *cb_data)
3272{
3273 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003274 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003275 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003276
Mark Brown81204c82011-05-24 17:35:53 +08003277 switch (control->type) {
3278 case WM1811:
3279 case WM8958:
3280 break;
3281 default:
Mark Brown821edd22010-11-26 15:21:09 +00003282 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003283 }
Mark Brown821edd22010-11-26 15:21:09 +00003284
3285 if (jack) {
3286 if (!cb) {
3287 dev_dbg(codec->dev, "Using default micdet callback\n");
3288 cb = wm8958_default_micdet;
3289 cb_data = codec;
3290 }
3291
Mark Brown4cdf5e42011-11-29 14:36:17 +00003292 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
3293
Mark Brown821edd22010-11-26 15:21:09 +00003294 wm8994->micdet[0].jack = jack;
3295 wm8994->jack_cb = cb;
3296 wm8994->jack_cb_data = cb_data;
3297
Mark Brown157a75e2011-11-30 13:43:51 +00003298 wm8994->mic_detecting = true;
Mark Brownb00adf72011-08-13 11:57:18 +09003299 wm8994->jack_mic = false;
3300
3301 wm8958_micd_set_rate(codec);
3302
Mark Brown4585790d2011-11-30 10:55:14 +00003303 /* Detect microphones and short circuits by default */
3304 if (wm8994->pdata->micd_lvl_sel)
3305 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3306 else
3307 micd_lvl_sel = 0x41;
3308
3309 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3310 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3311 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3312
Mark Brownb00adf72011-08-13 11:57:18 +09003313 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003314 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003315
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003316 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3317
3318 /*
3319 * If we can use jack detection start off with that,
3320 * otherwise jump straight to microphone detection.
3321 */
3322 if (wm8994->jackdet) {
3323 snd_soc_update_bits(codec, WM8994_LDO_1,
3324 WM8994_LDO1_DISCH, 0);
3325 wm1811_jackdet_set_mode(codec,
3326 WM1811_JACKDET_MODE_JACK);
3327 } else {
3328 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3329 WM8958_MICD_ENA, WM8958_MICD_ENA);
3330 }
3331
Mark Brown821edd22010-11-26 15:21:09 +00003332 } else {
3333 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3334 WM8958_MICD_ENA, 0);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003335 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown821edd22010-11-26 15:21:09 +00003336 }
3337
3338 return 0;
3339}
3340EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3341
3342static irqreturn_t wm8958_mic_irq(int irq, void *data)
3343{
3344 struct wm8994_priv *wm8994 = data;
3345 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003346 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003347
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003348 mutex_lock(&wm8994->accdet_lock);
3349
3350 /*
3351 * Jack detection may have detected a removal simulataneously
3352 * with an update of the MICDET status; if so it will have
3353 * stopped detection and we can ignore this interrupt.
3354 */
3355 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA)) {
3356 mutex_unlock(&wm8994->accdet_lock);
3357 return IRQ_HANDLED;
3358 }
3359
Mark Brown19940b32011-08-19 18:05:05 +09003360 /* We may occasionally read a detection without an impedence
3361 * range being provided - if that happens loop again.
3362 */
3363 count = 10;
3364 do {
3365 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3366 if (reg < 0) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003367 mutex_unlock(&wm8994->accdet_lock);
Mark Brown19940b32011-08-19 18:05:05 +09003368 dev_err(codec->dev,
3369 "Failed to read mic detect status: %d\n",
3370 reg);
3371 return IRQ_NONE;
3372 }
Mark Brown821edd22010-11-26 15:21:09 +00003373
Mark Brown19940b32011-08-19 18:05:05 +09003374 if (!(reg & WM8958_MICD_VALID)) {
3375 dev_dbg(codec->dev, "Mic detect data not valid\n");
3376 goto out;
3377 }
3378
3379 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3380 break;
3381
3382 msleep(1);
3383 } while (count--);
3384
3385 if (count == 0)
3386 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003387
Mark Brown7116f452010-12-29 13:05:21 +00003388#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003389 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003390#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003391
Mark Brown821edd22010-11-26 15:21:09 +00003392 if (wm8994->jack_cb)
3393 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3394 else
3395 dev_warn(codec->dev, "Accessory detection with no callback\n");
3396
3397out:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003398 mutex_unlock(&wm8994->accdet_lock);
3399
Mark Brown821edd22010-11-26 15:21:09 +00003400 return IRQ_HANDLED;
3401}
3402
Mark Brown3b1af3f2011-07-14 12:38:18 +09003403static irqreturn_t wm8994_fifo_error(int irq, void *data)
3404{
3405 struct snd_soc_codec *codec = data;
3406
3407 dev_err(codec->dev, "FIFO error\n");
3408
3409 return IRQ_HANDLED;
3410}
3411
Mark Brownf0b182b2011-08-16 12:01:27 +09003412static irqreturn_t wm8994_temp_warn(int irq, void *data)
3413{
3414 struct snd_soc_codec *codec = data;
3415
3416 dev_err(codec->dev, "Thermal warning\n");
3417
3418 return IRQ_HANDLED;
3419}
3420
3421static irqreturn_t wm8994_temp_shut(int irq, void *data)
3422{
3423 struct snd_soc_codec *codec = data;
3424
3425 dev_crit(codec->dev, "Thermal shutdown\n");
3426
3427 return IRQ_HANDLED;
3428}
3429
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003430static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003431{
Mark Brownd9a76662011-07-24 12:49:52 +01003432 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003433 struct wm8994_priv *wm8994;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003434 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003435 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003436 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003437
Mark Brownd9a76662011-07-24 12:49:52 +01003438 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003439
Mark Brown7270ceb2011-12-01 14:00:19 +00003440 wm8994 = devm_kzalloc(codec->dev, sizeof(struct wm8994_priv),
3441 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003442 if (wm8994 == NULL)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003443 return -ENOMEM;
Mark Brownb2c812e2010-04-14 15:35:19 +09003444 snd_soc_codec_set_drvdata(codec, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003445
Mark Brownd9a76662011-07-24 12:49:52 +01003446 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003447
3448 wm8994->wm8994 = dev_get_drvdata(codec->dev->parent);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003449 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3450 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003451
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003452 mutex_init(&wm8994->accdet_lock);
3453
Mark Brownc7ebf932011-07-12 19:47:59 +09003454 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3455 init_completion(&wm8994->fll_locked[i]);
3456
Mark Brown9b7c5252011-02-17 20:05:44 -08003457 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3458 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3459 else if (wm8994->pdata && wm8994->pdata->irq_base)
3460 wm8994->micdet_irq = wm8994->pdata->irq_base +
3461 WM8994_IRQ_MIC1_DET;
3462
Mark Brown39fb51a2010-11-26 17:23:43 +00003463 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003464 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003465
Mark Brownf959dee2012-01-31 16:16:47 +00003466 /* By default use idle_bias_off, will override for WM8994 */
3467 codec->dapm.idle_bias_off = 1;
3468
Mark Brown9e6e96a2010-01-29 17:47:12 +00003469 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003470 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003471 switch (control->type) {
3472 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003473 /* Single ended line outputs should have VMID on. */
3474 if (!wm8994->pdata->lineout1_diff ||
3475 !wm8994->pdata->lineout2_diff)
3476 codec->dapm.idle_bias_off = 0;
3477
Mark Brown3a423152010-11-26 15:21:06 +00003478 switch (wm8994->revision) {
3479 case 2:
3480 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003481 wm8994->hubs.dcs_codes_l = -5;
3482 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003483 wm8994->hubs.hp_startup_mode = 1;
3484 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003485 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003486 break;
3487 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003488 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003489 break;
3490 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003491 break;
Mark Brown3a423152010-11-26 15:21:06 +00003492
3493 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003494 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003495 break;
Mark Brown3a423152010-11-26 15:21:06 +00003496
Mark Brown81204c82011-05-24 17:35:53 +08003497 case WM1811:
3498 wm8994->hubs.dcs_readback_mode = 2;
3499 wm8994->hubs.no_series_update = 1;
3500
3501 switch (wm8994->revision) {
3502 case 0:
3503 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003504 case 2:
3505 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003506 wm8994->hubs.dcs_codes_l = -9;
3507 wm8994->hubs.dcs_codes_r = -5;
Mark Brown81204c82011-05-24 17:35:53 +08003508 break;
3509 default:
3510 break;
3511 }
3512
3513 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3514 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3515 break;
3516
Mark Brown9e6e96a2010-01-29 17:47:12 +00003517 default:
3518 break;
3519 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003520
Mark Brown2a8a8562011-07-24 12:20:41 +01003521 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003522 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003523 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003524 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003525 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003526 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003527
Mark Brown2a8a8562011-07-24 12:20:41 +01003528 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003529 wm_hubs_dcs_done, "DC servo done",
3530 &wm8994->hubs);
3531 if (ret == 0)
3532 wm8994->hubs.dcs_done_irq = true;
3533
Mark Brown3a423152010-11-26 15:21:06 +00003534 switch (control->type) {
3535 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003536 if (wm8994->micdet_irq) {
3537 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3538 wm8994_mic_irq,
3539 IRQF_TRIGGER_RISING,
3540 "Mic1 detect",
3541 wm8994);
3542 if (ret != 0)
3543 dev_warn(codec->dev,
3544 "Failed to request Mic1 detect IRQ: %d\n",
3545 ret);
3546 }
Mark Brown88766982010-03-29 20:57:12 +01003547
Mark Brown2a8a8562011-07-24 12:20:41 +01003548 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003549 WM8994_IRQ_MIC1_SHRT,
3550 wm8994_mic_irq, "Mic 1 short",
3551 wm8994);
3552 if (ret != 0)
3553 dev_warn(codec->dev,
3554 "Failed to request Mic1 short IRQ: %d\n",
3555 ret);
Mark Brown88766982010-03-29 20:57:12 +01003556
Mark Brown2a8a8562011-07-24 12:20:41 +01003557 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003558 WM8994_IRQ_MIC2_DET,
3559 wm8994_mic_irq, "Mic 2 detect",
3560 wm8994);
3561 if (ret != 0)
3562 dev_warn(codec->dev,
3563 "Failed to request Mic2 detect IRQ: %d\n",
3564 ret);
Mark Brown88766982010-03-29 20:57:12 +01003565
Mark Brown2a8a8562011-07-24 12:20:41 +01003566 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003567 WM8994_IRQ_MIC2_SHRT,
3568 wm8994_mic_irq, "Mic 2 short",
3569 wm8994);
3570 if (ret != 0)
3571 dev_warn(codec->dev,
3572 "Failed to request Mic2 short IRQ: %d\n",
3573 ret);
3574 break;
Mark Brown821edd22010-11-26 15:21:09 +00003575
3576 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003577 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003578 if (wm8994->micdet_irq) {
3579 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3580 wm8958_mic_irq,
3581 IRQF_TRIGGER_RISING,
3582 "Mic detect",
3583 wm8994);
3584 if (ret != 0)
3585 dev_warn(codec->dev,
3586 "Failed to request Mic detect IRQ: %d\n",
3587 ret);
3588 }
Mark Brown3a423152010-11-26 15:21:06 +00003589 }
Mark Brown88766982010-03-29 20:57:12 +01003590
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003591 switch (control->type) {
3592 case WM1811:
3593 if (wm8994->revision > 1) {
3594 ret = wm8994_request_irq(wm8994->wm8994,
3595 WM8994_IRQ_GPIO(6),
3596 wm1811_jackdet_irq, "JACKDET",
3597 wm8994);
3598 if (ret == 0)
3599 wm8994->jackdet = true;
3600 }
3601 break;
3602 default:
3603 break;
3604 }
3605
Mark Brownc7ebf932011-07-12 19:47:59 +09003606 wm8994->fll_locked_irq = true;
3607 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01003608 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09003609 WM8994_IRQ_FLL1_LOCK + i,
3610 wm8994_fll_locked_irq, "FLL lock",
3611 &wm8994->fll_locked[i]);
3612 if (ret != 0)
3613 wm8994->fll_locked_irq = false;
3614 }
3615
Mark Brown27060b3c2012-02-06 18:42:14 +00003616 /* Make sure we can read from the GPIOs if they're inputs */
3617 pm_runtime_get_sync(codec->dev);
3618
Mark Brown9e6e96a2010-01-29 17:47:12 +00003619 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3620 * configured on init - if a system wants to do this dynamically
3621 * at runtime we can deal with that then.
3622 */
Mark Brownd9a76662011-07-24 12:49:52 +01003623 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003624 if (ret < 0) {
3625 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003626 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003627 }
Mark Brownd9a76662011-07-24 12:49:52 +01003628 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003629 wm8994->lrclk_shared[0] = 1;
3630 wm8994_dai[0].symmetric_rates = 1;
3631 } else {
3632 wm8994->lrclk_shared[0] = 0;
3633 }
3634
Mark Brownd9a76662011-07-24 12:49:52 +01003635 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003636 if (ret < 0) {
3637 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003638 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003639 }
Mark Brownd9a76662011-07-24 12:49:52 +01003640 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003641 wm8994->lrclk_shared[1] = 1;
3642 wm8994_dai[1].symmetric_rates = 1;
3643 } else {
3644 wm8994->lrclk_shared[1] = 0;
3645 }
3646
Mark Brown27060b3c2012-02-06 18:42:14 +00003647 pm_runtime_put(codec->dev);
3648
Mark Brown9e6e96a2010-01-29 17:47:12 +00003649 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003650 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3651 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003652 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3653 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003654 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3655 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003656 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3657 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003658 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3659 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003660 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3661 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003662 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3663 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003664 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3665 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003666 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3667 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003668 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3669 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003670 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3671 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003672 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3673 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003674 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3675 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003676 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3677 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003678 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3679 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003680 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3681 WM8994_DAC2_VU, WM8994_DAC2_VU);
3682
3683 /* Set the low bit of the 3D stereo depth so TLV matches */
3684 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3685 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3686 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3687 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3688 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3689 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3690 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3691 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3692 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3693
Mark Brown5b739672011-07-06 00:08:43 -07003694 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3695 * use this; it only affects behaviour on idle TDM clock
3696 * cycles. */
3697 switch (control->type) {
3698 case WM8994:
3699 case WM8958:
3700 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3701 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3702 break;
3703 default:
3704 break;
3705 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003706
Mark Brown500fa302011-11-29 19:58:19 +00003707 /* Put MICBIAS into bypass mode by default on newer devices */
3708 switch (control->type) {
3709 case WM8958:
3710 case WM1811:
3711 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3712 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3713 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3714 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3715 break;
3716 default:
3717 break;
3718 }
3719
Mark Brown9e6e96a2010-01-29 17:47:12 +00003720 wm8994_update_class_w(codec);
3721
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003722 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003723
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003724 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00003725 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003726 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003727 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003728 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003729
3730 switch (control->type) {
3731 case WM8994:
3732 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3733 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003734 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003735 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3736 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003737 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3738 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003739 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3740 ARRAY_SIZE(wm8994_dac_revd_widgets));
3741 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003742 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3743 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003744 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3745 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003746 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3747 ARRAY_SIZE(wm8994_dac_widgets));
3748 }
Mark Brownc4431df2010-11-26 15:21:07 +00003749 break;
3750 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00003751 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00003752 ARRAY_SIZE(wm8958_snd_controls));
3753 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3754 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003755 if (wm8994->revision < 1) {
3756 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3757 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3758 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3759 ARRAY_SIZE(wm8994_adc_revd_widgets));
3760 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3761 ARRAY_SIZE(wm8994_dac_revd_widgets));
3762 } else {
3763 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3764 ARRAY_SIZE(wm8994_lateclk_widgets));
3765 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3766 ARRAY_SIZE(wm8994_adc_widgets));
3767 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3768 ARRAY_SIZE(wm8994_dac_widgets));
3769 }
Mark Brownc4431df2010-11-26 15:21:07 +00003770 break;
Mark Brown81204c82011-05-24 17:35:53 +08003771
3772 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00003773 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08003774 ARRAY_SIZE(wm8958_snd_controls));
3775 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3776 ARRAY_SIZE(wm8958_dapm_widgets));
3777 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3778 ARRAY_SIZE(wm8994_lateclk_widgets));
3779 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3780 ARRAY_SIZE(wm8994_adc_widgets));
3781 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3782 ARRAY_SIZE(wm8994_dac_widgets));
3783 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003784 }
3785
3786
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003787 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003788 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003789
Mark Brownc4431df2010-11-26 15:21:07 +00003790 switch (control->type) {
3791 case WM8994:
3792 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3793 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003794
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003795 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003796 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3797 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003798 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3799 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3800 } else {
3801 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3802 ARRAY_SIZE(wm8994_lateclk_intercon));
3803 }
Mark Brownc4431df2010-11-26 15:21:07 +00003804 break;
3805 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003806 if (wm8994->revision < 1) {
3807 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3808 ARRAY_SIZE(wm8994_revd_intercon));
3809 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3810 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3811 } else {
3812 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3813 ARRAY_SIZE(wm8994_lateclk_intercon));
3814 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3815 ARRAY_SIZE(wm8958_intercon));
3816 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003817
3818 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003819 break;
Mark Brown81204c82011-05-24 17:35:53 +08003820 case WM1811:
3821 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3822 ARRAY_SIZE(wm8994_lateclk_intercon));
3823 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3824 ARRAY_SIZE(wm8958_intercon));
3825 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003826 }
3827
Mark Brown9e6e96a2010-01-29 17:47:12 +00003828 return 0;
3829
Mark Brown88766982010-03-29 20:57:12 +01003830err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003831 if (wm8994->jackdet)
3832 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003833 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
3834 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
3835 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003836 if (wm8994->micdet_irq)
3837 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003838 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003839 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003840 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01003841 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003842 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003843 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3844 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3845 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00003846
Mark Brown9e6e96a2010-01-29 17:47:12 +00003847 return ret;
3848}
3849
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003850static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003851{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003852 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003853 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09003854 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003855
3856 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003857
Mark Brown39fb51a2010-11-26 17:23:43 +00003858 pm_runtime_disable(codec->dev);
3859
Mark Brownc7ebf932011-07-12 19:47:59 +09003860 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003861 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003862 &wm8994->fll_locked[i]);
3863
Mark Brown2a8a8562011-07-24 12:20:41 +01003864 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003865 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003866 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3867 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3868 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003869
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003870 if (wm8994->jackdet)
3871 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
3872
Mark Brown3a423152010-11-26 15:21:06 +00003873 switch (control->type) {
3874 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003875 if (wm8994->micdet_irq)
3876 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003877 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003878 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003879 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00003880 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003881 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003882 wm8994);
3883 break;
Mark Brown821edd22010-11-26 15:21:09 +00003884
Mark Brown81204c82011-05-24 17:35:53 +08003885 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00003886 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003887 if (wm8994->micdet_irq)
3888 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003889 break;
Mark Brown3a423152010-11-26 15:21:06 +00003890 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003891 if (wm8994->mbc)
3892 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003893 if (wm8994->mbc_vss)
3894 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003895 if (wm8994->enh_eq)
3896 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003897 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003898
3899 return 0;
3900}
3901
Mark Brown1b39bf32011-12-29 12:18:53 +00003902static int wm8994_soc_volatile(struct snd_soc_codec *codec,
3903 unsigned int reg)
3904{
3905 return true;
3906}
3907
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003908static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3909 .probe = wm8994_codec_probe,
3910 .remove = wm8994_codec_remove,
3911 .suspend = wm8994_suspend,
3912 .resume = wm8994_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003913 .set_bias_level = wm8994_set_bias_level,
Mark Brown1b39bf32011-12-29 12:18:53 +00003914 .reg_cache_size = WM8994_MAX_REGISTER,
3915 .volatile_register = wm8994_soc_volatile,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003916};
3917
3918static int __devinit wm8994_probe(struct platform_device *pdev)
3919{
3920 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3921 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3922}
3923
3924static int __devexit wm8994_remove(struct platform_device *pdev)
3925{
3926 snd_soc_unregister_codec(&pdev->dev);
3927 return 0;
3928}
3929
Mark Brown9e6e96a2010-01-29 17:47:12 +00003930static struct platform_driver wm8994_codec_driver = {
3931 .driver = {
3932 .name = "wm8994-codec",
3933 .owner = THIS_MODULE,
3934 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003935 .probe = wm8994_probe,
3936 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003937};
3938
Mark Brown5bbcc3c2011-11-23 22:52:08 +00003939module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003940
3941MODULE_DESCRIPTION("ASoC WM8994 driver");
3942MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3943MODULE_LICENSE("GPL");
3944MODULE_ALIAS("platform:wm8994-codec");