blob: 9e13edd81292fcf8a3a85eb3e7747df28b5bab00 [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) \
Lars-Peter Clausen6e065092013-06-19 19:33:59 +0200292 SOC_SINGLE_EXT(xname, reg, shift, 1, 0, \
293 snd_soc_get_volsw, wm8994_put_drc_sw)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000294
295static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol)
297{
298 struct soc_mixer_control *mc =
299 (struct soc_mixer_control *)kcontrol->private_value;
300 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
301 int mask, ret;
302
303 /* Can't enable both ADC and DAC paths simultaneously */
304 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
305 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
306 WM8994_AIF1ADC1R_DRC_ENA_MASK;
307 else
308 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
309
310 ret = snd_soc_read(codec, mc->reg);
311 if (ret < 0)
312 return ret;
313 if (ret & mask)
314 return -EINVAL;
315
316 return snd_soc_put_volsw(kcontrol, ucontrol);
317}
318
Mark Brown9e6e96a2010-01-29 17:47:12 +0000319static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
320{
Mark Brownb2c812e2010-04-14 15:35:19 +0900321 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900322 struct wm8994 *control = wm8994->wm8994;
323 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000324 int base = wm8994_drc_base[drc];
325 int cfg = wm8994->drc_cfg[drc];
326 int save, i;
327
328 /* Save any enables; the configuration should clear them. */
329 save = snd_soc_read(codec, base);
330 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
331 WM8994_AIF1ADC1R_DRC_ENA;
332
333 for (i = 0; i < WM8994_DRC_REGS; i++)
334 snd_soc_update_bits(codec, base + i, 0xffff,
335 pdata->drc_cfgs[cfg].regs[i]);
336
337 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
338 WM8994_AIF1ADC1L_DRC_ENA |
339 WM8994_AIF1ADC1R_DRC_ENA, save);
340}
341
342/* Icky as hell but saves code duplication */
343static int wm8994_get_drc(const char *name)
344{
345 if (strcmp(name, "AIF1DRC1 Mode") == 0)
346 return 0;
347 if (strcmp(name, "AIF1DRC2 Mode") == 0)
348 return 1;
349 if (strcmp(name, "AIF2DRC Mode") == 0)
350 return 2;
351 return -EINVAL;
352}
353
354static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
356{
357 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000358 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900359 struct wm8994 *control = wm8994->wm8994;
360 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000361 int drc = wm8994_get_drc(kcontrol->id.name);
362 int value = ucontrol->value.integer.value[0];
363
364 if (drc < 0)
365 return drc;
366
367 if (value >= pdata->num_drc_cfgs)
368 return -EINVAL;
369
370 wm8994->drc_cfg[drc] = value;
371
372 wm8994_set_drc(codec, drc);
373
374 return 0;
375}
376
377static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_value *ucontrol)
379{
380 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900381 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000382 int drc = wm8994_get_drc(kcontrol->id.name);
383
Vinod Koul7d6898b2013-05-28 15:06:42 +0530384 if (drc < 0)
385 return drc;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000386 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
387
388 return 0;
389}
390
391static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
392{
Mark Brownb2c812e2010-04-14 15:35:19 +0900393 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900394 struct wm8994 *control = wm8994->wm8994;
395 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000396 int base = wm8994_retune_mobile_base[block];
397 int iface, best, best_val, save, i, cfg;
398
399 if (!pdata || !wm8994->num_retune_mobile_texts)
400 return;
401
402 switch (block) {
403 case 0:
404 case 1:
405 iface = 0;
406 break;
407 case 2:
408 iface = 1;
409 break;
410 default:
411 return;
412 }
413
414 /* Find the version of the currently selected configuration
415 * with the nearest sample rate. */
416 cfg = wm8994->retune_mobile_cfg[block];
417 best = 0;
418 best_val = INT_MAX;
419 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
420 if (strcmp(pdata->retune_mobile_cfgs[i].name,
421 wm8994->retune_mobile_texts[cfg]) == 0 &&
422 abs(pdata->retune_mobile_cfgs[i].rate
423 - wm8994->dac_rates[iface]) < best_val) {
424 best = i;
425 best_val = abs(pdata->retune_mobile_cfgs[i].rate
426 - wm8994->dac_rates[iface]);
427 }
428 }
429
430 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
431 block,
432 pdata->retune_mobile_cfgs[best].name,
433 pdata->retune_mobile_cfgs[best].rate,
434 wm8994->dac_rates[iface]);
435
436 /* The EQ will be disabled while reconfiguring it, remember the
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +0200437 * current configuration.
Mark Brown9e6e96a2010-01-29 17:47:12 +0000438 */
439 save = snd_soc_read(codec, base);
440 save &= WM8994_AIF1DAC1_EQ_ENA;
441
442 for (i = 0; i < WM8994_EQ_REGS; i++)
443 snd_soc_update_bits(codec, base + i, 0xffff,
444 pdata->retune_mobile_cfgs[best].regs[i]);
445
446 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
447}
448
449/* Icky as hell but saves code duplication */
450static int wm8994_get_retune_mobile_block(const char *name)
451{
452 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
453 return 0;
454 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
455 return 1;
456 if (strcmp(name, "AIF2 EQ Mode") == 0)
457 return 2;
458 return -EINVAL;
459}
460
461static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_value *ucontrol)
463{
464 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000465 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownd9dd4ad2012-10-08 18:36:09 +0900466 struct wm8994 *control = wm8994->wm8994;
467 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000468 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
469 int value = ucontrol->value.integer.value[0];
470
471 if (block < 0)
472 return block;
473
474 if (value >= pdata->num_retune_mobile_cfgs)
475 return -EINVAL;
476
477 wm8994->retune_mobile_cfg[block] = value;
478
479 wm8994_set_retune_mobile(codec, block);
480
481 return 0;
482}
483
484static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
485 struct snd_ctl_elem_value *ucontrol)
486{
487 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800488 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000489 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
490
Vinod Koul7d6898b2013-05-28 15:06:42 +0530491 if (block < 0)
492 return block;
493
Mark Brown9e6e96a2010-01-29 17:47:12 +0000494 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
495
496 return 0;
497}
498
Mark Brown96b101e2010-11-18 15:49:38 +0000499static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100500 "Left", "Right"
501};
502
Mark Brown96b101e2010-11-18 15:49:38 +0000503static const struct soc_enum aif1adcl_src =
504 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
505
506static const struct soc_enum aif1adcr_src =
507 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
508
509static const struct soc_enum aif2adcl_src =
510 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
511
512static const struct soc_enum aif2adcr_src =
513 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
514
Mark Brownf5548852010-08-31 19:39:48 +0100515static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000516 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100517
518static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000519 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100520
521static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000522 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100523
524static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000525 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100526
Mark Brown154b26a2010-12-09 12:07:44 +0000527static const char *osr_text[] = {
528 "Low Power", "High Performance",
529};
530
531static const struct soc_enum dac_osr =
532 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
533
534static const struct soc_enum adc_osr =
535 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
536
Mark Brown9e6e96a2010-01-29 17:47:12 +0000537static const struct snd_kcontrol_new wm8994_snd_controls[] = {
538SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
539 WM8994_AIF1_ADC1_RIGHT_VOLUME,
540 1, 119, 0, digital_tlv),
541SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
542 WM8994_AIF1_ADC2_RIGHT_VOLUME,
543 1, 119, 0, digital_tlv),
544SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
545 WM8994_AIF2_ADC_RIGHT_VOLUME,
546 1, 119, 0, digital_tlv),
547
Mark Brown96b101e2010-11-18 15:49:38 +0000548SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
549SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000550SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
551SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000552
Mark Brownf5548852010-08-31 19:39:48 +0100553SOC_ENUM("AIF1DACL Source", aif1dacl_src),
554SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000555SOC_ENUM("AIF2DACL Source", aif2dacl_src),
556SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100557
Mark Brown9e6e96a2010-01-29 17:47:12 +0000558SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
559 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
560SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
561 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
562SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
563 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
564
565SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
566SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
567
568SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
569SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
570SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
571
572WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
573WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
574WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
575
576WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
577WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
578WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
579
580WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
581WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
582WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
583
584SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
585 5, 12, 0, st_tlv),
586SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
587 0, 12, 0, st_tlv),
588SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
589 5, 12, 0, st_tlv),
590SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
591 0, 12, 0, st_tlv),
592SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
593SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
594
Uk Kim146fd572010-12-07 13:58:40 +0000595SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
596SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
597
598SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
599SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
600
601SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
602SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
603
Mark Brown154b26a2010-12-09 12:07:44 +0000604SOC_ENUM("ADC OSR", adc_osr),
605SOC_ENUM("DAC OSR", dac_osr),
606
Mark Brown9e6e96a2010-01-29 17:47:12 +0000607SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
608 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
609SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
610 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
611
612SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
613 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
614SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
615 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
616
617SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
618 6, 1, 1, wm_hubs_spkmix_tlv),
619SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
620 2, 1, 1, wm_hubs_spkmix_tlv),
621
622SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
623 6, 1, 1, wm_hubs_spkmix_tlv),
624SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
625 2, 1, 1, wm_hubs_spkmix_tlv),
626
627SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
628 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000629SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000630 8, 1, 0),
631SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
632 10, 15, 0, wm8994_3d_tlv),
633SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
634 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000635SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000636 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000637SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000638 8, 1, 0),
639};
640
641static const struct snd_kcontrol_new wm8994_eq_controls[] = {
642SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
643 eq_tlv),
644SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
645 eq_tlv),
646SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
647 eq_tlv),
648SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
649 eq_tlv),
650SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
651 eq_tlv),
652
653SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
654 eq_tlv),
655SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
656 eq_tlv),
657SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
658 eq_tlv),
659SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
660 eq_tlv),
661SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
662 eq_tlv),
663
664SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
665 eq_tlv),
666SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
667 eq_tlv),
668SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
669 eq_tlv),
670SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
671 eq_tlv),
672SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
673 eq_tlv),
674};
675
Mark Brown45a690f2012-08-15 19:20:54 +0100676static const struct snd_kcontrol_new wm8994_drc_controls[] = {
677SND_SOC_BYTES_MASK("AIF1.1 DRC", WM8994_AIF1_DRC1_1, 5,
678 WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
679 WM8994_AIF1ADC1R_DRC_ENA),
680SND_SOC_BYTES_MASK("AIF1.2 DRC", WM8994_AIF1_DRC2_1, 5,
681 WM8994_AIF1DAC2_DRC_ENA | WM8994_AIF1ADC2L_DRC_ENA |
682 WM8994_AIF1ADC2R_DRC_ENA),
683SND_SOC_BYTES_MASK("AIF2 DRC", WM8994_AIF2_DRC_1, 5,
684 WM8994_AIF2DAC_DRC_ENA | WM8994_AIF2ADCL_DRC_ENA |
685 WM8994_AIF2ADCR_DRC_ENA),
686};
687
Mark Brown1ddc07d2011-08-16 10:08:48 +0900688static const char *wm8958_ng_text[] = {
689 "30ms", "125ms", "250ms", "500ms",
690};
691
692static const struct soc_enum wm8958_aif1dac1_ng_hold =
693 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
694 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
695
696static const struct soc_enum wm8958_aif1dac2_ng_hold =
697 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
698 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
699
700static const struct soc_enum wm8958_aif2dac_ng_hold =
701 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
702 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
703
Mark Brownc4431df2010-11-26 15:21:07 +0000704static const struct snd_kcontrol_new wm8958_snd_controls[] = {
705SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brown1ddc07d2011-08-16 10:08:48 +0900706
707SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
708 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
709SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
710SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
711 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
712 7, 1, ng_tlv),
713
714SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
715 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
716SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
717SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
718 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
719 7, 1, ng_tlv),
720
721SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
722 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
723SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
724SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
725 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
726 7, 1, ng_tlv),
Mark Brownc4431df2010-11-26 15:21:07 +0000727};
728
Mark Brown81204c82011-05-24 17:35:53 +0800729static const struct snd_kcontrol_new wm1811_snd_controls[] = {
730SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
731 mixin_boost_tlv),
732SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
733 mixin_boost_tlv),
734};
735
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000736/* We run all mode setting through a function to enforce audio mode */
737static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
738{
739 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
740
Mark Brown78b76db2012-11-22 17:02:09 +0900741 if (!wm8994->jackdet || !wm8994->micdet[0].jack)
Mark Brown28e33262012-03-03 00:10:02 +0000742 return;
743
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000744 if (wm8994->active_refcount)
745 mode = WM1811_JACKDET_MODE_AUDIO;
746
Mark Brown4752a882012-03-04 02:16:01 +0000747 if (mode == wm8994->jackdet_mode)
Mark Brown1defde22012-03-03 20:02:49 +0000748 return;
749
Mark Brown4752a882012-03-04 02:16:01 +0000750 wm8994->jackdet_mode = mode;
751
752 /* Always use audio mode to detect while the system is active */
753 if (mode != WM1811_JACKDET_MODE_NONE)
754 mode = WM1811_JACKDET_MODE_AUDIO;
755
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000756 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
757 WM1811_JACKDET_MODE_MASK, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000758}
759
760static void active_reference(struct snd_soc_codec *codec)
761{
762 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
763
764 mutex_lock(&wm8994->accdet_lock);
765
766 wm8994->active_refcount++;
767
768 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
769 wm8994->active_refcount);
770
Mark Brown1defde22012-03-03 20:02:49 +0000771 /* If we're using jack detection go into audio mode */
772 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000773
774 mutex_unlock(&wm8994->accdet_lock);
775}
776
777static void active_dereference(struct snd_soc_codec *codec)
778{
779 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
780 u16 mode;
781
782 mutex_lock(&wm8994->accdet_lock);
783
784 wm8994->active_refcount--;
785
786 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
787 wm8994->active_refcount);
788
789 if (wm8994->active_refcount == 0) {
790 /* Go into appropriate detection only mode */
Mark Brown1defde22012-03-03 20:02:49 +0000791 if (wm8994->jack_mic || wm8994->mic_detecting)
792 mode = WM1811_JACKDET_MODE_MIC;
793 else
794 mode = WM1811_JACKDET_MODE_JACK;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000795
Mark Brown1defde22012-03-03 20:02:49 +0000796 wm1811_jackdet_set_mode(codec, mode);
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000797 }
798
799 mutex_unlock(&wm8994->accdet_lock);
800}
801
Mark Brown9e6e96a2010-01-29 17:47:12 +0000802static int clk_sys_event(struct snd_soc_dapm_widget *w,
803 struct snd_kcontrol *kcontrol, int event)
804{
805 struct snd_soc_codec *codec = w->codec;
Mark Brown99af79d2012-07-25 23:03:36 +0100806 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000807
808 switch (event) {
809 case SND_SOC_DAPM_PRE_PMU:
810 return configure_clock(codec);
811
Mark Brown99af79d2012-07-25 23:03:36 +0100812 case SND_SOC_DAPM_POST_PMU:
813 /*
814 * JACKDET won't run until we start the clock and it
815 * only reports deltas, make sure we notify the state
816 * up the stack on startup. Use a *very* generous
817 * timeout for paranoia, there's no urgency and we
818 * don't want false reports.
819 */
820 if (wm8994->jackdet && !wm8994->clk_has_run) {
821 schedule_delayed_work(&wm8994->jackdet_bootstrap,
822 msecs_to_jiffies(1000));
823 wm8994->clk_has_run = true;
824 }
825 break;
826
Mark Brown9e6e96a2010-01-29 17:47:12 +0000827 case SND_SOC_DAPM_POST_PMD:
828 configure_clock(codec);
829 break;
830 }
831
832 return 0;
833}
834
Mark Brown4b7ed832011-08-10 17:47:33 +0900835static void vmid_reference(struct snd_soc_codec *codec)
836{
837 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
838
Mark Browndb966f82012-02-06 12:07:08 +0000839 pm_runtime_get_sync(codec->dev);
840
Mark Brown4b7ed832011-08-10 17:47:33 +0900841 wm8994->vmid_refcount++;
842
843 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
844 wm8994->vmid_refcount);
845
846 if (wm8994->vmid_refcount == 1) {
Mark Browncc6d5a82012-02-11 23:09:53 +0000847 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
Mark Browncc6d5a82012-02-11 23:09:53 +0000848 WM8994_LINEOUT1_DISCH |
Mark Brown22f8d052012-03-19 17:32:06 +0000849 WM8994_LINEOUT2_DISCH, 0);
Mark Browncc6d5a82012-02-11 23:09:53 +0000850
Mark Brownf7085642012-02-21 16:24:00 +0000851 wm_hubs_vmid_ena(codec);
852
Mark Brown22f8d052012-03-19 17:32:06 +0000853 switch (wm8994->vmid_mode) {
854 default:
Mark Browncbd71f32012-05-09 19:11:03 +0100855 WARN_ON(NULL == "Invalid VMID mode");
Mark Brown22f8d052012-03-19 17:32:06 +0000856 case WM8994_VMID_NORMAL:
857 /* Startup bias, VMID ramp & buffer */
858 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
859 WM8994_BIAS_SRC |
860 WM8994_VMID_DISCH |
861 WM8994_STARTUP_BIAS_ENA |
862 WM8994_VMID_BUF_ENA |
863 WM8994_VMID_RAMP_MASK,
864 WM8994_BIAS_SRC |
865 WM8994_STARTUP_BIAS_ENA |
866 WM8994_VMID_BUF_ENA |
Mark Browna3a1d9d2012-08-22 17:23:56 +0100867 (0x2 << WM8994_VMID_RAMP_SHIFT));
Mark Brown4b7ed832011-08-10 17:47:33 +0900868
Mark Brown22f8d052012-03-19 17:32:06 +0000869 /* Main bias enable, VMID=2x40k */
870 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
871 WM8994_BIAS_ENA |
872 WM8994_VMID_SEL_MASK,
873 WM8994_BIAS_ENA | 0x2);
Mark Brown4b7ed832011-08-10 17:47:33 +0900874
Mark Browna3a1d9d2012-08-22 17:23:56 +0100875 msleep(300);
Mark Browncc6d5a82012-02-11 23:09:53 +0000876
Mark Brown22f8d052012-03-19 17:32:06 +0000877 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
878 WM8994_VMID_RAMP_MASK |
879 WM8994_BIAS_SRC,
880 0);
881 break;
882
883 case WM8994_VMID_FORCE:
884 /* Startup bias, slow VMID ramp & buffer */
885 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
886 WM8994_BIAS_SRC |
887 WM8994_VMID_DISCH |
888 WM8994_STARTUP_BIAS_ENA |
889 WM8994_VMID_BUF_ENA |
890 WM8994_VMID_RAMP_MASK,
891 WM8994_BIAS_SRC |
892 WM8994_STARTUP_BIAS_ENA |
893 WM8994_VMID_BUF_ENA |
894 (0x2 << WM8994_VMID_RAMP_SHIFT));
895
896 /* Main bias enable, VMID=2x40k */
897 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
898 WM8994_BIAS_ENA |
899 WM8994_VMID_SEL_MASK,
900 WM8994_BIAS_ENA | 0x2);
901
902 msleep(400);
903
904 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
905 WM8994_VMID_RAMP_MASK |
906 WM8994_BIAS_SRC,
907 0);
908 break;
909 }
Mark Brown4b7ed832011-08-10 17:47:33 +0900910 }
911}
912
913static void vmid_dereference(struct snd_soc_codec *codec)
914{
915 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
916
917 wm8994->vmid_refcount--;
918
919 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
920 wm8994->vmid_refcount);
921
922 if (wm8994->vmid_refcount == 0) {
Mark Brown22f8d052012-03-19 17:32:06 +0000923 if (wm8994->hubs.lineout1_se)
924 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
925 WM8994_LINEOUT1N_ENA |
926 WM8994_LINEOUT1P_ENA,
927 WM8994_LINEOUT1N_ENA |
928 WM8994_LINEOUT1P_ENA);
929
930 if (wm8994->hubs.lineout2_se)
931 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
932 WM8994_LINEOUT2N_ENA |
933 WM8994_LINEOUT2P_ENA,
934 WM8994_LINEOUT2N_ENA |
935 WM8994_LINEOUT2P_ENA);
936
937 /* Start discharging VMID */
Mark Brown4b7ed832011-08-10 17:47:33 +0900938 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
939 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000940 WM8994_VMID_DISCH,
Mark Brown4b7ed832011-08-10 17:47:33 +0900941 WM8994_BIAS_SRC |
Mark Brown22f8d052012-03-19 17:32:06 +0000942 WM8994_VMID_DISCH);
Mark Brown4b7ed832011-08-10 17:47:33 +0900943
Mark Brownf95be9d2012-08-22 17:25:37 +0100944 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
945 WM8994_VMID_SEL_MASK, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900946
Mark Brownf95be9d2012-08-22 17:25:37 +0100947 msleep(400);
Mark Browne85b26c2012-02-11 23:10:30 +0000948
Mark Brown22f8d052012-03-19 17:32:06 +0000949 /* Active discharge */
Mark Brown4b7ed832011-08-10 17:47:33 +0900950 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
951 WM8994_LINEOUT1_DISCH |
952 WM8994_LINEOUT2_DISCH,
953 WM8994_LINEOUT1_DISCH |
954 WM8994_LINEOUT2_DISCH);
955
Mark Brown22f8d052012-03-19 17:32:06 +0000956 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
957 WM8994_LINEOUT1N_ENA |
958 WM8994_LINEOUT1P_ENA |
959 WM8994_LINEOUT2N_ENA |
960 WM8994_LINEOUT2P_ENA, 0);
961
Mark Brown4b7ed832011-08-10 17:47:33 +0900962 /* Switch off startup biases */
963 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
964 WM8994_BIAS_SRC |
965 WM8994_STARTUP_BIAS_ENA |
966 WM8994_VMID_BUF_ENA |
967 WM8994_VMID_RAMP_MASK, 0);
Mark Brown22f8d052012-03-19 17:32:06 +0000968
969 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
Mark Brownf95be9d2012-08-22 17:25:37 +0100970 WM8994_VMID_SEL_MASK, 0);
Mark Brown4b7ed832011-08-10 17:47:33 +0900971 }
Mark Browndb966f82012-02-06 12:07:08 +0000972
973 pm_runtime_put(codec->dev);
Mark Brown4b7ed832011-08-10 17:47:33 +0900974}
975
976static int vmid_event(struct snd_soc_dapm_widget *w,
977 struct snd_kcontrol *kcontrol, int event)
978{
979 struct snd_soc_codec *codec = w->codec;
980
981 switch (event) {
982 case SND_SOC_DAPM_PRE_PMU:
983 vmid_reference(codec);
984 break;
985
986 case SND_SOC_DAPM_POST_PMD:
987 vmid_dereference(codec);
988 break;
989 }
990
991 return 0;
992}
993
Mark Brownc3403042012-04-26 21:29:29 +0100994static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000995{
Mark Brown9e6e96a2010-01-29 17:47:12 +0000996 int source = 0; /* GCC flow analysis can't track enable */
997 int reg, reg_r;
998
Mark Brownc3403042012-04-26 21:29:29 +0100999 /* We also need the same AIF source for L/R and only one path */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001000 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
1001 switch (reg) {
1002 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001003 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001004 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1005 break;
1006 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001007 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001008 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1009 break;
1010 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +09001011 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +00001012 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1013 break;
1014 default:
Mark Brownee839a22010-04-20 13:57:08 +09001015 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brownc3403042012-04-26 21:29:29 +01001016 return false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001017 }
1018
1019 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
1020 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +09001021 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brownc3403042012-04-26 21:29:29 +01001022 return false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001023 }
1024
Mark Brownc3403042012-04-26 21:29:29 +01001025 /* Set the source up */
1026 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
1027 WM8994_CP_DYN_SRC_SEL_MASK, source);
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02001028
Mark Brownc3403042012-04-26 21:29:29 +01001029 return true;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001030}
1031
Mark Brown1a383362012-04-12 19:47:11 +01001032static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1033 struct snd_kcontrol *kcontrol, int event)
1034{
1035 struct snd_soc_codec *codec = w->codec;
Mark Brown79748cd2012-10-01 15:28:30 +01001036 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Vinod Kould3134e22013-05-28 15:41:57 +05301037 struct wm8994 *control = wm8994->wm8994;
Mark Brown1a383362012-04-12 19:47:11 +01001038 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
Mark Brownbfd37bb2012-06-05 12:31:32 +01001039 int i;
Mark Brown1a383362012-04-12 19:47:11 +01001040 int dac;
1041 int adc;
1042 int val;
1043
1044 switch (control->type) {
1045 case WM8994:
1046 case WM8958:
1047 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1048 break;
1049 default:
1050 break;
1051 }
1052
1053 switch (event) {
1054 case SND_SOC_DAPM_PRE_PMU:
Mark Brown79748cd2012-10-01 15:28:30 +01001055 /* Don't enable timeslot 2 if not in use */
1056 if (wm8994->channels[0] <= 2)
1057 mask &= ~(WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
1058
Mark Brown1a383362012-04-12 19:47:11 +01001059 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
1060 if ((val & WM8994_AIF1ADCL_SRC) &&
1061 (val & WM8994_AIF1ADCR_SRC))
1062 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1063 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1064 !(val & WM8994_AIF1ADCR_SRC))
1065 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1066 else
1067 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1068 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1069
1070 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
1071 if ((val & WM8994_AIF1DACL_SRC) &&
1072 (val & WM8994_AIF1DACR_SRC))
1073 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1074 else if (!(val & WM8994_AIF1DACL_SRC) &&
1075 !(val & WM8994_AIF1DACR_SRC))
1076 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1077 else
1078 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1079 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1080
1081 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1082 mask, adc);
1083 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1084 mask, dac);
1085 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1086 WM8994_AIF1DSPCLK_ENA |
1087 WM8994_SYSDSPCLK_ENA,
1088 WM8994_AIF1DSPCLK_ENA |
1089 WM8994_SYSDSPCLK_ENA);
1090 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
1091 WM8994_AIF1ADC1R_ENA |
1092 WM8994_AIF1ADC1L_ENA |
1093 WM8994_AIF1ADC2R_ENA |
1094 WM8994_AIF1ADC2L_ENA);
1095 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
1096 WM8994_AIF1DAC1R_ENA |
1097 WM8994_AIF1DAC1L_ENA |
1098 WM8994_AIF1DAC2R_ENA |
1099 WM8994_AIF1DAC2L_ENA);
1100 break;
1101
Mark Brownbfd37bb2012-06-05 12:31:32 +01001102 case SND_SOC_DAPM_POST_PMU:
1103 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1104 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1105 snd_soc_read(codec,
1106 wm8994_vu_bits[i].reg));
1107 break;
1108
Mark Brown1a383362012-04-12 19:47:11 +01001109 case SND_SOC_DAPM_PRE_PMD:
1110 case SND_SOC_DAPM_POST_PMD:
1111 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1112 mask, 0);
1113 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1114 mask, 0);
1115
1116 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1117 if (val & WM8994_AIF2DSPCLK_ENA)
1118 val = WM8994_SYSDSPCLK_ENA;
1119 else
1120 val = 0;
1121 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1122 WM8994_SYSDSPCLK_ENA |
1123 WM8994_AIF1DSPCLK_ENA, val);
1124 break;
1125 }
1126
1127 return 0;
1128}
1129
1130static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1131 struct snd_kcontrol *kcontrol, int event)
1132{
1133 struct snd_soc_codec *codec = w->codec;
Mark Brownbfd37bb2012-06-05 12:31:32 +01001134 int i;
Mark Brown1a383362012-04-12 19:47:11 +01001135 int dac;
1136 int adc;
1137 int val;
1138
1139 switch (event) {
1140 case SND_SOC_DAPM_PRE_PMU:
1141 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
1142 if ((val & WM8994_AIF2ADCL_SRC) &&
1143 (val & WM8994_AIF2ADCR_SRC))
1144 adc = WM8994_AIF2ADCR_ENA;
1145 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1146 !(val & WM8994_AIF2ADCR_SRC))
1147 adc = WM8994_AIF2ADCL_ENA;
1148 else
1149 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1150
1151
1152 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
1153 if ((val & WM8994_AIF2DACL_SRC) &&
1154 (val & WM8994_AIF2DACR_SRC))
1155 dac = WM8994_AIF2DACR_ENA;
1156 else if (!(val & WM8994_AIF2DACL_SRC) &&
1157 !(val & WM8994_AIF2DACR_SRC))
1158 dac = WM8994_AIF2DACL_ENA;
1159 else
1160 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1161
1162 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1163 WM8994_AIF2ADCL_ENA |
1164 WM8994_AIF2ADCR_ENA, adc);
1165 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1166 WM8994_AIF2DACL_ENA |
1167 WM8994_AIF2DACR_ENA, dac);
1168 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1169 WM8994_AIF2DSPCLK_ENA |
1170 WM8994_SYSDSPCLK_ENA,
1171 WM8994_AIF2DSPCLK_ENA |
1172 WM8994_SYSDSPCLK_ENA);
1173 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1174 WM8994_AIF2ADCL_ENA |
1175 WM8994_AIF2ADCR_ENA,
1176 WM8994_AIF2ADCL_ENA |
1177 WM8994_AIF2ADCR_ENA);
1178 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1179 WM8994_AIF2DACL_ENA |
1180 WM8994_AIF2DACR_ENA,
1181 WM8994_AIF2DACL_ENA |
1182 WM8994_AIF2DACR_ENA);
1183 break;
1184
Mark Brownbfd37bb2012-06-05 12:31:32 +01001185 case SND_SOC_DAPM_POST_PMU:
1186 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1187 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1188 snd_soc_read(codec,
1189 wm8994_vu_bits[i].reg));
1190 break;
1191
Mark Brown1a383362012-04-12 19:47:11 +01001192 case SND_SOC_DAPM_PRE_PMD:
1193 case SND_SOC_DAPM_POST_PMD:
1194 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1195 WM8994_AIF2DACL_ENA |
1196 WM8994_AIF2DACR_ENA, 0);
Mark Brownc7f5f232012-05-15 18:13:00 +01001197 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
Mark Brown1a383362012-04-12 19:47:11 +01001198 WM8994_AIF2ADCL_ENA |
1199 WM8994_AIF2ADCR_ENA, 0);
1200
1201 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1202 if (val & WM8994_AIF1DSPCLK_ENA)
1203 val = WM8994_SYSDSPCLK_ENA;
1204 else
1205 val = 0;
1206 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1207 WM8994_SYSDSPCLK_ENA |
1208 WM8994_AIF2DSPCLK_ENA, val);
1209 break;
1210 }
1211
1212 return 0;
1213}
1214
1215static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1216 struct snd_kcontrol *kcontrol, int event)
1217{
1218 struct snd_soc_codec *codec = w->codec;
1219 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1220
1221 switch (event) {
1222 case SND_SOC_DAPM_PRE_PMU:
1223 wm8994->aif1clk_enable = 1;
1224 break;
1225 case SND_SOC_DAPM_POST_PMD:
1226 wm8994->aif1clk_disable = 1;
1227 break;
1228 }
1229
1230 return 0;
1231}
1232
1233static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1234 struct snd_kcontrol *kcontrol, int event)
1235{
1236 struct snd_soc_codec *codec = w->codec;
1237 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1238
1239 switch (event) {
1240 case SND_SOC_DAPM_PRE_PMU:
1241 wm8994->aif2clk_enable = 1;
1242 break;
1243 case SND_SOC_DAPM_POST_PMD:
1244 wm8994->aif2clk_disable = 1;
1245 break;
1246 }
1247
1248 return 0;
1249}
1250
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001251static int late_enable_ev(struct snd_soc_dapm_widget *w,
1252 struct snd_kcontrol *kcontrol, int event)
1253{
1254 struct snd_soc_codec *codec = w->codec;
1255 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1256
1257 switch (event) {
1258 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001259 if (wm8994->aif1clk_enable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001260 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001261 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1262 WM8994_AIF1CLK_ENA_MASK,
1263 WM8994_AIF1CLK_ENA);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001264 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001265 wm8994->aif1clk_enable = 0;
1266 }
1267 if (wm8994->aif2clk_enable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001268 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001269 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1270 WM8994_AIF2CLK_ENA_MASK,
1271 WM8994_AIF2CLK_ENA);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001272 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001273 wm8994->aif2clk_enable = 0;
1274 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001275 break;
1276 }
1277
Mark Brownc6b7b572011-03-11 18:13:12 +00001278 /* We may also have postponed startup of DSP, handle that. */
1279 wm8958_aif_ev(w, kcontrol, event);
1280
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001281 return 0;
1282}
1283
1284static int late_disable_ev(struct snd_soc_dapm_widget *w,
1285 struct snd_kcontrol *kcontrol, int event)
1286{
1287 struct snd_soc_codec *codec = w->codec;
1288 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1289
1290 switch (event) {
1291 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001292 if (wm8994->aif1clk_disable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001293 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001294 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1295 WM8994_AIF1CLK_ENA_MASK, 0);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001296 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001297 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001298 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001299 if (wm8994->aif2clk_disable) {
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001300 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001301 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1302 WM8994_AIF2CLK_ENA_MASK, 0);
Mark Brownc8fdc1b2012-06-05 12:25:19 +01001303 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +00001304 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001305 }
1306 break;
1307 }
1308
1309 return 0;
1310}
1311
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001312static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1313 struct snd_kcontrol *kcontrol, int event)
1314{
1315 late_enable_ev(w, kcontrol, event);
1316 return 0;
1317}
1318
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001319static int micbias_ev(struct snd_soc_dapm_widget *w,
1320 struct snd_kcontrol *kcontrol, int event)
1321{
1322 late_enable_ev(w, kcontrol, event);
1323 return 0;
1324}
1325
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001326static int dac_ev(struct snd_soc_dapm_widget *w,
1327 struct snd_kcontrol *kcontrol, int event)
1328{
1329 struct snd_soc_codec *codec = w->codec;
1330 unsigned int mask = 1 << w->shift;
1331
1332 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1333 mask, mask);
1334 return 0;
1335}
1336
Mark Brown9e6e96a2010-01-29 17:47:12 +00001337static const char *adc_mux_text[] = {
1338 "ADC",
1339 "DMIC",
1340};
1341
1342static const struct soc_enum adc_enum =
1343 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1344
1345static const struct snd_kcontrol_new adcl_mux =
1346 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1347
1348static const struct snd_kcontrol_new adcr_mux =
1349 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1350
1351static const struct snd_kcontrol_new left_speaker_mixer[] = {
1352SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1353SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1354SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1355SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1356SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1357};
1358
1359static const struct snd_kcontrol_new right_speaker_mixer[] = {
1360SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1361SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1362SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1363SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1364SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1365};
1366
1367/* Debugging; dump chip status after DAPM transitions */
1368static int post_ev(struct snd_soc_dapm_widget *w,
1369 struct snd_kcontrol *kcontrol, int event)
1370{
1371 struct snd_soc_codec *codec = w->codec;
1372 dev_dbg(codec->dev, "SRC status: %x\n",
1373 snd_soc_read(codec,
1374 WM8994_RATE_STATUS));
1375 return 0;
1376}
1377
1378static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1379SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1380 1, 1, 0),
1381SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1382 0, 1, 0),
1383};
1384
1385static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1386SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1387 1, 1, 0),
1388SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1389 0, 1, 0),
1390};
1391
Mark Browna3257ba2010-07-19 14:02:34 +01001392static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1393SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1394 1, 1, 0),
1395SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1396 0, 1, 0),
1397};
1398
1399static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1400SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1401 1, 1, 0),
1402SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1403 0, 1, 0),
1404};
1405
Mark Brown9e6e96a2010-01-29 17:47:12 +00001406static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1407SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1408 5, 1, 0),
1409SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1410 4, 1, 0),
1411SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1412 2, 1, 0),
1413SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1414 1, 1, 0),
1415SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1416 0, 1, 0),
1417};
1418
1419static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1420SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1421 5, 1, 0),
1422SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1423 4, 1, 0),
1424SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1425 2, 1, 0),
1426SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1427 1, 1, 0),
1428SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1429 0, 1, 0),
1430};
1431
1432#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
Lars-Peter Clausen6e065092013-06-19 19:33:59 +02001433 SOC_SINGLE_EXT(xname, reg, shift, max, invert, \
1434 snd_soc_get_volsw, wm8994_put_class_w)
Mark Brown9e6e96a2010-01-29 17:47:12 +00001435
1436static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1437 struct snd_ctl_elem_value *ucontrol)
1438{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001439 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1440 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001441 struct snd_soc_codec *codec = w->codec;
1442 int ret;
1443
1444 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1445
Mark Brownc3403042012-04-26 21:29:29 +01001446 wm_hubs_update_class_w(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001447
1448 return ret;
1449}
1450
1451static const struct snd_kcontrol_new dac1l_mix[] = {
1452WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1453 5, 1, 0),
1454WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1455 4, 1, 0),
1456WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1457 2, 1, 0),
1458WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1459 1, 1, 0),
1460WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1461 0, 1, 0),
1462};
1463
1464static const struct snd_kcontrol_new dac1r_mix[] = {
1465WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1466 5, 1, 0),
1467WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1468 4, 1, 0),
1469WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1470 2, 1, 0),
1471WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1472 1, 1, 0),
1473WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1474 0, 1, 0),
1475};
1476
1477static const char *sidetone_text[] = {
1478 "ADC/DMIC1", "DMIC2",
1479};
1480
1481static const struct soc_enum sidetone1_enum =
1482 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1483
1484static const struct snd_kcontrol_new sidetone1_mux =
1485 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1486
1487static const struct soc_enum sidetone2_enum =
1488 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1489
1490static const struct snd_kcontrol_new sidetone2_mux =
1491 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1492
1493static const char *aif1dac_text[] = {
1494 "AIF1DACDAT", "AIF3DACDAT",
1495};
1496
1497static const struct soc_enum aif1dac_enum =
1498 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1499
1500static const struct snd_kcontrol_new aif1dac_mux =
1501 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1502
1503static const char *aif2dac_text[] = {
1504 "AIF2DACDAT", "AIF3DACDAT",
1505};
1506
1507static const struct soc_enum aif2dac_enum =
1508 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1509
1510static const struct snd_kcontrol_new aif2dac_mux =
1511 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1512
1513static const char *aif2adc_text[] = {
1514 "AIF2ADCDAT", "AIF3DACDAT",
1515};
1516
1517static const struct soc_enum aif2adc_enum =
1518 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1519
1520static const struct snd_kcontrol_new aif2adc_mux =
1521 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1522
1523static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001524 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001525};
1526
Mark Brownc4431df2010-11-26 15:21:07 +00001527static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001528 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1529
Mark Brownc4431df2010-11-26 15:21:07 +00001530static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1531 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1532
1533static const struct soc_enum wm8958_aif3adc_enum =
1534 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1535
1536static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1537 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1538
1539static const char *mono_pcm_out_text[] = {
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02001540 "None", "AIF2ADCL", "AIF2ADCR",
Mark Brownc4431df2010-11-26 15:21:07 +00001541};
1542
1543static const struct soc_enum mono_pcm_out_enum =
1544 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1545
1546static const struct snd_kcontrol_new mono_pcm_out_mux =
1547 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1548
1549static const char *aif2dac_src_text[] = {
1550 "AIF2", "AIF3",
1551};
1552
1553/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1554static const struct soc_enum aif2dacl_src_enum =
1555 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1556
1557static const struct snd_kcontrol_new aif2dacl_src_mux =
1558 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1559
1560static const struct soc_enum aif2dacr_src_enum =
1561 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1562
1563static const struct snd_kcontrol_new aif2dacr_src_mux =
1564 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001565
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001566static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001567SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001568 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown1a383362012-04-12 19:47:11 +01001569SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001570 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1571
1572SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1573 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1574SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1575 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1576SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1577 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1578SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1579 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001580SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1581 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1582
1583SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1584 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1585 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1586SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1587 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1588 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownc3403042012-04-26 21:29:29 +01001589SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
Mark Brownb70a51b2011-06-29 00:21:09 -07001590 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownc3403042012-04-26 21:29:29 +01001591SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
Mark Brownb70a51b2011-06-29 00:21:09 -07001592 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001593
1594SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1595};
1596
1597static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
Mark Brown1a383362012-04-12 19:47:11 +01001598SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
Mark Brownbfd37bb2012-06-05 12:31:32 +01001599 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1600 SND_SOC_DAPM_PRE_PMD),
Mark Brown1a383362012-04-12 19:47:11 +01001601SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
Mark Brownbfd37bb2012-06-05 12:31:32 +01001602 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1603 SND_SOC_DAPM_PRE_PMD),
Mark Brownb70a51b2011-06-29 00:21:09 -07001604SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1605SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1606 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1607SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1608 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
Mark Brownc3403042012-04-26 21:29:29 +01001609SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1610SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001611};
1612
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001613static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1614SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1615 dac_ev, SND_SOC_DAPM_PRE_PMU),
1616SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1617 dac_ev, SND_SOC_DAPM_PRE_PMU),
1618SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1619 dac_ev, SND_SOC_DAPM_PRE_PMU),
1620SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1621 dac_ev, SND_SOC_DAPM_PRE_PMU),
1622};
1623
1624static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1625SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001626SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001627SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1628SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1629};
1630
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001631static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001632SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1633 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1634SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1635 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001636};
1637
1638static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
Mark Brown87b86ad2011-08-14 13:39:20 +09001639SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1640SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001641};
1642
Mark Brown9e6e96a2010-01-29 17:47:12 +00001643static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1644SND_SOC_DAPM_INPUT("DMIC1DAT"),
1645SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001646SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001647
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001648SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1649 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001650SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1651 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001652
Mark Brown9e6e96a2010-01-29 17:47:12 +00001653SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
Mark Brown99af79d2012-07-25 23:03:36 +01001654 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1655 SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001656
Mark Brown1a383362012-04-12 19:47:11 +01001657SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1658SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1659SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001660
Mark Brown7f94de42011-02-03 16:27:34 +00001661SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001662 0, SND_SOC_NOPM, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001663SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001664 0, SND_SOC_NOPM, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001665SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001666 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001667 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001668SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001669 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001670 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001671
Mark Brown7f94de42011-02-03 16:27:34 +00001672SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001673 0, SND_SOC_NOPM, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001674SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown1a383362012-04-12 19:47:11 +01001675 0, SND_SOC_NOPM, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001676SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001677 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001678 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001679SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001680 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001681 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001682
1683SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1684 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1685SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1686 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1687
Mark Browna3257ba2010-07-19 14:02:34 +01001688SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1689 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1690SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1691 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1692
Mark Brown9e6e96a2010-01-29 17:47:12 +00001693SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1694 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1695SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1696 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1697
1698SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1699SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1700
1701SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1702 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1703SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1704 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1705
1706SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001707 SND_SOC_NOPM, 13, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001708SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001709 SND_SOC_NOPM, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001710SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001711 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001712 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1713SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
Mark Brown1a383362012-04-12 19:47:11 +01001714 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
Mark Brownd6addcc2010-11-26 15:21:08 +00001715 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001716
Mark Brown5567d8c2012-02-16 21:43:29 -08001717SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1718SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1719SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1720SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001721
1722SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1723SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1724SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001725
Mark Brown5567d8c2012-02-16 21:43:29 -08001726SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1727SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001728
1729SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1730
1731SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1732SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1733SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1734SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1735
1736/* Power is done with the muxes since the ADC power also controls the
1737 * downsampling chain, the chip will automatically manage the analogue
1738 * specific portions.
1739 */
1740SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1741SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1742
Mark Brown9e6e96a2010-01-29 17:47:12 +00001743SND_SOC_DAPM_POST("Debug log", post_ev),
1744};
1745
Mark Brownc4431df2010-11-26 15:21:07 +00001746static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1747SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1748};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001749
Mark Brownc4431df2010-11-26 15:21:07 +00001750static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
Mark Brown8c5b8422012-04-17 20:49:05 +01001751SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
Mark Brownc4431df2010-11-26 15:21:07 +00001752SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1753SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1754SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1755SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1756};
1757
1758static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001759 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1760 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1761
1762 { "DSP1CLK", NULL, "CLK_SYS" },
1763 { "DSP2CLK", NULL, "CLK_SYS" },
1764 { "DSPINTCLK", NULL, "CLK_SYS" },
1765
1766 { "AIF1ADC1L", NULL, "AIF1CLK" },
1767 { "AIF1ADC1L", NULL, "DSP1CLK" },
1768 { "AIF1ADC1R", NULL, "AIF1CLK" },
1769 { "AIF1ADC1R", NULL, "DSP1CLK" },
1770 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1771
1772 { "AIF1DAC1L", NULL, "AIF1CLK" },
1773 { "AIF1DAC1L", NULL, "DSP1CLK" },
1774 { "AIF1DAC1R", NULL, "AIF1CLK" },
1775 { "AIF1DAC1R", NULL, "DSP1CLK" },
1776 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1777
1778 { "AIF1ADC2L", NULL, "AIF1CLK" },
1779 { "AIF1ADC2L", NULL, "DSP1CLK" },
1780 { "AIF1ADC2R", NULL, "AIF1CLK" },
1781 { "AIF1ADC2R", NULL, "DSP1CLK" },
1782 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1783
1784 { "AIF1DAC2L", NULL, "AIF1CLK" },
1785 { "AIF1DAC2L", NULL, "DSP1CLK" },
1786 { "AIF1DAC2R", NULL, "AIF1CLK" },
1787 { "AIF1DAC2R", NULL, "DSP1CLK" },
1788 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1789
1790 { "AIF2ADCL", NULL, "AIF2CLK" },
1791 { "AIF2ADCL", NULL, "DSP2CLK" },
1792 { "AIF2ADCR", NULL, "AIF2CLK" },
1793 { "AIF2ADCR", NULL, "DSP2CLK" },
1794 { "AIF2ADCR", NULL, "DSPINTCLK" },
1795
1796 { "AIF2DACL", NULL, "AIF2CLK" },
1797 { "AIF2DACL", NULL, "DSP2CLK" },
1798 { "AIF2DACR", NULL, "AIF2CLK" },
1799 { "AIF2DACR", NULL, "DSP2CLK" },
1800 { "AIF2DACR", NULL, "DSPINTCLK" },
1801
1802 { "DMIC1L", NULL, "DMIC1DAT" },
1803 { "DMIC1L", NULL, "CLK_SYS" },
1804 { "DMIC1R", NULL, "DMIC1DAT" },
1805 { "DMIC1R", NULL, "CLK_SYS" },
1806 { "DMIC2L", NULL, "DMIC2DAT" },
1807 { "DMIC2L", NULL, "CLK_SYS" },
1808 { "DMIC2R", NULL, "DMIC2DAT" },
1809 { "DMIC2R", NULL, "CLK_SYS" },
1810
1811 { "ADCL", NULL, "AIF1CLK" },
1812 { "ADCL", NULL, "DSP1CLK" },
1813 { "ADCL", NULL, "DSPINTCLK" },
1814
1815 { "ADCR", NULL, "AIF1CLK" },
1816 { "ADCR", NULL, "DSP1CLK" },
1817 { "ADCR", NULL, "DSPINTCLK" },
1818
1819 { "ADCL Mux", "ADC", "ADCL" },
1820 { "ADCL Mux", "DMIC", "DMIC1L" },
1821 { "ADCR Mux", "ADC", "ADCR" },
1822 { "ADCR Mux", "DMIC", "DMIC1R" },
1823
1824 { "DAC1L", NULL, "AIF1CLK" },
1825 { "DAC1L", NULL, "DSP1CLK" },
1826 { "DAC1L", NULL, "DSPINTCLK" },
1827
1828 { "DAC1R", NULL, "AIF1CLK" },
1829 { "DAC1R", NULL, "DSP1CLK" },
1830 { "DAC1R", NULL, "DSPINTCLK" },
1831
1832 { "DAC2L", NULL, "AIF2CLK" },
1833 { "DAC2L", NULL, "DSP2CLK" },
1834 { "DAC2L", NULL, "DSPINTCLK" },
1835
1836 { "DAC2R", NULL, "AIF2DACR" },
1837 { "DAC2R", NULL, "AIF2CLK" },
1838 { "DAC2R", NULL, "DSP2CLK" },
1839 { "DAC2R", NULL, "DSPINTCLK" },
1840
1841 { "TOCLK", NULL, "CLK_SYS" },
1842
Mark Brown5567d8c2012-02-16 21:43:29 -08001843 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1844 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1845 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1846
1847 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1848 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1849 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1850
Mark Brown9e6e96a2010-01-29 17:47:12 +00001851 /* AIF1 outputs */
1852 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1853 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1854 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1855
1856 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1857 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1858 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1859
Mark Browna3257ba2010-07-19 14:02:34 +01001860 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1861 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1862 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1863
1864 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1865 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1866 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1867
Mark Brown9e6e96a2010-01-29 17:47:12 +00001868 /* Pin level routing for AIF3 */
1869 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1870 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1871 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1872 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1873
Mark Brown9e6e96a2010-01-29 17:47:12 +00001874 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1875 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1876 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1877 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1878 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1879 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1880 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1881
1882 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001883 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1884 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1885 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1886 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1887 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1888
Mark Brown9e6e96a2010-01-29 17:47:12 +00001889 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1890 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1891 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1892 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1893 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1894
1895 /* DAC2/AIF2 outputs */
1896 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001897 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1898 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1899 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1900 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1901 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1902
1903 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001904 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1905 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1906 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1907 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1908 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1909
Mark Brown7f94de42011-02-03 16:27:34 +00001910 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1911 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1912 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1913 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1914
Mark Brown9e6e96a2010-01-29 17:47:12 +00001915 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1916
1917 /* AIF3 output */
1918 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1919 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1920 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1921 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1922 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1923 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1924 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1925 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1926
1927 /* Sidetone */
1928 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1929 { "Left Sidetone", "DMIC2", "DMIC2L" },
1930 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1931 { "Right Sidetone", "DMIC2", "DMIC2R" },
1932
1933 /* Output stages */
1934 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1935 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1936
1937 { "SPKL", "DAC1 Switch", "DAC1L" },
1938 { "SPKL", "DAC2 Switch", "DAC2L" },
1939
1940 { "SPKR", "DAC1 Switch", "DAC1R" },
1941 { "SPKR", "DAC2 Switch", "DAC2R" },
1942
1943 { "Left Headphone Mux", "DAC", "DAC1L" },
1944 { "Right Headphone Mux", "DAC", "DAC1R" },
1945};
1946
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001947static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1948 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1949 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1950 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1951 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1952 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1953 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1954 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1955 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1956};
1957
1958static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1959 { "DAC1L", NULL, "DAC1L Mixer" },
1960 { "DAC1R", NULL, "DAC1R Mixer" },
1961 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1962 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1963};
1964
Mark Brown6ed8f142011-02-03 16:27:35 +00001965static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1966 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1967 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1968 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1969 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001970 { "MICBIAS1", NULL, "CLK_SYS" },
1971 { "MICBIAS1", NULL, "MICBIAS Supply" },
1972 { "MICBIAS2", NULL, "CLK_SYS" },
1973 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001974};
1975
Mark Brownc4431df2010-11-26 15:21:07 +00001976static const struct snd_soc_dapm_route wm8994_intercon[] = {
1977 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1978 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001979 { "MICBIAS1", NULL, "VMID" },
1980 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001981};
1982
1983static const struct snd_soc_dapm_route wm8958_intercon[] = {
1984 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1985 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1986
1987 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1988 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1989 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1990 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1991
Mark Brown8c5b8422012-04-17 20:49:05 +01001992 { "AIF3DACDAT", NULL, "AIF3" },
1993 { "AIF3ADCDAT", NULL, "AIF3" },
1994
Mark Brownc4431df2010-11-26 15:21:07 +00001995 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1996 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1997
1998 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1999};
2000
Mark Brown9e6e96a2010-01-29 17:47:12 +00002001/* The size in bits of the FLL divide multiplied by 10
2002 * to allow rounding later */
2003#define FIXED_FLL_SIZE ((1 << 16) * 10)
2004
2005struct fll_div {
2006 u16 outdiv;
2007 u16 n;
2008 u16 k;
2009 u16 clk_ref_div;
2010 u16 fll_fratio;
2011};
2012
2013static int wm8994_get_fll_config(struct fll_div *fll,
2014 int freq_in, int freq_out)
2015{
2016 u64 Kpart;
2017 unsigned int K, Ndiv, Nmod;
2018
2019 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2020
2021 /* Scale the input frequency down to <= 13.5MHz */
2022 fll->clk_ref_div = 0;
2023 while (freq_in > 13500000) {
2024 fll->clk_ref_div++;
2025 freq_in /= 2;
2026
2027 if (fll->clk_ref_div > 3)
2028 return -EINVAL;
2029 }
2030 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2031
2032 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2033 fll->outdiv = 3;
2034 while (freq_out * (fll->outdiv + 1) < 90000000) {
2035 fll->outdiv++;
2036 if (fll->outdiv > 63)
2037 return -EINVAL;
2038 }
2039 freq_out *= fll->outdiv + 1;
2040 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2041
2042 if (freq_in > 1000000) {
2043 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002044 } else if (freq_in > 256000) {
2045 fll->fll_fratio = 1;
2046 freq_in *= 2;
2047 } else if (freq_in > 128000) {
2048 fll->fll_fratio = 2;
2049 freq_in *= 4;
2050 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002051 fll->fll_fratio = 3;
2052 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09002053 } else {
2054 fll->fll_fratio = 4;
2055 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002056 }
2057 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2058
2059 /* Now, calculate N.K */
2060 Ndiv = freq_out / freq_in;
2061
2062 fll->n = Ndiv;
2063 Nmod = freq_out % freq_in;
2064 pr_debug("Nmod=%d\n", Nmod);
2065
2066 /* Calculate fractional part - scale up so we can round. */
2067 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2068
2069 do_div(Kpart, freq_in);
2070
2071 K = Kpart & 0xFFFFFFFF;
2072
2073 if ((K % 10) >= 5)
2074 K += 5;
2075
2076 /* Move down to proper range now rounding is done */
2077 fll->k = K / 10;
2078
2079 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2080
2081 return 0;
2082}
2083
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002084static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002085 unsigned int freq_in, unsigned int freq_out)
2086{
Mark Brownb2c812e2010-04-14 15:35:19 +09002087 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002088 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002089 int reg_offset, ret;
2090 struct fll_div fll;
Mark Browne413ba82012-03-29 14:49:27 +01002091 u16 reg, clk1, aif_reg, aif_src;
Mark Brownc7ebf932011-07-12 19:47:59 +09002092 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09002093 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002094
Mark Brown9e6e96a2010-01-29 17:47:12 +00002095 switch (id) {
2096 case WM8994_FLL1:
2097 reg_offset = 0;
2098 id = 0;
Mark Browne413ba82012-03-29 14:49:27 +01002099 aif_src = 0x10;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002100 break;
2101 case WM8994_FLL2:
2102 reg_offset = 0x20;
2103 id = 1;
Mark Browne413ba82012-03-29 14:49:27 +01002104 aif_src = 0x18;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002105 break;
2106 default:
2107 return -EINVAL;
2108 }
2109
Mark Brown4b7ed832011-08-10 17:47:33 +09002110 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
2111 was_enabled = reg & WM8994_FLL1_ENA;
2112
Mark Brown136ff2a2010-04-20 12:56:18 +09002113 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09002114 case 0:
2115 /* Allow no source specification when stopping */
2116 if (freq_out)
2117 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00002118 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09002119 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09002120 case WM8994_FLL_SRC_MCLK1:
2121 case WM8994_FLL_SRC_MCLK2:
2122 case WM8994_FLL_SRC_LRCLK:
2123 case WM8994_FLL_SRC_BCLK:
2124 break;
Mark Brownfbfe6982012-07-23 20:14:43 +01002125 case WM8994_FLL_SRC_INTERNAL:
2126 freq_in = 12000000;
2127 freq_out = 12000000;
2128 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09002129 default:
2130 return -EINVAL;
2131 }
2132
Mark Brown9e6e96a2010-01-29 17:47:12 +00002133 /* Are we changing anything? */
2134 if (wm8994->fll[id].src == src &&
2135 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2136 return 0;
2137
2138 /* If we're stopping the FLL redo the old config - no
2139 * registers will actually be written but we avoid GCC flow
2140 * analysis bugs spewing warnings.
2141 */
2142 if (freq_out)
2143 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
2144 else
2145 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
2146 wm8994->fll[id].out);
2147 if (ret < 0)
2148 return ret;
2149
Mark Browne413ba82012-03-29 14:49:27 +01002150 /* Make sure that we're not providing SYSCLK right now */
2151 clk1 = snd_soc_read(codec, WM8994_CLOCKING_1);
2152 if (clk1 & WM8994_SYSCLK_SRC)
2153 aif_reg = WM8994_AIF2_CLOCKING_1;
2154 else
2155 aif_reg = WM8994_AIF1_CLOCKING_1;
2156 reg = snd_soc_read(codec, aif_reg);
2157
2158 if ((reg & WM8994_AIF1CLK_ENA) &&
2159 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2160 dev_err(codec->dev, "FLL%d is currently providing SYSCLK\n",
2161 id + 1);
2162 return -EBUSY;
2163 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002164
2165 /* We always need to disable the FLL while reconfiguring */
2166 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2167 WM8994_FLL1_ENA, 0);
2168
Mark Brown20dc24a2012-04-05 12:55:20 +01002169 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
Kyung-Kwee Ryue05854d2012-04-24 18:01:48 +01002170 freq_in == freq_out && freq_out) {
Mark Brown20dc24a2012-04-05 12:55:20 +01002171 dev_dbg(codec->dev, "Bypassing FLL%d\n", id + 1);
2172 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2173 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2174 goto out;
2175 }
2176
Mark Brown9e6e96a2010-01-29 17:47:12 +00002177 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2178 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2179 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
2180 WM8994_FLL1_OUTDIV_MASK |
2181 WM8994_FLL1_FRATIO_MASK, reg);
2182
Mark Brownb16db742012-03-03 15:33:23 +00002183 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
2184 WM8994_FLL1_K_MASK, fll.k);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002185
2186 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
2187 WM8994_FLL1_N_MASK,
Mark Brown7435d4e2012-07-26 14:49:11 +01002188 fll.n << WM8994_FLL1_N_SHIFT);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002189
2190 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brownfbfe6982012-07-23 20:14:43 +01002191 WM8994_FLL1_FRC_NCO | WM8958_FLL1_BYP |
Mark Brown136ff2a2010-04-20 12:56:18 +09002192 WM8994_FLL1_REFCLK_DIV_MASK |
2193 WM8994_FLL1_REFCLK_SRC_MASK,
Mark Brownfbfe6982012-07-23 20:14:43 +01002194 ((src == WM8994_FLL_SRC_INTERNAL)
2195 << WM8994_FLL1_FRC_NCO_SHIFT) |
Mark Brown136ff2a2010-04-20 12:56:18 +09002196 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2197 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00002198
Mark Brownf0f50392011-07-16 03:12:18 +09002199 /* Clear any pending completion from a previous failure */
2200 try_wait_for_completion(&wm8994->fll_locked[id]);
2201
Mark Brown9e6e96a2010-01-29 17:47:12 +00002202 /* Enable (with fractional mode if required) */
2203 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09002204 /* Enable VMID if we need it */
2205 if (!was_enabled) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002206 active_reference(codec);
2207
Mark Brown4b7ed832011-08-10 17:47:33 +09002208 switch (control->type) {
2209 case WM8994:
2210 vmid_reference(codec);
2211 break;
2212 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002213 if (control->revision < 1)
Mark Brown4b7ed832011-08-10 17:47:33 +09002214 vmid_reference(codec);
2215 break;
2216 default:
2217 break;
2218 }
2219 }
2220
Mark Brownfbfe6982012-07-23 20:14:43 +01002221 reg = WM8994_FLL1_ENA;
2222
Mark Brown9e6e96a2010-01-29 17:47:12 +00002223 if (fll.k)
Mark Brownfbfe6982012-07-23 20:14:43 +01002224 reg |= WM8994_FLL1_FRAC;
2225 if (src == WM8994_FLL_SRC_INTERNAL)
2226 reg |= WM8994_FLL1_OSC_ENA;
2227
Mark Brown9e6e96a2010-01-29 17:47:12 +00002228 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
Mark Brownfbfe6982012-07-23 20:14:43 +01002229 WM8994_FLL1_ENA | WM8994_FLL1_OSC_ENA |
2230 WM8994_FLL1_FRAC, reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07002231
Mark Brownc7ebf932011-07-12 19:47:59 +09002232 if (wm8994->fll_locked_irq) {
2233 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2234 msecs_to_jiffies(10));
2235 if (timeout == 0)
2236 dev_warn(codec->dev,
2237 "Timed out waiting for FLL lock\n");
2238 } else {
2239 msleep(5);
2240 }
Mark Brown4b7ed832011-08-10 17:47:33 +09002241 } else {
2242 if (was_enabled) {
2243 switch (control->type) {
2244 case WM8994:
2245 vmid_dereference(codec);
2246 break;
2247 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002248 if (control->revision < 1)
Mark Brown4b7ed832011-08-10 17:47:33 +09002249 vmid_dereference(codec);
2250 break;
2251 default:
2252 break;
2253 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002254
2255 active_dereference(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09002256 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002257 }
2258
Mark Brown20dc24a2012-04-05 12:55:20 +01002259out:
Mark Brown9e6e96a2010-01-29 17:47:12 +00002260 wm8994->fll[id].in = freq_in;
2261 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09002262 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002263
Mark Brown9e6e96a2010-01-29 17:47:12 +00002264 configure_clock(codec);
2265
Mark Browncd220002012-10-24 10:56:30 +01002266 /*
2267 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2268 * for detection.
2269 */
2270 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2271 dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
Mark Brownd3725762013-01-29 23:17:12 +08002272
2273 wm8994->aifdiv[0] = snd_soc_read(codec, WM8994_AIF1_RATE)
2274 & WM8994_AIF1CLK_RATE_MASK;
2275 wm8994->aifdiv[1] = snd_soc_read(codec, WM8994_AIF2_RATE)
2276 & WM8994_AIF1CLK_RATE_MASK;
2277
Mark Browncd220002012-10-24 10:56:30 +01002278 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2279 WM8994_AIF1CLK_RATE_MASK, 0x1);
2280 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2281 WM8994_AIF2CLK_RATE_MASK, 0x1);
Mark Brownd3725762013-01-29 23:17:12 +08002282 } else if (wm8994->aifdiv[0]) {
2283 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2284 WM8994_AIF1CLK_RATE_MASK,
2285 wm8994->aifdiv[0]);
2286 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2287 WM8994_AIF2CLK_RATE_MASK,
2288 wm8994->aifdiv[1]);
2289
2290 wm8994->aifdiv[0] = 0;
2291 wm8994->aifdiv[1] = 0;
Mark Browncd220002012-10-24 10:56:30 +01002292 }
2293
Mark Brown9e6e96a2010-01-29 17:47:12 +00002294 return 0;
2295}
2296
Mark Brownc7ebf932011-07-12 19:47:59 +09002297static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2298{
2299 struct completion *completion = data;
2300
2301 complete(completion);
2302
2303 return IRQ_HANDLED;
2304}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002305
Mark Brown66b47fd2010-07-08 11:25:43 +09002306static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2307
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002308static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2309 unsigned int freq_in, unsigned int freq_out)
2310{
2311 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2312}
2313
Mark Brown9e6e96a2010-01-29 17:47:12 +00002314static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2315 int clk_id, unsigned int freq, int dir)
2316{
2317 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002318 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09002319 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002320
2321 switch (dai->id) {
2322 case 1:
2323 case 2:
2324 break;
2325
2326 default:
2327 /* AIF3 shares clocking with AIF1/2 */
2328 return -EINVAL;
2329 }
2330
2331 switch (clk_id) {
2332 case WM8994_SYSCLK_MCLK1:
2333 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2334 wm8994->mclk[0] = freq;
2335 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2336 dai->id, freq);
2337 break;
2338
2339 case WM8994_SYSCLK_MCLK2:
2340 /* TODO: Set GPIO AF */
2341 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2342 wm8994->mclk[1] = freq;
2343 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2344 dai->id, freq);
2345 break;
2346
2347 case WM8994_SYSCLK_FLL1:
2348 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2349 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2350 break;
2351
2352 case WM8994_SYSCLK_FLL2:
2353 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2354 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2355 break;
2356
Mark Brown66b47fd2010-07-08 11:25:43 +09002357 case WM8994_SYSCLK_OPCLK:
2358 /* Special case - a division (times 10) is given and
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02002359 * no effect on main clocking.
Mark Brown66b47fd2010-07-08 11:25:43 +09002360 */
2361 if (freq) {
2362 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2363 if (opclk_divs[i] == freq)
2364 break;
2365 if (i == ARRAY_SIZE(opclk_divs))
2366 return -EINVAL;
2367 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2368 WM8994_OPCLK_DIV_MASK, i);
2369 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2370 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2371 } else {
2372 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2373 WM8994_OPCLK_ENA, 0);
2374 }
2375
Mark Brown9e6e96a2010-01-29 17:47:12 +00002376 default:
2377 return -EINVAL;
2378 }
2379
2380 configure_clock(codec);
2381
Mark Brown67300492012-10-24 10:56:30 +01002382 /*
2383 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2384 * for detection.
2385 */
2386 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2387 dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
Mark Brownd3725762013-01-29 23:17:12 +08002388
2389 wm8994->aifdiv[0] = snd_soc_read(codec, WM8994_AIF1_RATE)
2390 & WM8994_AIF1CLK_RATE_MASK;
2391 wm8994->aifdiv[1] = snd_soc_read(codec, WM8994_AIF2_RATE)
2392 & WM8994_AIF1CLK_RATE_MASK;
2393
Mark Brown67300492012-10-24 10:56:30 +01002394 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2395 WM8994_AIF1CLK_RATE_MASK, 0x1);
2396 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2397 WM8994_AIF2CLK_RATE_MASK, 0x1);
Mark Brownd3725762013-01-29 23:17:12 +08002398 } else if (wm8994->aifdiv[0]) {
2399 snd_soc_update_bits(codec, WM8994_AIF1_RATE,
2400 WM8994_AIF1CLK_RATE_MASK,
2401 wm8994->aifdiv[0]);
2402 snd_soc_update_bits(codec, WM8994_AIF2_RATE,
2403 WM8994_AIF2CLK_RATE_MASK,
2404 wm8994->aifdiv[1]);
2405
2406 wm8994->aifdiv[0] = 0;
2407 wm8994->aifdiv[1] = 0;
Mark Brown67300492012-10-24 10:56:30 +01002408 }
2409
Mark Brown9e6e96a2010-01-29 17:47:12 +00002410 return 0;
2411}
2412
2413static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2414 enum snd_soc_bias_level level)
2415{
Mark Brownb6b05692010-08-13 12:58:20 +01002416 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01002417 struct wm8994 *control = wm8994->wm8994;
Mark Brownb6b05692010-08-13 12:58:20 +01002418
Mark Brown5f2f3892012-02-08 18:51:42 +00002419 wm_hubs_set_bias_level(codec, level);
2420
Mark Brown9e6e96a2010-01-29 17:47:12 +00002421 switch (level) {
2422 case SND_SOC_BIAS_ON:
2423 break;
2424
2425 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002426 /* MICBIAS into regulating mode */
2427 switch (control->type) {
2428 case WM8958:
2429 case WM1811:
2430 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2431 WM8958_MICB1_MODE, 0);
2432 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2433 WM8958_MICB2_MODE, 0);
2434 break;
2435 default:
2436 break;
2437 }
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002438
2439 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2440 active_reference(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002441 break;
2442
2443 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002444 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002445 switch (control->type) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002446 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00002447 if (control->revision == 0) {
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002448 /* Optimise performance for rev A */
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002449 snd_soc_update_bits(codec,
2450 WM8958_CHARGE_PUMP_2,
2451 WM8958_CP_DISCH,
2452 WM8958_CP_DISCH);
2453 }
2454 break;
Mark Brown81204c82011-05-24 17:35:53 +08002455
Mark Brown462835e2012-01-21 12:11:53 +00002456 default:
Mark Brown81204c82011-05-24 17:35:53 +08002457 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002458 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002459
2460 /* Discharge LINEOUT1 & 2 */
2461 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2462 WM8994_LINEOUT1_DISCH |
2463 WM8994_LINEOUT2_DISCH,
2464 WM8994_LINEOUT1_DISCH |
2465 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002466 }
2467
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002468 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2469 active_dereference(codec);
2470
Mark Brown500fa302011-11-29 19:58:19 +00002471 /* MICBIAS into bypass mode on newer devices */
2472 switch (control->type) {
2473 case WM8958:
2474 case WM1811:
2475 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2476 WM8958_MICB1_MODE,
2477 WM8958_MICB1_MODE);
2478 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2479 WM8958_MICB2_MODE,
2480 WM8958_MICB2_MODE);
2481 break;
2482 default:
2483 break;
2484 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002485 break;
2486
2487 case SND_SOC_BIAS_OFF:
Mark Brown4105ab82011-12-05 15:17:36 +00002488 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
Mark Brownfbbf5922011-03-11 18:09:04 +00002489 wm8994->cur_fw = NULL;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002490 break;
2491 }
Mark Brown5f2f3892012-02-08 18:51:42 +00002492
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002493 codec->dapm.bias_level = level;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00002494
Mark Brown9e6e96a2010-01-29 17:47:12 +00002495 return 0;
2496}
2497
Mark Brown22f8d052012-03-19 17:32:06 +00002498int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2499{
2500 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2501
2502 switch (mode) {
2503 case WM8994_VMID_NORMAL:
2504 if (wm8994->hubs.lineout1_se) {
2505 snd_soc_dapm_disable_pin(&codec->dapm,
2506 "LINEOUT1N Driver");
2507 snd_soc_dapm_disable_pin(&codec->dapm,
2508 "LINEOUT1P Driver");
2509 }
2510 if (wm8994->hubs.lineout2_se) {
2511 snd_soc_dapm_disable_pin(&codec->dapm,
2512 "LINEOUT2N Driver");
2513 snd_soc_dapm_disable_pin(&codec->dapm,
2514 "LINEOUT2P Driver");
2515 }
2516
2517 /* Do the sync with the old mode to allow it to clean up */
2518 snd_soc_dapm_sync(&codec->dapm);
2519 wm8994->vmid_mode = mode;
2520 break;
2521
2522 case WM8994_VMID_FORCE:
2523 if (wm8994->hubs.lineout1_se) {
2524 snd_soc_dapm_force_enable_pin(&codec->dapm,
2525 "LINEOUT1N Driver");
2526 snd_soc_dapm_force_enable_pin(&codec->dapm,
2527 "LINEOUT1P Driver");
2528 }
2529 if (wm8994->hubs.lineout2_se) {
2530 snd_soc_dapm_force_enable_pin(&codec->dapm,
2531 "LINEOUT2N Driver");
2532 snd_soc_dapm_force_enable_pin(&codec->dapm,
2533 "LINEOUT2P Driver");
2534 }
2535
2536 wm8994->vmid_mode = mode;
2537 snd_soc_dapm_sync(&codec->dapm);
2538 break;
2539
2540 default:
2541 return -EINVAL;
2542 }
2543
2544 return 0;
2545}
2546
Mark Brown9e6e96a2010-01-29 17:47:12 +00002547static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2548{
2549 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002550 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2551 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002552 int ms_reg;
2553 int aif1_reg;
2554 int ms = 0;
2555 int aif1 = 0;
2556
2557 switch (dai->id) {
2558 case 1:
2559 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2560 aif1_reg = WM8994_AIF1_CONTROL_1;
2561 break;
2562 case 2:
2563 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2564 aif1_reg = WM8994_AIF2_CONTROL_1;
2565 break;
2566 default:
2567 return -EINVAL;
2568 }
2569
2570 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2571 case SND_SOC_DAIFMT_CBS_CFS:
2572 break;
2573 case SND_SOC_DAIFMT_CBM_CFM:
2574 ms = WM8994_AIF1_MSTR;
2575 break;
2576 default:
2577 return -EINVAL;
2578 }
2579
2580 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2581 case SND_SOC_DAIFMT_DSP_B:
2582 aif1 |= WM8994_AIF1_LRCLK_INV;
2583 case SND_SOC_DAIFMT_DSP_A:
2584 aif1 |= 0x18;
2585 break;
2586 case SND_SOC_DAIFMT_I2S:
2587 aif1 |= 0x10;
2588 break;
2589 case SND_SOC_DAIFMT_RIGHT_J:
2590 break;
2591 case SND_SOC_DAIFMT_LEFT_J:
2592 aif1 |= 0x8;
2593 break;
2594 default:
2595 return -EINVAL;
2596 }
2597
2598 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2599 case SND_SOC_DAIFMT_DSP_A:
2600 case SND_SOC_DAIFMT_DSP_B:
2601 /* frame inversion not valid for DSP modes */
2602 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2603 case SND_SOC_DAIFMT_NB_NF:
2604 break;
2605 case SND_SOC_DAIFMT_IB_NF:
2606 aif1 |= WM8994_AIF1_BCLK_INV;
2607 break;
2608 default:
2609 return -EINVAL;
2610 }
2611 break;
2612
2613 case SND_SOC_DAIFMT_I2S:
2614 case SND_SOC_DAIFMT_RIGHT_J:
2615 case SND_SOC_DAIFMT_LEFT_J:
2616 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2617 case SND_SOC_DAIFMT_NB_NF:
2618 break;
2619 case SND_SOC_DAIFMT_IB_IF:
2620 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2621 break;
2622 case SND_SOC_DAIFMT_IB_NF:
2623 aif1 |= WM8994_AIF1_BCLK_INV;
2624 break;
2625 case SND_SOC_DAIFMT_NB_IF:
2626 aif1 |= WM8994_AIF1_LRCLK_INV;
2627 break;
2628 default:
2629 return -EINVAL;
2630 }
2631 break;
2632 default:
2633 return -EINVAL;
2634 }
2635
Mark Brownc4431df2010-11-26 15:21:07 +00002636 /* The AIF2 format configuration needs to be mirrored to AIF3
2637 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002638 switch (control->type) {
2639 case WM1811:
2640 case WM8958:
2641 if (dai->id == 2)
2642 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2643 WM8994_AIF1_LRCLK_INV |
2644 WM8958_AIF3_FMT_MASK, aif1);
2645 break;
2646
2647 default:
2648 break;
2649 }
Mark Brownc4431df2010-11-26 15:21:07 +00002650
Mark Brown9e6e96a2010-01-29 17:47:12 +00002651 snd_soc_update_bits(codec, aif1_reg,
2652 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2653 WM8994_AIF1_FMT_MASK,
2654 aif1);
2655 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2656 ms);
2657
2658 return 0;
2659}
2660
2661static struct {
2662 int val, rate;
2663} srs[] = {
2664 { 0, 8000 },
2665 { 1, 11025 },
2666 { 2, 12000 },
2667 { 3, 16000 },
2668 { 4, 22050 },
2669 { 5, 24000 },
2670 { 6, 32000 },
2671 { 7, 44100 },
2672 { 8, 48000 },
2673 { 9, 88200 },
2674 { 10, 96000 },
2675};
2676
2677static int fs_ratios[] = {
2678 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2679};
2680
2681static int bclk_divs[] = {
2682 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2683 640, 880, 960, 1280, 1760, 1920
2684};
2685
2686static int wm8994_hw_params(struct snd_pcm_substream *substream,
2687 struct snd_pcm_hw_params *params,
2688 struct snd_soc_dai *dai)
2689{
2690 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002691 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown3cf956e2013-03-20 10:12:10 +01002692 struct wm8994 *control = wm8994->wm8994;
2693 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002694 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002695 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002696 int bclk_reg;
2697 int lrclk_reg;
2698 int rate_reg;
2699 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002700 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002701 int bclk = 0;
2702 int lrclk = 0;
2703 int rate_val = 0;
2704 int id = dai->id - 1;
2705
2706 int i, cur_val, best_val, bclk_rate, best;
2707
2708 switch (dai->id) {
2709 case 1:
2710 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002711 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002712 bclk_reg = WM8994_AIF1_BCLK;
2713 rate_reg = WM8994_AIF1_RATE;
2714 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002715 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002716 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002717 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002718 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002719 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2720 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002721 break;
2722 case 2:
2723 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002724 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002725 bclk_reg = WM8994_AIF2_BCLK;
2726 rate_reg = WM8994_AIF2_RATE;
2727 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002728 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002729 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002730 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002731 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002732 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2733 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002734 break;
2735 default:
2736 return -EINVAL;
2737 }
2738
Mark Brown79748cd2012-10-01 15:28:30 +01002739 bclk_rate = params_rate(params);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002740 switch (params_format(params)) {
2741 case SNDRV_PCM_FORMAT_S16_LE:
2742 bclk_rate *= 16;
2743 break;
2744 case SNDRV_PCM_FORMAT_S20_3LE:
2745 bclk_rate *= 20;
2746 aif1 |= 0x20;
2747 break;
2748 case SNDRV_PCM_FORMAT_S24_LE:
2749 bclk_rate *= 24;
2750 aif1 |= 0x40;
2751 break;
2752 case SNDRV_PCM_FORMAT_S32_LE:
2753 bclk_rate *= 32;
2754 aif1 |= 0x60;
2755 break;
2756 default:
2757 return -EINVAL;
2758 }
2759
Mark Brown79748cd2012-10-01 15:28:30 +01002760 wm8994->channels[id] = params_channels(params);
Mark Brown3cf956e2013-03-20 10:12:10 +01002761 if (pdata->max_channels_clocked[id] &&
2762 wm8994->channels[id] > pdata->max_channels_clocked[id]) {
2763 dev_dbg(dai->dev, "Constraining channels to %d from %d\n",
2764 pdata->max_channels_clocked[id], wm8994->channels[id]);
2765 wm8994->channels[id] = pdata->max_channels_clocked[id];
2766 }
2767
2768 switch (wm8994->channels[id]) {
Mark Brown79748cd2012-10-01 15:28:30 +01002769 case 1:
2770 case 2:
2771 bclk_rate *= 2;
2772 break;
2773 default:
2774 bclk_rate *= 4;
2775 break;
2776 }
2777
Mark Brown9e6e96a2010-01-29 17:47:12 +00002778 /* Try to find an appropriate sample rate; look for an exact match. */
2779 for (i = 0; i < ARRAY_SIZE(srs); i++)
2780 if (srs[i].rate == params_rate(params))
2781 break;
2782 if (i == ARRAY_SIZE(srs))
2783 return -EINVAL;
2784 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2785
2786 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2787 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2788 dai->id, wm8994->aifclk[id], bclk_rate);
2789
Mark Brown3cf956e2013-03-20 10:12:10 +01002790 if (wm8994->channels[id] == 1 &&
Mark Brownb1e43d92010-12-07 17:14:56 +00002791 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2792 aif2 |= WM8994_AIF1_MONO;
2793
Mark Brown9e6e96a2010-01-29 17:47:12 +00002794 if (wm8994->aifclk[id] == 0) {
2795 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2796 return -EINVAL;
2797 }
2798
2799 /* AIFCLK/fs ratio; look for a close match in either direction */
2800 best = 0;
2801 best_val = abs((fs_ratios[0] * params_rate(params))
2802 - wm8994->aifclk[id]);
2803 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2804 cur_val = abs((fs_ratios[i] * params_rate(params))
2805 - wm8994->aifclk[id]);
2806 if (cur_val >= best_val)
2807 continue;
2808 best = i;
2809 best_val = cur_val;
2810 }
2811 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2812 dai->id, fs_ratios[best]);
2813 rate_val |= best;
2814
2815 /* We may not get quite the right frequency if using
2816 * approximate clocks so look for the closest match that is
2817 * higher than the target (we need to ensure that there enough
2818 * BCLKs to clock out the samples).
2819 */
2820 best = 0;
2821 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002822 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002823 if (cur_val < 0) /* BCLK table is sorted */
2824 break;
2825 best = i;
2826 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002827 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002828 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2829 bclk_divs[best], bclk_rate);
2830 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2831
2832 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002833 if (!lrclk) {
2834 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2835 bclk_rate);
2836 return -EINVAL;
2837 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002838 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2839 lrclk, bclk_rate / lrclk);
2840
2841 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002842 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002843 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2844 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2845 lrclk);
2846 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2847 WM8994_AIF1CLK_RATE_MASK, rate_val);
2848
2849 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2850 switch (dai->id) {
2851 case 1:
2852 wm8994->dac_rates[0] = params_rate(params);
2853 wm8994_set_retune_mobile(codec, 0);
2854 wm8994_set_retune_mobile(codec, 1);
2855 break;
2856 case 2:
2857 wm8994->dac_rates[1] = params_rate(params);
2858 wm8994_set_retune_mobile(codec, 2);
2859 break;
2860 }
2861 }
2862
2863 return 0;
2864}
2865
Mark Brownc4431df2010-11-26 15:21:07 +00002866static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2867 struct snd_pcm_hw_params *params,
2868 struct snd_soc_dai *dai)
2869{
2870 struct snd_soc_codec *codec = dai->codec;
Mark Brown2a8a8562011-07-24 12:20:41 +01002871 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2872 struct wm8994 *control = wm8994->wm8994;
Mark Brownc4431df2010-11-26 15:21:07 +00002873 int aif1_reg;
2874 int aif1 = 0;
2875
2876 switch (dai->id) {
2877 case 3:
2878 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002879 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002880 case WM8958:
2881 aif1_reg = WM8958_AIF3_CONTROL_1;
2882 break;
2883 default:
2884 return 0;
2885 }
Dan Carpenter4495e46f2013-04-30 10:24:41 +03002886 break;
Mark Brownc4431df2010-11-26 15:21:07 +00002887 default:
2888 return 0;
2889 }
2890
2891 switch (params_format(params)) {
2892 case SNDRV_PCM_FORMAT_S16_LE:
2893 break;
2894 case SNDRV_PCM_FORMAT_S20_3LE:
2895 aif1 |= 0x20;
2896 break;
2897 case SNDRV_PCM_FORMAT_S24_LE:
2898 aif1 |= 0x40;
2899 break;
2900 case SNDRV_PCM_FORMAT_S32_LE:
2901 aif1 |= 0x60;
2902 break;
2903 default:
2904 return -EINVAL;
2905 }
2906
2907 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2908}
2909
Mark Brown9e6e96a2010-01-29 17:47:12 +00002910static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2911{
2912 struct snd_soc_codec *codec = codec_dai->codec;
2913 int mute_reg;
2914 int reg;
2915
2916 switch (codec_dai->id) {
2917 case 1:
2918 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2919 break;
2920 case 2:
2921 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2922 break;
2923 default:
2924 return -EINVAL;
2925 }
2926
2927 if (mute)
2928 reg = WM8994_AIF1DAC1_MUTE;
2929 else
2930 reg = 0;
2931
2932 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2933
2934 return 0;
2935}
2936
Mark Brown778a76e2010-03-22 22:05:10 +00002937static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2938{
2939 struct snd_soc_codec *codec = codec_dai->codec;
2940 int reg, val, mask;
2941
2942 switch (codec_dai->id) {
2943 case 1:
2944 reg = WM8994_AIF1_MASTER_SLAVE;
2945 mask = WM8994_AIF1_TRI;
2946 break;
2947 case 2:
2948 reg = WM8994_AIF2_MASTER_SLAVE;
2949 mask = WM8994_AIF2_TRI;
2950 break;
Mark Brown778a76e2010-03-22 22:05:10 +00002951 default:
2952 return -EINVAL;
2953 }
2954
2955 if (tristate)
2956 val = mask;
2957 else
2958 val = 0;
2959
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002960 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002961}
2962
Mark Brownd09f3ec2011-08-15 11:01:02 +09002963static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2964{
2965 struct snd_soc_codec *codec = dai->codec;
2966
2967 /* Disable the pulls on the AIF if we're using it to save power. */
2968 snd_soc_update_bits(codec, WM8994_GPIO_3,
2969 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2970 snd_soc_update_bits(codec, WM8994_GPIO_4,
2971 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2972 snd_soc_update_bits(codec, WM8994_GPIO_5,
2973 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2974
2975 return 0;
2976}
2977
Mark Brown9e6e96a2010-01-29 17:47:12 +00002978#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2979
2980#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002981 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002982
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002983static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002984 .set_sysclk = wm8994_set_dai_sysclk,
2985 .set_fmt = wm8994_set_dai_fmt,
2986 .hw_params = wm8994_hw_params,
2987 .digital_mute = wm8994_aif_mute,
2988 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002989 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002990};
2991
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002992static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002993 .set_sysclk = wm8994_set_dai_sysclk,
2994 .set_fmt = wm8994_set_dai_fmt,
2995 .hw_params = wm8994_hw_params,
2996 .digital_mute = wm8994_aif_mute,
2997 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002998 .set_tristate = wm8994_set_tristate,
2999};
3000
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01003001static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00003002 .hw_params = wm8994_aif3_hw_params,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003003};
3004
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003005static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003006 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003007 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003008 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003009 .playback = {
3010 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003011 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003012 .channels_max = 2,
3013 .rates = WM8994_RATES,
3014 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003015 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003016 },
3017 .capture = {
3018 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003019 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003020 .channels_max = 2,
3021 .rates = WM8994_RATES,
3022 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003023 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003024 },
3025 .ops = &wm8994_aif1_dai_ops,
3026 },
3027 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003028 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003029 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003030 .playback = {
3031 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003032 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003033 .channels_max = 2,
3034 .rates = WM8994_RATES,
3035 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003036 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003037 },
3038 .capture = {
3039 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003040 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003041 .channels_max = 2,
3042 .rates = WM8994_RATES,
3043 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003044 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003045 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09003046 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003047 .ops = &wm8994_aif2_dai_ops,
3048 },
3049 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003050 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01003051 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003052 .playback = {
3053 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00003054 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003055 .channels_max = 2,
3056 .rates = WM8994_RATES,
3057 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003058 .sig_bits = 24,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003059 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03003060 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00003061 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00003062 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003063 .channels_max = 2,
3064 .rates = WM8994_RATES,
3065 .formats = WM8994_FORMATS,
Mark Brown99b02922012-01-17 11:50:26 +00003066 .sig_bits = 24,
3067 },
Mark Brown778a76e2010-03-22 22:05:10 +00003068 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003069 }
3070};
Mark Brown9e6e96a2010-01-29 17:47:12 +00003071
3072#ifdef CONFIG_PM
Mark Brown4752a882012-03-04 02:16:01 +00003073static int wm8994_codec_suspend(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003074{
Mark Brownb2c812e2010-04-14 15:35:19 +09003075 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003076 int i, ret;
3077
3078 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3079 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00003080 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003081 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003082 if (ret < 0)
3083 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
3084 i + 1, ret);
3085 }
3086
3087 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
3088
3089 return 0;
3090}
3091
Mark Brown4752a882012-03-04 02:16:01 +00003092static int wm8994_codec_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003093{
Mark Brownb2c812e2010-04-14 15:35:19 +09003094 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003095 struct wm8994 *control = wm8994->wm8994;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003096 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003097 unsigned int val, mask;
3098
Mark Brownda445afe2013-03-12 17:46:09 +00003099 if (control->revision < 4) {
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003100 /* force a HW read */
Mark Brownd9a76662011-07-24 12:49:52 +01003101 ret = regmap_read(control->regmap,
3102 WM8994_POWER_MANAGEMENT_5, &val);
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003103
3104 /* modify the cache only */
3105 codec->cache_only = 1;
3106 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
3107 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
3108 val &= mask;
3109 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
3110 mask, val);
3111 codec->cache_only = 0;
3112 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003113
Mark Brown9e6e96a2010-01-29 17:47:12 +00003114 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01003115 if (!wm8994->fll_suspend[i].out)
3116 continue;
3117
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003118 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003119 wm8994->fll_suspend[i].src,
3120 wm8994->fll_suspend[i].in,
3121 wm8994->fll_suspend[i].out);
3122 if (ret < 0)
3123 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
3124 i + 1, ret);
3125 }
3126
3127 return 0;
3128}
3129#else
Mark Brown4752a882012-03-04 02:16:01 +00003130#define wm8994_codec_suspend NULL
3131#define wm8994_codec_resume NULL
Mark Brown9e6e96a2010-01-29 17:47:12 +00003132#endif
3133
3134static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3135{
Mark Brown8cb8e832012-07-25 18:10:03 +01003136 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003137 struct wm8994 *control = wm8994->wm8994;
3138 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003139 struct snd_kcontrol_new controls[] = {
3140 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3141 wm8994->retune_mobile_enum,
3142 wm8994_get_retune_mobile_enum,
3143 wm8994_put_retune_mobile_enum),
3144 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3145 wm8994->retune_mobile_enum,
3146 wm8994_get_retune_mobile_enum,
3147 wm8994_put_retune_mobile_enum),
3148 SOC_ENUM_EXT("AIF2 EQ Mode",
3149 wm8994->retune_mobile_enum,
3150 wm8994_get_retune_mobile_enum,
3151 wm8994_put_retune_mobile_enum),
3152 };
3153 int ret, i, j;
3154 const char **t;
3155
3156 /* We need an array of texts for the enum API but the number
3157 * of texts is likely to be less than the number of
3158 * configurations due to the sample rate dependency of the
3159 * configurations. */
3160 wm8994->num_retune_mobile_texts = 0;
3161 wm8994->retune_mobile_texts = NULL;
3162 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3163 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3164 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3165 wm8994->retune_mobile_texts[j]) == 0)
3166 break;
3167 }
3168
3169 if (j != wm8994->num_retune_mobile_texts)
3170 continue;
3171
3172 /* Expand the array... */
3173 t = krealloc(wm8994->retune_mobile_texts,
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02003174 sizeof(char *) *
Mark Brown9e6e96a2010-01-29 17:47:12 +00003175 (wm8994->num_retune_mobile_texts + 1),
3176 GFP_KERNEL);
3177 if (t == NULL)
3178 continue;
3179
3180 /* ...store the new entry... */
Jesper Juhlc1a4ecd2012-04-09 00:40:32 +02003181 t[wm8994->num_retune_mobile_texts] =
Mark Brown9e6e96a2010-01-29 17:47:12 +00003182 pdata->retune_mobile_cfgs[i].name;
3183
3184 /* ...and remember the new version. */
3185 wm8994->num_retune_mobile_texts++;
3186 wm8994->retune_mobile_texts = t;
3187 }
3188
3189 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
3190 wm8994->num_retune_mobile_texts);
3191
3192 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
3193 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3194
Mark Brown8cb8e832012-07-25 18:10:03 +01003195 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003196 ARRAY_SIZE(controls));
3197 if (ret != 0)
Mark Brown8cb8e832012-07-25 18:10:03 +01003198 dev_err(wm8994->hubs.codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003199 "Failed to add ReTune Mobile controls: %d\n", ret);
3200}
3201
3202static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3203{
Mark Brown8cb8e832012-07-25 18:10:03 +01003204 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003205 struct wm8994 *control = wm8994->wm8994;
3206 struct wm8994_pdata *pdata = &control->pdata;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003207 int ret, i;
3208
3209 if (!pdata)
3210 return;
3211
3212 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
3213 pdata->lineout2_diff,
3214 pdata->lineout1fb,
3215 pdata->lineout2fb,
3216 pdata->jd_scthr,
3217 pdata->jd_thr,
Mark Brown02e79472012-08-21 17:54:52 +01003218 pdata->micb1_delay,
3219 pdata->micb2_delay,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003220 pdata->micbias1_lvl,
3221 pdata->micbias2_lvl);
3222
3223 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3224
3225 if (pdata->num_drc_cfgs) {
3226 struct snd_kcontrol_new controls[] = {
3227 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3228 wm8994_get_drc_enum, wm8994_put_drc_enum),
3229 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3230 wm8994_get_drc_enum, wm8994_put_drc_enum),
3231 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3232 wm8994_get_drc_enum, wm8994_put_drc_enum),
3233 };
3234
3235 /* We need an array of texts for the enum API */
Mark Brown8cb8e832012-07-25 18:10:03 +01003236 wm8994->drc_texts = devm_kzalloc(wm8994->hubs.codec->dev,
Mark Brown7270ceb2011-12-01 14:00:19 +00003237 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003238 if (!wm8994->drc_texts) {
Mark Brown8cb8e832012-07-25 18:10:03 +01003239 dev_err(wm8994->hubs.codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003240 "Failed to allocate %d DRC config texts\n",
3241 pdata->num_drc_cfgs);
3242 return;
3243 }
3244
3245 for (i = 0; i < pdata->num_drc_cfgs; i++)
3246 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3247
3248 wm8994->drc_enum.max = pdata->num_drc_cfgs;
3249 wm8994->drc_enum.texts = wm8994->drc_texts;
3250
Mark Brown8cb8e832012-07-25 18:10:03 +01003251 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003252 ARRAY_SIZE(controls));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003253 for (i = 0; i < WM8994_NUM_DRC; i++)
3254 wm8994_set_drc(codec, i);
Mark Brown45a690f2012-08-15 19:20:54 +01003255 } else {
3256 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
3257 wm8994_drc_controls,
3258 ARRAY_SIZE(wm8994_drc_controls));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003259 }
3260
Mark Brown45a690f2012-08-15 19:20:54 +01003261 if (ret != 0)
3262 dev_err(wm8994->hubs.codec->dev,
3263 "Failed to add DRC mode controls: %d\n", ret);
3264
3265
Mark Brown9e6e96a2010-01-29 17:47:12 +00003266 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
3267 pdata->num_retune_mobile_cfgs);
3268
3269 if (pdata->num_retune_mobile_cfgs)
3270 wm8994_handle_retune_mobile_pdata(wm8994);
3271 else
Mark Brown8cb8e832012-07-25 18:10:03 +01003272 snd_soc_add_codec_controls(wm8994->hubs.codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00003273 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08003274
3275 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3276 if (pdata->micbias[i]) {
3277 snd_soc_write(codec, WM8958_MICBIAS1 + i,
3278 pdata->micbias[i] & 0xffff);
3279 }
3280 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003281}
3282
Mark Brown88766982010-03-29 20:57:12 +01003283/**
3284 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3285 *
3286 * @codec: WM8994 codec
3287 * @jack: jack to report detection events on
3288 * @micbias: microphone bias to detect on
Mark Brown88766982010-03-29 20:57:12 +01003289 *
3290 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3291 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01003292 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01003293 * be configured using snd_soc_jack_add_gpios() instead.
3294 *
3295 * Configuration of detection levels is available via the micbias1_lvl
3296 * and micbias2_lvl platform data members.
3297 */
3298int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +00003299 int micbias)
Mark Brown88766982010-03-29 20:57:12 +01003300{
Mark Brownb2c812e2010-04-14 15:35:19 +09003301 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01003302 struct wm8994_micdet *micdet;
Mark Brown2a8a8562011-07-24 12:20:41 +01003303 struct wm8994 *control = wm8994->wm8994;
Mark Brown87092e32012-02-06 18:50:39 +00003304 int reg, ret;
Mark Brown88766982010-03-29 20:57:12 +01003305
Mark Brown87092e32012-02-06 18:50:39 +00003306 if (control->type != WM8994) {
3307 dev_warn(codec->dev, "Not a WM8994\n");
Mark Brown3a423152010-11-26 15:21:06 +00003308 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003309 }
Mark Brown3a423152010-11-26 15:21:06 +00003310
Mark Brown88766982010-03-29 20:57:12 +01003311 switch (micbias) {
3312 case 1:
3313 micdet = &wm8994->micdet[0];
Mark Brown87092e32012-02-06 18:50:39 +00003314 if (jack)
3315 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3316 "MICBIAS1");
3317 else
3318 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3319 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003320 break;
3321 case 2:
3322 micdet = &wm8994->micdet[1];
Mark Brown87092e32012-02-06 18:50:39 +00003323 if (jack)
3324 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3325 "MICBIAS1");
3326 else
3327 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3328 "MICBIAS1");
Mark Brown88766982010-03-29 20:57:12 +01003329 break;
3330 default:
Mark Brown87092e32012-02-06 18:50:39 +00003331 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
Mark Brown88766982010-03-29 20:57:12 +01003332 return -EINVAL;
Mark Brown87092e32012-02-06 18:50:39 +00003333 }
Mark Brown88766982010-03-29 20:57:12 +01003334
Mark Brown87092e32012-02-06 18:50:39 +00003335 if (ret != 0)
3336 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3337 micbias, ret);
3338
3339 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3340 micbias, jack);
Mark Brown88766982010-03-29 20:57:12 +01003341
3342 /* Store the configuration */
3343 micdet->jack = jack;
Mark Brown87092e32012-02-06 18:50:39 +00003344 micdet->detecting = true;
Mark Brown88766982010-03-29 20:57:12 +01003345
3346 /* If either of the jacks is set up then enable detection */
3347 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3348 reg = WM8994_MICD_ENA;
Mark Brown87092e32012-02-06 18:50:39 +00003349 else
Mark Brown88766982010-03-29 20:57:12 +01003350 reg = 0;
3351
3352 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3353
Chris Rattrayd9f34df2012-07-31 14:51:34 +01003354 /* enable MICDET and MICSHRT deboune */
3355 snd_soc_update_bits(codec, WM8994_IRQ_DEBOUNCE,
3356 WM8994_MIC1_DET_DB_MASK | WM8994_MIC1_SHRT_DB_MASK |
3357 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK,
3358 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB);
3359
Mark Brown87092e32012-02-06 18:50:39 +00003360 snd_soc_dapm_sync(&codec->dapm);
3361
Mark Brown88766982010-03-29 20:57:12 +01003362 return 0;
3363}
3364EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3365
Mark Browne9b54de42012-05-09 19:20:59 +01003366static void wm8994_mic_work(struct work_struct *work)
Mark Brown88766982010-03-29 20:57:12 +01003367{
Mark Browne9b54de42012-05-09 19:20:59 +01003368 struct wm8994_priv *priv = container_of(work,
3369 struct wm8994_priv,
3370 mic_work.work);
Mark Brownfdfc4f32012-05-09 19:24:39 +01003371 struct regmap *regmap = priv->wm8994->regmap;
3372 struct device *dev = priv->wm8994->dev;
3373 unsigned int reg;
3374 int ret;
Mark Brown88766982010-03-29 20:57:12 +01003375 int report;
3376
Mark Brownb8176622012-07-24 15:48:57 +01003377 pm_runtime_get_sync(dev);
3378
Mark Brownfdfc4f32012-05-09 19:24:39 +01003379 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, &reg);
3380 if (ret < 0) {
3381 dev_err(dev, "Failed to read microphone status: %d\n",
3382 ret);
Mark Brownb8176622012-07-24 15:48:57 +01003383 pm_runtime_put(dev);
Mark Browne9b54de42012-05-09 19:20:59 +01003384 return;
Mark Brown88766982010-03-29 20:57:12 +01003385 }
3386
Mark Brownfdfc4f32012-05-09 19:24:39 +01003387 dev_dbg(dev, "Microphone status: %x\n", reg);
Mark Brown88766982010-03-29 20:57:12 +01003388
3389 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003390 if (reg & WM8994_MIC1_DET_STS) {
3391 if (priv->micdet[0].detecting)
3392 report = SND_JACK_HEADSET;
3393 }
3394 if (reg & WM8994_MIC1_SHRT_STS) {
3395 if (priv->micdet[0].detecting)
3396 report = SND_JACK_HEADPHONE;
3397 else
3398 report |= SND_JACK_BTN_0;
3399 }
3400 if (report)
3401 priv->micdet[0].detecting = false;
3402 else
3403 priv->micdet[0].detecting = true;
3404
Mark Brown88766982010-03-29 20:57:12 +01003405 snd_soc_jack_report(priv->micdet[0].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003406 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brown88766982010-03-29 20:57:12 +01003407
3408 report = 0;
Mark Brown87092e32012-02-06 18:50:39 +00003409 if (reg & WM8994_MIC2_DET_STS) {
3410 if (priv->micdet[1].detecting)
3411 report = SND_JACK_HEADSET;
3412 }
3413 if (reg & WM8994_MIC2_SHRT_STS) {
3414 if (priv->micdet[1].detecting)
3415 report = SND_JACK_HEADPHONE;
3416 else
3417 report |= SND_JACK_BTN_0;
3418 }
3419 if (report)
3420 priv->micdet[1].detecting = false;
3421 else
3422 priv->micdet[1].detecting = true;
3423
Mark Brown88766982010-03-29 20:57:12 +01003424 snd_soc_jack_report(priv->micdet[1].jack, report,
Mark Brown87092e32012-02-06 18:50:39 +00003425 SND_JACK_HEADSET | SND_JACK_BTN_0);
Mark Brownb8176622012-07-24 15:48:57 +01003426
3427 pm_runtime_put(dev);
Mark Browne9b54de42012-05-09 19:20:59 +01003428}
3429
3430static irqreturn_t wm8994_mic_irq(int irq, void *data)
3431{
3432 struct wm8994_priv *priv = data;
Mark Brown8cb8e832012-07-25 18:10:03 +01003433 struct snd_soc_codec *codec = priv->hubs.codec;
Mark Browne9b54de42012-05-09 19:20:59 +01003434
3435#ifndef CONFIG_SND_SOC_WM8994_MODULE
3436 trace_snd_soc_jack_irq(dev_name(codec->dev));
3437#endif
3438
3439 pm_wakeup_event(codec->dev, 300);
3440
3441 schedule_delayed_work(&priv->mic_work, msecs_to_jiffies(250));
Mark Brown88766982010-03-29 20:57:12 +01003442
3443 return IRQ_HANDLED;
3444}
3445
Mark Brownf02b0de2012-10-01 16:41:09 +01003446static void wm1811_micd_stop(struct snd_soc_codec *codec)
Mark Brown821edd22010-11-26 15:21:09 +00003447{
Mark Brownf02b0de2012-10-01 16:41:09 +01003448 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3449
3450 if (!wm8994->jackdet)
3451 return;
3452
3453 mutex_lock(&wm8994->accdet_lock);
3454
3455 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, WM8958_MICD_ENA, 0);
3456
3457 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3458
3459 mutex_unlock(&wm8994->accdet_lock);
3460
3461 if (wm8994->wm8994->pdata.jd_ext_cap)
3462 snd_soc_dapm_disable_pin(&codec->dapm,
3463 "MICBIAS2");
3464}
3465
Mark Brown78b76db2012-11-22 17:02:09 +09003466static void wm8958_button_det(struct snd_soc_codec *codec, u16 status)
Mark Brown821edd22010-11-26 15:21:09 +00003467{
Mark Brown821edd22010-11-26 15:21:09 +00003468 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4585790d2011-11-30 10:55:14 +00003469 int report;
Mark Brown821edd22010-11-26 15:21:09 +00003470
Mark Brown78b76db2012-11-22 17:02:09 +09003471 report = 0;
3472 if (status & 0x4)
3473 report |= SND_JACK_BTN_0;
3474
3475 if (status & 0x8)
3476 report |= SND_JACK_BTN_1;
3477
3478 if (status & 0x10)
3479 report |= SND_JACK_BTN_2;
3480
3481 if (status & 0x20)
3482 report |= SND_JACK_BTN_3;
3483
3484 if (status & 0x40)
3485 report |= SND_JACK_BTN_4;
3486
3487 if (status & 0x80)
3488 report |= SND_JACK_BTN_5;
3489
3490 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3491 wm8994->btn_mask);
3492}
3493
Mark Brown98869f62012-12-03 16:14:37 +09003494static void wm8958_mic_id(void *data, u16 status)
Mark Brown78b76db2012-11-22 17:02:09 +09003495{
Mark Brown98869f62012-12-03 16:14:37 +09003496 struct snd_soc_codec *codec = data;
Mark Brown78b76db2012-11-22 17:02:09 +09003497 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Browna1691342011-11-30 14:56:40 +00003498
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003499 /* Either nothing present or just starting detection */
Mark Brownb00adf72011-08-13 11:57:18 +09003500 if (!(status & WM8958_MICD_STS)) {
Mark Brownf02b0de2012-10-01 16:41:09 +01003501 /* If nothing present then clear our statuses */
3502 dev_dbg(codec->dev, "Detected open circuit\n");
3503 wm8994->jack_mic = false;
3504 wm8994->mic_detecting = true;
Mark Brown821edd22010-11-26 15:21:09 +00003505
Mark Brownf02b0de2012-10-01 16:41:09 +01003506 wm1811_micd_stop(codec);
Mark Brown821edd22010-11-26 15:21:09 +00003507
Mark Brownf02b0de2012-10-01 16:41:09 +01003508 wm8958_micd_set_rate(codec);
3509
3510 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3511 wm8994->btn_mask |
3512 SND_JACK_HEADSET);
Mark Brownb00adf72011-08-13 11:57:18 +09003513 return;
3514 }
3515
3516 /* If the measurement is showing a high impedence we've got a
3517 * microphone.
3518 */
Mark Brown78b76db2012-11-22 17:02:09 +09003519 if (status & 0x600) {
Mark Brownb00adf72011-08-13 11:57:18 +09003520 dev_dbg(codec->dev, "Detected microphone\n");
3521
Mark Brown157a75e2011-11-30 13:43:51 +00003522 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003523 wm8994->jack_mic = true;
3524
3525 wm8958_micd_set_rate(codec);
3526
3527 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3528 SND_JACK_HEADSET);
3529 }
3530
3531
Mark Brown78b76db2012-11-22 17:02:09 +09003532 if (status & 0xfc) {
Mark Brownb00adf72011-08-13 11:57:18 +09003533 dev_dbg(codec->dev, "Detected headphone\n");
Mark Brown157a75e2011-11-30 13:43:51 +00003534 wm8994->mic_detecting = false;
Mark Brownb00adf72011-08-13 11:57:18 +09003535
3536 wm8958_micd_set_rate(codec);
3537
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003538 /* If we have jackdet that will detect removal */
Mark Brownf02b0de2012-10-01 16:41:09 +01003539 wm1811_micd_stop(codec);
Mark Brownecd17322012-03-12 16:34:35 +00003540
3541 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3542 SND_JACK_HEADSET);
Mark Brownb00adf72011-08-13 11:57:18 +09003543 }
Mark Brown821edd22010-11-26 15:21:09 +00003544}
Mark Brown9e6e96a2010-01-29 17:47:12 +00003545
Mark Brownc0cc3f12012-09-28 16:50:15 +01003546/* Deferred mic detection to allow for extra settling time */
3547static void wm1811_mic_work(struct work_struct *work)
3548{
3549 struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
3550 mic_work.work);
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003551 struct wm8994 *control = wm8994->wm8994;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003552 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brown821edd22010-11-26 15:21:09 +00003553
Mark Brownc0cc3f12012-09-28 16:50:15 +01003554 pm_runtime_get_sync(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003555
Mark Brownc0cc3f12012-09-28 16:50:15 +01003556 /* If required for an external cap force MICBIAS on */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003557 if (control->pdata.jd_ext_cap) {
Mark Brownc0cc3f12012-09-28 16:50:15 +01003558 snd_soc_dapm_force_enable_pin(&codec->dapm,
3559 "MICBIAS2");
3560 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003561 }
Mark Brownc0cc3f12012-09-28 16:50:15 +01003562
3563 mutex_lock(&wm8994->accdet_lock);
3564
3565 dev_dbg(codec->dev, "Starting mic detection\n");
3566
Mark Brown63dd5452012-11-22 20:44:32 +09003567 /* Use a user-supplied callback if we have one */
3568 if (wm8994->micd_cb) {
3569 wm8994->micd_cb(wm8994->micd_cb_data);
3570 } else {
3571 /*
3572 * Start off measument of microphone impedence to find out
3573 * what's actually there.
3574 */
3575 wm8994->mic_detecting = true;
3576 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
Mark Brownc0cc3f12012-09-28 16:50:15 +01003577
Mark Brown63dd5452012-11-22 20:44:32 +09003578 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3579 WM8958_MICD_ENA, WM8958_MICD_ENA);
3580 }
Mark Brownc0cc3f12012-09-28 16:50:15 +01003581
3582 mutex_unlock(&wm8994->accdet_lock);
3583
3584 pm_runtime_put(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003585}
3586
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003587static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3588{
3589 struct wm8994_priv *wm8994 = data;
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003590 struct wm8994 *control = wm8994->wm8994;
Mark Brown8cb8e832012-07-25 18:10:03 +01003591 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003592 int reg, delay;
Mark Brownc9865642012-03-12 16:31:50 +00003593 bool present;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003594
Mark Brownb8176622012-07-24 15:48:57 +01003595 pm_runtime_get_sync(codec->dev);
3596
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003597 mutex_lock(&wm8994->accdet_lock);
3598
3599 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3600 if (reg < 0) {
3601 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3602 mutex_unlock(&wm8994->accdet_lock);
Mark Brownb8176622012-07-24 15:48:57 +01003603 pm_runtime_put(codec->dev);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003604 return IRQ_NONE;
3605 }
3606
3607 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3608
Mark Brownc9865642012-03-12 16:31:50 +00003609 present = reg & WM1811_JACKDET_LVL;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003610
Mark Brownc9865642012-03-12 16:31:50 +00003611 if (present) {
3612 dev_dbg(codec->dev, "Jack detected\n");
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003613
Mark Browne9d9a962012-04-26 16:07:32 +01003614 wm8958_micd_set_rate(codec);
3615
Mark Brown55a27782012-02-21 13:45:53 +00003616 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3617 WM8958_MICB2_DISCH, 0);
3618
Mark Brown378ec0c2012-03-01 19:01:43 +00003619 /* Disable debounce while inserted */
3620 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3621 WM1811_JACKDET_DB, 0);
3622
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003623 delay = control->pdata.micdet_delay;
Mark Brownc0cc3f12012-09-28 16:50:15 +01003624 schedule_delayed_work(&wm8994->mic_work,
3625 msecs_to_jiffies(delay));
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003626 } else {
3627 dev_dbg(codec->dev, "Jack not detected\n");
3628
Mark Brownc0cc3f12012-09-28 16:50:15 +01003629 cancel_delayed_work_sync(&wm8994->mic_work);
3630
Mark Brown55a27782012-02-21 13:45:53 +00003631 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3632 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3633
Mark Brown378ec0c2012-03-01 19:01:43 +00003634 /* Enable debounce while removed */
3635 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3636 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3637
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003638 wm8994->mic_detecting = false;
3639 wm8994->jack_mic = false;
3640 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3641 WM8958_MICD_ENA, 0);
3642 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3643 }
3644
3645 mutex_unlock(&wm8994->accdet_lock);
3646
Mark Brownc0cc3f12012-09-28 16:50:15 +01003647 /* Turn off MICBIAS if it was on for an external cap */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003648 if (control->pdata.jd_ext_cap && !present)
Mark Brownc0cc3f12012-09-28 16:50:15 +01003649 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
Mark Brownc9865642012-03-12 16:31:50 +00003650
3651 if (present)
3652 snd_soc_jack_report(wm8994->micdet[0].jack,
3653 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3654 else
3655 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3656 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3657 wm8994->btn_mask);
3658
Mark Brown99af79d2012-07-25 23:03:36 +01003659 /* Since we only report deltas force an update, ensures we
3660 * avoid bootstrapping issues with the core. */
3661 snd_soc_jack_report(wm8994->micdet[0].jack, 0, 0);
3662
Mark Brownb8176622012-07-24 15:48:57 +01003663 pm_runtime_put(codec->dev);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003664 return IRQ_HANDLED;
3665}
3666
Mark Brown99af79d2012-07-25 23:03:36 +01003667static void wm1811_jackdet_bootstrap(struct work_struct *work)
3668{
3669 struct wm8994_priv *wm8994 = container_of(work,
3670 struct wm8994_priv,
3671 jackdet_bootstrap.work);
3672 wm1811_jackdet_irq(0, wm8994);
3673}
3674
Mark Brown821edd22010-11-26 15:21:09 +00003675/**
3676 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3677 *
3678 * @codec: WM8958 codec
3679 * @jack: jack to report detection events on
3680 *
3681 * Enable microphone detection functionality for the WM8958. By
3682 * default simple detection which supports the detection of up to 6
3683 * buttons plus video and microphone functionality is supported.
3684 *
3685 * The WM8958 has an advanced jack detection facility which is able to
3686 * support complex accessory detection, especially when used in
3687 * conjunction with external circuitry. In order to provide maximum
3688 * flexiblity a callback is provided which allows a completely custom
3689 * detection algorithm.
3690 */
3691int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
Mark Brown98869f62012-12-03 16:14:37 +09003692 wm1811_micdet_cb det_cb, void *det_cb_data,
3693 wm1811_mic_id_cb id_cb, void *id_cb_data)
Mark Brown821edd22010-11-26 15:21:09 +00003694{
3695 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003696 struct wm8994 *control = wm8994->wm8994;
Mark Brown4585790d2011-11-30 10:55:14 +00003697 u16 micd_lvl_sel;
Mark Brown821edd22010-11-26 15:21:09 +00003698
Mark Brown81204c82011-05-24 17:35:53 +08003699 switch (control->type) {
3700 case WM1811:
3701 case WM8958:
3702 break;
3703 default:
Mark Brown821edd22010-11-26 15:21:09 +00003704 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003705 }
Mark Brown821edd22010-11-26 15:21:09 +00003706
3707 if (jack) {
Mark Brown4cdf5e42011-11-29 14:36:17 +00003708 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003709 snd_soc_dapm_sync(&codec->dapm);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003710
Mark Brown821edd22010-11-26 15:21:09 +00003711 wm8994->micdet[0].jack = jack;
Mark Brown821edd22010-11-26 15:21:09 +00003712
Mark Brown98869f62012-12-03 16:14:37 +09003713 if (det_cb) {
3714 wm8994->micd_cb = det_cb;
3715 wm8994->micd_cb_data = det_cb_data;
Mark Brown63dd5452012-11-22 20:44:32 +09003716 } else {
3717 wm8994->mic_detecting = true;
3718 wm8994->jack_mic = false;
3719 }
Mark Brownb00adf72011-08-13 11:57:18 +09003720
Mark Brown98869f62012-12-03 16:14:37 +09003721 if (id_cb) {
3722 wm8994->mic_id_cb = id_cb;
3723 wm8994->mic_id_cb_data = id_cb_data;
3724 } else {
3725 wm8994->mic_id_cb = wm8958_mic_id;
3726 wm8994->mic_id_cb_data = codec;
3727 }
Mark Brownb00adf72011-08-13 11:57:18 +09003728
3729 wm8958_micd_set_rate(codec);
3730
Mark Brown4585790d2011-11-30 10:55:14 +00003731 /* Detect microphones and short circuits by default */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003732 if (control->pdata.micd_lvl_sel)
3733 micd_lvl_sel = control->pdata.micd_lvl_sel;
Mark Brown4585790d2011-11-30 10:55:14 +00003734 else
3735 micd_lvl_sel = 0x41;
3736
3737 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3738 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3739 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3740
Mark Brownb00adf72011-08-13 11:57:18 +09003741 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
Mark Brown4585790d2011-11-30 10:55:14 +00003742 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
Mark Brownb00adf72011-08-13 11:57:18 +09003743
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003744 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3745
3746 /*
3747 * If we can use jack detection start off with that,
3748 * otherwise jump straight to microphone detection.
3749 */
3750 if (wm8994->jackdet) {
Mark Brown99af79d2012-07-25 23:03:36 +01003751 /* Disable debounce for the initial detect */
3752 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3753 WM1811_JACKDET_DB, 0);
3754
Mark Brown55a27782012-02-21 13:45:53 +00003755 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3756 WM8958_MICB2_DISCH,
3757 WM8958_MICB2_DISCH);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003758 snd_soc_update_bits(codec, WM8994_LDO_1,
3759 WM8994_LDO1_DISCH, 0);
3760 wm1811_jackdet_set_mode(codec,
3761 WM1811_JACKDET_MODE_JACK);
3762 } else {
3763 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3764 WM8958_MICD_ENA, WM8958_MICD_ENA);
3765 }
3766
Mark Brown821edd22010-11-26 15:21:09 +00003767 } else {
3768 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3769 WM8958_MICD_ENA, 0);
Mark Brownafaf1592012-03-03 18:46:36 +00003770 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003771 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown7d464b22012-03-03 18:46:06 +00003772 snd_soc_dapm_sync(&codec->dapm);
Mark Brown821edd22010-11-26 15:21:09 +00003773 }
3774
3775 return 0;
3776}
3777EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3778
3779static irqreturn_t wm8958_mic_irq(int irq, void *data)
3780{
3781 struct wm8994_priv *wm8994 = data;
Mark Brown8cb8e832012-07-25 18:10:03 +01003782 struct snd_soc_codec *codec = wm8994->hubs.codec;
Mark Brown8afd0ef2012-12-07 17:10:05 +09003783 int reg, count, ret;
Mark Brown821edd22010-11-26 15:21:09 +00003784
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003785 /*
3786 * Jack detection may have detected a removal simulataneously
3787 * with an update of the MICDET status; if so it will have
3788 * stopped detection and we can ignore this interrupt.
3789 */
Mark Brownc9865642012-03-12 16:31:50 +00003790 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003791 return IRQ_HANDLED;
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003792
Mark Brownb8176622012-07-24 15:48:57 +01003793 pm_runtime_get_sync(codec->dev);
3794
Mark Brown19940b32011-08-19 18:05:05 +09003795 /* We may occasionally read a detection without an impedence
3796 * range being provided - if that happens loop again.
3797 */
3798 count = 10;
3799 do {
3800 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3801 if (reg < 0) {
3802 dev_err(codec->dev,
3803 "Failed to read mic detect status: %d\n",
3804 reg);
Mark Brownb8176622012-07-24 15:48:57 +01003805 pm_runtime_put(codec->dev);
Mark Brown19940b32011-08-19 18:05:05 +09003806 return IRQ_NONE;
3807 }
Mark Brown821edd22010-11-26 15:21:09 +00003808
Mark Brown19940b32011-08-19 18:05:05 +09003809 if (!(reg & WM8958_MICD_VALID)) {
3810 dev_dbg(codec->dev, "Mic detect data not valid\n");
3811 goto out;
3812 }
3813
3814 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3815 break;
3816
3817 msleep(1);
3818 } while (count--);
3819
3820 if (count == 0)
Masanari Iidaec8f53f2012-11-02 00:28:50 +09003821 dev_warn(codec->dev, "No impedance range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003822
Mark Brown7116f452010-12-29 13:05:21 +00003823#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003824 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003825#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003826
Mark Browne874de42012-12-03 15:58:55 +09003827 /* Avoid a transient report when the accessory is being removed */
3828 if (wm8994->jackdet) {
Mark Brown8afd0ef2012-12-07 17:10:05 +09003829 ret = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3830 if (ret < 0) {
Mark Browne874de42012-12-03 15:58:55 +09003831 dev_err(codec->dev, "Failed to read jack status: %d\n",
Mark Brown8afd0ef2012-12-07 17:10:05 +09003832 ret);
3833 } else if (!(ret & WM1811_JACKDET_LVL)) {
Mark Browne874de42012-12-03 15:58:55 +09003834 dev_dbg(codec->dev, "Ignoring removed jack\n");
Mark Brown9e430882013-05-29 18:38:46 +01003835 goto out;
Mark Browne874de42012-12-03 15:58:55 +09003836 }
Mark Brown9767a582013-05-28 12:52:08 +01003837 } else if (!(reg & WM8958_MICD_STS)) {
3838 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3839 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3840 wm8994->btn_mask);
Mark Brown7afce3f2013-05-30 13:42:27 +01003841 wm8994->mic_detecting = true;
Mark Brown9767a582013-05-28 12:52:08 +01003842 goto out;
Mark Browne874de42012-12-03 15:58:55 +09003843 }
3844
Mark Brown78b76db2012-11-22 17:02:09 +09003845 if (wm8994->mic_detecting)
Mark Brown98869f62012-12-03 16:14:37 +09003846 wm8994->mic_id_cb(wm8994->mic_id_cb_data, reg);
Mark Brown821edd22010-11-26 15:21:09 +00003847 else
Mark Brown78b76db2012-11-22 17:02:09 +09003848 wm8958_button_det(codec, reg);
Mark Brown821edd22010-11-26 15:21:09 +00003849
3850out:
Mark Brownb8176622012-07-24 15:48:57 +01003851 pm_runtime_put(codec->dev);
Mark Brown821edd22010-11-26 15:21:09 +00003852 return IRQ_HANDLED;
3853}
3854
Mark Brown3b1af3f2011-07-14 12:38:18 +09003855static irqreturn_t wm8994_fifo_error(int irq, void *data)
3856{
3857 struct snd_soc_codec *codec = data;
3858
3859 dev_err(codec->dev, "FIFO error\n");
3860
3861 return IRQ_HANDLED;
3862}
3863
Mark Brownf0b182b2011-08-16 12:01:27 +09003864static irqreturn_t wm8994_temp_warn(int irq, void *data)
3865{
3866 struct snd_soc_codec *codec = data;
3867
3868 dev_err(codec->dev, "Thermal warning\n");
3869
3870 return IRQ_HANDLED;
3871}
3872
3873static irqreturn_t wm8994_temp_shut(int irq, void *data)
3874{
3875 struct snd_soc_codec *codec = data;
3876
3877 dev_crit(codec->dev, "Thermal shutdown\n");
3878
3879 return IRQ_HANDLED;
3880}
3881
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003882static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003883{
Mark Brownd9a76662011-07-24 12:49:52 +01003884 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00003885 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003886 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownd9a76662011-07-24 12:49:52 +01003887 unsigned int reg;
Mark Brownec62dbd2010-08-15 14:56:40 +01003888 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003889
Mark Brown8cb8e832012-07-25 18:10:03 +01003890 wm8994->hubs.codec = codec;
Mark Brownd9a76662011-07-24 12:49:52 +01003891 codec->control_data = control->regmap;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003892
Mark Brownd9a76662011-07-24 12:49:52 +01003893 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
Mark Brown2a8a8562011-07-24 12:20:41 +01003894
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003895 mutex_init(&wm8994->accdet_lock);
Mark Brown99af79d2012-07-25 23:03:36 +01003896 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
3897 wm1811_jackdet_bootstrap);
Mark Brownaf6b6fe2011-11-30 20:32:05 +00003898
Mark Brownc0cc3f12012-09-28 16:50:15 +01003899 switch (control->type) {
3900 case WM8994:
3901 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
3902 break;
3903 case WM1811:
3904 INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
3905 break;
3906 default:
3907 break;
3908 }
3909
Mark Brownc7ebf932011-07-12 19:47:59 +09003910 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3911 init_completion(&wm8994->fll_locked[i]);
3912
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003913 wm8994->micdet_irq = control->pdata.micdet_irq;
Mark Brown9b7c5252011-02-17 20:05:44 -08003914
Mark Brown39fb51a2010-11-26 17:23:43 +00003915 pm_runtime_enable(codec->dev);
Mark Brown5fab51742012-02-06 18:37:08 +00003916 pm_runtime_idle(codec->dev);
Mark Brown39fb51a2010-11-26 17:23:43 +00003917
Mark Brownf959dee2012-01-31 16:16:47 +00003918 /* By default use idle_bias_off, will override for WM8994 */
3919 codec->dapm.idle_bias_off = 1;
3920
Mark Brown9e6e96a2010-01-29 17:47:12 +00003921 /* Set revision-specific configuration */
Mark Brown3a423152010-11-26 15:21:06 +00003922 switch (control->type) {
3923 case WM8994:
Mark Brownf959dee2012-01-31 16:16:47 +00003924 /* Single ended line outputs should have VMID on. */
Mark Brownd9dd4ad2012-10-08 18:36:09 +09003925 if (!control->pdata.lineout1_diff ||
3926 !control->pdata.lineout2_diff)
Mark Brownf959dee2012-01-31 16:16:47 +00003927 codec->dapm.idle_bias_off = 0;
3928
Mark Brownda445afe2013-03-12 17:46:09 +00003929 switch (control->revision) {
Mark Brown3a423152010-11-26 15:21:06 +00003930 case 2:
3931 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003932 wm8994->hubs.dcs_codes_l = -5;
3933 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003934 wm8994->hubs.hp_startup_mode = 1;
3935 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003936 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003937 break;
3938 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003939 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003940 break;
3941 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003942 break;
Mark Brown3a423152010-11-26 15:21:06 +00003943
3944 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003945 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003946 wm8994->hubs.hp_startup_mode = 1;
Mark Brown20dc24a2012-04-05 12:55:20 +01003947
Mark Brownda445afe2013-03-12 17:46:09 +00003948 switch (control->revision) {
Mark Brown20dc24a2012-04-05 12:55:20 +01003949 case 0:
3950 break;
3951 default:
3952 wm8994->fll_byp = true;
3953 break;
3954 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003955 break;
Mark Brown3a423152010-11-26 15:21:06 +00003956
Mark Brown81204c82011-05-24 17:35:53 +08003957 case WM1811:
3958 wm8994->hubs.dcs_readback_mode = 2;
3959 wm8994->hubs.no_series_update = 1;
Mark Brown29fdc362012-02-21 10:50:50 +00003960 wm8994->hubs.hp_startup_mode = 1;
Mark Brownaf31a222012-04-26 20:06:56 +01003961 wm8994->hubs.no_cache_dac_hp_direct = true;
Mark Brown20dc24a2012-04-05 12:55:20 +01003962 wm8994->fll_byp = true;
Mark Brown81204c82011-05-24 17:35:53 +08003963
Mark Brown72222be32012-11-28 13:46:56 +00003964 wm8994->hubs.dcs_codes_l = -9;
3965 wm8994->hubs.dcs_codes_r = -7;
Mark Brown81204c82011-05-24 17:35:53 +08003966
3967 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3968 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3969 break;
3970
Mark Brown9e6e96a2010-01-29 17:47:12 +00003971 default:
3972 break;
3973 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003974
Mark Brown2a8a8562011-07-24 12:20:41 +01003975 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
Mark Brown3b1af3f2011-07-14 12:38:18 +09003976 wm8994_fifo_error, "FIFO error", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003977 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003978 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01003979 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003980 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003981
Mark Brown2a8a8562011-07-24 12:20:41 +01003982 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09003983 wm_hubs_dcs_done, "DC servo done",
3984 &wm8994->hubs);
3985 if (ret == 0)
3986 wm8994->hubs.dcs_done_irq = true;
3987
Mark Brown3a423152010-11-26 15:21:06 +00003988 switch (control->type) {
3989 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003990 if (wm8994->micdet_irq) {
3991 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3992 wm8994_mic_irq,
3993 IRQF_TRIGGER_RISING,
3994 "Mic1 detect",
3995 wm8994);
3996 if (ret != 0)
3997 dev_warn(codec->dev,
3998 "Failed to request Mic1 detect IRQ: %d\n",
3999 ret);
4000 }
Mark Brown88766982010-03-29 20:57:12 +01004001
Mark Brown2a8a8562011-07-24 12:20:41 +01004002 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004003 WM8994_IRQ_MIC1_SHRT,
4004 wm8994_mic_irq, "Mic 1 short",
4005 wm8994);
4006 if (ret != 0)
4007 dev_warn(codec->dev,
4008 "Failed to request Mic1 short IRQ: %d\n",
4009 ret);
Mark Brown88766982010-03-29 20:57:12 +01004010
Mark Brown2a8a8562011-07-24 12:20:41 +01004011 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004012 WM8994_IRQ_MIC2_DET,
4013 wm8994_mic_irq, "Mic 2 detect",
4014 wm8994);
4015 if (ret != 0)
4016 dev_warn(codec->dev,
4017 "Failed to request Mic2 detect IRQ: %d\n",
4018 ret);
Mark Brown88766982010-03-29 20:57:12 +01004019
Mark Brown2a8a8562011-07-24 12:20:41 +01004020 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brown3a423152010-11-26 15:21:06 +00004021 WM8994_IRQ_MIC2_SHRT,
4022 wm8994_mic_irq, "Mic 2 short",
4023 wm8994);
4024 if (ret != 0)
4025 dev_warn(codec->dev,
4026 "Failed to request Mic2 short IRQ: %d\n",
4027 ret);
4028 break;
Mark Brown821edd22010-11-26 15:21:09 +00004029
4030 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08004031 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08004032 if (wm8994->micdet_irq) {
4033 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4034 wm8958_mic_irq,
4035 IRQF_TRIGGER_RISING,
4036 "Mic detect",
4037 wm8994);
4038 if (ret != 0)
4039 dev_warn(codec->dev,
4040 "Failed to request Mic detect IRQ: %d\n",
4041 ret);
Mark Brownb4046d02012-07-18 19:11:30 +01004042 } else {
4043 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4044 wm8958_mic_irq, "Mic detect",
4045 wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08004046 }
Mark Brown3a423152010-11-26 15:21:06 +00004047 }
Mark Brown88766982010-03-29 20:57:12 +01004048
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004049 switch (control->type) {
4050 case WM1811:
Mark Brownda445afe2013-03-12 17:46:09 +00004051 if (control->cust_id > 1 || control->revision > 1) {
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004052 ret = wm8994_request_irq(wm8994->wm8994,
4053 WM8994_IRQ_GPIO(6),
4054 wm1811_jackdet_irq, "JACKDET",
4055 wm8994);
4056 if (ret == 0)
4057 wm8994->jackdet = true;
4058 }
4059 break;
4060 default:
4061 break;
4062 }
4063
Mark Brownc7ebf932011-07-12 19:47:59 +09004064 wm8994->fll_locked_irq = true;
4065 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
Mark Brown2a8a8562011-07-24 12:20:41 +01004066 ret = wm8994_request_irq(wm8994->wm8994,
Mark Brownc7ebf932011-07-12 19:47:59 +09004067 WM8994_IRQ_FLL1_LOCK + i,
4068 wm8994_fll_locked_irq, "FLL lock",
4069 &wm8994->fll_locked[i]);
4070 if (ret != 0)
4071 wm8994->fll_locked_irq = false;
4072 }
4073
Mark Brown27060b3c2012-02-06 18:42:14 +00004074 /* Make sure we can read from the GPIOs if they're inputs */
4075 pm_runtime_get_sync(codec->dev);
4076
Mark Brown9e6e96a2010-01-29 17:47:12 +00004077 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
4078 * configured on init - if a system wants to do this dynamically
4079 * at runtime we can deal with that then.
4080 */
Mark Brownd9a76662011-07-24 12:49:52 +01004081 ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004082 if (ret < 0) {
4083 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01004084 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004085 }
Mark Brownd9a76662011-07-24 12:49:52 +01004086 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00004087 wm8994->lrclk_shared[0] = 1;
4088 wm8994_dai[0].symmetric_rates = 1;
4089 } else {
4090 wm8994->lrclk_shared[0] = 0;
4091 }
4092
Mark Brownd9a76662011-07-24 12:49:52 +01004093 ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004094 if (ret < 0) {
4095 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01004096 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004097 }
Mark Brownd9a76662011-07-24 12:49:52 +01004098 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00004099 wm8994->lrclk_shared[1] = 1;
4100 wm8994_dai[1].symmetric_rates = 1;
4101 } else {
4102 wm8994->lrclk_shared[1] = 0;
4103 }
4104
Mark Brown27060b3c2012-02-06 18:42:14 +00004105 pm_runtime_put(codec->dev);
4106
Mark Brownbfd37bb2012-06-05 12:31:32 +01004107 /* Latch volume update bits */
4108 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
4109 snd_soc_update_bits(codec, wm8994_vu_bits[i].reg,
4110 wm8994_vu_bits[i].mask,
4111 wm8994_vu_bits[i].mask);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004112
4113 /* Set the low bit of the 3D stereo depth so TLV matches */
4114 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
4115 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
4116 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
4117 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
4118 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
4119 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
4120 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
4121 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
4122 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
4123
Mark Brown5b739672011-07-06 00:08:43 -07004124 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
4125 * use this; it only affects behaviour on idle TDM clock
4126 * cycles. */
4127 switch (control->type) {
4128 case WM8994:
4129 case WM8958:
4130 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
4131 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
4132 break;
4133 default:
4134 break;
4135 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01004136
Mark Brown500fa302011-11-29 19:58:19 +00004137 /* Put MICBIAS into bypass mode by default on newer devices */
4138 switch (control->type) {
4139 case WM8958:
4140 case WM1811:
4141 snd_soc_update_bits(codec, WM8958_MICBIAS1,
4142 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
4143 snd_soc_update_bits(codec, WM8958_MICBIAS2,
4144 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
4145 break;
4146 default:
4147 break;
4148 }
4149
Mark Brownc3403042012-04-26 21:29:29 +01004150 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
4151 wm_hubs_update_class_w(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004152
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004153 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004154
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004155 wm_hubs_add_analogue_controls(codec);
Liam Girdwood022658b2012-02-03 17:43:09 +00004156 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004157 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004158 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004159 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00004160
4161 switch (control->type) {
4162 case WM8994:
4163 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
4164 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Mark Brownda445afe2013-03-12 17:46:09 +00004165 if (control->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004166 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4167 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004168 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4169 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004170 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4171 ARRAY_SIZE(wm8994_dac_revd_widgets));
4172 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004173 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4174 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00004175 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4176 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00004177 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4178 ARRAY_SIZE(wm8994_dac_widgets));
4179 }
Mark Brownc4431df2010-11-26 15:21:07 +00004180 break;
4181 case WM8958:
Liam Girdwood022658b2012-02-03 17:43:09 +00004182 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brownc4431df2010-11-26 15:21:07 +00004183 ARRAY_SIZE(wm8958_snd_controls));
4184 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4185 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brownda445afe2013-03-12 17:46:09 +00004186 if (control->revision < 1) {
Mark Brown780e2802011-03-11 18:00:19 +00004187 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4188 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4189 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4190 ARRAY_SIZE(wm8994_adc_revd_widgets));
4191 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4192 ARRAY_SIZE(wm8994_dac_revd_widgets));
4193 } else {
4194 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4195 ARRAY_SIZE(wm8994_lateclk_widgets));
4196 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4197 ARRAY_SIZE(wm8994_adc_widgets));
4198 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4199 ARRAY_SIZE(wm8994_dac_widgets));
4200 }
Mark Brownc4431df2010-11-26 15:21:07 +00004201 break;
Mark Brown81204c82011-05-24 17:35:53 +08004202
4203 case WM1811:
Liam Girdwood022658b2012-02-03 17:43:09 +00004204 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
Mark Brown81204c82011-05-24 17:35:53 +08004205 ARRAY_SIZE(wm8958_snd_controls));
4206 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4207 ARRAY_SIZE(wm8958_dapm_widgets));
4208 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4209 ARRAY_SIZE(wm8994_lateclk_widgets));
4210 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4211 ARRAY_SIZE(wm8994_adc_widgets));
4212 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4213 ARRAY_SIZE(wm8994_dac_widgets));
4214 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004215 }
Mark Brownc4431df2010-11-26 15:21:07 +00004216
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004217 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004218 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00004219
Mark Brownc4431df2010-11-26 15:21:07 +00004220 switch (control->type) {
4221 case WM8994:
4222 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4223 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00004224
Mark Brownda445afe2013-03-12 17:46:09 +00004225 if (control->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00004226 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4227 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00004228 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4229 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4230 } else {
4231 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4232 ARRAY_SIZE(wm8994_lateclk_intercon));
4233 }
Mark Brownc4431df2010-11-26 15:21:07 +00004234 break;
4235 case WM8958:
Mark Brownda445afe2013-03-12 17:46:09 +00004236 if (control->revision < 1) {
Chris Rattray15676932012-08-09 10:10:54 +01004237 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4238 ARRAY_SIZE(wm8994_intercon));
Mark Brown780e2802011-03-11 18:00:19 +00004239 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4240 ARRAY_SIZE(wm8994_revd_intercon));
4241 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4242 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4243 } else {
4244 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4245 ARRAY_SIZE(wm8994_lateclk_intercon));
4246 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4247 ARRAY_SIZE(wm8958_intercon));
4248 }
Mark Brownf701a2e2011-03-09 19:31:01 +00004249
4250 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00004251 break;
Mark Brown81204c82011-05-24 17:35:53 +08004252 case WM1811:
4253 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4254 ARRAY_SIZE(wm8994_lateclk_intercon));
4255 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4256 ARRAY_SIZE(wm8958_intercon));
4257 break;
Mark Brownc4431df2010-11-26 15:21:07 +00004258 }
4259
Mark Brown9e6e96a2010-01-29 17:47:12 +00004260 return 0;
4261
Mark Brown88766982010-03-29 20:57:12 +01004262err_irq:
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004263 if (wm8994->jackdet)
4264 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004265 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4266 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4267 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08004268 if (wm8994->micdet_irq)
4269 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09004270 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004271 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004272 &wm8994->fll_locked[i]);
Mark Brown2a8a8562011-07-24 12:20:41 +01004273 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004274 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004275 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4276 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4277 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Browna421a0e2011-12-29 11:08:34 +00004278
Mark Brown9e6e96a2010-01-29 17:47:12 +00004279 return ret;
4280}
4281
Jesper Juhl34ff0f92012-04-09 22:52:19 +02004282static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00004283{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004284 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown2a8a8562011-07-24 12:20:41 +01004285 struct wm8994 *control = wm8994->wm8994;
Mark Brownc7ebf932011-07-12 19:47:59 +09004286 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00004287
4288 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004289
Mark Brown39fb51a2010-11-26 17:23:43 +00004290 pm_runtime_disable(codec->dev);
4291
Mark Brownc7ebf932011-07-12 19:47:59 +09004292 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
Mark Brown2a8a8562011-07-24 12:20:41 +01004293 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
Mark Brownc7ebf932011-07-12 19:47:59 +09004294 &wm8994->fll_locked[i]);
4295
Mark Brown2a8a8562011-07-24 12:20:41 +01004296 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
Mark Brownb30ead52011-07-12 15:47:17 +09004297 &wm8994->hubs);
Mark Brown2a8a8562011-07-24 12:20:41 +01004298 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4299 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4300 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09004301
Mark Brownaf6b6fe2011-11-30 20:32:05 +00004302 if (wm8994->jackdet)
4303 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4304
Mark Brown3a423152010-11-26 15:21:06 +00004305 switch (control->type) {
4306 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08004307 if (wm8994->micdet_irq)
4308 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004309 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004310 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004311 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
Mark Brown3a423152010-11-26 15:21:06 +00004312 wm8994);
Mark Brown2a8a8562011-07-24 12:20:41 +01004313 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
Mark Brown3a423152010-11-26 15:21:06 +00004314 wm8994);
4315 break;
Mark Brown821edd22010-11-26 15:21:09 +00004316
Mark Brown81204c82011-05-24 17:35:53 +08004317 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00004318 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08004319 if (wm8994->micdet_irq)
4320 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00004321 break;
Mark Brown3a423152010-11-26 15:21:06 +00004322 }
Jesper Juhl34ff0f92012-04-09 22:52:19 +02004323 release_firmware(wm8994->mbc);
4324 release_firmware(wm8994->mbc_vss);
4325 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08004326 kfree(wm8994->retune_mobile_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004327 return 0;
4328}
4329
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004330static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4331 .probe = wm8994_codec_probe,
4332 .remove = wm8994_codec_remove,
Mark Brown4752a882012-03-04 02:16:01 +00004333 .suspend = wm8994_codec_suspend,
4334 .resume = wm8994_codec_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004335 .set_bias_level = wm8994_set_bias_level,
4336};
4337
Bill Pemberton7a79e942012-12-07 09:26:37 -05004338static int wm8994_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004339{
Mark Brown2bc16ed2012-03-03 23:24:39 +00004340 struct wm8994_priv *wm8994;
4341
4342 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4343 GFP_KERNEL);
4344 if (wm8994 == NULL)
4345 return -ENOMEM;
4346 platform_set_drvdata(pdev, wm8994);
4347
4348 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
Mark Brown2bc16ed2012-03-03 23:24:39 +00004349
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004350 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
4351 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4352}
4353
Bill Pemberton7a79e942012-12-07 09:26:37 -05004354static int wm8994_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004355{
4356 snd_soc_unregister_codec(&pdev->dev);
4357 return 0;
4358}
4359
Mark Brown4752a882012-03-04 02:16:01 +00004360#ifdef CONFIG_PM_SLEEP
4361static int wm8994_suspend(struct device *dev)
4362{
4363 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4364
4365 /* Drop down to power saving mode when system is suspended */
4366 if (wm8994->jackdet && !wm8994->active_refcount)
4367 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4368 WM1811_JACKDET_MODE_MASK,
4369 wm8994->jackdet_mode);
4370
4371 return 0;
4372}
4373
4374static int wm8994_resume(struct device *dev)
4375{
4376 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4377
Mark Brown78b76db2012-11-22 17:02:09 +09004378 if (wm8994->jackdet && wm8994->jackdet_mode)
Mark Brown4752a882012-03-04 02:16:01 +00004379 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4380 WM1811_JACKDET_MODE_MASK,
4381 WM1811_JACKDET_MODE_AUDIO);
4382
4383 return 0;
4384}
4385#endif
4386
4387static const struct dev_pm_ops wm8994_pm_ops = {
4388 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4389};
4390
Mark Brown9e6e96a2010-01-29 17:47:12 +00004391static struct platform_driver wm8994_codec_driver = {
4392 .driver = {
Mark Brown4752a882012-03-04 02:16:01 +00004393 .name = "wm8994-codec",
4394 .owner = THIS_MODULE,
4395 .pm = &wm8994_pm_ops,
4396 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004397 .probe = wm8994_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05004398 .remove = wm8994_remove,
Mark Brown9e6e96a2010-01-29 17:47:12 +00004399};
4400
Mark Brown5bbcc3c2011-11-23 22:52:08 +00004401module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00004402
4403MODULE_DESCRIPTION("ASoC WM8994 driver");
4404MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4405MODULE_LICENSE("GPL");
4406MODULE_ALIAS("platform:wm8994-codec");