1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8994.c -- WM8994 ALSA SoC Audio driver
5 * Copyright 2009-12 Wolfson Microelectronics plc
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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_common_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("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
541 WM8994_AIF2_ADC_RIGHT_VOLUME,
542 1, 119, 0, digital_tlv),
544 SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
545 SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
546 SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
547 SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
549 SOC_ENUM("AIF1DACL Source", aif1dacl_src),
550 SOC_ENUM("AIF1DACR Source", aif1dacr_src),
551 SOC_ENUM("AIF2DACL Source", aif2dacl_src),
552 SOC_ENUM("AIF2DACR Source", aif2dacr_src),
554 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
555 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
556 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
557 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
559 SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
560 SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
562 SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
563 SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
565 WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
566 WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
567 WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
569 WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
570 WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
571 WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
573 SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
575 SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
577 SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
579 SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
581 SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
582 SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
584 SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
585 SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
587 SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
588 SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
590 SOC_ENUM("ADC OSR", adc_osr),
591 SOC_ENUM("DAC OSR", dac_osr),
593 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
594 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
595 SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
596 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
598 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
599 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
600 SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
601 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
603 SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
604 6, 1, 1, wm_hubs_spkmix_tlv),
605 SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
606 2, 1, 1, wm_hubs_spkmix_tlv),
608 SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
609 6, 1, 1, wm_hubs_spkmix_tlv),
610 SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
611 2, 1, 1, wm_hubs_spkmix_tlv),
613 SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
614 10, 15, 0, wm8994_3d_tlv),
615 SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
617 SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
618 10, 15, 0, wm8994_3d_tlv),
619 SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
621 SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
622 10, 15, 0, wm8994_3d_tlv),
623 SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
627 /* Controls not available on WM1811 */
628 static const struct snd_kcontrol_new wm8994_snd_controls[] = {
629 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
630 WM8994_AIF1_ADC2_RIGHT_VOLUME,
631 1, 119, 0, digital_tlv),
632 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
633 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
635 SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
637 WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
638 WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
639 WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
641 SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
642 SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
645 static const struct snd_kcontrol_new wm8994_eq_controls[] = {
646 SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
648 SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
650 SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
652 SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
654 SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
657 SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
659 SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
661 SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
663 SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
665 SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
668 SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
670 SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
672 SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
674 SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
676 SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
680 static const struct snd_kcontrol_new wm8994_drc_controls[] = {
681 SND_SOC_BYTES_MASK("AIF1.1 DRC", WM8994_AIF1_DRC1_1, 5,
682 WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
683 WM8994_AIF1ADC1R_DRC_ENA),
684 SND_SOC_BYTES_MASK("AIF1.2 DRC", WM8994_AIF1_DRC2_1, 5,
685 WM8994_AIF1DAC2_DRC_ENA | WM8994_AIF1ADC2L_DRC_ENA |
686 WM8994_AIF1ADC2R_DRC_ENA),
687 SND_SOC_BYTES_MASK("AIF2 DRC", WM8994_AIF2_DRC_1, 5,
688 WM8994_AIF2DAC_DRC_ENA | WM8994_AIF2ADCL_DRC_ENA |
689 WM8994_AIF2ADCR_DRC_ENA),
692 static const char *wm8958_ng_text[] = {
693 "30ms", "125ms", "250ms", "500ms",
696 static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac1_ng_hold,
697 WM8958_AIF1_DAC1_NOISE_GATE,
698 WM8958_AIF1DAC1_NG_THR_SHIFT,
701 static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac2_ng_hold,
702 WM8958_AIF1_DAC2_NOISE_GATE,
703 WM8958_AIF1DAC2_NG_THR_SHIFT,
706 static SOC_ENUM_SINGLE_DECL(wm8958_aif2dac_ng_hold,
707 WM8958_AIF2_DAC_NOISE_GATE,
708 WM8958_AIF2DAC_NG_THR_SHIFT,
711 static const struct snd_kcontrol_new wm8958_snd_controls[] = {
712 SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
714 SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
715 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
716 SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
717 SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
718 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
721 SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
722 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
723 SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
724 SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
725 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
728 SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
729 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
730 SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
731 SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
732 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
736 static const struct snd_kcontrol_new wm1811_snd_controls[] = {
737 SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
739 SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
743 /* We run all mode setting through a function to enforce audio mode */
744 static void wm1811_jackdet_set_mode(struct snd_soc_component *component, u16 mode)
746 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
748 if (!wm8994->jackdet || !wm8994->micdet[0].jack)
751 if (wm8994->active_refcount)
752 mode = WM1811_JACKDET_MODE_AUDIO;
754 if (mode == wm8994->jackdet_mode)
757 wm8994->jackdet_mode = mode;
759 /* Always use audio mode to detect while the system is active */
760 if (mode != WM1811_JACKDET_MODE_NONE)
761 mode = WM1811_JACKDET_MODE_AUDIO;
763 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
764 WM1811_JACKDET_MODE_MASK, mode);
767 static void active_reference(struct snd_soc_component *component)
769 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
771 mutex_lock(&wm8994->accdet_lock);
773 wm8994->active_refcount++;
775 dev_dbg(component->dev, "Active refcount incremented, now %d\n",
776 wm8994->active_refcount);
778 /* If we're using jack detection go into audio mode */
779 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_AUDIO);
781 mutex_unlock(&wm8994->accdet_lock);
784 static void active_dereference(struct snd_soc_component *component)
786 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
789 mutex_lock(&wm8994->accdet_lock);
791 wm8994->active_refcount--;
793 dev_dbg(component->dev, "Active refcount decremented, now %d\n",
794 wm8994->active_refcount);
796 if (wm8994->active_refcount == 0) {
797 /* Go into appropriate detection only mode */
798 if (wm8994->jack_mic || wm8994->mic_detecting)
799 mode = WM1811_JACKDET_MODE_MIC;
801 mode = WM1811_JACKDET_MODE_JACK;
803 wm1811_jackdet_set_mode(component, mode);
806 mutex_unlock(&wm8994->accdet_lock);
809 static int clk_sys_event(struct snd_soc_dapm_widget *w,
810 struct snd_kcontrol *kcontrol, int event)
812 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
813 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
816 case SND_SOC_DAPM_PRE_PMU:
817 return configure_clock(component);
819 case SND_SOC_DAPM_POST_PMU:
821 * JACKDET won't run until we start the clock and it
822 * only reports deltas, make sure we notify the state
823 * up the stack on startup. Use a *very* generous
824 * timeout for paranoia, there's no urgency and we
825 * don't want false reports.
827 if (wm8994->jackdet && !wm8994->clk_has_run) {
828 queue_delayed_work(system_power_efficient_wq,
829 &wm8994->jackdet_bootstrap,
830 msecs_to_jiffies(1000));
831 wm8994->clk_has_run = true;
835 case SND_SOC_DAPM_POST_PMD:
836 configure_clock(component);
843 static void vmid_reference(struct snd_soc_component *component)
845 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
847 pm_runtime_get_sync(component->dev);
849 wm8994->vmid_refcount++;
851 dev_dbg(component->dev, "Referencing VMID, refcount is now %d\n",
852 wm8994->vmid_refcount);
854 if (wm8994->vmid_refcount == 1) {
855 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
856 WM8994_LINEOUT1_DISCH |
857 WM8994_LINEOUT2_DISCH, 0);
859 wm_hubs_vmid_ena(component);
861 switch (wm8994->vmid_mode) {
863 WARN_ON(NULL == "Invalid VMID mode");
865 case WM8994_VMID_NORMAL:
866 /* Startup bias, VMID ramp & buffer */
867 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
870 WM8994_STARTUP_BIAS_ENA |
871 WM8994_VMID_BUF_ENA |
872 WM8994_VMID_RAMP_MASK,
874 WM8994_STARTUP_BIAS_ENA |
875 WM8994_VMID_BUF_ENA |
876 (0x2 << WM8994_VMID_RAMP_SHIFT));
878 /* Main bias enable, VMID=2x40k */
879 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
881 WM8994_VMID_SEL_MASK,
882 WM8994_BIAS_ENA | 0x2);
886 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
887 WM8994_VMID_RAMP_MASK |
892 case WM8994_VMID_FORCE:
893 /* Startup bias, slow VMID ramp & buffer */
894 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
897 WM8994_STARTUP_BIAS_ENA |
898 WM8994_VMID_BUF_ENA |
899 WM8994_VMID_RAMP_MASK,
901 WM8994_STARTUP_BIAS_ENA |
902 WM8994_VMID_BUF_ENA |
903 (0x2 << WM8994_VMID_RAMP_SHIFT));
905 /* Main bias enable, VMID=2x40k */
906 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
908 WM8994_VMID_SEL_MASK,
909 WM8994_BIAS_ENA | 0x2);
913 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
914 WM8994_VMID_RAMP_MASK |
922 static void vmid_dereference(struct snd_soc_component *component)
924 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
926 wm8994->vmid_refcount--;
928 dev_dbg(component->dev, "Dereferencing VMID, refcount is now %d\n",
929 wm8994->vmid_refcount);
931 if (wm8994->vmid_refcount == 0) {
932 if (wm8994->hubs.lineout1_se)
933 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
934 WM8994_LINEOUT1N_ENA |
935 WM8994_LINEOUT1P_ENA,
936 WM8994_LINEOUT1N_ENA |
937 WM8994_LINEOUT1P_ENA);
939 if (wm8994->hubs.lineout2_se)
940 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
941 WM8994_LINEOUT2N_ENA |
942 WM8994_LINEOUT2P_ENA,
943 WM8994_LINEOUT2N_ENA |
944 WM8994_LINEOUT2P_ENA);
946 /* Start discharging VMID */
947 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
953 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
954 WM8994_VMID_SEL_MASK, 0);
958 /* Active discharge */
959 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
960 WM8994_LINEOUT1_DISCH |
961 WM8994_LINEOUT2_DISCH,
962 WM8994_LINEOUT1_DISCH |
963 WM8994_LINEOUT2_DISCH);
965 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_3,
966 WM8994_LINEOUT1N_ENA |
967 WM8994_LINEOUT1P_ENA |
968 WM8994_LINEOUT2N_ENA |
969 WM8994_LINEOUT2P_ENA, 0);
971 /* Switch off startup biases */
972 snd_soc_component_update_bits(component, WM8994_ANTIPOP_2,
974 WM8994_STARTUP_BIAS_ENA |
975 WM8994_VMID_BUF_ENA |
976 WM8994_VMID_RAMP_MASK, 0);
978 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_1,
979 WM8994_VMID_SEL_MASK, 0);
982 pm_runtime_put(component->dev);
985 static int vmid_event(struct snd_soc_dapm_widget *w,
986 struct snd_kcontrol *kcontrol, int event)
988 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
991 case SND_SOC_DAPM_PRE_PMU:
992 vmid_reference(component);
995 case SND_SOC_DAPM_POST_PMD:
996 vmid_dereference(component);
1003 static bool wm8994_check_class_w_digital(struct snd_soc_component *component)
1005 int source = 0; /* GCC flow analysis can't track enable */
1008 /* We also need the same AIF source for L/R and only one path */
1009 reg = snd_soc_component_read32(component, WM8994_DAC1_LEFT_MIXER_ROUTING);
1011 case WM8994_AIF2DACL_TO_DAC1L:
1012 dev_vdbg(component->dev, "Class W source AIF2DAC\n");
1013 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1015 case WM8994_AIF1DAC2L_TO_DAC1L:
1016 dev_vdbg(component->dev, "Class W source AIF1DAC2\n");
1017 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1019 case WM8994_AIF1DAC1L_TO_DAC1L:
1020 dev_vdbg(component->dev, "Class W source AIF1DAC1\n");
1021 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
1024 dev_vdbg(component->dev, "DAC mixer setting: %x\n", reg);
1028 reg_r = snd_soc_component_read32(component, WM8994_DAC1_RIGHT_MIXER_ROUTING);
1030 dev_vdbg(component->dev, "Left and right DAC mixers different\n");
1034 /* Set the source up */
1035 snd_soc_component_update_bits(component, WM8994_CLASS_W_1,
1036 WM8994_CP_DYN_SRC_SEL_MASK, source);
1041 static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1042 struct snd_kcontrol *kcontrol, int event)
1044 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1045 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1046 struct wm8994 *control = wm8994->wm8994;
1047 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
1053 switch (control->type) {
1056 mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
1063 case SND_SOC_DAPM_PRE_PMU:
1064 /* Don't enable timeslot 2 if not in use */
1065 if (wm8994->channels[0] <= 2)
1066 mask &= ~(WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
1068 val = snd_soc_component_read32(component, WM8994_AIF1_CONTROL_1);
1069 if ((val & WM8994_AIF1ADCL_SRC) &&
1070 (val & WM8994_AIF1ADCR_SRC))
1071 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
1072 else if (!(val & WM8994_AIF1ADCL_SRC) &&
1073 !(val & WM8994_AIF1ADCR_SRC))
1074 adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1076 adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
1077 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
1079 val = snd_soc_component_read32(component, WM8994_AIF1_CONTROL_2);
1080 if ((val & WM8994_AIF1DACL_SRC) &&
1081 (val & WM8994_AIF1DACR_SRC))
1082 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
1083 else if (!(val & WM8994_AIF1DACL_SRC) &&
1084 !(val & WM8994_AIF1DACR_SRC))
1085 dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1087 dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
1088 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
1090 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1092 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1094 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1095 WM8994_AIF1DSPCLK_ENA |
1096 WM8994_SYSDSPCLK_ENA,
1097 WM8994_AIF1DSPCLK_ENA |
1098 WM8994_SYSDSPCLK_ENA);
1099 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4, mask,
1100 WM8994_AIF1ADC1R_ENA |
1101 WM8994_AIF1ADC1L_ENA |
1102 WM8994_AIF1ADC2R_ENA |
1103 WM8994_AIF1ADC2L_ENA);
1104 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5, mask,
1105 WM8994_AIF1DAC1R_ENA |
1106 WM8994_AIF1DAC1L_ENA |
1107 WM8994_AIF1DAC2R_ENA |
1108 WM8994_AIF1DAC2L_ENA);
1111 case SND_SOC_DAPM_POST_PMU:
1112 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1113 snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1114 snd_soc_component_read32(component,
1115 wm8994_vu_bits[i].reg));
1118 case SND_SOC_DAPM_PRE_PMD:
1119 case SND_SOC_DAPM_POST_PMD:
1120 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1122 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1125 val = snd_soc_component_read32(component, WM8994_CLOCKING_1);
1126 if (val & WM8994_AIF2DSPCLK_ENA)
1127 val = WM8994_SYSDSPCLK_ENA;
1130 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1131 WM8994_SYSDSPCLK_ENA |
1132 WM8994_AIF1DSPCLK_ENA, val);
1139 static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1140 struct snd_kcontrol *kcontrol, int event)
1142 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1149 case SND_SOC_DAPM_PRE_PMU:
1150 val = snd_soc_component_read32(component, WM8994_AIF2_CONTROL_1);
1151 if ((val & WM8994_AIF2ADCL_SRC) &&
1152 (val & WM8994_AIF2ADCR_SRC))
1153 adc = WM8994_AIF2ADCR_ENA;
1154 else if (!(val & WM8994_AIF2ADCL_SRC) &&
1155 !(val & WM8994_AIF2ADCR_SRC))
1156 adc = WM8994_AIF2ADCL_ENA;
1158 adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
1161 val = snd_soc_component_read32(component, WM8994_AIF2_CONTROL_2);
1162 if ((val & WM8994_AIF2DACL_SRC) &&
1163 (val & WM8994_AIF2DACR_SRC))
1164 dac = WM8994_AIF2DACR_ENA;
1165 else if (!(val & WM8994_AIF2DACL_SRC) &&
1166 !(val & WM8994_AIF2DACR_SRC))
1167 dac = WM8994_AIF2DACL_ENA;
1169 dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
1171 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1172 WM8994_AIF2ADCL_ENA |
1173 WM8994_AIF2ADCR_ENA, adc);
1174 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1175 WM8994_AIF2DACL_ENA |
1176 WM8994_AIF2DACR_ENA, dac);
1177 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1178 WM8994_AIF2DSPCLK_ENA |
1179 WM8994_SYSDSPCLK_ENA,
1180 WM8994_AIF2DSPCLK_ENA |
1181 WM8994_SYSDSPCLK_ENA);
1182 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1183 WM8994_AIF2ADCL_ENA |
1184 WM8994_AIF2ADCR_ENA,
1185 WM8994_AIF2ADCL_ENA |
1186 WM8994_AIF2ADCR_ENA);
1187 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1188 WM8994_AIF2DACL_ENA |
1189 WM8994_AIF2DACR_ENA,
1190 WM8994_AIF2DACL_ENA |
1191 WM8994_AIF2DACR_ENA);
1194 case SND_SOC_DAPM_POST_PMU:
1195 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1196 snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1197 snd_soc_component_read32(component,
1198 wm8994_vu_bits[i].reg));
1201 case SND_SOC_DAPM_PRE_PMD:
1202 case SND_SOC_DAPM_POST_PMD:
1203 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1204 WM8994_AIF2DACL_ENA |
1205 WM8994_AIF2DACR_ENA, 0);
1206 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_4,
1207 WM8994_AIF2ADCL_ENA |
1208 WM8994_AIF2ADCR_ENA, 0);
1210 val = snd_soc_component_read32(component, WM8994_CLOCKING_1);
1211 if (val & WM8994_AIF1DSPCLK_ENA)
1212 val = WM8994_SYSDSPCLK_ENA;
1215 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
1216 WM8994_SYSDSPCLK_ENA |
1217 WM8994_AIF2DSPCLK_ENA, val);
1224 static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1225 struct snd_kcontrol *kcontrol, int event)
1227 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1228 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1231 case SND_SOC_DAPM_PRE_PMU:
1232 wm8994->aif1clk_enable = 1;
1234 case SND_SOC_DAPM_POST_PMD:
1235 wm8994->aif1clk_disable = 1;
1242 static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1243 struct snd_kcontrol *kcontrol, int event)
1245 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1246 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1249 case SND_SOC_DAPM_PRE_PMU:
1250 wm8994->aif2clk_enable = 1;
1252 case SND_SOC_DAPM_POST_PMD:
1253 wm8994->aif2clk_disable = 1;
1260 static int late_enable_ev(struct snd_soc_dapm_widget *w,
1261 struct snd_kcontrol *kcontrol, int event)
1263 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1264 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1267 case SND_SOC_DAPM_PRE_PMU:
1268 if (wm8994->aif1clk_enable) {
1269 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1270 snd_soc_component_update_bits(component, WM8994_AIF1_CLOCKING_1,
1271 WM8994_AIF1CLK_ENA_MASK,
1272 WM8994_AIF1CLK_ENA);
1273 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1274 wm8994->aif1clk_enable = 0;
1276 if (wm8994->aif2clk_enable) {
1277 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
1278 snd_soc_component_update_bits(component, WM8994_AIF2_CLOCKING_1,
1279 WM8994_AIF2CLK_ENA_MASK,
1280 WM8994_AIF2CLK_ENA);
1281 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
1282 wm8994->aif2clk_enable = 0;
1287 /* We may also have postponed startup of DSP, handle that. */
1288 wm8958_aif_ev(w, kcontrol, event);
1293 static int late_disable_ev(struct snd_soc_dapm_widget *w,
1294 struct snd_kcontrol *kcontrol, int event)
1296 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1297 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1300 case SND_SOC_DAPM_POST_PMD:
1301 if (wm8994->aif1clk_disable) {
1302 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1303 snd_soc_component_update_bits(component, WM8994_AIF1_CLOCKING_1,
1304 WM8994_AIF1CLK_ENA_MASK, 0);
1305 aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1306 wm8994->aif1clk_disable = 0;
1308 if (wm8994->aif2clk_disable) {
1309 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
1310 snd_soc_component_update_bits(component, WM8994_AIF2_CLOCKING_1,
1311 WM8994_AIF2CLK_ENA_MASK, 0);
1312 aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
1313 wm8994->aif2clk_disable = 0;
1321 static int adc_mux_ev(struct snd_soc_dapm_widget *w,
1322 struct snd_kcontrol *kcontrol, int event)
1324 late_enable_ev(w, kcontrol, event);
1328 static int micbias_ev(struct snd_soc_dapm_widget *w,
1329 struct snd_kcontrol *kcontrol, int event)
1331 late_enable_ev(w, kcontrol, event);
1335 static int dac_ev(struct snd_soc_dapm_widget *w,
1336 struct snd_kcontrol *kcontrol, int event)
1338 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1339 unsigned int mask = 1 << w->shift;
1341 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_5,
1346 static const char *adc_mux_text[] = {
1351 static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
1353 static const struct snd_kcontrol_new adcl_mux =
1354 SOC_DAPM_ENUM("ADCL Mux", adc_enum);
1356 static const struct snd_kcontrol_new adcr_mux =
1357 SOC_DAPM_ENUM("ADCR Mux", adc_enum);
1359 static const struct snd_kcontrol_new left_speaker_mixer[] = {
1360 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1361 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1362 SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1363 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1364 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1367 static const struct snd_kcontrol_new right_speaker_mixer[] = {
1368 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1369 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1370 SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1371 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1372 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1375 /* Debugging; dump chip status after DAPM transitions */
1376 static int post_ev(struct snd_soc_dapm_widget *w,
1377 struct snd_kcontrol *kcontrol, int event)
1379 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1380 dev_dbg(component->dev, "SRC status: %x\n",
1381 snd_soc_component_read32(component,
1382 WM8994_RATE_STATUS));
1386 static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1387 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1389 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1393 static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1394 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1396 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1400 static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1401 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1403 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1407 static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1408 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1410 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1414 static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1415 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1417 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1419 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1421 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1423 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1427 static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1428 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1430 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1432 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1434 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1436 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1440 #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1441 SOC_SINGLE_EXT(xname, reg, shift, max, invert, \
1442 snd_soc_dapm_get_volsw, wm8994_put_class_w)
1444 static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1445 struct snd_ctl_elem_value *ucontrol)
1447 struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol);
1450 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1452 wm_hubs_update_class_w(component);
1457 static const struct snd_kcontrol_new dac1l_mix[] = {
1458 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1460 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1462 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1464 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1466 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1470 static const struct snd_kcontrol_new dac1r_mix[] = {
1471 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1473 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1475 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1477 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1479 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1483 static const char *sidetone_text[] = {
1484 "ADC/DMIC1", "DMIC2",
1487 static SOC_ENUM_SINGLE_DECL(sidetone1_enum,
1488 WM8994_SIDETONE, 0, sidetone_text);
1490 static const struct snd_kcontrol_new sidetone1_mux =
1491 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1493 static SOC_ENUM_SINGLE_DECL(sidetone2_enum,
1494 WM8994_SIDETONE, 1, sidetone_text);
1496 static const struct snd_kcontrol_new sidetone2_mux =
1497 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1499 static const char *aif1dac_text[] = {
1500 "AIF1DACDAT", "AIF3DACDAT",
1503 static const char *loopback_text[] = {
1507 static SOC_ENUM_SINGLE_DECL(aif1_loopback_enum,
1508 WM8994_AIF1_CONTROL_2,
1509 WM8994_AIF1_LOOPBACK_SHIFT,
1512 static const struct snd_kcontrol_new aif1_loopback =
1513 SOC_DAPM_ENUM("AIF1 Loopback", aif1_loopback_enum);
1515 static SOC_ENUM_SINGLE_DECL(aif2_loopback_enum,
1516 WM8994_AIF2_CONTROL_2,
1517 WM8994_AIF2_LOOPBACK_SHIFT,
1520 static const struct snd_kcontrol_new aif2_loopback =
1521 SOC_DAPM_ENUM("AIF2 Loopback", aif2_loopback_enum);
1523 static SOC_ENUM_SINGLE_DECL(aif1dac_enum,
1524 WM8994_POWER_MANAGEMENT_6, 0, aif1dac_text);
1526 static const struct snd_kcontrol_new aif1dac_mux =
1527 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1529 static const char *aif2dac_text[] = {
1530 "AIF2DACDAT", "AIF3DACDAT",
1533 static SOC_ENUM_SINGLE_DECL(aif2dac_enum,
1534 WM8994_POWER_MANAGEMENT_6, 1, aif2dac_text);
1536 static const struct snd_kcontrol_new aif2dac_mux =
1537 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1539 static const char *aif2adc_text[] = {
1540 "AIF2ADCDAT", "AIF3DACDAT",
1543 static SOC_ENUM_SINGLE_DECL(aif2adc_enum,
1544 WM8994_POWER_MANAGEMENT_6, 2, aif2adc_text);
1546 static const struct snd_kcontrol_new aif2adc_mux =
1547 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1549 static const char *aif3adc_text[] = {
1550 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
1553 static SOC_ENUM_SINGLE_DECL(wm8994_aif3adc_enum,
1554 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1556 static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1557 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1559 static SOC_ENUM_SINGLE_DECL(wm8958_aif3adc_enum,
1560 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1562 static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1563 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1565 static const char *mono_pcm_out_text[] = {
1566 "None", "AIF2ADCL", "AIF2ADCR",
1569 static SOC_ENUM_SINGLE_DECL(mono_pcm_out_enum,
1570 WM8994_POWER_MANAGEMENT_6, 9, mono_pcm_out_text);
1572 static const struct snd_kcontrol_new mono_pcm_out_mux =
1573 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1575 static const char *aif2dac_src_text[] = {
1579 /* Note that these two control shouldn't be simultaneously switched to AIF3 */
1580 static SOC_ENUM_SINGLE_DECL(aif2dacl_src_enum,
1581 WM8994_POWER_MANAGEMENT_6, 7, aif2dac_src_text);
1583 static const struct snd_kcontrol_new aif2dacl_src_mux =
1584 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1586 static SOC_ENUM_SINGLE_DECL(aif2dacr_src_enum,
1587 WM8994_POWER_MANAGEMENT_6, 8, aif2dac_src_text);
1589 static const struct snd_kcontrol_new aif2dacr_src_mux =
1590 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
1592 static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1593 SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
1594 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1595 SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
1596 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1598 SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1599 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1600 SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1601 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1602 SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1603 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1604 SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1605 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1606 SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1607 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1609 SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1610 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1611 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1612 SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1613 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1614 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1615 SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
1616 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1617 SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
1618 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1620 SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1623 static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1624 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
1625 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1626 SND_SOC_DAPM_PRE_PMD),
1627 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
1628 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1629 SND_SOC_DAPM_PRE_PMD),
1630 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1631 SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1632 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1633 SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1634 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1635 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1636 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
1639 static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1640 SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1641 dac_ev, SND_SOC_DAPM_PRE_PMU),
1642 SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1643 dac_ev, SND_SOC_DAPM_PRE_PMU),
1644 SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1645 dac_ev, SND_SOC_DAPM_PRE_PMU),
1646 SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1647 dac_ev, SND_SOC_DAPM_PRE_PMU),
1650 static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1651 SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
1652 SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
1653 SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1654 SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1657 static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
1658 SND_SOC_DAPM_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1659 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1660 SND_SOC_DAPM_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1661 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1664 static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
1665 SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1666 SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1669 static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1670 SND_SOC_DAPM_INPUT("DMIC1DAT"),
1671 SND_SOC_DAPM_INPUT("DMIC2DAT"),
1672 SND_SOC_DAPM_INPUT("Clock"),
1674 SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1675 SND_SOC_DAPM_PRE_PMU),
1676 SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1677 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1679 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1680 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1681 SND_SOC_DAPM_PRE_PMD),
1683 SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
1684 SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
1685 SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
1687 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
1688 0, SND_SOC_NOPM, 9, 0),
1689 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
1690 0, SND_SOC_NOPM, 8, 0),
1691 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1692 SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
1693 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1694 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1695 SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
1696 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1698 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
1699 0, SND_SOC_NOPM, 11, 0),
1700 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
1701 0, SND_SOC_NOPM, 10, 0),
1702 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1703 SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
1704 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1705 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1706 SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
1707 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1709 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1710 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1711 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1712 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1714 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1715 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1716 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1717 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1719 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1720 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1721 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1722 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1724 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1725 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1727 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1728 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1729 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1730 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1732 SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1733 SND_SOC_NOPM, 13, 0),
1734 SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1735 SND_SOC_NOPM, 12, 0),
1736 SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1737 SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
1738 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1739 SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1740 SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
1741 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1743 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1744 SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1745 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1746 SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1748 SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1749 SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1750 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
1752 SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1753 SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
1755 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1757 SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1758 SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1759 SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1760 SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1762 /* Power is done with the muxes since the ADC power also controls the
1763 * downsampling chain, the chip will automatically manage the analogue
1764 * specific portions.
1766 SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1767 SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1769 SND_SOC_DAPM_MUX("AIF1 Loopback", SND_SOC_NOPM, 0, 0, &aif1_loopback),
1770 SND_SOC_DAPM_MUX("AIF2 Loopback", SND_SOC_NOPM, 0, 0, &aif2_loopback),
1772 SND_SOC_DAPM_POST("Debug log", post_ev),
1775 static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1776 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1779 static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1780 SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
1781 SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1782 SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1783 SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1784 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1787 static const struct snd_soc_dapm_route intercon[] = {
1788 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1789 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1791 { "DSP1CLK", NULL, "CLK_SYS" },
1792 { "DSP2CLK", NULL, "CLK_SYS" },
1793 { "DSPINTCLK", NULL, "CLK_SYS" },
1795 { "AIF1ADC1L", NULL, "AIF1CLK" },
1796 { "AIF1ADC1L", NULL, "DSP1CLK" },
1797 { "AIF1ADC1R", NULL, "AIF1CLK" },
1798 { "AIF1ADC1R", NULL, "DSP1CLK" },
1799 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1801 { "AIF1DAC1L", NULL, "AIF1CLK" },
1802 { "AIF1DAC1L", NULL, "DSP1CLK" },
1803 { "AIF1DAC1R", NULL, "AIF1CLK" },
1804 { "AIF1DAC1R", NULL, "DSP1CLK" },
1805 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1807 { "AIF1ADC2L", NULL, "AIF1CLK" },
1808 { "AIF1ADC2L", NULL, "DSP1CLK" },
1809 { "AIF1ADC2R", NULL, "AIF1CLK" },
1810 { "AIF1ADC2R", NULL, "DSP1CLK" },
1811 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1813 { "AIF1DAC2L", NULL, "AIF1CLK" },
1814 { "AIF1DAC2L", NULL, "DSP1CLK" },
1815 { "AIF1DAC2R", NULL, "AIF1CLK" },
1816 { "AIF1DAC2R", NULL, "DSP1CLK" },
1817 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1819 { "AIF2ADCL", NULL, "AIF2CLK" },
1820 { "AIF2ADCL", NULL, "DSP2CLK" },
1821 { "AIF2ADCR", NULL, "AIF2CLK" },
1822 { "AIF2ADCR", NULL, "DSP2CLK" },
1823 { "AIF2ADCR", NULL, "DSPINTCLK" },
1825 { "AIF2DACL", NULL, "AIF2CLK" },
1826 { "AIF2DACL", NULL, "DSP2CLK" },
1827 { "AIF2DACR", NULL, "AIF2CLK" },
1828 { "AIF2DACR", NULL, "DSP2CLK" },
1829 { "AIF2DACR", NULL, "DSPINTCLK" },
1831 { "DMIC1L", NULL, "DMIC1DAT" },
1832 { "DMIC1L", NULL, "CLK_SYS" },
1833 { "DMIC1R", NULL, "DMIC1DAT" },
1834 { "DMIC1R", NULL, "CLK_SYS" },
1835 { "DMIC2L", NULL, "DMIC2DAT" },
1836 { "DMIC2L", NULL, "CLK_SYS" },
1837 { "DMIC2R", NULL, "DMIC2DAT" },
1838 { "DMIC2R", NULL, "CLK_SYS" },
1840 { "ADCL", NULL, "AIF1CLK" },
1841 { "ADCL", NULL, "DSP1CLK" },
1842 { "ADCL", NULL, "DSPINTCLK" },
1844 { "ADCR", NULL, "AIF1CLK" },
1845 { "ADCR", NULL, "DSP1CLK" },
1846 { "ADCR", NULL, "DSPINTCLK" },
1848 { "ADCL Mux", "ADC", "ADCL" },
1849 { "ADCL Mux", "DMIC", "DMIC1L" },
1850 { "ADCR Mux", "ADC", "ADCR" },
1851 { "ADCR Mux", "DMIC", "DMIC1R" },
1853 { "DAC1L", NULL, "AIF1CLK" },
1854 { "DAC1L", NULL, "DSP1CLK" },
1855 { "DAC1L", NULL, "DSPINTCLK" },
1857 { "DAC1R", NULL, "AIF1CLK" },
1858 { "DAC1R", NULL, "DSP1CLK" },
1859 { "DAC1R", NULL, "DSPINTCLK" },
1861 { "DAC2L", NULL, "AIF2CLK" },
1862 { "DAC2L", NULL, "DSP2CLK" },
1863 { "DAC2L", NULL, "DSPINTCLK" },
1865 { "DAC2R", NULL, "AIF2DACR" },
1866 { "DAC2R", NULL, "AIF2CLK" },
1867 { "DAC2R", NULL, "DSP2CLK" },
1868 { "DAC2R", NULL, "DSPINTCLK" },
1870 { "TOCLK", NULL, "CLK_SYS" },
1872 { "AIF1DACDAT", NULL, "AIF1 Playback" },
1873 { "AIF2DACDAT", NULL, "AIF2 Playback" },
1874 { "AIF3DACDAT", NULL, "AIF3 Playback" },
1876 { "AIF1 Capture", NULL, "AIF1ADCDAT" },
1877 { "AIF2 Capture", NULL, "AIF2ADCDAT" },
1878 { "AIF3 Capture", NULL, "AIF3ADCDAT" },
1881 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1882 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1883 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1885 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1886 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1887 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1889 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1890 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1891 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1893 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1894 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1895 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1897 /* Pin level routing for AIF3 */
1898 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1899 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1900 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1901 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1903 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1 Loopback" },
1904 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1905 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2 Loopback" },
1906 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1907 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1908 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1909 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1912 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1913 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1914 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1915 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1916 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1918 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1919 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1920 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1921 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1922 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1924 /* DAC2/AIF2 outputs */
1925 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
1926 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1927 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1928 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1929 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1930 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1932 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
1933 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1934 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1935 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1936 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1937 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1939 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1940 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1941 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1942 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1944 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1947 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1L" },
1948 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1R" },
1949 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2L" },
1950 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2R" },
1951 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1952 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1953 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACL" },
1954 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACR" },
1956 { "AIF3ADCDAT", NULL, "AIF3ADC Mux" },
1959 { "AIF1 Loopback", "ADCDAT", "AIF1ADCDAT" },
1960 { "AIF1 Loopback", "None", "AIF1DACDAT" },
1961 { "AIF2 Loopback", "ADCDAT", "AIF2ADCDAT" },
1962 { "AIF2 Loopback", "None", "AIF2DACDAT" },
1965 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1966 { "Left Sidetone", "DMIC2", "DMIC2L" },
1967 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1968 { "Right Sidetone", "DMIC2", "DMIC2R" },
1971 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1972 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1974 { "SPKL", "DAC1 Switch", "DAC1L" },
1975 { "SPKL", "DAC2 Switch", "DAC2L" },
1977 { "SPKR", "DAC1 Switch", "DAC1R" },
1978 { "SPKR", "DAC2 Switch", "DAC2R" },
1980 { "Left Headphone Mux", "DAC", "DAC1L" },
1981 { "Right Headphone Mux", "DAC", "DAC1R" },
1984 static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1985 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1986 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1987 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1988 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1989 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1990 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1991 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1992 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1995 static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1996 { "DAC1L", NULL, "DAC1L Mixer" },
1997 { "DAC1R", NULL, "DAC1R Mixer" },
1998 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1999 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
2002 static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
2003 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
2004 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
2005 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
2006 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
2007 { "MICBIAS1", NULL, "CLK_SYS" },
2008 { "MICBIAS1", NULL, "MICBIAS Supply" },
2009 { "MICBIAS2", NULL, "CLK_SYS" },
2010 { "MICBIAS2", NULL, "MICBIAS Supply" },
2013 static const struct snd_soc_dapm_route wm8994_intercon[] = {
2014 { "AIF2DACL", NULL, "AIF2DAC Mux" },
2015 { "AIF2DACR", NULL, "AIF2DAC Mux" },
2016 { "MICBIAS1", NULL, "VMID" },
2017 { "MICBIAS2", NULL, "VMID" },
2020 static const struct snd_soc_dapm_route wm8958_intercon[] = {
2021 { "AIF2DACL", NULL, "AIF2DACL Mux" },
2022 { "AIF2DACR", NULL, "AIF2DACR Mux" },
2024 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
2025 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
2026 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
2027 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
2029 { "AIF3DACDAT", NULL, "AIF3" },
2030 { "AIF3ADCDAT", NULL, "AIF3" },
2032 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
2033 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
2035 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
2038 /* The size in bits of the FLL divide multiplied by 10
2039 * to allow rounding later */
2040 #define FIXED_FLL_SIZE ((1 << 16) * 10)
2051 static int wm8994_get_fll_config(struct wm8994 *control, struct fll_div *fll,
2052 int freq_in, int freq_out)
2055 unsigned int K, Ndiv, Nmod, gcd_fll;
2057 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
2059 /* Scale the input frequency down to <= 13.5MHz */
2060 fll->clk_ref_div = 0;
2061 while (freq_in > 13500000) {
2065 if (fll->clk_ref_div > 3)
2068 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
2070 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2072 while (freq_out * (fll->outdiv + 1) < 90000000) {
2074 if (fll->outdiv > 63)
2077 freq_out *= fll->outdiv + 1;
2078 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
2080 if (freq_in > 1000000) {
2081 fll->fll_fratio = 0;
2082 } else if (freq_in > 256000) {
2083 fll->fll_fratio = 1;
2085 } else if (freq_in > 128000) {
2086 fll->fll_fratio = 2;
2088 } else if (freq_in > 64000) {
2089 fll->fll_fratio = 3;
2092 fll->fll_fratio = 4;
2095 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
2097 /* Now, calculate N.K */
2098 Ndiv = freq_out / freq_in;
2101 Nmod = freq_out % freq_in;
2102 pr_debug("Nmod=%d\n", Nmod);
2104 switch (control->type) {
2106 /* Calculate fractional part - scale up so we can round. */
2107 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
2109 do_div(Kpart, freq_in);
2111 K = Kpart & 0xFFFFFFFF;
2116 /* Move down to proper range now rounding is done */
2120 pr_debug("N=%x K=%x\n", fll->n, fll->k);
2124 gcd_fll = gcd(freq_out, freq_in);
2126 fll->k = (freq_out - (freq_in * fll->n)) / gcd_fll;
2127 fll->lambda = freq_in / gcd_fll;
2134 static int _wm8994_set_fll(struct snd_soc_component *component, int id, int src,
2135 unsigned int freq_in, unsigned int freq_out)
2137 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2138 struct wm8994 *control = wm8994->wm8994;
2139 int reg_offset, ret;
2141 u16 reg, clk1, aif_reg, aif_src;
2142 unsigned long timeout;
2160 reg = snd_soc_component_read32(component, WM8994_FLL1_CONTROL_1 + reg_offset);
2161 was_enabled = reg & WM8994_FLL1_ENA;
2165 /* Allow no source specification when stopping */
2168 src = wm8994->fll[id].src;
2170 case WM8994_FLL_SRC_MCLK1:
2171 case WM8994_FLL_SRC_MCLK2:
2172 case WM8994_FLL_SRC_LRCLK:
2173 case WM8994_FLL_SRC_BCLK:
2175 case WM8994_FLL_SRC_INTERNAL:
2177 freq_out = 12000000;
2183 /* Are we changing anything? */
2184 if (wm8994->fll[id].src == src &&
2185 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
2188 /* If we're stopping the FLL redo the old config - no
2189 * registers will actually be written but we avoid GCC flow
2190 * analysis bugs spewing warnings.
2193 ret = wm8994_get_fll_config(control, &fll, freq_in, freq_out);
2195 ret = wm8994_get_fll_config(control, &fll, wm8994->fll[id].in,
2196 wm8994->fll[id].out);
2200 /* Make sure that we're not providing SYSCLK right now */
2201 clk1 = snd_soc_component_read32(component, WM8994_CLOCKING_1);
2202 if (clk1 & WM8994_SYSCLK_SRC)
2203 aif_reg = WM8994_AIF2_CLOCKING_1;
2205 aif_reg = WM8994_AIF1_CLOCKING_1;
2206 reg = snd_soc_component_read32(component, aif_reg);
2208 if ((reg & WM8994_AIF1CLK_ENA) &&
2209 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2210 dev_err(component->dev, "FLL%d is currently providing SYSCLK\n",
2215 /* We always need to disable the FLL while reconfiguring */
2216 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_1 + reg_offset,
2217 WM8994_FLL1_ENA, 0);
2219 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
2220 freq_in == freq_out && freq_out) {
2221 dev_dbg(component->dev, "Bypassing FLL%d\n", id + 1);
2222 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_5 + reg_offset,
2223 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2227 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2228 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2229 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_2 + reg_offset,
2230 WM8994_FLL1_OUTDIV_MASK |
2231 WM8994_FLL1_FRATIO_MASK, reg);
2233 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_3 + reg_offset,
2234 WM8994_FLL1_K_MASK, fll.k);
2236 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_4 + reg_offset,
2238 fll.n << WM8994_FLL1_N_SHIFT);
2241 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_1 + reg_offset,
2242 WM8958_FLL1_LAMBDA_MASK,
2244 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_2 + reg_offset,
2245 WM8958_FLL1_EFS_ENA, WM8958_FLL1_EFS_ENA);
2247 snd_soc_component_update_bits(component, WM8958_FLL1_EFS_2 + reg_offset,
2248 WM8958_FLL1_EFS_ENA, 0);
2251 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_5 + reg_offset,
2252 WM8994_FLL1_FRC_NCO | WM8958_FLL1_BYP |
2253 WM8994_FLL1_REFCLK_DIV_MASK |
2254 WM8994_FLL1_REFCLK_SRC_MASK,
2255 ((src == WM8994_FLL_SRC_INTERNAL)
2256 << WM8994_FLL1_FRC_NCO_SHIFT) |
2257 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
2260 /* Clear any pending completion from a previous failure */
2261 try_wait_for_completion(&wm8994->fll_locked[id]);
2263 /* Enable (with fractional mode if required) */
2265 /* Enable VMID if we need it */
2267 active_reference(component);
2269 switch (control->type) {
2271 vmid_reference(component);
2274 if (control->revision < 1)
2275 vmid_reference(component);
2282 reg = WM8994_FLL1_ENA;
2285 reg |= WM8994_FLL1_FRAC;
2286 if (src == WM8994_FLL_SRC_INTERNAL)
2287 reg |= WM8994_FLL1_OSC_ENA;
2289 snd_soc_component_update_bits(component, WM8994_FLL1_CONTROL_1 + reg_offset,
2290 WM8994_FLL1_ENA | WM8994_FLL1_OSC_ENA |
2291 WM8994_FLL1_FRAC, reg);
2293 if (wm8994->fll_locked_irq) {
2294 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
2295 msecs_to_jiffies(10));
2297 dev_warn(component->dev,
2298 "Timed out waiting for FLL lock\n");
2304 switch (control->type) {
2306 vmid_dereference(component);
2309 if (control->revision < 1)
2310 vmid_dereference(component);
2316 active_dereference(component);
2321 wm8994->fll[id].in = freq_in;
2322 wm8994->fll[id].out = freq_out;
2323 wm8994->fll[id].src = src;
2325 configure_clock(component);
2328 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2331 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2332 dev_dbg(component->dev, "Configuring AIFs for 128fs\n");
2334 wm8994->aifdiv[0] = snd_soc_component_read32(component, WM8994_AIF1_RATE)
2335 & WM8994_AIF1CLK_RATE_MASK;
2336 wm8994->aifdiv[1] = snd_soc_component_read32(component, WM8994_AIF2_RATE)
2337 & WM8994_AIF1CLK_RATE_MASK;
2339 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2340 WM8994_AIF1CLK_RATE_MASK, 0x1);
2341 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2342 WM8994_AIF2CLK_RATE_MASK, 0x1);
2343 } else if (wm8994->aifdiv[0]) {
2344 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2345 WM8994_AIF1CLK_RATE_MASK,
2347 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2348 WM8994_AIF2CLK_RATE_MASK,
2351 wm8994->aifdiv[0] = 0;
2352 wm8994->aifdiv[1] = 0;
2358 static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
2360 struct completion *completion = data;
2362 complete(completion);
2367 static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2369 static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
2370 unsigned int freq_in, unsigned int freq_out)
2372 return _wm8994_set_fll(dai->component, id, src, freq_in, freq_out);
2375 static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2376 int clk_id, unsigned int freq, int dir)
2378 struct snd_soc_component *component = dai->component;
2379 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2388 /* AIF3 shares clocking with AIF1/2 */
2393 case WM8994_SYSCLK_MCLK1:
2394 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
2395 wm8994->mclk[0] = freq;
2396 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
2400 case WM8994_SYSCLK_MCLK2:
2401 /* TODO: Set GPIO AF */
2402 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
2403 wm8994->mclk[1] = freq;
2404 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
2408 case WM8994_SYSCLK_FLL1:
2409 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
2410 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
2413 case WM8994_SYSCLK_FLL2:
2414 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
2415 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
2418 case WM8994_SYSCLK_OPCLK:
2419 /* Special case - a division (times 10) is given and
2420 * no effect on main clocking.
2423 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2424 if (opclk_divs[i] == freq)
2426 if (i == ARRAY_SIZE(opclk_divs))
2428 snd_soc_component_update_bits(component, WM8994_CLOCKING_2,
2429 WM8994_OPCLK_DIV_MASK, i);
2430 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_2,
2431 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2433 snd_soc_component_update_bits(component, WM8994_POWER_MANAGEMENT_2,
2434 WM8994_OPCLK_ENA, 0);
2442 configure_clock(component);
2445 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2448 if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
2449 dev_dbg(component->dev, "Configuring AIFs for 128fs\n");
2451 wm8994->aifdiv[0] = snd_soc_component_read32(component, WM8994_AIF1_RATE)
2452 & WM8994_AIF1CLK_RATE_MASK;
2453 wm8994->aifdiv[1] = snd_soc_component_read32(component, WM8994_AIF2_RATE)
2454 & WM8994_AIF1CLK_RATE_MASK;
2456 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2457 WM8994_AIF1CLK_RATE_MASK, 0x1);
2458 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2459 WM8994_AIF2CLK_RATE_MASK, 0x1);
2460 } else if (wm8994->aifdiv[0]) {
2461 snd_soc_component_update_bits(component, WM8994_AIF1_RATE,
2462 WM8994_AIF1CLK_RATE_MASK,
2464 snd_soc_component_update_bits(component, WM8994_AIF2_RATE,
2465 WM8994_AIF2CLK_RATE_MASK,
2468 wm8994->aifdiv[0] = 0;
2469 wm8994->aifdiv[1] = 0;
2475 static int wm8994_set_bias_level(struct snd_soc_component *component,
2476 enum snd_soc_bias_level level)
2478 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2479 struct wm8994 *control = wm8994->wm8994;
2481 wm_hubs_set_bias_level(component, level);
2484 case SND_SOC_BIAS_ON:
2487 case SND_SOC_BIAS_PREPARE:
2488 /* MICBIAS into regulating mode */
2489 switch (control->type) {
2492 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
2493 WM8958_MICB1_MODE, 0);
2494 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
2495 WM8958_MICB2_MODE, 0);
2501 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY)
2502 active_reference(component);
2505 case SND_SOC_BIAS_STANDBY:
2506 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
2507 switch (control->type) {
2509 if (control->revision == 0) {
2510 /* Optimise performance for rev A */
2511 snd_soc_component_update_bits(component,
2512 WM8958_CHARGE_PUMP_2,
2522 /* Discharge LINEOUT1 & 2 */
2523 snd_soc_component_update_bits(component, WM8994_ANTIPOP_1,
2524 WM8994_LINEOUT1_DISCH |
2525 WM8994_LINEOUT2_DISCH,
2526 WM8994_LINEOUT1_DISCH |
2527 WM8994_LINEOUT2_DISCH);
2530 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE)
2531 active_dereference(component);
2533 /* MICBIAS into bypass mode on newer devices */
2534 switch (control->type) {
2537 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
2540 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
2549 case SND_SOC_BIAS_OFF:
2550 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY)
2551 wm8994->cur_fw = NULL;
2558 int wm8994_vmid_mode(struct snd_soc_component *component, enum wm8994_vmid_mode mode)
2560 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2561 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
2564 case WM8994_VMID_NORMAL:
2565 snd_soc_dapm_mutex_lock(dapm);
2567 if (wm8994->hubs.lineout1_se) {
2568 snd_soc_dapm_disable_pin_unlocked(dapm,
2569 "LINEOUT1N Driver");
2570 snd_soc_dapm_disable_pin_unlocked(dapm,
2571 "LINEOUT1P Driver");
2573 if (wm8994->hubs.lineout2_se) {
2574 snd_soc_dapm_disable_pin_unlocked(dapm,
2575 "LINEOUT2N Driver");
2576 snd_soc_dapm_disable_pin_unlocked(dapm,
2577 "LINEOUT2P Driver");
2580 /* Do the sync with the old mode to allow it to clean up */
2581 snd_soc_dapm_sync_unlocked(dapm);
2582 wm8994->vmid_mode = mode;
2584 snd_soc_dapm_mutex_unlock(dapm);
2587 case WM8994_VMID_FORCE:
2588 snd_soc_dapm_mutex_lock(dapm);
2590 if (wm8994->hubs.lineout1_se) {
2591 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2592 "LINEOUT1N Driver");
2593 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2594 "LINEOUT1P Driver");
2596 if (wm8994->hubs.lineout2_se) {
2597 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2598 "LINEOUT2N Driver");
2599 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2600 "LINEOUT2P Driver");
2603 wm8994->vmid_mode = mode;
2604 snd_soc_dapm_sync_unlocked(dapm);
2606 snd_soc_dapm_mutex_unlock(dapm);
2616 static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2618 struct snd_soc_component *component = dai->component;
2619 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2620 struct wm8994 *control = wm8994->wm8994;
2631 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2632 aif1_reg = WM8994_AIF1_CONTROL_1;
2633 dac_reg = WM8994_AIF1DAC_LRCLK;
2634 adc_reg = WM8994_AIF1ADC_LRCLK;
2637 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2638 aif1_reg = WM8994_AIF2_CONTROL_1;
2639 dac_reg = WM8994_AIF1DAC_LRCLK;
2640 adc_reg = WM8994_AIF1ADC_LRCLK;
2646 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2647 case SND_SOC_DAIFMT_CBS_CFS:
2649 case SND_SOC_DAIFMT_CBM_CFM:
2650 ms = WM8994_AIF1_MSTR;
2656 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2657 case SND_SOC_DAIFMT_DSP_B:
2658 aif1 |= WM8994_AIF1_LRCLK_INV;
2659 lrclk |= WM8958_AIF1_LRCLK_INV;
2661 case SND_SOC_DAIFMT_DSP_A:
2664 case SND_SOC_DAIFMT_I2S:
2667 case SND_SOC_DAIFMT_RIGHT_J:
2669 case SND_SOC_DAIFMT_LEFT_J:
2676 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2677 case SND_SOC_DAIFMT_DSP_A:
2678 case SND_SOC_DAIFMT_DSP_B:
2679 /* frame inversion not valid for DSP modes */
2680 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2681 case SND_SOC_DAIFMT_NB_NF:
2683 case SND_SOC_DAIFMT_IB_NF:
2684 aif1 |= WM8994_AIF1_BCLK_INV;
2691 case SND_SOC_DAIFMT_I2S:
2692 case SND_SOC_DAIFMT_RIGHT_J:
2693 case SND_SOC_DAIFMT_LEFT_J:
2694 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2695 case SND_SOC_DAIFMT_NB_NF:
2697 case SND_SOC_DAIFMT_IB_IF:
2698 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2699 lrclk |= WM8958_AIF1_LRCLK_INV;
2701 case SND_SOC_DAIFMT_IB_NF:
2702 aif1 |= WM8994_AIF1_BCLK_INV;
2704 case SND_SOC_DAIFMT_NB_IF:
2705 aif1 |= WM8994_AIF1_LRCLK_INV;
2706 lrclk |= WM8958_AIF1_LRCLK_INV;
2716 /* The AIF2 format configuration needs to be mirrored to AIF3
2717 * on WM8958 if it's in use so just do it all the time. */
2718 switch (control->type) {
2722 snd_soc_component_update_bits(component, WM8958_AIF3_CONTROL_1,
2723 WM8994_AIF1_LRCLK_INV |
2724 WM8958_AIF3_FMT_MASK, aif1);
2731 snd_soc_component_update_bits(component, aif1_reg,
2732 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2733 WM8994_AIF1_FMT_MASK,
2735 snd_soc_component_update_bits(component, ms_reg, WM8994_AIF1_MSTR,
2737 snd_soc_component_update_bits(component, dac_reg,
2738 WM8958_AIF1_LRCLK_INV, lrclk);
2739 snd_soc_component_update_bits(component, adc_reg,
2740 WM8958_AIF1_LRCLK_INV, lrclk);
2761 static int fs_ratios[] = {
2762 64, 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
2765 static int bclk_divs[] = {
2766 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2767 640, 880, 960, 1280, 1760, 1920
2770 static int wm8994_hw_params(struct snd_pcm_substream *substream,
2771 struct snd_pcm_hw_params *params,
2772 struct snd_soc_dai *dai)
2774 struct snd_soc_component *component = dai->component;
2775 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2776 struct wm8994 *control = wm8994->wm8994;
2777 struct wm8994_pdata *pdata = &control->pdata;
2788 int id = dai->id - 1;
2790 int i, cur_val, best_val, bclk_rate, best;
2794 aif1_reg = WM8994_AIF1_CONTROL_1;
2795 aif2_reg = WM8994_AIF1_CONTROL_2;
2796 bclk_reg = WM8994_AIF1_BCLK;
2797 rate_reg = WM8994_AIF1_RATE;
2798 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2799 wm8994->lrclk_shared[0]) {
2800 lrclk_reg = WM8994_AIF1DAC_LRCLK;
2802 lrclk_reg = WM8994_AIF1ADC_LRCLK;
2803 dev_dbg(component->dev, "AIF1 using split LRCLK\n");
2807 aif1_reg = WM8994_AIF2_CONTROL_1;
2808 aif2_reg = WM8994_AIF2_CONTROL_2;
2809 bclk_reg = WM8994_AIF2_BCLK;
2810 rate_reg = WM8994_AIF2_RATE;
2811 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
2812 wm8994->lrclk_shared[1]) {
2813 lrclk_reg = WM8994_AIF2DAC_LRCLK;
2815 lrclk_reg = WM8994_AIF2ADC_LRCLK;
2816 dev_dbg(component->dev, "AIF2 using split LRCLK\n");
2823 bclk_rate = params_rate(params);
2824 switch (params_width(params)) {
2844 wm8994->channels[id] = params_channels(params);
2845 if (pdata->max_channels_clocked[id] &&
2846 wm8994->channels[id] > pdata->max_channels_clocked[id]) {
2847 dev_dbg(dai->dev, "Constraining channels to %d from %d\n",
2848 pdata->max_channels_clocked[id], wm8994->channels[id]);
2849 wm8994->channels[id] = pdata->max_channels_clocked[id];
2852 switch (wm8994->channels[id]) {
2862 /* Try to find an appropriate sample rate; look for an exact match. */
2863 for (i = 0; i < ARRAY_SIZE(srs); i++)
2864 if (srs[i].rate == params_rate(params))
2866 if (i == ARRAY_SIZE(srs))
2868 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2870 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2871 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2872 dai->id, wm8994->aifclk[id], bclk_rate);
2874 if (wm8994->channels[id] == 1 &&
2875 (snd_soc_component_read32(component, aif1_reg) & 0x18) == 0x18)
2876 aif2 |= WM8994_AIF1_MONO;
2878 if (wm8994->aifclk[id] == 0) {
2879 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2883 /* AIFCLK/fs ratio; look for a close match in either direction */
2885 best_val = abs((fs_ratios[0] * params_rate(params))
2886 - wm8994->aifclk[id]);
2887 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2888 cur_val = abs((fs_ratios[i] * params_rate(params))
2889 - wm8994->aifclk[id]);
2890 if (cur_val >= best_val)
2895 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2896 dai->id, fs_ratios[best]);
2899 /* We may not get quite the right frequency if using
2900 * approximate clocks so look for the closest match that is
2901 * higher than the target (we need to ensure that there enough
2902 * BCLKs to clock out the samples).
2905 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
2906 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
2907 if (cur_val < 0) /* BCLK table is sorted */
2911 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
2912 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2913 bclk_divs[best], bclk_rate);
2914 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2916 lrclk = bclk_rate / params_rate(params);
2918 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2922 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2923 lrclk, bclk_rate / lrclk);
2925 snd_soc_component_update_bits(component, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2926 snd_soc_component_update_bits(component, aif2_reg, WM8994_AIF1_MONO, aif2);
2927 snd_soc_component_update_bits(component, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2928 snd_soc_component_update_bits(component, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2930 snd_soc_component_update_bits(component, rate_reg, WM8994_AIF1_SR_MASK |
2931 WM8994_AIF1CLK_RATE_MASK, rate_val);
2933 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2936 wm8994->dac_rates[0] = params_rate(params);
2937 wm8994_set_retune_mobile(component, 0);
2938 wm8994_set_retune_mobile(component, 1);
2941 wm8994->dac_rates[1] = params_rate(params);
2942 wm8994_set_retune_mobile(component, 2);
2950 static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2951 struct snd_pcm_hw_params *params,
2952 struct snd_soc_dai *dai)
2954 struct snd_soc_component *component = dai->component;
2955 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
2956 struct wm8994 *control = wm8994->wm8994;
2962 switch (control->type) {
2965 aif1_reg = WM8958_AIF3_CONTROL_1;
2975 switch (params_width(params)) {
2991 return snd_soc_component_update_bits(component, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2994 static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2996 struct snd_soc_component *component = codec_dai->component;
3000 switch (codec_dai->id) {
3002 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
3005 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
3012 reg = WM8994_AIF1DAC1_MUTE;
3016 snd_soc_component_update_bits(component, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
3021 static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
3023 struct snd_soc_component *component = codec_dai->component;
3026 switch (codec_dai->id) {
3028 reg = WM8994_AIF1_MASTER_SLAVE;
3029 mask = WM8994_AIF1_TRI;
3032 reg = WM8994_AIF2_MASTER_SLAVE;
3033 mask = WM8994_AIF2_TRI;
3044 return snd_soc_component_update_bits(component, reg, mask, val);
3047 static int wm8994_aif2_probe(struct snd_soc_dai *dai)
3049 struct snd_soc_component *component = dai->component;
3051 /* Disable the pulls on the AIF if we're using it to save power. */
3052 snd_soc_component_update_bits(component, WM8994_GPIO_3,
3053 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3054 snd_soc_component_update_bits(component, WM8994_GPIO_4,
3055 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3056 snd_soc_component_update_bits(component, WM8994_GPIO_5,
3057 WM8994_GPN_PU | WM8994_GPN_PD, 0);
3062 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
3064 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
3065 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
3067 static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
3068 .set_sysclk = wm8994_set_dai_sysclk,
3069 .set_fmt = wm8994_set_dai_fmt,
3070 .hw_params = wm8994_hw_params,
3071 .digital_mute = wm8994_aif_mute,
3072 .set_pll = wm8994_set_fll,
3073 .set_tristate = wm8994_set_tristate,
3076 static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
3077 .set_sysclk = wm8994_set_dai_sysclk,
3078 .set_fmt = wm8994_set_dai_fmt,
3079 .hw_params = wm8994_hw_params,
3080 .digital_mute = wm8994_aif_mute,
3081 .set_pll = wm8994_set_fll,
3082 .set_tristate = wm8994_set_tristate,
3085 static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
3086 .hw_params = wm8994_aif3_hw_params,
3089 static struct snd_soc_dai_driver wm8994_dai[] = {
3091 .name = "wm8994-aif1",
3094 .stream_name = "AIF1 Playback",
3097 .rates = WM8994_RATES,
3098 .formats = WM8994_FORMATS,
3102 .stream_name = "AIF1 Capture",
3105 .rates = WM8994_RATES,
3106 .formats = WM8994_FORMATS,
3109 .ops = &wm8994_aif1_dai_ops,
3112 .name = "wm8994-aif2",
3115 .stream_name = "AIF2 Playback",
3118 .rates = WM8994_RATES,
3119 .formats = WM8994_FORMATS,
3123 .stream_name = "AIF2 Capture",
3126 .rates = WM8994_RATES,
3127 .formats = WM8994_FORMATS,
3130 .probe = wm8994_aif2_probe,
3131 .ops = &wm8994_aif2_dai_ops,
3134 .name = "wm8994-aif3",
3137 .stream_name = "AIF3 Playback",
3140 .rates = WM8994_RATES,
3141 .formats = WM8994_FORMATS,
3145 .stream_name = "AIF3 Capture",
3148 .rates = WM8994_RATES,
3149 .formats = WM8994_FORMATS,
3152 .ops = &wm8994_aif3_dai_ops,
3157 static int wm8994_component_suspend(struct snd_soc_component *component)
3159 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3162 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3163 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
3164 sizeof(struct wm8994_fll_config));
3165 ret = _wm8994_set_fll(component, i + 1, 0, 0, 0);
3167 dev_warn(component->dev, "Failed to stop FLL%d: %d\n",
3171 snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
3176 static int wm8994_component_resume(struct snd_soc_component *component)
3178 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3181 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
3182 if (!wm8994->fll_suspend[i].out)
3185 ret = _wm8994_set_fll(component, i + 1,
3186 wm8994->fll_suspend[i].src,
3187 wm8994->fll_suspend[i].in,
3188 wm8994->fll_suspend[i].out);
3190 dev_warn(component->dev, "Failed to restore FLL%d: %d\n",
3197 #define wm8994_component_suspend NULL
3198 #define wm8994_component_resume NULL
3201 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3203 struct snd_soc_component *component = wm8994->hubs.component;
3204 struct wm8994 *control = wm8994->wm8994;
3205 struct wm8994_pdata *pdata = &control->pdata;
3206 struct snd_kcontrol_new controls[] = {
3207 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3208 wm8994->retune_mobile_enum,
3209 wm8994_get_retune_mobile_enum,
3210 wm8994_put_retune_mobile_enum),
3211 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3212 wm8994->retune_mobile_enum,
3213 wm8994_get_retune_mobile_enum,
3214 wm8994_put_retune_mobile_enum),
3215 SOC_ENUM_EXT("AIF2 EQ Mode",
3216 wm8994->retune_mobile_enum,
3217 wm8994_get_retune_mobile_enum,
3218 wm8994_put_retune_mobile_enum),
3223 /* We need an array of texts for the enum API but the number
3224 * of texts is likely to be less than the number of
3225 * configurations due to the sample rate dependency of the
3226 * configurations. */
3227 wm8994->num_retune_mobile_texts = 0;
3228 wm8994->retune_mobile_texts = NULL;
3229 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
3230 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
3231 if (strcmp(pdata->retune_mobile_cfgs[i].name,
3232 wm8994->retune_mobile_texts[j]) == 0)
3236 if (j != wm8994->num_retune_mobile_texts)
3239 /* Expand the array... */
3240 t = krealloc(wm8994->retune_mobile_texts,
3242 (wm8994->num_retune_mobile_texts + 1),
3247 /* ...store the new entry... */
3248 t[wm8994->num_retune_mobile_texts] =
3249 pdata->retune_mobile_cfgs[i].name;
3251 /* ...and remember the new version. */
3252 wm8994->num_retune_mobile_texts++;
3253 wm8994->retune_mobile_texts = t;
3256 dev_dbg(component->dev, "Allocated %d unique ReTune Mobile names\n",
3257 wm8994->num_retune_mobile_texts);
3259 wm8994->retune_mobile_enum.items = wm8994->num_retune_mobile_texts;
3260 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3262 ret = snd_soc_add_component_controls(wm8994->hubs.component, controls,
3263 ARRAY_SIZE(controls));
3265 dev_err(wm8994->hubs.component->dev,
3266 "Failed to add ReTune Mobile controls: %d\n", ret);
3269 static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3271 struct snd_soc_component *component = wm8994->hubs.component;
3272 struct wm8994 *control = wm8994->wm8994;
3273 struct wm8994_pdata *pdata = &control->pdata;
3279 wm_hubs_handle_analogue_pdata(component, pdata->lineout1_diff,
3280 pdata->lineout2_diff,
3287 pdata->micbias1_lvl,
3288 pdata->micbias2_lvl);
3290 dev_dbg(component->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
3292 if (pdata->num_drc_cfgs) {
3293 struct snd_kcontrol_new controls[] = {
3294 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
3295 wm8994_get_drc_enum, wm8994_put_drc_enum),
3296 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
3297 wm8994_get_drc_enum, wm8994_put_drc_enum),
3298 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
3299 wm8994_get_drc_enum, wm8994_put_drc_enum),
3302 /* We need an array of texts for the enum API */
3303 wm8994->drc_texts = devm_kcalloc(wm8994->hubs.component->dev,
3304 pdata->num_drc_cfgs, sizeof(char *), GFP_KERNEL);
3305 if (!wm8994->drc_texts)
3308 for (i = 0; i < pdata->num_drc_cfgs; i++)
3309 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3311 wm8994->drc_enum.items = pdata->num_drc_cfgs;
3312 wm8994->drc_enum.texts = wm8994->drc_texts;
3314 ret = snd_soc_add_component_controls(wm8994->hubs.component, controls,
3315 ARRAY_SIZE(controls));
3316 for (i = 0; i < WM8994_NUM_DRC; i++)
3317 wm8994_set_drc(component, i);
3319 ret = snd_soc_add_component_controls(wm8994->hubs.component,
3320 wm8994_drc_controls,
3321 ARRAY_SIZE(wm8994_drc_controls));
3325 dev_err(wm8994->hubs.component->dev,
3326 "Failed to add DRC mode controls: %d\n", ret);
3329 dev_dbg(component->dev, "%d ReTune Mobile configurations\n",
3330 pdata->num_retune_mobile_cfgs);
3332 if (pdata->num_retune_mobile_cfgs)
3333 wm8994_handle_retune_mobile_pdata(wm8994);
3335 snd_soc_add_component_controls(wm8994->hubs.component, wm8994_eq_controls,
3336 ARRAY_SIZE(wm8994_eq_controls));
3338 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
3339 if (pdata->micbias[i]) {
3340 snd_soc_component_write(component, WM8958_MICBIAS1 + i,
3341 pdata->micbias[i] & 0xffff);
3347 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3349 * @component: WM8994 component
3350 * @jack: jack to report detection events on
3351 * @micbias: microphone bias to detect on
3353 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3354 * being used to bring out signals to the processor then only platform
3355 * data configuration is needed for WM8994 and processor GPIOs should
3356 * be configured using snd_soc_jack_add_gpios() instead.
3358 * Configuration of detection levels is available via the micbias1_lvl
3359 * and micbias2_lvl platform data members.
3361 int wm8994_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
3364 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3365 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3366 struct wm8994_micdet *micdet;
3367 struct wm8994 *control = wm8994->wm8994;
3370 if (control->type != WM8994) {
3371 dev_warn(component->dev, "Not a WM8994\n");
3375 pm_runtime_get_sync(component->dev);
3379 micdet = &wm8994->micdet[0];
3381 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3383 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3386 micdet = &wm8994->micdet[1];
3388 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3390 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3393 dev_warn(component->dev, "Invalid MICBIAS %d\n", micbias);
3398 dev_warn(component->dev, "Failed to configure MICBIAS%d: %d\n",
3401 dev_dbg(component->dev, "Configuring microphone detection on %d %p\n",
3404 /* Store the configuration */
3405 micdet->jack = jack;
3406 micdet->detecting = true;
3408 /* If either of the jacks is set up then enable detection */
3409 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
3410 reg = WM8994_MICD_ENA;
3414 snd_soc_component_update_bits(component, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
3416 /* enable MICDET and MICSHRT deboune */
3417 snd_soc_component_update_bits(component, WM8994_IRQ_DEBOUNCE,
3418 WM8994_MIC1_DET_DB_MASK | WM8994_MIC1_SHRT_DB_MASK |
3419 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK,
3420 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB);
3422 snd_soc_dapm_sync(dapm);
3424 pm_runtime_put(component->dev);
3428 EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3430 static void wm8994_mic_work(struct work_struct *work)
3432 struct wm8994_priv *priv = container_of(work,
3435 struct regmap *regmap = priv->wm8994->regmap;
3436 struct device *dev = priv->wm8994->dev;
3441 pm_runtime_get_sync(dev);
3443 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, ®);
3445 dev_err(dev, "Failed to read microphone status: %d\n",
3447 pm_runtime_put(dev);
3451 dev_dbg(dev, "Microphone status: %x\n", reg);
3454 if (reg & WM8994_MIC1_DET_STS) {
3455 if (priv->micdet[0].detecting)
3456 report = SND_JACK_HEADSET;
3458 if (reg & WM8994_MIC1_SHRT_STS) {
3459 if (priv->micdet[0].detecting)
3460 report = SND_JACK_HEADPHONE;
3462 report |= SND_JACK_BTN_0;
3465 priv->micdet[0].detecting = false;
3467 priv->micdet[0].detecting = true;
3469 snd_soc_jack_report(priv->micdet[0].jack, report,
3470 SND_JACK_HEADSET | SND_JACK_BTN_0);
3473 if (reg & WM8994_MIC2_DET_STS) {
3474 if (priv->micdet[1].detecting)
3475 report = SND_JACK_HEADSET;
3477 if (reg & WM8994_MIC2_SHRT_STS) {
3478 if (priv->micdet[1].detecting)
3479 report = SND_JACK_HEADPHONE;
3481 report |= SND_JACK_BTN_0;
3484 priv->micdet[1].detecting = false;
3486 priv->micdet[1].detecting = true;
3488 snd_soc_jack_report(priv->micdet[1].jack, report,
3489 SND_JACK_HEADSET | SND_JACK_BTN_0);
3491 pm_runtime_put(dev);
3494 static irqreturn_t wm8994_mic_irq(int irq, void *data)
3496 struct wm8994_priv *priv = data;
3497 struct snd_soc_component *component = priv->hubs.component;
3499 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3500 trace_snd_soc_jack_irq(dev_name(component->dev));
3503 pm_wakeup_event(component->dev, 300);
3505 queue_delayed_work(system_power_efficient_wq,
3506 &priv->mic_work, msecs_to_jiffies(250));
3511 /* Should be called with accdet_lock held */
3512 static void wm1811_micd_stop(struct snd_soc_component *component)
3514 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3515 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3517 if (!wm8994->jackdet)
3520 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1, WM8958_MICD_ENA, 0);
3522 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_JACK);
3524 if (wm8994->wm8994->pdata.jd_ext_cap)
3525 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3528 static void wm8958_button_det(struct snd_soc_component *component, u16 status)
3530 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3535 report |= SND_JACK_BTN_0;
3538 report |= SND_JACK_BTN_1;
3541 report |= SND_JACK_BTN_2;
3544 report |= SND_JACK_BTN_3;
3547 report |= SND_JACK_BTN_4;
3550 report |= SND_JACK_BTN_5;
3552 snd_soc_jack_report(wm8994->micdet[0].jack, report,
3556 static void wm8958_open_circuit_work(struct work_struct *work)
3558 struct wm8994_priv *wm8994 = container_of(work,
3560 open_circuit_work.work);
3561 struct device *dev = wm8994->wm8994->dev;
3563 mutex_lock(&wm8994->accdet_lock);
3565 wm1811_micd_stop(wm8994->hubs.component);
3567 dev_dbg(dev, "Reporting open circuit\n");
3569 wm8994->jack_mic = false;
3570 wm8994->mic_detecting = true;
3572 wm8958_micd_set_rate(wm8994->hubs.component);
3574 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3578 mutex_unlock(&wm8994->accdet_lock);
3581 static void wm8958_mic_id(void *data, u16 status)
3583 struct snd_soc_component *component = data;
3584 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3586 /* Either nothing present or just starting detection */
3587 if (!(status & WM8958_MICD_STS)) {
3588 /* If nothing present then clear our statuses */
3589 dev_dbg(component->dev, "Detected open circuit\n");
3591 queue_delayed_work(system_power_efficient_wq,
3592 &wm8994->open_circuit_work,
3593 msecs_to_jiffies(2500));
3597 /* If the measurement is showing a high impedence we've got a
3600 if (status & 0x600) {
3601 dev_dbg(component->dev, "Detected microphone\n");
3603 wm8994->mic_detecting = false;
3604 wm8994->jack_mic = true;
3606 wm8958_micd_set_rate(component);
3608 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
3613 if (status & 0xfc) {
3614 dev_dbg(component->dev, "Detected headphone\n");
3615 wm8994->mic_detecting = false;
3617 wm8958_micd_set_rate(component);
3619 /* If we have jackdet that will detect removal */
3620 wm1811_micd_stop(component);
3622 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3627 /* Deferred mic detection to allow for extra settling time */
3628 static void wm1811_mic_work(struct work_struct *work)
3630 struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
3632 struct wm8994 *control = wm8994->wm8994;
3633 struct snd_soc_component *component = wm8994->hubs.component;
3634 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3636 pm_runtime_get_sync(component->dev);
3638 /* If required for an external cap force MICBIAS on */
3639 if (control->pdata.jd_ext_cap) {
3640 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2");
3641 snd_soc_dapm_sync(dapm);
3644 mutex_lock(&wm8994->accdet_lock);
3646 dev_dbg(component->dev, "Starting mic detection\n");
3648 /* Use a user-supplied callback if we have one */
3649 if (wm8994->micd_cb) {
3650 wm8994->micd_cb(wm8994->micd_cb_data);
3653 * Start off measument of microphone impedence to find out
3654 * what's actually there.
3656 wm8994->mic_detecting = true;
3657 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_MIC);
3659 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3660 WM8958_MICD_ENA, WM8958_MICD_ENA);
3663 mutex_unlock(&wm8994->accdet_lock);
3665 pm_runtime_put(component->dev);
3668 static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3670 struct wm8994_priv *wm8994 = data;
3671 struct wm8994 *control = wm8994->wm8994;
3672 struct snd_soc_component *component = wm8994->hubs.component;
3673 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3677 pm_runtime_get_sync(component->dev);
3679 cancel_delayed_work_sync(&wm8994->mic_complete_work);
3681 mutex_lock(&wm8994->accdet_lock);
3683 reg = snd_soc_component_read32(component, WM1811_JACKDET_CTRL);
3685 dev_err(component->dev, "Failed to read jack status: %d\n", reg);
3686 mutex_unlock(&wm8994->accdet_lock);
3687 pm_runtime_put(component->dev);
3691 dev_dbg(component->dev, "JACKDET %x\n", reg);
3693 present = reg & WM1811_JACKDET_LVL;
3696 dev_dbg(component->dev, "Jack detected\n");
3698 wm8958_micd_set_rate(component);
3700 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3701 WM8958_MICB2_DISCH, 0);
3703 /* Disable debounce while inserted */
3704 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3705 WM1811_JACKDET_DB, 0);
3707 delay = control->pdata.micdet_delay;
3708 queue_delayed_work(system_power_efficient_wq,
3710 msecs_to_jiffies(delay));
3712 dev_dbg(component->dev, "Jack not detected\n");
3714 cancel_delayed_work_sync(&wm8994->mic_work);
3716 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3717 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
3719 /* Enable debounce while removed */
3720 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3721 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
3723 wm8994->mic_detecting = false;
3724 wm8994->jack_mic = false;
3725 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3726 WM8958_MICD_ENA, 0);
3727 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_JACK);
3730 mutex_unlock(&wm8994->accdet_lock);
3732 /* Turn off MICBIAS if it was on for an external cap */
3733 if (control->pdata.jd_ext_cap && !present)
3734 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3737 snd_soc_jack_report(wm8994->micdet[0].jack,
3738 SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
3740 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3741 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3744 /* Since we only report deltas force an update, ensures we
3745 * avoid bootstrapping issues with the core. */
3746 snd_soc_jack_report(wm8994->micdet[0].jack, 0, 0);
3748 pm_runtime_put(component->dev);
3752 static void wm1811_jackdet_bootstrap(struct work_struct *work)
3754 struct wm8994_priv *wm8994 = container_of(work,
3756 jackdet_bootstrap.work);
3757 wm1811_jackdet_irq(0, wm8994);
3761 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3763 * @component: WM8958 component
3764 * @jack: jack to report detection events on
3766 * Enable microphone detection functionality for the WM8958. By
3767 * default simple detection which supports the detection of up to 6
3768 * buttons plus video and microphone functionality is supported.
3770 * The WM8958 has an advanced jack detection facility which is able to
3771 * support complex accessory detection, especially when used in
3772 * conjunction with external circuitry. In order to provide maximum
3773 * flexiblity a callback is provided which allows a completely custom
3774 * detection algorithm.
3776 int wm8958_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
3777 wm1811_micdet_cb det_cb, void *det_cb_data,
3778 wm1811_mic_id_cb id_cb, void *id_cb_data)
3780 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
3781 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
3782 struct wm8994 *control = wm8994->wm8994;
3785 switch (control->type) {
3793 pm_runtime_get_sync(component->dev);
3796 snd_soc_dapm_force_enable_pin(dapm, "CLK_SYS");
3797 snd_soc_dapm_sync(dapm);
3799 wm8994->micdet[0].jack = jack;
3802 wm8994->micd_cb = det_cb;
3803 wm8994->micd_cb_data = det_cb_data;
3805 wm8994->mic_detecting = true;
3806 wm8994->jack_mic = false;
3810 wm8994->mic_id_cb = id_cb;
3811 wm8994->mic_id_cb_data = id_cb_data;
3813 wm8994->mic_id_cb = wm8958_mic_id;
3814 wm8994->mic_id_cb_data = component;
3817 wm8958_micd_set_rate(component);
3819 /* Detect microphones and short circuits by default */
3820 if (control->pdata.micd_lvl_sel)
3821 micd_lvl_sel = control->pdata.micd_lvl_sel;
3823 micd_lvl_sel = 0x41;
3825 wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3826 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
3827 SND_JACK_BTN_4 | SND_JACK_BTN_5;
3829 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_2,
3830 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
3832 WARN_ON(snd_soc_component_get_bias_level(component) > SND_SOC_BIAS_STANDBY);
3835 * If we can use jack detection start off with that,
3836 * otherwise jump straight to microphone detection.
3838 if (wm8994->jackdet) {
3839 /* Disable debounce for the initial detect */
3840 snd_soc_component_update_bits(component, WM1811_JACKDET_CTRL,
3841 WM1811_JACKDET_DB, 0);
3843 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
3845 WM8958_MICB2_DISCH);
3846 snd_soc_component_update_bits(component, WM8994_LDO_1,
3847 WM8994_LDO1_DISCH, 0);
3848 wm1811_jackdet_set_mode(component,
3849 WM1811_JACKDET_MODE_JACK);
3851 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3852 WM8958_MICD_ENA, WM8958_MICD_ENA);
3856 snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
3857 WM8958_MICD_ENA, 0);
3858 wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_NONE);
3859 snd_soc_dapm_disable_pin(dapm, "CLK_SYS");
3860 snd_soc_dapm_sync(dapm);
3863 pm_runtime_put(component->dev);
3867 EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3869 static void wm8958_mic_work(struct work_struct *work)
3871 struct wm8994_priv *wm8994 = container_of(work,
3873 mic_complete_work.work);
3874 struct snd_soc_component *component = wm8994->hubs.component;
3876 pm_runtime_get_sync(component->dev);
3878 mutex_lock(&wm8994->accdet_lock);
3880 wm8994->mic_id_cb(wm8994->mic_id_cb_data, wm8994->mic_status);
3882 mutex_unlock(&wm8994->accdet_lock);
3884 pm_runtime_put(component->dev);
3887 static irqreturn_t wm8958_mic_irq(int irq, void *data)
3889 struct wm8994_priv *wm8994 = data;
3890 struct snd_soc_component *component = wm8994->hubs.component;
3891 int reg, count, ret, id_delay;
3894 * Jack detection may have detected a removal simulataneously
3895 * with an update of the MICDET status; if so it will have
3896 * stopped detection and we can ignore this interrupt.
3898 if (!(snd_soc_component_read32(component, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
3901 cancel_delayed_work_sync(&wm8994->mic_complete_work);
3902 cancel_delayed_work_sync(&wm8994->open_circuit_work);
3904 pm_runtime_get_sync(component->dev);
3906 /* We may occasionally read a detection without an impedence
3907 * range being provided - if that happens loop again.
3911 reg = snd_soc_component_read32(component, WM8958_MIC_DETECT_3);
3913 dev_err(component->dev,
3914 "Failed to read mic detect status: %d\n",
3916 pm_runtime_put(component->dev);
3920 if (!(reg & WM8958_MICD_VALID)) {
3921 dev_dbg(component->dev, "Mic detect data not valid\n");
3925 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3932 dev_warn(component->dev, "No impedance range reported for jack\n");
3934 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3935 trace_snd_soc_jack_irq(dev_name(component->dev));
3938 /* Avoid a transient report when the accessory is being removed */
3939 if (wm8994->jackdet) {
3940 ret = snd_soc_component_read32(component, WM1811_JACKDET_CTRL);
3942 dev_err(component->dev, "Failed to read jack status: %d\n",
3944 } else if (!(ret & WM1811_JACKDET_LVL)) {
3945 dev_dbg(component->dev, "Ignoring removed jack\n");
3948 } else if (!(reg & WM8958_MICD_STS)) {
3949 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
3950 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
3952 wm8994->mic_detecting = true;
3956 wm8994->mic_status = reg;
3957 id_delay = wm8994->wm8994->pdata.mic_id_delay;
3959 if (wm8994->mic_detecting)
3960 queue_delayed_work(system_power_efficient_wq,
3961 &wm8994->mic_complete_work,
3962 msecs_to_jiffies(id_delay));
3964 wm8958_button_det(component, reg);
3967 pm_runtime_put(component->dev);
3971 static irqreturn_t wm8994_fifo_error(int irq, void *data)
3973 struct snd_soc_component *component = data;
3975 dev_err(component->dev, "FIFO error\n");
3980 static irqreturn_t wm8994_temp_warn(int irq, void *data)
3982 struct snd_soc_component *component = data;
3984 dev_err(component->dev, "Thermal warning\n");
3989 static irqreturn_t wm8994_temp_shut(int irq, void *data)
3991 struct snd_soc_component *component = data;
3993 dev_crit(component->dev, "Thermal shutdown\n");
3998 static int wm8994_component_probe(struct snd_soc_component *component)
4000 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
4001 struct wm8994 *control = dev_get_drvdata(component->dev->parent);
4002 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
4006 snd_soc_component_init_regmap(component, control->regmap);
4008 wm8994->hubs.component = component;
4010 mutex_init(&wm8994->accdet_lock);
4011 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
4012 wm1811_jackdet_bootstrap);
4013 INIT_DELAYED_WORK(&wm8994->open_circuit_work,
4014 wm8958_open_circuit_work);
4016 switch (control->type) {
4018 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
4021 INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
4027 INIT_DELAYED_WORK(&wm8994->mic_complete_work, wm8958_mic_work);
4029 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4030 init_completion(&wm8994->fll_locked[i]);
4032 wm8994->micdet_irq = control->pdata.micdet_irq;
4034 /* By default use idle_bias_off, will override for WM8994 */
4035 dapm->idle_bias_off = 1;
4037 /* Set revision-specific configuration */
4038 switch (control->type) {
4040 /* Single ended line outputs should have VMID on. */
4041 if (!control->pdata.lineout1_diff ||
4042 !control->pdata.lineout2_diff)
4043 dapm->idle_bias_off = 0;
4045 switch (control->revision) {
4048 wm8994->hubs.dcs_codes_l = -5;
4049 wm8994->hubs.dcs_codes_r = -5;
4050 wm8994->hubs.hp_startup_mode = 1;
4051 wm8994->hubs.dcs_readback_mode = 1;
4052 wm8994->hubs.series_startup = 1;
4055 wm8994->hubs.dcs_readback_mode = 2;
4058 wm8994->hubs.micd_scthr = true;
4062 wm8994->hubs.dcs_readback_mode = 1;
4063 wm8994->hubs.hp_startup_mode = 1;
4064 wm8994->hubs.micd_scthr = true;
4066 switch (control->revision) {
4070 wm8994->fll_byp = true;
4076 wm8994->hubs.dcs_readback_mode = 2;
4077 wm8994->hubs.no_series_update = 1;
4078 wm8994->hubs.hp_startup_mode = 1;
4079 wm8994->hubs.no_cache_dac_hp_direct = true;
4080 wm8994->fll_byp = true;
4082 wm8994->hubs.dcs_codes_l = -9;
4083 wm8994->hubs.dcs_codes_r = -7;
4085 snd_soc_component_update_bits(component, WM8994_ANALOGUE_HP_1,
4086 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
4093 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
4094 wm8994_fifo_error, "FIFO error", component);
4095 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
4096 wm8994_temp_warn, "Thermal warning", component);
4097 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
4098 wm8994_temp_shut, "Thermal shutdown", component);
4100 switch (control->type) {
4102 if (wm8994->micdet_irq)
4103 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4105 IRQF_TRIGGER_RISING |
4110 ret = wm8994_request_irq(wm8994->wm8994,
4111 WM8994_IRQ_MIC1_DET,
4112 wm8994_mic_irq, "Mic 1 detect",
4116 dev_warn(component->dev,
4117 "Failed to request Mic1 detect IRQ: %d\n",
4121 ret = wm8994_request_irq(wm8994->wm8994,
4122 WM8994_IRQ_MIC1_SHRT,
4123 wm8994_mic_irq, "Mic 1 short",
4126 dev_warn(component->dev,
4127 "Failed to request Mic1 short IRQ: %d\n",
4130 ret = wm8994_request_irq(wm8994->wm8994,
4131 WM8994_IRQ_MIC2_DET,
4132 wm8994_mic_irq, "Mic 2 detect",
4135 dev_warn(component->dev,
4136 "Failed to request Mic2 detect IRQ: %d\n",
4139 ret = wm8994_request_irq(wm8994->wm8994,
4140 WM8994_IRQ_MIC2_SHRT,
4141 wm8994_mic_irq, "Mic 2 short",
4144 dev_warn(component->dev,
4145 "Failed to request Mic2 short IRQ: %d\n",
4151 if (wm8994->micdet_irq) {
4152 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
4154 IRQF_TRIGGER_RISING |
4159 dev_warn(component->dev,
4160 "Failed to request Mic detect IRQ: %d\n",
4163 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4164 wm8958_mic_irq, "Mic detect",
4169 switch (control->type) {
4171 if (control->cust_id > 1 || control->revision > 1) {
4172 ret = wm8994_request_irq(wm8994->wm8994,
4174 wm1811_jackdet_irq, "JACKDET",
4177 wm8994->jackdet = true;
4184 wm8994->fll_locked_irq = true;
4185 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
4186 ret = wm8994_request_irq(wm8994->wm8994,
4187 WM8994_IRQ_FLL1_LOCK + i,
4188 wm8994_fll_locked_irq, "FLL lock",
4189 &wm8994->fll_locked[i]);
4191 wm8994->fll_locked_irq = false;
4194 /* Make sure we can read from the GPIOs if they're inputs */
4195 pm_runtime_get_sync(component->dev);
4197 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
4198 * configured on init - if a system wants to do this dynamically
4199 * at runtime we can deal with that then.
4201 ret = regmap_read(control->regmap, WM8994_GPIO_1, ®);
4203 dev_err(component->dev, "Failed to read GPIO1 state: %d\n", ret);
4206 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
4207 wm8994->lrclk_shared[0] = 1;
4208 wm8994_dai[0].symmetric_rates = 1;
4210 wm8994->lrclk_shared[0] = 0;
4213 ret = regmap_read(control->regmap, WM8994_GPIO_6, ®);
4215 dev_err(component->dev, "Failed to read GPIO6 state: %d\n", ret);
4218 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
4219 wm8994->lrclk_shared[1] = 1;
4220 wm8994_dai[1].symmetric_rates = 1;
4222 wm8994->lrclk_shared[1] = 0;
4225 pm_runtime_put(component->dev);
4227 /* Latch volume update bits */
4228 for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
4229 snd_soc_component_update_bits(component, wm8994_vu_bits[i].reg,
4230 wm8994_vu_bits[i].mask,
4231 wm8994_vu_bits[i].mask);
4233 /* Set the low bit of the 3D stereo depth so TLV matches */
4234 snd_soc_component_update_bits(component, WM8994_AIF1_DAC1_FILTERS_2,
4235 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
4236 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
4237 snd_soc_component_update_bits(component, WM8994_AIF1_DAC2_FILTERS_2,
4238 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
4239 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
4240 snd_soc_component_update_bits(component, WM8994_AIF2_DAC_FILTERS_2,
4241 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
4242 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
4244 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
4245 * use this; it only affects behaviour on idle TDM clock
4247 switch (control->type) {
4250 snd_soc_component_update_bits(component, WM8994_AIF1_CONTROL_1,
4251 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
4257 /* Put MICBIAS into bypass mode by default on newer devices */
4258 switch (control->type) {
4261 snd_soc_component_update_bits(component, WM8958_MICBIAS1,
4262 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
4263 snd_soc_component_update_bits(component, WM8958_MICBIAS2,
4264 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
4270 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
4271 wm_hubs_update_class_w(component);
4273 wm8994_handle_pdata(wm8994);
4275 wm_hubs_add_analogue_controls(component);
4276 snd_soc_add_component_controls(component, wm8994_common_snd_controls,
4277 ARRAY_SIZE(wm8994_common_snd_controls));
4278 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
4279 ARRAY_SIZE(wm8994_dapm_widgets));
4281 switch (control->type) {
4283 snd_soc_add_component_controls(component, wm8994_snd_controls,
4284 ARRAY_SIZE(wm8994_snd_controls));
4285 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
4286 ARRAY_SIZE(wm8994_specific_dapm_widgets));
4287 if (control->revision < 4) {
4288 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4289 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4290 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4291 ARRAY_SIZE(wm8994_adc_revd_widgets));
4292 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4293 ARRAY_SIZE(wm8994_dac_revd_widgets));
4295 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4296 ARRAY_SIZE(wm8994_lateclk_widgets));
4297 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4298 ARRAY_SIZE(wm8994_adc_widgets));
4299 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4300 ARRAY_SIZE(wm8994_dac_widgets));
4304 snd_soc_add_component_controls(component, wm8994_snd_controls,
4305 ARRAY_SIZE(wm8994_snd_controls));
4306 snd_soc_add_component_controls(component, wm8958_snd_controls,
4307 ARRAY_SIZE(wm8958_snd_controls));
4308 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4309 ARRAY_SIZE(wm8958_dapm_widgets));
4310 if (control->revision < 1) {
4311 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
4312 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
4313 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
4314 ARRAY_SIZE(wm8994_adc_revd_widgets));
4315 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
4316 ARRAY_SIZE(wm8994_dac_revd_widgets));
4318 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4319 ARRAY_SIZE(wm8994_lateclk_widgets));
4320 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4321 ARRAY_SIZE(wm8994_adc_widgets));
4322 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4323 ARRAY_SIZE(wm8994_dac_widgets));
4328 snd_soc_add_component_controls(component, wm8958_snd_controls,
4329 ARRAY_SIZE(wm8958_snd_controls));
4330 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
4331 ARRAY_SIZE(wm8958_dapm_widgets));
4332 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
4333 ARRAY_SIZE(wm8994_lateclk_widgets));
4334 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
4335 ARRAY_SIZE(wm8994_adc_widgets));
4336 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
4337 ARRAY_SIZE(wm8994_dac_widgets));
4341 wm_hubs_add_analogue_routes(component, 0, 0);
4342 ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4343 wm_hubs_dcs_done, "DC servo done",
4346 wm8994->hubs.dcs_done_irq = true;
4347 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
4349 switch (control->type) {
4351 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4352 ARRAY_SIZE(wm8994_intercon));
4354 if (control->revision < 4) {
4355 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4356 ARRAY_SIZE(wm8994_revd_intercon));
4357 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4358 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4360 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4361 ARRAY_SIZE(wm8994_lateclk_intercon));
4365 if (control->revision < 1) {
4366 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
4367 ARRAY_SIZE(wm8994_intercon));
4368 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
4369 ARRAY_SIZE(wm8994_revd_intercon));
4370 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
4371 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
4373 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4374 ARRAY_SIZE(wm8994_lateclk_intercon));
4375 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4376 ARRAY_SIZE(wm8958_intercon));
4379 wm8958_dsp2_init(component);
4382 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
4383 ARRAY_SIZE(wm8994_lateclk_intercon));
4384 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
4385 ARRAY_SIZE(wm8958_intercon));
4392 if (wm8994->jackdet)
4393 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4394 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
4395 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
4396 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
4397 if (wm8994->micdet_irq)
4398 free_irq(wm8994->micdet_irq, wm8994);
4399 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4400 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4401 &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);
4411 static void wm8994_component_remove(struct snd_soc_component *component)
4413 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
4414 struct wm8994 *control = wm8994->wm8994;
4417 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4418 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4419 &wm8994->fll_locked[i]);
4421 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
4423 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, component);
4424 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, component);
4425 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, component);
4427 if (wm8994->jackdet)
4428 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
4430 switch (control->type) {
4432 if (wm8994->micdet_irq)
4433 free_irq(wm8994->micdet_irq, wm8994);
4434 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
4436 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
4438 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
4444 if (wm8994->micdet_irq)
4445 free_irq(wm8994->micdet_irq, wm8994);
4448 release_firmware(wm8994->mbc);
4449 release_firmware(wm8994->mbc_vss);
4450 release_firmware(wm8994->enh_eq);
4451 kfree(wm8994->retune_mobile_texts);
4454 static const struct snd_soc_component_driver soc_component_dev_wm8994 = {
4455 .probe = wm8994_component_probe,
4456 .remove = wm8994_component_remove,
4457 .suspend = wm8994_component_suspend,
4458 .resume = wm8994_component_resume,
4459 .set_bias_level = wm8994_set_bias_level,
4461 .use_pmdown_time = 1,
4463 .non_legacy_dai_naming = 1,
4466 static int wm8994_probe(struct platform_device *pdev)
4468 struct wm8994_priv *wm8994;
4470 wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
4474 platform_set_drvdata(pdev, wm8994);
4476 mutex_init(&wm8994->fw_lock);
4478 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
4480 pm_runtime_enable(&pdev->dev);
4481 pm_runtime_idle(&pdev->dev);
4483 return devm_snd_soc_register_component(&pdev->dev, &soc_component_dev_wm8994,
4484 wm8994_dai, ARRAY_SIZE(wm8994_dai));
4487 static int wm8994_remove(struct platform_device *pdev)
4489 pm_runtime_disable(&pdev->dev);
4494 #ifdef CONFIG_PM_SLEEP
4495 static int wm8994_suspend(struct device *dev)
4497 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4499 /* Drop down to power saving mode when system is suspended */
4500 if (wm8994->jackdet && !wm8994->active_refcount)
4501 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4502 WM1811_JACKDET_MODE_MASK,
4503 wm8994->jackdet_mode);
4508 static int wm8994_resume(struct device *dev)
4510 struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
4512 if (wm8994->jackdet && wm8994->jackdet_mode)
4513 regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
4514 WM1811_JACKDET_MODE_MASK,
4515 WM1811_JACKDET_MODE_AUDIO);
4521 static const struct dev_pm_ops wm8994_pm_ops = {
4522 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
4525 static struct platform_driver wm8994_codec_driver = {
4527 .name = "wm8994-codec",
4528 .pm = &wm8994_pm_ops,
4530 .probe = wm8994_probe,
4531 .remove = wm8994_remove,
4534 module_platform_driver(wm8994_codec_driver);
4536 MODULE_DESCRIPTION("ASoC WM8994 driver");
4537 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4538 MODULE_LICENSE("GPL");
4539 MODULE_ALIAS("platform:wm8994-codec");