blob: 29e95f93d482201a91cd0523c008bb2ca2b01bd3 [file] [log] [blame]
Mark Brown9e6e96a2010-01-29 17:47:12 +00001/*
2 * wm8994.c -- WM8994 ALSA SoC Audio driver
3 *
Mark Brown656baae2012-05-23 12:39:07 +01004 * Copyright 2009-12 Wolfson Microelectronics plc
Mark Brown9e6e96a2010-01-29 17:47:12 +00005 *
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
Mark Brownbfd37bb2012-06-05 12:31:32 +010049static struct {
50 unsigned int reg;
51 unsigned int mask;
52} wm8994_vu_bits[] = {
53 { WM8994_LEFT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
54 { WM8994_RIGHT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
55 { WM8994_LEFT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
56 { WM8994_RIGHT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
57 { WM8994_SPEAKER_VOLUME_LEFT, WM8994_SPKOUT_VU },
58 { WM8994_SPEAKER_VOLUME_RIGHT, WM8994_SPKOUT_VU },
59 { WM8994_LEFT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
60 { WM8994_RIGHT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
61 { WM8994_LEFT_OPGA_VOLUME, WM8994_MIXOUT_VU },
62 { WM8994_RIGHT_OPGA_VOLUME, WM8994_MIXOUT_VU },
63
64 { WM8994_AIF1_DAC1_LEFT_VOLUME, WM8994_AIF1DAC1_VU },
65 { WM8994_AIF1_DAC1_RIGHT_VOLUME, WM8994_AIF1DAC1_VU },
66 { WM8994_AIF1_DAC2_LEFT_VOLUME, WM8994_AIF1DAC2_VU },
67 { WM8994_AIF1_DAC2_RIGHT_VOLUME, WM8994_AIF1DAC2_VU },
68 { WM8994_AIF2_DAC_LEFT_VOLUME, WM8994_AIF2DAC_VU },
69 { WM8994_AIF2_DAC_RIGHT_VOLUME, WM8994_AIF2DAC_VU },
70 { WM8994_AIF1_ADC1_LEFT_VOLUME, WM8994_AIF1ADC1_VU },
71 { WM8994_AIF1_ADC1_RIGHT_VOLUME, WM8994_AIF1ADC1_VU },
72 { WM8994_AIF1_ADC2_LEFT_VOLUME, WM8994_AIF1ADC2_VU },
73 { WM8994_AIF1_ADC2_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
74 { WM8994_AIF2_ADC_LEFT_VOLUME, WM8994_AIF2ADC_VU },
75 { WM8994_AIF2_ADC_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
76 { WM8994_DAC1_LEFT_VOLUME, WM8994_DAC1_VU },
77 { WM8994_DAC1_RIGHT_VOLUME, WM8994_DAC1_VU },
78 { WM8994_DAC2_LEFT_VOLUME, WM8994_DAC2_VU },
79 { WM8994_DAC2_RIGHT_VOLUME, WM8994_DAC2_VU },
80};
81
Mark Brown9e6e96a2010-01-29 17:47:12 +000082static int wm8994_drc_base[] = {
83 WM8994_AIF1_DRC1_1,
84 WM8994_AIF1_DRC2_1,
85 WM8994_AIF2_DRC_1,
86};
87
88static int wm8994_retune_mobile_base[] = {
89 WM8994_AIF1_DAC1_EQ_GAINS_1,
90 WM8994_AIF1_DAC2_EQ_GAINS_1,
91 WM8994_AIF2_EQ_GAINS_1,
92};
93
Mark Brownaf6b6fe2011-11-30 20:32:05 +000094static const struct wm8958_micd_rate micdet_rates[] = {
Mark Brownb00adf72011-08-13 11:57:18 +090095 { 32768, true, 1, 4 },
96 { 32768, false, 1, 1 },
Mark Brown604533d2011-12-01 12:51:25 +000097 { 44100 * 256, true, 7, 10 },
98 { 44100 * 256, false, 7, 10 },
Mark Brownb00adf72011-08-13 11:57:18 +090099};
100
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000101static const struct wm8958_micd_rate jackdet_rates[] = {
102 { 32768, true, 0, 1 },
103 { 32768, false, 0, 1 },
Mark Browne9d9a962012-04-26 16:07:32 +0100104 { 44100 * 256, true, 10, 10 },
105 { 44100 * 256, false, 7, 8 },
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000106};
107
Mark Brownb00adf72011-08-13 11:57:18 +0900108static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
109{
110 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900111 struct wm8994 *control = wm8994->wm8994;
Mark Brownb00adf72011-08-13 11:57:18 +0900112 int best, i, sysclk, val;
113 bool idle;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000114 const struct wm8958_micd_rate *rates;
115 int num_rates;
Mark Brownb00adf72011-08-13 11:57:18 +0900116
Mark Brownb00adf72011-08-13 11:57:18 +0900117 idle = !wm8994->jack_mic;
118
119 sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
120 if (sysclk & WM8994_SYSCLK_SRC)
121 sysclk = wm8994->aifclk[1];
122 else
123 sysclk = wm8994->aifclk[0];
124
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900125 if (control->pdata.micd_rates) {
126 rates = control->pdata.micd_rates;
127 num_rates = control->pdata.num_micd_rates;
Mark Browncd1707a2011-12-01 13:44:25 +0000128 } else if (wm8994->jackdet) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000129 rates = jackdet_rates;
130 num_rates = ARRAY_SIZE(jackdet_rates);
131 } else {
132 rates = micdet_rates;
133 num_rates = ARRAY_SIZE(micdet_rates);
134 }
135
Mark Brownb00adf72011-08-13 11:57:18 +0900136 best = 0;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000137 for (i = 0; i < num_rates; i++) {
138 if (rates[i].idle != idle)
Mark Brownb00adf72011-08-13 11:57:18 +0900139 continue;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000140 if (abs(rates[i].sysclk - sysclk) <
141 abs(rates[best].sysclk - sysclk))
Mark Brownb00adf72011-08-13 11:57:18 +0900142 best = i;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000143 else if (rates[best].idle != idle)
Mark Brownb00adf72011-08-13 11:57:18 +0900144 best = i;
145 }
146
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000147 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
148 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
Mark Brownb00adf72011-08-13 11:57:18 +0900149
Mark Brown3a334ad2012-04-26 17:02:16 +0100150 dev_dbg(codec->dev, "MICD rate %d,%d for %dHz %s\n",
151 rates[best].start, rates[best].rate, sysclk,
152 idle ? "idle" : "active");
153
Mark Brownb00adf72011-08-13 11:57:18 +0900154 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
155 WM8958_MICD_BIAS_STARTTIME_MASK |
156 WM8958_MICD_RATE_MASK, val);
157}
158
Mark Brown9e6e96a2010-01-29 17:47:12 +0000159static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
160{
Mark Brownb2c812e2010-04-14 15:35:19 +0900161 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000162 int rate;
163 int reg1 = 0;
164 int offset;
165
166 if (aif)
167 offset = 4;
168 else
169 offset = 0;
170
171 switch (wm8994->sysclk[aif]) {
172 case WM8994_SYSCLK_MCLK1:
173 rate = wm8994->mclk[0];
174 break;
175
176 case WM8994_SYSCLK_MCLK2:
177 reg1 |= 0x8;
178 rate = wm8994->mclk[1];
179 break;
180
181 case WM8994_SYSCLK_FLL1:
182 reg1 |= 0x10;
183 rate = wm8994->fll[0].out;
184 break;
185
186 case WM8994_SYSCLK_FLL2:
187 reg1 |= 0x18;
188 rate = wm8994->fll[1].out;
189 break;
190
191 default:
192 return -EINVAL;
193 }
194
195 if (rate >= 13500000) {
196 rate /= 2;
197 reg1 |= WM8994_AIF1CLK_DIV;
198
199 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
200 aif + 1, rate);
201 }
Mark Brown5e5e2be2010-04-25 12:20:30 +0100202
Mark Brown9e6e96a2010-01-29 17:47:12 +0000203 wm8994->aifclk[aif] = rate;
204
205 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
206 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
207 reg1);
208
209 return 0;
210}
211
212static int configure_clock(struct snd_soc_codec *codec)
213{
Mark Brownb2c812e2010-04-14 15:35:19 +0900214 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Axel Lin04f45c42011-10-04 20:07:03 +0800215 int change, new;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000216
217 /* Bring up the AIF clocks first */
218 configure_aif_clock(codec, 0);
219 configure_aif_clock(codec, 1);
220
221 /* Then switch CLK_SYS over to the higher of them; a change
222 * can only happen as a result of a clocking change which can
223 * only be made outside of DAPM so we can safely redo the
224 * clocking.
225 */
226
227 /* If they're equal it doesn't matter which is used */
Mark Brownb00adf72011-08-13 11:57:18 +0900228 if (wm8994->aifclk[0] == wm8994->aifclk[1]) {
229 wm8958_micd_set_rate(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000230 return 0;
Mark Brownb00adf72011-08-13 11:57:18 +0900231 }
Mark Brown9e6e96a2010-01-29 17:47:12 +0000232
233 if (wm8994->aifclk[0] < wm8994->aifclk[1])
234 new = WM8994_SYSCLK_SRC;
235 else
236 new = 0;
237
Axel Lin04f45c42011-10-04 20:07:03 +0800238 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
239 WM8994_SYSCLK_SRC, new);
Mark Brown52ac7ab2011-12-01 12:43:26 +0000240 if (change)
241 snd_soc_dapm_sync(&codec->dapm);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000242
Mark Brownb00adf72011-08-13 11:57:18 +0900243 wm8958_micd_set_rate(codec);
244
Mark Brown9e6e96a2010-01-29 17:47:12 +0000245 return 0;
246}
247
248static int check_clk_sys(struct snd_soc_dapm_widget *source,
249 struct snd_soc_dapm_widget *sink)
250{
251 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
252 const char *clk;
253
254 /* Check what we're currently using for CLK_SYS */
255 if (reg & WM8994_SYSCLK_SRC)
256 clk = "AIF2CLK";
257 else
258 clk = "AIF1CLK";
259
260 return strcmp(source->name, clk) == 0;
261}
262
263static const char *sidetone_hpf_text[] = {
264 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
265};
266
267static const struct soc_enum sidetone_hpf =
268 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
269
Uk Kim146fd572010-12-07 13:58:40 +0000270static const char *adc_hpf_text[] = {
271 "HiFi", "Voice 1", "Voice 2", "Voice 3"
272};
273
274static const struct soc_enum aif1adc1_hpf =
275 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
276
277static const struct soc_enum aif1adc2_hpf =
278 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
279
280static const struct soc_enum aif2adc_hpf =
281 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
282
Mark Brown9e6e96a2010-01-29 17:47:12 +0000283static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
284static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
285static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
286static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
287static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
Mark Brown1ddc07d2011-08-16 10:08:48 +0900288static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
Mark Brown81204c82011-05-24 17:35:53 +0800289static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000290
291#define WM8994_DRC_SWITCH(xname, reg, shift) \
292{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
293 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
294 .put = wm8994_put_drc_sw, \
295 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
296
297static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol)
299{
300 struct soc_mixer_control *mc =
301 (struct soc_mixer_control *)kcontrol->private_value;
302 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
303 int mask, ret;
304
305 /* Can't enable both ADC and DAC paths simultaneously */
306 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
307 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
308 WM8994_AIF1ADC1R_DRC_ENA_MASK;
309 else
310 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
311
312 ret = snd_soc_read(codec, mc->reg);
313 if (ret < 0)
314 return ret;
315 if (ret & mask)
316 return -EINVAL;
317
318 return snd_soc_put_volsw(kcontrol, ucontrol);
319}
320
Mark Brown9e6e96a2010-01-29 17:47:12 +0000321static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
322{
Mark Brownb2c812e2010-04-14 15:35:19 +0900323 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900324 struct wm8994 *control = wm8994->wm8994;
325 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000326 int base = wm8994_drc_base[drc];
327 int cfg = wm8994->drc_cfg[drc];
328 int save, i;
329
330 /* Save any enables; the configuration should clear them. */
331 save = snd_soc_read(codec, base);
332 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
333 WM8994_AIF1ADC1R_DRC_ENA;
334
335 for (i = 0; i < WM8994_DRC_REGS; i++)
336 snd_soc_update_bits(codec, base + i, 0xffff,
337 pdata->drc_cfgs[cfg].regs[i]);
338
339 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
340 WM8994_AIF1ADC1L_DRC_ENA |
341 WM8994_AIF1ADC1R_DRC_ENA, save);
342}
343
344/* Icky as hell but saves code duplication */
345static int wm8994_get_drc(const char *name)
346{
347 if (strcmp(name, "AIF1DRC1 Mode") == 0)
348 return 0;
349 if (strcmp(name, "AIF1DRC2 Mode") == 0)
350 return 1;
351 if (strcmp(name, "AIF2DRC Mode") == 0)
352 return 2;
353 return -EINVAL;
354}
355
356static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
357 struct snd_ctl_elem_value *ucontrol)
358{
359 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000360 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900361 struct wm8994 *control = wm8994->wm8994;
362 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000363 int drc = wm8994_get_drc(kcontrol->id.name);
364 int value = ucontrol->value.integer.value[0];
365
366 if (drc < 0)
367 return drc;
368
369 if (value >= pdata->num_drc_cfgs)
370 return -EINVAL;
371
372 wm8994->drc_cfg[drc] = value;
373
374 wm8994_set_drc(codec, drc);
375
376 return 0;
377}
378
379static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
381{
382 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900383 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000384 int drc = wm8994_get_drc(kcontrol->id.name);
385
Vinod Koul7d6898b2013-05-28 15:06:42 +0530386 if (drc < 0)
387 return drc;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000388 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
389
390 return 0;
391}
392
393static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
394{
Mark Brownb2c812e2010-04-14 15:35:19 +0900395 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900396 struct wm8994 *control = wm8994->wm8994;
397 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000398 int base = wm8994_retune_mobile_base[block];
399 int iface, best, best_val, save, i, cfg;
400
401 if (!pdata || !wm8994->num_retune_mobile_texts)
402 return;
403
404 switch (block) {
405 case 0:
406 case 1:
407 iface = 0;
408 break;
409 case 2:
410 iface = 1;
411 break;
412 default:
413 return;
414 }
415
416 /* Find the version of the currently selected configuration
417 * with the nearest sample rate. */
418 cfg = wm8994->retune_mobile_cfg[block];
419 best = 0;
420 best_val = INT_MAX;
421 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
422 if (strcmp(pdata->retune_mobile_cfgs[i].name,
423 wm8994->retune_mobile_texts[cfg]) == 0 &&
424 abs(pdata->retune_mobile_cfgs[i].rate
425 - wm8994->dac_rates[iface]) < best_val) {
426 best = i;
427 best_val = abs(pdata->retune_mobile_cfgs[i].rate
428 - wm8994->dac_rates[iface]);
429 }
430 }
431
432 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
433 block,
434 pdata->retune_mobile_cfgs[best].name,
435 pdata->retune_mobile_cfgs[best].rate,
436 wm8994->dac_rates[iface]);
437
438 /* The EQ will be disabled while reconfiguring it, remember the
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +0200439 * current configuration.
Mark Brown9e6e96a2010-01-29 17:47:12 +0000440 */
441 save = snd_soc_read(codec, base);
442 save &= WM8994_AIF1DAC1_EQ_ENA;
443
444 for (i = 0; i < WM8994_EQ_REGS; i++)
445 snd_soc_update_bits(codec, base + i, 0xffff,
446 pdata->retune_mobile_cfgs[best].regs[i]);
447
448 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
449}
450
451/* Icky as hell but saves code duplication */
452static int wm8994_get_retune_mobile_block(const char *name)
453{
454 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
455 return 0;
456 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
457 return 1;
458 if (strcmp(name, "AIF2 EQ Mode") == 0)
459 return 2;
460 return -EINVAL;
461}
462
463static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
465{
466 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000467 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900468 struct wm8994 *control = wm8994->wm8994;
469 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000470 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
471 int value = ucontrol->value.integer.value[0];
472
473 if (block < 0)
474 return block;
475
476 if (value >= pdata->num_retune_mobile_cfgs)
477 return -EINVAL;
478
479 wm8994->retune_mobile_cfg[block] = value;
480
481 wm8994_set_retune_mobile(codec, block);
482
483 return 0;
484}
485
486static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
487 struct snd_ctl_elem_value *ucontrol)
488{
489 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800490 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000491 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
492
Vinod Koul7d6898b2013-05-28 15:06:42 +0530493 if (block < 0)
494 return block;
495
Mark Brown9e6e96a2010-01-29 17:47:12 +0000496 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
497
498 return 0;
499}
500
Mark Brown96b101e2010-11-18 15:49:38 +0000501static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100502 "Left", "Right"
503};
504
Mark Brown96b101e2010-11-18 15:49:38 +0000505static const struct soc_enum aif1adcl_src =
506 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
507
508static const struct soc_enum aif1adcr_src =
509 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
510
511static const struct soc_enum aif2adcl_src =
512 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
513
514static const struct soc_enum aif2adcr_src =
515 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
516
Mark Brownf5548852010-08-31 19:39:48 +0100517static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000518 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100519
520static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000521 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100522
523static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000524 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100525
526static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000527 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100528
Mark Brown154b26a2010-12-09 12:07:44 +0000529static const char *osr_text[] = {
530 "Low Power", "High Performance",
531};
532
533static const struct soc_enum dac_osr =
534 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
535
536static const struct soc_enum adc_osr =
537 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
538
Mark Brown9e6e96a2010-01-29 17:47:12 +0000539static const struct snd_kcontrol_new wm8994_snd_controls[] = {
540SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
541 WM8994_AIF1_ADC1_RIGHT_VOLUME,
542 1, 119, 0, digital_tlv),
543SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
544 WM8994_AIF1_ADC2_RIGHT_VOLUME,
545 1, 119, 0, digital_tlv),
546SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
547 WM8994_AIF2_ADC_RIGHT_VOLUME,
548 1, 119, 0, digital_tlv),
549
Mark Brown96b101e2010-11-18 15:49:38 +0000550SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
551SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000552SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
553SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000554
Mark Brownf5548852010-08-31 19:39:48 +0100555SOC_ENUM("AIF1DACL Source", aif1dacl_src),
556SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000557SOC_ENUM("AIF2DACL Source", aif2dacl_src),
558SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100559
Mark Brown9e6e96a2010-01-29 17:47:12 +0000560SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
561 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
562SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
563 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
564SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
565 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
566
567SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
568SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
569
570SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
571SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
572SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
573
574WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
575WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
576WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
577
578WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
579WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
580WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
581
582WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
583WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
584WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
585
586SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
587 5, 12, 0, st_tlv),
588SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
589 0, 12, 0, st_tlv),
590SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
591 5, 12, 0, st_tlv),
592SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
593 0, 12, 0, st_tlv),
594SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
595SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
596
Uk Kim146fd572010-12-07 13:58:40 +0000597SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
598SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
599
600SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
601SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
602
603SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
604SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
605
Mark Brown154b26a2010-12-09 12:07:44 +0000606SOC_ENUM("ADC OSR", adc_osr),
607SOC_ENUM("DAC OSR", dac_osr),
608
Mark Brown9e6e96a2010-01-29 17:47:12 +0000609SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
610 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
611SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
612 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
613
614SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
615 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
616SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
617 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
618
619SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
620 6, 1, 1, wm_hubs_spkmix_tlv),
621SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
622 2, 1, 1, wm_hubs_spkmix_tlv),
623
624SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
625 6, 1, 1, wm_hubs_spkmix_tlv),
626SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
627 2, 1, 1, wm_hubs_spkmix_tlv),
628
629SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
630 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000631SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000632 8, 1, 0),
633SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
634 10, 15, 0, wm8994_3d_tlv),
635SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
636 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000637SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000638 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000639SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000640 8, 1, 0),
641};
642
643static const struct snd_kcontrol_new wm8994_eq_controls[] = {
644SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
645 eq_tlv),
646SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
647 eq_tlv),
648SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
649 eq_tlv),
650SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
651 eq_tlv),
652SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
653 eq_tlv),
654
655SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
656 eq_tlv),
657SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
658 eq_tlv),
659SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
660 eq_tlv),
661SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
662 eq_tlv),
663SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
664 eq_tlv),
665
666SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
667 eq_tlv),
668SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
669 eq_tlv),
670SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
671 eq_tlv),
672SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
673 eq_tlv),
674SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
675 eq_tlv),
676};
677
Mark Brown45a690f2012-08-15 19:20:54 +0100678static const struct snd_kcontrol_new wm8994_drc_controls[] = {
679SND_SOC_BYTES_MASK("AIF1.1 DRC", WM8994_AIF1_DRC1_1, 5,
680 WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
681 WM8994_AIF1ADC1R_DRC_ENA),
682SND_SOC_BYTES_MASK("AIF1.2 DRC", WM8994_AIF1_DRC2_1, 5,
683 WM8994_AIF1DAC2_DRC_ENA | WM8994_AIF1ADC2L_DRC_ENA |
684 WM8994_AIF1ADC2R_DRC_ENA),
685SND_SOC_BYTES_MASK("AIF2 DRC", WM8994_AIF2_DRC_1, 5,
686 WM8994_AIF2DAC_DRC_ENA | WM8994_AIF2ADCL_DRC_ENA |
687 WM8994_AIF2ADCR_DRC_ENA),
688};
689
Mark Brown1ddc07d2011-08-16 10:08:48 +0900690static const char *wm8958_ng_text[] = {
691 "30ms", "125ms", "250ms", "500ms",
692};
693
694static const struct soc_enum wm8958_aif1dac1_ng_hold =
695 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
696 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
697
698static const struct soc_enum wm8958_aif1dac2_ng_hold =
699 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
700 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
701
702static const struct soc_enum wm8958_aif2dac_ng_hold =
703 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
704 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
705
Mark Brownc4431df2010-11-26 15:21:07 +0000706static const struct snd_kcontrol_new wm8958_snd_controls[] = {
707SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brown1ddc07d2011-08-16 10:08:48 +0900708
709SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
710 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
711SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
712SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
713 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
714 7, 1, ng_tlv),
715
716SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
717 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
718SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
719SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
720 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
721 7, 1, ng_tlv),
722
723SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
724 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
725SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
726SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
727 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
728 7, 1, ng_tlv),
Mark Brownc4431df2010-11-26 15:21:07 +0000729};
730
Mark Brown81204c82011-05-24 17:35:53 +0800731static const struct snd_kcontrol_new wm1811_snd_controls[] = {
732SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
733 mixin_boost_tlv),
734SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
735 mixin_boost_tlv),
736};
737
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000738/* We run all mode setting through a function to enforce audio mode */
739static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
740{
741 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
742
Mark Brown78b76db2012-11-22 17:02:09 +0900743 if (!wm8994->jackdet || !wm8994->micdet[0].jack)
Mark Brown28e33262012-03-03 00:10:02 +0000744 return;
745
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000746 if (wm8994->active_refcount)
747 mode = WM1811_JACKDET_MODE_AUDIO;
748
Mark Brown4752a882012-03-04 02:16:01 +0000749 if (mode == wm8994->jackdet_mode)
Mark Brown1defde22012-03-03 20:02:49 +0000750 return;
751
Mark Brown4752a882012-03-04 02:16:01 +0000752 wm8994->jackdet_mode = mode;
753
754 /* Always use audio mode to detect while the system is active */
755 if (mode != WM1811_JACKDET_MODE_NONE)
756 mode = WM1811_JACKDET_MODE_AUDIO;
757
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000758 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
759 WM1811_JACKDET_MODE_MASK, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000760}
761
762static void active_reference(struct snd_soc_codec *codec)
763{
764 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
765
766 mutex_lock(&wm8994->accdet_lock);
767
768 wm8994->active_refcount++;
769
770 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
771 wm8994->active_refcount);
772
Mark Brown1defde22012-03-03 20:02:49 +0000773 /* If we're using jack detection go into audio mode */
774 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000775
776 mutex_unlock(&wm8994->accdet_lock);
777}
778
779static void active_dereference(struct snd_soc_codec *codec)
780{
781 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
782 u16 mode;
783
784 mutex_lock(&wm8994->accdet_lock);
785
786 wm8994->active_refcount--;
787
788 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
789 wm8994->active_refcount);
790
791 if (wm8994->active_refcount == 0) {
792 /* Go into appropriate detection only mode */
Mark Brown1defde22012-03-03 20:02:49 +0000793 if (wm8994->jack_mic || wm8994->mic_detecting)
794 mode = WM1811_JACKDET_MODE_MIC;
795 else
796 mode = WM1811_JACKDET_MODE_JACK;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000797
Mark Brown1defde22012-03-03 20:02:49 +0000798 wm1811_jackdet_set_mode(codec, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000799 }
800
801 mutex_unlock(&wm8994->accdet_lock);
802}
803
Mark Brown9e6e96a2010-01-29 17:47:12 +0000804static int clk_sys_event(struct snd_soc_dapm_widget *w,
805 struct snd_kcontrol *kcontrol, int event)
806{
807 struct snd_soc_codec *codec = w->codec;
Mark Brown99af79d2012-07-25 23:03:36 +0100808 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000809
810 switch (event) {
811 case SND_SOC_DAPM_PRE_PMU:
812 return configure_clock(codec);
813
Mark Brown99af79d2012-07-25 23:03:36 +0100814 case SND_SOC_DAPM_POST_PMU:
815 /*
816 * JACKDET won't run until we start the clock and it
817 * only reports deltas, make sure we notify the state
818 * up the stack on startup. Use a *very* generous
819 * timeout for paranoia, there's no urgency and we
820 * don't want false reports.
821 */
822 if (wm8994->jackdet && !wm8994->clk_has_run) {
823 schedule_delayed_work(&wm8994->jackdet_bootstrap,
824 msecs_to_jiffies(1000));
825 wm8994->clk_has_run = true;
826 }
827 break;
828
Mark Brown9e6e96a2010-01-29 17:47:12 +0000829 case SND_SOC_DAPM_POST_PMD:
830 configure_clock(codec);
831 break;
832 }
833
834 return 0;
835}
836
Mark Brown4b7ed832011-08-10 17:47:33 +0900837static void vmid_reference(struct snd_soc_codec *codec)
838{
839 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
840
Mark Browndb966f82012-02-06 12:07:08 +0000841 pm_runtime_get_sync(codec->dev);
842
Mark Brown4b7ed832011-08-10 17:47:33 +0900843 wm8994->vmid_refcount++;
844
845 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
846 wm8994->vmid_refcount);
847
848 if (wm8994->vmid_refcount == 1) {
Mark Browncc6d5a82012-02-11 23:09:53 +0000849 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
Mark Browncc6d5a82012-02-11 23:09:53 +0000850 WM8994_LINEOUT1_DISCH |
Mark Brown22f8d052012-03-19 17:32:06 +0000851 WM8994_LINEOUT2_DISCH, 0);
Mark Browncc6d5a82012-02-11 23:09:53 +0000852
Mark Brownf7085642012-02-21 16:24:00 +0000853 wm_hubs_vmid_ena(codec);
854
Mark Brown22f8d052012-03-19 17:32:06 +0000855 switch (wm8994->vmid_mode) {
856 default:
Mark Browncbd71f32012-05-09 19:11:03 +0100857 WARN_ON(NULL == "Invalid VMID mode");
Mark Brown22f8d052012-03-19 17:32:06 +0000858 case WM8994_VMID_NORMAL:
859 /* Startup bias, VMID ramp & buffer */
860 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
861 WM8994_BIAS_SRC |
862 WM8994_VMID_DISCH |
863 WM8994_STARTUP_BIAS_ENA |
864 WM8994_VMID_BUF_ENA |
865 WM8994_VMID_RAMP_MASK,
866 WM8994_BIAS_SRC |
867 WM8994_STARTUP_BIAS_ENA |
868 WM8994_VMID_BUF_ENA |
Mark Browna3a1d9d2012-08-22 17:23:56 +0100869 (0x2 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900870
Mark Brown22f8d052012-03-19 17:32:06 +0000871 /* Main bias enable, VMID=2x40k */
872 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
873 WM8994_BIAS_ENA |
874 WM8994_VMID_SEL_MASK,
875 WM8994_BIAS_ENA | 0x2);
Mark Brown4b7ed832011-08-10 17:47:33 +0900876
Mark Browna3a1d9d2012-08-22 17:23:56 +0100877 msleep(300);
Mark Browncc6d5a82012-02-11 23:09:53 +0000878
Mark Brown22f8d052012-03-19 17:32:06 +0000879 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
880 WM8994_VMID_RAMP_MASK |
881 WM8994_BIAS_SRC,
882 0);
883 break;
884
885 case WM8994_VMID_FORCE:
886 /* Startup bias, slow VMID ramp & buffer */
887 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
888 WM8994_BIAS_SRC |
889 WM8994_VMID_DISCH |
890 WM8994_STARTUP_BIAS_ENA |
891 WM8994_VMID_BUF_ENA |
892 WM8994_VMID_RAMP_MASK,
893 WM8994_BIAS_SRC |
894 WM8994_STARTUP_BIAS_ENA |
895 WM8994_VMID_BUF_ENA |
896 (0x2 << WM8994_VMID_RAMP_SHIFT));
897
898 /* Main bias enable, VMID=2x40k */
899 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
900 WM8994_BIAS_ENA |
901 WM8994_VMID_SEL_MASK,
902 WM8994_BIAS_ENA | 0x2);
903
904 msleep(400);
905
906 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
907 WM8994_VMID_RAMP_MASK |
908 WM8994_BIAS_SRC,
909 0);
910 break;
911 }
Mark Brown4b7ed832011-08-10 17:47:33 +0900912 }
913}
914
915static void vmid_dereference(struct snd_soc_codec *codec)
916{
917 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
918
919 wm8994->vmid_refcount--;
920
921 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
922 wm8994->vmid_refcount);
923
924 if (wm8994->vmid_refcount == 0) {
Mark Brown22f8d052012-03-19 17:32:06 +0000925 if (wm8994->hubs.lineout1_se)
926 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
927 WM8994_LINEOUT1N_ENA |
928 WM8994_LINEOUT1P_ENA,
929 WM8994_LINEOUT1N_ENA |
930 WM8994_LINEOUT1P_ENA);
931
932 if (wm8994->hubs.lineout2_se)
933 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
934 WM8994_LINEOUT2N_ENA |
935 WM8994_LINEOUT2P_ENA,
936 WM8994_LINEOUT2N_ENA |
937 WM8994_LINEOUT2P_ENA);
938
939 /* Start discharging VMID */
Mark Brown4b7ed832011-08-10 17:47:33 +0900940 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
941 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000942 WM8994_VMID_DISCH,
Mark Brown4b7ed832011-08-10 17:47:33 +0900943 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000944 WM8994_VMID_DISCH);
Mark Brown4b7ed832011-08-10 17:47:33 +0900945
Mark Brownf95be9d2012-08-22 17:25:37 +0100946 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
947 WM8994_VMID_SEL_MASK, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900948
Mark Brownf95be9d2012-08-22 17:25:37 +0100949 msleep(400);
Mark Browne85b26c2012-02-11 23:10:30 +0000950
Mark Brown22f8d052012-03-19 17:32:06 +0000951 /* Active discharge */
Mark Brown4b7ed832011-08-10 17:47:33 +0900952 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
953 WM8994_LINEOUT1_DISCH |
954 WM8994_LINEOUT2_DISCH,
955 WM8994_LINEOUT1_DISCH |
956 WM8994_LINEOUT2_DISCH);
957
Mark Brown22f8d052012-03-19 17:32:06 +0000958 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
959 WM8994_LINEOUT1N_ENA |
960 WM8994_LINEOUT1P_ENA |
961 WM8994_LINEOUT2N_ENA |
962 WM8994_LINEOUT2P_ENA, 0);
963
Mark Brown4b7ed832011-08-10 17:47:33 +0900964 /* Switch off startup biases */
965 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
966 WM8994_BIAS_SRC |
967 WM8994_STARTUP_BIAS_ENA |
968 WM8994_VMID_BUF_ENA |
969 WM8994_VMID_RAMP_MASK, 0);
Mark Brown22f8d052012-03-19 17:32:06 +0000970
971 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
Mark Brownf95be9d2012-08-22 17:25:37 +0100972 WM8994_VMID_SEL_MASK, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900973 }
Mark Browndb966f82012-02-06 12:07:08 +0000974
975 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900976}
977
978static int vmid_event(struct snd_soc_dapm_widget *w,
979 struct snd_kcontrol *kcontrol, int event)
980{
981 struct snd_soc_codec *codec = w->codec;
982
983 switch (event) {
984 case SND_SOC_DAPM_PRE_PMU:
985 vmid_reference(codec);
986 break;
987
988 case SND_SOC_DAPM_POST_PMD:
989 vmid_dereference(codec);
990 break;
991 }
992
993 return 0;
994}
995
Mark Brownc3403042012-04-26 21:29:29 +0100996static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000997{
Mark Brown9e6e96a2010-01-29 17:47:12 +0000998 int source = 0; /* GCC flow analysis can't track enable */
999 int reg, reg_r;
1000
Mark Brownc3403042012-04-26 21:29:29 +01001001 /* We also need the same AIF source for L/R and only one path */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001002 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
1003 switch (reg) {
1004 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001005 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001006 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1007 break;
1008 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001009 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001010 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1011 break;
1012 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001013 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001014 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1015 break;
1016 default:
Mark Brownee839a22010-04-20 13:57:08 +09001017 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brownc3403042012-04-26 21:29:29 +01001018 return false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001019 }
1020
1021 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
1022 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +09001023 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brownc3403042012-04-26 21:29:29 +01001024 return false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001025 }
1026
Mark Brownc3403042012-04-26 21:29:29 +01001027 /* Set the source up */
1028 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
1029 WM8994_CP_DYN_SRC_SEL_MASK, source);
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02001030
Mark Brownc3403042012-04-26 21:29:29 +01001031 return true;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001032}
1033
Mark Brown1a383362012-04-12 19:47:11 +01001034static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1035 struct snd_kcontrol *kcontrol, int event)
1036{
1037 struct snd_soc_codec *codec = w->codec;
Mark Brown79748cd2012-10-01 15:28:30 +01001038 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Vinod Kould3134e22013-05-28 15:41:57 +05301039 struct wm8994 *control = wm8994->wm8994;
Mark Brown1a383362012-04-12 19:47:11 +01001040 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
Mark Brownbfd37bb2012-06-05 12:31:32 +01001041 int i;
Mark Brown1a383362012-04-12 19:47:11 +01001042 int dac;
1043 int adc;
1044 int val;
1045
1046 switch (control->type) {
1047 case WM8994:
1048 case WM8958:
1049 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1050 break;
1051 default:
1052 break;
1053 }
1054
1055 switch (event) {
1056 case SND_SOC_DAPM_PRE_PMU:
Mark Brown79748cd2012-10-01 15:28:30 +01001057 /* Don't enable timeslot 2 if not in use */
1058 if (wm8994->channels[0] <= 2)
1059 mask &= ~(WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
1060
Mark Brown1a383362012-04-12 19:47:11 +01001061 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
1062 if ((val & WM8994_AIF1ADCL_SRC) &&
1063 (val & WM8994_AIF1ADCR_SRC))
1064 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1065 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1066 !(val & WM8994_AIF1ADCR_SRC))
1067 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1068 else
1069 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1070 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1071
1072 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
1073 if ((val & WM8994_AIF1DACL_SRC) &&
1074 (val & WM8994_AIF1DACR_SRC))
1075 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1076 else if (!(val & WM8994_AIF1DACL_SRC) &&
1077 !(val & WM8994_AIF1DACR_SRC))
1078 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1079 else
1080 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1081 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1082
1083 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1084 mask, adc);
1085 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1086 mask, dac);
1087 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1088 WM8994_AIF1DSPCLK_ENA |
1089 WM8994_SYSDSPCLK_ENA,
1090 WM8994_AIF1DSPCLK_ENA |
1091 WM8994_SYSDSPCLK_ENA);
1092 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
1093 WM8994_AIF1ADC1R_ENA |
1094 WM8994_AIF1ADC1L_ENA |
1095 WM8994_AIF1ADC2R_ENA |
1096 WM8994_AIF1ADC2L_ENA);
1097 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
1098 WM8994_AIF1DAC1R_ENA |
1099 WM8994_AIF1DAC1L_ENA |
1100 WM8994_AIF1DAC2R_ENA |
1101 WM8994_AIF1DAC2L_ENA);
1102 break;
1103
Mark Brownbfd37bb2012-06-05 12:31:32 +01001104 case SND_SOC_DAPM_POST_PMU:
1105 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1106 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1107 snd_soc_read(codec,
1108 wm8994_vu_bits[i].reg));
1109 break;
1110
Mark Brown1a383362012-04-12 19:47:11 +01001111 case SND_SOC_DAPM_PRE_PMD:
1112 case SND_SOC_DAPM_POST_PMD:
1113 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1114 mask, 0);
1115 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1116 mask, 0);
1117
1118 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1119 if (val & WM8994_AIF2DSPCLK_ENA)
1120 val = WM8994_SYSDSPCLK_ENA;
1121 else
1122 val = 0;
1123 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1124 WM8994_SYSDSPCLK_ENA |
1125 WM8994_AIF1DSPCLK_ENA, val);
1126 break;
1127 }
1128
1129 return 0;
1130}
1131
1132static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1133 struct snd_kcontrol *kcontrol, int event)
1134{
1135 struct snd_soc_codec *codec = w->codec;
Mark Brownbfd37bb2012-06-05 12:31:32 +01001136 int i;
Mark Brown1a383362012-04-12 19:47:11 +01001137 int dac;
1138 int adc;
1139 int val;
1140
1141 switch (event) {
1142 case SND_SOC_DAPM_PRE_PMU:
1143 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
1144 if ((val & WM8994_AIF2ADCL_SRC) &&
1145 (val & WM8994_AIF2ADCR_SRC))
1146 adc = WM8994_AIF2ADCR_ENA;
1147 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1148 !(val & WM8994_AIF2ADCR_SRC))
1149 adc = WM8994_AIF2ADCL_ENA;
1150 else
1151 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1152
1153
1154 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
1155 if ((val & WM8994_AIF2DACL_SRC) &&
1156 (val & WM8994_AIF2DACR_SRC))
1157 dac = WM8994_AIF2DACR_ENA;
1158 else if (!(val & WM8994_AIF2DACL_SRC) &&
1159 !(val & WM8994_AIF2DACR_SRC))
1160 dac = WM8994_AIF2DACL_ENA;
1161 else
1162 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1163
1164 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1165 WM8994_AIF2ADCL_ENA |
1166 WM8994_AIF2ADCR_ENA, adc);
1167 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1168 WM8994_AIF2DACL_ENA |
1169 WM8994_AIF2DACR_ENA, dac);
1170 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1171 WM8994_AIF2DSPCLK_ENA |
1172 WM8994_SYSDSPCLK_ENA,
1173 WM8994_AIF2DSPCLK_ENA |
1174 WM8994_SYSDSPCLK_ENA);
1175 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1176 WM8994_AIF2ADCL_ENA |
1177 WM8994_AIF2ADCR_ENA,
1178 WM8994_AIF2ADCL_ENA |
1179 WM8994_AIF2ADCR_ENA);
1180 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1181 WM8994_AIF2DACL_ENA |
1182 WM8994_AIF2DACR_ENA,
1183 WM8994_AIF2DACL_ENA |
1184 WM8994_AIF2DACR_ENA);
1185 break;
1186
Mark Brownbfd37bb2012-06-05 12:31:32 +01001187 case SND_SOC_DAPM_POST_PMU:
1188 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1189 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1190 snd_soc_read(codec,
1191 wm8994_vu_bits[i].reg));
1192 break;
1193
Mark Brown1a383362012-04-12 19:47:11 +01001194 case SND_SOC_DAPM_PRE_PMD:
1195 case SND_SOC_DAPM_POST_PMD:
1196 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1197 WM8994_AIF2DACL_ENA |
1198 WM8994_AIF2DACR_ENA, 0);
Mark Brownc7f5f232012-05-15 18:13:00 +01001199 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
Mark Brown1a383362012-04-12 19:47:11 +01001200 WM8994_AIF2ADCL_ENA |
1201 WM8994_AIF2ADCR_ENA, 0);
1202
1203 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1204 if (val & WM8994_AIF1DSPCLK_ENA)
1205 val = WM8994_SYSDSPCLK_ENA;
1206 else
1207 val = 0;
1208 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1209 WM8994_SYSDSPCLK_ENA |
1210 WM8994_AIF2DSPCLK_ENA, val);
1211 break;
1212 }
1213
1214 return 0;
1215}
1216
1217static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1218 struct snd_kcontrol *kcontrol, int event)
1219{
1220 struct snd_soc_codec *codec = w->codec;
1221 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1222
1223 switch (event) {
1224 case SND_SOC_DAPM_PRE_PMU:
1225 wm8994->aif1clk_enable = 1;
1226 break;
1227 case SND_SOC_DAPM_POST_PMD:
1228 wm8994->aif1clk_disable = 1;
1229 break;
1230 }
1231
1232 return 0;
1233}
1234
1235static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1236 struct snd_kcontrol *kcontrol, int event)
1237{
1238 struct snd_soc_codec *codec = w->codec;
1239 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1240
1241 switch (event) {
1242 case SND_SOC_DAPM_PRE_PMU:
1243 wm8994->aif2clk_enable = 1;
1244 break;
1245 case SND_SOC_DAPM_POST_PMD:
1246 wm8994->aif2clk_disable = 1;
1247 break;
1248 }
1249
1250 return 0;
1251}
1252
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001253static int late_enable_ev(struct snd_soc_dapm_widget *w,
1254 struct snd_kcontrol *kcontrol, int event)
1255{
1256 struct snd_soc_codec *codec = w->codec;
1257 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1258
1259 switch (event) {
1260 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001261 if (wm8994->aif1clk_enable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001262 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001263 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1264 WM8994_AIF1CLK_ENA_MASK,
1265 WM8994_AIF1CLK_ENA);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001266 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001267 wm8994->aif1clk_enable = 0;
1268 }
1269 if (wm8994->aif2clk_enable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001270 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001271 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1272 WM8994_AIF2CLK_ENA_MASK,
1273 WM8994_AIF2CLK_ENA);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001274 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001275 wm8994->aif2clk_enable = 0;
1276 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001277 break;
1278 }
1279
Mark Brownc6b7b572011-03-11 18:13:12 +00001280 /* We may also have postponed startup of DSP, handle that. */
1281 wm8958_aif_ev(w, kcontrol, event);
1282
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001283 return 0;
1284}
1285
1286static int late_disable_ev(struct snd_soc_dapm_widget *w,
1287 struct snd_kcontrol *kcontrol, int event)
1288{
1289 struct snd_soc_codec *codec = w->codec;
1290 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1291
1292 switch (event) {
1293 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001294 if (wm8994->aif1clk_disable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001295 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001296 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1297 WM8994_AIF1CLK_ENA_MASK, 0);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001298 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001299 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001300 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001301 if (wm8994->aif2clk_disable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001302 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001303 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1304 WM8994_AIF2CLK_ENA_MASK, 0);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001305 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001306 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001307 }
1308 break;
1309 }
1310
1311 return 0;
1312}
1313
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001314static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1315 struct snd_kcontrol *kcontrol, int event)
1316{
1317 late_enable_ev(w, kcontrol, event);
1318 return 0;
1319}
1320
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001321static int micbias_ev(struct snd_soc_dapm_widget *w,
1322 struct snd_kcontrol *kcontrol, int event)
1323{
1324 late_enable_ev(w, kcontrol, event);
1325 return 0;
1326}
1327
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001328static int dac_ev(struct snd_soc_dapm_widget *w,
1329 struct snd_kcontrol *kcontrol, int event)
1330{
1331 struct snd_soc_codec *codec = w->codec;
1332 unsigned int mask = 1 << w->shift;
1333
1334 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1335 mask, mask);
1336 return 0;
1337}
1338
Mark Brown9e6e96a2010-01-29 17:47:12 +00001339static const char *adc_mux_text[] = {
1340 "ADC",
1341 "DMIC",
1342};
1343
1344static const struct soc_enum adc_enum =
1345 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1346
1347static const struct snd_kcontrol_new adcl_mux =
1348 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1349
1350static const struct snd_kcontrol_new adcr_mux =
1351 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1352
1353static const struct snd_kcontrol_new left_speaker_mixer[] = {
1354SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1355SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1356SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1357SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1358SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1359};
1360
1361static const struct snd_kcontrol_new right_speaker_mixer[] = {
1362SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1363SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1364SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1365SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1366SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1367};
1368
1369/* Debugging; dump chip status after DAPM transitions */
1370static int post_ev(struct snd_soc_dapm_widget *w,
1371 struct snd_kcontrol *kcontrol, int event)
1372{
1373 struct snd_soc_codec *codec = w->codec;
1374 dev_dbg(codec->dev, "SRC status: %x\n",
1375 snd_soc_read(codec,
1376 WM8994_RATE_STATUS));
1377 return 0;
1378}
1379
1380static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1381SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1382 1, 1, 0),
1383SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1384 0, 1, 0),
1385};
1386
1387static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1388SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1389 1, 1, 0),
1390SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1391 0, 1, 0),
1392};
1393
Mark Browna3257ba2010-07-19 14:02:34 +01001394static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1395SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1396 1, 1, 0),
1397SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1398 0, 1, 0),
1399};
1400
1401static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1402SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1403 1, 1, 0),
1404SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1405 0, 1, 0),
1406};
1407
Mark Brown9e6e96a2010-01-29 17:47:12 +00001408static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1409SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1410 5, 1, 0),
1411SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1412 4, 1, 0),
1413SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1414 2, 1, 0),
1415SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1416 1, 1, 0),
1417SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1418 0, 1, 0),
1419};
1420
1421static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1422SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1423 5, 1, 0),
1424SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1425 4, 1, 0),
1426SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1427 2, 1, 0),
1428SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1429 1, 1, 0),
1430SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1431 0, 1, 0),
1432};
1433
1434#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1435{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1436 .info = snd_soc_info_volsw, \
1437 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1438 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1439
1440static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1441 struct snd_ctl_elem_value *ucontrol)
1442{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001443 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1444 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001445 struct snd_soc_codec *codec = w->codec;
1446 int ret;
1447
1448 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1449
Mark Brownc3403042012-04-26 21:29:29 +01001450 wm_hubs_update_class_w(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001451
1452 return ret;
1453}
1454
1455static const struct snd_kcontrol_new dac1l_mix[] = {
1456WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1457 5, 1, 0),
1458WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1459 4, 1, 0),
1460WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1461 2, 1, 0),
1462WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1463 1, 1, 0),
1464WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1465 0, 1, 0),
1466};
1467
1468static const struct snd_kcontrol_new dac1r_mix[] = {
1469WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1470 5, 1, 0),
1471WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1472 4, 1, 0),
1473WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1474 2, 1, 0),
1475WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1476 1, 1, 0),
1477WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1478 0, 1, 0),
1479};
1480
1481static const char *sidetone_text[] = {
1482 "ADC/DMIC1", "DMIC2",
1483};
1484
1485static const struct soc_enum sidetone1_enum =
1486 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1487
1488static const struct snd_kcontrol_new sidetone1_mux =
1489 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1490
1491static const struct soc_enum sidetone2_enum =
1492 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1493
1494static const struct snd_kcontrol_new sidetone2_mux =
1495 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1496
1497static const char *aif1dac_text[] = {
1498 "AIF1DACDAT", "AIF3DACDAT",
1499};
1500
1501static const struct soc_enum aif1dac_enum =
1502 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1503
1504static const struct snd_kcontrol_new aif1dac_mux =
1505 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1506
1507static const char *aif2dac_text[] = {
1508 "AIF2DACDAT", "AIF3DACDAT",
1509};
1510
1511static const struct soc_enum aif2dac_enum =
1512 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1513
1514static const struct snd_kcontrol_new aif2dac_mux =
1515 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1516
1517static const char *aif2adc_text[] = {
1518 "AIF2ADCDAT", "AIF3DACDAT",
1519};
1520
1521static const struct soc_enum aif2adc_enum =
1522 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1523
1524static const struct snd_kcontrol_new aif2adc_mux =
1525 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1526
1527static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001528 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001529};
1530
Mark Brownc4431df2010-11-26 15:21:07 +00001531static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001532 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1533
Mark Brownc4431df2010-11-26 15:21:07 +00001534static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1535 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1536
1537static const struct soc_enum wm8958_aif3adc_enum =
1538 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1539
1540static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1541 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1542
1543static const char *mono_pcm_out_text[] = {
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02001544 "None", "AIF2ADCL", "AIF2ADCR",
Mark Brownc4431df2010-11-26 15:21:07 +00001545};
1546
1547static const struct soc_enum mono_pcm_out_enum =
1548 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1549
1550static const struct snd_kcontrol_new mono_pcm_out_mux =
1551 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1552
1553static const char *aif2dac_src_text[] = {
1554 "AIF2", "AIF3",
1555};
1556
1557/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1558static const struct soc_enum aif2dacl_src_enum =
1559 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1560
1561static const struct snd_kcontrol_new aif2dacl_src_mux =
1562 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1563
1564static const struct soc_enum aif2dacr_src_enum =
1565 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1566
1567static const struct snd_kcontrol_new aif2dacr_src_mux =
1568 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001569
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001570static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001571SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001572 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown1a383362012-04-12 19:47:11 +01001573SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001574 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1575
1576SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1577 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1578SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1579 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1580SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1581 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1582SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1583 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001584SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1585 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1586
1587SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1588 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1589 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1590SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1591 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1592 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownc3403042012-04-26 21:29:29 +01001593SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
Mark Brownb70a51b2011-06-29 00:21:09 -07001594 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownc3403042012-04-26 21:29:29 +01001595SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
Mark Brownb70a51b2011-06-29 00:21:09 -07001596 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001597
1598SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1599};
1600
1601static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001602SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
Mark Brownbfd37bb2012-06-05 12:31:32 +01001603 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1604 SND_SOC_DAPM_PRE_PMD),
Mark Brown1a383362012-04-12 19:47:11 +01001605SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
Mark Brownbfd37bb2012-06-05 12:31:32 +01001606 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1607 SND_SOC_DAPM_PRE_PMD),
Mark Brownb70a51b2011-06-29 00:21:09 -07001608SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1609SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1610 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1611SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1612 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
Mark Brownc3403042012-04-26 21:29:29 +01001613SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1614SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001615};
1616
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001617static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1618SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1619 dac_ev, SND_SOC_DAPM_PRE_PMU),
1620SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1621 dac_ev, SND_SOC_DAPM_PRE_PMU),
1622SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1623 dac_ev, SND_SOC_DAPM_PRE_PMU),
1624SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1625 dac_ev, SND_SOC_DAPM_PRE_PMU),
1626};
1627
1628static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1629SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001630SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001631SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1632SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1633};
1634
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001635static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001636SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1637 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1638SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1639 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001640};
1641
1642static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001643SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1644SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001645};
1646
Mark Brown9e6e96a2010-01-29 17:47:12 +00001647static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1648SND_SOC_DAPM_INPUT("DMIC1DAT"),
1649SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001650SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001651
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001652SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1653 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001654SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1655 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001656
Mark Brown9e6e96a2010-01-29 17:47:12 +00001657SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
Mark Brown99af79d2012-07-25 23:03:36 +01001658 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1659 SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001660
Mark Brown1a383362012-04-12 19:47:11 +01001661SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1662SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1663SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001664
Mark Brown7f94de42011-02-03 16:27:34 +00001665SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001666 0, SND_SOC_NOPM, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001667SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001668 0, SND_SOC_NOPM, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001669SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001670 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001671 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001672SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001673 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001674 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001675
Mark Brown7f94de42011-02-03 16:27:34 +00001676SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001677 0, SND_SOC_NOPM, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001678SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001679 0, SND_SOC_NOPM, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001680SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001681 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001682 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001683SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001684 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001685 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001686
1687SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1688 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1689SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1690 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1691
Mark Browna3257ba2010-07-19 14:02:34 +01001692SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1693 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1694SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1695 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1696
Mark Brown9e6e96a2010-01-29 17:47:12 +00001697SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1698 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1699SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1700 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1701
1702SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1703SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1704
1705SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1706 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1707SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1708 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1709
1710SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001711 SND_SOC_NOPM, 13, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001712SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001713 SND_SOC_NOPM, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001714SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001715 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001716 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1717SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001718 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001719 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001720
Mark Brown5567d8c2012-02-16 21:43:29 -08001721SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1722SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1723SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1724SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001725
1726SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1727SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1728SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001729
Mark Brown5567d8c2012-02-16 21:43:29 -08001730SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1731SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001732
1733SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1734
1735SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1736SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1737SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1738SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1739
1740/* Power is done with the muxes since the ADC power also controls the
1741 * downsampling chain, the chip will automatically manage the analogue
1742 * specific portions.
1743 */
1744SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1745SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1746
Mark Brown9e6e96a2010-01-29 17:47:12 +00001747SND_SOC_DAPM_POST("Debug log", post_ev),
1748};
1749
Mark Brownc4431df2010-11-26 15:21:07 +00001750static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1751SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1752};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001753
Mark Brownc4431df2010-11-26 15:21:07 +00001754static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
Mark Brown8c5b8422012-04-17 20:49:05 +01001755SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
Mark Brownc4431df2010-11-26 15:21:07 +00001756SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1757SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1758SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1759SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1760};
1761
1762static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001763 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1764 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1765
1766 { "DSP1CLK", NULL, "CLK_SYS" },
1767 { "DSP2CLK", NULL, "CLK_SYS" },
1768 { "DSPINTCLK", NULL, "CLK_SYS" },
1769
1770 { "AIF1ADC1L", NULL, "AIF1CLK" },
1771 { "AIF1ADC1L", NULL, "DSP1CLK" },
1772 { "AIF1ADC1R", NULL, "AIF1CLK" },
1773 { "AIF1ADC1R", NULL, "DSP1CLK" },
1774 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1775
1776 { "AIF1DAC1L", NULL, "AIF1CLK" },
1777 { "AIF1DAC1L", NULL, "DSP1CLK" },
1778 { "AIF1DAC1R", NULL, "AIF1CLK" },
1779 { "AIF1DAC1R", NULL, "DSP1CLK" },
1780 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1781
1782 { "AIF1ADC2L", NULL, "AIF1CLK" },
1783 { "AIF1ADC2L", NULL, "DSP1CLK" },
1784 { "AIF1ADC2R", NULL, "AIF1CLK" },
1785 { "AIF1ADC2R", NULL, "DSP1CLK" },
1786 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1787
1788 { "AIF1DAC2L", NULL, "AIF1CLK" },
1789 { "AIF1DAC2L", NULL, "DSP1CLK" },
1790 { "AIF1DAC2R", NULL, "AIF1CLK" },
1791 { "AIF1DAC2R", NULL, "DSP1CLK" },
1792 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1793
1794 { "AIF2ADCL", NULL, "AIF2CLK" },
1795 { "AIF2ADCL", NULL, "DSP2CLK" },
1796 { "AIF2ADCR", NULL, "AIF2CLK" },
1797 { "AIF2ADCR", NULL, "DSP2CLK" },
1798 { "AIF2ADCR", NULL, "DSPINTCLK" },
1799
1800 { "AIF2DACL", NULL, "AIF2CLK" },
1801 { "AIF2DACL", NULL, "DSP2CLK" },
1802 { "AIF2DACR", NULL, "AIF2CLK" },
1803 { "AIF2DACR", NULL, "DSP2CLK" },
1804 { "AIF2DACR", NULL, "DSPINTCLK" },
1805
1806 { "DMIC1L", NULL, "DMIC1DAT" },
1807 { "DMIC1L", NULL, "CLK_SYS" },
1808 { "DMIC1R", NULL, "DMIC1DAT" },
1809 { "DMIC1R", NULL, "CLK_SYS" },
1810 { "DMIC2L", NULL, "DMIC2DAT" },
1811 { "DMIC2L", NULL, "CLK_SYS" },
1812 { "DMIC2R", NULL, "DMIC2DAT" },
1813 { "DMIC2R", NULL, "CLK_SYS" },
1814
1815 { "ADCL", NULL, "AIF1CLK" },
1816 { "ADCL", NULL, "DSP1CLK" },
1817 { "ADCL", NULL, "DSPINTCLK" },
1818
1819 { "ADCR", NULL, "AIF1CLK" },
1820 { "ADCR", NULL, "DSP1CLK" },
1821 { "ADCR", NULL, "DSPINTCLK" },
1822
1823 { "ADCL Mux", "ADC", "ADCL" },
1824 { "ADCL Mux", "DMIC", "DMIC1L" },
1825 { "ADCR Mux", "ADC", "ADCR" },
1826 { "ADCR Mux", "DMIC", "DMIC1R" },
1827
1828 { "DAC1L", NULL, "AIF1CLK" },
1829 { "DAC1L", NULL, "DSP1CLK" },
1830 { "DAC1L", NULL, "DSPINTCLK" },
1831
1832 { "DAC1R", NULL, "AIF1CLK" },
1833 { "DAC1R", NULL, "DSP1CLK" },
1834 { "DAC1R", NULL, "DSPINTCLK" },
1835
1836 { "DAC2L", NULL, "AIF2CLK" },
1837 { "DAC2L", NULL, "DSP2CLK" },
1838 { "DAC2L", NULL, "DSPINTCLK" },
1839
1840 { "DAC2R", NULL, "AIF2DACR" },
1841 { "DAC2R", NULL, "AIF2CLK" },
1842 { "DAC2R", NULL, "DSP2CLK" },
1843 { "DAC2R", NULL, "DSPINTCLK" },
1844
1845 { "TOCLK", NULL, "CLK_SYS" },
1846
Mark Brown5567d8c2012-02-16 21:43:29 -08001847 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1848 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1849 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1850
1851 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1852 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1853 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1854
Mark Brown9e6e96a2010-01-29 17:47:12 +00001855 /* AIF1 outputs */
1856 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1857 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1858 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1859
1860 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1861 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1862 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1863
Mark Browna3257ba2010-07-19 14:02:34 +01001864 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1865 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1866 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1867
1868 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1869 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1870 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1871
Mark Brown9e6e96a2010-01-29 17:47:12 +00001872 /* Pin level routing for AIF3 */
1873 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1874 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1875 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1876 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1877
Mark Brown9e6e96a2010-01-29 17:47:12 +00001878 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1879 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1880 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1881 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1882 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1883 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1884 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1885
1886 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001887 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1888 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1889 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1890 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1891 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1892
Mark Brown9e6e96a2010-01-29 17:47:12 +00001893 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1894 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1895 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1896 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1897 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1898
1899 /* DAC2/AIF2 outputs */
1900 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001901 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1902 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1903 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1904 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1905 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1906
1907 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001908 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1909 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1910 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1911 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1912 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1913
Mark Brown7f94de42011-02-03 16:27:34 +00001914 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1915 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1916 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1917 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1918
Mark Brown9e6e96a2010-01-29 17:47:12 +00001919 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1920
1921 /* AIF3 output */
1922 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1923 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1924 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1925 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1926 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1927 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1928 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1929 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1930
1931 /* Sidetone */
1932 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1933 { "Left Sidetone", "DMIC2", "DMIC2L" },
1934 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1935 { "Right Sidetone", "DMIC2", "DMIC2R" },
1936
1937 /* Output stages */
1938 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1939 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1940
1941 { "SPKL", "DAC1 Switch", "DAC1L" },
1942 { "SPKL", "DAC2 Switch", "DAC2L" },
1943
1944 { "SPKR", "DAC1 Switch", "DAC1R" },
1945 { "SPKR", "DAC2 Switch", "DAC2R" },
1946
1947 { "Left Headphone Mux", "DAC", "DAC1L" },
1948 { "Right Headphone Mux", "DAC", "DAC1R" },
1949};
1950
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001951static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1952 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1953 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1954 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1955 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1956 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1957 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1958 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1959 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1960};
1961
1962static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1963 { "DAC1L", NULL, "DAC1L Mixer" },
1964 { "DAC1R", NULL, "DAC1R Mixer" },
1965 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1966 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1967};
1968
Mark Brown6ed8f142011-02-03 16:27:35 +00001969static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1970 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1971 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1972 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1973 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001974 { "MICBIAS1", NULL, "CLK_SYS" },
1975 { "MICBIAS1", NULL, "MICBIAS Supply" },
1976 { "MICBIAS2", NULL, "CLK_SYS" },
1977 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001978};
1979
Mark Brownc4431df2010-11-26 15:21:07 +00001980static const struct snd_soc_dapm_route wm8994_intercon[] = {
1981 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1982 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001983 { "MICBIAS1", NULL, "VMID" },
1984 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001985};
1986
1987static const struct snd_soc_dapm_route wm8958_intercon[] = {
1988 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1989 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1990
1991 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1992 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1993 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1994 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1995
Mark Brown8c5b8422012-04-17 20:49:05 +01001996 { "AIF3DACDAT", NULL, "AIF3" },
1997 { "AIF3ADCDAT", NULL, "AIF3" },
1998
Mark Brownc4431df2010-11-26 15:21:07 +00001999 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
2000 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
2001
2002 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
2003};
2004
Mark Brown9e6e96a2010-01-29 17:47:12 +00002005/* The size in bits of the FLL divide multiplied by 10
2006 * to allow rounding later */
2007#define FIXED_FLL_SIZE ((1 << 16) * 10)
2008
2009struct fll_div {
2010 u16 outdiv;
2011 u16 n;
2012 u16 k;
2013 u16 clk_ref_div;
2014 u16 fll_fratio;
2015};
2016
2017static int wm8994_get_fll_config(struct fll_div *fll,
2018 int freq_in, int freq_out)
2019{
2020 u64 Kpart;
2021 unsigned int K, Ndiv, Nmod;
2022
2023 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2024
2025 /* Scale the input frequency down to <= 13.5MHz */
2026 fll->clk_ref_div = 0;
2027 while (freq_in > 13500000) {
2028 fll->clk_ref_div++;
2029 freq_in /= 2;
2030
2031 if (fll->clk_ref_div > 3)
2032 return -EINVAL;
2033 }
2034 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2035
2036 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2037 fll->outdiv = 3;
2038 while (freq_out * (fll->outdiv + 1) < 90000000) {
2039 fll->outdiv++;
2040 if (fll->outdiv > 63)
2041 return -EINVAL;
2042 }
2043 freq_out *= fll->outdiv + 1;
2044 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2045
2046 if (freq_in > 1000000) {
2047 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002048 } else if (freq_in > 256000) {
2049 fll->fll_fratio = 1;
2050 freq_in *= 2;
2051 } else if (freq_in > 128000) {
2052 fll->fll_fratio = 2;
2053 freq_in *= 4;
2054 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002055 fll->fll_fratio = 3;
2056 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002057 } else {
2058 fll->fll_fratio = 4;
2059 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002060 }
2061 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2062
2063 /* Now, calculate N.K */
2064 Ndiv = freq_out / freq_in;
2065
2066 fll->n = Ndiv;
2067 Nmod = freq_out % freq_in;
2068 pr_debug("Nmod=%d\n", Nmod);
2069
2070 /* Calculate fractional part - scale up so we can round. */
2071 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2072
2073 do_div(Kpart, freq_in);
2074
2075 K = Kpart & 0xFFFFFFFF;
2076
2077 if ((K % 10) >= 5)
2078 K += 5;
2079
2080 /* Move down to proper range now rounding is done */
2081 fll->k = K / 10;
2082
2083 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2084
2085 return 0;
2086}
2087
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002088static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002089 unsigned int freq_in, unsigned int freq_out)
2090{
Mark Brownb2c812e2010-04-14 15:35:19 +09002091 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002092 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002093 int reg_offset, ret;
2094 struct fll_div fll;
Mark Browne413ba82012-03-29 14:49:27 +01002095 u16 reg, clk1, aif_reg, aif_src;
Mark Brownc7ebf932011-07-12 19:47:59 +09002096 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09002097 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002098
Mark Brown9e6e96a2010-01-29 17:47:12 +00002099 switch (id) {
2100 case WM8994_FLL1:
2101 reg_offset = 0;
2102 id = 0;
Mark Browne413ba82012-03-29 14:49:27 +01002103 aif_src = 0x10;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002104 break;
2105 case WM8994_FLL2:
2106 reg_offset = 0x20;
2107 id = 1;
Mark Browne413ba82012-03-29 14:49:27 +01002108 aif_src = 0x18;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002109 break;
2110 default:
2111 return -EINVAL;
2112 }
2113
Mark Brown4b7ed832011-08-10 17:47:33 +09002114 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
2115 was_enabled = reg & WM8994_FLL1_ENA;
2116
Mark Brown136ff2a2010-04-20 12:56:18 +09002117 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09002118 case 0:
2119 /* Allow no source specification when stopping */
2120 if (freq_out)
2121 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00002122 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09002123 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09002124 case WM8994_FLL_SRC_MCLK1:
2125 case WM8994_FLL_SRC_MCLK2:
2126 case WM8994_FLL_SRC_LRCLK:
2127 case WM8994_FLL_SRC_BCLK:
2128 break;
Mark Brownfbfe6982012-07-23 20:14:43 +01002129 case WM8994_FLL_SRC_INTERNAL:
2130 freq_in = 12000000;
2131 freq_out = 12000000;
2132 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09002133 default:
2134 return -EINVAL;
2135 }
2136
Mark Brown9e6e96a2010-01-29 17:47:12 +00002137 /* Are we changing anything? */
2138 if (wm8994->fll[id].src == src &&
2139 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2140 return 0;
2141
2142 /* If we're stopping the FLL redo the old config - no
2143 * registers will actually be written but we avoid GCC flow
2144 * analysis bugs spewing warnings.
2145 */
2146 if (freq_out)
2147 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
2148 else
2149 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
2150 wm8994->fll[id].out);
2151 if (ret < 0)
2152 return ret;
2153
Mark Browne413ba82012-03-29 14:49:27 +01002154 /* Make sure that we're not providing SYSCLK right now */
2155 clk1 = snd_soc_read(codec, WM8994_CLOCKING_1);
2156 if (clk1 & WM8994_SYSCLK_SRC)
2157 aif_reg = WM8994_AIF2_CLOCKING_1;
2158 else
2159 aif_reg = WM8994_AIF1_CLOCKING_1;
2160 reg = snd_soc_read(codec, aif_reg);
2161
2162 if ((reg & WM8994_AIF1CLK_ENA) &&
2163 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2164 dev_err(codec->dev, "FLL%d is currently providing SYSCLK\n",
2165 id + 1);
2166 return -EBUSY;
2167 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002168
2169 /* We always need to disable the FLL while reconfiguring */
2170 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2171 WM8994_FLL1_ENA, 0);
2172
Mark Brown20dc24a2012-04-05 12:55:20 +01002173 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
Kyung-Kwee Ryue05854d2012-04-24 18:01:48 +01002174 freq_in == freq_out && freq_out) {
Mark Brown20dc24a2012-04-05 12:55:20 +01002175 dev_dbg(codec->dev, "Bypassing FLL%d\n", id + 1);
2176 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2177 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2178 goto out;
2179 }
2180
Mark Brown9e6e96a2010-01-29 17:47:12 +00002181 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2182 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2183 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
2184 WM8994_FLL1_OUTDIV_MASK |
2185 WM8994_FLL1_FRATIO_MASK, reg);
2186
Mark Brownb16db742012-03-03 15:33:23 +00002187 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
2188 WM8994_FLL1_K_MASK, fll.k);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002189
2190 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
2191 WM8994_FLL1_N_MASK,
Mark Brown7435d4e2012-07-26 14:49:11 +01002192 fll.n << WM8994_FLL1_N_SHIFT);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002193
2194 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brownfbfe6982012-07-23 20:14:43 +01002195 WM8994_FLL1_FRC_NCO | WM8958_FLL1_BYP |
Mark Brown136ff2a2010-04-20 12:56:18 +09002196 WM8994_FLL1_REFCLK_DIV_MASK |
2197 WM8994_FLL1_REFCLK_SRC_MASK,
Mark Brownfbfe6982012-07-23 20:14:43 +01002198 ((src == WM8994_FLL_SRC_INTERNAL)
2199 << WM8994_FLL1_FRC_NCO_SHIFT) |
Mark Brown136ff2a2010-04-20 12:56:18 +09002200 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2201 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00002202
Mark Brownf0f50392011-07-16 03:12:18 +09002203 /* Clear any pending completion from a previous failure */
2204 try_wait_for_completion(&wm8994->fll_locked[id]);
2205
Mark Brown9e6e96a2010-01-29 17:47:12 +00002206 /* Enable (with fractional mode if required) */
2207 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09002208 /* Enable VMID if we need it */
2209 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002210 active_reference(codec);
2211
Mark Brown4b7ed832011-08-10 17:47:33 +09002212 switch (control->type) {
2213 case WM8994:
2214 vmid_reference(codec);
2215 break;
2216 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002217 if (control->revision < 1)
Mark Brown4b7ed832011-08-10 17:47:33 +09002218 vmid_reference(codec);
2219 break;
2220 default:
2221 break;
2222 }
2223 }
2224
Mark Brownfbfe6982012-07-23 20:14:43 +01002225 reg = WM8994_FLL1_ENA;
2226
Mark Brown9e6e96a2010-01-29 17:47:12 +00002227 if (fll.k)
Mark Brownfbfe6982012-07-23 20:14:43 +01002228 reg |= WM8994_FLL1_FRAC;
2229 if (src == WM8994_FLL_SRC_INTERNAL)
2230 reg |= WM8994_FLL1_OSC_ENA;
2231
Mark Brown9e6e96a2010-01-29 17:47:12 +00002232 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
Mark Brownfbfe6982012-07-23 20:14:43 +01002233 WM8994_FLL1_ENA | WM8994_FLL1_OSC_ENA |
2234 WM8994_FLL1_FRAC, reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07002235
Mark Brownc7ebf932011-07-12 19:47:59 +09002236 if (wm8994->fll_locked_irq) {
2237 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2238 msecs_to_jiffies(10));
2239 if (timeout == 0)
2240 dev_warn(codec->dev,
2241 "Timed out waiting for FLL lock\n");
2242 } else {
2243 msleep(5);
2244 }
Mark Brown4b7ed832011-08-10 17:47:33 +09002245 } else {
2246 if (was_enabled) {
2247 switch (control->type) {
2248 case WM8994:
2249 vmid_dereference(codec);
2250 break;
2251 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002252 if (control->revision < 1)
Mark Brown4b7ed832011-08-10 17:47:33 +09002253 vmid_dereference(codec);
2254 break;
2255 default:
2256 break;
2257 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002258
2259 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09002260 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002261 }
2262
Mark Brown20dc24a2012-04-05 12:55:20 +01002263out:
Mark Brown9e6e96a2010-01-29 17:47:12 +00002264 wm8994->fll[id].in = freq_in;
2265 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09002266 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002267
Mark Brown9e6e96a2010-01-29 17:47:12 +00002268 configure_clock(codec);
2269
Mark Browncd220002012-10-24 10:56:30 +01002270 /*
2271 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2272 * for detection.
2273 */
2274 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2275 dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
Mark Brownd3725762013-01-29 23:17:12 +08002276
2277 wm8994->aifdiv[0] = snd_soc_read(codec, WM8994_AIF1_RATE)
2278 & WM8994_AIF1CLK_RATE_MASK;
2279 wm8994->aifdiv[1] = snd_soc_read(codec, WM8994_AIF2_RATE)
2280 & WM8994_AIF1CLK_RATE_MASK;
2281
Mark Browncd220002012-10-24 10:56:30 +01002282 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2283 WM8994_AIF1CLK_RATE_MASK, 0x1);
2284 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2285 WM8994_AIF2CLK_RATE_MASK, 0x1);
Mark Brownd3725762013-01-29 23:17:12 +08002286 } else if (wm8994->aifdiv[0]) {
2287 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2288 WM8994_AIF1CLK_RATE_MASK,
2289 wm8994->aifdiv[0]);
2290 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2291 WM8994_AIF2CLK_RATE_MASK,
2292 wm8994->aifdiv[1]);
2293
2294 wm8994->aifdiv[0] = 0;
2295 wm8994->aifdiv[1] = 0;
Mark Browncd220002012-10-24 10:56:30 +01002296 }
2297
Mark Brown9e6e96a2010-01-29 17:47:12 +00002298 return 0;
2299}
2300
Mark Brownc7ebf932011-07-12 19:47:59 +09002301static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2302{
2303 struct completion *completion = data;
2304
2305 complete(completion);
2306
2307 return IRQ_HANDLED;
2308}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002309
Mark Brown66b47fd2010-07-08 11:25:43 +09002310static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2311
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002312static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2313 unsigned int freq_in, unsigned int freq_out)
2314{
2315 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2316}
2317
Mark Brown9e6e96a2010-01-29 17:47:12 +00002318static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2319 int clk_id, unsigned int freq, int dir)
2320{
2321 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002322 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002323 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002324
2325 switch (dai->id) {
2326 case 1:
2327 case 2:
2328 break;
2329
2330 default:
2331 /* AIF3 shares clocking with AIF1/2 */
2332 return -EINVAL;
2333 }
2334
2335 switch (clk_id) {
2336 case WM8994_SYSCLK_MCLK1:
2337 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2338 wm8994->mclk[0] = freq;
2339 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2340 dai->id, freq);
2341 break;
2342
2343 case WM8994_SYSCLK_MCLK2:
2344 /* TODO: Set GPIO AF */
2345 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2346 wm8994->mclk[1] = freq;
2347 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2348 dai->id, freq);
2349 break;
2350
2351 case WM8994_SYSCLK_FLL1:
2352 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2353 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2354 break;
2355
2356 case WM8994_SYSCLK_FLL2:
2357 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2358 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2359 break;
2360
Mark Brown66b47fd2010-07-08 11:25:43 +09002361 case WM8994_SYSCLK_OPCLK:
2362 /* Special case - a division (times 10) is given and
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02002363 * no effect on main clocking.
Mark Brown66b47fd2010-07-08 11:25:43 +09002364 */
2365 if (freq) {
2366 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2367 if (opclk_divs[i] == freq)
2368 break;
2369 if (i == ARRAY_SIZE(opclk_divs))
2370 return -EINVAL;
2371 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2372 WM8994_OPCLK_DIV_MASK, i);
2373 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2374 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2375 } else {
2376 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2377 WM8994_OPCLK_ENA, 0);
2378 }
2379
Mark Brown9e6e96a2010-01-29 17:47:12 +00002380 default:
2381 return -EINVAL;
2382 }
2383
2384 configure_clock(codec);
2385
Mark Brown67300492012-10-24 10:56:30 +01002386 /*
2387 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2388 * for detection.
2389 */
2390 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2391 dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
Mark Brownd3725762013-01-29 23:17:12 +08002392
2393 wm8994->aifdiv[0] = snd_soc_read(codec, WM8994_AIF1_RATE)
2394 & WM8994_AIF1CLK_RATE_MASK;
2395 wm8994->aifdiv[1] = snd_soc_read(codec, WM8994_AIF2_RATE)
2396 & WM8994_AIF1CLK_RATE_MASK;
2397
Mark Brown67300492012-10-24 10:56:30 +01002398 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2399 WM8994_AIF1CLK_RATE_MASK, 0x1);
2400 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2401 WM8994_AIF2CLK_RATE_MASK, 0x1);
Mark Brownd3725762013-01-29 23:17:12 +08002402 } else if (wm8994->aifdiv[0]) {
2403 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2404 WM8994_AIF1CLK_RATE_MASK,
2405 wm8994->aifdiv[0]);
2406 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2407 WM8994_AIF2CLK_RATE_MASK,
2408 wm8994->aifdiv[1]);
2409
2410 wm8994->aifdiv[0] = 0;
2411 wm8994->aifdiv[1] = 0;
Mark Brown67300492012-10-24 10:56:30 +01002412 }
2413
Mark Brown9e6e96a2010-01-29 17:47:12 +00002414 return 0;
2415}
2416
2417static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2418 enum snd_soc_bias_level level)
2419{
Mark Brownb6b05692010-08-13 12:58:20 +01002420 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002421 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002422
Mark Brown5f2f3892012-02-08 18:51:42 +00002423 wm_hubs_set_bias_level(codec, level);
2424
Mark Brown9e6e96a2010-01-29 17:47:12 +00002425 switch (level) {
2426 case SND_SOC_BIAS_ON:
2427 break;
2428
2429 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002430 /* MICBIAS into regulating mode */
2431 switch (control->type) {
2432 case WM8958:
2433 case WM1811:
2434 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2435 WM8958_MICB1_MODE, 0);
2436 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2437 WM8958_MICB2_MODE, 0);
2438 break;
2439 default:
2440 break;
2441 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002442
2443 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2444 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002445 break;
2446
2447 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002448 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002449 switch (control->type) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002450 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002451 if (control->revision == 0) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002452 /* Optimise performance for rev A */
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002453 snd_soc_update_bits(codec,
2454 WM8958_CHARGE_PUMP_2,
2455 WM8958_CP_DISCH,
2456 WM8958_CP_DISCH);
2457 }
2458 break;
Mark Brown81204c82011-05-24 17:35:53 +08002459
Mark Brown462835e2012-01-21 12:11:53 +00002460 default:
Mark Brown81204c82011-05-24 17:35:53 +08002461 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002462 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002463
2464 /* Discharge LINEOUT1 & 2 */
2465 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2466 WM8994_LINEOUT1_DISCH |
2467 WM8994_LINEOUT2_DISCH,
2468 WM8994_LINEOUT1_DISCH |
2469 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002470 }
2471
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002472 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2473 active_dereference(codec);
2474
Mark Brown500fa302011-11-29 19:58:19 +00002475 /* MICBIAS into bypass mode on newer devices */
2476 switch (control->type) {
2477 case WM8958:
2478 case WM1811:
2479 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2480 WM8958_MICB1_MODE,
2481 WM8958_MICB1_MODE);
2482 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2483 WM8958_MICB2_MODE,
2484 WM8958_MICB2_MODE);
2485 break;
2486 default:
2487 break;
2488 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002489 break;
2490
2491 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002492 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002493 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002494 break;
2495 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002496
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002497 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002498
Mark Brown9e6e96a2010-01-29 17:47:12 +00002499 return 0;
2500}
2501
Mark Brown22f8d052012-03-19 17:32:06 +00002502int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2503{
2504 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2505
2506 switch (mode) {
2507 case WM8994_VMID_NORMAL:
2508 if (wm8994->hubs.lineout1_se) {
2509 snd_soc_dapm_disable_pin(&codec->dapm,
2510 "LINEOUT1N Driver");
2511 snd_soc_dapm_disable_pin(&codec->dapm,
2512 "LINEOUT1P Driver");
2513 }
2514 if (wm8994->hubs.lineout2_se) {
2515 snd_soc_dapm_disable_pin(&codec->dapm,
2516 "LINEOUT2N Driver");
2517 snd_soc_dapm_disable_pin(&codec->dapm,
2518 "LINEOUT2P Driver");
2519 }
2520
2521 /* Do the sync with the old mode to allow it to clean up */
2522 snd_soc_dapm_sync(&codec->dapm);
2523 wm8994->vmid_mode = mode;
2524 break;
2525
2526 case WM8994_VMID_FORCE:
2527 if (wm8994->hubs.lineout1_se) {
2528 snd_soc_dapm_force_enable_pin(&codec->dapm,
2529 "LINEOUT1N Driver");
2530 snd_soc_dapm_force_enable_pin(&codec->dapm,
2531 "LINEOUT1P Driver");
2532 }
2533 if (wm8994->hubs.lineout2_se) {
2534 snd_soc_dapm_force_enable_pin(&codec->dapm,
2535 "LINEOUT2N Driver");
2536 snd_soc_dapm_force_enable_pin(&codec->dapm,
2537 "LINEOUT2P Driver");
2538 }
2539
2540 wm8994->vmid_mode = mode;
2541 snd_soc_dapm_sync(&codec->dapm);
2542 break;
2543
2544 default:
2545 return -EINVAL;
2546 }
2547
2548 return 0;
2549}
2550
Mark Brown9e6e96a2010-01-29 17:47:12 +00002551static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2552{
2553 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002554 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2555 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002556 int ms_reg;
2557 int aif1_reg;
2558 int ms = 0;
2559 int aif1 = 0;
2560
2561 switch (dai->id) {
2562 case 1:
2563 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2564 aif1_reg = WM8994_AIF1_CONTROL_1;
2565 break;
2566 case 2:
2567 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2568 aif1_reg = WM8994_AIF2_CONTROL_1;
2569 break;
2570 default:
2571 return -EINVAL;
2572 }
2573
2574 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2575 case SND_SOC_DAIFMT_CBS_CFS:
2576 break;
2577 case SND_SOC_DAIFMT_CBM_CFM:
2578 ms = WM8994_AIF1_MSTR;
2579 break;
2580 default:
2581 return -EINVAL;
2582 }
2583
2584 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2585 case SND_SOC_DAIFMT_DSP_B:
2586 aif1 |= WM8994_AIF1_LRCLK_INV;
2587 case SND_SOC_DAIFMT_DSP_A:
2588 aif1 |= 0x18;
2589 break;
2590 case SND_SOC_DAIFMT_I2S:
2591 aif1 |= 0x10;
2592 break;
2593 case SND_SOC_DAIFMT_RIGHT_J:
2594 break;
2595 case SND_SOC_DAIFMT_LEFT_J:
2596 aif1 |= 0x8;
2597 break;
2598 default:
2599 return -EINVAL;
2600 }
2601
2602 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2603 case SND_SOC_DAIFMT_DSP_A:
2604 case SND_SOC_DAIFMT_DSP_B:
2605 /* frame inversion not valid for DSP modes */
2606 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2607 case SND_SOC_DAIFMT_NB_NF:
2608 break;
2609 case SND_SOC_DAIFMT_IB_NF:
2610 aif1 |= WM8994_AIF1_BCLK_INV;
2611 break;
2612 default:
2613 return -EINVAL;
2614 }
2615 break;
2616
2617 case SND_SOC_DAIFMT_I2S:
2618 case SND_SOC_DAIFMT_RIGHT_J:
2619 case SND_SOC_DAIFMT_LEFT_J:
2620 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2621 case SND_SOC_DAIFMT_NB_NF:
2622 break;
2623 case SND_SOC_DAIFMT_IB_IF:
2624 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2625 break;
2626 case SND_SOC_DAIFMT_IB_NF:
2627 aif1 |= WM8994_AIF1_BCLK_INV;
2628 break;
2629 case SND_SOC_DAIFMT_NB_IF:
2630 aif1 |= WM8994_AIF1_LRCLK_INV;
2631 break;
2632 default:
2633 return -EINVAL;
2634 }
2635 break;
2636 default:
2637 return -EINVAL;
2638 }
2639
Mark Brownc4431df2010-11-26 15:21:07 +00002640 /* The AIF2 format configuration needs to be mirrored to AIF3
2641 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002642 switch (control->type) {
2643 case WM1811:
2644 case WM8958:
2645 if (dai->id == 2)
2646 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2647 WM8994_AIF1_LRCLK_INV |
2648 WM8958_AIF3_FMT_MASK, aif1);
2649 break;
2650
2651 default:
2652 break;
2653 }
Mark Brownc4431df2010-11-26 15:21:07 +00002654
Mark Brown9e6e96a2010-01-29 17:47:12 +00002655 snd_soc_update_bits(codec, aif1_reg,
2656 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2657 WM8994_AIF1_FMT_MASK,
2658 aif1);
2659 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2660 ms);
2661
2662 return 0;
2663}
2664
2665static struct {
2666 int val, rate;
2667} srs[] = {
2668 { 0, 8000 },
2669 { 1, 11025 },
2670 { 2, 12000 },
2671 { 3, 16000 },
2672 { 4, 22050 },
2673 { 5, 24000 },
2674 { 6, 32000 },
2675 { 7, 44100 },
2676 { 8, 48000 },
2677 { 9, 88200 },
2678 { 10, 96000 },
2679};
2680
2681static int fs_ratios[] = {
2682 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2683};
2684
2685static int bclk_divs[] = {
2686 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2687 640, 880, 960, 1280, 1760, 1920
2688};
2689
2690static int wm8994_hw_params(struct snd_pcm_substream *substream,
2691 struct snd_pcm_hw_params *params,
2692 struct snd_soc_dai *dai)
2693{
2694 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002695 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown3cf956e2013-03-20 10:12:10 +01002696 struct wm8994 *control = wm8994->wm8994;
2697 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002698 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002699 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002700 int bclk_reg;
2701 int lrclk_reg;
2702 int rate_reg;
2703 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002704 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002705 int bclk = 0;
2706 int lrclk = 0;
2707 int rate_val = 0;
2708 int id = dai->id - 1;
2709
2710 int i, cur_val, best_val, bclk_rate, best;
2711
2712 switch (dai->id) {
2713 case 1:
2714 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002715 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002716 bclk_reg = WM8994_AIF1_BCLK;
2717 rate_reg = WM8994_AIF1_RATE;
2718 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002719 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002720 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002721 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002722 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002723 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2724 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002725 break;
2726 case 2:
2727 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002728 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002729 bclk_reg = WM8994_AIF2_BCLK;
2730 rate_reg = WM8994_AIF2_RATE;
2731 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002732 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002733 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002734 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002735 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002736 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2737 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002738 break;
2739 default:
2740 return -EINVAL;
2741 }
2742
Mark Brown79748cd2012-10-01 15:28:30 +01002743 bclk_rate = params_rate(params);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002744 switch (params_format(params)) {
2745 case SNDRV_PCM_FORMAT_S16_LE:
2746 bclk_rate *= 16;
2747 break;
2748 case SNDRV_PCM_FORMAT_S20_3LE:
2749 bclk_rate *= 20;
2750 aif1 |= 0x20;
2751 break;
2752 case SNDRV_PCM_FORMAT_S24_LE:
2753 bclk_rate *= 24;
2754 aif1 |= 0x40;
2755 break;
2756 case SNDRV_PCM_FORMAT_S32_LE:
2757 bclk_rate *= 32;
2758 aif1 |= 0x60;
2759 break;
2760 default:
2761 return -EINVAL;
2762 }
2763
Mark Brown79748cd2012-10-01 15:28:30 +01002764 wm8994->channels[id] = params_channels(params);
Mark Brown3cf956e2013-03-20 10:12:10 +01002765 if (pdata->max_channels_clocked[id] &&
2766 wm8994->channels[id] > pdata->max_channels_clocked[id]) {
2767 dev_dbg(dai->dev, "Constraining channels to %d from %d\n",
2768 pdata->max_channels_clocked[id], wm8994->channels[id]);
2769 wm8994->channels[id] = pdata->max_channels_clocked[id];
2770 }
2771
2772 switch (wm8994->channels[id]) {
Mark Brown79748cd2012-10-01 15:28:30 +01002773 case 1:
2774 case 2:
2775 bclk_rate *= 2;
2776 break;
2777 default:
2778 bclk_rate *= 4;
2779 break;
2780 }
2781
Mark Brown9e6e96a2010-01-29 17:47:12 +00002782 /* Try to find an appropriate sample rate; look for an exact match. */
2783 for (i = 0; i < ARRAY_SIZE(srs); i++)
2784 if (srs[i].rate == params_rate(params))
2785 break;
2786 if (i == ARRAY_SIZE(srs))
2787 return -EINVAL;
2788 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2789
2790 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2791 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2792 dai->id, wm8994->aifclk[id], bclk_rate);
2793
Mark Brown3cf956e2013-03-20 10:12:10 +01002794 if (wm8994->channels[id] == 1 &&
Mark Brownb1e43d92010-12-07 17:14:56 +00002795 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2796 aif2 |= WM8994_AIF1_MONO;
2797
Mark Brown9e6e96a2010-01-29 17:47:12 +00002798 if (wm8994->aifclk[id] == 0) {
2799 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2800 return -EINVAL;
2801 }
2802
2803 /* AIFCLK/fs ratio; look for a close match in either direction */
2804 best = 0;
2805 best_val = abs((fs_ratios[0] * params_rate(params))
2806 - wm8994->aifclk[id]);
2807 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2808 cur_val = abs((fs_ratios[i] * params_rate(params))
2809 - wm8994->aifclk[id]);
2810 if (cur_val >= best_val)
2811 continue;
2812 best = i;
2813 best_val = cur_val;
2814 }
2815 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2816 dai->id, fs_ratios[best]);
2817 rate_val |= best;
2818
2819 /* We may not get quite the right frequency if using
2820 * approximate clocks so look for the closest match that is
2821 * higher than the target (we need to ensure that there enough
2822 * BCLKs to clock out the samples).
2823 */
2824 best = 0;
2825 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002826 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002827 if (cur_val < 0) /* BCLK table is sorted */
2828 break;
2829 best = i;
2830 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002831 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002832 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2833 bclk_divs[best], bclk_rate);
2834 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2835
2836 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002837 if (!lrclk) {
2838 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2839 bclk_rate);
2840 return -EINVAL;
2841 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002842 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2843 lrclk, bclk_rate / lrclk);
2844
2845 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002846 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002847 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2848 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2849 lrclk);
2850 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2851 WM8994_AIF1CLK_RATE_MASK, rate_val);
2852
2853 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2854 switch (dai->id) {
2855 case 1:
2856 wm8994->dac_rates[0] = params_rate(params);
2857 wm8994_set_retune_mobile(codec, 0);
2858 wm8994_set_retune_mobile(codec, 1);
2859 break;
2860 case 2:
2861 wm8994->dac_rates[1] = params_rate(params);
2862 wm8994_set_retune_mobile(codec, 2);
2863 break;
2864 }
2865 }
2866
2867 return 0;
2868}
2869
Mark Brownc4431df2010-11-26 15:21:07 +00002870static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2871 struct snd_pcm_hw_params *params,
2872 struct snd_soc_dai *dai)
2873{
2874 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002875 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2876 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002877 int aif1_reg;
2878 int aif1 = 0;
2879
2880 switch (dai->id) {
2881 case 3:
2882 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002883 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002884 case WM8958:
2885 aif1_reg = WM8958_AIF3_CONTROL_1;
2886 break;
2887 default:
2888 return 0;
2889 }
Dan Carpenter4495e46f2013-04-30 10:24:41 +03002890 break;
Mark Brownc4431df2010-11-26 15:21:07 +00002891 default:
2892 return 0;
2893 }
2894
2895 switch (params_format(params)) {
2896 case SNDRV_PCM_FORMAT_S16_LE:
2897 break;
2898 case SNDRV_PCM_FORMAT_S20_3LE:
2899 aif1 |= 0x20;
2900 break;
2901 case SNDRV_PCM_FORMAT_S24_LE:
2902 aif1 |= 0x40;
2903 break;
2904 case SNDRV_PCM_FORMAT_S32_LE:
2905 aif1 |= 0x60;
2906 break;
2907 default:
2908 return -EINVAL;
2909 }
2910
2911 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2912}
2913
Mark Brown9e6e96a2010-01-29 17:47:12 +00002914static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2915{
2916 struct snd_soc_codec *codec = codec_dai->codec;
2917 int mute_reg;
2918 int reg;
2919
2920 switch (codec_dai->id) {
2921 case 1:
2922 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2923 break;
2924 case 2:
2925 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2926 break;
2927 default:
2928 return -EINVAL;
2929 }
2930
2931 if (mute)
2932 reg = WM8994_AIF1DAC1_MUTE;
2933 else
2934 reg = 0;
2935
2936 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2937
2938 return 0;
2939}
2940
Mark Brown778a76e2010-03-22 22:05:10 +00002941static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2942{
2943 struct snd_soc_codec *codec = codec_dai->codec;
2944 int reg, val, mask;
2945
2946 switch (codec_dai->id) {
2947 case 1:
2948 reg = WM8994_AIF1_MASTER_SLAVE;
2949 mask = WM8994_AIF1_TRI;
2950 break;
2951 case 2:
2952 reg = WM8994_AIF2_MASTER_SLAVE;
2953 mask = WM8994_AIF2_TRI;
2954 break;
Mark Brown778a76e2010-03-22 22:05:10 +00002955 default:
2956 return -EINVAL;
2957 }
2958
2959 if (tristate)
2960 val = mask;
2961 else
2962 val = 0;
2963
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002964 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002965}
2966
Mark Brownd09f3ec2011-08-15 11:01:02 +09002967static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2968{
2969 struct snd_soc_codec *codec = dai->codec;
2970
2971 /* Disable the pulls on the AIF if we're using it to save power. */
2972 snd_soc_update_bits(codec, WM8994_GPIO_3,
2973 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2974 snd_soc_update_bits(codec, WM8994_GPIO_4,
2975 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2976 snd_soc_update_bits(codec, WM8994_GPIO_5,
2977 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2978
2979 return 0;
2980}
2981
Mark Brown9e6e96a2010-01-29 17:47:12 +00002982#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2983
2984#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002985 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002986
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002987static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002988 .set_sysclk = wm8994_set_dai_sysclk,
2989 .set_fmt = wm8994_set_dai_fmt,
2990 .hw_params = wm8994_hw_params,
2991 .digital_mute = wm8994_aif_mute,
2992 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002993 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002994};
2995
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002996static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002997 .set_sysclk = wm8994_set_dai_sysclk,
2998 .set_fmt = wm8994_set_dai_fmt,
2999 .hw_params = wm8994_hw_params,
3000 .digital_mute = wm8994_aif_mute,
3001 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00003002 .set_tristate = wm8994_set_tristate,
3003};
3004
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01003005static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00003006 .hw_params = wm8994_aif3_hw_params,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003007};
3008
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003009static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003010 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003011 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003012 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003013 .playback = {
3014 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003015 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003016 .channels_max = 2,
3017 .rates = WM8994_RATES,
3018 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003019 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003020 },
3021 .capture = {
3022 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003023 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003024 .channels_max = 2,
3025 .rates = WM8994_RATES,
3026 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003027 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003028 },
3029 .ops = &wm8994_aif1_dai_ops,
3030 },
3031 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003032 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003033 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003034 .playback = {
3035 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003036 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003037 .channels_max = 2,
3038 .rates = WM8994_RATES,
3039 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003040 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003041 },
3042 .capture = {
3043 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003044 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003045 .channels_max = 2,
3046 .rates = WM8994_RATES,
3047 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003048 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003049 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09003050 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003051 .ops = &wm8994_aif2_dai_ops,
3052 },
3053 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003054 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003055 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003056 .playback = {
3057 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003058 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003059 .channels_max = 2,
3060 .rates = WM8994_RATES,
3061 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003062 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003063 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03003064 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003065 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003066 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003067 .channels_max = 2,
3068 .rates = WM8994_RATES,
3069 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003070 .sig_bits = 24,
3071 },
Mark Brown778a76e2010-03-22 22:05:10 +00003072 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003073 }
3074};
Mark Brown9e6e96a2010-01-29 17:47:12 +00003075
3076#ifdef CONFIG_PM
Mark Brown4752a882012-03-04 02:16:01 +00003077static int wm8994_codec_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003078{
Mark Brownb2c812e2010-04-14 15:35:19 +09003079 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003080 int i, ret;
3081
3082 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3083 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00003084 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003085 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003086 if (ret < 0)
3087 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
3088 i + 1, ret);
3089 }
3090
3091 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
3092
3093 return 0;
3094}
3095
Mark Brown4752a882012-03-04 02:16:01 +00003096static int wm8994_codec_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003097{
Mark Brownb2c812e2010-04-14 15:35:19 +09003098 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003099 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003100 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003101 unsigned int val, mask;
3102
Mark Brownda445afe2013-03-12 17:46:09 +00003103 if (control->revision < 4) {
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003104 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01003105 ret = regmap_read(control->regmap,
3106 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003107
3108 /* modify the cache only */
3109 codec->cache_only = 1;
3110 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
3111 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
3112 val &= mask;
3113 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
3114 mask, val);
3115 codec->cache_only = 0;
3116 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003117
Mark Brown9e6e96a2010-01-29 17:47:12 +00003118 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01003119 if (!wm8994->fll_suspend[i].out)
3120 continue;
3121
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003122 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003123 wm8994->fll_suspend[i].src,
3124 wm8994->fll_suspend[i].in,
3125 wm8994->fll_suspend[i].out);
3126 if (ret < 0)
3127 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
3128 i + 1, ret);
3129 }
3130
3131 return 0;
3132}
3133#else
Mark Brown4752a882012-03-04 02:16:01 +00003134#define wm8994_codec_suspend NULL
3135#define wm8994_codec_resume NULL
Mark Brown9e6e96a2010-01-29 17:47:12 +00003136#endif
3137
3138static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3139{
Mark Brown8cb8e832012-07-25 18:10:03 +01003140 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003141 struct wm8994 *control = wm8994->wm8994;
3142 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003143 struct snd_kcontrol_new controls[] = {
3144 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3145 wm8994->retune_mobile_enum,
3146 wm8994_get_retune_mobile_enum,
3147 wm8994_put_retune_mobile_enum),
3148 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3149 wm8994->retune_mobile_enum,
3150 wm8994_get_retune_mobile_enum,
3151 wm8994_put_retune_mobile_enum),
3152 SOC_ENUM_EXT("AIF2 EQ Mode",
3153 wm8994->retune_mobile_enum,
3154 wm8994_get_retune_mobile_enum,
3155 wm8994_put_retune_mobile_enum),
3156 };
3157 int ret, i, j;
3158 const char **t;
3159
3160 /* We need an array of texts for the enum API but the number
3161 * of texts is likely to be less than the number of
3162 * configurations due to the sample rate dependency of the
3163 * configurations. */
3164 wm8994->num_retune_mobile_texts = 0;
3165 wm8994->retune_mobile_texts = NULL;
3166 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3167 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3168 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3169 wm8994->retune_mobile_texts[j]) == 0)
3170 break;
3171 }
3172
3173 if (j != wm8994->num_retune_mobile_texts)
3174 continue;
3175
3176 /* Expand the array... */
3177 t = krealloc(wm8994->retune_mobile_texts,
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02003178 sizeof(char *) *
Mark Brown9e6e96a2010-01-29 17:47:12 +00003179 (wm8994->num_retune_mobile_texts + 1),
3180 GFP_KERNEL);
3181 if (t == NULL)
3182 continue;
3183
3184 /* ...store the new entry... */
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02003185 t[wm8994->num_retune_mobile_texts] =
Mark Brown9e6e96a2010-01-29 17:47:12 +00003186 pdata->retune_mobile_cfgs[i].name;
3187
3188 /* ...and remember the new version. */
3189 wm8994->num_retune_mobile_texts++;
3190 wm8994->retune_mobile_texts = t;
3191 }
3192
3193 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
3194 wm8994->num_retune_mobile_texts);
3195
3196 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
3197 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3198
Mark Brown8cb8e832012-07-25 18:10:03 +01003199 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003200 ARRAY_SIZE(controls));
3201 if (ret != 0)
Mark Brown8cb8e832012-07-25 18:10:03 +01003202 dev_err(wm8994->hubs.codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003203 "Failed to add ReTune Mobile controls: %d\n", ret);
3204}
3205
3206static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3207{
Mark Brown8cb8e832012-07-25 18:10:03 +01003208 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003209 struct wm8994 *control = wm8994->wm8994;
3210 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003211 int ret, i;
3212
3213 if (!pdata)
3214 return;
3215
3216 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
3217 pdata->lineout2_diff,
3218 pdata->lineout1fb,
3219 pdata->lineout2fb,
3220 pdata->jd_scthr,
3221 pdata->jd_thr,
Mark Brown02e79472012-08-21 17:54:52 +01003222 pdata->micb1_delay,
3223 pdata->micb2_delay,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003224 pdata->micbias1_lvl,
3225 pdata->micbias2_lvl);
3226
3227 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3228
3229 if (pdata->num_drc_cfgs) {
3230 struct snd_kcontrol_new controls[] = {
3231 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3232 wm8994_get_drc_enum, wm8994_put_drc_enum),
3233 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3234 wm8994_get_drc_enum, wm8994_put_drc_enum),
3235 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3236 wm8994_get_drc_enum, wm8994_put_drc_enum),
3237 };
3238
3239 /* We need an array of texts for the enum API */
Mark Brown8cb8e832012-07-25 18:10:03 +01003240 wm8994->drc_texts = devm_kzalloc(wm8994->hubs.codec->dev,
Mark Brown7270ceb2011-12-01 14:00:19 +00003241 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003242 if (!wm8994->drc_texts) {
Mark Brown8cb8e832012-07-25 18:10:03 +01003243 dev_err(wm8994->hubs.codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003244 "Failed to allocate %d DRC config texts\n",
3245 pdata->num_drc_cfgs);
3246 return;
3247 }
3248
3249 for (i = 0; i < pdata->num_drc_cfgs; i++)
3250 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3251
3252 wm8994->drc_enum.max = pdata->num_drc_cfgs;
3253 wm8994->drc_enum.texts = wm8994->drc_texts;
3254
Mark Brown8cb8e832012-07-25 18:10:03 +01003255 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003256 ARRAY_SIZE(controls));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003257 for (i = 0; i < WM8994_NUM_DRC; i++)
3258 wm8994_set_drc(codec, i);
Mark Brown45a690f2012-08-15 19:20:54 +01003259 } else {
3260 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
3261 wm8994_drc_controls,
3262 ARRAY_SIZE(wm8994_drc_controls));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003263 }
3264
Mark Brown45a690f2012-08-15 19:20:54 +01003265 if (ret != 0)
3266 dev_err(wm8994->hubs.codec->dev,
3267 "Failed to add DRC mode controls: %d\n", ret);
3268
3269
Mark Brown9e6e96a2010-01-29 17:47:12 +00003270 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
3271 pdata->num_retune_mobile_cfgs);
3272
3273 if (pdata->num_retune_mobile_cfgs)
3274 wm8994_handle_retune_mobile_pdata(wm8994);
3275 else
Mark Brown8cb8e832012-07-25 18:10:03 +01003276 snd_soc_add_codec_controls(wm8994->hubs.codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003277 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08003278
3279 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3280 if (pdata->micbias[i]) {
3281 snd_soc_write(codec, WM8958_MICBIAS1 + i,
3282 pdata->micbias[i] & 0xffff);
3283 }
3284 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003285}
3286
Mark Brown88766982010-03-29 20:57:12 +01003287/**
3288 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3289 *
3290 * @codec: WM8994 codec
3291 * @jack: jack to report detection events on
3292 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01003293 *
3294 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3295 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01003296 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01003297 * be configured using snd_soc_jack_add_gpios() instead.
3298 *
3299 * Configuration of detection levels is available via the micbias1_lvl
3300 * and micbias2_lvl platform data members.
3301 */
3302int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00003303 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01003304{
Mark Brownb2c812e2010-04-14 15:35:19 +09003305 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01003306 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01003307 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00003308 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01003309
Mark Brown87092e32012-02-06 18:50:39 +00003310 if (control->type != WM8994) {
3311 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003312 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003313 }
Mark Brown3a423152010-11-26 15:21:06 +00003314
Mark Brown88766982010-03-29 20:57:12 +01003315 switch (micbias) {
3316 case 1:
3317 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003318 if (jack)
3319 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3320 "MICBIAS1");
3321 else
3322 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3323 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003324 break;
3325 case 2:
3326 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003327 if (jack)
3328 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3329 "MICBIAS1");
3330 else
3331 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3332 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003333 break;
3334 default:
Mark Brown87092e32012-02-06 18:50:39 +00003335 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003336 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003337 }
Mark Brown88766982010-03-29 20:57:12 +01003338
Mark Brown87092e32012-02-06 18:50:39 +00003339 if (ret != 0)
3340 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3341 micbias, ret);
3342
3343 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3344 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003345
3346 /* Store the configuration */
3347 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003348 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003349
3350 /* If either of the jacks is set up then enable detection */
3351 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3352 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003353 else
Mark Brown88766982010-03-29 20:57:12 +01003354 reg = 0;
3355
3356 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3357
Chris Rattrayd9f34df2012-07-31 14:51:34 +01003358 /* enable MICDET and MICSHRT deboune */
3359 snd_soc_update_bits(codec, WM8994_IRQ_DEBOUNCE,
3360 WM8994_MIC1_DET_DB_MASK | WM8994_MIC1_SHRT_DB_MASK |
3361 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK,
3362 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB);
3363
Mark Brown87092e32012-02-06 18:50:39 +00003364 snd_soc_dapm_sync(&codec->dapm);
3365
Mark Brown88766982010-03-29 20:57:12 +01003366 return 0;
3367}
3368EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3369
Mark Browne9b54de42012-05-09 19:20:59 +01003370static void wm8994_mic_work(struct work_struct *work)
Mark Brown88766982010-03-29 20:57:12 +01003371{
Mark Browne9b54de42012-05-09 19:20:59 +01003372 struct wm8994_priv *priv = container_of(work,
3373 struct wm8994_priv,
3374 mic_work.work);
Mark Brownfdfc4f32012-05-09 19:24:39 +01003375 struct regmap *regmap = priv->wm8994->regmap;
3376 struct device *dev = priv->wm8994->dev;
3377 unsigned int reg;
3378 int ret;
Mark Brown88766982010-03-29 20:57:12 +01003379 int report;
3380
Mark Brownb8176622012-07-24 15:48:57 +01003381 pm_runtime_get_sync(dev);
3382
Mark Brownfdfc4f32012-05-09 19:24:39 +01003383 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, &reg);
3384 if (ret < 0) {
3385 dev_err(dev, "Failed to read microphone status: %d\n",
3386 ret);
Mark Brownb8176622012-07-24 15:48:57 +01003387 pm_runtime_put(dev);
Mark Browne9b54de42012-05-09 19:20:59 +01003388 return;
Mark Brown88766982010-03-29 20:57:12 +01003389 }
3390
Mark Brownfdfc4f32012-05-09 19:24:39 +01003391 dev_dbg(dev, "Microphone status: %x\n", reg);
Mark Brown88766982010-03-29 20:57:12 +01003392
3393 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003394 if (reg & WM8994_MIC1_DET_STS) {
3395 if (priv->micdet[0].detecting)
3396 report = SND_JACK_HEADSET;
3397 }
3398 if (reg & WM8994_MIC1_SHRT_STS) {
3399 if (priv->micdet[0].detecting)
3400 report = SND_JACK_HEADPHONE;
3401 else
3402 report |= SND_JACK_BTN_0;
3403 }
3404 if (report)
3405 priv->micdet[0].detecting = false;
3406 else
3407 priv->micdet[0].detecting = true;
3408
Mark Brown88766982010-03-29 20:57:12 +01003409 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003410 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003411
3412 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003413 if (reg & WM8994_MIC2_DET_STS) {
3414 if (priv->micdet[1].detecting)
3415 report = SND_JACK_HEADSET;
3416 }
3417 if (reg & WM8994_MIC2_SHRT_STS) {
3418 if (priv->micdet[1].detecting)
3419 report = SND_JACK_HEADPHONE;
3420 else
3421 report |= SND_JACK_BTN_0;
3422 }
3423 if (report)
3424 priv->micdet[1].detecting = false;
3425 else
3426 priv->micdet[1].detecting = true;
3427
Mark Brown88766982010-03-29 20:57:12 +01003428 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003429 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brownb8176622012-07-24 15:48:57 +01003430
3431 pm_runtime_put(dev);
Mark Browne9b54de42012-05-09 19:20:59 +01003432}
3433
3434static irqreturn_t wm8994_mic_irq(int irq, void *data)
3435{
3436 struct wm8994_priv *priv = data;
Mark Brown8cb8e832012-07-25 18:10:03 +01003437 struct snd_soc_codec *codec = priv->hubs.codec;
Mark Browne9b54de42012-05-09 19:20:59 +01003438
3439#ifndef CONFIG_SND_SOC_WM8994_MODULE
3440 trace_snd_soc_jack_irq(dev_name(codec->dev));
3441#endif
3442
3443 pm_wakeup_event(codec->dev, 300);
3444
3445 schedule_delayed_work(&priv->mic_work, msecs_to_jiffies(250));
Mark Brown88766982010-03-29 20:57:12 +01003446
3447 return IRQ_HANDLED;
3448}
3449
Mark Brownf02b0de2012-10-01 16:41:09 +01003450static void wm1811_micd_stop(struct snd_soc_codec *codec)
Mark Brown821edd22010-11-26 15:21:09 +00003451{
Mark Brownf02b0de2012-10-01 16:41:09 +01003452 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3453
3454 if (!wm8994->jackdet)
3455 return;
3456
3457 mutex_lock(&wm8994->accdet_lock);
3458
3459 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, WM8958_MICD_ENA, 0);
3460
3461 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3462
3463 mutex_unlock(&wm8994->accdet_lock);
3464
3465 if (wm8994->wm8994->pdata.jd_ext_cap)
3466 snd_soc_dapm_disable_pin(&codec->dapm,
3467 "MICBIAS2");
3468}
3469
Mark Brown78b76db2012-11-22 17:02:09 +09003470static void wm8958_button_det(struct snd_soc_codec *codec, u16 status)
Mark Brown821edd22010-11-26 15:21:09 +00003471{
Mark Brown821edd22010-11-26 15:21:09 +00003472 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003473 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003474
Mark Brown78b76db2012-11-22 17:02:09 +09003475 report = 0;
3476 if (status & 0x4)
3477 report |= SND_JACK_BTN_0;
3478
3479 if (status & 0x8)
3480 report |= SND_JACK_BTN_1;
3481
3482 if (status & 0x10)
3483 report |= SND_JACK_BTN_2;
3484
3485 if (status & 0x20)
3486 report |= SND_JACK_BTN_3;
3487
3488 if (status & 0x40)
3489 report |= SND_JACK_BTN_4;
3490
3491 if (status & 0x80)
3492 report |= SND_JACK_BTN_5;
3493
3494 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3495 wm8994->btn_mask);
3496}
3497
Mark Brown98869f62012-12-03 16:14:37 +09003498static void wm8958_mic_id(void *data, u16 status)
Mark Brown78b76db2012-11-22 17:02:09 +09003499{
Mark Brown98869f62012-12-03 16:14:37 +09003500 struct snd_soc_codec *codec = data;
Mark Brown78b76db2012-11-22 17:02:09 +09003501 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Browna1691342011-11-30 14:56:40 +00003502
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003503 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003504 if (!(status & WM8958_MICD_STS)) {
Mark Brownf02b0de2012-10-01 16:41:09 +01003505 /* If nothing present then clear our statuses */
3506 dev_dbg(codec->dev, "Detected open circuit\n");
3507 wm8994->jack_mic = false;
3508 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003509
Mark Brownf02b0de2012-10-01 16:41:09 +01003510 wm1811_micd_stop(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003511
Mark Brownf02b0de2012-10-01 16:41:09 +01003512 wm8958_micd_set_rate(codec);
3513
3514 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3515 wm8994->btn_mask |
3516 SND_JACK_HEADSET);
Mark Brownb00adf72011-08-13 11:57:18 +09003517 return;
3518 }
3519
3520 /* If the measurement is showing a high impedence we've got a
3521 * microphone.
3522 */
Mark Brown78b76db2012-11-22 17:02:09 +09003523 if (status & 0x600) {
Mark Brownb00adf72011-08-13 11:57:18 +09003524 dev_dbg(codec->dev, "Detected microphone\n");
3525
Mark Brown157a75e2011-11-30 13:43:51 +00003526 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003527 wm8994->jack_mic = true;
3528
3529 wm8958_micd_set_rate(codec);
3530
3531 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3532 SND_JACK_HEADSET);
3533 }
3534
3535
Mark Brown78b76db2012-11-22 17:02:09 +09003536 if (status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003537 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003538 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003539
3540 wm8958_micd_set_rate(codec);
3541
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003542 /* If we have jackdet that will detect removal */
Mark Brownf02b0de2012-10-01 16:41:09 +01003543 wm1811_micd_stop(codec);
Mark Brownecd17322012-03-12 16:34:35 +00003544
3545 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3546 SND_JACK_HEADSET);
Mark Brownb00adf72011-08-13 11:57:18 +09003547 }
Mark Brown821edd22010-11-26 15:21:09 +00003548}
Mark Brown9e6e96a2010-01-29 17:47:12 +00003549
Mark Brownc0cc3f12012-09-28 16:50:15 +01003550/* Deferred mic detection to allow for extra settling time */
3551static void wm1811_mic_work(struct work_struct *work)
3552{
3553 struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
3554 mic_work.work);
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003555 struct wm8994 *control = wm8994->wm8994;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003556 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brown821edd22010-11-26 15:21:09 +00003557
Mark Brownc0cc3f12012-09-28 16:50:15 +01003558 pm_runtime_get_sync(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003559
Mark Brownc0cc3f12012-09-28 16:50:15 +01003560 /* If required for an external cap force MICBIAS on */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003561 if (control->pdata.jd_ext_cap) {
Mark Brownc0cc3f12012-09-28 16:50:15 +01003562 snd_soc_dapm_force_enable_pin(&codec->dapm,
3563 "MICBIAS2");
3564 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003565 }
Mark Brownc0cc3f12012-09-28 16:50:15 +01003566
3567 mutex_lock(&wm8994->accdet_lock);
3568
3569 dev_dbg(codec->dev, "Starting mic detection\n");
3570
Mark Brown63dd5452012-11-22 20:44:32 +09003571 /* Use a user-supplied callback if we have one */
3572 if (wm8994->micd_cb) {
3573 wm8994->micd_cb(wm8994->micd_cb_data);
3574 } else {
3575 /*
3576 * Start off measument of microphone impedence to find out
3577 * what's actually there.
3578 */
3579 wm8994->mic_detecting = true;
3580 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
Mark Brownc0cc3f12012-09-28 16:50:15 +01003581
Mark Brown63dd5452012-11-22 20:44:32 +09003582 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3583 WM8958_MICD_ENA, WM8958_MICD_ENA);
3584 }
Mark Brownc0cc3f12012-09-28 16:50:15 +01003585
3586 mutex_unlock(&wm8994->accdet_lock);
3587
3588 pm_runtime_put(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003589}
3590
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003591static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3592{
3593 struct wm8994_priv *wm8994 = data;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003594 struct wm8994 *control = wm8994->wm8994;
Mark Brown8cb8e832012-07-25 18:10:03 +01003595 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003596 int reg, delay;
Mark Brownc9865642012-03-12 16:31:50 +00003597 bool present;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003598
Mark Brownb8176622012-07-24 15:48:57 +01003599 pm_runtime_get_sync(codec->dev);
3600
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003601 mutex_lock(&wm8994->accdet_lock);
3602
3603 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3604 if (reg < 0) {
3605 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3606 mutex_unlock(&wm8994->accdet_lock);
Mark Brownb8176622012-07-24 15:48:57 +01003607 pm_runtime_put(codec->dev);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003608 return IRQ_NONE;
3609 }
3610
3611 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3612
Mark Brownc9865642012-03-12 16:31:50 +00003613 present = reg & WM1811_JACKDET_LVL;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003614
Mark Brownc9865642012-03-12 16:31:50 +00003615 if (present) {
3616 dev_dbg(codec->dev, "Jack detected\n");
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003617
Mark Browne9d9a962012-04-26 16:07:32 +01003618 wm8958_micd_set_rate(codec);
3619
Mark Brown55a27782012-02-21 13:45:53 +00003620 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3621 WM8958_MICB2_DISCH, 0);
3622
Mark Brown378ec0c2012-03-01 19:01:43 +00003623 /* Disable debounce while inserted */
3624 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3625 WM1811_JACKDET_DB, 0);
3626
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003627 delay = control->pdata.micdet_delay;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003628 schedule_delayed_work(&wm8994->mic_work,
3629 msecs_to_jiffies(delay));
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003630 } else {
3631 dev_dbg(codec->dev, "Jack not detected\n");
3632
Mark Brownc0cc3f12012-09-28 16:50:15 +01003633 cancel_delayed_work_sync(&wm8994->mic_work);
3634
Mark Brown55a27782012-02-21 13:45:53 +00003635 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3636 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3637
Mark Brown378ec0c2012-03-01 19:01:43 +00003638 /* Enable debounce while removed */
3639 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3640 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3641
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003642 wm8994->mic_detecting = false;
3643 wm8994->jack_mic = false;
3644 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3645 WM8958_MICD_ENA, 0);
3646 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3647 }
3648
3649 mutex_unlock(&wm8994->accdet_lock);
3650
Mark Brownc0cc3f12012-09-28 16:50:15 +01003651 /* Turn off MICBIAS if it was on for an external cap */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003652 if (control->pdata.jd_ext_cap && !present)
Mark Brownc0cc3f12012-09-28 16:50:15 +01003653 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
Mark Brownc9865642012-03-12 16:31:50 +00003654
3655 if (present)
3656 snd_soc_jack_report(wm8994->micdet[0].jack,
3657 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3658 else
3659 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3660 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3661 wm8994->btn_mask);
3662
Mark Brown99af79d2012-07-25 23:03:36 +01003663 /* Since we only report deltas force an update, ensures we
3664 * avoid bootstrapping issues with the core. */
3665 snd_soc_jack_report(wm8994->micdet[0].jack, 0, 0);
3666
Mark Brownb8176622012-07-24 15:48:57 +01003667 pm_runtime_put(codec->dev);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003668 return IRQ_HANDLED;
3669}
3670
Mark Brown99af79d2012-07-25 23:03:36 +01003671static void wm1811_jackdet_bootstrap(struct work_struct *work)
3672{
3673 struct wm8994_priv *wm8994 = container_of(work,
3674 struct wm8994_priv,
3675 jackdet_bootstrap.work);
3676 wm1811_jackdet_irq(0, wm8994);
3677}
3678
Mark Brown821edd22010-11-26 15:21:09 +00003679/**
3680 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3681 *
3682 * @codec: WM8958 codec
3683 * @jack: jack to report detection events on
3684 *
3685 * Enable microphone detection functionality for the WM8958. By
3686 * default simple detection which supports the detection of up to 6
3687 * buttons plus video and microphone functionality is supported.
3688 *
3689 * The WM8958 has an advanced jack detection facility which is able to
3690 * support complex accessory detection, especially when used in
3691 * conjunction with external circuitry. In order to provide maximum
3692 * flexiblity a callback is provided which allows a completely custom
3693 * detection algorithm.
3694 */
3695int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown98869f62012-12-03 16:14:37 +09003696 wm1811_micdet_cb det_cb, void *det_cb_data,
3697 wm1811_mic_id_cb id_cb, void *id_cb_data)
Mark Brown821edd22010-11-26 15:21:09 +00003698{
3699 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003700 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003701 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003702
Mark Brown81204c82011-05-24 17:35:53 +08003703 switch (control->type) {
3704 case WM1811:
3705 case WM8958:
3706 break;
3707 default:
Mark Brown821edd22010-11-26 15:21:09 +00003708 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003709 }
Mark Brown821edd22010-11-26 15:21:09 +00003710
3711 if (jack) {
Mark Brown4cdf5e42011-11-29 14:36:17 +00003712 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003713 snd_soc_dapm_sync(&codec->dapm);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003714
Mark Brown821edd22010-11-26 15:21:09 +00003715 wm8994->micdet[0].jack = jack;
Mark Brown821edd22010-11-26 15:21:09 +00003716
Mark Brown98869f62012-12-03 16:14:37 +09003717 if (det_cb) {
3718 wm8994->micd_cb = det_cb;
3719 wm8994->micd_cb_data = det_cb_data;
Mark Brown63dd5452012-11-22 20:44:32 +09003720 } else {
3721 wm8994->mic_detecting = true;
3722 wm8994->jack_mic = false;
3723 }
Mark Brownb00adf72011-08-13 11:57:18 +09003724
Mark Brown98869f62012-12-03 16:14:37 +09003725 if (id_cb) {
3726 wm8994->mic_id_cb = id_cb;
3727 wm8994->mic_id_cb_data = id_cb_data;
3728 } else {
3729 wm8994->mic_id_cb = wm8958_mic_id;
3730 wm8994->mic_id_cb_data = codec;
3731 }
Mark Brownb00adf72011-08-13 11:57:18 +09003732
3733 wm8958_micd_set_rate(codec);
3734
Mark Brown4585790d2011-11-30 10:55:14 +00003735 /* Detect microphones and short circuits by default */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003736 if (control->pdata.micd_lvl_sel)
3737 micd_lvl_sel = control->pdata.micd_lvl_sel;
Mark Brown4585790d2011-11-30 10:55:14 +00003738 else
3739 micd_lvl_sel = 0x41;
3740
3741 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3742 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3743 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3744
Mark Brownb00adf72011-08-13 11:57:18 +09003745 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003746 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003747
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003748 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3749
3750 /*
3751 * If we can use jack detection start off with that,
3752 * otherwise jump straight to microphone detection.
3753 */
3754 if (wm8994->jackdet) {
Mark Brown99af79d2012-07-25 23:03:36 +01003755 /* Disable debounce for the initial detect */
3756 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3757 WM1811_JACKDET_DB, 0);
3758
Mark Brown55a27782012-02-21 13:45:53 +00003759 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3760 WM8958_MICB2_DISCH,
3761 WM8958_MICB2_DISCH);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003762 snd_soc_update_bits(codec, WM8994_LDO_1,
3763 WM8994_LDO1_DISCH, 0);
3764 wm1811_jackdet_set_mode(codec,
3765 WM1811_JACKDET_MODE_JACK);
3766 } else {
3767 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3768 WM8958_MICD_ENA, WM8958_MICD_ENA);
3769 }
3770
Mark Brown821edd22010-11-26 15:21:09 +00003771 } else {
3772 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3773 WM8958_MICD_ENA, 0);
Mark Brownafaf1592012-03-03 18:46:36 +00003774 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003775 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003776 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003777 }
3778
3779 return 0;
3780}
3781EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3782
3783static irqreturn_t wm8958_mic_irq(int irq, void *data)
3784{
3785 struct wm8994_priv *wm8994 = data;
Mark Brown8cb8e832012-07-25 18:10:03 +01003786 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brown8afd0ef2012-12-07 17:10:05 +09003787 int reg, count, ret;
Mark Brown821edd22010-11-26 15:21:09 +00003788
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003789 /*
3790 * Jack detection may have detected a removal simulataneously
3791 * with an update of the MICDET status; if so it will have
3792 * stopped detection and we can ignore this interrupt.
3793 */
Mark Brownc9865642012-03-12 16:31:50 +00003794 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003795 return IRQ_HANDLED;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003796
Mark Brownb8176622012-07-24 15:48:57 +01003797 pm_runtime_get_sync(codec->dev);
3798
Mark Brown19940b32011-08-19 18:05:05 +09003799 /* We may occasionally read a detection without an impedence
3800 * range being provided - if that happens loop again.
3801 */
3802 count = 10;
3803 do {
3804 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3805 if (reg < 0) {
3806 dev_err(codec->dev,
3807 "Failed to read mic detect status: %d\n",
3808 reg);
Mark Brownb8176622012-07-24 15:48:57 +01003809 pm_runtime_put(codec->dev);
Mark Brown19940b32011-08-19 18:05:05 +09003810 return IRQ_NONE;
3811 }
Mark Brown821edd22010-11-26 15:21:09 +00003812
Mark Brown19940b32011-08-19 18:05:05 +09003813 if (!(reg & WM8958_MICD_VALID)) {
3814 dev_dbg(codec->dev, "Mic detect data not valid\n");
3815 goto out;
3816 }
3817
3818 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3819 break;
3820
3821 msleep(1);
3822 } while (count--);
3823
3824 if (count == 0)
Masanari Iidaec8f53f2012-11-02 00:28:50 +09003825 dev_warn(codec->dev, "No impedance range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003826
Mark Brown7116f452010-12-29 13:05:21 +00003827#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003828 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003829#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003830
Mark Browne874de42012-12-03 15:58:55 +09003831 /* Avoid a transient report when the accessory is being removed */
3832 if (wm8994->jackdet) {
Mark Brown8afd0ef2012-12-07 17:10:05 +09003833 ret = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3834 if (ret < 0) {
Mark Browne874de42012-12-03 15:58:55 +09003835 dev_err(codec->dev, "Failed to read jack status: %d\n",
Mark Brown8afd0ef2012-12-07 17:10:05 +09003836 ret);
3837 } else if (!(ret & WM1811_JACKDET_LVL)) {
Mark Browne874de42012-12-03 15:58:55 +09003838 dev_dbg(codec->dev, "Ignoring removed jack\n");
Mark Brown9e430882013-05-29 18:38:46 +01003839 goto out;
Mark Browne874de42012-12-03 15:58:55 +09003840 }
Mark Brown9767a582013-05-28 12:52:08 +01003841 } else if (!(reg & WM8958_MICD_STS)) {
3842 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3843 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3844 wm8994->btn_mask);
Mark Brown7afce3f2013-05-30 13:42:27 +01003845 wm8994->mic_detecting = true;
Mark Brown9767a582013-05-28 12:52:08 +01003846 goto out;
Mark Browne874de42012-12-03 15:58:55 +09003847 }
3848
Mark Brown78b76db2012-11-22 17:02:09 +09003849 if (wm8994->mic_detecting)
Mark Brown98869f62012-12-03 16:14:37 +09003850 wm8994->mic_id_cb(wm8994->mic_id_cb_data, reg);
Mark Brown821edd22010-11-26 15:21:09 +00003851 else
Mark Brown78b76db2012-11-22 17:02:09 +09003852 wm8958_button_det(codec, reg);
Mark Brown821edd22010-11-26 15:21:09 +00003853
3854out:
Mark Brownb8176622012-07-24 15:48:57 +01003855 pm_runtime_put(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003856 return IRQ_HANDLED;
3857}
3858
Mark Brown3b1af3f2011-07-14 12:38:18 +09003859static irqreturn_t wm8994_fifo_error(int irq, void *data)
3860{
3861 struct snd_soc_codec *codec = data;
3862
3863 dev_err(codec->dev, "FIFO error\n");
3864
3865 return IRQ_HANDLED;
3866}
3867
Mark Brownf0b182b2011-08-16 12:01:27 +09003868static irqreturn_t wm8994_temp_warn(int irq, void *data)
3869{
3870 struct snd_soc_codec *codec = data;
3871
3872 dev_err(codec->dev, "Thermal warning\n");
3873
3874 return IRQ_HANDLED;
3875}
3876
3877static irqreturn_t wm8994_temp_shut(int irq, void *data)
3878{
3879 struct snd_soc_codec *codec = data;
3880
3881 dev_crit(codec->dev, "Thermal shutdown\n");
3882
3883 return IRQ_HANDLED;
3884}
3885
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003886static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003887{
Mark Brownd9a76662011-07-24 12:49:52 +01003888 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00003889 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003890 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003891 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003892 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003893
Mark Brown8cb8e832012-07-25 18:10:03 +01003894 wm8994->hubs.codec = codec;
Mark Brownd9a76662011-07-24 12:49:52 +01003895 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003896
Mark Brownd9a76662011-07-24 12:49:52 +01003897 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003898
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003899 mutex_init(&wm8994->accdet_lock);
Mark Brown99af79d2012-07-25 23:03:36 +01003900 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
3901 wm1811_jackdet_bootstrap);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003902
Mark Brownc0cc3f12012-09-28 16:50:15 +01003903 switch (control->type) {
3904 case WM8994:
3905 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
3906 break;
3907 case WM1811:
3908 INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
3909 break;
3910 default:
3911 break;
3912 }
3913
Mark Brownc7ebf932011-07-12 19:47:59 +09003914 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3915 init_completion(&wm8994->fll_locked[i]);
3916
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003917 wm8994->micdet_irq = control->pdata.micdet_irq;
Mark Brown9b7c5252011-02-17 20:05:44 -08003918
Mark Brown39fb51a2010-11-26 17:23:43 +00003919 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003920 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003921
Mark Brownf959dee2012-01-31 16:16:47 +00003922 /* By default use idle_bias_off, will override for WM8994 */
3923 codec->dapm.idle_bias_off = 1;
3924
Mark Brown9e6e96a2010-01-29 17:47:12 +00003925 /* Set revision-specific configuration */
Mark Brown3a423152010-11-26 15:21:06 +00003926 switch (control->type) {
3927 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003928 /* Single ended line outputs should have VMID on. */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003929 if (!control->pdata.lineout1_diff ||
3930 !control->pdata.lineout2_diff)
Mark Brownf959dee2012-01-31 16:16:47 +00003931 codec->dapm.idle_bias_off = 0;
3932
Mark Brownda445afe2013-03-12 17:46:09 +00003933 switch (control->revision) {
Mark Brown3a423152010-11-26 15:21:06 +00003934 case 2:
3935 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003936 wm8994->hubs.dcs_codes_l = -5;
3937 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003938 wm8994->hubs.hp_startup_mode = 1;
3939 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003940 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003941 break;
3942 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003943 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003944 break;
3945 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003946 break;
Mark Brown3a423152010-11-26 15:21:06 +00003947
3948 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003949 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003950 wm8994->hubs.hp_startup_mode = 1;
Mark Brown20dc24a2012-04-05 12:55:20 +01003951
Mark Brownda445afe2013-03-12 17:46:09 +00003952 switch (control->revision) {
Mark Brown20dc24a2012-04-05 12:55:20 +01003953 case 0:
3954 break;
3955 default:
3956 wm8994->fll_byp = true;
3957 break;
3958 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003959 break;
Mark Brown3a423152010-11-26 15:21:06 +00003960
Mark Brown81204c82011-05-24 17:35:53 +08003961 case WM1811:
3962 wm8994->hubs.dcs_readback_mode = 2;
3963 wm8994->hubs.no_series_update = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003964 wm8994->hubs.hp_startup_mode = 1;
Mark Brownaf31a222012-04-26 20:06:56 +01003965 wm8994->hubs.no_cache_dac_hp_direct = true;
Mark Brown20dc24a2012-04-05 12:55:20 +01003966 wm8994->fll_byp = true;
Mark Brown81204c82011-05-24 17:35:53 +08003967
Mark Brown72222be32012-11-28 13:46:56 +00003968 wm8994->hubs.dcs_codes_l = -9;
3969 wm8994->hubs.dcs_codes_r = -7;
Mark Brown81204c82011-05-24 17:35:53 +08003970
3971 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3972 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3973 break;
3974
Mark Brown9e6e96a2010-01-29 17:47:12 +00003975 default:
3976 break;
3977 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003978
Mark Brown2a8a8562011-07-24 12:20:41 +01003979 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003980 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003981 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003982 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003983 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003984 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003985
Mark Brown2a8a8562011-07-24 12:20:41 +01003986 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003987 wm_hubs_dcs_done, "DC servo done",
3988 &wm8994->hubs);
3989 if (ret == 0)
3990 wm8994->hubs.dcs_done_irq = true;
3991
Mark Brown3a423152010-11-26 15:21:06 +00003992 switch (control->type) {
3993 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003994 if (wm8994->micdet_irq) {
3995 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3996 wm8994_mic_irq,
3997 IRQF_TRIGGER_RISING,
3998 "Mic1 detect",
3999 wm8994);
4000 if (ret != 0)
4001 dev_warn(codec->dev,
4002 "Failed to request Mic1 detect IRQ: %d\n",
4003 ret);
4004 }
Mark Brown88766982010-03-29 20:57:12 +01004005
Mark Brown2a8a8562011-07-24 12:20:41 +01004006 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004007 WM8994_IRQ_MIC1_SHRT,
4008 wm8994_mic_irq, "Mic 1 short",
4009 wm8994);
4010 if (ret != 0)
4011 dev_warn(codec->dev,
4012 "Failed to request Mic1 short IRQ: %d\n",
4013 ret);
Mark Brown88766982010-03-29 20:57:12 +01004014
Mark Brown2a8a8562011-07-24 12:20:41 +01004015 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004016 WM8994_IRQ_MIC2_DET,
4017 wm8994_mic_irq, "Mic 2 detect",
4018 wm8994);
4019 if (ret != 0)
4020 dev_warn(codec->dev,
4021 "Failed to request Mic2 detect IRQ: %d\n",
4022 ret);
Mark Brown88766982010-03-29 20:57:12 +01004023
Mark Brown2a8a8562011-07-24 12:20:41 +01004024 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004025 WM8994_IRQ_MIC2_SHRT,
4026 wm8994_mic_irq, "Mic 2 short",
4027 wm8994);
4028 if (ret != 0)
4029 dev_warn(codec->dev,
4030 "Failed to request Mic2 short IRQ: %d\n",
4031 ret);
4032 break;
Mark Brown821edd22010-11-26 15:21:09 +00004033
4034 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08004035 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08004036 if (wm8994->micdet_irq) {
4037 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4038 wm8958_mic_irq,
4039 IRQF_TRIGGER_RISING,
4040 "Mic detect",
4041 wm8994);
4042 if (ret != 0)
4043 dev_warn(codec->dev,
4044 "Failed to request Mic detect IRQ: %d\n",
4045 ret);
Mark Brownb4046d02012-07-18 19:11:30 +01004046 } else {
4047 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4048 wm8958_mic_irq, "Mic detect",
4049 wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08004050 }
Mark Brown3a423152010-11-26 15:21:06 +00004051 }
Mark Brown88766982010-03-29 20:57:12 +01004052
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004053 switch (control->type) {
4054 case WM1811:
Mark Brownda445afe2013-03-12 17:46:09 +00004055 if (control->cust_id > 1 || control->revision > 1) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004056 ret = wm8994_request_irq(wm8994->wm8994,
4057 WM8994_IRQ_GPIO(6),
4058 wm1811_jackdet_irq, "JACKDET",
4059 wm8994);
4060 if (ret == 0)
4061 wm8994->jackdet = true;
4062 }
4063 break;
4064 default:
4065 break;
4066 }
4067
Mark Brownc7ebf932011-07-12 19:47:59 +09004068 wm8994->fll_locked_irq = true;
4069 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01004070 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09004071 WM8994_IRQ_FLL1_LOCK + i,
4072 wm8994_fll_locked_irq, "FLL lock",
4073 &wm8994->fll_locked[i]);
4074 if (ret != 0)
4075 wm8994->fll_locked_irq = false;
4076 }
4077
Mark Brown27060b3c2012-02-06 18:42:14 +00004078 /* Make sure we can read from the GPIOs if they're inputs */
4079 pm_runtime_get_sync(codec->dev);
4080
Mark Brown9e6e96a2010-01-29 17:47:12 +00004081 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
4082 * configured on init - if a system wants to do this dynamically
4083 * at runtime we can deal with that then.
4084 */
Mark Brownd9a76662011-07-24 12:49:52 +01004085 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004086 if (ret < 0) {
4087 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01004088 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004089 }
Mark Brownd9a76662011-07-24 12:49:52 +01004090 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00004091 wm8994->lrclk_shared[0] = 1;
4092 wm8994_dai[0].symmetric_rates = 1;
4093 } else {
4094 wm8994->lrclk_shared[0] = 0;
4095 }
4096
Mark Brownd9a76662011-07-24 12:49:52 +01004097 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004098 if (ret < 0) {
4099 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01004100 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004101 }
Mark Brownd9a76662011-07-24 12:49:52 +01004102 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00004103 wm8994->lrclk_shared[1] = 1;
4104 wm8994_dai[1].symmetric_rates = 1;
4105 } else {
4106 wm8994->lrclk_shared[1] = 0;
4107 }
4108
Mark Brown27060b3c2012-02-06 18:42:14 +00004109 pm_runtime_put(codec->dev);
4110
Mark Brownbfd37bb2012-06-05 12:31:32 +01004111 /* Latch volume update bits */
4112 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
4113 snd_soc_update_bits(codec, wm8994_vu_bits[i].reg,
4114 wm8994_vu_bits[i].mask,
4115 wm8994_vu_bits[i].mask);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004116
4117 /* Set the low bit of the 3D stereo depth so TLV matches */
4118 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
4119 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
4120 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
4121 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
4122 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
4123 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
4124 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
4125 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
4126 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
4127
Mark Brown5b739672011-07-06 00:08:43 -07004128 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
4129 * use this; it only affects behaviour on idle TDM clock
4130 * cycles. */
4131 switch (control->type) {
4132 case WM8994:
4133 case WM8958:
4134 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
4135 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
4136 break;
4137 default:
4138 break;
4139 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01004140
Mark Brown500fa302011-11-29 19:58:19 +00004141 /* Put MICBIAS into bypass mode by default on newer devices */
4142 switch (control->type) {
4143 case WM8958:
4144 case WM1811:
4145 snd_soc_update_bits(codec, WM8958_MICBIAS1,
4146 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
4147 snd_soc_update_bits(codec, WM8958_MICBIAS2,
4148 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
4149 break;
4150 default:
4151 break;
4152 }
4153
Mark Brownc3403042012-04-26 21:29:29 +01004154 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
4155 wm_hubs_update_class_w(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004156
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004157 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004158
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004159 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00004160 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004161 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004162 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004163 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00004164
4165 switch (control->type) {
4166 case WM8994:
4167 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
4168 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Mark Brownda445afe2013-03-12 17:46:09 +00004169 if (control->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004170 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4171 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004172 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4173 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004174 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4175 ARRAY_SIZE(wm8994_dac_revd_widgets));
4176 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004177 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4178 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004179 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4180 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004181 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4182 ARRAY_SIZE(wm8994_dac_widgets));
4183 }
Mark Brownc4431df2010-11-26 15:21:07 +00004184 break;
4185 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00004186 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00004187 ARRAY_SIZE(wm8958_snd_controls));
4188 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4189 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brownda445afe2013-03-12 17:46:09 +00004190 if (control->revision < 1) {
Mark Brown780e2802011-03-11 18:00:19 +00004191 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4192 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4193 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4194 ARRAY_SIZE(wm8994_adc_revd_widgets));
4195 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4196 ARRAY_SIZE(wm8994_dac_revd_widgets));
4197 } else {
4198 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4199 ARRAY_SIZE(wm8994_lateclk_widgets));
4200 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4201 ARRAY_SIZE(wm8994_adc_widgets));
4202 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4203 ARRAY_SIZE(wm8994_dac_widgets));
4204 }
Mark Brownc4431df2010-11-26 15:21:07 +00004205 break;
Mark Brown81204c82011-05-24 17:35:53 +08004206
4207 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00004208 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08004209 ARRAY_SIZE(wm8958_snd_controls));
4210 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4211 ARRAY_SIZE(wm8958_dapm_widgets));
4212 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4213 ARRAY_SIZE(wm8994_lateclk_widgets));
4214 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4215 ARRAY_SIZE(wm8994_adc_widgets));
4216 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4217 ARRAY_SIZE(wm8994_dac_widgets));
4218 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004219 }
Mark Brownc4431df2010-11-26 15:21:07 +00004220
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004221 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004222 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00004223
Mark Brownc4431df2010-11-26 15:21:07 +00004224 switch (control->type) {
4225 case WM8994:
4226 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4227 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00004228
Mark Brownda445afe2013-03-12 17:46:09 +00004229 if (control->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00004230 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4231 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004232 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4233 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4234 } else {
4235 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4236 ARRAY_SIZE(wm8994_lateclk_intercon));
4237 }
Mark Brownc4431df2010-11-26 15:21:07 +00004238 break;
4239 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00004240 if (control->revision < 1) {
Chris Rattray15676932012-08-09 10:10:54 +01004241 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4242 ARRAY_SIZE(wm8994_intercon));
Mark Brown780e2802011-03-11 18:00:19 +00004243 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4244 ARRAY_SIZE(wm8994_revd_intercon));
4245 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4246 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4247 } else {
4248 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4249 ARRAY_SIZE(wm8994_lateclk_intercon));
4250 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4251 ARRAY_SIZE(wm8958_intercon));
4252 }
Mark Brownf701a2e2011-03-09 19:31:01 +00004253
4254 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00004255 break;
Mark Brown81204c82011-05-24 17:35:53 +08004256 case WM1811:
4257 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4258 ARRAY_SIZE(wm8994_lateclk_intercon));
4259 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4260 ARRAY_SIZE(wm8958_intercon));
4261 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004262 }
4263
Mark Brown9e6e96a2010-01-29 17:47:12 +00004264 return 0;
4265
Mark Brown88766982010-03-29 20:57:12 +01004266err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004267 if (wm8994->jackdet)
4268 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004269 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4270 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4271 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08004272 if (wm8994->micdet_irq)
4273 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09004274 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004275 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004276 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01004277 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004278 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004279 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4280 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4281 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00004282
Mark Brown9e6e96a2010-01-29 17:47:12 +00004283 return ret;
4284}
4285
Jesper Juhl34ff0f92012-04-09 22:52:19 +02004286static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00004287{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004288 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01004289 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09004290 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004291
4292 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004293
Mark Brown39fb51a2010-11-26 17:23:43 +00004294 pm_runtime_disable(codec->dev);
4295
Mark Brownc7ebf932011-07-12 19:47:59 +09004296 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004297 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004298 &wm8994->fll_locked[i]);
4299
Mark Brown2a8a8562011-07-24 12:20:41 +01004300 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004301 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004302 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4303 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4304 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09004305
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004306 if (wm8994->jackdet)
4307 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4308
Mark Brown3a423152010-11-26 15:21:06 +00004309 switch (control->type) {
4310 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08004311 if (wm8994->micdet_irq)
4312 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004313 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004314 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004315 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00004316 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004317 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004318 wm8994);
4319 break;
Mark Brown821edd22010-11-26 15:21:09 +00004320
Mark Brown81204c82011-05-24 17:35:53 +08004321 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00004322 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08004323 if (wm8994->micdet_irq)
4324 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00004325 break;
Mark Brown3a423152010-11-26 15:21:06 +00004326 }
Jesper Juhl34ff0f92012-04-09 22:52:19 +02004327 release_firmware(wm8994->mbc);
4328 release_firmware(wm8994->mbc_vss);
4329 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08004330 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004331 return 0;
4332}
4333
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004334static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4335 .probe = wm8994_codec_probe,
4336 .remove = wm8994_codec_remove,
Mark Brown4752a882012-03-04 02:16:01 +00004337 .suspend = wm8994_codec_suspend,
4338 .resume = wm8994_codec_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004339 .set_bias_level = wm8994_set_bias_level,
4340};
4341
Bill Pemberton7a79e942012-12-07 09:26:37 -05004342static int wm8994_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004343{
Mark Brown2bc16ed2012-03-03 23:24:39 +00004344 struct wm8994_priv *wm8994;
4345
4346 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4347 GFP_KERNEL);
4348 if (wm8994 == NULL)
4349 return -ENOMEM;
4350 platform_set_drvdata(pdev, wm8994);
4351
4352 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00004353
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004354 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
4355 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4356}
4357
Bill Pemberton7a79e942012-12-07 09:26:37 -05004358static int wm8994_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004359{
4360 snd_soc_unregister_codec(&pdev->dev);
4361 return 0;
4362}
4363
Mark Brown4752a882012-03-04 02:16:01 +00004364#ifdef CONFIG_PM_SLEEP
4365static int wm8994_suspend(struct device *dev)
4366{
4367 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4368
4369 /* Drop down to power saving mode when system is suspended */
4370 if (wm8994->jackdet && !wm8994->active_refcount)
4371 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4372 WM1811_JACKDET_MODE_MASK,
4373 wm8994->jackdet_mode);
4374
4375 return 0;
4376}
4377
4378static int wm8994_resume(struct device *dev)
4379{
4380 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4381
Mark Brown78b76db2012-11-22 17:02:09 +09004382 if (wm8994->jackdet && wm8994->jackdet_mode)
Mark Brown4752a882012-03-04 02:16:01 +00004383 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4384 WM1811_JACKDET_MODE_MASK,
4385 WM1811_JACKDET_MODE_AUDIO);
4386
4387 return 0;
4388}
4389#endif
4390
4391static const struct dev_pm_ops wm8994_pm_ops = {
4392 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4393};
4394
Mark Brown9e6e96a2010-01-29 17:47:12 +00004395static struct platform_driver wm8994_codec_driver = {
4396 .driver = {
Mark Brown4752a882012-03-04 02:16:01 +00004397 .name = "wm8994-codec",
4398 .owner = THIS_MODULE,
4399 .pm = &wm8994_pm_ops,
4400 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004401 .probe = wm8994_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05004402 .remove = wm8994_remove,
Mark Brown9e6e96a2010-01-29 17:47:12 +00004403};
4404
Mark Brown5bbcc3c2011-11-23 22:52:08 +00004405module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004406
4407MODULE_DESCRIPTION("ASoC WM8994 driver");
4408MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4409MODULE_LICENSE("GPL");
4410MODULE_ALIAS("platform:wm8994-codec");