2 * wm8994.c -- WM8994 ALSA SoC Audio driver
4 * Copyright 2009-12 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/slab.h>
24 #include <sound/core.h>
25 #include <sound/jack.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/initval.h>
30 #include <sound/tlv.h>
31 #include <trace/events/asoc.h>
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>
41 #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
46 #define WM8994_NUM_DRC 3
47 #define WM8994_NUM_EQ 3
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 },
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 },
82 static int wm8994_drc_base[] = {
88 static 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,
94 static void wm8958_default_micdet(u16 status, void *data);
96 static const struct wm8958_micd_rate micdet_rates[] = {
97 { 32768, true, 1, 4 },
98 { 32768, false, 1, 1 },
99 { 44100 * 256, true, 7, 10 },
100 { 44100 * 256, false, 7, 10 },
103 static const struct wm8958_micd_rate jackdet_rates[] = {
104 { 32768, true, 0, 1 },
105 { 32768, false, 0, 1 },
106 { 44100 * 256, true, 10, 10 },
107 { 44100 * 256, false, 7, 8 },
110 static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
112 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
113 int best, i, sysclk, val;
115 const struct wm8958_micd_rate *rates;
118 if (!(wm8994->pdata && wm8994->pdata->micd_rates) &&
119 wm8994->jack_cb != wm8958_default_micdet)
122 idle = !wm8994->jack_mic;
124 sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
125 if (sysclk & WM8994_SYSCLK_SRC)
126 sysclk = wm8994->aifclk[1];
128 sysclk = wm8994->aifclk[0];
130 if (wm8994->pdata && wm8994->pdata->micd_rates) {
131 rates = wm8994->pdata->micd_rates;
132 num_rates = wm8994->pdata->num_micd_rates;
133 } else if (wm8994->jackdet) {
134 rates = jackdet_rates;
135 num_rates = ARRAY_SIZE(jackdet_rates);
137 rates = micdet_rates;
138 num_rates = ARRAY_SIZE(micdet_rates);
142 for (i = 0; i < num_rates; i++) {
143 if (rates[i].idle != idle)
145 if (abs(rates[i].sysclk - sysclk) <
146 abs(rates[best].sysclk - sysclk))
148 else if (rates[best].idle != idle)
152 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
153 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
155 dev_dbg(codec->dev, "MICD rate %d,%d for %dHz %s\n",
156 rates[best].start, rates[best].rate, sysclk,
157 idle ? "idle" : "active");
159 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
160 WM8958_MICD_BIAS_STARTTIME_MASK |
161 WM8958_MICD_RATE_MASK, val);
164 static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
166 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
176 switch (wm8994->sysclk[aif]) {
177 case WM8994_SYSCLK_MCLK1:
178 rate = wm8994->mclk[0];
181 case WM8994_SYSCLK_MCLK2:
183 rate = wm8994->mclk[1];
186 case WM8994_SYSCLK_FLL1:
188 rate = wm8994->fll[0].out;
191 case WM8994_SYSCLK_FLL2:
193 rate = wm8994->fll[1].out;
200 if (rate >= 13500000) {
202 reg1 |= WM8994_AIF1CLK_DIV;
204 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
208 wm8994->aifclk[aif] = rate;
210 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
211 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
217 static int configure_clock(struct snd_soc_codec *codec)
219 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
222 /* Bring up the AIF clocks first */
223 configure_aif_clock(codec, 0);
224 configure_aif_clock(codec, 1);
226 /* Then switch CLK_SYS over to the higher of them; a change
227 * can only happen as a result of a clocking change which can
228 * only be made outside of DAPM so we can safely redo the
232 /* If they're equal it doesn't matter which is used */
233 if (wm8994->aifclk[0] == wm8994->aifclk[1]) {
234 wm8958_micd_set_rate(codec);
238 if (wm8994->aifclk[0] < wm8994->aifclk[1])
239 new = WM8994_SYSCLK_SRC;
243 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
244 WM8994_SYSCLK_SRC, new);
246 snd_soc_dapm_sync(&codec->dapm);
248 wm8958_micd_set_rate(codec);
253 static int check_clk_sys(struct snd_soc_dapm_widget *source,
254 struct snd_soc_dapm_widget *sink)
256 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
259 /* Check what we're currently using for CLK_SYS */
260 if (reg & WM8994_SYSCLK_SRC)
265 return strcmp(source->name, clk) == 0;
268 static const char *sidetone_hpf_text[] = {
269 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
272 static const struct soc_enum sidetone_hpf =
273 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
275 static const char *adc_hpf_text[] = {
276 "HiFi", "Voice 1", "Voice 2", "Voice 3"
279 static const struct soc_enum aif1adc1_hpf =
280 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
282 static const struct soc_enum aif1adc2_hpf =
283 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
285 static const struct soc_enum aif2adc_hpf =
286 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
288 static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
289 static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
290 static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
291 static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
292 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
293 static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
294 static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
296 #define WM8994_DRC_SWITCH(xname, reg, shift) \
297 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
298 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
299 .put = wm8994_put_drc_sw, \
300 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
302 static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
303 struct snd_ctl_elem_value *ucontrol)
305 struct soc_mixer_control *mc =
306 (struct soc_mixer_control *)kcontrol->private_value;
307 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
310 /* Can't enable both ADC and DAC paths simultaneously */
311 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
312 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
313 WM8994_AIF1ADC1R_DRC_ENA_MASK;
315 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
317 ret = snd_soc_read(codec, mc->reg);
323 return snd_soc_put_volsw(kcontrol, ucontrol);
326 static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
328 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
329 struct wm8994_pdata *pdata = wm8994->pdata;
330 int base = wm8994_drc_base[drc];
331 int cfg = wm8994->drc_cfg[drc];
334 /* Save any enables; the configuration should clear them. */
335 save = snd_soc_read(codec, base);
336 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
337 WM8994_AIF1ADC1R_DRC_ENA;
339 for (i = 0; i < WM8994_DRC_REGS; i++)
340 snd_soc_update_bits(codec, base + i, 0xffff,
341 pdata->drc_cfgs[cfg].regs[i]);
343 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
344 WM8994_AIF1ADC1L_DRC_ENA |
345 WM8994_AIF1ADC1R_DRC_ENA, save);
348 /* Icky as hell but saves code duplication */
349 static int wm8994_get_drc(const char *name)
351 if (strcmp(name, "AIF1DRC1 Mode") == 0)
353 if (strcmp(name, "AIF1DRC2 Mode") == 0)
355 if (strcmp(name, "AIF2DRC Mode") == 0)
360 static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
361 struct snd_ctl_elem_value *ucontrol)
363 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
364 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
365 struct wm8994_pdata *pdata = wm8994->pdata;
366 int drc = wm8994_get_drc(kcontrol->id.name);
367 int value = ucontrol->value.integer.value[0];
372 if (value >= pdata->num_drc_cfgs)
375 wm8994->drc_cfg[drc] = value;
377 wm8994_set_drc(codec, drc);
382 static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
383 struct snd_ctl_elem_value *ucontrol)
385 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
386 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
387 int drc = wm8994_get_drc(kcontrol->id.name);
389 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
394 static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
396 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
397 struct wm8994_pdata *pdata = wm8994->pdata;
398 int base = wm8994_retune_mobile_base[block];
399 int iface, best, best_val, save, i, cfg;
401 if (!pdata || !wm8994->num_retune_mobile_texts)
416 /* Find the version of the currently selected configuration
417 * with the nearest sample rate. */
418 cfg = wm8994->retune_mobile_cfg[block];
421 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
422 if (strcmp(pdata->retune_mobile_cfgs[i].name,
423 wm8994->retune_mobile_texts[cfg]) == 0 &&
424 abs(pdata->retune_mobile_cfgs[i].rate
425 - wm8994->dac_rates[iface]) < best_val) {
427 best_val = abs(pdata->retune_mobile_cfgs[i].rate
428 - wm8994->dac_rates[iface]);
432 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
434 pdata->retune_mobile_cfgs[best].name,
435 pdata->retune_mobile_cfgs[best].rate,
436 wm8994->dac_rates[iface]);
438 /* The EQ will be disabled while reconfiguring it, remember the
439 * current configuration.
441 save = snd_soc_read(codec, base);
442 save &= WM8994_AIF1DAC1_EQ_ENA;
444 for (i = 0; i < WM8994_EQ_REGS; i++)
445 snd_soc_update_bits(codec, base + i, 0xffff,
446 pdata->retune_mobile_cfgs[best].regs[i]);
448 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
451 /* Icky as hell but saves code duplication */
452 static int wm8994_get_retune_mobile_block(const char *name)
454 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
456 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
458 if (strcmp(name, "AIF2 EQ Mode") == 0)
463 static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
466 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
467 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
468 struct wm8994_pdata *pdata = wm8994->pdata;
469 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
470 int value = ucontrol->value.integer.value[0];
475 if (value >= pdata->num_retune_mobile_cfgs)
478 wm8994->retune_mobile_cfg[block] = value;
480 wm8994_set_retune_mobile(codec, block);
485 static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
486 struct snd_ctl_elem_value *ucontrol)
488 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
489 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
490 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
492 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
497 static const char *aif_chan_src_text[] = {
501 static const struct soc_enum aif1adcl_src =
502 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
504 static const struct soc_enum aif1adcr_src =
505 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
507 static const struct soc_enum aif2adcl_src =
508 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
510 static const struct soc_enum aif2adcr_src =
511 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
513 static const struct soc_enum aif1dacl_src =
514 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
516 static const struct soc_enum aif1dacr_src =
517 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
519 static const struct soc_enum aif2dacl_src =
520 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
522 static const struct soc_enum aif2dacr_src =
523 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
525 static const char *osr_text[] = {
526 "Low Power", "High Performance",
529 static const struct soc_enum dac_osr =
530 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
532 static const struct soc_enum adc_osr =
533 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
535 static const struct snd_kcontrol_new wm8994_snd_controls[] = {
536 SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
537 WM8994_AIF1_ADC1_RIGHT_VOLUME,
538 1, 119, 0, digital_tlv),
539 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
540 WM8994_AIF1_ADC2_RIGHT_VOLUME,
541 1, 119, 0, digital_tlv),
542 SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
543 WM8994_AIF2_ADC_RIGHT_VOLUME,
544 1, 119, 0, digital_tlv),
546 SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
547 SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
548 SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
549 SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
551 SOC_ENUM("AIF1DACL Source", aif1dacl_src),
552 SOC_ENUM("AIF1DACR Source", aif1dacr_src),
553 SOC_ENUM("AIF2DACL Source", aif2dacl_src),
554 SOC_ENUM("AIF2DACR Source", aif2dacr_src),
556 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
557 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
558 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
559 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
560 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
561 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
563 SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
564 SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
566 SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
567 SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
568 SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
570 WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
571 WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
572 WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
574 WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
575 WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
576 WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
578 WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
579 WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
580 WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
582 SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
584 SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
586 SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
588 SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
590 SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
591 SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
593 SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
594 SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
596 SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
597 SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
599 SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
600 SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
602 SOC_ENUM("ADC OSR", adc_osr),
603 SOC_ENUM("DAC OSR", dac_osr),
605 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
606 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
607 SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
608 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
610 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
611 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
612 SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
613 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
615 SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
616 6, 1, 1, wm_hubs_spkmix_tlv),
617 SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
618 2, 1, 1, wm_hubs_spkmix_tlv),
620 SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
621 6, 1, 1, wm_hubs_spkmix_tlv),
622 SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
623 2, 1, 1, wm_hubs_spkmix_tlv),
625 SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
626 10, 15, 0, wm8994_3d_tlv),
627 SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
629 SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
630 10, 15, 0, wm8994_3d_tlv),
631 SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
633 SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
634 10, 15, 0, wm8994_3d_tlv),
635 SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
639 static const struct snd_kcontrol_new wm8994_eq_controls[] = {
640 SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
642 SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
644 SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
646 SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
648 SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
651 SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
653 SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
655 SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
657 SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
659 SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
662 SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
664 SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
666 SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
668 SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
670 SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
674 static const char *wm8958_ng_text[] = {
675 "30ms", "125ms", "250ms", "500ms",
678 static const struct soc_enum wm8958_aif1dac1_ng_hold =
679 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
680 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
682 static const struct soc_enum wm8958_aif1dac2_ng_hold =
683 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
684 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
686 static const struct soc_enum wm8958_aif2dac_ng_hold =
687 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
688 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
690 static const struct snd_kcontrol_new wm8958_snd_controls[] = {
691 SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
693 SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
694 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
695 SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
696 SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
697 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
700 SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
701 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
702 SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
703 SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
704 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
707 SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
708 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
709 SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
710 SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
711 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
715 static const struct snd_kcontrol_new wm1811_snd_controls[] = {
716 SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
718 SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
722 /* We run all mode setting through a function to enforce audio mode */
723 static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
725 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
727 if (!wm8994->jackdet || !wm8994->jack_cb)
730 if (!wm8994->jackdet || !wm8994->jack_cb)
733 if (wm8994->active_refcount)
734 mode = WM1811_JACKDET_MODE_AUDIO;
736 if (mode == wm8994->jackdet_mode)
739 wm8994->jackdet_mode = mode;
741 /* Always use audio mode to detect while the system is active */
742 if (mode != WM1811_JACKDET_MODE_NONE)
743 mode = WM1811_JACKDET_MODE_AUDIO;
745 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
746 WM1811_JACKDET_MODE_MASK, mode);
749 static void active_reference(struct snd_soc_codec *codec)
751 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
753 mutex_lock(&wm8994->accdet_lock);
755 wm8994->active_refcount++;
757 dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
758 wm8994->active_refcount);
760 /* If we're using jack detection go into audio mode */
761 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
763 mutex_unlock(&wm8994->accdet_lock);
766 static void active_dereference(struct snd_soc_codec *codec)
768 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
771 mutex_lock(&wm8994->accdet_lock);
773 wm8994->active_refcount--;
775 dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
776 wm8994->active_refcount);
778 if (wm8994->active_refcount == 0) {
779 /* Go into appropriate detection only mode */
780 if (wm8994->jack_mic || wm8994->mic_detecting)
781 mode = WM1811_JACKDET_MODE_MIC;
783 mode = WM1811_JACKDET_MODE_JACK;
785 wm1811_jackdet_set_mode(codec, mode);
788 mutex_unlock(&wm8994->accdet_lock);
791 static int clk_sys_event(struct snd_soc_dapm_widget *w,
792 struct snd_kcontrol *kcontrol, int event)
794 struct snd_soc_codec *codec = w->codec;
797 case SND_SOC_DAPM_PRE_PMU:
798 return configure_clock(codec);
800 case SND_SOC_DAPM_POST_PMD:
801 configure_clock(codec);
808 static void vmid_reference(struct snd_soc_codec *codec)
810 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
812 pm_runtime_get_sync(codec->dev);
814 wm8994->vmid_refcount++;
816 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
817 wm8994->vmid_refcount);
819 if (wm8994->vmid_refcount == 1) {
820 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
821 WM8994_LINEOUT1_DISCH |
822 WM8994_LINEOUT2_DISCH, 0);
824 wm_hubs_vmid_ena(codec);
826 switch (wm8994->vmid_mode) {
828 WARN_ON(NULL == "Invalid VMID mode");
829 case WM8994_VMID_NORMAL:
830 /* Startup bias, VMID ramp & buffer */
831 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
834 WM8994_STARTUP_BIAS_ENA |
835 WM8994_VMID_BUF_ENA |
836 WM8994_VMID_RAMP_MASK,
838 WM8994_STARTUP_BIAS_ENA |
839 WM8994_VMID_BUF_ENA |
840 (0x3 << WM8994_VMID_RAMP_SHIFT));
842 /* Main bias enable, VMID=2x40k */
843 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
845 WM8994_VMID_SEL_MASK,
846 WM8994_BIAS_ENA | 0x2);
850 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
851 WM8994_VMID_RAMP_MASK |
856 case WM8994_VMID_FORCE:
857 /* Startup bias, slow VMID ramp & buffer */
858 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
861 WM8994_STARTUP_BIAS_ENA |
862 WM8994_VMID_BUF_ENA |
863 WM8994_VMID_RAMP_MASK,
865 WM8994_STARTUP_BIAS_ENA |
866 WM8994_VMID_BUF_ENA |
867 (0x2 << WM8994_VMID_RAMP_SHIFT));
869 /* Main bias enable, VMID=2x40k */
870 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
872 WM8994_VMID_SEL_MASK,
873 WM8994_BIAS_ENA | 0x2);
877 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
878 WM8994_VMID_RAMP_MASK |
886 static void vmid_dereference(struct snd_soc_codec *codec)
888 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
890 wm8994->vmid_refcount--;
892 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
893 wm8994->vmid_refcount);
895 if (wm8994->vmid_refcount == 0) {
896 if (wm8994->hubs.lineout1_se)
897 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
898 WM8994_LINEOUT1N_ENA |
899 WM8994_LINEOUT1P_ENA,
900 WM8994_LINEOUT1N_ENA |
901 WM8994_LINEOUT1P_ENA);
903 if (wm8994->hubs.lineout2_se)
904 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
905 WM8994_LINEOUT2N_ENA |
906 WM8994_LINEOUT2P_ENA,
907 WM8994_LINEOUT2N_ENA |
908 WM8994_LINEOUT2P_ENA);
910 /* Start discharging VMID */
911 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
917 switch (wm8994->vmid_mode) {
918 case WM8994_VMID_FORCE:
925 snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
926 WM8994_VROI, WM8994_VROI);
928 /* Active discharge */
929 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
930 WM8994_LINEOUT1_DISCH |
931 WM8994_LINEOUT2_DISCH,
932 WM8994_LINEOUT1_DISCH |
933 WM8994_LINEOUT2_DISCH);
937 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
938 WM8994_LINEOUT1N_ENA |
939 WM8994_LINEOUT1P_ENA |
940 WM8994_LINEOUT2N_ENA |
941 WM8994_LINEOUT2P_ENA, 0);
943 snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
946 /* Switch off startup biases */
947 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
949 WM8994_STARTUP_BIAS_ENA |
950 WM8994_VMID_BUF_ENA |
951 WM8994_VMID_RAMP_MASK, 0);
953 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
954 WM8994_BIAS_ENA | WM8994_VMID_SEL_MASK, 0);
956 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
957 WM8994_VMID_RAMP_MASK, 0);
960 pm_runtime_put(codec->dev);
963 static int vmid_event(struct snd_soc_dapm_widget *w,
964 struct snd_kcontrol *kcontrol, int event)
966 struct snd_soc_codec *codec = w->codec;
969 case SND_SOC_DAPM_PRE_PMU:
970 vmid_reference(codec);
973 case SND_SOC_DAPM_POST_PMD:
974 vmid_dereference(codec);
981 static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec)
983 int source = 0; /* GCC flow analysis can't track enable */
986 /* We also need the same AIF source for L/R and only one path */
987 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
989 case WM8994_AIF2DACL_TO_DAC1L:
990 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
991 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
993 case WM8994_AIF1DAC2L_TO_DAC1L:
994 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
995 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
997 case WM8994_AIF1DAC1L_TO_DAC1L:
998 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
999 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1002 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
1006 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
1008 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
1012 /* Set the source up */
1013 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
1014 WM8994_CP_DYN_SRC_SEL_MASK, source);
1019 static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1020 struct snd_kcontrol *kcontrol, int event)
1022 struct snd_soc_codec *codec = w->codec;
1023 struct wm8994 *control = codec->control_data;
1024 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
1030 switch (control->type) {
1033 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1040 case SND_SOC_DAPM_PRE_PMU:
1041 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
1042 if ((val & WM8994_AIF1ADCL_SRC) &&
1043 (val & WM8994_AIF1ADCR_SRC))
1044 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1045 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1046 !(val & WM8994_AIF1ADCR_SRC))
1047 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1049 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1050 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1052 val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
1053 if ((val & WM8994_AIF1DACL_SRC) &&
1054 (val & WM8994_AIF1DACR_SRC))
1055 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1056 else if (!(val & WM8994_AIF1DACL_SRC) &&
1057 !(val & WM8994_AIF1DACR_SRC))
1058 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1060 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1061 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1063 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1065 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1067 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1068 WM8994_AIF1DSPCLK_ENA |
1069 WM8994_SYSDSPCLK_ENA,
1070 WM8994_AIF1DSPCLK_ENA |
1071 WM8994_SYSDSPCLK_ENA);
1072 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
1073 WM8994_AIF1ADC1R_ENA |
1074 WM8994_AIF1ADC1L_ENA |
1075 WM8994_AIF1ADC2R_ENA |
1076 WM8994_AIF1ADC2L_ENA);
1077 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
1078 WM8994_AIF1DAC1R_ENA |
1079 WM8994_AIF1DAC1L_ENA |
1080 WM8994_AIF1DAC2R_ENA |
1081 WM8994_AIF1DAC2L_ENA);
1084 case SND_SOC_DAPM_POST_PMU:
1085 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1086 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1088 wm8994_vu_bits[i].reg));
1091 case SND_SOC_DAPM_PRE_PMD:
1092 case SND_SOC_DAPM_POST_PMD:
1093 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1095 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1098 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1099 if (val & WM8994_AIF2DSPCLK_ENA)
1100 val = WM8994_SYSDSPCLK_ENA;
1103 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1104 WM8994_SYSDSPCLK_ENA |
1105 WM8994_AIF1DSPCLK_ENA, val);
1112 static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1113 struct snd_kcontrol *kcontrol, int event)
1115 struct snd_soc_codec *codec = w->codec;
1122 case SND_SOC_DAPM_PRE_PMU:
1123 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
1124 if ((val & WM8994_AIF2ADCL_SRC) &&
1125 (val & WM8994_AIF2ADCR_SRC))
1126 adc = WM8994_AIF2ADCR_ENA;
1127 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1128 !(val & WM8994_AIF2ADCR_SRC))
1129 adc = WM8994_AIF2ADCL_ENA;
1131 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1134 val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
1135 if ((val & WM8994_AIF2DACL_SRC) &&
1136 (val & WM8994_AIF2DACR_SRC))
1137 dac = WM8994_AIF2DACR_ENA;
1138 else if (!(val & WM8994_AIF2DACL_SRC) &&
1139 !(val & WM8994_AIF2DACR_SRC))
1140 dac = WM8994_AIF2DACL_ENA;
1142 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1144 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1145 WM8994_AIF2ADCL_ENA |
1146 WM8994_AIF2ADCR_ENA, adc);
1147 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1148 WM8994_AIF2DACL_ENA |
1149 WM8994_AIF2DACR_ENA, dac);
1150 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1151 WM8994_AIF2DSPCLK_ENA |
1152 WM8994_SYSDSPCLK_ENA,
1153 WM8994_AIF2DSPCLK_ENA |
1154 WM8994_SYSDSPCLK_ENA);
1155 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1156 WM8994_AIF2ADCL_ENA |
1157 WM8994_AIF2ADCR_ENA,
1158 WM8994_AIF2ADCL_ENA |
1159 WM8994_AIF2ADCR_ENA);
1160 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1161 WM8994_AIF2DACL_ENA |
1162 WM8994_AIF2DACR_ENA,
1163 WM8994_AIF2DACL_ENA |
1164 WM8994_AIF2DACR_ENA);
1167 case SND_SOC_DAPM_POST_PMU:
1168 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1169 snd_soc_write(codec, wm8994_vu_bits[i].reg,
1171 wm8994_vu_bits[i].reg));
1174 case SND_SOC_DAPM_PRE_PMD:
1175 case SND_SOC_DAPM_POST_PMD:
1176 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1177 WM8994_AIF2DACL_ENA |
1178 WM8994_AIF2DACR_ENA, 0);
1179 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
1180 WM8994_AIF2ADCL_ENA |
1181 WM8994_AIF2ADCR_ENA, 0);
1183 val = snd_soc_read(codec, WM8994_CLOCKING_1);
1184 if (val & WM8994_AIF1DSPCLK_ENA)
1185 val = WM8994_SYSDSPCLK_ENA;
1188 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
1189 WM8994_SYSDSPCLK_ENA |
1190 WM8994_AIF2DSPCLK_ENA, val);
1197 static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1198 struct snd_kcontrol *kcontrol, int event)
1200 struct snd_soc_codec *codec = w->codec;
1201 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1204 case SND_SOC_DAPM_PRE_PMU:
1205 wm8994->aif1clk_enable = 1;
1207 case SND_SOC_DAPM_POST_PMD:
1208 wm8994->aif1clk_disable = 1;
1215 static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1216 struct snd_kcontrol *kcontrol, int event)
1218 struct snd_soc_codec *codec = w->codec;
1219 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1222 case SND_SOC_DAPM_PRE_PMU:
1223 wm8994->aif2clk_enable = 1;
1225 case SND_SOC_DAPM_POST_PMD:
1226 wm8994->aif2clk_disable = 1;
1233 static int late_enable_ev(struct snd_soc_dapm_widget *w,
1234 struct snd_kcontrol *kcontrol, int event)
1236 struct snd_soc_codec *codec = w->codec;
1237 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1240 case SND_SOC_DAPM_PRE_PMU:
1241 if (wm8994->aif1clk_enable) {
1242 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1243 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1244 WM8994_AIF1CLK_ENA_MASK,
1245 WM8994_AIF1CLK_ENA);
1246 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1247 wm8994->aif1clk_enable = 0;
1249 if (wm8994->aif2clk_enable) {
1250 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1251 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1252 WM8994_AIF2CLK_ENA_MASK,
1253 WM8994_AIF2CLK_ENA);
1254 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1255 wm8994->aif2clk_enable = 0;
1260 /* We may also have postponed startup of DSP, handle that. */
1261 wm8958_aif_ev(w, kcontrol, event);
1266 static int late_disable_ev(struct snd_soc_dapm_widget *w,
1267 struct snd_kcontrol *kcontrol, int event)
1269 struct snd_soc_codec *codec = w->codec;
1270 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1273 case SND_SOC_DAPM_POST_PMD:
1274 if (wm8994->aif1clk_disable) {
1275 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1276 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1277 WM8994_AIF1CLK_ENA_MASK, 0);
1278 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1279 wm8994->aif1clk_disable = 0;
1281 if (wm8994->aif2clk_disable) {
1282 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1283 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1284 WM8994_AIF2CLK_ENA_MASK, 0);
1285 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1286 wm8994->aif2clk_disable = 0;
1294 static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1295 struct snd_kcontrol *kcontrol, int event)
1297 late_enable_ev(w, kcontrol, event);
1301 static int micbias_ev(struct snd_soc_dapm_widget *w,
1302 struct snd_kcontrol *kcontrol, int event)
1304 late_enable_ev(w, kcontrol, event);
1308 static int dac_ev(struct snd_soc_dapm_widget *w,
1309 struct snd_kcontrol *kcontrol, int event)
1311 struct snd_soc_codec *codec = w->codec;
1312 unsigned int mask = 1 << w->shift;
1314 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1319 static const char *adc_mux_text[] = {
1324 static const struct soc_enum adc_enum =
1325 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1327 static const struct snd_kcontrol_new adcl_mux =
1328 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1330 static const struct snd_kcontrol_new adcr_mux =
1331 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1333 static const struct snd_kcontrol_new left_speaker_mixer[] = {
1334 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1335 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1336 SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1337 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1338 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1341 static const struct snd_kcontrol_new right_speaker_mixer[] = {
1342 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1343 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1344 SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1345 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1346 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1349 /* Debugging; dump chip status after DAPM transitions */
1350 static int post_ev(struct snd_soc_dapm_widget *w,
1351 struct snd_kcontrol *kcontrol, int event)
1353 struct snd_soc_codec *codec = w->codec;
1354 dev_dbg(codec->dev, "SRC status: %x\n",
1356 WM8994_RATE_STATUS));
1360 static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1361 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1363 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1367 static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1368 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1370 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1374 static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1375 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1377 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1381 static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1382 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1384 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1388 static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1389 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1391 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1393 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1395 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1397 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1401 static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1402 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1404 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1406 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1408 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1410 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1414 #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1415 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1416 .info = snd_soc_info_volsw, \
1417 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1418 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1420 static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1421 struct snd_ctl_elem_value *ucontrol)
1423 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1424 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1425 struct snd_soc_codec *codec = w->codec;
1428 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1430 wm_hubs_update_class_w(codec);
1435 static const struct snd_kcontrol_new dac1l_mix[] = {
1436 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1438 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1440 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1442 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1444 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1448 static const struct snd_kcontrol_new dac1r_mix[] = {
1449 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1451 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1453 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1455 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1457 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1461 static const char *sidetone_text[] = {
1462 "ADC/DMIC1", "DMIC2",
1465 static const struct soc_enum sidetone1_enum =
1466 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1468 static const struct snd_kcontrol_new sidetone1_mux =
1469 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1471 static const struct soc_enum sidetone2_enum =
1472 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1474 static const struct snd_kcontrol_new sidetone2_mux =
1475 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1477 static const char *aif1dac_text[] = {
1478 "AIF1DACDAT", "AIF3DACDAT",
1481 static const struct soc_enum aif1dac_enum =
1482 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1484 static const struct snd_kcontrol_new aif1dac_mux =
1485 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1487 static const char *aif2dac_text[] = {
1488 "AIF2DACDAT", "AIF3DACDAT",
1491 static const struct soc_enum aif2dac_enum =
1492 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1494 static const struct snd_kcontrol_new aif2dac_mux =
1495 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1497 static const char *aif2adc_text[] = {
1498 "AIF2ADCDAT", "AIF3DACDAT",
1501 static const struct soc_enum aif2adc_enum =
1502 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1504 static const struct snd_kcontrol_new aif2adc_mux =
1505 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1507 static const char *aif3adc_text[] = {
1508 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
1511 static const struct soc_enum wm8994_aif3adc_enum =
1512 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1514 static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1515 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1517 static const struct soc_enum wm8958_aif3adc_enum =
1518 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1520 static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1521 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1523 static const char *mono_pcm_out_text[] = {
1524 "None", "AIF2ADCL", "AIF2ADCR",
1527 static const struct soc_enum mono_pcm_out_enum =
1528 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1530 static const struct snd_kcontrol_new mono_pcm_out_mux =
1531 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1533 static const char *aif2dac_src_text[] = {
1537 /* Note that these two control shouldn't be simultaneously switched to AIF3 */
1538 static const struct soc_enum aif2dacl_src_enum =
1539 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1541 static const struct snd_kcontrol_new aif2dacl_src_mux =
1542 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1544 static const struct soc_enum aif2dacr_src_enum =
1545 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1547 static const struct snd_kcontrol_new aif2dacr_src_mux =
1548 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
1550 static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1551 SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
1552 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1553 SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
1554 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1556 SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1557 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1558 SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1559 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1560 SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1561 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1562 SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1563 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1564 SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1565 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1567 SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1568 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1569 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1570 SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1571 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1572 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1573 SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
1574 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1575 SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
1576 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1578 SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1581 static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1582 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
1583 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1584 SND_SOC_DAPM_PRE_PMD),
1585 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
1586 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1587 SND_SOC_DAPM_PRE_PMD),
1588 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1589 SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1590 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1591 SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1592 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1593 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1594 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
1597 static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1598 SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1599 dac_ev, SND_SOC_DAPM_PRE_PMU),
1600 SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1601 dac_ev, SND_SOC_DAPM_PRE_PMU),
1602 SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1603 dac_ev, SND_SOC_DAPM_PRE_PMU),
1604 SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1605 dac_ev, SND_SOC_DAPM_PRE_PMU),
1608 static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1609 SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
1610 SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
1611 SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1612 SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1615 static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
1616 SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1617 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1618 SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1619 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1622 static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
1623 SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1624 SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1627 static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1628 SND_SOC_DAPM_INPUT("DMIC1DAT"),
1629 SND_SOC_DAPM_INPUT("DMIC2DAT"),
1630 SND_SOC_DAPM_INPUT("Clock"),
1632 SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1633 SND_SOC_DAPM_PRE_PMU),
1634 SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1635 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1637 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1638 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1640 SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1641 SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1642 SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
1644 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
1645 0, SND_SOC_NOPM, 9, 0),
1646 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
1647 0, SND_SOC_NOPM, 8, 0),
1648 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1649 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
1650 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1651 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1652 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
1653 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1655 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
1656 0, SND_SOC_NOPM, 11, 0),
1657 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
1658 0, SND_SOC_NOPM, 10, 0),
1659 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1660 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
1661 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1662 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1663 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
1664 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1666 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1667 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1668 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1669 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1671 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1672 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1673 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1674 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1676 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1677 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1678 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1679 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1681 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1682 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1684 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1685 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1686 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1687 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1689 SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1690 SND_SOC_NOPM, 13, 0),
1691 SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1692 SND_SOC_NOPM, 12, 0),
1693 SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1694 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
1695 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1696 SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1697 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
1698 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1700 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1701 SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1702 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1703 SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1705 SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1706 SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1707 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
1709 SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1710 SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1712 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1714 SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1715 SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1716 SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1717 SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1719 /* Power is done with the muxes since the ADC power also controls the
1720 * downsampling chain, the chip will automatically manage the analogue
1721 * specific portions.
1723 SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1724 SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1726 SND_SOC_DAPM_POST("Debug log", post_ev),
1729 static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1730 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1733 static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1734 SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
1735 SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1736 SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1737 SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1738 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1741 static const struct snd_soc_dapm_route intercon[] = {
1742 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1743 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1745 { "DSP1CLK", NULL, "CLK_SYS" },
1746 { "DSP2CLK", NULL, "CLK_SYS" },
1747 { "DSPINTCLK", NULL, "CLK_SYS" },
1749 { "AIF1ADC1L", NULL, "AIF1CLK" },
1750 { "AIF1ADC1L", NULL, "DSP1CLK" },
1751 { "AIF1ADC1R", NULL, "AIF1CLK" },
1752 { "AIF1ADC1R", NULL, "DSP1CLK" },
1753 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1755 { "AIF1DAC1L", NULL, "AIF1CLK" },
1756 { "AIF1DAC1L", NULL, "DSP1CLK" },
1757 { "AIF1DAC1R", NULL, "AIF1CLK" },
1758 { "AIF1DAC1R", NULL, "DSP1CLK" },
1759 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1761 { "AIF1ADC2L", NULL, "AIF1CLK" },
1762 { "AIF1ADC2L", NULL, "DSP1CLK" },
1763 { "AIF1ADC2R", NULL, "AIF1CLK" },
1764 { "AIF1ADC2R", NULL, "DSP1CLK" },
1765 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1767 { "AIF1DAC2L", NULL, "AIF1CLK" },
1768 { "AIF1DAC2L", NULL, "DSP1CLK" },
1769 { "AIF1DAC2R", NULL, "AIF1CLK" },
1770 { "AIF1DAC2R", NULL, "DSP1CLK" },
1771 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1773 { "AIF2ADCL", NULL, "AIF2CLK" },
1774 { "AIF2ADCL", NULL, "DSP2CLK" },
1775 { "AIF2ADCR", NULL, "AIF2CLK" },
1776 { "AIF2ADCR", NULL, "DSP2CLK" },
1777 { "AIF2ADCR", NULL, "DSPINTCLK" },
1779 { "AIF2DACL", NULL, "AIF2CLK" },
1780 { "AIF2DACL", NULL, "DSP2CLK" },
1781 { "AIF2DACR", NULL, "AIF2CLK" },
1782 { "AIF2DACR", NULL, "DSP2CLK" },
1783 { "AIF2DACR", NULL, "DSPINTCLK" },
1785 { "DMIC1L", NULL, "DMIC1DAT" },
1786 { "DMIC1L", NULL, "CLK_SYS" },
1787 { "DMIC1R", NULL, "DMIC1DAT" },
1788 { "DMIC1R", NULL, "CLK_SYS" },
1789 { "DMIC2L", NULL, "DMIC2DAT" },
1790 { "DMIC2L", NULL, "CLK_SYS" },
1791 { "DMIC2R", NULL, "DMIC2DAT" },
1792 { "DMIC2R", NULL, "CLK_SYS" },
1794 { "ADCL", NULL, "AIF1CLK" },
1795 { "ADCL", NULL, "DSP1CLK" },
1796 { "ADCL", NULL, "DSPINTCLK" },
1798 { "ADCR", NULL, "AIF1CLK" },
1799 { "ADCR", NULL, "DSP1CLK" },
1800 { "ADCR", NULL, "DSPINTCLK" },
1802 { "ADCL Mux", "ADC", "ADCL" },
1803 { "ADCL Mux", "DMIC", "DMIC1L" },
1804 { "ADCR Mux", "ADC", "ADCR" },
1805 { "ADCR Mux", "DMIC", "DMIC1R" },
1807 { "DAC1L", NULL, "AIF1CLK" },
1808 { "DAC1L", NULL, "DSP1CLK" },
1809 { "DAC1L", NULL, "DSPINTCLK" },
1811 { "DAC1R", NULL, "AIF1CLK" },
1812 { "DAC1R", NULL, "DSP1CLK" },
1813 { "DAC1R", NULL, "DSPINTCLK" },
1815 { "DAC2L", NULL, "AIF2CLK" },
1816 { "DAC2L", NULL, "DSP2CLK" },
1817 { "DAC2L", NULL, "DSPINTCLK" },
1819 { "DAC2R", NULL, "AIF2DACR" },
1820 { "DAC2R", NULL, "AIF2CLK" },
1821 { "DAC2R", NULL, "DSP2CLK" },
1822 { "DAC2R", NULL, "DSPINTCLK" },
1824 { "TOCLK", NULL, "CLK_SYS" },
1826 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1827 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1828 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1830 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1831 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1832 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1835 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1836 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1837 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1839 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1840 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1841 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1843 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1844 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1845 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1847 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1848 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1849 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1851 /* Pin level routing for AIF3 */
1852 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1853 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1854 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1855 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1857 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1858 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1859 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1860 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1861 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1862 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1863 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1866 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1867 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1868 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1869 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1870 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1872 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1873 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1874 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1875 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1876 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1878 /* DAC2/AIF2 outputs */
1879 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
1880 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1881 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1882 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1883 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1884 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1886 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
1887 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1888 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1889 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1890 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1891 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1893 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1894 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1895 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1896 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1898 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1901 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1902 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1903 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1904 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1905 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1906 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1907 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1908 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1911 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1912 { "Left Sidetone", "DMIC2", "DMIC2L" },
1913 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1914 { "Right Sidetone", "DMIC2", "DMIC2R" },
1917 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1918 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1920 { "SPKL", "DAC1 Switch", "DAC1L" },
1921 { "SPKL", "DAC2 Switch", "DAC2L" },
1923 { "SPKR", "DAC1 Switch", "DAC1R" },
1924 { "SPKR", "DAC2 Switch", "DAC2R" },
1926 { "Left Headphone Mux", "DAC", "DAC1L" },
1927 { "Right Headphone Mux", "DAC", "DAC1R" },
1930 static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1931 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1932 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1933 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1934 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1935 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1936 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1937 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1938 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1941 static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1942 { "DAC1L", NULL, "DAC1L Mixer" },
1943 { "DAC1R", NULL, "DAC1R Mixer" },
1944 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1945 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1948 static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1949 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1950 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1951 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1952 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
1953 { "MICBIAS1", NULL, "CLK_SYS" },
1954 { "MICBIAS1", NULL, "MICBIAS Supply" },
1955 { "MICBIAS2", NULL, "CLK_SYS" },
1956 { "MICBIAS2", NULL, "MICBIAS Supply" },
1959 static const struct snd_soc_dapm_route wm8994_intercon[] = {
1960 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1961 { "AIF2DACR", NULL, "AIF2DAC Mux" },
1962 { "MICBIAS1", NULL, "VMID" },
1963 { "MICBIAS2", NULL, "VMID" },
1966 static const struct snd_soc_dapm_route wm8958_intercon[] = {
1967 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1968 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1970 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1971 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1972 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1973 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1975 { "AIF3DACDAT", NULL, "AIF3" },
1976 { "AIF3ADCDAT", NULL, "AIF3" },
1978 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1979 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1981 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1984 /* The size in bits of the FLL divide multiplied by 10
1985 * to allow rounding later */
1986 #define FIXED_FLL_SIZE ((1 << 16) * 10)
1996 static int wm8994_get_fll_config(struct fll_div *fll,
1997 int freq_in, int freq_out)
2000 unsigned int K, Ndiv, Nmod;
2002 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2004 /* Scale the input frequency down to <= 13.5MHz */
2005 fll->clk_ref_div = 0;
2006 while (freq_in > 13500000) {
2010 if (fll->clk_ref_div > 3)
2013 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2015 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2017 while (freq_out * (fll->outdiv + 1) < 90000000) {
2019 if (fll->outdiv > 63)
2022 freq_out *= fll->outdiv + 1;
2023 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2025 if (freq_in > 1000000) {
2026 fll->fll_fratio = 0;
2027 } else if (freq_in > 256000) {
2028 fll->fll_fratio = 1;
2030 } else if (freq_in > 128000) {
2031 fll->fll_fratio = 2;
2033 } else if (freq_in > 64000) {
2034 fll->fll_fratio = 3;
2037 fll->fll_fratio = 4;
2040 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2042 /* Now, calculate N.K */
2043 Ndiv = freq_out / freq_in;
2046 Nmod = freq_out % freq_in;
2047 pr_debug("Nmod=%d\n", Nmod);
2049 /* Calculate fractional part - scale up so we can round. */
2050 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2052 do_div(Kpart, freq_in);
2054 K = Kpart & 0xFFFFFFFF;
2059 /* Move down to proper range now rounding is done */
2062 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2067 static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2068 unsigned int freq_in, unsigned int freq_out)
2070 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2071 struct wm8994 *control = wm8994->wm8994;
2072 int reg_offset, ret;
2074 u16 reg, clk1, aif_reg, aif_src;
2075 unsigned long timeout;
2093 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
2094 was_enabled = reg & WM8994_FLL1_ENA;
2098 /* Allow no source specification when stopping */
2101 src = wm8994->fll[id].src;
2103 case WM8994_FLL_SRC_MCLK1:
2104 case WM8994_FLL_SRC_MCLK2:
2105 case WM8994_FLL_SRC_LRCLK:
2106 case WM8994_FLL_SRC_BCLK:
2112 /* Are we changing anything? */
2113 if (wm8994->fll[id].src == src &&
2114 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2117 /* If we're stopping the FLL redo the old config - no
2118 * registers will actually be written but we avoid GCC flow
2119 * analysis bugs spewing warnings.
2122 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
2124 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
2125 wm8994->fll[id].out);
2129 /* Make sure that we're not providing SYSCLK right now */
2130 clk1 = snd_soc_read(codec, WM8994_CLOCKING_1);
2131 if (clk1 & WM8994_SYSCLK_SRC)
2132 aif_reg = WM8994_AIF2_CLOCKING_1;
2134 aif_reg = WM8994_AIF1_CLOCKING_1;
2135 reg = snd_soc_read(codec, aif_reg);
2137 if ((reg & WM8994_AIF1CLK_ENA) &&
2138 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2139 dev_err(codec->dev, "FLL%d is currently providing SYSCLK\n",
2144 /* We always need to disable the FLL while reconfiguring */
2145 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2146 WM8994_FLL1_ENA, 0);
2148 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
2149 freq_in == freq_out && freq_out) {
2150 dev_dbg(codec->dev, "Bypassing FLL%d\n", id + 1);
2151 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2152 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2156 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2157 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2158 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
2159 WM8994_FLL1_OUTDIV_MASK |
2160 WM8994_FLL1_FRATIO_MASK, reg);
2162 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
2163 WM8994_FLL1_K_MASK, fll.k);
2165 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
2167 fll.n << WM8994_FLL1_N_SHIFT);
2169 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2171 WM8994_FLL1_REFCLK_DIV_MASK |
2172 WM8994_FLL1_REFCLK_SRC_MASK,
2173 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2176 /* Clear any pending completion from a previous failure */
2177 try_wait_for_completion(&wm8994->fll_locked[id]);
2179 /* Enable (with fractional mode if required) */
2181 /* Enable VMID if we need it */
2183 active_reference(codec);
2185 switch (control->type) {
2187 vmid_reference(codec);
2190 if (wm8994->revision < 1)
2191 vmid_reference(codec);
2199 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
2201 reg = WM8994_FLL1_ENA;
2202 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2203 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
2206 if (wm8994->fll_locked_irq) {
2207 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2208 msecs_to_jiffies(10));
2210 dev_warn(codec->dev,
2211 "Timed out waiting for FLL lock\n");
2217 switch (control->type) {
2219 vmid_dereference(codec);
2222 if (wm8994->revision < 1)
2223 vmid_dereference(codec);
2229 active_dereference(codec);
2234 wm8994->fll[id].in = freq_in;
2235 wm8994->fll[id].out = freq_out;
2236 wm8994->fll[id].src = src;
2238 configure_clock(codec);
2243 static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2245 struct completion *completion = data;
2247 complete(completion);
2252 static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2254 static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2255 unsigned int freq_in, unsigned int freq_out)
2257 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
2260 static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2261 int clk_id, unsigned int freq, int dir)
2263 struct snd_soc_codec *codec = dai->codec;
2264 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2273 /* AIF3 shares clocking with AIF1/2 */
2278 case WM8994_SYSCLK_MCLK1:
2279 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2280 wm8994->mclk[0] = freq;
2281 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2285 case WM8994_SYSCLK_MCLK2:
2286 /* TODO: Set GPIO AF */
2287 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2288 wm8994->mclk[1] = freq;
2289 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2293 case WM8994_SYSCLK_FLL1:
2294 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2295 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2298 case WM8994_SYSCLK_FLL2:
2299 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2300 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2303 case WM8994_SYSCLK_OPCLK:
2304 /* Special case - a division (times 10) is given and
2305 * no effect on main clocking.
2308 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2309 if (opclk_divs[i] == freq)
2311 if (i == ARRAY_SIZE(opclk_divs))
2313 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2314 WM8994_OPCLK_DIV_MASK, i);
2315 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2316 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2318 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2319 WM8994_OPCLK_ENA, 0);
2326 configure_clock(codec);
2331 static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2332 enum snd_soc_bias_level level)
2334 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2335 struct wm8994 *control = wm8994->wm8994;
2337 wm_hubs_set_bias_level(codec, level);
2340 case SND_SOC_BIAS_ON:
2343 case SND_SOC_BIAS_PREPARE:
2344 /* MICBIAS into regulating mode */
2345 switch (control->type) {
2348 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2349 WM8958_MICB1_MODE, 0);
2350 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2351 WM8958_MICB2_MODE, 0);
2357 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2358 active_reference(codec);
2361 case SND_SOC_BIAS_STANDBY:
2362 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
2363 switch (control->type) {
2365 if (wm8994->revision == 0) {
2366 /* Optimise performance for rev A */
2367 snd_soc_update_bits(codec,
2368 WM8958_CHARGE_PUMP_2,
2378 /* Discharge LINEOUT1 & 2 */
2379 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2380 WM8994_LINEOUT1_DISCH |
2381 WM8994_LINEOUT2_DISCH,
2382 WM8994_LINEOUT1_DISCH |
2383 WM8994_LINEOUT2_DISCH);
2386 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
2387 active_dereference(codec);
2389 /* MICBIAS into bypass mode on newer devices */
2390 switch (control->type) {
2393 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2396 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2405 case SND_SOC_BIAS_OFF:
2406 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
2407 wm8994->cur_fw = NULL;
2411 codec->dapm.bias_level = level;
2416 int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2418 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2421 case WM8994_VMID_NORMAL:
2422 if (wm8994->hubs.lineout1_se) {
2423 snd_soc_dapm_disable_pin(&codec->dapm,
2424 "LINEOUT1N Driver");
2425 snd_soc_dapm_disable_pin(&codec->dapm,
2426 "LINEOUT1P Driver");
2428 if (wm8994->hubs.lineout2_se) {
2429 snd_soc_dapm_disable_pin(&codec->dapm,
2430 "LINEOUT2N Driver");
2431 snd_soc_dapm_disable_pin(&codec->dapm,
2432 "LINEOUT2P Driver");
2435 /* Do the sync with the old mode to allow it to clean up */
2436 snd_soc_dapm_sync(&codec->dapm);
2437 wm8994->vmid_mode = mode;
2440 case WM8994_VMID_FORCE:
2441 if (wm8994->hubs.lineout1_se) {
2442 snd_soc_dapm_force_enable_pin(&codec->dapm,
2443 "LINEOUT1N Driver");
2444 snd_soc_dapm_force_enable_pin(&codec->dapm,
2445 "LINEOUT1P Driver");
2447 if (wm8994->hubs.lineout2_se) {
2448 snd_soc_dapm_force_enable_pin(&codec->dapm,
2449 "LINEOUT2N Driver");
2450 snd_soc_dapm_force_enable_pin(&codec->dapm,
2451 "LINEOUT2P Driver");
2454 wm8994->vmid_mode = mode;
2455 snd_soc_dapm_sync(&codec->dapm);
2465 static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2467 struct snd_soc_codec *codec = dai->codec;
2468 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2469 struct wm8994 *control = wm8994->wm8994;
2477 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2478 aif1_reg = WM8994_AIF1_CONTROL_1;
2481 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2482 aif1_reg = WM8994_AIF2_CONTROL_1;
2488 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2489 case SND_SOC_DAIFMT_CBS_CFS:
2491 case SND_SOC_DAIFMT_CBM_CFM:
2492 ms = WM8994_AIF1_MSTR;
2498 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2499 case SND_SOC_DAIFMT_DSP_B:
2500 aif1 |= WM8994_AIF1_LRCLK_INV;
2501 case SND_SOC_DAIFMT_DSP_A:
2504 case SND_SOC_DAIFMT_I2S:
2507 case SND_SOC_DAIFMT_RIGHT_J:
2509 case SND_SOC_DAIFMT_LEFT_J:
2516 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2517 case SND_SOC_DAIFMT_DSP_A:
2518 case SND_SOC_DAIFMT_DSP_B:
2519 /* frame inversion not valid for DSP modes */
2520 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2521 case SND_SOC_DAIFMT_NB_NF:
2523 case SND_SOC_DAIFMT_IB_NF:
2524 aif1 |= WM8994_AIF1_BCLK_INV;
2531 case SND_SOC_DAIFMT_I2S:
2532 case SND_SOC_DAIFMT_RIGHT_J:
2533 case SND_SOC_DAIFMT_LEFT_J:
2534 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2535 case SND_SOC_DAIFMT_NB_NF:
2537 case SND_SOC_DAIFMT_IB_IF:
2538 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2540 case SND_SOC_DAIFMT_IB_NF:
2541 aif1 |= WM8994_AIF1_BCLK_INV;
2543 case SND_SOC_DAIFMT_NB_IF:
2544 aif1 |= WM8994_AIF1_LRCLK_INV;
2554 /* The AIF2 format configuration needs to be mirrored to AIF3
2555 * on WM8958 if it's in use so just do it all the time. */
2556 switch (control->type) {
2560 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2561 WM8994_AIF1_LRCLK_INV |
2562 WM8958_AIF3_FMT_MASK, aif1);
2569 snd_soc_update_bits(codec, aif1_reg,
2570 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2571 WM8994_AIF1_FMT_MASK,
2573 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2595 static int fs_ratios[] = {
2596 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2599 static int bclk_divs[] = {
2600 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2601 640, 880, 960, 1280, 1760, 1920
2604 static int wm8994_hw_params(struct snd_pcm_substream *substream,
2605 struct snd_pcm_hw_params *params,
2606 struct snd_soc_dai *dai)
2608 struct snd_soc_codec *codec = dai->codec;
2609 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2620 int id = dai->id - 1;
2622 int i, cur_val, best_val, bclk_rate, best;
2626 aif1_reg = WM8994_AIF1_CONTROL_1;
2627 aif2_reg = WM8994_AIF1_CONTROL_2;
2628 bclk_reg = WM8994_AIF1_BCLK;
2629 rate_reg = WM8994_AIF1_RATE;
2630 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2631 wm8994->lrclk_shared[0]) {
2632 lrclk_reg = WM8994_AIF1DAC_LRCLK;
2634 lrclk_reg = WM8994_AIF1ADC_LRCLK;
2635 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2639 aif1_reg = WM8994_AIF2_CONTROL_1;
2640 aif2_reg = WM8994_AIF2_CONTROL_2;
2641 bclk_reg = WM8994_AIF2_BCLK;
2642 rate_reg = WM8994_AIF2_RATE;
2643 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2644 wm8994->lrclk_shared[1]) {
2645 lrclk_reg = WM8994_AIF2DAC_LRCLK;
2647 lrclk_reg = WM8994_AIF2ADC_LRCLK;
2648 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2655 bclk_rate = params_rate(params) * 2;
2656 switch (params_format(params)) {
2657 case SNDRV_PCM_FORMAT_S16_LE:
2660 case SNDRV_PCM_FORMAT_S20_3LE:
2664 case SNDRV_PCM_FORMAT_S24_LE:
2668 case SNDRV_PCM_FORMAT_S32_LE:
2676 /* Try to find an appropriate sample rate; look for an exact match. */
2677 for (i = 0; i < ARRAY_SIZE(srs); i++)
2678 if (srs[i].rate == params_rate(params))
2680 if (i == ARRAY_SIZE(srs))
2682 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2684 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2685 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2686 dai->id, wm8994->aifclk[id], bclk_rate);
2688 if (params_channels(params) == 1 &&
2689 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2690 aif2 |= WM8994_AIF1_MONO;
2692 if (wm8994->aifclk[id] == 0) {
2693 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2697 /* AIFCLK/fs ratio; look for a close match in either direction */
2699 best_val = abs((fs_ratios[0] * params_rate(params))
2700 - wm8994->aifclk[id]);
2701 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2702 cur_val = abs((fs_ratios[i] * params_rate(params))
2703 - wm8994->aifclk[id]);
2704 if (cur_val >= best_val)
2709 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2710 dai->id, fs_ratios[best]);
2713 /* We may not get quite the right frequency if using
2714 * approximate clocks so look for the closest match that is
2715 * higher than the target (we need to ensure that there enough
2716 * BCLKs to clock out the samples).
2719 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
2720 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
2721 if (cur_val < 0) /* BCLK table is sorted */
2725 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
2726 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2727 bclk_divs[best], bclk_rate);
2728 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2730 lrclk = bclk_rate / params_rate(params);
2732 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2736 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2737 lrclk, bclk_rate / lrclk);
2739 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2740 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
2741 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2742 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2744 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2745 WM8994_AIF1CLK_RATE_MASK, rate_val);
2747 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2750 wm8994->dac_rates[0] = params_rate(params);
2751 wm8994_set_retune_mobile(codec, 0);
2752 wm8994_set_retune_mobile(codec, 1);
2755 wm8994->dac_rates[1] = params_rate(params);
2756 wm8994_set_retune_mobile(codec, 2);
2764 static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2765 struct snd_pcm_hw_params *params,
2766 struct snd_soc_dai *dai)
2768 struct snd_soc_codec *codec = dai->codec;
2769 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2770 struct wm8994 *control = wm8994->wm8994;
2776 switch (control->type) {
2779 aif1_reg = WM8958_AIF3_CONTROL_1;
2788 switch (params_format(params)) {
2789 case SNDRV_PCM_FORMAT_S16_LE:
2791 case SNDRV_PCM_FORMAT_S20_3LE:
2794 case SNDRV_PCM_FORMAT_S24_LE:
2797 case SNDRV_PCM_FORMAT_S32_LE:
2804 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2807 static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2809 struct snd_soc_codec *codec = codec_dai->codec;
2813 switch (codec_dai->id) {
2815 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2818 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2825 reg = WM8994_AIF1DAC1_MUTE;
2829 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2834 static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2836 struct snd_soc_codec *codec = codec_dai->codec;
2839 switch (codec_dai->id) {
2841 reg = WM8994_AIF1_MASTER_SLAVE;
2842 mask = WM8994_AIF1_TRI;
2845 reg = WM8994_AIF2_MASTER_SLAVE;
2846 mask = WM8994_AIF2_TRI;
2857 return snd_soc_update_bits(codec, reg, mask, val);
2860 static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2862 struct snd_soc_codec *codec = dai->codec;
2864 /* Disable the pulls on the AIF if we're using it to save power. */
2865 snd_soc_update_bits(codec, WM8994_GPIO_3,
2866 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2867 snd_soc_update_bits(codec, WM8994_GPIO_4,
2868 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2869 snd_soc_update_bits(codec, WM8994_GPIO_5,
2870 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2875 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2877 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
2878 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
2880 static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
2881 .set_sysclk = wm8994_set_dai_sysclk,
2882 .set_fmt = wm8994_set_dai_fmt,
2883 .hw_params = wm8994_hw_params,
2884 .digital_mute = wm8994_aif_mute,
2885 .set_pll = wm8994_set_fll,
2886 .set_tristate = wm8994_set_tristate,
2889 static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
2890 .set_sysclk = wm8994_set_dai_sysclk,
2891 .set_fmt = wm8994_set_dai_fmt,
2892 .hw_params = wm8994_hw_params,
2893 .digital_mute = wm8994_aif_mute,
2894 .set_pll = wm8994_set_fll,
2895 .set_tristate = wm8994_set_tristate,
2898 static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
2899 .hw_params = wm8994_aif3_hw_params,
2902 static struct snd_soc_dai_driver wm8994_dai[] = {
2904 .name = "wm8994-aif1",
2907 .stream_name = "AIF1 Playback",
2910 .rates = WM8994_RATES,
2911 .formats = WM8994_FORMATS,
2915 .stream_name = "AIF1 Capture",
2918 .rates = WM8994_RATES,
2919 .formats = WM8994_FORMATS,
2922 .ops = &wm8994_aif1_dai_ops,
2925 .name = "wm8994-aif2",
2928 .stream_name = "AIF2 Playback",
2931 .rates = WM8994_RATES,
2932 .formats = WM8994_FORMATS,
2936 .stream_name = "AIF2 Capture",
2939 .rates = WM8994_RATES,
2940 .formats = WM8994_FORMATS,
2943 .probe = wm8994_aif2_probe,
2944 .ops = &wm8994_aif2_dai_ops,
2947 .name = "wm8994-aif3",
2950 .stream_name = "AIF3 Playback",
2953 .rates = WM8994_RATES,
2954 .formats = WM8994_FORMATS,
2958 .stream_name = "AIF3 Capture",
2961 .rates = WM8994_RATES,
2962 .formats = WM8994_FORMATS,
2965 .ops = &wm8994_aif3_dai_ops,
2970 static int wm8994_codec_suspend(struct snd_soc_codec *codec)
2972 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2975 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2976 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
2977 sizeof(struct wm8994_fll_config));
2978 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
2980 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2984 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2989 static int wm8994_codec_resume(struct snd_soc_codec *codec)
2991 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2992 struct wm8994 *control = wm8994->wm8994;
2994 unsigned int val, mask;
2996 if (wm8994->revision < 4) {
2997 /* force a HW read */
2998 ret = regmap_read(control->regmap,
2999 WM8994_POWER_MANAGEMENT_5, &val);
3001 /* modify the cache only */
3002 codec->cache_only = 1;
3003 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
3004 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
3006 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
3008 codec->cache_only = 0;
3011 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3012 if (!wm8994->fll_suspend[i].out)
3015 ret = _wm8994_set_fll(codec, i + 1,
3016 wm8994->fll_suspend[i].src,
3017 wm8994->fll_suspend[i].in,
3018 wm8994->fll_suspend[i].out);
3020 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
3027 #define wm8994_codec_suspend NULL
3028 #define wm8994_codec_resume NULL
3031 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3033 struct snd_soc_codec *codec = wm8994->codec;
3034 struct wm8994_pdata *pdata = wm8994->pdata;
3035 struct snd_kcontrol_new controls[] = {
3036 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3037 wm8994->retune_mobile_enum,
3038 wm8994_get_retune_mobile_enum,
3039 wm8994_put_retune_mobile_enum),
3040 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3041 wm8994->retune_mobile_enum,
3042 wm8994_get_retune_mobile_enum,
3043 wm8994_put_retune_mobile_enum),
3044 SOC_ENUM_EXT("AIF2 EQ Mode",
3045 wm8994->retune_mobile_enum,
3046 wm8994_get_retune_mobile_enum,
3047 wm8994_put_retune_mobile_enum),
3052 /* We need an array of texts for the enum API but the number
3053 * of texts is likely to be less than the number of
3054 * configurations due to the sample rate dependency of the
3055 * configurations. */
3056 wm8994->num_retune_mobile_texts = 0;
3057 wm8994->retune_mobile_texts = NULL;
3058 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3059 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3060 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3061 wm8994->retune_mobile_texts[j]) == 0)
3065 if (j != wm8994->num_retune_mobile_texts)
3068 /* Expand the array... */
3069 t = krealloc(wm8994->retune_mobile_texts,
3071 (wm8994->num_retune_mobile_texts + 1),
3076 /* ...store the new entry... */
3077 t[wm8994->num_retune_mobile_texts] =
3078 pdata->retune_mobile_cfgs[i].name;
3080 /* ...and remember the new version. */
3081 wm8994->num_retune_mobile_texts++;
3082 wm8994->retune_mobile_texts = t;
3085 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
3086 wm8994->num_retune_mobile_texts);
3088 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
3089 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3091 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
3092 ARRAY_SIZE(controls));
3094 dev_err(wm8994->codec->dev,
3095 "Failed to add ReTune Mobile controls: %d\n", ret);
3098 static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3100 struct snd_soc_codec *codec = wm8994->codec;
3101 struct wm8994_pdata *pdata = wm8994->pdata;
3107 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
3108 pdata->lineout2_diff,
3113 pdata->micbias1_lvl,
3114 pdata->micbias2_lvl);
3116 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3118 if (pdata->num_drc_cfgs) {
3119 struct snd_kcontrol_new controls[] = {
3120 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3121 wm8994_get_drc_enum, wm8994_put_drc_enum),
3122 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3123 wm8994_get_drc_enum, wm8994_put_drc_enum),
3124 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3125 wm8994_get_drc_enum, wm8994_put_drc_enum),
3128 /* We need an array of texts for the enum API */
3129 wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
3130 sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
3131 if (!wm8994->drc_texts) {
3132 dev_err(wm8994->codec->dev,
3133 "Failed to allocate %d DRC config texts\n",
3134 pdata->num_drc_cfgs);
3138 for (i = 0; i < pdata->num_drc_cfgs; i++)
3139 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3141 wm8994->drc_enum.max = pdata->num_drc_cfgs;
3142 wm8994->drc_enum.texts = wm8994->drc_texts;
3144 ret = snd_soc_add_codec_controls(wm8994->codec, controls,
3145 ARRAY_SIZE(controls));
3147 dev_err(wm8994->codec->dev,
3148 "Failed to add DRC mode controls: %d\n", ret);
3150 for (i = 0; i < WM8994_NUM_DRC; i++)
3151 wm8994_set_drc(codec, i);
3154 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
3155 pdata->num_retune_mobile_cfgs);
3157 if (pdata->num_retune_mobile_cfgs)
3158 wm8994_handle_retune_mobile_pdata(wm8994);
3160 snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
3161 ARRAY_SIZE(wm8994_eq_controls));
3163 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3164 if (pdata->micbias[i]) {
3165 snd_soc_write(codec, WM8958_MICBIAS1 + i,
3166 pdata->micbias[i] & 0xffff);
3172 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3174 * @codec: WM8994 codec
3175 * @jack: jack to report detection events on
3176 * @micbias: microphone bias to detect on
3178 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3179 * being used to bring out signals to the processor then only platform
3180 * data configuration is needed for WM8994 and processor GPIOs should
3181 * be configured using snd_soc_jack_add_gpios() instead.
3183 * Configuration of detection levels is available via the micbias1_lvl
3184 * and micbias2_lvl platform data members.
3186 int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3189 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3190 struct wm8994_micdet *micdet;
3191 struct wm8994 *control = wm8994->wm8994;
3194 if (control->type != WM8994) {
3195 dev_warn(codec->dev, "Not a WM8994\n");
3201 micdet = &wm8994->micdet[0];
3203 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3206 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3210 micdet = &wm8994->micdet[1];
3212 ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
3215 ret = snd_soc_dapm_disable_pin(&codec->dapm,
3219 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
3224 dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
3227 dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
3230 /* Store the configuration */
3231 micdet->jack = jack;
3232 micdet->detecting = true;
3234 /* If either of the jacks is set up then enable detection */
3235 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3236 reg = WM8994_MICD_ENA;
3240 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3242 snd_soc_dapm_sync(&codec->dapm);
3246 EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3248 static void wm8994_mic_work(struct work_struct *work)
3250 struct wm8994_priv *priv = container_of(work,
3253 struct regmap *regmap = priv->wm8994->regmap;
3254 struct device *dev = priv->wm8994->dev;
3259 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, ®);
3261 dev_err(dev, "Failed to read microphone status: %d\n",
3266 dev_dbg(dev, "Microphone status: %x\n", reg);
3269 if (reg & WM8994_MIC1_DET_STS) {
3270 if (priv->micdet[0].detecting)
3271 report = SND_JACK_HEADSET;
3273 if (reg & WM8994_MIC1_SHRT_STS) {
3274 if (priv->micdet[0].detecting)
3275 report = SND_JACK_HEADPHONE;
3277 report |= SND_JACK_BTN_0;
3280 priv->micdet[0].detecting = false;
3282 priv->micdet[0].detecting = true;
3284 snd_soc_jack_report(priv->micdet[0].jack, report,
3285 SND_JACK_HEADSET | SND_JACK_BTN_0);
3288 if (reg & WM8994_MIC2_DET_STS) {
3289 if (priv->micdet[1].detecting)
3290 report = SND_JACK_HEADSET;
3292 if (reg & WM8994_MIC2_SHRT_STS) {
3293 if (priv->micdet[1].detecting)
3294 report = SND_JACK_HEADPHONE;
3296 report |= SND_JACK_BTN_0;
3299 priv->micdet[1].detecting = false;
3301 priv->micdet[1].detecting = true;
3303 snd_soc_jack_report(priv->micdet[1].jack, report,
3304 SND_JACK_HEADSET | SND_JACK_BTN_0);
3307 static irqreturn_t wm8994_mic_irq(int irq, void *data)
3309 struct wm8994_priv *priv = data;
3310 struct snd_soc_codec *codec = priv->codec;
3312 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3313 trace_snd_soc_jack_irq(dev_name(codec->dev));
3316 pm_wakeup_event(codec->dev, 300);
3318 schedule_delayed_work(&priv->mic_work, msecs_to_jiffies(250));
3323 /* Default microphone detection handler for WM8958 - the user can
3324 * override this if they wish.
3326 static void wm8958_default_micdet(u16 status, void *data)
3328 struct snd_soc_codec *codec = data;
3329 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3332 dev_dbg(codec->dev, "MICDET %x\n", status);
3334 /* Either nothing present or just starting detection */
3335 if (!(status & WM8958_MICD_STS)) {
3336 if (!wm8994->jackdet) {
3337 /* If nothing present then clear our statuses */
3338 dev_dbg(codec->dev, "Detected open circuit\n");
3339 wm8994->jack_mic = false;
3340 wm8994->mic_detecting = true;
3342 wm8958_micd_set_rate(codec);
3344 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3351 /* If the measurement is showing a high impedence we've got a
3354 if (wm8994->mic_detecting && (status & 0x600)) {
3355 dev_dbg(codec->dev, "Detected microphone\n");
3357 wm8994->mic_detecting = false;
3358 wm8994->jack_mic = true;
3360 wm8958_micd_set_rate(codec);
3362 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3367 if (wm8994->mic_detecting && status & 0xfc) {
3368 dev_dbg(codec->dev, "Detected headphone\n");
3369 wm8994->mic_detecting = false;
3371 wm8958_micd_set_rate(codec);
3373 /* If we have jackdet that will detect removal */
3374 if (wm8994->jackdet) {
3375 mutex_lock(&wm8994->accdet_lock);
3377 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3378 WM8958_MICD_ENA, 0);
3380 wm1811_jackdet_set_mode(codec,
3381 WM1811_JACKDET_MODE_JACK);
3383 mutex_unlock(&wm8994->accdet_lock);
3385 if (wm8994->pdata->jd_ext_cap)
3386 snd_soc_dapm_disable_pin(&codec->dapm,
3390 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3394 /* Report short circuit as a button */
3395 if (wm8994->jack_mic) {
3398 report |= SND_JACK_BTN_0;
3401 report |= SND_JACK_BTN_1;
3404 report |= SND_JACK_BTN_2;
3407 report |= SND_JACK_BTN_3;
3410 report |= SND_JACK_BTN_4;
3413 report |= SND_JACK_BTN_5;
3415 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3420 static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3422 struct wm8994_priv *wm8994 = data;
3423 struct snd_soc_codec *codec = wm8994->codec;
3427 mutex_lock(&wm8994->accdet_lock);
3429 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3431 dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
3432 mutex_unlock(&wm8994->accdet_lock);
3436 dev_dbg(codec->dev, "JACKDET %x\n", reg);
3438 present = reg & WM1811_JACKDET_LVL;
3441 dev_dbg(codec->dev, "Jack detected\n");
3443 wm8958_micd_set_rate(codec);
3445 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3446 WM8958_MICB2_DISCH, 0);
3448 /* Disable debounce while inserted */
3449 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3450 WM1811_JACKDET_DB, 0);
3453 * Start off measument of microphone impedence to find
3454 * out what's actually there.
3456 wm8994->mic_detecting = true;
3457 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3459 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3460 WM8958_MICD_ENA, WM8958_MICD_ENA);
3462 dev_dbg(codec->dev, "Jack not detected\n");
3464 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3465 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3467 /* Enable debounce while removed */
3468 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
3469 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3471 wm8994->mic_detecting = false;
3472 wm8994->jack_mic = false;
3473 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3474 WM8958_MICD_ENA, 0);
3475 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3478 mutex_unlock(&wm8994->accdet_lock);
3480 /* If required for an external cap force MICBIAS on */
3481 if (wm8994->pdata->jd_ext_cap) {
3483 snd_soc_dapm_force_enable_pin(&codec->dapm,
3486 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3490 snd_soc_jack_report(wm8994->micdet[0].jack,
3491 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3493 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3494 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3501 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3503 * @codec: WM8958 codec
3504 * @jack: jack to report detection events on
3506 * Enable microphone detection functionality for the WM8958. By
3507 * default simple detection which supports the detection of up to 6
3508 * buttons plus video and microphone functionality is supported.
3510 * The WM8958 has an advanced jack detection facility which is able to
3511 * support complex accessory detection, especially when used in
3512 * conjunction with external circuitry. In order to provide maximum
3513 * flexiblity a callback is provided which allows a completely custom
3514 * detection algorithm.
3516 int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3517 wm8958_micdet_cb cb, void *cb_data)
3519 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3520 struct wm8994 *control = wm8994->wm8994;
3523 switch (control->type) {
3533 dev_dbg(codec->dev, "Using default micdet callback\n");
3534 cb = wm8958_default_micdet;
3538 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
3539 snd_soc_dapm_sync(&codec->dapm);
3541 wm8994->micdet[0].jack = jack;
3542 wm8994->jack_cb = cb;
3543 wm8994->jack_cb_data = cb_data;
3545 wm8994->mic_detecting = true;
3546 wm8994->jack_mic = false;
3548 wm8958_micd_set_rate(codec);
3550 /* Detect microphones and short circuits by default */
3551 if (wm8994->pdata->micd_lvl_sel)
3552 micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
3554 micd_lvl_sel = 0x41;
3556 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3557 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3558 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3560 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
3561 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
3563 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
3566 * If we can use jack detection start off with that,
3567 * otherwise jump straight to microphone detection.
3569 if (wm8994->jackdet) {
3570 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3572 WM8958_MICB2_DISCH);
3573 snd_soc_update_bits(codec, WM8994_LDO_1,
3574 WM8994_LDO1_DISCH, 0);
3575 wm1811_jackdet_set_mode(codec,
3576 WM1811_JACKDET_MODE_JACK);
3578 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3579 WM8958_MICD_ENA, WM8958_MICD_ENA);
3583 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3584 WM8958_MICD_ENA, 0);
3585 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
3586 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
3587 snd_soc_dapm_sync(&codec->dapm);
3592 EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3594 static irqreturn_t wm8958_mic_irq(int irq, void *data)
3596 struct wm8994_priv *wm8994 = data;
3597 struct snd_soc_codec *codec = wm8994->codec;
3601 * Jack detection may have detected a removal simulataneously
3602 * with an update of the MICDET status; if so it will have
3603 * stopped detection and we can ignore this interrupt.
3605 if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
3608 /* We may occasionally read a detection without an impedence
3609 * range being provided - if that happens loop again.
3613 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3616 "Failed to read mic detect status: %d\n",
3621 if (!(reg & WM8958_MICD_VALID)) {
3622 dev_dbg(codec->dev, "Mic detect data not valid\n");
3626 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3633 dev_warn(codec->dev, "No impedence range reported for jack\n");
3635 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3636 trace_snd_soc_jack_irq(dev_name(codec->dev));
3639 if (wm8994->jack_cb)
3640 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3642 dev_warn(codec->dev, "Accessory detection with no callback\n");
3648 static irqreturn_t wm8994_fifo_error(int irq, void *data)
3650 struct snd_soc_codec *codec = data;
3652 dev_err(codec->dev, "FIFO error\n");
3657 static irqreturn_t wm8994_temp_warn(int irq, void *data)
3659 struct snd_soc_codec *codec = data;
3661 dev_err(codec->dev, "Thermal warning\n");
3666 static irqreturn_t wm8994_temp_shut(int irq, void *data)
3668 struct snd_soc_codec *codec = data;
3670 dev_crit(codec->dev, "Thermal shutdown\n");
3675 static int wm8994_codec_probe(struct snd_soc_codec *codec)
3677 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
3678 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3679 struct snd_soc_dapm_context *dapm = &codec->dapm;
3683 wm8994->codec = codec;
3684 codec->control_data = control->regmap;
3686 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
3688 wm8994->codec = codec;
3690 mutex_init(&wm8994->accdet_lock);
3691 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
3693 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3694 init_completion(&wm8994->fll_locked[i]);
3696 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3697 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3698 else if (wm8994->pdata && wm8994->pdata->irq_base)
3699 wm8994->micdet_irq = wm8994->pdata->irq_base +
3700 WM8994_IRQ_MIC1_DET;
3702 pm_runtime_enable(codec->dev);
3703 pm_runtime_idle(codec->dev);
3705 /* By default use idle_bias_off, will override for WM8994 */
3706 codec->dapm.idle_bias_off = 1;
3708 /* Set revision-specific configuration */
3709 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
3710 switch (control->type) {
3712 /* Single ended line outputs should have VMID on. */
3713 if (!wm8994->pdata->lineout1_diff ||
3714 !wm8994->pdata->lineout2_diff)
3715 codec->dapm.idle_bias_off = 0;
3717 switch (wm8994->revision) {
3720 wm8994->hubs.dcs_codes_l = -5;
3721 wm8994->hubs.dcs_codes_r = -5;
3722 wm8994->hubs.hp_startup_mode = 1;
3723 wm8994->hubs.dcs_readback_mode = 1;
3724 wm8994->hubs.series_startup = 1;
3727 wm8994->hubs.dcs_readback_mode = 2;
3733 wm8994->hubs.dcs_readback_mode = 1;
3734 wm8994->hubs.hp_startup_mode = 1;
3736 switch (wm8994->revision) {
3740 wm8994->fll_byp = true;
3746 wm8994->hubs.dcs_readback_mode = 2;
3747 wm8994->hubs.no_series_update = 1;
3748 wm8994->hubs.hp_startup_mode = 1;
3749 wm8994->hubs.no_cache_dac_hp_direct = true;
3750 wm8994->fll_byp = true;
3752 switch (wm8994->revision) {
3757 wm8994->hubs.dcs_codes_l = -9;
3758 wm8994->hubs.dcs_codes_r = -7;
3764 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3765 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3772 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
3773 wm8994_fifo_error, "FIFO error", codec);
3774 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
3775 wm8994_temp_warn, "Thermal warning", codec);
3776 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
3777 wm8994_temp_shut, "Thermal shutdown", codec);
3779 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
3780 wm_hubs_dcs_done, "DC servo done",
3783 wm8994->hubs.dcs_done_irq = true;
3785 switch (control->type) {
3787 if (wm8994->micdet_irq) {
3788 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3790 IRQF_TRIGGER_RISING,
3794 dev_warn(codec->dev,
3795 "Failed to request Mic1 detect IRQ: %d\n",
3799 ret = wm8994_request_irq(wm8994->wm8994,
3800 WM8994_IRQ_MIC1_SHRT,
3801 wm8994_mic_irq, "Mic 1 short",
3804 dev_warn(codec->dev,
3805 "Failed to request Mic1 short IRQ: %d\n",
3808 ret = wm8994_request_irq(wm8994->wm8994,
3809 WM8994_IRQ_MIC2_DET,
3810 wm8994_mic_irq, "Mic 2 detect",
3813 dev_warn(codec->dev,
3814 "Failed to request Mic2 detect IRQ: %d\n",
3817 ret = wm8994_request_irq(wm8994->wm8994,
3818 WM8994_IRQ_MIC2_SHRT,
3819 wm8994_mic_irq, "Mic 2 short",
3822 dev_warn(codec->dev,
3823 "Failed to request Mic2 short IRQ: %d\n",
3829 if (wm8994->micdet_irq) {
3830 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3832 IRQF_TRIGGER_RISING,
3836 dev_warn(codec->dev,
3837 "Failed to request Mic detect IRQ: %d\n",
3842 switch (control->type) {
3844 if (wm8994->revision > 1) {
3845 ret = wm8994_request_irq(wm8994->wm8994,
3847 wm1811_jackdet_irq, "JACKDET",
3850 wm8994->jackdet = true;
3857 wm8994->fll_locked_irq = true;
3858 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
3859 ret = wm8994_request_irq(wm8994->wm8994,
3860 WM8994_IRQ_FLL1_LOCK + i,
3861 wm8994_fll_locked_irq, "FLL lock",
3862 &wm8994->fll_locked[i]);
3864 wm8994->fll_locked_irq = false;
3867 /* Make sure we can read from the GPIOs if they're inputs */
3868 pm_runtime_get_sync(codec->dev);
3870 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3871 * configured on init - if a system wants to do this dynamically
3872 * at runtime we can deal with that then.
3874 ret = regmap_read(control->regmap, WM8994_GPIO_1, ®);
3876 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
3879 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3880 wm8994->lrclk_shared[0] = 1;
3881 wm8994_dai[0].symmetric_rates = 1;
3883 wm8994->lrclk_shared[0] = 0;
3886 ret = regmap_read(control->regmap, WM8994_GPIO_6, ®);
3888 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
3891 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3892 wm8994->lrclk_shared[1] = 1;
3893 wm8994_dai[1].symmetric_rates = 1;
3895 wm8994->lrclk_shared[1] = 0;
3898 pm_runtime_put(codec->dev);
3900 /* Latch volume update bits */
3901 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
3902 snd_soc_update_bits(codec, wm8994_vu_bits[i].reg,
3903 wm8994_vu_bits[i].mask,
3904 wm8994_vu_bits[i].mask);
3906 /* Set the low bit of the 3D stereo depth so TLV matches */
3907 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3908 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3909 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3910 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3911 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3912 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3913 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3914 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3915 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3917 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3918 * use this; it only affects behaviour on idle TDM clock
3920 switch (control->type) {
3923 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3924 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3930 /* Put MICBIAS into bypass mode by default on newer devices */
3931 switch (control->type) {
3934 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3935 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3936 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3937 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3943 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
3944 wm_hubs_update_class_w(codec);
3946 wm8994_handle_pdata(wm8994);
3948 wm_hubs_add_analogue_controls(codec);
3949 snd_soc_add_codec_controls(codec, wm8994_snd_controls,
3950 ARRAY_SIZE(wm8994_snd_controls));
3951 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
3952 ARRAY_SIZE(wm8994_dapm_widgets));
3954 switch (control->type) {
3956 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3957 ARRAY_SIZE(wm8994_specific_dapm_widgets));
3958 if (wm8994->revision < 4) {
3959 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3960 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3961 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3962 ARRAY_SIZE(wm8994_adc_revd_widgets));
3963 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3964 ARRAY_SIZE(wm8994_dac_revd_widgets));
3966 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3967 ARRAY_SIZE(wm8994_lateclk_widgets));
3968 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3969 ARRAY_SIZE(wm8994_adc_widgets));
3970 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3971 ARRAY_SIZE(wm8994_dac_widgets));
3975 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
3976 ARRAY_SIZE(wm8958_snd_controls));
3977 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3978 ARRAY_SIZE(wm8958_dapm_widgets));
3979 if (wm8994->revision < 1) {
3980 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3981 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3982 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3983 ARRAY_SIZE(wm8994_adc_revd_widgets));
3984 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3985 ARRAY_SIZE(wm8994_dac_revd_widgets));
3987 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3988 ARRAY_SIZE(wm8994_lateclk_widgets));
3989 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3990 ARRAY_SIZE(wm8994_adc_widgets));
3991 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3992 ARRAY_SIZE(wm8994_dac_widgets));
3997 snd_soc_add_codec_controls(codec, wm8958_snd_controls,
3998 ARRAY_SIZE(wm8958_snd_controls));
3999 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4000 ARRAY_SIZE(wm8958_dapm_widgets));
4001 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4002 ARRAY_SIZE(wm8994_lateclk_widgets));
4003 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4004 ARRAY_SIZE(wm8994_adc_widgets));
4005 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4006 ARRAY_SIZE(wm8994_dac_widgets));
4010 wm_hubs_add_analogue_routes(codec, 0, 0);
4011 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
4013 switch (control->type) {
4015 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4016 ARRAY_SIZE(wm8994_intercon));
4018 if (wm8994->revision < 4) {
4019 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4020 ARRAY_SIZE(wm8994_revd_intercon));
4021 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4022 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4024 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4025 ARRAY_SIZE(wm8994_lateclk_intercon));
4029 if (wm8994->revision < 1) {
4030 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4031 ARRAY_SIZE(wm8994_revd_intercon));
4032 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4033 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4035 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4036 ARRAY_SIZE(wm8994_lateclk_intercon));
4037 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4038 ARRAY_SIZE(wm8958_intercon));
4041 wm8958_dsp2_init(codec);
4044 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4045 ARRAY_SIZE(wm8994_lateclk_intercon));
4046 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4047 ARRAY_SIZE(wm8958_intercon));
4054 if (wm8994->jackdet)
4055 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4056 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4057 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4058 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
4059 if (wm8994->micdet_irq)
4060 free_irq(wm8994->micdet_irq, wm8994);
4061 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4062 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4063 &wm8994->fll_locked[i]);
4064 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4066 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4067 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4068 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
4073 static int wm8994_codec_remove(struct snd_soc_codec *codec)
4075 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
4076 struct wm8994 *control = wm8994->wm8994;
4079 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
4081 pm_runtime_disable(codec->dev);
4083 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4084 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4085 &wm8994->fll_locked[i]);
4087 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4089 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
4090 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
4091 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
4093 if (wm8994->jackdet)
4094 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4096 switch (control->type) {
4098 if (wm8994->micdet_irq)
4099 free_irq(wm8994->micdet_irq, wm8994);
4100 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
4102 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
4104 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4110 if (wm8994->micdet_irq)
4111 free_irq(wm8994->micdet_irq, wm8994);
4114 release_firmware(wm8994->mbc);
4115 release_firmware(wm8994->mbc_vss);
4116 release_firmware(wm8994->enh_eq);
4117 kfree(wm8994->retune_mobile_texts);
4121 static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4122 .probe = wm8994_codec_probe,
4123 .remove = wm8994_codec_remove,
4124 .suspend = wm8994_codec_suspend,
4125 .resume = wm8994_codec_resume,
4126 .set_bias_level = wm8994_set_bias_level,
4129 static int __devinit wm8994_probe(struct platform_device *pdev)
4131 struct wm8994_priv *wm8994;
4133 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4137 platform_set_drvdata(pdev, wm8994);
4139 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
4140 wm8994->pdata = dev_get_platdata(pdev->dev.parent);
4142 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
4143 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4146 static int __devexit wm8994_remove(struct platform_device *pdev)
4148 snd_soc_unregister_codec(&pdev->dev);
4152 #ifdef CONFIG_PM_SLEEP
4153 static int wm8994_suspend(struct device *dev)
4155 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4157 /* Drop down to power saving mode when system is suspended */
4158 if (wm8994->jackdet && !wm8994->active_refcount)
4159 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4160 WM1811_JACKDET_MODE_MASK,
4161 wm8994->jackdet_mode);
4166 static int wm8994_resume(struct device *dev)
4168 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4170 if (wm8994->jackdet && wm8994->jack_cb)
4171 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4172 WM1811_JACKDET_MODE_MASK,
4173 WM1811_JACKDET_MODE_AUDIO);
4179 static const struct dev_pm_ops wm8994_pm_ops = {
4180 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4183 static struct platform_driver wm8994_codec_driver = {
4185 .name = "wm8994-codec",
4186 .owner = THIS_MODULE,
4187 .pm = &wm8994_pm_ops,
4189 .probe = wm8994_probe,
4190 .remove = __devexit_p(wm8994_remove),
4193 module_platform_driver(wm8994_codec_driver);
4195 MODULE_DESCRIPTION("ASoC WM8994 driver");
4196 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4197 MODULE_LICENSE("GPL");
4198 MODULE_ALIAS("platform:wm8994-codec");