1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8994.c -- WM8994 ALSA SoC Audio driver
5 * Copyright 2009-12 Wolfson Microelectronics plc
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
15 #include <linux/gcd.h>
16 #include <linux/i2c.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/regulator/consumer.h>
20 #include <linux/slab.h>
21 #include <sound/core.h>
22 #include <sound/jack.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/initval.h>
27 #include <sound/tlv.h>
28 #include <trace/events/asoc.h>
30 #include <linux/mfd/wm8994/core.h>
31 #include <linux/mfd/wm8994/registers.h>
32 #include <linux/mfd/wm8994/pdata.h>
33 #include <linux/mfd/wm8994/gpio.h>
38 #define WM1811_JACKDET_MODE_NONE 0x0000
39 #define WM1811_JACKDET_MODE_JACK 0x0100
40 #define WM1811_JACKDET_MODE_MIC 0x0080
41 #define WM1811_JACKDET_MODE_AUDIO 0x0180
43 #define WM8994_NUM_DRC 3
44 #define WM8994_NUM_EQ 3
49 } wm8994_vu_bits[] = {
50 { WM8994_LEFT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
51 { WM8994_RIGHT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
52 { WM8994_LEFT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
53 { WM8994_RIGHT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
54 { WM8994_SPEAKER_VOLUME_LEFT, WM8994_SPKOUT_VU },
55 { WM8994_SPEAKER_VOLUME_RIGHT, WM8994_SPKOUT_VU },
56 { WM8994_LEFT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
57 { WM8994_RIGHT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
58 { WM8994_LEFT_OPGA_VOLUME, WM8994_MIXOUT_VU },
59 { WM8994_RIGHT_OPGA_VOLUME, WM8994_MIXOUT_VU },
61 { WM8994_AIF1_DAC1_LEFT_VOLUME, WM8994_AIF1DAC1_VU },
62 { WM8994_AIF1_DAC1_RIGHT_VOLUME, WM8994_AIF1DAC1_VU },
63 { WM8994_AIF1_DAC2_LEFT_VOLUME, WM8994_AIF1DAC2_VU },
64 { WM8994_AIF1_DAC2_RIGHT_VOLUME, WM8994_AIF1DAC2_VU },
65 { WM8994_AIF2_DAC_LEFT_VOLUME, WM8994_AIF2DAC_VU },
66 { WM8994_AIF2_DAC_RIGHT_VOLUME, WM8994_AIF2DAC_VU },
67 { WM8994_AIF1_ADC1_LEFT_VOLUME, WM8994_AIF1ADC1_VU },
68 { WM8994_AIF1_ADC1_RIGHT_VOLUME, WM8994_AIF1ADC1_VU },
69 { WM8994_AIF1_ADC2_LEFT_VOLUME, WM8994_AIF1ADC2_VU },
70 { WM8994_AIF1_ADC2_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
71 { WM8994_AIF2_ADC_LEFT_VOLUME, WM8994_AIF2ADC_VU },
72 { WM8994_AIF2_ADC_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
73 { WM8994_DAC1_LEFT_VOLUME, WM8994_DAC1_VU },
74 { WM8994_DAC1_RIGHT_VOLUME, WM8994_DAC1_VU },
75 { WM8994_DAC2_LEFT_VOLUME, WM8994_DAC2_VU },
76 { WM8994_DAC2_RIGHT_VOLUME, WM8994_DAC2_VU },
79 static int wm8994_drc_base[] = {
85 static int wm8994_retune_mobile_base[] = {
86 WM8994_AIF1_DAC1_EQ_GAINS_1,
87 WM8994_AIF1_DAC2_EQ_GAINS_1,
88 WM8994_AIF2_EQ_GAINS_1,
91 static const struct wm8958_micd_rate micdet_rates[] = {
92 { 32768, true, 1, 4 },
93 { 32768, false, 1, 1 },
94 { 44100 * 256, true, 7, 10 },
95 { 44100 * 256, false, 7, 10 },
98 static const struct wm8958_micd_rate jackdet_rates[] = {
99 { 32768, true, 0, 1 },
100 { 32768, false, 0, 1 },
101 { 44100 * 256, true, 10, 10 },
102 { 44100 * 256, false, 7, 8 },
105 static void wm8958_micd_set_rate(struct snd_soc_component *component)
107 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
108 struct wm8994 *control = wm8994->wm8994;
109 int best, i, sysclk, val;
111 const struct wm8958_micd_rate *rates;
114 idle = !wm8994->jack_mic;
116 sysclk = snd_soc_component_read32(component, WM8994_CLOCKING_1);
117 if (sysclk & WM8994_SYSCLK_SRC)
118 sysclk = wm8994->aifclk[1];
120 sysclk = wm8994->aifclk[0];
122 if (control->pdata.micd_rates) {
123 rates = control->pdata.micd_rates;
124 num_rates = control->pdata.num_micd_rates;
125 } else if (wm8994->jackdet) {
126 rates = jackdet_rates;
127 num_rates = ARRAY_SIZE(jackdet_rates);
129 rates = micdet_rates;
130 num_rates = ARRAY_SIZE(micdet_rates);
134 for (i = 0; i < num_rates; i++) {
135 if (rates[i].idle != idle)
137 if (abs(rates[i].sysclk - sysclk) <
138 abs(rates[best].sysclk - sysclk))
140 else if (rates[best].idle != idle)
144 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
145 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
147 dev_dbg(component->dev, "MICD rate %d,%d for %dHz %s\n",
148 rates[best].start, rates[best].rate, sysclk,
149 idle ? "idle" : "active");
151 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
152 WM8958_MICD_BIAS_STARTTIME_MASK |
153 WM8958_MICD_RATE_MASK, val);
156 static int configure_aif_clock(struct snd_soc_component *component, int aif)
158 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
168 switch (wm8994->sysclk[aif]) {
169 case WM8994_SYSCLK_MCLK1:
170 rate = wm8994->mclk[0];
173 case WM8994_SYSCLK_MCLK2:
175 rate = wm8994->mclk[1];
178 case WM8994_SYSCLK_FLL1:
180 rate = wm8994->fll[0].out;
183 case WM8994_SYSCLK_FLL2:
185 rate = wm8994->fll[1].out;
192 if (rate >= 13500000) {
194 reg1 |= WM8994_AIF1CLK_DIV;
196 dev_dbg(component->dev, "Dividing AIF%d clock to %dHz\n",
200 wm8994->aifclk[aif] = rate;
202 snd_soc_component_update_bits(component, WM8994_AIF1_CLOCKING_1 + offset,
203 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
209 static int configure_clock(struct snd_soc_component *component)
211 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
212 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
215 /* Bring up the AIF clocks first */
216 configure_aif_clock(component, 0);
217 configure_aif_clock(component, 1);
219 /* Then switch CLK_SYS over to the higher of them; a change
220 * can only happen as a result of a clocking change which can
221 * only be made outside of DAPM so we can safely redo the
225 /* If they're equal it doesn't matter which is used */
226 if (wm8994->aifclk[0] == wm8994->aifclk[1]) {
227 wm8958_micd_set_rate(component);
231 if (wm8994->aifclk[0] < wm8994->aifclk[1])
232 new = WM8994_SYSCLK_SRC;
236 change = snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
237 WM8994_SYSCLK_SRC, new);
239 snd_soc_dapm_sync(dapm);
241 wm8958_micd_set_rate(component);
246 static int check_clk_sys(struct snd_soc_dapm_widget *source,
247 struct snd_soc_dapm_widget *sink)
249 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
250 int reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
253 /* Check what we're currently using for CLK_SYS */
254 if (reg & WM8994_SYSCLK_SRC)
259 return strcmp(source->name, clk) == 0;
262 static const char *sidetone_hpf_text[] = {
263 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
266 static SOC_ENUM_SINGLE_DECL(sidetone_hpf,
267 WM8994_SIDETONE, 7, sidetone_hpf_text);
269 static const char *adc_hpf_text[] = {
270 "HiFi", "Voice 1", "Voice 2", "Voice 3"
273 static SOC_ENUM_SINGLE_DECL(aif1adc1_hpf,
274 WM8994_AIF1_ADC1_FILTERS, 13, adc_hpf_text);
276 static SOC_ENUM_SINGLE_DECL(aif1adc2_hpf,
277 WM8994_AIF1_ADC2_FILTERS, 13, adc_hpf_text);
279 static SOC_ENUM_SINGLE_DECL(aif2adc_hpf,
280 WM8994_AIF2_ADC_FILTERS, 13, adc_hpf_text);
282 static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
283 static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
284 static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
285 static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
286 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
287 static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
288 static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
290 #define WM8994_DRC_SWITCH(xname, reg, shift) \
291 SOC_SINGLE_EXT(xname, reg, shift, 1, 0, \
292 snd_soc_get_volsw, wm8994_put_drc_sw)
294 static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
295 struct snd_ctl_elem_value *ucontrol)
297 struct soc_mixer_control *mc =
298 (struct soc_mixer_control *)kcontrol->private_value;
299 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
302 /* Can't enable both ADC and DAC paths simultaneously */
303 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
304 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
305 WM8994_AIF1ADC1R_DRC_ENA_MASK;
307 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
309 ret = snd_soc_component_read32(component, mc->reg);
315 return snd_soc_put_volsw(kcontrol, ucontrol);
318 static void wm8994_set_drc(struct snd_soc_component *component, int drc)
320 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
321 struct wm8994 *control = wm8994->wm8994;
322 struct wm8994_pdata *pdata = &control->pdata;
323 int base = wm8994_drc_base[drc];
324 int cfg = wm8994->drc_cfg[drc];
327 /* Save any enables; the configuration should clear them. */
328 save = snd_soc_component_read32(component, base);
329 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
330 WM8994_AIF1ADC1R_DRC_ENA;
332 for (i = 0; i < WM8994_DRC_REGS; i++)
333 snd_soc_component_update_bits(component, base + i, 0xffff,
334 pdata->drc_cfgs[cfg].regs[i]);
336 snd_soc_component_update_bits(component, base, WM8994_AIF1DAC1_DRC_ENA |
337 WM8994_AIF1ADC1L_DRC_ENA |
338 WM8994_AIF1ADC1R_DRC_ENA, save);
341 /* Icky as hell but saves code duplication */
342 static int wm8994_get_drc(const char *name)
344 if (strcmp(name, "AIF1DRC1 Mode") == 0)
346 if (strcmp(name, "AIF1DRC2 Mode") == 0)
348 if (strcmp(name, "AIF2DRC Mode") == 0)
353 static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
354 struct snd_ctl_elem_value *ucontrol)
356 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
357 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
358 struct wm8994 *control = wm8994->wm8994;
359 struct wm8994_pdata *pdata = &control->pdata;
360 int drc = wm8994_get_drc(kcontrol->id.name);
361 int value = ucontrol->value.enumerated.item[0];
366 if (value >= pdata->num_drc_cfgs)
369 wm8994->drc_cfg[drc] = value;
371 wm8994_set_drc(component, drc);
376 static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
377 struct snd_ctl_elem_value *ucontrol)
379 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
380 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
381 int drc = wm8994_get_drc(kcontrol->id.name);
385 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
390 static void wm8994_set_retune_mobile(struct snd_soc_component *component, int block)
392 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
393 struct wm8994 *control = wm8994->wm8994;
394 struct wm8994_pdata *pdata = &control->pdata;
395 int base = wm8994_retune_mobile_base[block];
396 int iface, best, best_val, save, i, cfg;
398 if (!pdata || !wm8994->num_retune_mobile_texts)
413 /* Find the version of the currently selected configuration
414 * with the nearest sample rate. */
415 cfg = wm8994->retune_mobile_cfg[block];
418 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
419 if (strcmp(pdata->retune_mobile_cfgs[i].name,
420 wm8994->retune_mobile_texts[cfg]) == 0 &&
421 abs(pdata->retune_mobile_cfgs[i].rate
422 - wm8994->dac_rates[iface]) < best_val) {
424 best_val = abs(pdata->retune_mobile_cfgs[i].rate
425 - wm8994->dac_rates[iface]);
429 dev_dbg(component->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
431 pdata->retune_mobile_cfgs[best].name,
432 pdata->retune_mobile_cfgs[best].rate,
433 wm8994->dac_rates[iface]);
435 /* The EQ will be disabled while reconfiguring it, remember the
436 * current configuration.
438 save = snd_soc_component_read32(component, base);
439 save &= WM8994_AIF1DAC1_EQ_ENA;
441 for (i = 0; i < WM8994_EQ_REGS; i++)
442 snd_soc_component_update_bits(component, base + i, 0xffff,
443 pdata->retune_mobile_cfgs[best].regs[i]);
445 snd_soc_component_update_bits(component, base, WM8994_AIF1DAC1_EQ_ENA, save);
448 /* Icky as hell but saves code duplication */
449 static int wm8994_get_retune_mobile_block(const char *name)
451 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
453 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
455 if (strcmp(name, "AIF2 EQ Mode") == 0)
460 static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
464 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
465 struct wm8994 *control = wm8994->wm8994;
466 struct wm8994_pdata *pdata = &control->pdata;
467 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
468 int value = ucontrol->value.enumerated.item[0];
473 if (value >= pdata->num_retune_mobile_cfgs)
476 wm8994->retune_mobile_cfg[block] = value;
478 wm8994_set_retune_mobile(component, block);
483 static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
484 struct snd_ctl_elem_value *ucontrol)
486 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
487 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
488 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
493 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
498 static const char *aif_chan_src_text[] = {
502 static SOC_ENUM_SINGLE_DECL(aif1adcl_src,
503 WM8994_AIF1_CONTROL_1, 15, aif_chan_src_text);
505 static SOC_ENUM_SINGLE_DECL(aif1adcr_src,
506 WM8994_AIF1_CONTROL_1, 14, aif_chan_src_text);
508 static SOC_ENUM_SINGLE_DECL(aif2adcl_src,
509 WM8994_AIF2_CONTROL_1, 15, aif_chan_src_text);
511 static SOC_ENUM_SINGLE_DECL(aif2adcr_src,
512 WM8994_AIF2_CONTROL_1, 14, aif_chan_src_text);
514 static SOC_ENUM_SINGLE_DECL(aif1dacl_src,
515 WM8994_AIF1_CONTROL_2, 15, aif_chan_src_text);
517 static SOC_ENUM_SINGLE_DECL(aif1dacr_src,
518 WM8994_AIF1_CONTROL_2, 14, aif_chan_src_text);
520 static SOC_ENUM_SINGLE_DECL(aif2dacl_src,
521 WM8994_AIF2_CONTROL_2, 15, aif_chan_src_text);
523 static SOC_ENUM_SINGLE_DECL(aif2dacr_src,
524 WM8994_AIF2_CONTROL_2, 14, aif_chan_src_text);
526 static const char *osr_text[] = {
527 "Low Power", "High Performance",
530 static SOC_ENUM_SINGLE_DECL(dac_osr,
531 WM8994_OVERSAMPLING, 0, osr_text);
533 static SOC_ENUM_SINGLE_DECL(adc_osr,
534 WM8994_OVERSAMPLING, 1, osr_text);
536 static const struct snd_kcontrol_new wm8994_snd_controls[] = {
537 SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
538 WM8994_AIF1_ADC1_RIGHT_VOLUME,
539 1, 119, 0, digital_tlv),
540 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
541 WM8994_AIF1_ADC2_RIGHT_VOLUME,
542 1, 119, 0, digital_tlv),
543 SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
544 WM8994_AIF2_ADC_RIGHT_VOLUME,
545 1, 119, 0, digital_tlv),
547 SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
548 SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
549 SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
550 SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
552 SOC_ENUM("AIF1DACL Source", aif1dacl_src),
553 SOC_ENUM("AIF1DACR Source", aif1dacr_src),
554 SOC_ENUM("AIF2DACL Source", aif2dacl_src),
555 SOC_ENUM("AIF2DACR Source", aif2dacr_src),
557 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
558 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
559 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
560 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
561 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
562 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
564 SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
565 SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
567 SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
568 SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
569 SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
571 WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
572 WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
573 WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
575 WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
576 WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
577 WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
579 WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
580 WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
581 WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
583 SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
585 SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
587 SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
589 SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
591 SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
592 SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
594 SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
595 SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
597 SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
598 SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
600 SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
601 SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
603 SOC_ENUM("ADC OSR", adc_osr),
604 SOC_ENUM("DAC OSR", dac_osr),
606 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
607 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
608 SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
609 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
611 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
612 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
613 SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
614 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
616 SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
617 6, 1, 1, wm_hubs_spkmix_tlv),
618 SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
619 2, 1, 1, wm_hubs_spkmix_tlv),
621 SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
622 6, 1, 1, wm_hubs_spkmix_tlv),
623 SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
624 2, 1, 1, wm_hubs_spkmix_tlv),
626 SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
627 10, 15, 0, wm8994_3d_tlv),
628 SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
630 SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
631 10, 15, 0, wm8994_3d_tlv),
632 SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
634 SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
635 10, 15, 0, wm8994_3d_tlv),
636 SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
640 static const struct snd_kcontrol_new wm8994_eq_controls[] = {
641 SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
643 SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
645 SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
647 SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
649 SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
652 SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
654 SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
656 SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
658 SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
660 SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
663 SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
665 SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
667 SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
669 SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
671 SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
675 static const struct snd_kcontrol_new wm8994_drc_controls[] = {
676 SND_SOC_BYTES_MASK("AIF1.1 DRC", WM8994_AIF1_DRC1_1, 5,
677 WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
678 WM8994_AIF1ADC1R_DRC_ENA),
679 SND_SOC_BYTES_MASK("AIF1.2 DRC", WM8994_AIF1_DRC2_1, 5,
680 WM8994_AIF1DAC2_DRC_ENA | WM8994_AIF1ADC2L_DRC_ENA |
681 WM8994_AIF1ADC2R_DRC_ENA),
682 SND_SOC_BYTES_MASK("AIF2 DRC", WM8994_AIF2_DRC_1, 5,
683 WM8994_AIF2DAC_DRC_ENA | WM8994_AIF2ADCL_DRC_ENA |
684 WM8994_AIF2ADCR_DRC_ENA),
687 static const char *wm8958_ng_text[] = {
688 "30ms", "125ms", "250ms", "500ms",
691 static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac1_ng_hold,
692 WM8958_AIF1_DAC1_NOISE_GATE,
693 WM8958_AIF1DAC1_NG_THR_SHIFT,
696 static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac2_ng_hold,
697 WM8958_AIF1_DAC2_NOISE_GATE,
698 WM8958_AIF1DAC2_NG_THR_SHIFT,
701 static SOC_ENUM_SINGLE_DECL(wm8958_aif2dac_ng_hold,
702 WM8958_AIF2_DAC_NOISE_GATE,
703 WM8958_AIF2DAC_NG_THR_SHIFT,
706 static const struct snd_kcontrol_new wm8958_snd_controls[] = {
707 SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
709 SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
710 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
711 SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
712 SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
713 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
716 SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
717 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
718 SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
719 SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
720 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
723 SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
724 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
725 SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
726 SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
727 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
731 static const struct snd_kcontrol_new wm1811_snd_controls[] = {
732 SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
734 SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
738 /* We run all mode setting through a function to enforce audio mode */
739 static void wm1811_jackdet_set_mode(struct snd_soc_component *component, u16 mode)
741 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
743 if (!wm8994->jackdet || !wm8994->micdet[0].jack)
746 if (wm8994->active_refcount)
747 mode = WM1811_JACKDET_MODE_AUDIO;
749 if (mode == wm8994->jackdet_mode)
752 wm8994->jackdet_mode = mode;
754 /* Always use audio mode to detect while the system is active */
755 if (mode != WM1811_JACKDET_MODE_NONE)
756 mode = WM1811_JACKDET_MODE_AUDIO;
758 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
759 WM1811_JACKDET_MODE_MASK, mode);
762 static void active_reference(struct snd_soc_component *component)
764 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
766 mutex_lock(&wm8994->accdet_lock);
768 wm8994->active_refcount++;
770 dev_dbg(component->dev, "Active refcount incremented, now %d\n",
771 wm8994->active_refcount);
773 /* If we're using jack detection go into audio mode */
774 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_AUDIO);
776 mutex_unlock(&wm8994->accdet_lock);
779 static void active_dereference(struct snd_soc_component *component)
781 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
784 mutex_lock(&wm8994->accdet_lock);
786 wm8994->active_refcount--;
788 dev_dbg(component->dev, "Active refcount decremented, now %d\n",
789 wm8994->active_refcount);
791 if (wm8994->active_refcount == 0) {
792 /* Go into appropriate detection only mode */
793 if (wm8994->jack_mic || wm8994->mic_detecting)
794 mode = WM1811_JACKDET_MODE_MIC;
796 mode = WM1811_JACKDET_MODE_JACK;
798 wm1811_jackdet_set_mode(component, mode);
801 mutex_unlock(&wm8994->accdet_lock);
804 static int clk_sys_event(struct snd_soc_dapm_widget *w,
805 struct snd_kcontrol *kcontrol, int event)
807 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
808 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
811 case SND_SOC_DAPM_PRE_PMU:
812 return configure_clock(component);
814 case SND_SOC_DAPM_POST_PMU:
816 * JACKDET won't run until we start the clock and it
817 * only reports deltas, make sure we notify the state
818 * up the stack on startup. Use a *very* generous
819 * timeout for paranoia, there's no urgency and we
820 * don't want false reports.
822 if (wm8994->jackdet && !wm8994->clk_has_run) {
823 queue_delayed_work(system_power_efficient_wq,
824 &wm8994->jackdet_bootstrap,
825 msecs_to_jiffies(1000));
826 wm8994->clk_has_run = true;
830 case SND_SOC_DAPM_POST_PMD:
831 configure_clock(component);
838 static void vmid_reference(struct snd_soc_component *component)
840 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
842 pm_runtime_get_sync(component->dev);
844 wm8994->vmid_refcount++;
846 dev_dbg(component->dev, "Referencing VMID, refcount is now %d\n",
847 wm8994->vmid_refcount);
849 if (wm8994->vmid_refcount == 1) {
850 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
851 WM8994_LINEOUT1_DISCH |
852 WM8994_LINEOUT2_DISCH, 0);
854 wm_hubs_vmid_ena(component);
856 switch (wm8994->vmid_mode) {
858 WARN_ON(NULL == "Invalid VMID mode");
860 case WM8994_VMID_NORMAL:
861 /* Startup bias, VMID ramp & buffer */
862 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
865 WM8994_STARTUP_BIAS_ENA |
866 WM8994_VMID_BUF_ENA |
867 WM8994_VMID_RAMP_MASK,
869 WM8994_STARTUP_BIAS_ENA |
870 WM8994_VMID_BUF_ENA |
871 (0x2 << WM8994_VMID_RAMP_SHIFT));
873 /* Main bias enable, VMID=2x40k */
874 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
876 WM8994_VMID_SEL_MASK,
877 WM8994_BIAS_ENA | 0x2);
881 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
882 WM8994_VMID_RAMP_MASK |
887 case WM8994_VMID_FORCE:
888 /* Startup bias, slow VMID ramp & buffer */
889 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
892 WM8994_STARTUP_BIAS_ENA |
893 WM8994_VMID_BUF_ENA |
894 WM8994_VMID_RAMP_MASK,
896 WM8994_STARTUP_BIAS_ENA |
897 WM8994_VMID_BUF_ENA |
898 (0x2 << WM8994_VMID_RAMP_SHIFT));
900 /* Main bias enable, VMID=2x40k */
901 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
903 WM8994_VMID_SEL_MASK,
904 WM8994_BIAS_ENA | 0x2);
908 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
909 WM8994_VMID_RAMP_MASK |
917 static void vmid_dereference(struct snd_soc_component *component)
919 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
921 wm8994->vmid_refcount--;
923 dev_dbg(component->dev, "Dereferencing VMID, refcount is now %d\n",
924 wm8994->vmid_refcount);
926 if (wm8994->vmid_refcount == 0) {
927 if (wm8994->hubs.lineout1_se)
928 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
929 WM8994_LINEOUT1N_ENA |
930 WM8994_LINEOUT1P_ENA,
931 WM8994_LINEOUT1N_ENA |
932 WM8994_LINEOUT1P_ENA);
934 if (wm8994->hubs.lineout2_se)
935 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
936 WM8994_LINEOUT2N_ENA |
937 WM8994_LINEOUT2P_ENA,
938 WM8994_LINEOUT2N_ENA |
939 WM8994_LINEOUT2P_ENA);
941 /* Start discharging VMID */
942 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
948 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
949 WM8994_VMID_SEL_MASK, 0);
953 /* Active discharge */
954 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
955 WM8994_LINEOUT1_DISCH |
956 WM8994_LINEOUT2_DISCH,
957 WM8994_LINEOUT1_DISCH |
958 WM8994_LINEOUT2_DISCH);
960 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
961 WM8994_LINEOUT1N_ENA |
962 WM8994_LINEOUT1P_ENA |
963 WM8994_LINEOUT2N_ENA |
964 WM8994_LINEOUT2P_ENA, 0);
966 /* Switch off startup biases */
967 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
969 WM8994_STARTUP_BIAS_ENA |
970 WM8994_VMID_BUF_ENA |
971 WM8994_VMID_RAMP_MASK, 0);
973 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
974 WM8994_VMID_SEL_MASK, 0);
977 pm_runtime_put(component->dev);
980 static int vmid_event(struct snd_soc_dapm_widget *w,
981 struct snd_kcontrol *kcontrol, int event)
983 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
986 case SND_SOC_DAPM_PRE_PMU:
987 vmid_reference(component);
990 case SND_SOC_DAPM_POST_PMD:
991 vmid_dereference(component);
998 static bool wm8994_check_class_w_digital(struct snd_soc_component *component)
1000 int source = 0; /* GCC flow analysis can't track enable */
1003 /* We also need the same AIF source for L/R and only one path */
1004 reg = snd_soc_component_read32(component, WM8994_DAC1_LEFT_MIXER_ROUTING);
1006 case WM8994_AIF2DACL_TO_DAC1L:
1007 dev_vdbg(component->dev, "Class W source AIF2DAC\n");
1008 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1010 case WM8994_AIF1DAC2L_TO_DAC1L:
1011 dev_vdbg(component->dev, "Class W source AIF1DAC2\n");
1012 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1014 case WM8994_AIF1DAC1L_TO_DAC1L:
1015 dev_vdbg(component->dev, "Class W source AIF1DAC1\n");
1016 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1019 dev_vdbg(component->dev, "DAC mixer setting: %x\n", reg);
1023 reg_r = snd_soc_component_read32(component, WM8994_DAC1_RIGHT_MIXER_ROUTING);
1025 dev_vdbg(component->dev, "Left and right DAC mixers different\n");
1029 /* Set the source up */
1030 snd_soc_component_update_bits(component, WM8994_CLASS_W_1,
1031 WM8994_CP_DYN_SRC_SEL_MASK, source);
1036 static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1037 struct snd_kcontrol *kcontrol, int event)
1039 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1040 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1041 struct wm8994 *control = wm8994->wm8994;
1042 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
1048 switch (control->type) {
1051 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1058 case SND_SOC_DAPM_PRE_PMU:
1059 /* Don't enable timeslot 2 if not in use */
1060 if (wm8994->channels[0] <= 2)
1061 mask &= ~(WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
1063 val = snd_soc_component_read32(component, WM8994_AIF1_CONTROL_1);
1064 if ((val & WM8994_AIF1ADCL_SRC) &&
1065 (val & WM8994_AIF1ADCR_SRC))
1066 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1067 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1068 !(val & WM8994_AIF1ADCR_SRC))
1069 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1071 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1072 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1074 val = snd_soc_component_read32(component, WM8994_AIF1_CONTROL_2);
1075 if ((val & WM8994_AIF1DACL_SRC) &&
1076 (val & WM8994_AIF1DACR_SRC))
1077 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1078 else if (!(val & WM8994_AIF1DACL_SRC) &&
1079 !(val & WM8994_AIF1DACR_SRC))
1080 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1082 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1083 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1085 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1087 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1089 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1090 WM8994_AIF1DSPCLK_ENA |
1091 WM8994_SYSDSPCLK_ENA,
1092 WM8994_AIF1DSPCLK_ENA |
1093 WM8994_SYSDSPCLK_ENA);
1094 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4, mask,
1095 WM8994_AIF1ADC1R_ENA |
1096 WM8994_AIF1ADC1L_ENA |
1097 WM8994_AIF1ADC2R_ENA |
1098 WM8994_AIF1ADC2L_ENA);
1099 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5, mask,
1100 WM8994_AIF1DAC1R_ENA |
1101 WM8994_AIF1DAC1L_ENA |
1102 WM8994_AIF1DAC2R_ENA |
1103 WM8994_AIF1DAC2L_ENA);
1106 case SND_SOC_DAPM_POST_PMU:
1107 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1108 snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1109 snd_soc_component_read32(component,
1110 wm8994_vu_bits[i].reg));
1113 case SND_SOC_DAPM_PRE_PMD:
1114 case SND_SOC_DAPM_POST_PMD:
1115 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1117 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1120 val = snd_soc_component_read32(component, WM8994_CLOCKING_1);
1121 if (val & WM8994_AIF2DSPCLK_ENA)
1122 val = WM8994_SYSDSPCLK_ENA;
1125 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1126 WM8994_SYSDSPCLK_ENA |
1127 WM8994_AIF1DSPCLK_ENA, val);
1134 static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1135 struct snd_kcontrol *kcontrol, int event)
1137 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1144 case SND_SOC_DAPM_PRE_PMU:
1145 val = snd_soc_component_read32(component, WM8994_AIF2_CONTROL_1);
1146 if ((val & WM8994_AIF2ADCL_SRC) &&
1147 (val & WM8994_AIF2ADCR_SRC))
1148 adc = WM8994_AIF2ADCR_ENA;
1149 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1150 !(val & WM8994_AIF2ADCR_SRC))
1151 adc = WM8994_AIF2ADCL_ENA;
1153 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1156 val = snd_soc_component_read32(component, WM8994_AIF2_CONTROL_2);
1157 if ((val & WM8994_AIF2DACL_SRC) &&
1158 (val & WM8994_AIF2DACR_SRC))
1159 dac = WM8994_AIF2DACR_ENA;
1160 else if (!(val & WM8994_AIF2DACL_SRC) &&
1161 !(val & WM8994_AIF2DACR_SRC))
1162 dac = WM8994_AIF2DACL_ENA;
1164 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1166 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1167 WM8994_AIF2ADCL_ENA |
1168 WM8994_AIF2ADCR_ENA, adc);
1169 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1170 WM8994_AIF2DACL_ENA |
1171 WM8994_AIF2DACR_ENA, dac);
1172 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1173 WM8994_AIF2DSPCLK_ENA |
1174 WM8994_SYSDSPCLK_ENA,
1175 WM8994_AIF2DSPCLK_ENA |
1176 WM8994_SYSDSPCLK_ENA);
1177 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1178 WM8994_AIF2ADCL_ENA |
1179 WM8994_AIF2ADCR_ENA,
1180 WM8994_AIF2ADCL_ENA |
1181 WM8994_AIF2ADCR_ENA);
1182 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1183 WM8994_AIF2DACL_ENA |
1184 WM8994_AIF2DACR_ENA,
1185 WM8994_AIF2DACL_ENA |
1186 WM8994_AIF2DACR_ENA);
1189 case SND_SOC_DAPM_POST_PMU:
1190 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1191 snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1192 snd_soc_component_read32(component,
1193 wm8994_vu_bits[i].reg));
1196 case SND_SOC_DAPM_PRE_PMD:
1197 case SND_SOC_DAPM_POST_PMD:
1198 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1199 WM8994_AIF2DACL_ENA |
1200 WM8994_AIF2DACR_ENA, 0);
1201 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1202 WM8994_AIF2ADCL_ENA |
1203 WM8994_AIF2ADCR_ENA, 0);
1205 val = snd_soc_component_read32(component, WM8994_CLOCKING_1);
1206 if (val & WM8994_AIF1DSPCLK_ENA)
1207 val = WM8994_SYSDSPCLK_ENA;
1210 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1211 WM8994_SYSDSPCLK_ENA |
1212 WM8994_AIF2DSPCLK_ENA, val);
1219 static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1220 struct snd_kcontrol *kcontrol, int event)
1222 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1223 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1226 case SND_SOC_DAPM_PRE_PMU:
1227 wm8994->aif1clk_enable = 1;
1229 case SND_SOC_DAPM_POST_PMD:
1230 wm8994->aif1clk_disable = 1;
1237 static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1238 struct snd_kcontrol *kcontrol, int event)
1240 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1241 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1244 case SND_SOC_DAPM_PRE_PMU:
1245 wm8994->aif2clk_enable = 1;
1247 case SND_SOC_DAPM_POST_PMD:
1248 wm8994->aif2clk_disable = 1;
1255 static int late_enable_ev(struct snd_soc_dapm_widget *w,
1256 struct snd_kcontrol *kcontrol, int event)
1258 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1259 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1262 case SND_SOC_DAPM_PRE_PMU:
1263 if (wm8994->aif1clk_enable) {
1264 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1265 snd_soc_component_update_bits(component, WM8994_AIF1_CLOCKING_1,
1266 WM8994_AIF1CLK_ENA_MASK,
1267 WM8994_AIF1CLK_ENA);
1268 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1269 wm8994->aif1clk_enable = 0;
1271 if (wm8994->aif2clk_enable) {
1272 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1273 snd_soc_component_update_bits(component, WM8994_AIF2_CLOCKING_1,
1274 WM8994_AIF2CLK_ENA_MASK,
1275 WM8994_AIF2CLK_ENA);
1276 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1277 wm8994->aif2clk_enable = 0;
1282 /* We may also have postponed startup of DSP, handle that. */
1283 wm8958_aif_ev(w, kcontrol, event);
1288 static int late_disable_ev(struct snd_soc_dapm_widget *w,
1289 struct snd_kcontrol *kcontrol, int event)
1291 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1292 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1295 case SND_SOC_DAPM_POST_PMD:
1296 if (wm8994->aif1clk_disable) {
1297 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1298 snd_soc_component_update_bits(component, WM8994_AIF1_CLOCKING_1,
1299 WM8994_AIF1CLK_ENA_MASK, 0);
1300 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1301 wm8994->aif1clk_disable = 0;
1303 if (wm8994->aif2clk_disable) {
1304 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1305 snd_soc_component_update_bits(component, WM8994_AIF2_CLOCKING_1,
1306 WM8994_AIF2CLK_ENA_MASK, 0);
1307 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1308 wm8994->aif2clk_disable = 0;
1316 static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1317 struct snd_kcontrol *kcontrol, int event)
1319 late_enable_ev(w, kcontrol, event);
1323 static int micbias_ev(struct snd_soc_dapm_widget *w,
1324 struct snd_kcontrol *kcontrol, int event)
1326 late_enable_ev(w, kcontrol, event);
1330 static int dac_ev(struct snd_soc_dapm_widget *w,
1331 struct snd_kcontrol *kcontrol, int event)
1333 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1334 unsigned int mask = 1 << w->shift;
1336 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1341 static const char *adc_mux_text[] = {
1346 static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
1348 static const struct snd_kcontrol_new adcl_mux =
1349 SOC_DAPM_ENUM("ADCL Mux", adc_enum);
1351 static const struct snd_kcontrol_new adcr_mux =
1352 SOC_DAPM_ENUM("ADCR Mux", adc_enum);
1354 static const struct snd_kcontrol_new left_speaker_mixer[] = {
1355 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1356 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1357 SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1358 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1359 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1362 static const struct snd_kcontrol_new right_speaker_mixer[] = {
1363 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1364 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1365 SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1366 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1367 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1370 /* Debugging; dump chip status after DAPM transitions */
1371 static int post_ev(struct snd_soc_dapm_widget *w,
1372 struct snd_kcontrol *kcontrol, int event)
1374 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1375 dev_dbg(component->dev, "SRC status: %x\n",
1376 snd_soc_component_read32(component,
1377 WM8994_RATE_STATUS));
1381 static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1382 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1384 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1388 static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1389 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1391 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1395 static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1396 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1398 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1402 static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1403 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1405 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1409 static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1410 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1412 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1414 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1416 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1418 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1422 static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1423 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1425 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1427 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1429 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1431 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1435 #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1436 SOC_SINGLE_EXT(xname, reg, shift, max, invert, \
1437 snd_soc_dapm_get_volsw, wm8994_put_class_w)
1439 static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1440 struct snd_ctl_elem_value *ucontrol)
1442 struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol);
1445 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1447 wm_hubs_update_class_w(component);
1452 static const struct snd_kcontrol_new dac1l_mix[] = {
1453 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1455 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1457 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1459 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1461 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1465 static const struct snd_kcontrol_new dac1r_mix[] = {
1466 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1468 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1470 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1472 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1474 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1478 static const char *sidetone_text[] = {
1479 "ADC/DMIC1", "DMIC2",
1482 static SOC_ENUM_SINGLE_DECL(sidetone1_enum,
1483 WM8994_SIDETONE, 0, sidetone_text);
1485 static const struct snd_kcontrol_new sidetone1_mux =
1486 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1488 static SOC_ENUM_SINGLE_DECL(sidetone2_enum,
1489 WM8994_SIDETONE, 1, sidetone_text);
1491 static const struct snd_kcontrol_new sidetone2_mux =
1492 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1494 static const char *aif1dac_text[] = {
1495 "AIF1DACDAT", "AIF3DACDAT",
1498 static const char *loopback_text[] = {
1502 static SOC_ENUM_SINGLE_DECL(aif1_loopback_enum,
1503 WM8994_AIF1_CONTROL_2,
1504 WM8994_AIF1_LOOPBACK_SHIFT,
1507 static const struct snd_kcontrol_new aif1_loopback =
1508 SOC_DAPM_ENUM("AIF1 Loopback", aif1_loopback_enum);
1510 static SOC_ENUM_SINGLE_DECL(aif2_loopback_enum,
1511 WM8994_AIF2_CONTROL_2,
1512 WM8994_AIF2_LOOPBACK_SHIFT,
1515 static const struct snd_kcontrol_new aif2_loopback =
1516 SOC_DAPM_ENUM("AIF2 Loopback", aif2_loopback_enum);
1518 static SOC_ENUM_SINGLE_DECL(aif1dac_enum,
1519 WM8994_POWER_MANAGEMENT_6, 0, aif1dac_text);
1521 static const struct snd_kcontrol_new aif1dac_mux =
1522 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1524 static const char *aif2dac_text[] = {
1525 "AIF2DACDAT", "AIF3DACDAT",
1528 static SOC_ENUM_SINGLE_DECL(aif2dac_enum,
1529 WM8994_POWER_MANAGEMENT_6, 1, aif2dac_text);
1531 static const struct snd_kcontrol_new aif2dac_mux =
1532 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1534 static const char *aif2adc_text[] = {
1535 "AIF2ADCDAT", "AIF3DACDAT",
1538 static SOC_ENUM_SINGLE_DECL(aif2adc_enum,
1539 WM8994_POWER_MANAGEMENT_6, 2, aif2adc_text);
1541 static const struct snd_kcontrol_new aif2adc_mux =
1542 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1544 static const char *aif3adc_text[] = {
1545 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
1548 static SOC_ENUM_SINGLE_DECL(wm8994_aif3adc_enum,
1549 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1551 static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1552 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1554 static SOC_ENUM_SINGLE_DECL(wm8958_aif3adc_enum,
1555 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1557 static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1558 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1560 static const char *mono_pcm_out_text[] = {
1561 "None", "AIF2ADCL", "AIF2ADCR",
1564 static SOC_ENUM_SINGLE_DECL(mono_pcm_out_enum,
1565 WM8994_POWER_MANAGEMENT_6, 9, mono_pcm_out_text);
1567 static const struct snd_kcontrol_new mono_pcm_out_mux =
1568 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1570 static const char *aif2dac_src_text[] = {
1574 /* Note that these two control shouldn't be simultaneously switched to AIF3 */
1575 static SOC_ENUM_SINGLE_DECL(aif2dacl_src_enum,
1576 WM8994_POWER_MANAGEMENT_6, 7, aif2dac_src_text);
1578 static const struct snd_kcontrol_new aif2dacl_src_mux =
1579 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1581 static SOC_ENUM_SINGLE_DECL(aif2dacr_src_enum,
1582 WM8994_POWER_MANAGEMENT_6, 8, aif2dac_src_text);
1584 static const struct snd_kcontrol_new aif2dacr_src_mux =
1585 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
1587 static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1588 SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
1589 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1590 SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
1591 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1593 SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1594 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1595 SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1596 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1597 SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1598 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1599 SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1600 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1601 SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1602 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1604 SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1605 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1606 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1607 SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1608 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1609 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1610 SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
1611 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1612 SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
1613 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1615 SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1618 static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1619 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
1620 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1621 SND_SOC_DAPM_PRE_PMD),
1622 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
1623 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1624 SND_SOC_DAPM_PRE_PMD),
1625 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1626 SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1627 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1628 SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1629 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1630 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1631 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
1634 static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1635 SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1636 dac_ev, SND_SOC_DAPM_PRE_PMU),
1637 SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1638 dac_ev, SND_SOC_DAPM_PRE_PMU),
1639 SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1640 dac_ev, SND_SOC_DAPM_PRE_PMU),
1641 SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1642 dac_ev, SND_SOC_DAPM_PRE_PMU),
1645 static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1646 SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
1647 SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
1648 SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1649 SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1652 static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
1653 SND_SOC_DAPM_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1654 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1655 SND_SOC_DAPM_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1656 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1659 static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
1660 SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1661 SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1664 static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1665 SND_SOC_DAPM_INPUT("DMIC1DAT"),
1666 SND_SOC_DAPM_INPUT("DMIC2DAT"),
1667 SND_SOC_DAPM_INPUT("Clock"),
1669 SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1670 SND_SOC_DAPM_PRE_PMU),
1671 SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1672 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1674 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1675 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1676 SND_SOC_DAPM_PRE_PMD),
1678 SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1679 SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1680 SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
1682 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
1683 0, SND_SOC_NOPM, 9, 0),
1684 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
1685 0, SND_SOC_NOPM, 8, 0),
1686 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1687 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
1688 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1689 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1690 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
1691 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1693 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
1694 0, SND_SOC_NOPM, 11, 0),
1695 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
1696 0, SND_SOC_NOPM, 10, 0),
1697 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1698 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
1699 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1700 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1701 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
1702 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1704 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1705 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1706 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1707 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1709 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1710 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1711 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1712 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1714 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1715 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1716 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1717 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1719 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1720 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1722 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1723 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1724 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1725 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1727 SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1728 SND_SOC_NOPM, 13, 0),
1729 SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1730 SND_SOC_NOPM, 12, 0),
1731 SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1732 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
1733 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1734 SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1735 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
1736 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1738 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1739 SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1740 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1741 SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1743 SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1744 SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1745 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
1747 SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1748 SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1750 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1752 SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1753 SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1754 SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1755 SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1757 /* Power is done with the muxes since the ADC power also controls the
1758 * downsampling chain, the chip will automatically manage the analogue
1759 * specific portions.
1761 SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1762 SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1764 SND_SOC_DAPM_MUX("AIF1 Loopback", SND_SOC_NOPM, 0, 0, &aif1_loopback),
1765 SND_SOC_DAPM_MUX("AIF2 Loopback", SND_SOC_NOPM, 0, 0, &aif2_loopback),
1767 SND_SOC_DAPM_POST("Debug log", post_ev),
1770 static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1771 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1774 static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1775 SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
1776 SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1777 SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1778 SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1779 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1782 static const struct snd_soc_dapm_route intercon[] = {
1783 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1784 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1786 { "DSP1CLK", NULL, "CLK_SYS" },
1787 { "DSP2CLK", NULL, "CLK_SYS" },
1788 { "DSPINTCLK", NULL, "CLK_SYS" },
1790 { "AIF1ADC1L", NULL, "AIF1CLK" },
1791 { "AIF1ADC1L", NULL, "DSP1CLK" },
1792 { "AIF1ADC1R", NULL, "AIF1CLK" },
1793 { "AIF1ADC1R", NULL, "DSP1CLK" },
1794 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1796 { "AIF1DAC1L", NULL, "AIF1CLK" },
1797 { "AIF1DAC1L", NULL, "DSP1CLK" },
1798 { "AIF1DAC1R", NULL, "AIF1CLK" },
1799 { "AIF1DAC1R", NULL, "DSP1CLK" },
1800 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1802 { "AIF1ADC2L", NULL, "AIF1CLK" },
1803 { "AIF1ADC2L", NULL, "DSP1CLK" },
1804 { "AIF1ADC2R", NULL, "AIF1CLK" },
1805 { "AIF1ADC2R", NULL, "DSP1CLK" },
1806 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1808 { "AIF1DAC2L", NULL, "AIF1CLK" },
1809 { "AIF1DAC2L", NULL, "DSP1CLK" },
1810 { "AIF1DAC2R", NULL, "AIF1CLK" },
1811 { "AIF1DAC2R", NULL, "DSP1CLK" },
1812 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1814 { "AIF2ADCL", NULL, "AIF2CLK" },
1815 { "AIF2ADCL", NULL, "DSP2CLK" },
1816 { "AIF2ADCR", NULL, "AIF2CLK" },
1817 { "AIF2ADCR", NULL, "DSP2CLK" },
1818 { "AIF2ADCR", NULL, "DSPINTCLK" },
1820 { "AIF2DACL", NULL, "AIF2CLK" },
1821 { "AIF2DACL", NULL, "DSP2CLK" },
1822 { "AIF2DACR", NULL, "AIF2CLK" },
1823 { "AIF2DACR", NULL, "DSP2CLK" },
1824 { "AIF2DACR", NULL, "DSPINTCLK" },
1826 { "DMIC1L", NULL, "DMIC1DAT" },
1827 { "DMIC1L", NULL, "CLK_SYS" },
1828 { "DMIC1R", NULL, "DMIC1DAT" },
1829 { "DMIC1R", NULL, "CLK_SYS" },
1830 { "DMIC2L", NULL, "DMIC2DAT" },
1831 { "DMIC2L", NULL, "CLK_SYS" },
1832 { "DMIC2R", NULL, "DMIC2DAT" },
1833 { "DMIC2R", NULL, "CLK_SYS" },
1835 { "ADCL", NULL, "AIF1CLK" },
1836 { "ADCL", NULL, "DSP1CLK" },
1837 { "ADCL", NULL, "DSPINTCLK" },
1839 { "ADCR", NULL, "AIF1CLK" },
1840 { "ADCR", NULL, "DSP1CLK" },
1841 { "ADCR", NULL, "DSPINTCLK" },
1843 { "ADCL Mux", "ADC", "ADCL" },
1844 { "ADCL Mux", "DMIC", "DMIC1L" },
1845 { "ADCR Mux", "ADC", "ADCR" },
1846 { "ADCR Mux", "DMIC", "DMIC1R" },
1848 { "DAC1L", NULL, "AIF1CLK" },
1849 { "DAC1L", NULL, "DSP1CLK" },
1850 { "DAC1L", NULL, "DSPINTCLK" },
1852 { "DAC1R", NULL, "AIF1CLK" },
1853 { "DAC1R", NULL, "DSP1CLK" },
1854 { "DAC1R", NULL, "DSPINTCLK" },
1856 { "DAC2L", NULL, "AIF2CLK" },
1857 { "DAC2L", NULL, "DSP2CLK" },
1858 { "DAC2L", NULL, "DSPINTCLK" },
1860 { "DAC2R", NULL, "AIF2DACR" },
1861 { "DAC2R", NULL, "AIF2CLK" },
1862 { "DAC2R", NULL, "DSP2CLK" },
1863 { "DAC2R", NULL, "DSPINTCLK" },
1865 { "TOCLK", NULL, "CLK_SYS" },
1867 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1868 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1869 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1871 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1872 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1873 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1876 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1877 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1878 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1880 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1881 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1882 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1884 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1885 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1886 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1888 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1889 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1890 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1892 /* Pin level routing for AIF3 */
1893 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1894 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1895 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1896 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1898 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1 Loopback" },
1899 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1900 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2 Loopback" },
1901 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1902 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1903 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1904 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1907 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1908 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1909 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1910 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1911 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1913 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1914 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1915 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1916 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1917 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1919 /* DAC2/AIF2 outputs */
1920 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
1921 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1922 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1923 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1924 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1925 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1927 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
1928 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1929 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1930 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1931 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1932 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1934 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1935 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1936 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1937 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1939 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1942 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1L" },
1943 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1R" },
1944 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2L" },
1945 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2R" },
1946 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1947 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1948 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACL" },
1949 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACR" },
1951 { "AIF3ADCDAT", NULL, "AIF3ADC Mux" },
1954 { "AIF1 Loopback", "ADCDAT", "AIF1ADCDAT" },
1955 { "AIF1 Loopback", "None", "AIF1DACDAT" },
1956 { "AIF2 Loopback", "ADCDAT", "AIF2ADCDAT" },
1957 { "AIF2 Loopback", "None", "AIF2DACDAT" },
1960 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1961 { "Left Sidetone", "DMIC2", "DMIC2L" },
1962 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1963 { "Right Sidetone", "DMIC2", "DMIC2R" },
1966 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1967 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1969 { "SPKL", "DAC1 Switch", "DAC1L" },
1970 { "SPKL", "DAC2 Switch", "DAC2L" },
1972 { "SPKR", "DAC1 Switch", "DAC1R" },
1973 { "SPKR", "DAC2 Switch", "DAC2R" },
1975 { "Left Headphone Mux", "DAC", "DAC1L" },
1976 { "Right Headphone Mux", "DAC", "DAC1R" },
1979 static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1980 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1981 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1982 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1983 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1984 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1985 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1986 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1987 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1990 static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1991 { "DAC1L", NULL, "DAC1L Mixer" },
1992 { "DAC1R", NULL, "DAC1R Mixer" },
1993 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1994 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1997 static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1998 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1999 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
2000 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
2001 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
2002 { "MICBIAS1", NULL, "CLK_SYS" },
2003 { "MICBIAS1", NULL, "MICBIAS Supply" },
2004 { "MICBIAS2", NULL, "CLK_SYS" },
2005 { "MICBIAS2", NULL, "MICBIAS Supply" },
2008 static const struct snd_soc_dapm_route wm8994_intercon[] = {
2009 { "AIF2DACL", NULL, "AIF2DAC Mux" },
2010 { "AIF2DACR", NULL, "AIF2DAC Mux" },
2011 { "MICBIAS1", NULL, "VMID" },
2012 { "MICBIAS2", NULL, "VMID" },
2015 static const struct snd_soc_dapm_route wm8958_intercon[] = {
2016 { "AIF2DACL", NULL, "AIF2DACL Mux" },
2017 { "AIF2DACR", NULL, "AIF2DACR Mux" },
2019 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
2020 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
2021 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
2022 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
2024 { "AIF3DACDAT", NULL, "AIF3" },
2025 { "AIF3ADCDAT", NULL, "AIF3" },
2027 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
2028 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
2030 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
2033 /* The size in bits of the FLL divide multiplied by 10
2034 * to allow rounding later */
2035 #define FIXED_FLL_SIZE ((1 << 16) * 10)
2046 static int wm8994_get_fll_config(struct wm8994 *control, struct fll_div *fll,
2047 int freq_in, int freq_out)
2050 unsigned int K, Ndiv, Nmod, gcd_fll;
2052 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2054 /* Scale the input frequency down to <= 13.5MHz */
2055 fll->clk_ref_div = 0;
2056 while (freq_in > 13500000) {
2060 if (fll->clk_ref_div > 3)
2063 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2065 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2067 while (freq_out * (fll->outdiv + 1) < 90000000) {
2069 if (fll->outdiv > 63)
2072 freq_out *= fll->outdiv + 1;
2073 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2075 if (freq_in > 1000000) {
2076 fll->fll_fratio = 0;
2077 } else if (freq_in > 256000) {
2078 fll->fll_fratio = 1;
2080 } else if (freq_in > 128000) {
2081 fll->fll_fratio = 2;
2083 } else if (freq_in > 64000) {
2084 fll->fll_fratio = 3;
2087 fll->fll_fratio = 4;
2090 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2092 /* Now, calculate N.K */
2093 Ndiv = freq_out / freq_in;
2096 Nmod = freq_out % freq_in;
2097 pr_debug("Nmod=%d\n", Nmod);
2099 switch (control->type) {
2101 /* Calculate fractional part - scale up so we can round. */
2102 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2104 do_div(Kpart, freq_in);
2106 K = Kpart & 0xFFFFFFFF;
2111 /* Move down to proper range now rounding is done */
2115 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2119 gcd_fll = gcd(freq_out, freq_in);
2121 fll->k = (freq_out - (freq_in * fll->n)) / gcd_fll;
2122 fll->lambda = freq_in / gcd_fll;
2129 static int _wm8994_set_fll(struct snd_soc_component *component, int id, int src,
2130 unsigned int freq_in, unsigned int freq_out)
2132 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2133 struct wm8994 *control = wm8994->wm8994;
2134 int reg_offset, ret;
2136 u16 reg, clk1, aif_reg, aif_src;
2137 unsigned long timeout;
2155 reg = snd_soc_component_read32(component, WM8994_FLL1_CONTROL_1 + reg_offset);
2156 was_enabled = reg & WM8994_FLL1_ENA;
2160 /* Allow no source specification when stopping */
2163 src = wm8994->fll[id].src;
2165 case WM8994_FLL_SRC_MCLK1:
2166 case WM8994_FLL_SRC_MCLK2:
2167 case WM8994_FLL_SRC_LRCLK:
2168 case WM8994_FLL_SRC_BCLK:
2170 case WM8994_FLL_SRC_INTERNAL:
2172 freq_out = 12000000;
2178 /* Are we changing anything? */
2179 if (wm8994->fll[id].src == src &&
2180 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2183 /* If we're stopping the FLL redo the old config - no
2184 * registers will actually be written but we avoid GCC flow
2185 * analysis bugs spewing warnings.
2188 ret = wm8994_get_fll_config(control, &fll, freq_in, freq_out);
2190 ret = wm8994_get_fll_config(control, &fll, wm8994->fll[id].in,
2191 wm8994->fll[id].out);
2195 /* Make sure that we're not providing SYSCLK right now */
2196 clk1 = snd_soc_component_read32(component, WM8994_CLOCKING_1);
2197 if (clk1 & WM8994_SYSCLK_SRC)
2198 aif_reg = WM8994_AIF2_CLOCKING_1;
2200 aif_reg = WM8994_AIF1_CLOCKING_1;
2201 reg = snd_soc_component_read32(component, aif_reg);
2203 if ((reg & WM8994_AIF1CLK_ENA) &&
2204 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2205 dev_err(component->dev, "FLL%d is currently providing SYSCLK\n",
2210 /* We always need to disable the FLL while reconfiguring */
2211 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_1 + reg_offset,
2212 WM8994_FLL1_ENA, 0);
2214 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
2215 freq_in == freq_out && freq_out) {
2216 dev_dbg(component->dev, "Bypassing FLL%d\n", id + 1);
2217 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_5 + reg_offset,
2218 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2222 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2223 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2224 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_2 + reg_offset,
2225 WM8994_FLL1_OUTDIV_MASK |
2226 WM8994_FLL1_FRATIO_MASK, reg);
2228 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_3 + reg_offset,
2229 WM8994_FLL1_K_MASK, fll.k);
2231 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_4 + reg_offset,
2233 fll.n << WM8994_FLL1_N_SHIFT);
2236 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_1 + reg_offset,
2237 WM8958_FLL1_LAMBDA_MASK,
2239 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_2 + reg_offset,
2240 WM8958_FLL1_EFS_ENA, WM8958_FLL1_EFS_ENA);
2242 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_2 + reg_offset,
2243 WM8958_FLL1_EFS_ENA, 0);
2246 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_5 + reg_offset,
2247 WM8994_FLL1_FRC_NCO | WM8958_FLL1_BYP |
2248 WM8994_FLL1_REFCLK_DIV_MASK |
2249 WM8994_FLL1_REFCLK_SRC_MASK,
2250 ((src == WM8994_FLL_SRC_INTERNAL)
2251 << WM8994_FLL1_FRC_NCO_SHIFT) |
2252 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2255 /* Clear any pending completion from a previous failure */
2256 try_wait_for_completion(&wm8994->fll_locked[id]);
2258 /* Enable (with fractional mode if required) */
2260 /* Enable VMID if we need it */
2262 active_reference(component);
2264 switch (control->type) {
2266 vmid_reference(component);
2269 if (control->revision < 1)
2270 vmid_reference(component);
2277 reg = WM8994_FLL1_ENA;
2280 reg |= WM8994_FLL1_FRAC;
2281 if (src == WM8994_FLL_SRC_INTERNAL)
2282 reg |= WM8994_FLL1_OSC_ENA;
2284 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_1 + reg_offset,
2285 WM8994_FLL1_ENA | WM8994_FLL1_OSC_ENA |
2286 WM8994_FLL1_FRAC, reg);
2288 if (wm8994->fll_locked_irq) {
2289 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2290 msecs_to_jiffies(10));
2292 dev_warn(component->dev,
2293 "Timed out waiting for FLL lock\n");
2299 switch (control->type) {
2301 vmid_dereference(component);
2304 if (control->revision < 1)
2305 vmid_dereference(component);
2311 active_dereference(component);
2316 wm8994->fll[id].in = freq_in;
2317 wm8994->fll[id].out = freq_out;
2318 wm8994->fll[id].src = src;
2320 configure_clock(component);
2323 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2326 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2327 dev_dbg(component->dev, "Configuring AIFs for 128fs\n");
2329 wm8994->aifdiv[0] = snd_soc_component_read32(component, WM8994_AIF1_RATE)
2330 & WM8994_AIF1CLK_RATE_MASK;
2331 wm8994->aifdiv[1] = snd_soc_component_read32(component, WM8994_AIF2_RATE)
2332 & WM8994_AIF1CLK_RATE_MASK;
2334 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2335 WM8994_AIF1CLK_RATE_MASK, 0x1);
2336 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2337 WM8994_AIF2CLK_RATE_MASK, 0x1);
2338 } else if (wm8994->aifdiv[0]) {
2339 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2340 WM8994_AIF1CLK_RATE_MASK,
2342 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2343 WM8994_AIF2CLK_RATE_MASK,
2346 wm8994->aifdiv[0] = 0;
2347 wm8994->aifdiv[1] = 0;
2353 static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2355 struct completion *completion = data;
2357 complete(completion);
2362 static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2364 static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2365 unsigned int freq_in, unsigned int freq_out)
2367 return _wm8994_set_fll(dai->component, id, src, freq_in, freq_out);
2370 static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2371 int clk_id, unsigned int freq, int dir)
2373 struct snd_soc_component *component = dai->component;
2374 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2383 /* AIF3 shares clocking with AIF1/2 */
2388 case WM8994_SYSCLK_MCLK1:
2389 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2390 wm8994->mclk[0] = freq;
2391 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2395 case WM8994_SYSCLK_MCLK2:
2396 /* TODO: Set GPIO AF */
2397 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2398 wm8994->mclk[1] = freq;
2399 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2403 case WM8994_SYSCLK_FLL1:
2404 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2405 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2408 case WM8994_SYSCLK_FLL2:
2409 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2410 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2413 case WM8994_SYSCLK_OPCLK:
2414 /* Special case - a division (times 10) is given and
2415 * no effect on main clocking.
2418 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2419 if (opclk_divs[i] == freq)
2421 if (i == ARRAY_SIZE(opclk_divs))
2423 snd_soc_component_update_bits(component, WM8994_CLOCKING_2,
2424 WM8994_OPCLK_DIV_MASK, i);
2425 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_2,
2426 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2428 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_2,
2429 WM8994_OPCLK_ENA, 0);
2437 configure_clock(component);
2440 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2443 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2444 dev_dbg(component->dev, "Configuring AIFs for 128fs\n");
2446 wm8994->aifdiv[0] = snd_soc_component_read32(component, WM8994_AIF1_RATE)
2447 & WM8994_AIF1CLK_RATE_MASK;
2448 wm8994->aifdiv[1] = snd_soc_component_read32(component, WM8994_AIF2_RATE)
2449 & WM8994_AIF1CLK_RATE_MASK;
2451 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2452 WM8994_AIF1CLK_RATE_MASK, 0x1);
2453 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2454 WM8994_AIF2CLK_RATE_MASK, 0x1);
2455 } else if (wm8994->aifdiv[0]) {
2456 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2457 WM8994_AIF1CLK_RATE_MASK,
2459 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2460 WM8994_AIF2CLK_RATE_MASK,
2463 wm8994->aifdiv[0] = 0;
2464 wm8994->aifdiv[1] = 0;
2470 static int wm8994_set_bias_level(struct snd_soc_component *component,
2471 enum snd_soc_bias_level level)
2473 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2474 struct wm8994 *control = wm8994->wm8994;
2476 wm_hubs_set_bias_level(component, level);
2479 case SND_SOC_BIAS_ON:
2482 case SND_SOC_BIAS_PREPARE:
2483 /* MICBIAS into regulating mode */
2484 switch (control->type) {
2487 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
2488 WM8958_MICB1_MODE, 0);
2489 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
2490 WM8958_MICB2_MODE, 0);
2496 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY)
2497 active_reference(component);
2500 case SND_SOC_BIAS_STANDBY:
2501 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
2502 switch (control->type) {
2504 if (control->revision == 0) {
2505 /* Optimise performance for rev A */
2506 snd_soc_component_update_bits(component,
2507 WM8958_CHARGE_PUMP_2,
2517 /* Discharge LINEOUT1 & 2 */
2518 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
2519 WM8994_LINEOUT1_DISCH |
2520 WM8994_LINEOUT2_DISCH,
2521 WM8994_LINEOUT1_DISCH |
2522 WM8994_LINEOUT2_DISCH);
2525 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE)
2526 active_dereference(component);
2528 /* MICBIAS into bypass mode on newer devices */
2529 switch (control->type) {
2532 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
2535 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
2544 case SND_SOC_BIAS_OFF:
2545 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY)
2546 wm8994->cur_fw = NULL;
2553 int wm8994_vmid_mode(struct snd_soc_component *component, enum wm8994_vmid_mode mode)
2555 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2556 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
2559 case WM8994_VMID_NORMAL:
2560 snd_soc_dapm_mutex_lock(dapm);
2562 if (wm8994->hubs.lineout1_se) {
2563 snd_soc_dapm_disable_pin_unlocked(dapm,
2564 "LINEOUT1N Driver");
2565 snd_soc_dapm_disable_pin_unlocked(dapm,
2566 "LINEOUT1P Driver");
2568 if (wm8994->hubs.lineout2_se) {
2569 snd_soc_dapm_disable_pin_unlocked(dapm,
2570 "LINEOUT2N Driver");
2571 snd_soc_dapm_disable_pin_unlocked(dapm,
2572 "LINEOUT2P Driver");
2575 /* Do the sync with the old mode to allow it to clean up */
2576 snd_soc_dapm_sync_unlocked(dapm);
2577 wm8994->vmid_mode = mode;
2579 snd_soc_dapm_mutex_unlock(dapm);
2582 case WM8994_VMID_FORCE:
2583 snd_soc_dapm_mutex_lock(dapm);
2585 if (wm8994->hubs.lineout1_se) {
2586 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2587 "LINEOUT1N Driver");
2588 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2589 "LINEOUT1P Driver");
2591 if (wm8994->hubs.lineout2_se) {
2592 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2593 "LINEOUT2N Driver");
2594 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2595 "LINEOUT2P Driver");
2598 wm8994->vmid_mode = mode;
2599 snd_soc_dapm_sync_unlocked(dapm);
2601 snd_soc_dapm_mutex_unlock(dapm);
2611 static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2613 struct snd_soc_component *component = dai->component;
2614 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2615 struct wm8994 *control = wm8994->wm8994;
2626 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2627 aif1_reg = WM8994_AIF1_CONTROL_1;
2628 dac_reg = WM8994_AIF1DAC_LRCLK;
2629 adc_reg = WM8994_AIF1ADC_LRCLK;
2632 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2633 aif1_reg = WM8994_AIF2_CONTROL_1;
2634 dac_reg = WM8994_AIF1DAC_LRCLK;
2635 adc_reg = WM8994_AIF1ADC_LRCLK;
2641 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2642 case SND_SOC_DAIFMT_CBS_CFS:
2644 case SND_SOC_DAIFMT_CBM_CFM:
2645 ms = WM8994_AIF1_MSTR;
2651 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2652 case SND_SOC_DAIFMT_DSP_B:
2653 aif1 |= WM8994_AIF1_LRCLK_INV;
2654 lrclk |= WM8958_AIF1_LRCLK_INV;
2656 case SND_SOC_DAIFMT_DSP_A:
2659 case SND_SOC_DAIFMT_I2S:
2662 case SND_SOC_DAIFMT_RIGHT_J:
2664 case SND_SOC_DAIFMT_LEFT_J:
2671 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2672 case SND_SOC_DAIFMT_DSP_A:
2673 case SND_SOC_DAIFMT_DSP_B:
2674 /* frame inversion not valid for DSP modes */
2675 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2676 case SND_SOC_DAIFMT_NB_NF:
2678 case SND_SOC_DAIFMT_IB_NF:
2679 aif1 |= WM8994_AIF1_BCLK_INV;
2686 case SND_SOC_DAIFMT_I2S:
2687 case SND_SOC_DAIFMT_RIGHT_J:
2688 case SND_SOC_DAIFMT_LEFT_J:
2689 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2690 case SND_SOC_DAIFMT_NB_NF:
2692 case SND_SOC_DAIFMT_IB_IF:
2693 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2694 lrclk |= WM8958_AIF1_LRCLK_INV;
2696 case SND_SOC_DAIFMT_IB_NF:
2697 aif1 |= WM8994_AIF1_BCLK_INV;
2699 case SND_SOC_DAIFMT_NB_IF:
2700 aif1 |= WM8994_AIF1_LRCLK_INV;
2701 lrclk |= WM8958_AIF1_LRCLK_INV;
2711 /* The AIF2 format configuration needs to be mirrored to AIF3
2712 * on WM8958 if it's in use so just do it all the time. */
2713 switch (control->type) {
2717 snd_soc_component_update_bits(component, WM8958_AIF3_CONTROL_1,
2718 WM8994_AIF1_LRCLK_INV |
2719 WM8958_AIF3_FMT_MASK, aif1);
2726 snd_soc_component_update_bits(component, aif1_reg,
2727 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2728 WM8994_AIF1_FMT_MASK,
2730 snd_soc_component_update_bits(component, ms_reg, WM8994_AIF1_MSTR,
2732 snd_soc_component_update_bits(component, dac_reg,
2733 WM8958_AIF1_LRCLK_INV, lrclk);
2734 snd_soc_component_update_bits(component, adc_reg,
2735 WM8958_AIF1_LRCLK_INV, lrclk);
2756 static int fs_ratios[] = {
2757 64, 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
2760 static int bclk_divs[] = {
2761 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2762 640, 880, 960, 1280, 1760, 1920
2765 static int wm8994_hw_params(struct snd_pcm_substream *substream,
2766 struct snd_pcm_hw_params *params,
2767 struct snd_soc_dai *dai)
2769 struct snd_soc_component *component = dai->component;
2770 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2771 struct wm8994 *control = wm8994->wm8994;
2772 struct wm8994_pdata *pdata = &control->pdata;
2783 int id = dai->id - 1;
2785 int i, cur_val, best_val, bclk_rate, best;
2789 aif1_reg = WM8994_AIF1_CONTROL_1;
2790 aif2_reg = WM8994_AIF1_CONTROL_2;
2791 bclk_reg = WM8994_AIF1_BCLK;
2792 rate_reg = WM8994_AIF1_RATE;
2793 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2794 wm8994->lrclk_shared[0]) {
2795 lrclk_reg = WM8994_AIF1DAC_LRCLK;
2797 lrclk_reg = WM8994_AIF1ADC_LRCLK;
2798 dev_dbg(component->dev, "AIF1 using split LRCLK\n");
2802 aif1_reg = WM8994_AIF2_CONTROL_1;
2803 aif2_reg = WM8994_AIF2_CONTROL_2;
2804 bclk_reg = WM8994_AIF2_BCLK;
2805 rate_reg = WM8994_AIF2_RATE;
2806 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2807 wm8994->lrclk_shared[1]) {
2808 lrclk_reg = WM8994_AIF2DAC_LRCLK;
2810 lrclk_reg = WM8994_AIF2ADC_LRCLK;
2811 dev_dbg(component->dev, "AIF2 using split LRCLK\n");
2818 bclk_rate = params_rate(params);
2819 switch (params_width(params)) {
2839 wm8994->channels[id] = params_channels(params);
2840 if (pdata->max_channels_clocked[id] &&
2841 wm8994->channels[id] > pdata->max_channels_clocked[id]) {
2842 dev_dbg(dai->dev, "Constraining channels to %d from %d\n",
2843 pdata->max_channels_clocked[id], wm8994->channels[id]);
2844 wm8994->channels[id] = pdata->max_channels_clocked[id];
2847 switch (wm8994->channels[id]) {
2857 /* Try to find an appropriate sample rate; look for an exact match. */
2858 for (i = 0; i < ARRAY_SIZE(srs); i++)
2859 if (srs[i].rate == params_rate(params))
2861 if (i == ARRAY_SIZE(srs))
2863 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2865 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2866 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2867 dai->id, wm8994->aifclk[id], bclk_rate);
2869 if (wm8994->channels[id] == 1 &&
2870 (snd_soc_component_read32(component, aif1_reg) & 0x18) == 0x18)
2871 aif2 |= WM8994_AIF1_MONO;
2873 if (wm8994->aifclk[id] == 0) {
2874 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2878 /* AIFCLK/fs ratio; look for a close match in either direction */
2880 best_val = abs((fs_ratios[0] * params_rate(params))
2881 - wm8994->aifclk[id]);
2882 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2883 cur_val = abs((fs_ratios[i] * params_rate(params))
2884 - wm8994->aifclk[id]);
2885 if (cur_val >= best_val)
2890 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2891 dai->id, fs_ratios[best]);
2894 /* We may not get quite the right frequency if using
2895 * approximate clocks so look for the closest match that is
2896 * higher than the target (we need to ensure that there enough
2897 * BCLKs to clock out the samples).
2900 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
2901 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
2902 if (cur_val < 0) /* BCLK table is sorted */
2906 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
2907 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2908 bclk_divs[best], bclk_rate);
2909 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2911 lrclk = bclk_rate / params_rate(params);
2913 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2917 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2918 lrclk, bclk_rate / lrclk);
2920 snd_soc_component_update_bits(component, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2921 snd_soc_component_update_bits(component, aif2_reg, WM8994_AIF1_MONO, aif2);
2922 snd_soc_component_update_bits(component, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2923 snd_soc_component_update_bits(component, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2925 snd_soc_component_update_bits(component, rate_reg, WM8994_AIF1_SR_MASK |
2926 WM8994_AIF1CLK_RATE_MASK, rate_val);
2928 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2931 wm8994->dac_rates[0] = params_rate(params);
2932 wm8994_set_retune_mobile(component, 0);
2933 wm8994_set_retune_mobile(component, 1);
2936 wm8994->dac_rates[1] = params_rate(params);
2937 wm8994_set_retune_mobile(component, 2);
2945 static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2946 struct snd_pcm_hw_params *params,
2947 struct snd_soc_dai *dai)
2949 struct snd_soc_component *component = dai->component;
2950 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2951 struct wm8994 *control = wm8994->wm8994;
2957 switch (control->type) {
2960 aif1_reg = WM8958_AIF3_CONTROL_1;
2970 switch (params_width(params)) {
2986 return snd_soc_component_update_bits(component, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2989 static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2991 struct snd_soc_component *component = codec_dai->component;
2995 switch (codec_dai->id) {
2997 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
3000 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
3007 reg = WM8994_AIF1DAC1_MUTE;
3011 snd_soc_component_update_bits(component, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
3016 static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
3018 struct snd_soc_component *component = codec_dai->component;
3021 switch (codec_dai->id) {
3023 reg = WM8994_AIF1_MASTER_SLAVE;
3024 mask = WM8994_AIF1_TRI;
3027 reg = WM8994_AIF2_MASTER_SLAVE;
3028 mask = WM8994_AIF2_TRI;
3039 return snd_soc_component_update_bits(component, reg, mask, val);
3042 static int wm8994_aif2_probe(struct snd_soc_dai *dai)
3044 struct snd_soc_component *component = dai->component;
3046 /* Disable the pulls on the AIF if we're using it to save power. */
3047 snd_soc_component_update_bits(component, WM8994_GPIO_3,
3048 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3049 snd_soc_component_update_bits(component, WM8994_GPIO_4,
3050 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3051 snd_soc_component_update_bits(component, WM8994_GPIO_5,
3052 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3057 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
3059 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
3060 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
3062 static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
3063 .set_sysclk = wm8994_set_dai_sysclk,
3064 .set_fmt = wm8994_set_dai_fmt,
3065 .hw_params = wm8994_hw_params,
3066 .digital_mute = wm8994_aif_mute,
3067 .set_pll = wm8994_set_fll,
3068 .set_tristate = wm8994_set_tristate,
3071 static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
3072 .set_sysclk = wm8994_set_dai_sysclk,
3073 .set_fmt = wm8994_set_dai_fmt,
3074 .hw_params = wm8994_hw_params,
3075 .digital_mute = wm8994_aif_mute,
3076 .set_pll = wm8994_set_fll,
3077 .set_tristate = wm8994_set_tristate,
3080 static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
3081 .hw_params = wm8994_aif3_hw_params,
3084 static struct snd_soc_dai_driver wm8994_dai[] = {
3086 .name = "wm8994-aif1",
3089 .stream_name = "AIF1 Playback",
3092 .rates = WM8994_RATES,
3093 .formats = WM8994_FORMATS,
3097 .stream_name = "AIF1 Capture",
3100 .rates = WM8994_RATES,
3101 .formats = WM8994_FORMATS,
3104 .ops = &wm8994_aif1_dai_ops,
3107 .name = "wm8994-aif2",
3110 .stream_name = "AIF2 Playback",
3113 .rates = WM8994_RATES,
3114 .formats = WM8994_FORMATS,
3118 .stream_name = "AIF2 Capture",
3121 .rates = WM8994_RATES,
3122 .formats = WM8994_FORMATS,
3125 .probe = wm8994_aif2_probe,
3126 .ops = &wm8994_aif2_dai_ops,
3129 .name = "wm8994-aif3",
3132 .stream_name = "AIF3 Playback",
3135 .rates = WM8994_RATES,
3136 .formats = WM8994_FORMATS,
3140 .stream_name = "AIF3 Capture",
3143 .rates = WM8994_RATES,
3144 .formats = WM8994_FORMATS,
3147 .ops = &wm8994_aif3_dai_ops,
3152 static int wm8994_component_suspend(struct snd_soc_component *component)
3154 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3157 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3158 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
3159 sizeof(struct wm8994_fll_config));
3160 ret = _wm8994_set_fll(component, i + 1, 0, 0, 0);
3162 dev_warn(component->dev, "Failed to stop FLL%d: %d\n",
3166 snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
3171 static int wm8994_component_resume(struct snd_soc_component *component)
3173 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3176 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3177 if (!wm8994->fll_suspend[i].out)
3180 ret = _wm8994_set_fll(component, i + 1,
3181 wm8994->fll_suspend[i].src,
3182 wm8994->fll_suspend[i].in,
3183 wm8994->fll_suspend[i].out);
3185 dev_warn(component->dev, "Failed to restore FLL%d: %d\n",
3192 #define wm8994_component_suspend NULL
3193 #define wm8994_component_resume NULL
3196 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3198 struct snd_soc_component *component = wm8994->hubs.component;
3199 struct wm8994 *control = wm8994->wm8994;
3200 struct wm8994_pdata *pdata = &control->pdata;
3201 struct snd_kcontrol_new controls[] = {
3202 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3203 wm8994->retune_mobile_enum,
3204 wm8994_get_retune_mobile_enum,
3205 wm8994_put_retune_mobile_enum),
3206 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3207 wm8994->retune_mobile_enum,
3208 wm8994_get_retune_mobile_enum,
3209 wm8994_put_retune_mobile_enum),
3210 SOC_ENUM_EXT("AIF2 EQ Mode",
3211 wm8994->retune_mobile_enum,
3212 wm8994_get_retune_mobile_enum,
3213 wm8994_put_retune_mobile_enum),
3218 /* We need an array of texts for the enum API but the number
3219 * of texts is likely to be less than the number of
3220 * configurations due to the sample rate dependency of the
3221 * configurations. */
3222 wm8994->num_retune_mobile_texts = 0;
3223 wm8994->retune_mobile_texts = NULL;
3224 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3225 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3226 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3227 wm8994->retune_mobile_texts[j]) == 0)
3231 if (j != wm8994->num_retune_mobile_texts)
3234 /* Expand the array... */
3235 t = krealloc(wm8994->retune_mobile_texts,
3237 (wm8994->num_retune_mobile_texts + 1),
3242 /* ...store the new entry... */
3243 t[wm8994->num_retune_mobile_texts] =
3244 pdata->retune_mobile_cfgs[i].name;
3246 /* ...and remember the new version. */
3247 wm8994->num_retune_mobile_texts++;
3248 wm8994->retune_mobile_texts = t;
3251 dev_dbg(component->dev, "Allocated %d unique ReTune Mobile names\n",
3252 wm8994->num_retune_mobile_texts);
3254 wm8994->retune_mobile_enum.items = wm8994->num_retune_mobile_texts;
3255 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3257 ret = snd_soc_add_component_controls(wm8994->hubs.component, controls,
3258 ARRAY_SIZE(controls));
3260 dev_err(wm8994->hubs.component->dev,
3261 "Failed to add ReTune Mobile controls: %d\n", ret);
3264 static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3266 struct snd_soc_component *component = wm8994->hubs.component;
3267 struct wm8994 *control = wm8994->wm8994;
3268 struct wm8994_pdata *pdata = &control->pdata;
3274 wm_hubs_handle_analogue_pdata(component, pdata->lineout1_diff,
3275 pdata->lineout2_diff,
3282 pdata->micbias1_lvl,
3283 pdata->micbias2_lvl);
3285 dev_dbg(component->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3287 if (pdata->num_drc_cfgs) {
3288 struct snd_kcontrol_new controls[] = {
3289 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3290 wm8994_get_drc_enum, wm8994_put_drc_enum),
3291 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3292 wm8994_get_drc_enum, wm8994_put_drc_enum),
3293 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3294 wm8994_get_drc_enum, wm8994_put_drc_enum),
3297 /* We need an array of texts for the enum API */
3298 wm8994->drc_texts = devm_kcalloc(wm8994->hubs.component->dev,
3299 pdata->num_drc_cfgs, sizeof(char *), GFP_KERNEL);
3300 if (!wm8994->drc_texts)
3303 for (i = 0; i < pdata->num_drc_cfgs; i++)
3304 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3306 wm8994->drc_enum.items = pdata->num_drc_cfgs;
3307 wm8994->drc_enum.texts = wm8994->drc_texts;
3309 ret = snd_soc_add_component_controls(wm8994->hubs.component, controls,
3310 ARRAY_SIZE(controls));
3311 for (i = 0; i < WM8994_NUM_DRC; i++)
3312 wm8994_set_drc(component, i);
3314 ret = snd_soc_add_component_controls(wm8994->hubs.component,
3315 wm8994_drc_controls,
3316 ARRAY_SIZE(wm8994_drc_controls));
3320 dev_err(wm8994->hubs.component->dev,
3321 "Failed to add DRC mode controls: %d\n", ret);
3324 dev_dbg(component->dev, "%d ReTune Mobile configurations\n",
3325 pdata->num_retune_mobile_cfgs);
3327 if (pdata->num_retune_mobile_cfgs)
3328 wm8994_handle_retune_mobile_pdata(wm8994);
3330 snd_soc_add_component_controls(wm8994->hubs.component, wm8994_eq_controls,
3331 ARRAY_SIZE(wm8994_eq_controls));
3333 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3334 if (pdata->micbias[i]) {
3335 snd_soc_component_write(component, WM8958_MICBIAS1 + i,
3336 pdata->micbias[i] & 0xffff);
3342 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3344 * @component: WM8994 component
3345 * @jack: jack to report detection events on
3346 * @micbias: microphone bias to detect on
3348 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3349 * being used to bring out signals to the processor then only platform
3350 * data configuration is needed for WM8994 and processor GPIOs should
3351 * be configured using snd_soc_jack_add_gpios() instead.
3353 * Configuration of detection levels is available via the micbias1_lvl
3354 * and micbias2_lvl platform data members.
3356 int wm8994_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
3359 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3360 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3361 struct wm8994_micdet *micdet;
3362 struct wm8994 *control = wm8994->wm8994;
3365 if (control->type != WM8994) {
3366 dev_warn(component->dev, "Not a WM8994\n");
3372 micdet = &wm8994->micdet[0];
3374 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3376 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3379 micdet = &wm8994->micdet[1];
3381 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3383 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3386 dev_warn(component->dev, "Invalid MICBIAS %d\n", micbias);
3391 dev_warn(component->dev, "Failed to configure MICBIAS%d: %d\n",
3394 dev_dbg(component->dev, "Configuring microphone detection on %d %p\n",
3397 /* Store the configuration */
3398 micdet->jack = jack;
3399 micdet->detecting = true;
3401 /* If either of the jacks is set up then enable detection */
3402 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3403 reg = WM8994_MICD_ENA;
3407 snd_soc_component_update_bits(component, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3409 /* enable MICDET and MICSHRT deboune */
3410 snd_soc_component_update_bits(component, WM8994_IRQ_DEBOUNCE,
3411 WM8994_MIC1_DET_DB_MASK | WM8994_MIC1_SHRT_DB_MASK |
3412 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK,
3413 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB);
3415 snd_soc_dapm_sync(dapm);
3419 EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3421 static void wm8994_mic_work(struct work_struct *work)
3423 struct wm8994_priv *priv = container_of(work,
3426 struct regmap *regmap = priv->wm8994->regmap;
3427 struct device *dev = priv->wm8994->dev;
3432 pm_runtime_get_sync(dev);
3434 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, ®);
3436 dev_err(dev, "Failed to read microphone status: %d\n",
3438 pm_runtime_put(dev);
3442 dev_dbg(dev, "Microphone status: %x\n", reg);
3445 if (reg & WM8994_MIC1_DET_STS) {
3446 if (priv->micdet[0].detecting)
3447 report = SND_JACK_HEADSET;
3449 if (reg & WM8994_MIC1_SHRT_STS) {
3450 if (priv->micdet[0].detecting)
3451 report = SND_JACK_HEADPHONE;
3453 report |= SND_JACK_BTN_0;
3456 priv->micdet[0].detecting = false;
3458 priv->micdet[0].detecting = true;
3460 snd_soc_jack_report(priv->micdet[0].jack, report,
3461 SND_JACK_HEADSET | SND_JACK_BTN_0);
3464 if (reg & WM8994_MIC2_DET_STS) {
3465 if (priv->micdet[1].detecting)
3466 report = SND_JACK_HEADSET;
3468 if (reg & WM8994_MIC2_SHRT_STS) {
3469 if (priv->micdet[1].detecting)
3470 report = SND_JACK_HEADPHONE;
3472 report |= SND_JACK_BTN_0;
3475 priv->micdet[1].detecting = false;
3477 priv->micdet[1].detecting = true;
3479 snd_soc_jack_report(priv->micdet[1].jack, report,
3480 SND_JACK_HEADSET | SND_JACK_BTN_0);
3482 pm_runtime_put(dev);
3485 static irqreturn_t wm8994_mic_irq(int irq, void *data)
3487 struct wm8994_priv *priv = data;
3488 struct snd_soc_component *component = priv->hubs.component;
3490 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3491 trace_snd_soc_jack_irq(dev_name(component->dev));
3494 pm_wakeup_event(component->dev, 300);
3496 queue_delayed_work(system_power_efficient_wq,
3497 &priv->mic_work, msecs_to_jiffies(250));
3502 /* Should be called with accdet_lock held */
3503 static void wm1811_micd_stop(struct snd_soc_component *component)
3505 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3506 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3508 if (!wm8994->jackdet)
3511 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1, WM8958_MICD_ENA, 0);
3513 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_JACK);
3515 if (wm8994->wm8994->pdata.jd_ext_cap)
3516 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3519 static void wm8958_button_det(struct snd_soc_component *component, u16 status)
3521 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3526 report |= SND_JACK_BTN_0;
3529 report |= SND_JACK_BTN_1;
3532 report |= SND_JACK_BTN_2;
3535 report |= SND_JACK_BTN_3;
3538 report |= SND_JACK_BTN_4;
3541 report |= SND_JACK_BTN_5;
3543 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3547 static void wm8958_open_circuit_work(struct work_struct *work)
3549 struct wm8994_priv *wm8994 = container_of(work,
3551 open_circuit_work.work);
3552 struct device *dev = wm8994->wm8994->dev;
3554 mutex_lock(&wm8994->accdet_lock);
3556 wm1811_micd_stop(wm8994->hubs.component);
3558 dev_dbg(dev, "Reporting open circuit\n");
3560 wm8994->jack_mic = false;
3561 wm8994->mic_detecting = true;
3563 wm8958_micd_set_rate(wm8994->hubs.component);
3565 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3569 mutex_unlock(&wm8994->accdet_lock);
3572 static void wm8958_mic_id(void *data, u16 status)
3574 struct snd_soc_component *component = data;
3575 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3577 /* Either nothing present or just starting detection */
3578 if (!(status & WM8958_MICD_STS)) {
3579 /* If nothing present then clear our statuses */
3580 dev_dbg(component->dev, "Detected open circuit\n");
3582 queue_delayed_work(system_power_efficient_wq,
3583 &wm8994->open_circuit_work,
3584 msecs_to_jiffies(2500));
3588 /* If the measurement is showing a high impedence we've got a
3591 if (status & 0x600) {
3592 dev_dbg(component->dev, "Detected microphone\n");
3594 wm8994->mic_detecting = false;
3595 wm8994->jack_mic = true;
3597 wm8958_micd_set_rate(component);
3599 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3604 if (status & 0xfc) {
3605 dev_dbg(component->dev, "Detected headphone\n");
3606 wm8994->mic_detecting = false;
3608 wm8958_micd_set_rate(component);
3610 /* If we have jackdet that will detect removal */
3611 wm1811_micd_stop(component);
3613 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3618 /* Deferred mic detection to allow for extra settling time */
3619 static void wm1811_mic_work(struct work_struct *work)
3621 struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
3623 struct wm8994 *control = wm8994->wm8994;
3624 struct snd_soc_component *component = wm8994->hubs.component;
3625 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3627 pm_runtime_get_sync(component->dev);
3629 /* If required for an external cap force MICBIAS on */
3630 if (control->pdata.jd_ext_cap) {
3631 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2");
3632 snd_soc_dapm_sync(dapm);
3635 mutex_lock(&wm8994->accdet_lock);
3637 dev_dbg(component->dev, "Starting mic detection\n");
3639 /* Use a user-supplied callback if we have one */
3640 if (wm8994->micd_cb) {
3641 wm8994->micd_cb(wm8994->micd_cb_data);
3644 * Start off measument of microphone impedence to find out
3645 * what's actually there.
3647 wm8994->mic_detecting = true;
3648 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_MIC);
3650 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3651 WM8958_MICD_ENA, WM8958_MICD_ENA);
3654 mutex_unlock(&wm8994->accdet_lock);
3656 pm_runtime_put(component->dev);
3659 static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3661 struct wm8994_priv *wm8994 = data;
3662 struct wm8994 *control = wm8994->wm8994;
3663 struct snd_soc_component *component = wm8994->hubs.component;
3664 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3668 pm_runtime_get_sync(component->dev);
3670 cancel_delayed_work_sync(&wm8994->mic_complete_work);
3672 mutex_lock(&wm8994->accdet_lock);
3674 reg = snd_soc_component_read32(component, WM1811_JACKDET_CTRL);
3676 dev_err(component->dev, "Failed to read jack status: %d\n", reg);
3677 mutex_unlock(&wm8994->accdet_lock);
3678 pm_runtime_put(component->dev);
3682 dev_dbg(component->dev, "JACKDET %x\n", reg);
3684 present = reg & WM1811_JACKDET_LVL;
3687 dev_dbg(component->dev, "Jack detected\n");
3689 wm8958_micd_set_rate(component);
3691 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3692 WM8958_MICB2_DISCH, 0);
3694 /* Disable debounce while inserted */
3695 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3696 WM1811_JACKDET_DB, 0);
3698 delay = control->pdata.micdet_delay;
3699 queue_delayed_work(system_power_efficient_wq,
3701 msecs_to_jiffies(delay));
3703 dev_dbg(component->dev, "Jack not detected\n");
3705 cancel_delayed_work_sync(&wm8994->mic_work);
3707 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3708 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3710 /* Enable debounce while removed */
3711 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3712 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3714 wm8994->mic_detecting = false;
3715 wm8994->jack_mic = false;
3716 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3717 WM8958_MICD_ENA, 0);
3718 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_JACK);
3721 mutex_unlock(&wm8994->accdet_lock);
3723 /* Turn off MICBIAS if it was on for an external cap */
3724 if (control->pdata.jd_ext_cap && !present)
3725 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3728 snd_soc_jack_report(wm8994->micdet[0].jack,
3729 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3731 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3732 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3735 /* Since we only report deltas force an update, ensures we
3736 * avoid bootstrapping issues with the core. */
3737 snd_soc_jack_report(wm8994->micdet[0].jack, 0, 0);
3739 pm_runtime_put(component->dev);
3743 static void wm1811_jackdet_bootstrap(struct work_struct *work)
3745 struct wm8994_priv *wm8994 = container_of(work,
3747 jackdet_bootstrap.work);
3748 wm1811_jackdet_irq(0, wm8994);
3752 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3754 * @component: WM8958 component
3755 * @jack: jack to report detection events on
3757 * Enable microphone detection functionality for the WM8958. By
3758 * default simple detection which supports the detection of up to 6
3759 * buttons plus video and microphone functionality is supported.
3761 * The WM8958 has an advanced jack detection facility which is able to
3762 * support complex accessory detection, especially when used in
3763 * conjunction with external circuitry. In order to provide maximum
3764 * flexiblity a callback is provided which allows a completely custom
3765 * detection algorithm.
3767 int wm8958_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
3768 wm1811_micdet_cb det_cb, void *det_cb_data,
3769 wm1811_mic_id_cb id_cb, void *id_cb_data)
3771 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3772 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3773 struct wm8994 *control = wm8994->wm8994;
3776 switch (control->type) {
3785 snd_soc_dapm_force_enable_pin(dapm, "CLK_SYS");
3786 snd_soc_dapm_sync(dapm);
3788 wm8994->micdet[0].jack = jack;
3791 wm8994->micd_cb = det_cb;
3792 wm8994->micd_cb_data = det_cb_data;
3794 wm8994->mic_detecting = true;
3795 wm8994->jack_mic = false;
3799 wm8994->mic_id_cb = id_cb;
3800 wm8994->mic_id_cb_data = id_cb_data;
3802 wm8994->mic_id_cb = wm8958_mic_id;
3803 wm8994->mic_id_cb_data = component;
3806 wm8958_micd_set_rate(component);
3808 /* Detect microphones and short circuits by default */
3809 if (control->pdata.micd_lvl_sel)
3810 micd_lvl_sel = control->pdata.micd_lvl_sel;
3812 micd_lvl_sel = 0x41;
3814 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3815 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3816 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3818 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_2,
3819 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
3821 WARN_ON(snd_soc_component_get_bias_level(component) > SND_SOC_BIAS_STANDBY);
3824 * If we can use jack detection start off with that,
3825 * otherwise jump straight to microphone detection.
3827 if (wm8994->jackdet) {
3828 /* Disable debounce for the initial detect */
3829 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3830 WM1811_JACKDET_DB, 0);
3832 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3834 WM8958_MICB2_DISCH);
3835 snd_soc_component_update_bits(component, WM8994_LDO_1,
3836 WM8994_LDO1_DISCH, 0);
3837 wm1811_jackdet_set_mode(component,
3838 WM1811_JACKDET_MODE_JACK);
3840 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3841 WM8958_MICD_ENA, WM8958_MICD_ENA);
3845 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3846 WM8958_MICD_ENA, 0);
3847 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_NONE);
3848 snd_soc_dapm_disable_pin(dapm, "CLK_SYS");
3849 snd_soc_dapm_sync(dapm);
3854 EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3856 static void wm8958_mic_work(struct work_struct *work)
3858 struct wm8994_priv *wm8994 = container_of(work,
3860 mic_complete_work.work);
3861 struct snd_soc_component *component = wm8994->hubs.component;
3863 pm_runtime_get_sync(component->dev);
3865 mutex_lock(&wm8994->accdet_lock);
3867 wm8994->mic_id_cb(wm8994->mic_id_cb_data, wm8994->mic_status);
3869 mutex_unlock(&wm8994->accdet_lock);
3871 pm_runtime_put(component->dev);
3874 static irqreturn_t wm8958_mic_irq(int irq, void *data)
3876 struct wm8994_priv *wm8994 = data;
3877 struct snd_soc_component *component = wm8994->hubs.component;
3878 int reg, count, ret, id_delay;
3881 * Jack detection may have detected a removal simulataneously
3882 * with an update of the MICDET status; if so it will have
3883 * stopped detection and we can ignore this interrupt.
3885 if (!(snd_soc_component_read32(component, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
3888 cancel_delayed_work_sync(&wm8994->mic_complete_work);
3889 cancel_delayed_work_sync(&wm8994->open_circuit_work);
3891 pm_runtime_get_sync(component->dev);
3893 /* We may occasionally read a detection without an impedence
3894 * range being provided - if that happens loop again.
3898 reg = snd_soc_component_read32(component, WM8958_MIC_DETECT_3);
3900 dev_err(component->dev,
3901 "Failed to read mic detect status: %d\n",
3903 pm_runtime_put(component->dev);
3907 if (!(reg & WM8958_MICD_VALID)) {
3908 dev_dbg(component->dev, "Mic detect data not valid\n");
3912 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3919 dev_warn(component->dev, "No impedance range reported for jack\n");
3921 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3922 trace_snd_soc_jack_irq(dev_name(component->dev));
3925 /* Avoid a transient report when the accessory is being removed */
3926 if (wm8994->jackdet) {
3927 ret = snd_soc_component_read32(component, WM1811_JACKDET_CTRL);
3929 dev_err(component->dev, "Failed to read jack status: %d\n",
3931 } else if (!(ret & WM1811_JACKDET_LVL)) {
3932 dev_dbg(component->dev, "Ignoring removed jack\n");
3935 } else if (!(reg & WM8958_MICD_STS)) {
3936 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3937 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3939 wm8994->mic_detecting = true;
3943 wm8994->mic_status = reg;
3944 id_delay = wm8994->wm8994->pdata.mic_id_delay;
3946 if (wm8994->mic_detecting)
3947 queue_delayed_work(system_power_efficient_wq,
3948 &wm8994->mic_complete_work,
3949 msecs_to_jiffies(id_delay));
3951 wm8958_button_det(component, reg);
3954 pm_runtime_put(component->dev);
3958 static irqreturn_t wm8994_fifo_error(int irq, void *data)
3960 struct snd_soc_component *component = data;
3962 dev_err(component->dev, "FIFO error\n");
3967 static irqreturn_t wm8994_temp_warn(int irq, void *data)
3969 struct snd_soc_component *component = data;
3971 dev_err(component->dev, "Thermal warning\n");
3976 static irqreturn_t wm8994_temp_shut(int irq, void *data)
3978 struct snd_soc_component *component = data;
3980 dev_crit(component->dev, "Thermal shutdown\n");
3985 static int wm8994_component_probe(struct snd_soc_component *component)
3987 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3988 struct wm8994 *control = dev_get_drvdata(component->dev->parent);
3989 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3993 snd_soc_component_init_regmap(component, control->regmap);
3995 wm8994->hubs.component = component;
3997 mutex_init(&wm8994->accdet_lock);
3998 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
3999 wm1811_jackdet_bootstrap);
4000 INIT_DELAYED_WORK(&wm8994->open_circuit_work,
4001 wm8958_open_circuit_work);
4003 switch (control->type) {
4005 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
4008 INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
4014 INIT_DELAYED_WORK(&wm8994->mic_complete_work, wm8958_mic_work);
4016 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4017 init_completion(&wm8994->fll_locked[i]);
4019 wm8994->micdet_irq = control->pdata.micdet_irq;
4021 /* By default use idle_bias_off, will override for WM8994 */
4022 dapm->idle_bias_off = 1;
4024 /* Set revision-specific configuration */
4025 switch (control->type) {
4027 /* Single ended line outputs should have VMID on. */
4028 if (!control->pdata.lineout1_diff ||
4029 !control->pdata.lineout2_diff)
4030 dapm->idle_bias_off = 0;
4032 switch (control->revision) {
4035 wm8994->hubs.dcs_codes_l = -5;
4036 wm8994->hubs.dcs_codes_r = -5;
4037 wm8994->hubs.hp_startup_mode = 1;
4038 wm8994->hubs.dcs_readback_mode = 1;
4039 wm8994->hubs.series_startup = 1;
4042 wm8994->hubs.dcs_readback_mode = 2;
4048 wm8994->hubs.dcs_readback_mode = 1;
4049 wm8994->hubs.hp_startup_mode = 1;
4051 switch (control->revision) {
4055 wm8994->fll_byp = true;
4061 wm8994->hubs.dcs_readback_mode = 2;
4062 wm8994->hubs.no_series_update = 1;
4063 wm8994->hubs.hp_startup_mode = 1;
4064 wm8994->hubs.no_cache_dac_hp_direct = true;
4065 wm8994->fll_byp = true;
4067 wm8994->hubs.dcs_codes_l = -9;
4068 wm8994->hubs.dcs_codes_r = -7;
4070 snd_soc_component_update_bits(component, WM8994_ANALOGUE_HP_1,
4071 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
4078 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
4079 wm8994_fifo_error, "FIFO error", component);
4080 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
4081 wm8994_temp_warn, "Thermal warning", component);
4082 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
4083 wm8994_temp_shut, "Thermal shutdown", component);
4085 switch (control->type) {
4087 if (wm8994->micdet_irq)
4088 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4090 IRQF_TRIGGER_RISING |
4095 ret = wm8994_request_irq(wm8994->wm8994,
4096 WM8994_IRQ_MIC1_DET,
4097 wm8994_mic_irq, "Mic 1 detect",
4101 dev_warn(component->dev,
4102 "Failed to request Mic1 detect IRQ: %d\n",
4106 ret = wm8994_request_irq(wm8994->wm8994,
4107 WM8994_IRQ_MIC1_SHRT,
4108 wm8994_mic_irq, "Mic 1 short",
4111 dev_warn(component->dev,
4112 "Failed to request Mic1 short IRQ: %d\n",
4115 ret = wm8994_request_irq(wm8994->wm8994,
4116 WM8994_IRQ_MIC2_DET,
4117 wm8994_mic_irq, "Mic 2 detect",
4120 dev_warn(component->dev,
4121 "Failed to request Mic2 detect IRQ: %d\n",
4124 ret = wm8994_request_irq(wm8994->wm8994,
4125 WM8994_IRQ_MIC2_SHRT,
4126 wm8994_mic_irq, "Mic 2 short",
4129 dev_warn(component->dev,
4130 "Failed to request Mic2 short IRQ: %d\n",
4136 if (wm8994->micdet_irq) {
4137 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4139 IRQF_TRIGGER_RISING |
4144 dev_warn(component->dev,
4145 "Failed to request Mic detect IRQ: %d\n",
4148 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4149 wm8958_mic_irq, "Mic detect",
4154 switch (control->type) {
4156 if (control->cust_id > 1 || control->revision > 1) {
4157 ret = wm8994_request_irq(wm8994->wm8994,
4159 wm1811_jackdet_irq, "JACKDET",
4162 wm8994->jackdet = true;
4169 wm8994->fll_locked_irq = true;
4170 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
4171 ret = wm8994_request_irq(wm8994->wm8994,
4172 WM8994_IRQ_FLL1_LOCK + i,
4173 wm8994_fll_locked_irq, "FLL lock",
4174 &wm8994->fll_locked[i]);
4176 wm8994->fll_locked_irq = false;
4179 /* Make sure we can read from the GPIOs if they're inputs */
4180 pm_runtime_get_sync(component->dev);
4182 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
4183 * configured on init - if a system wants to do this dynamically
4184 * at runtime we can deal with that then.
4186 ret = regmap_read(control->regmap, WM8994_GPIO_1, ®);
4188 dev_err(component->dev, "Failed to read GPIO1 state: %d\n", ret);
4191 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
4192 wm8994->lrclk_shared[0] = 1;
4193 wm8994_dai[0].symmetric_rates = 1;
4195 wm8994->lrclk_shared[0] = 0;
4198 ret = regmap_read(control->regmap, WM8994_GPIO_6, ®);
4200 dev_err(component->dev, "Failed to read GPIO6 state: %d\n", ret);
4203 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
4204 wm8994->lrclk_shared[1] = 1;
4205 wm8994_dai[1].symmetric_rates = 1;
4207 wm8994->lrclk_shared[1] = 0;
4210 pm_runtime_put(component->dev);
4212 /* Latch volume update bits */
4213 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
4214 snd_soc_component_update_bits(component, wm8994_vu_bits[i].reg,
4215 wm8994_vu_bits[i].mask,
4216 wm8994_vu_bits[i].mask);
4218 /* Set the low bit of the 3D stereo depth so TLV matches */
4219 snd_soc_component_update_bits(component, WM8994_AIF1_DAC1_FILTERS_2,
4220 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
4221 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
4222 snd_soc_component_update_bits(component, WM8994_AIF1_DAC2_FILTERS_2,
4223 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
4224 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
4225 snd_soc_component_update_bits(component, WM8994_AIF2_DAC_FILTERS_2,
4226 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
4227 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
4229 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
4230 * use this; it only affects behaviour on idle TDM clock
4232 switch (control->type) {
4235 snd_soc_component_update_bits(component, WM8994_AIF1_CONTROL_1,
4236 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
4242 /* Put MICBIAS into bypass mode by default on newer devices */
4243 switch (control->type) {
4246 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
4247 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
4248 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
4249 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
4255 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
4256 wm_hubs_update_class_w(component);
4258 wm8994_handle_pdata(wm8994);
4260 wm_hubs_add_analogue_controls(component);
4261 snd_soc_add_component_controls(component, wm8994_snd_controls,
4262 ARRAY_SIZE(wm8994_snd_controls));
4263 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
4264 ARRAY_SIZE(wm8994_dapm_widgets));
4266 switch (control->type) {
4268 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
4269 ARRAY_SIZE(wm8994_specific_dapm_widgets));
4270 if (control->revision < 4) {
4271 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4272 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4273 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4274 ARRAY_SIZE(wm8994_adc_revd_widgets));
4275 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4276 ARRAY_SIZE(wm8994_dac_revd_widgets));
4278 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4279 ARRAY_SIZE(wm8994_lateclk_widgets));
4280 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4281 ARRAY_SIZE(wm8994_adc_widgets));
4282 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4283 ARRAY_SIZE(wm8994_dac_widgets));
4287 snd_soc_add_component_controls(component, wm8958_snd_controls,
4288 ARRAY_SIZE(wm8958_snd_controls));
4289 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4290 ARRAY_SIZE(wm8958_dapm_widgets));
4291 if (control->revision < 1) {
4292 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4293 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4294 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4295 ARRAY_SIZE(wm8994_adc_revd_widgets));
4296 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4297 ARRAY_SIZE(wm8994_dac_revd_widgets));
4299 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4300 ARRAY_SIZE(wm8994_lateclk_widgets));
4301 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4302 ARRAY_SIZE(wm8994_adc_widgets));
4303 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4304 ARRAY_SIZE(wm8994_dac_widgets));
4309 snd_soc_add_component_controls(component, wm8958_snd_controls,
4310 ARRAY_SIZE(wm8958_snd_controls));
4311 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4312 ARRAY_SIZE(wm8958_dapm_widgets));
4313 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4314 ARRAY_SIZE(wm8994_lateclk_widgets));
4315 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4316 ARRAY_SIZE(wm8994_adc_widgets));
4317 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4318 ARRAY_SIZE(wm8994_dac_widgets));
4322 wm_hubs_add_analogue_routes(component, 0, 0);
4323 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4324 wm_hubs_dcs_done, "DC servo done",
4327 wm8994->hubs.dcs_done_irq = true;
4328 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
4330 switch (control->type) {
4332 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4333 ARRAY_SIZE(wm8994_intercon));
4335 if (control->revision < 4) {
4336 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4337 ARRAY_SIZE(wm8994_revd_intercon));
4338 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4339 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4341 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4342 ARRAY_SIZE(wm8994_lateclk_intercon));
4346 if (control->revision < 1) {
4347 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4348 ARRAY_SIZE(wm8994_intercon));
4349 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4350 ARRAY_SIZE(wm8994_revd_intercon));
4351 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4352 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4354 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4355 ARRAY_SIZE(wm8994_lateclk_intercon));
4356 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4357 ARRAY_SIZE(wm8958_intercon));
4360 wm8958_dsp2_init(component);
4363 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4364 ARRAY_SIZE(wm8994_lateclk_intercon));
4365 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4366 ARRAY_SIZE(wm8958_intercon));
4373 if (wm8994->jackdet)
4374 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4375 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4376 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4377 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
4378 if (wm8994->micdet_irq)
4379 free_irq(wm8994->micdet_irq, wm8994);
4380 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4381 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4382 &wm8994->fll_locked[i]);
4383 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4385 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, component);
4386 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, component);
4387 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, component);
4392 static void wm8994_component_remove(struct snd_soc_component *component)
4394 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
4395 struct wm8994 *control = wm8994->wm8994;
4398 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4399 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4400 &wm8994->fll_locked[i]);
4402 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4404 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, component);
4405 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, component);
4406 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, component);
4408 if (wm8994->jackdet)
4409 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4411 switch (control->type) {
4413 if (wm8994->micdet_irq)
4414 free_irq(wm8994->micdet_irq, wm8994);
4415 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
4417 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
4419 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4425 if (wm8994->micdet_irq)
4426 free_irq(wm8994->micdet_irq, wm8994);
4429 release_firmware(wm8994->mbc);
4430 release_firmware(wm8994->mbc_vss);
4431 release_firmware(wm8994->enh_eq);
4432 kfree(wm8994->retune_mobile_texts);
4435 static const struct snd_soc_component_driver soc_component_dev_wm8994 = {
4436 .probe = wm8994_component_probe,
4437 .remove = wm8994_component_remove,
4438 .suspend = wm8994_component_suspend,
4439 .resume = wm8994_component_resume,
4440 .set_bias_level = wm8994_set_bias_level,
4442 .use_pmdown_time = 1,
4444 .non_legacy_dai_naming = 1,
4447 static int wm8994_probe(struct platform_device *pdev)
4449 struct wm8994_priv *wm8994;
4451 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4455 platform_set_drvdata(pdev, wm8994);
4457 mutex_init(&wm8994->fw_lock);
4459 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
4461 pm_runtime_enable(&pdev->dev);
4462 pm_runtime_idle(&pdev->dev);
4464 return devm_snd_soc_register_component(&pdev->dev, &soc_component_dev_wm8994,
4465 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4468 static int wm8994_remove(struct platform_device *pdev)
4470 pm_runtime_disable(&pdev->dev);
4475 #ifdef CONFIG_PM_SLEEP
4476 static int wm8994_suspend(struct device *dev)
4478 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4480 /* Drop down to power saving mode when system is suspended */
4481 if (wm8994->jackdet && !wm8994->active_refcount)
4482 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4483 WM1811_JACKDET_MODE_MASK,
4484 wm8994->jackdet_mode);
4489 static int wm8994_resume(struct device *dev)
4491 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4493 if (wm8994->jackdet && wm8994->jackdet_mode)
4494 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4495 WM1811_JACKDET_MODE_MASK,
4496 WM1811_JACKDET_MODE_AUDIO);
4502 static const struct dev_pm_ops wm8994_pm_ops = {
4503 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4506 static struct platform_driver wm8994_codec_driver = {
4508 .name = "wm8994-codec",
4509 .pm = &wm8994_pm_ops,
4511 .probe = wm8994_probe,
4512 .remove = wm8994_remove,
4515 module_platform_driver(wm8994_codec_driver);
4517 MODULE_DESCRIPTION("ASoC WM8994 driver");
4519 MODULE_LICENSE("GPL");
4520 MODULE_ALIAS("platform:wm8994-codec");