blob: 3a69ec0d5afd3f2510457120050af77617e5c7c5 [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 Brownf647e152012-02-07 17:24:19 +0000797 (0x3 << 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
1476SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1477SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001478SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001479SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
1480
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
1485SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
Axel Lin35024f42011-10-20 12:13:24 +08001486SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", "AIF3 Capture", 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
1601 /* AIF1 outputs */
1602 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1603 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1604 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1605
1606 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1607 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1608 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1609
Mark Browna3257ba2010-07-19 14:02:34 +01001610 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1611 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1612 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1613
1614 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1615 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1616 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1617
Mark Brown9e6e96a2010-01-29 17:47:12 +00001618 /* Pin level routing for AIF3 */
1619 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1620 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1621 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1622 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1623
Mark Brown9e6e96a2010-01-29 17:47:12 +00001624 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1625 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1626 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1627 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1628 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1629 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1630 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1631
1632 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001633 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1634 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1635 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1636 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1637 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1638
Mark Brown9e6e96a2010-01-29 17:47:12 +00001639 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1640 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1641 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1642 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1643 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1644
1645 /* DAC2/AIF2 outputs */
1646 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001647 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1648 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1649 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1650 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1651 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1652
1653 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001654 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1655 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1656 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1657 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1658 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1659
Mark Brown7f94de42011-02-03 16:27:34 +00001660 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1661 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1662 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1663 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1664
Mark Brown9e6e96a2010-01-29 17:47:12 +00001665 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1666
1667 /* AIF3 output */
1668 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1669 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1670 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1671 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1672 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1673 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1674 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1675 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1676
1677 /* Sidetone */
1678 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1679 { "Left Sidetone", "DMIC2", "DMIC2L" },
1680 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1681 { "Right Sidetone", "DMIC2", "DMIC2R" },
1682
1683 /* Output stages */
1684 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1685 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1686
1687 { "SPKL", "DAC1 Switch", "DAC1L" },
1688 { "SPKL", "DAC2 Switch", "DAC2L" },
1689
1690 { "SPKR", "DAC1 Switch", "DAC1R" },
1691 { "SPKR", "DAC2 Switch", "DAC2R" },
1692
1693 { "Left Headphone Mux", "DAC", "DAC1L" },
1694 { "Right Headphone Mux", "DAC", "DAC1R" },
1695};
1696
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001697static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1698 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1699 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1700 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1701 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1702 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1703 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1704 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1705 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1706};
1707
1708static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1709 { "DAC1L", NULL, "DAC1L Mixer" },
1710 { "DAC1R", NULL, "DAC1R Mixer" },
1711 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1712 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1713};
1714
Mark Brown6ed8f142011-02-03 16:27:35 +00001715static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1716 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1717 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1718 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1719 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001720 { "MICBIAS1", NULL, "CLK_SYS" },
1721 { "MICBIAS1", NULL, "MICBIAS Supply" },
1722 { "MICBIAS2", NULL, "CLK_SYS" },
1723 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001724};
1725
Mark Brownc4431df2010-11-26 15:21:07 +00001726static const struct snd_soc_dapm_route wm8994_intercon[] = {
1727 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1728 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001729 { "MICBIAS1", NULL, "VMID" },
1730 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001731};
1732
1733static const struct snd_soc_dapm_route wm8958_intercon[] = {
1734 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1735 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1736
1737 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1738 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1739 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1740 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1741
1742 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1743 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1744
1745 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1746};
1747
Mark Brown9e6e96a2010-01-29 17:47:12 +00001748/* The size in bits of the FLL divide multiplied by 10
1749 * to allow rounding later */
1750#define FIXED_FLL_SIZE ((1 << 16) * 10)
1751
1752struct fll_div {
1753 u16 outdiv;
1754 u16 n;
1755 u16 k;
1756 u16 clk_ref_div;
1757 u16 fll_fratio;
1758};
1759
1760static int wm8994_get_fll_config(struct fll_div *fll,
1761 int freq_in, int freq_out)
1762{
1763 u64 Kpart;
1764 unsigned int K, Ndiv, Nmod;
1765
1766 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1767
1768 /* Scale the input frequency down to <= 13.5MHz */
1769 fll->clk_ref_div = 0;
1770 while (freq_in > 13500000) {
1771 fll->clk_ref_div++;
1772 freq_in /= 2;
1773
1774 if (fll->clk_ref_div > 3)
1775 return -EINVAL;
1776 }
1777 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1778
1779 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1780 fll->outdiv = 3;
1781 while (freq_out * (fll->outdiv + 1) < 90000000) {
1782 fll->outdiv++;
1783 if (fll->outdiv > 63)
1784 return -EINVAL;
1785 }
1786 freq_out *= fll->outdiv + 1;
1787 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1788
1789 if (freq_in > 1000000) {
1790 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001791 } else if (freq_in > 256000) {
1792 fll->fll_fratio = 1;
1793 freq_in *= 2;
1794 } else if (freq_in > 128000) {
1795 fll->fll_fratio = 2;
1796 freq_in *= 4;
1797 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001798 fll->fll_fratio = 3;
1799 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001800 } else {
1801 fll->fll_fratio = 4;
1802 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001803 }
1804 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1805
1806 /* Now, calculate N.K */
1807 Ndiv = freq_out / freq_in;
1808
1809 fll->n = Ndiv;
1810 Nmod = freq_out % freq_in;
1811 pr_debug("Nmod=%d\n", Nmod);
1812
1813 /* Calculate fractional part - scale up so we can round. */
1814 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1815
1816 do_div(Kpart, freq_in);
1817
1818 K = Kpart & 0xFFFFFFFF;
1819
1820 if ((K % 10) >= 5)
1821 K += 5;
1822
1823 /* Move down to proper range now rounding is done */
1824 fll->k = K / 10;
1825
1826 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1827
1828 return 0;
1829}
1830
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001831static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001832 unsigned int freq_in, unsigned int freq_out)
1833{
Mark Brownb2c812e2010-04-14 15:35:19 +09001834 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01001835 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001836 int reg_offset, ret;
1837 struct fll_div fll;
1838 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001839 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001840 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001841
1842 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1843 & WM8994_AIF1CLK_ENA;
1844
1845 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1846 & WM8994_AIF2CLK_ENA;
1847
1848 switch (id) {
1849 case WM8994_FLL1:
1850 reg_offset = 0;
1851 id = 0;
1852 break;
1853 case WM8994_FLL2:
1854 reg_offset = 0x20;
1855 id = 1;
1856 break;
1857 default:
1858 return -EINVAL;
1859 }
1860
Mark Brown4b7ed832011-08-10 17:47:33 +09001861 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1862 was_enabled = reg & WM8994_FLL1_ENA;
1863
Mark Brown136ff2a2010-04-20 12:56:18 +09001864 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001865 case 0:
1866 /* Allow no source specification when stopping */
1867 if (freq_out)
1868 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001869 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001870 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001871 case WM8994_FLL_SRC_MCLK1:
1872 case WM8994_FLL_SRC_MCLK2:
1873 case WM8994_FLL_SRC_LRCLK:
1874 case WM8994_FLL_SRC_BCLK:
1875 break;
1876 default:
1877 return -EINVAL;
1878 }
1879
Mark Brown9e6e96a2010-01-29 17:47:12 +00001880 /* Are we changing anything? */
1881 if (wm8994->fll[id].src == src &&
1882 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1883 return 0;
1884
1885 /* If we're stopping the FLL redo the old config - no
1886 * registers will actually be written but we avoid GCC flow
1887 * analysis bugs spewing warnings.
1888 */
1889 if (freq_out)
1890 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1891 else
1892 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1893 wm8994->fll[id].out);
1894 if (ret < 0)
1895 return ret;
1896
1897 /* Gate the AIF clocks while we reclock */
1898 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1899 WM8994_AIF1CLK_ENA, 0);
1900 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1901 WM8994_AIF2CLK_ENA, 0);
1902
1903 /* We always need to disable the FLL while reconfiguring */
1904 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1905 WM8994_FLL1_ENA, 0);
1906
1907 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1908 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1909 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1910 WM8994_FLL1_OUTDIV_MASK |
1911 WM8994_FLL1_FRATIO_MASK, reg);
1912
1913 snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
1914
1915 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1916 WM8994_FLL1_N_MASK,
1917 fll.n << WM8994_FLL1_N_SHIFT);
1918
1919 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001920 WM8994_FLL1_REFCLK_DIV_MASK |
1921 WM8994_FLL1_REFCLK_SRC_MASK,
1922 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1923 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001924
Mark Brownf0f50392011-07-16 03:12:18 +09001925 /* Clear any pending completion from a previous failure */
1926 try_wait_for_completion(&wm8994->fll_locked[id]);
1927
Mark Brown9e6e96a2010-01-29 17:47:12 +00001928 /* Enable (with fractional mode if required) */
1929 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001930 /* Enable VMID if we need it */
1931 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001932 active_reference(codec);
1933
Mark Brown4b7ed832011-08-10 17:47:33 +09001934 switch (control->type) {
1935 case WM8994:
1936 vmid_reference(codec);
1937 break;
1938 case WM8958:
1939 if (wm8994->revision < 1)
1940 vmid_reference(codec);
1941 break;
1942 default:
1943 break;
1944 }
1945 }
1946
Mark Brown9e6e96a2010-01-29 17:47:12 +00001947 if (fll.k)
1948 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1949 else
1950 reg = WM8994_FLL1_ENA;
1951 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1952 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1953 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001954
Mark Brownc7ebf932011-07-12 19:47:59 +09001955 if (wm8994->fll_locked_irq) {
1956 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1957 msecs_to_jiffies(10));
1958 if (timeout == 0)
1959 dev_warn(codec->dev,
1960 "Timed out waiting for FLL lock\n");
1961 } else {
1962 msleep(5);
1963 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001964 } else {
1965 if (was_enabled) {
1966 switch (control->type) {
1967 case WM8994:
1968 vmid_dereference(codec);
1969 break;
1970 case WM8958:
1971 if (wm8994->revision < 1)
1972 vmid_dereference(codec);
1973 break;
1974 default:
1975 break;
1976 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00001977
1978 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001979 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00001980 }
1981
1982 wm8994->fll[id].in = freq_in;
1983 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001984 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001985
1986 /* Enable any gated AIF clocks */
1987 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1988 WM8994_AIF1CLK_ENA, aif1);
1989 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1990 WM8994_AIF2CLK_ENA, aif2);
1991
1992 configure_clock(codec);
1993
1994 return 0;
1995}
1996
Mark Brownc7ebf932011-07-12 19:47:59 +09001997static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
1998{
1999 struct completion *completion = data;
2000
2001 complete(completion);
2002
2003 return IRQ_HANDLED;
2004}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002005
Mark Brown66b47fd2010-07-08 11:25:43 +09002006static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2007
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002008static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2009 unsigned int freq_in, unsigned int freq_out)
2010{
2011 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2012}
2013
Mark Brown9e6e96a2010-01-29 17:47:12 +00002014static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2015 int clk_id, unsigned int freq, int dir)
2016{
2017 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002018 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002019 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002020
2021 switch (dai->id) {
2022 case 1:
2023 case 2:
2024 break;
2025
2026 default:
2027 /* AIF3 shares clocking with AIF1/2 */
2028 return -EINVAL;
2029 }
2030
2031 switch (clk_id) {
2032 case WM8994_SYSCLK_MCLK1:
2033 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2034 wm8994->mclk[0] = freq;
2035 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2036 dai->id, freq);
2037 break;
2038
2039 case WM8994_SYSCLK_MCLK2:
2040 /* TODO: Set GPIO AF */
2041 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2042 wm8994->mclk[1] = freq;
2043 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2044 dai->id, freq);
2045 break;
2046
2047 case WM8994_SYSCLK_FLL1:
2048 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2049 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2050 break;
2051
2052 case WM8994_SYSCLK_FLL2:
2053 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2054 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2055 break;
2056
Mark Brown66b47fd2010-07-08 11:25:43 +09002057 case WM8994_SYSCLK_OPCLK:
2058 /* Special case - a division (times 10) is given and
2059 * no effect on main clocking.
2060 */
2061 if (freq) {
2062 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2063 if (opclk_divs[i] == freq)
2064 break;
2065 if (i == ARRAY_SIZE(opclk_divs))
2066 return -EINVAL;
2067 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2068 WM8994_OPCLK_DIV_MASK, i);
2069 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2070 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2071 } else {
2072 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2073 WM8994_OPCLK_ENA, 0);
2074 }
2075
Mark Brown9e6e96a2010-01-29 17:47:12 +00002076 default:
2077 return -EINVAL;
2078 }
2079
2080 configure_clock(codec);
2081
2082 return 0;
2083}
2084
2085static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2086 enum snd_soc_bias_level level)
2087{
Mark Brownb6b05692010-08-13 12:58:20 +01002088 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002089 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002090
Mark Brown5f2f3892012-02-08 18:51:42 +00002091 wm_hubs_set_bias_level(codec, level);
2092
Mark Brown9e6e96a2010-01-29 17:47:12 +00002093 switch (level) {
2094 case SND_SOC_BIAS_ON:
2095 break;
2096
2097 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002098 /* MICBIAS into regulating mode */
2099 switch (control->type) {
2100 case WM8958:
2101 case WM1811:
2102 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2103 WM8958_MICB1_MODE, 0);
2104 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2105 WM8958_MICB2_MODE, 0);
2106 break;
2107 default:
2108 break;
2109 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002110
2111 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2112 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002113 break;
2114
2115 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002116 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002117 switch (control->type) {
2118 case WM8994:
2119 if (wm8994->revision < 4) {
2120 /* Tweak DC servo and DSP
2121 * configuration for improved
2122 * performance. */
2123 snd_soc_write(codec, 0x102, 0x3);
2124 snd_soc_write(codec, 0x56, 0x3);
2125 snd_soc_write(codec, 0x817, 0);
2126 snd_soc_write(codec, 0x102, 0);
2127 }
2128 break;
2129
2130 case WM8958:
2131 if (wm8994->revision == 0) {
2132 /* Optimise performance for rev A */
2133 snd_soc_write(codec, 0x102, 0x3);
2134 snd_soc_write(codec, 0xcb, 0x81);
2135 snd_soc_write(codec, 0x817, 0);
2136 snd_soc_write(codec, 0x102, 0);
2137
2138 snd_soc_update_bits(codec,
2139 WM8958_CHARGE_PUMP_2,
2140 WM8958_CP_DISCH,
2141 WM8958_CP_DISCH);
2142 }
2143 break;
Mark Brown81204c82011-05-24 17:35:53 +08002144
2145 case WM1811:
2146 if (wm8994->revision < 2) {
2147 snd_soc_write(codec, 0x102, 0x3);
2148 snd_soc_write(codec, 0x5d, 0x7e);
2149 snd_soc_write(codec, 0x5e, 0x0);
2150 snd_soc_write(codec, 0x102, 0x0);
2151 }
2152 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002153 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002154
2155 /* Discharge LINEOUT1 & 2 */
2156 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2157 WM8994_LINEOUT1_DISCH |
2158 WM8994_LINEOUT2_DISCH,
2159 WM8994_LINEOUT1_DISCH |
2160 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002161 }
2162
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002163 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2164 active_dereference(codec);
2165
Mark Brown500fa302011-11-29 19:58:19 +00002166 /* MICBIAS into bypass mode on newer devices */
2167 switch (control->type) {
2168 case WM8958:
2169 case WM1811:
2170 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2171 WM8958_MICB1_MODE,
2172 WM8958_MICB1_MODE);
2173 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2174 WM8958_MICB2_MODE,
2175 WM8958_MICB2_MODE);
2176 break;
2177 default:
2178 break;
2179 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002180 break;
2181
2182 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002183 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002184 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002185 break;
2186 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002187
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002188 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002189
Mark Brown9e6e96a2010-01-29 17:47:12 +00002190 return 0;
2191}
2192
2193static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2194{
2195 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002196 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2197 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002198 int ms_reg;
2199 int aif1_reg;
2200 int ms = 0;
2201 int aif1 = 0;
2202
2203 switch (dai->id) {
2204 case 1:
2205 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2206 aif1_reg = WM8994_AIF1_CONTROL_1;
2207 break;
2208 case 2:
2209 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2210 aif1_reg = WM8994_AIF2_CONTROL_1;
2211 break;
2212 default:
2213 return -EINVAL;
2214 }
2215
2216 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2217 case SND_SOC_DAIFMT_CBS_CFS:
2218 break;
2219 case SND_SOC_DAIFMT_CBM_CFM:
2220 ms = WM8994_AIF1_MSTR;
2221 break;
2222 default:
2223 return -EINVAL;
2224 }
2225
2226 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2227 case SND_SOC_DAIFMT_DSP_B:
2228 aif1 |= WM8994_AIF1_LRCLK_INV;
2229 case SND_SOC_DAIFMT_DSP_A:
2230 aif1 |= 0x18;
2231 break;
2232 case SND_SOC_DAIFMT_I2S:
2233 aif1 |= 0x10;
2234 break;
2235 case SND_SOC_DAIFMT_RIGHT_J:
2236 break;
2237 case SND_SOC_DAIFMT_LEFT_J:
2238 aif1 |= 0x8;
2239 break;
2240 default:
2241 return -EINVAL;
2242 }
2243
2244 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2245 case SND_SOC_DAIFMT_DSP_A:
2246 case SND_SOC_DAIFMT_DSP_B:
2247 /* frame inversion not valid for DSP modes */
2248 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2249 case SND_SOC_DAIFMT_NB_NF:
2250 break;
2251 case SND_SOC_DAIFMT_IB_NF:
2252 aif1 |= WM8994_AIF1_BCLK_INV;
2253 break;
2254 default:
2255 return -EINVAL;
2256 }
2257 break;
2258
2259 case SND_SOC_DAIFMT_I2S:
2260 case SND_SOC_DAIFMT_RIGHT_J:
2261 case SND_SOC_DAIFMT_LEFT_J:
2262 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2263 case SND_SOC_DAIFMT_NB_NF:
2264 break;
2265 case SND_SOC_DAIFMT_IB_IF:
2266 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2267 break;
2268 case SND_SOC_DAIFMT_IB_NF:
2269 aif1 |= WM8994_AIF1_BCLK_INV;
2270 break;
2271 case SND_SOC_DAIFMT_NB_IF:
2272 aif1 |= WM8994_AIF1_LRCLK_INV;
2273 break;
2274 default:
2275 return -EINVAL;
2276 }
2277 break;
2278 default:
2279 return -EINVAL;
2280 }
2281
Mark Brownc4431df2010-11-26 15:21:07 +00002282 /* The AIF2 format configuration needs to be mirrored to AIF3
2283 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002284 switch (control->type) {
2285 case WM1811:
2286 case WM8958:
2287 if (dai->id == 2)
2288 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2289 WM8994_AIF1_LRCLK_INV |
2290 WM8958_AIF3_FMT_MASK, aif1);
2291 break;
2292
2293 default:
2294 break;
2295 }
Mark Brownc4431df2010-11-26 15:21:07 +00002296
Mark Brown9e6e96a2010-01-29 17:47:12 +00002297 snd_soc_update_bits(codec, aif1_reg,
2298 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2299 WM8994_AIF1_FMT_MASK,
2300 aif1);
2301 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2302 ms);
2303
2304 return 0;
2305}
2306
2307static struct {
2308 int val, rate;
2309} srs[] = {
2310 { 0, 8000 },
2311 { 1, 11025 },
2312 { 2, 12000 },
2313 { 3, 16000 },
2314 { 4, 22050 },
2315 { 5, 24000 },
2316 { 6, 32000 },
2317 { 7, 44100 },
2318 { 8, 48000 },
2319 { 9, 88200 },
2320 { 10, 96000 },
2321};
2322
2323static int fs_ratios[] = {
2324 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2325};
2326
2327static int bclk_divs[] = {
2328 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2329 640, 880, 960, 1280, 1760, 1920
2330};
2331
2332static int wm8994_hw_params(struct snd_pcm_substream *substream,
2333 struct snd_pcm_hw_params *params,
2334 struct snd_soc_dai *dai)
2335{
2336 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002337 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002338 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002339 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002340 int bclk_reg;
2341 int lrclk_reg;
2342 int rate_reg;
2343 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002344 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002345 int bclk = 0;
2346 int lrclk = 0;
2347 int rate_val = 0;
2348 int id = dai->id - 1;
2349
2350 int i, cur_val, best_val, bclk_rate, best;
2351
2352 switch (dai->id) {
2353 case 1:
2354 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002355 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002356 bclk_reg = WM8994_AIF1_BCLK;
2357 rate_reg = WM8994_AIF1_RATE;
2358 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002359 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002360 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002361 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002362 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002363 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2364 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002365 break;
2366 case 2:
2367 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002368 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002369 bclk_reg = WM8994_AIF2_BCLK;
2370 rate_reg = WM8994_AIF2_RATE;
2371 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002372 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002373 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002374 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002375 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002376 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2377 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002378 break;
2379 default:
2380 return -EINVAL;
2381 }
2382
2383 bclk_rate = params_rate(params) * 2;
2384 switch (params_format(params)) {
2385 case SNDRV_PCM_FORMAT_S16_LE:
2386 bclk_rate *= 16;
2387 break;
2388 case SNDRV_PCM_FORMAT_S20_3LE:
2389 bclk_rate *= 20;
2390 aif1 |= 0x20;
2391 break;
2392 case SNDRV_PCM_FORMAT_S24_LE:
2393 bclk_rate *= 24;
2394 aif1 |= 0x40;
2395 break;
2396 case SNDRV_PCM_FORMAT_S32_LE:
2397 bclk_rate *= 32;
2398 aif1 |= 0x60;
2399 break;
2400 default:
2401 return -EINVAL;
2402 }
2403
2404 /* Try to find an appropriate sample rate; look for an exact match. */
2405 for (i = 0; i < ARRAY_SIZE(srs); i++)
2406 if (srs[i].rate == params_rate(params))
2407 break;
2408 if (i == ARRAY_SIZE(srs))
2409 return -EINVAL;
2410 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2411
2412 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2413 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2414 dai->id, wm8994->aifclk[id], bclk_rate);
2415
Mark Brownb1e43d92010-12-07 17:14:56 +00002416 if (params_channels(params) == 1 &&
2417 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2418 aif2 |= WM8994_AIF1_MONO;
2419
Mark Brown9e6e96a2010-01-29 17:47:12 +00002420 if (wm8994->aifclk[id] == 0) {
2421 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2422 return -EINVAL;
2423 }
2424
2425 /* AIFCLK/fs ratio; look for a close match in either direction */
2426 best = 0;
2427 best_val = abs((fs_ratios[0] * params_rate(params))
2428 - wm8994->aifclk[id]);
2429 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2430 cur_val = abs((fs_ratios[i] * params_rate(params))
2431 - wm8994->aifclk[id]);
2432 if (cur_val >= best_val)
2433 continue;
2434 best = i;
2435 best_val = cur_val;
2436 }
2437 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2438 dai->id, fs_ratios[best]);
2439 rate_val |= best;
2440
2441 /* We may not get quite the right frequency if using
2442 * approximate clocks so look for the closest match that is
2443 * higher than the target (we need to ensure that there enough
2444 * BCLKs to clock out the samples).
2445 */
2446 best = 0;
2447 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002448 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002449 if (cur_val < 0) /* BCLK table is sorted */
2450 break;
2451 best = i;
2452 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002453 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002454 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2455 bclk_divs[best], bclk_rate);
2456 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2457
2458 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002459 if (!lrclk) {
2460 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2461 bclk_rate);
2462 return -EINVAL;
2463 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002464 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2465 lrclk, bclk_rate / lrclk);
2466
2467 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002468 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002469 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2470 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2471 lrclk);
2472 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2473 WM8994_AIF1CLK_RATE_MASK, rate_val);
2474
2475 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2476 switch (dai->id) {
2477 case 1:
2478 wm8994->dac_rates[0] = params_rate(params);
2479 wm8994_set_retune_mobile(codec, 0);
2480 wm8994_set_retune_mobile(codec, 1);
2481 break;
2482 case 2:
2483 wm8994->dac_rates[1] = params_rate(params);
2484 wm8994_set_retune_mobile(codec, 2);
2485 break;
2486 }
2487 }
2488
2489 return 0;
2490}
2491
Mark Brownc4431df2010-11-26 15:21:07 +00002492static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2493 struct snd_pcm_hw_params *params,
2494 struct snd_soc_dai *dai)
2495{
2496 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002497 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2498 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002499 int aif1_reg;
2500 int aif1 = 0;
2501
2502 switch (dai->id) {
2503 case 3:
2504 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002505 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002506 case WM8958:
2507 aif1_reg = WM8958_AIF3_CONTROL_1;
2508 break;
2509 default:
2510 return 0;
2511 }
2512 default:
2513 return 0;
2514 }
2515
2516 switch (params_format(params)) {
2517 case SNDRV_PCM_FORMAT_S16_LE:
2518 break;
2519 case SNDRV_PCM_FORMAT_S20_3LE:
2520 aif1 |= 0x20;
2521 break;
2522 case SNDRV_PCM_FORMAT_S24_LE:
2523 aif1 |= 0x40;
2524 break;
2525 case SNDRV_PCM_FORMAT_S32_LE:
2526 aif1 |= 0x60;
2527 break;
2528 default:
2529 return -EINVAL;
2530 }
2531
2532 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2533}
2534
Mark Brown7d021732011-07-14 17:11:38 +09002535static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2536 struct snd_soc_dai *dai)
2537{
2538 struct snd_soc_codec *codec = dai->codec;
2539 int rate_reg = 0;
2540
2541 switch (dai->id) {
2542 case 1:
2543 rate_reg = WM8994_AIF1_RATE;
2544 break;
2545 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002546 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002547 break;
2548 default:
2549 break;
2550 }
2551
2552 /* If the DAI is idle then configure the divider tree for the
2553 * lowest output rate to save a little power if the clock is
2554 * still active (eg, because it is system clock).
2555 */
2556 if (rate_reg && !dai->playback_active && !dai->capture_active)
2557 snd_soc_update_bits(codec, rate_reg,
2558 WM8994_AIF1_SR_MASK |
2559 WM8994_AIF1CLK_RATE_MASK, 0x9);
2560}
2561
Mark Brown9e6e96a2010-01-29 17:47:12 +00002562static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2563{
2564 struct snd_soc_codec *codec = codec_dai->codec;
2565 int mute_reg;
2566 int reg;
2567
2568 switch (codec_dai->id) {
2569 case 1:
2570 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2571 break;
2572 case 2:
2573 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2574 break;
2575 default:
2576 return -EINVAL;
2577 }
2578
2579 if (mute)
2580 reg = WM8994_AIF1DAC1_MUTE;
2581 else
2582 reg = 0;
2583
2584 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2585
2586 return 0;
2587}
2588
Mark Brown778a76e2010-03-22 22:05:10 +00002589static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2590{
2591 struct snd_soc_codec *codec = codec_dai->codec;
2592 int reg, val, mask;
2593
2594 switch (codec_dai->id) {
2595 case 1:
2596 reg = WM8994_AIF1_MASTER_SLAVE;
2597 mask = WM8994_AIF1_TRI;
2598 break;
2599 case 2:
2600 reg = WM8994_AIF2_MASTER_SLAVE;
2601 mask = WM8994_AIF2_TRI;
2602 break;
2603 case 3:
2604 reg = WM8994_POWER_MANAGEMENT_6;
2605 mask = WM8994_AIF3_TRI;
2606 break;
2607 default:
2608 return -EINVAL;
2609 }
2610
2611 if (tristate)
2612 val = mask;
2613 else
2614 val = 0;
2615
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002616 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002617}
2618
Mark Brownd09f3ec2011-08-15 11:01:02 +09002619static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2620{
2621 struct snd_soc_codec *codec = dai->codec;
2622
2623 /* Disable the pulls on the AIF if we're using it to save power. */
2624 snd_soc_update_bits(codec, WM8994_GPIO_3,
2625 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2626 snd_soc_update_bits(codec, WM8994_GPIO_4,
2627 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2628 snd_soc_update_bits(codec, WM8994_GPIO_5,
2629 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2630
2631 return 0;
2632}
2633
Mark Brown9e6e96a2010-01-29 17:47:12 +00002634#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2635
2636#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002637 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002638
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002639static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002640 .set_sysclk = wm8994_set_dai_sysclk,
2641 .set_fmt = wm8994_set_dai_fmt,
2642 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002643 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002644 .digital_mute = wm8994_aif_mute,
2645 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002646 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002647};
2648
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002649static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002650 .set_sysclk = wm8994_set_dai_sysclk,
2651 .set_fmt = wm8994_set_dai_fmt,
2652 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002653 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002654 .digital_mute = wm8994_aif_mute,
2655 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002656 .set_tristate = wm8994_set_tristate,
2657};
2658
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002659static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002660 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002661 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002662};
2663
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002664static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002665 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002666 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002667 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002668 .playback = {
2669 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002670 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002671 .channels_max = 2,
2672 .rates = WM8994_RATES,
2673 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002674 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002675 },
2676 .capture = {
2677 .stream_name = "AIF1 Capture",
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 .ops = &wm8994_aif1_dai_ops,
2685 },
2686 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002687 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002688 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002689 .playback = {
2690 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002691 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002692 .channels_max = 2,
2693 .rates = WM8994_RATES,
2694 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002695 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002696 },
2697 .capture = {
2698 .stream_name = "AIF2 Capture",
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 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002705 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002706 .ops = &wm8994_aif2_dai_ops,
2707 },
2708 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002709 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002710 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002711 .playback = {
2712 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002713 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002714 .channels_max = 2,
2715 .rates = WM8994_RATES,
2716 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00002717 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002718 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002719 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002720 .stream_name = "AIF3 Capture",
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,
2726 },
Mark Brown778a76e2010-03-22 22:05:10 +00002727 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002728 }
2729};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002730
2731#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01002732static int wm8994_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002733{
Mark Brownb2c812e2010-04-14 15:35:19 +09002734 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002735 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002736 int i, ret;
2737
Mark Brownca629922011-05-11 14:34:53 +02002738 switch (control->type) {
2739 case WM8994:
2740 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2741 break;
Mark Brown81204c82011-05-24 17:35:53 +08002742 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002743 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2744 WM1811_JACKDET_MODE_MASK, 0);
2745 /* Fall through */
Mark Brownca629922011-05-11 14:34:53 +02002746 case WM8958:
2747 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2748 WM8958_MICD_ENA, 0);
2749 break;
2750 }
2751
Mark Brown9e6e96a2010-01-29 17:47:12 +00002752 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2753 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002754 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002755 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002756 if (ret < 0)
2757 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2758 i + 1, ret);
2759 }
2760
2761 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2762
2763 return 0;
2764}
2765
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002766static int wm8994_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002767{
Mark Brownb2c812e2010-04-14 15:35:19 +09002768 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002769 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002770 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002771 unsigned int val, mask;
2772
2773 if (wm8994->revision < 4) {
2774 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01002775 ret = regmap_read(control->regmap,
2776 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002777
2778 /* modify the cache only */
2779 codec->cache_only = 1;
2780 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2781 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2782 val &= mask;
2783 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2784 mask, val);
2785 codec->cache_only = 0;
2786 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002787
Mark Brown9e6e96a2010-01-29 17:47:12 +00002788 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002789 if (!wm8994->fll_suspend[i].out)
2790 continue;
2791
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002792 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002793 wm8994->fll_suspend[i].src,
2794 wm8994->fll_suspend[i].in,
2795 wm8994->fll_suspend[i].out);
2796 if (ret < 0)
2797 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2798 i + 1, ret);
2799 }
2800
Mark Brownca629922011-05-11 14:34:53 +02002801 switch (control->type) {
2802 case WM8994:
2803 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2804 snd_soc_update_bits(codec, WM8994_MICBIAS,
2805 WM8994_MICD_ENA, WM8994_MICD_ENA);
2806 break;
Mark Brown81204c82011-05-24 17:35:53 +08002807 case WM1811:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002808 if (wm8994->jackdet && wm8994->jack_cb) {
2809 /* Restart from idle */
2810 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2811 WM1811_JACKDET_MODE_MASK,
2812 WM1811_JACKDET_MODE_JACK);
2813 break;
2814 }
Mark Brownca629922011-05-11 14:34:53 +02002815 case WM8958:
2816 if (wm8994->jack_cb)
2817 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2818 WM8958_MICD_ENA, WM8958_MICD_ENA);
2819 break;
2820 }
2821
Mark Brown9e6e96a2010-01-29 17:47:12 +00002822 return 0;
2823}
2824#else
2825#define wm8994_suspend NULL
2826#define wm8994_resume NULL
2827#endif
2828
2829static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2830{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002831 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002832 struct wm8994_pdata *pdata = wm8994->pdata;
2833 struct snd_kcontrol_new controls[] = {
2834 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2835 wm8994->retune_mobile_enum,
2836 wm8994_get_retune_mobile_enum,
2837 wm8994_put_retune_mobile_enum),
2838 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2839 wm8994->retune_mobile_enum,
2840 wm8994_get_retune_mobile_enum,
2841 wm8994_put_retune_mobile_enum),
2842 SOC_ENUM_EXT("AIF2 EQ Mode",
2843 wm8994->retune_mobile_enum,
2844 wm8994_get_retune_mobile_enum,
2845 wm8994_put_retune_mobile_enum),
2846 };
2847 int ret, i, j;
2848 const char **t;
2849
2850 /* We need an array of texts for the enum API but the number
2851 * of texts is likely to be less than the number of
2852 * configurations due to the sample rate dependency of the
2853 * configurations. */
2854 wm8994->num_retune_mobile_texts = 0;
2855 wm8994->retune_mobile_texts = NULL;
2856 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2857 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2858 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2859 wm8994->retune_mobile_texts[j]) == 0)
2860 break;
2861 }
2862
2863 if (j != wm8994->num_retune_mobile_texts)
2864 continue;
2865
2866 /* Expand the array... */
2867 t = krealloc(wm8994->retune_mobile_texts,
2868 sizeof(char *) *
2869 (wm8994->num_retune_mobile_texts + 1),
2870 GFP_KERNEL);
2871 if (t == NULL)
2872 continue;
2873
2874 /* ...store the new entry... */
2875 t[wm8994->num_retune_mobile_texts] =
2876 pdata->retune_mobile_cfgs[i].name;
2877
2878 /* ...and remember the new version. */
2879 wm8994->num_retune_mobile_texts++;
2880 wm8994->retune_mobile_texts = t;
2881 }
2882
2883 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2884 wm8994->num_retune_mobile_texts);
2885
2886 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2887 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2888
Liam Girdwood022658b2012-02-03 17:43:09 +00002889 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002890 ARRAY_SIZE(controls));
2891 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002892 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002893 "Failed to add ReTune Mobile controls: %d\n", ret);
2894}
2895
2896static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2897{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002898 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002899 struct wm8994_pdata *pdata = wm8994->pdata;
2900 int ret, i;
2901
2902 if (!pdata)
2903 return;
2904
2905 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2906 pdata->lineout2_diff,
2907 pdata->lineout1fb,
2908 pdata->lineout2fb,
2909 pdata->jd_scthr,
2910 pdata->jd_thr,
2911 pdata->micbias1_lvl,
2912 pdata->micbias2_lvl);
2913
2914 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2915
2916 if (pdata->num_drc_cfgs) {
2917 struct snd_kcontrol_new controls[] = {
2918 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2919 wm8994_get_drc_enum, wm8994_put_drc_enum),
2920 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2921 wm8994_get_drc_enum, wm8994_put_drc_enum),
2922 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2923 wm8994_get_drc_enum, wm8994_put_drc_enum),
2924 };
2925
2926 /* We need an array of texts for the enum API */
Mark Brown7270ceb2011-12-01 14:00:19 +00002927 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
2928 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002929 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002930 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002931 "Failed to allocate %d DRC config texts\n",
2932 pdata->num_drc_cfgs);
2933 return;
2934 }
2935
2936 for (i = 0; i < pdata->num_drc_cfgs; i++)
2937 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2938
2939 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2940 wm8994->drc_enum.texts = wm8994->drc_texts;
2941
Liam Girdwood022658b2012-02-03 17:43:09 +00002942 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002943 ARRAY_SIZE(controls));
2944 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002945 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002946 "Failed to add DRC mode controls: %d\n", ret);
2947
2948 for (i = 0; i < WM8994_NUM_DRC; i++)
2949 wm8994_set_drc(codec, i);
2950 }
2951
2952 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2953 pdata->num_retune_mobile_cfgs);
2954
2955 if (pdata->num_retune_mobile_cfgs)
2956 wm8994_handle_retune_mobile_pdata(wm8994);
2957 else
Liam Girdwood022658b2012-02-03 17:43:09 +00002958 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002959 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002960
2961 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2962 if (pdata->micbias[i]) {
2963 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2964 pdata->micbias[i] & 0xffff);
2965 }
2966 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002967}
2968
Mark Brown88766982010-03-29 20:57:12 +01002969/**
2970 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2971 *
2972 * @codec: WM8994 codec
2973 * @jack: jack to report detection events on
2974 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01002975 *
2976 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2977 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002978 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002979 * be configured using snd_soc_jack_add_gpios() instead.
2980 *
2981 * Configuration of detection levels is available via the micbias1_lvl
2982 * and micbias2_lvl platform data members.
2983 */
2984int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00002985 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01002986{
Mark Brownb2c812e2010-04-14 15:35:19 +09002987 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002988 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01002989 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00002990 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01002991
Mark Brown87092e32012-02-06 18:50:39 +00002992 if (control->type != WM8994) {
2993 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00002994 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00002995 }
Mark Brown3a423152010-11-26 15:21:06 +00002996
Mark Brown88766982010-03-29 20:57:12 +01002997 switch (micbias) {
2998 case 1:
2999 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003000 if (jack)
3001 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3002 "MICBIAS1");
3003 else
3004 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3005 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003006 break;
3007 case 2:
3008 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003009 if (jack)
3010 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3011 "MICBIAS1");
3012 else
3013 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3014 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003015 break;
3016 default:
Mark Brown87092e32012-02-06 18:50:39 +00003017 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003018 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003019 }
Mark Brown88766982010-03-29 20:57:12 +01003020
Mark Brown87092e32012-02-06 18:50:39 +00003021 if (ret != 0)
3022 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3023 micbias, ret);
3024
3025 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3026 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003027
3028 /* Store the configuration */
3029 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003030 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003031
3032 /* If either of the jacks is set up then enable detection */
3033 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3034 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003035 else
Mark Brown88766982010-03-29 20:57:12 +01003036 reg = 0;
3037
3038 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3039
Mark Brown87092e32012-02-06 18:50:39 +00003040 snd_soc_dapm_sync(&codec->dapm);
3041
Mark Brown88766982010-03-29 20:57:12 +01003042 return 0;
3043}
3044EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3045
3046static irqreturn_t wm8994_mic_irq(int irq, void *data)
3047{
3048 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003049 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01003050 int reg;
3051 int report;
3052
Mark Brown7116f452010-12-29 13:05:21 +00003053#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003054 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003055#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003056
Mark Brown88766982010-03-29 20:57:12 +01003057 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3058 if (reg < 0) {
3059 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3060 reg);
3061 return IRQ_HANDLED;
3062 }
3063
3064 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
3065
3066 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003067 if (reg & WM8994_MIC1_DET_STS) {
3068 if (priv->micdet[0].detecting)
3069 report = SND_JACK_HEADSET;
3070 }
3071 if (reg & WM8994_MIC1_SHRT_STS) {
3072 if (priv->micdet[0].detecting)
3073 report = SND_JACK_HEADPHONE;
3074 else
3075 report |= SND_JACK_BTN_0;
3076 }
3077 if (report)
3078 priv->micdet[0].detecting = false;
3079 else
3080 priv->micdet[0].detecting = true;
3081
Mark Brown88766982010-03-29 20:57:12 +01003082 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003083 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003084
3085 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003086 if (reg & WM8994_MIC2_DET_STS) {
3087 if (priv->micdet[1].detecting)
3088 report = SND_JACK_HEADSET;
3089 }
3090 if (reg & WM8994_MIC2_SHRT_STS) {
3091 if (priv->micdet[1].detecting)
3092 report = SND_JACK_HEADPHONE;
3093 else
3094 report |= SND_JACK_BTN_0;
3095 }
3096 if (report)
3097 priv->micdet[1].detecting = false;
3098 else
3099 priv->micdet[1].detecting = true;
3100
Mark Brown88766982010-03-29 20:57:12 +01003101 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003102 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003103
3104 return IRQ_HANDLED;
3105}
3106
Mark Brown821edd22010-11-26 15:21:09 +00003107/* Default microphone detection handler for WM8958 - the user can
3108 * override this if they wish.
3109 */
3110static void wm8958_default_micdet(u16 status, void *data)
3111{
3112 struct snd_soc_codec *codec = data;
3113 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003114 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003115
Mark Browna1691342011-11-30 14:56:40 +00003116 dev_dbg(codec->dev, "MICDET %x\n", status);
3117
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003118 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003119 if (!(status & WM8958_MICD_STS)) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003120 if (!wm8994->jackdet) {
3121 /* If nothing present then clear our statuses */
3122 dev_dbg(codec->dev, "Detected open circuit\n");
3123 wm8994->jack_mic = false;
3124 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003125
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003126 wm8958_micd_set_rate(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003127
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003128 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3129 wm8994->btn_mask |
3130 SND_JACK_HEADSET);
3131 }
Mark Brownb00adf72011-08-13 11:57:18 +09003132 return;
3133 }
3134
3135 /* If the measurement is showing a high impedence we've got a
3136 * microphone.
3137 */
Mark Brown157a75e2011-11-30 13:43:51 +00003138 if (wm8994->mic_detecting && (status & 0x600)) {
Mark Brownb00adf72011-08-13 11:57:18 +09003139 dev_dbg(codec->dev, "Detected microphone\n");
3140
Mark Brown157a75e2011-11-30 13:43:51 +00003141 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003142 wm8994->jack_mic = true;
3143
3144 wm8958_micd_set_rate(codec);
3145
3146 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3147 SND_JACK_HEADSET);
3148 }
3149
3150
Mark Brown7c08b512012-01-26 18:33:24 +00003151 if (wm8994->mic_detecting && status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003152 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003153 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003154
3155 wm8958_micd_set_rate(codec);
3156
3157 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3158 SND_JACK_HEADSET);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003159
3160 /* If we have jackdet that will detect removal */
3161 if (wm8994->jackdet) {
3162 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3163 WM8958_MICD_ENA, 0);
3164
3165 wm1811_jackdet_set_mode(codec,
3166 WM1811_JACKDET_MODE_JACK);
3167 }
Mark Brownb00adf72011-08-13 11:57:18 +09003168 }
3169
3170 /* Report short circuit as a button */
3171 if (wm8994->jack_mic) {
Mark Brown4585790d2011-11-30 10:55:14 +00003172 report = 0;
Mark Brownb00adf72011-08-13 11:57:18 +09003173 if (status & 0x4)
Mark Brown4585790d2011-11-30 10:55:14 +00003174 report |= SND_JACK_BTN_0;
3175
3176 if (status & 0x8)
3177 report |= SND_JACK_BTN_1;
3178
3179 if (status & 0x10)
3180 report |= SND_JACK_BTN_2;
3181
3182 if (status & 0x20)
3183 report |= SND_JACK_BTN_3;
3184
3185 if (status & 0x40)
3186 report |= SND_JACK_BTN_4;
3187
3188 if (status & 0x80)
3189 report |= SND_JACK_BTN_5;
3190
3191 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3192 wm8994->btn_mask);
Mark Brownb00adf72011-08-13 11:57:18 +09003193 }
Mark Brown821edd22010-11-26 15:21:09 +00003194}
3195
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003196static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3197{
3198 struct wm8994_priv *wm8994 = data;
3199 struct snd_soc_codec *codec = wm8994->codec;
3200 int reg;
3201
3202 mutex_lock(&wm8994->accdet_lock);
3203
3204 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3205 if (reg < 0) {
3206 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3207 mutex_unlock(&wm8994->accdet_lock);
3208 return IRQ_NONE;
3209 }
3210
3211 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3212
3213 if (reg & WM1811_JACKDET_LVL) {
3214 dev_dbg(codec->dev, "Jack detected\n");
3215
3216 snd_soc_jack_report(wm8994->micdet[0].jack,
3217 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3218
3219 /*
3220 * Start off measument of microphone impedence to find
3221 * out what's actually there.
3222 */
3223 wm8994->mic_detecting = true;
3224 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3225 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3226 WM8958_MICD_ENA, WM8958_MICD_ENA);
3227 } else {
3228 dev_dbg(codec->dev, "Jack not detected\n");
3229
3230 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3231 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3232 wm8994->btn_mask);
3233
3234 wm8994->mic_detecting = false;
3235 wm8994->jack_mic = false;
3236 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3237 WM8958_MICD_ENA, 0);
3238 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3239 }
3240
3241 mutex_unlock(&wm8994->accdet_lock);
3242
3243 return IRQ_HANDLED;
3244}
3245
Mark Brown821edd22010-11-26 15:21:09 +00003246/**
3247 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3248 *
3249 * @codec: WM8958 codec
3250 * @jack: jack to report detection events on
3251 *
3252 * Enable microphone detection functionality for the WM8958. By
3253 * default simple detection which supports the detection of up to 6
3254 * buttons plus video and microphone functionality is supported.
3255 *
3256 * The WM8958 has an advanced jack detection facility which is able to
3257 * support complex accessory detection, especially when used in
3258 * conjunction with external circuitry. In order to provide maximum
3259 * flexiblity a callback is provided which allows a completely custom
3260 * detection algorithm.
3261 */
3262int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3263 wm8958_micdet_cb cb, void *cb_data)
3264{
3265 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003266 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003267 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003268
Mark Brown81204c82011-05-24 17:35:53 +08003269 switch (control->type) {
3270 case WM1811:
3271 case WM8958:
3272 break;
3273 default:
Mark Brown821edd22010-11-26 15:21:09 +00003274 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003275 }
Mark Brown821edd22010-11-26 15:21:09 +00003276
3277 if (jack) {
3278 if (!cb) {
3279 dev_dbg(codec->dev, "Using default micdet callback\n");
3280 cb = wm8958_default_micdet;
3281 cb_data = codec;
3282 }
3283
Mark Brown4cdf5e42011-11-29 14:36:17 +00003284 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
3285
Mark Brown821edd22010-11-26 15:21:09 +00003286 wm8994->micdet[0].jack = jack;
3287 wm8994->jack_cb = cb;
3288 wm8994->jack_cb_data = cb_data;
3289
Mark Brown157a75e2011-11-30 13:43:51 +00003290 wm8994->mic_detecting = true;
Mark Brownb00adf72011-08-13 11:57:18 +09003291 wm8994->jack_mic = false;
3292
3293 wm8958_micd_set_rate(codec);
3294
Mark Brown4585790d2011-11-30 10:55:14 +00003295 /* Detect microphones and short circuits by default */
3296 if (wm8994->pdata->micd_lvl_sel)
3297 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3298 else
3299 micd_lvl_sel = 0x41;
3300
3301 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3302 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3303 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3304
Mark Brownb00adf72011-08-13 11:57:18 +09003305 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003306 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003307
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003308 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3309
3310 /*
3311 * If we can use jack detection start off with that,
3312 * otherwise jump straight to microphone detection.
3313 */
3314 if (wm8994->jackdet) {
3315 snd_soc_update_bits(codec, WM8994_LDO_1,
3316 WM8994_LDO1_DISCH, 0);
3317 wm1811_jackdet_set_mode(codec,
3318 WM1811_JACKDET_MODE_JACK);
3319 } else {
3320 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3321 WM8958_MICD_ENA, WM8958_MICD_ENA);
3322 }
3323
Mark Brown821edd22010-11-26 15:21:09 +00003324 } else {
3325 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3326 WM8958_MICD_ENA, 0);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003327 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown821edd22010-11-26 15:21:09 +00003328 }
3329
3330 return 0;
3331}
3332EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3333
3334static irqreturn_t wm8958_mic_irq(int irq, void *data)
3335{
3336 struct wm8994_priv *wm8994 = data;
3337 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003338 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003339
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003340 mutex_lock(&wm8994->accdet_lock);
3341
3342 /*
3343 * Jack detection may have detected a removal simulataneously
3344 * with an update of the MICDET status; if so it will have
3345 * stopped detection and we can ignore this interrupt.
3346 */
3347 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA)) {
3348 mutex_unlock(&wm8994->accdet_lock);
3349 return IRQ_HANDLED;
3350 }
3351
Mark Brown19940b32011-08-19 18:05:05 +09003352 /* We may occasionally read a detection without an impedence
3353 * range being provided - if that happens loop again.
3354 */
3355 count = 10;
3356 do {
3357 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3358 if (reg < 0) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003359 mutex_unlock(&wm8994->accdet_lock);
Mark Brown19940b32011-08-19 18:05:05 +09003360 dev_err(codec->dev,
3361 "Failed to read mic detect status: %d\n",
3362 reg);
3363 return IRQ_NONE;
3364 }
Mark Brown821edd22010-11-26 15:21:09 +00003365
Mark Brown19940b32011-08-19 18:05:05 +09003366 if (!(reg & WM8958_MICD_VALID)) {
3367 dev_dbg(codec->dev, "Mic detect data not valid\n");
3368 goto out;
3369 }
3370
3371 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3372 break;
3373
3374 msleep(1);
3375 } while (count--);
3376
3377 if (count == 0)
3378 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003379
Mark Brown7116f452010-12-29 13:05:21 +00003380#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003381 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003382#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003383
Mark Brown821edd22010-11-26 15:21:09 +00003384 if (wm8994->jack_cb)
3385 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3386 else
3387 dev_warn(codec->dev, "Accessory detection with no callback\n");
3388
3389out:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003390 mutex_unlock(&wm8994->accdet_lock);
3391
Mark Brown821edd22010-11-26 15:21:09 +00003392 return IRQ_HANDLED;
3393}
3394
Mark Brown3b1af3f2011-07-14 12:38:18 +09003395static irqreturn_t wm8994_fifo_error(int irq, void *data)
3396{
3397 struct snd_soc_codec *codec = data;
3398
3399 dev_err(codec->dev, "FIFO error\n");
3400
3401 return IRQ_HANDLED;
3402}
3403
Mark Brownf0b182b2011-08-16 12:01:27 +09003404static irqreturn_t wm8994_temp_warn(int irq, void *data)
3405{
3406 struct snd_soc_codec *codec = data;
3407
3408 dev_err(codec->dev, "Thermal warning\n");
3409
3410 return IRQ_HANDLED;
3411}
3412
3413static irqreturn_t wm8994_temp_shut(int irq, void *data)
3414{
3415 struct snd_soc_codec *codec = data;
3416
3417 dev_crit(codec->dev, "Thermal shutdown\n");
3418
3419 return IRQ_HANDLED;
3420}
3421
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003422static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003423{
Mark Brownd9a76662011-07-24 12:49:52 +01003424 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003425 struct wm8994_priv *wm8994;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003426 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003427 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003428 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003429
Mark Brownd9a76662011-07-24 12:49:52 +01003430 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003431
Mark Brown7270ceb2011-12-01 14:00:19 +00003432 wm8994 = devm_kzalloc(codec->dev, sizeof(struct wm8994_priv),
3433 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003434 if (wm8994 == NULL)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003435 return -ENOMEM;
Mark Brownb2c812e2010-04-14 15:35:19 +09003436 snd_soc_codec_set_drvdata(codec, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003437
Mark Brownd9a76662011-07-24 12:49:52 +01003438 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003439
3440 wm8994->wm8994 = dev_get_drvdata(codec->dev->parent);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003441 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3442 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003443
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003444 mutex_init(&wm8994->accdet_lock);
3445
Mark Brownc7ebf932011-07-12 19:47:59 +09003446 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3447 init_completion(&wm8994->fll_locked[i]);
3448
Mark Brown9b7c5252011-02-17 20:05:44 -08003449 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3450 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3451 else if (wm8994->pdata && wm8994->pdata->irq_base)
3452 wm8994->micdet_irq = wm8994->pdata->irq_base +
3453 WM8994_IRQ_MIC1_DET;
3454
Mark Brown39fb51a2010-11-26 17:23:43 +00003455 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003456 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003457
Mark Brownf959dee2012-01-31 16:16:47 +00003458 /* By default use idle_bias_off, will override for WM8994 */
3459 codec->dapm.idle_bias_off = 1;
3460
Mark Brown9e6e96a2010-01-29 17:47:12 +00003461 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003462 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003463 switch (control->type) {
3464 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003465 /* Single ended line outputs should have VMID on. */
3466 if (!wm8994->pdata->lineout1_diff ||
3467 !wm8994->pdata->lineout2_diff)
3468 codec->dapm.idle_bias_off = 0;
3469
Mark Brown3a423152010-11-26 15:21:06 +00003470 switch (wm8994->revision) {
3471 case 2:
3472 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003473 wm8994->hubs.dcs_codes_l = -5;
3474 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003475 wm8994->hubs.hp_startup_mode = 1;
3476 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003477 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003478 break;
3479 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003480 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003481 break;
3482 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003483 break;
Mark Brown3a423152010-11-26 15:21:06 +00003484
3485 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003486 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003487 break;
Mark Brown3a423152010-11-26 15:21:06 +00003488
Mark Brown81204c82011-05-24 17:35:53 +08003489 case WM1811:
3490 wm8994->hubs.dcs_readback_mode = 2;
3491 wm8994->hubs.no_series_update = 1;
3492
3493 switch (wm8994->revision) {
3494 case 0:
3495 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003496 case 2:
3497 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003498 wm8994->hubs.dcs_codes_l = -9;
3499 wm8994->hubs.dcs_codes_r = -5;
Mark Brown81204c82011-05-24 17:35:53 +08003500 break;
3501 default:
3502 break;
3503 }
3504
3505 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3506 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3507 break;
3508
Mark Brown9e6e96a2010-01-29 17:47:12 +00003509 default:
3510 break;
3511 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003512
Mark Brown2a8a8562011-07-24 12:20:41 +01003513 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003514 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003515 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003516 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003517 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003518 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003519
Mark Brown2a8a8562011-07-24 12:20:41 +01003520 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003521 wm_hubs_dcs_done, "DC servo done",
3522 &wm8994->hubs);
3523 if (ret == 0)
3524 wm8994->hubs.dcs_done_irq = true;
3525
Mark Brown3a423152010-11-26 15:21:06 +00003526 switch (control->type) {
3527 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003528 if (wm8994->micdet_irq) {
3529 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3530 wm8994_mic_irq,
3531 IRQF_TRIGGER_RISING,
3532 "Mic1 detect",
3533 wm8994);
3534 if (ret != 0)
3535 dev_warn(codec->dev,
3536 "Failed to request Mic1 detect IRQ: %d\n",
3537 ret);
3538 }
Mark Brown88766982010-03-29 20:57:12 +01003539
Mark Brown2a8a8562011-07-24 12:20:41 +01003540 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003541 WM8994_IRQ_MIC1_SHRT,
3542 wm8994_mic_irq, "Mic 1 short",
3543 wm8994);
3544 if (ret != 0)
3545 dev_warn(codec->dev,
3546 "Failed to request Mic1 short IRQ: %d\n",
3547 ret);
Mark Brown88766982010-03-29 20:57:12 +01003548
Mark Brown2a8a8562011-07-24 12:20:41 +01003549 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003550 WM8994_IRQ_MIC2_DET,
3551 wm8994_mic_irq, "Mic 2 detect",
3552 wm8994);
3553 if (ret != 0)
3554 dev_warn(codec->dev,
3555 "Failed to request Mic2 detect IRQ: %d\n",
3556 ret);
Mark Brown88766982010-03-29 20:57:12 +01003557
Mark Brown2a8a8562011-07-24 12:20:41 +01003558 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00003559 WM8994_IRQ_MIC2_SHRT,
3560 wm8994_mic_irq, "Mic 2 short",
3561 wm8994);
3562 if (ret != 0)
3563 dev_warn(codec->dev,
3564 "Failed to request Mic2 short IRQ: %d\n",
3565 ret);
3566 break;
Mark Brown821edd22010-11-26 15:21:09 +00003567
3568 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003569 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003570 if (wm8994->micdet_irq) {
3571 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3572 wm8958_mic_irq,
3573 IRQF_TRIGGER_RISING,
3574 "Mic detect",
3575 wm8994);
3576 if (ret != 0)
3577 dev_warn(codec->dev,
3578 "Failed to request Mic detect IRQ: %d\n",
3579 ret);
3580 }
Mark Brown3a423152010-11-26 15:21:06 +00003581 }
Mark Brown88766982010-03-29 20:57:12 +01003582
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003583 switch (control->type) {
3584 case WM1811:
3585 if (wm8994->revision > 1) {
3586 ret = wm8994_request_irq(wm8994->wm8994,
3587 WM8994_IRQ_GPIO(6),
3588 wm1811_jackdet_irq, "JACKDET",
3589 wm8994);
3590 if (ret == 0)
3591 wm8994->jackdet = true;
3592 }
3593 break;
3594 default:
3595 break;
3596 }
3597
Mark Brownc7ebf932011-07-12 19:47:59 +09003598 wm8994->fll_locked_irq = true;
3599 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01003600 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09003601 WM8994_IRQ_FLL1_LOCK + i,
3602 wm8994_fll_locked_irq, "FLL lock",
3603 &wm8994->fll_locked[i]);
3604 if (ret != 0)
3605 wm8994->fll_locked_irq = false;
3606 }
3607
Mark Brown27060b3c2012-02-06 18:42:14 +00003608 /* Make sure we can read from the GPIOs if they're inputs */
3609 pm_runtime_get_sync(codec->dev);
3610
Mark Brown9e6e96a2010-01-29 17:47:12 +00003611 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3612 * configured on init - if a system wants to do this dynamically
3613 * at runtime we can deal with that then.
3614 */
Mark Brownd9a76662011-07-24 12:49:52 +01003615 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003616 if (ret < 0) {
3617 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003618 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003619 }
Mark Brownd9a76662011-07-24 12:49:52 +01003620 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003621 wm8994->lrclk_shared[0] = 1;
3622 wm8994_dai[0].symmetric_rates = 1;
3623 } else {
3624 wm8994->lrclk_shared[0] = 0;
3625 }
3626
Mark Brownd9a76662011-07-24 12:49:52 +01003627 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003628 if (ret < 0) {
3629 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003630 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003631 }
Mark Brownd9a76662011-07-24 12:49:52 +01003632 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003633 wm8994->lrclk_shared[1] = 1;
3634 wm8994_dai[1].symmetric_rates = 1;
3635 } else {
3636 wm8994->lrclk_shared[1] = 0;
3637 }
3638
Mark Brown27060b3c2012-02-06 18:42:14 +00003639 pm_runtime_put(codec->dev);
3640
Mark Brown9e6e96a2010-01-29 17:47:12 +00003641 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003642 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3643 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003644 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3645 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003646 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3647 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003648 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3649 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003650 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3651 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003652 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3653 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003654 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3655 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003656 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3657 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003658 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3659 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003660 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3661 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003662 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3663 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003664 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3665 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003666 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3667 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003668 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3669 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003670 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3671 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003672 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3673 WM8994_DAC2_VU, WM8994_DAC2_VU);
3674
3675 /* Set the low bit of the 3D stereo depth so TLV matches */
3676 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3677 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3678 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3679 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3680 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3681 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3682 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3683 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3684 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3685
Mark Brown5b739672011-07-06 00:08:43 -07003686 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3687 * use this; it only affects behaviour on idle TDM clock
3688 * cycles. */
3689 switch (control->type) {
3690 case WM8994:
3691 case WM8958:
3692 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3693 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3694 break;
3695 default:
3696 break;
3697 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003698
Mark Brown500fa302011-11-29 19:58:19 +00003699 /* Put MICBIAS into bypass mode by default on newer devices */
3700 switch (control->type) {
3701 case WM8958:
3702 case WM1811:
3703 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3704 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3705 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3706 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3707 break;
3708 default:
3709 break;
3710 }
3711
Mark Brown9e6e96a2010-01-29 17:47:12 +00003712 wm8994_update_class_w(codec);
3713
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003714 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003715
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003716 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00003717 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003718 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003719 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003720 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003721
3722 switch (control->type) {
3723 case WM8994:
3724 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3725 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003726 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003727 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3728 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003729 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3730 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003731 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3732 ARRAY_SIZE(wm8994_dac_revd_widgets));
3733 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003734 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3735 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003736 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3737 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003738 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3739 ARRAY_SIZE(wm8994_dac_widgets));
3740 }
Mark Brownc4431df2010-11-26 15:21:07 +00003741 break;
3742 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00003743 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00003744 ARRAY_SIZE(wm8958_snd_controls));
3745 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3746 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003747 if (wm8994->revision < 1) {
3748 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3749 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3750 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3751 ARRAY_SIZE(wm8994_adc_revd_widgets));
3752 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3753 ARRAY_SIZE(wm8994_dac_revd_widgets));
3754 } else {
3755 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3756 ARRAY_SIZE(wm8994_lateclk_widgets));
3757 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3758 ARRAY_SIZE(wm8994_adc_widgets));
3759 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3760 ARRAY_SIZE(wm8994_dac_widgets));
3761 }
Mark Brownc4431df2010-11-26 15:21:07 +00003762 break;
Mark Brown81204c82011-05-24 17:35:53 +08003763
3764 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00003765 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08003766 ARRAY_SIZE(wm8958_snd_controls));
3767 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3768 ARRAY_SIZE(wm8958_dapm_widgets));
3769 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3770 ARRAY_SIZE(wm8994_lateclk_widgets));
3771 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3772 ARRAY_SIZE(wm8994_adc_widgets));
3773 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3774 ARRAY_SIZE(wm8994_dac_widgets));
3775 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003776 }
3777
3778
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003779 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003780 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003781
Mark Brownc4431df2010-11-26 15:21:07 +00003782 switch (control->type) {
3783 case WM8994:
3784 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3785 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003786
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003787 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003788 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3789 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003790 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3791 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3792 } else {
3793 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3794 ARRAY_SIZE(wm8994_lateclk_intercon));
3795 }
Mark Brownc4431df2010-11-26 15:21:07 +00003796 break;
3797 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003798 if (wm8994->revision < 1) {
3799 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3800 ARRAY_SIZE(wm8994_revd_intercon));
3801 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3802 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3803 } else {
3804 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3805 ARRAY_SIZE(wm8994_lateclk_intercon));
3806 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3807 ARRAY_SIZE(wm8958_intercon));
3808 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003809
3810 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003811 break;
Mark Brown81204c82011-05-24 17:35:53 +08003812 case WM1811:
3813 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3814 ARRAY_SIZE(wm8994_lateclk_intercon));
3815 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3816 ARRAY_SIZE(wm8958_intercon));
3817 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003818 }
3819
Mark Brown9e6e96a2010-01-29 17:47:12 +00003820 return 0;
3821
Mark Brown88766982010-03-29 20:57:12 +01003822err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003823 if (wm8994->jackdet)
3824 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003825 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
3826 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
3827 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003828 if (wm8994->micdet_irq)
3829 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003830 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003831 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003832 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01003833 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003834 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003835 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3836 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3837 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00003838
Mark Brown9e6e96a2010-01-29 17:47:12 +00003839 return ret;
3840}
3841
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003842static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003843{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003844 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003845 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09003846 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003847
3848 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003849
Mark Brown39fb51a2010-11-26 17:23:43 +00003850 pm_runtime_disable(codec->dev);
3851
Mark Brownc7ebf932011-07-12 19:47:59 +09003852 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01003853 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09003854 &wm8994->fll_locked[i]);
3855
Mark Brown2a8a8562011-07-24 12:20:41 +01003856 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003857 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01003858 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
3859 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
3860 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003861
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003862 if (wm8994->jackdet)
3863 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
3864
Mark Brown3a423152010-11-26 15:21:06 +00003865 switch (control->type) {
3866 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003867 if (wm8994->micdet_irq)
3868 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003869 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003870 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003871 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00003872 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01003873 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00003874 wm8994);
3875 break;
Mark Brown821edd22010-11-26 15:21:09 +00003876
Mark Brown81204c82011-05-24 17:35:53 +08003877 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00003878 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003879 if (wm8994->micdet_irq)
3880 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003881 break;
Mark Brown3a423152010-11-26 15:21:06 +00003882 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003883 if (wm8994->mbc)
3884 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003885 if (wm8994->mbc_vss)
3886 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003887 if (wm8994->enh_eq)
3888 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003889 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003890
3891 return 0;
3892}
3893
Mark Brown1b39bf32011-12-29 12:18:53 +00003894static int wm8994_soc_volatile(struct snd_soc_codec *codec,
3895 unsigned int reg)
3896{
3897 return true;
3898}
3899
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003900static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3901 .probe = wm8994_codec_probe,
3902 .remove = wm8994_codec_remove,
3903 .suspend = wm8994_suspend,
3904 .resume = wm8994_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003905 .set_bias_level = wm8994_set_bias_level,
Mark Brown1b39bf32011-12-29 12:18:53 +00003906 .reg_cache_size = WM8994_MAX_REGISTER,
3907 .volatile_register = wm8994_soc_volatile,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003908};
3909
3910static int __devinit wm8994_probe(struct platform_device *pdev)
3911{
3912 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3913 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3914}
3915
3916static int __devexit wm8994_remove(struct platform_device *pdev)
3917{
3918 snd_soc_unregister_codec(&pdev->dev);
3919 return 0;
3920}
3921
Mark Brown9e6e96a2010-01-29 17:47:12 +00003922static struct platform_driver wm8994_codec_driver = {
3923 .driver = {
3924 .name = "wm8994-codec",
3925 .owner = THIS_MODULE,
3926 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003927 .probe = wm8994_probe,
3928 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003929};
3930
Mark Brown5bbcc3c2011-11-23 22:52:08 +00003931module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003932
3933MODULE_DESCRIPTION("ASoC WM8994 driver");
3934MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3935MODULE_LICENSE("GPL");
3936MODULE_ALIAS("platform:wm8994-codec");