2 * wm8994.c -- WM8994 ALSA SoC Audio driver
4 * Copyright 2009-12 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/gcd.h>
20 #include <linux/i2c.h>
21 #include <linux/platform_device.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/slab.h>
25 #include <sound/core.h>
26 #include <sound/jack.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include <sound/initval.h>
31 #include <sound/tlv.h>
32 #include <trace/events/asoc.h>
34 #include <linux/mfd/wm8994/core.h>
35 #include <linux/mfd/wm8994/registers.h>
36 #include <linux/mfd/wm8994/pdata.h>
37 #include <linux/mfd/wm8994/gpio.h>
42 #define WM1811_JACKDET_MODE_NONE 0x0000
43 #define WM1811_JACKDET_MODE_JACK 0x0100
44 #define WM1811_JACKDET_MODE_MIC 0x0080
45 #define WM1811_JACKDET_MODE_AUDIO 0x0180
47 #define WM8994_NUM_DRC 3
48 #define WM8994_NUM_EQ 3
53 } wm8994_vu_bits
[] = {
54 { WM8994_LEFT_LINE_INPUT_1_2_VOLUME
, WM8994_IN1_VU
},
55 { WM8994_RIGHT_LINE_INPUT_1_2_VOLUME
, WM8994_IN1_VU
},
56 { WM8994_LEFT_LINE_INPUT_3_4_VOLUME
, WM8994_IN2_VU
},
57 { WM8994_RIGHT_LINE_INPUT_3_4_VOLUME
, WM8994_IN2_VU
},
58 { WM8994_SPEAKER_VOLUME_LEFT
, WM8994_SPKOUT_VU
},
59 { WM8994_SPEAKER_VOLUME_RIGHT
, WM8994_SPKOUT_VU
},
60 { WM8994_LEFT_OUTPUT_VOLUME
, WM8994_HPOUT1_VU
},
61 { WM8994_RIGHT_OUTPUT_VOLUME
, WM8994_HPOUT1_VU
},
62 { WM8994_LEFT_OPGA_VOLUME
, WM8994_MIXOUT_VU
},
63 { WM8994_RIGHT_OPGA_VOLUME
, WM8994_MIXOUT_VU
},
65 { WM8994_AIF1_DAC1_LEFT_VOLUME
, WM8994_AIF1DAC1_VU
},
66 { WM8994_AIF1_DAC1_RIGHT_VOLUME
, WM8994_AIF1DAC1_VU
},
67 { WM8994_AIF1_DAC2_LEFT_VOLUME
, WM8994_AIF1DAC2_VU
},
68 { WM8994_AIF1_DAC2_RIGHT_VOLUME
, WM8994_AIF1DAC2_VU
},
69 { WM8994_AIF2_DAC_LEFT_VOLUME
, WM8994_AIF2DAC_VU
},
70 { WM8994_AIF2_DAC_RIGHT_VOLUME
, WM8994_AIF2DAC_VU
},
71 { WM8994_AIF1_ADC1_LEFT_VOLUME
, WM8994_AIF1ADC1_VU
},
72 { WM8994_AIF1_ADC1_RIGHT_VOLUME
, WM8994_AIF1ADC1_VU
},
73 { WM8994_AIF1_ADC2_LEFT_VOLUME
, WM8994_AIF1ADC2_VU
},
74 { WM8994_AIF1_ADC2_RIGHT_VOLUME
, WM8994_AIF1ADC2_VU
},
75 { WM8994_AIF2_ADC_LEFT_VOLUME
, WM8994_AIF2ADC_VU
},
76 { WM8994_AIF2_ADC_RIGHT_VOLUME
, WM8994_AIF1ADC2_VU
},
77 { WM8994_DAC1_LEFT_VOLUME
, WM8994_DAC1_VU
},
78 { WM8994_DAC1_RIGHT_VOLUME
, WM8994_DAC1_VU
},
79 { WM8994_DAC2_LEFT_VOLUME
, WM8994_DAC2_VU
},
80 { WM8994_DAC2_RIGHT_VOLUME
, WM8994_DAC2_VU
},
83 static int wm8994_drc_base
[] = {
89 static int wm8994_retune_mobile_base
[] = {
90 WM8994_AIF1_DAC1_EQ_GAINS_1
,
91 WM8994_AIF1_DAC2_EQ_GAINS_1
,
92 WM8994_AIF2_EQ_GAINS_1
,
95 static const struct wm8958_micd_rate micdet_rates
[] = {
96 { 32768, true, 1, 4 },
97 { 32768, false, 1, 1 },
98 { 44100 * 256, true, 7, 10 },
99 { 44100 * 256, false, 7, 10 },
102 static const struct wm8958_micd_rate jackdet_rates
[] = {
103 { 32768, true, 0, 1 },
104 { 32768, false, 0, 1 },
105 { 44100 * 256, true, 10, 10 },
106 { 44100 * 256, false, 7, 8 },
109 static void wm8958_micd_set_rate(struct snd_soc_codec
*codec
)
111 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
112 struct wm8994
*control
= wm8994
->wm8994
;
113 int best
, i
, sysclk
, val
;
115 const struct wm8958_micd_rate
*rates
;
118 idle
= !wm8994
->jack_mic
;
120 sysclk
= snd_soc_read(codec
, WM8994_CLOCKING_1
);
121 if (sysclk
& WM8994_SYSCLK_SRC
)
122 sysclk
= wm8994
->aifclk
[1];
124 sysclk
= wm8994
->aifclk
[0];
126 if (control
->pdata
.micd_rates
) {
127 rates
= control
->pdata
.micd_rates
;
128 num_rates
= control
->pdata
.num_micd_rates
;
129 } else if (wm8994
->jackdet
) {
130 rates
= jackdet_rates
;
131 num_rates
= ARRAY_SIZE(jackdet_rates
);
133 rates
= micdet_rates
;
134 num_rates
= ARRAY_SIZE(micdet_rates
);
138 for (i
= 0; i
< num_rates
; i
++) {
139 if (rates
[i
].idle
!= idle
)
141 if (abs(rates
[i
].sysclk
- sysclk
) <
142 abs(rates
[best
].sysclk
- sysclk
))
144 else if (rates
[best
].idle
!= idle
)
148 val
= rates
[best
].start
<< WM8958_MICD_BIAS_STARTTIME_SHIFT
149 | rates
[best
].rate
<< WM8958_MICD_RATE_SHIFT
;
151 dev_dbg(codec
->dev
, "MICD rate %d,%d for %dHz %s\n",
152 rates
[best
].start
, rates
[best
].rate
, sysclk
,
153 idle
? "idle" : "active");
155 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
,
156 WM8958_MICD_BIAS_STARTTIME_MASK
|
157 WM8958_MICD_RATE_MASK
, val
);
160 static int configure_aif_clock(struct snd_soc_codec
*codec
, int aif
)
162 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
172 switch (wm8994
->sysclk
[aif
]) {
173 case WM8994_SYSCLK_MCLK1
:
174 rate
= wm8994
->mclk
[0];
177 case WM8994_SYSCLK_MCLK2
:
179 rate
= wm8994
->mclk
[1];
182 case WM8994_SYSCLK_FLL1
:
184 rate
= wm8994
->fll
[0].out
;
187 case WM8994_SYSCLK_FLL2
:
189 rate
= wm8994
->fll
[1].out
;
196 if (rate
>= 13500000) {
198 reg1
|= WM8994_AIF1CLK_DIV
;
200 dev_dbg(codec
->dev
, "Dividing AIF%d clock to %dHz\n",
204 wm8994
->aifclk
[aif
] = rate
;
206 snd_soc_update_bits(codec
, WM8994_AIF1_CLOCKING_1
+ offset
,
207 WM8994_AIF1CLK_SRC_MASK
| WM8994_AIF1CLK_DIV
,
213 static int configure_clock(struct snd_soc_codec
*codec
)
215 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
218 /* Bring up the AIF clocks first */
219 configure_aif_clock(codec
, 0);
220 configure_aif_clock(codec
, 1);
222 /* Then switch CLK_SYS over to the higher of them; a change
223 * can only happen as a result of a clocking change which can
224 * only be made outside of DAPM so we can safely redo the
228 /* If they're equal it doesn't matter which is used */
229 if (wm8994
->aifclk
[0] == wm8994
->aifclk
[1]) {
230 wm8958_micd_set_rate(codec
);
234 if (wm8994
->aifclk
[0] < wm8994
->aifclk
[1])
235 new = WM8994_SYSCLK_SRC
;
239 change
= snd_soc_update_bits(codec
, WM8994_CLOCKING_1
,
240 WM8994_SYSCLK_SRC
, new);
242 snd_soc_dapm_sync(&codec
->dapm
);
244 wm8958_micd_set_rate(codec
);
249 static int check_clk_sys(struct snd_soc_dapm_widget
*source
,
250 struct snd_soc_dapm_widget
*sink
)
252 int reg
= snd_soc_read(source
->codec
, WM8994_CLOCKING_1
);
255 /* Check what we're currently using for CLK_SYS */
256 if (reg
& WM8994_SYSCLK_SRC
)
261 return strcmp(source
->name
, clk
) == 0;
264 static const char *sidetone_hpf_text
[] = {
265 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
268 static const struct soc_enum sidetone_hpf
=
269 SOC_ENUM_SINGLE(WM8994_SIDETONE
, 7, 7, sidetone_hpf_text
);
271 static const char *adc_hpf_text
[] = {
272 "HiFi", "Voice 1", "Voice 2", "Voice 3"
275 static const struct soc_enum aif1adc1_hpf
=
276 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS
, 13, 4, adc_hpf_text
);
278 static const struct soc_enum aif1adc2_hpf
=
279 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS
, 13, 4, adc_hpf_text
);
281 static const struct soc_enum aif2adc_hpf
=
282 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS
, 13, 4, adc_hpf_text
);
284 static const DECLARE_TLV_DB_SCALE(aif_tlv
, 0, 600, 0);
285 static const DECLARE_TLV_DB_SCALE(digital_tlv
, -7200, 75, 1);
286 static const DECLARE_TLV_DB_SCALE(st_tlv
, -3600, 300, 0);
287 static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv
, -1600, 183, 0);
288 static const DECLARE_TLV_DB_SCALE(eq_tlv
, -1200, 100, 0);
289 static const DECLARE_TLV_DB_SCALE(ng_tlv
, -10200, 600, 0);
290 static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv
, 0, 900, 0);
292 #define WM8994_DRC_SWITCH(xname, reg, shift) \
293 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
294 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
295 .put = wm8994_put_drc_sw, \
296 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
298 static int wm8994_put_drc_sw(struct snd_kcontrol
*kcontrol
,
299 struct snd_ctl_elem_value
*ucontrol
)
301 struct soc_mixer_control
*mc
=
302 (struct soc_mixer_control
*)kcontrol
->private_value
;
303 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
306 /* Can't enable both ADC and DAC paths simultaneously */
307 if (mc
->shift
== WM8994_AIF1DAC1_DRC_ENA_SHIFT
)
308 mask
= WM8994_AIF1ADC1L_DRC_ENA_MASK
|
309 WM8994_AIF1ADC1R_DRC_ENA_MASK
;
311 mask
= WM8994_AIF1DAC1_DRC_ENA_MASK
;
313 ret
= snd_soc_read(codec
, mc
->reg
);
319 return snd_soc_put_volsw(kcontrol
, ucontrol
);
322 static void wm8994_set_drc(struct snd_soc_codec
*codec
, int drc
)
324 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
325 struct wm8994
*control
= wm8994
->wm8994
;
326 struct wm8994_pdata
*pdata
= &control
->pdata
;
327 int base
= wm8994_drc_base
[drc
];
328 int cfg
= wm8994
->drc_cfg
[drc
];
331 /* Save any enables; the configuration should clear them. */
332 save
= snd_soc_read(codec
, base
);
333 save
&= WM8994_AIF1DAC1_DRC_ENA
| WM8994_AIF1ADC1L_DRC_ENA
|
334 WM8994_AIF1ADC1R_DRC_ENA
;
336 for (i
= 0; i
< WM8994_DRC_REGS
; i
++)
337 snd_soc_update_bits(codec
, base
+ i
, 0xffff,
338 pdata
->drc_cfgs
[cfg
].regs
[i
]);
340 snd_soc_update_bits(codec
, base
, WM8994_AIF1DAC1_DRC_ENA
|
341 WM8994_AIF1ADC1L_DRC_ENA
|
342 WM8994_AIF1ADC1R_DRC_ENA
, save
);
345 /* Icky as hell but saves code duplication */
346 static int wm8994_get_drc(const char *name
)
348 if (strcmp(name
, "AIF1DRC1 Mode") == 0)
350 if (strcmp(name
, "AIF1DRC2 Mode") == 0)
352 if (strcmp(name
, "AIF2DRC Mode") == 0)
357 static int wm8994_put_drc_enum(struct snd_kcontrol
*kcontrol
,
358 struct snd_ctl_elem_value
*ucontrol
)
360 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
361 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
362 struct wm8994
*control
= wm8994
->wm8994
;
363 struct wm8994_pdata
*pdata
= &control
->pdata
;
364 int drc
= wm8994_get_drc(kcontrol
->id
.name
);
365 int value
= ucontrol
->value
.integer
.value
[0];
370 if (value
>= pdata
->num_drc_cfgs
)
373 wm8994
->drc_cfg
[drc
] = value
;
375 wm8994_set_drc(codec
, drc
);
380 static int wm8994_get_drc_enum(struct snd_kcontrol
*kcontrol
,
381 struct snd_ctl_elem_value
*ucontrol
)
383 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
384 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
385 int drc
= wm8994_get_drc(kcontrol
->id
.name
);
387 ucontrol
->value
.enumerated
.item
[0] = wm8994
->drc_cfg
[drc
];
392 static void wm8994_set_retune_mobile(struct snd_soc_codec
*codec
, int block
)
394 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
395 struct wm8994
*control
= wm8994
->wm8994
;
396 struct wm8994_pdata
*pdata
= &control
->pdata
;
397 int base
= wm8994_retune_mobile_base
[block
];
398 int iface
, best
, best_val
, save
, i
, cfg
;
400 if (!pdata
|| !wm8994
->num_retune_mobile_texts
)
415 /* Find the version of the currently selected configuration
416 * with the nearest sample rate. */
417 cfg
= wm8994
->retune_mobile_cfg
[block
];
420 for (i
= 0; i
< pdata
->num_retune_mobile_cfgs
; i
++) {
421 if (strcmp(pdata
->retune_mobile_cfgs
[i
].name
,
422 wm8994
->retune_mobile_texts
[cfg
]) == 0 &&
423 abs(pdata
->retune_mobile_cfgs
[i
].rate
424 - wm8994
->dac_rates
[iface
]) < best_val
) {
426 best_val
= abs(pdata
->retune_mobile_cfgs
[i
].rate
427 - wm8994
->dac_rates
[iface
]);
431 dev_dbg(codec
->dev
, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
433 pdata
->retune_mobile_cfgs
[best
].name
,
434 pdata
->retune_mobile_cfgs
[best
].rate
,
435 wm8994
->dac_rates
[iface
]);
437 /* The EQ will be disabled while reconfiguring it, remember the
438 * current configuration.
440 save
= snd_soc_read(codec
, base
);
441 save
&= WM8994_AIF1DAC1_EQ_ENA
;
443 for (i
= 0; i
< WM8994_EQ_REGS
; i
++)
444 snd_soc_update_bits(codec
, base
+ i
, 0xffff,
445 pdata
->retune_mobile_cfgs
[best
].regs
[i
]);
447 snd_soc_update_bits(codec
, base
, WM8994_AIF1DAC1_EQ_ENA
, save
);
450 /* Icky as hell but saves code duplication */
451 static int wm8994_get_retune_mobile_block(const char *name
)
453 if (strcmp(name
, "AIF1.1 EQ Mode") == 0)
455 if (strcmp(name
, "AIF1.2 EQ Mode") == 0)
457 if (strcmp(name
, "AIF2 EQ Mode") == 0)
462 static int wm8994_put_retune_mobile_enum(struct snd_kcontrol
*kcontrol
,
463 struct snd_ctl_elem_value
*ucontrol
)
465 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
466 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
467 struct wm8994
*control
= wm8994
->wm8994
;
468 struct wm8994_pdata
*pdata
= &control
->pdata
;
469 int block
= wm8994_get_retune_mobile_block(kcontrol
->id
.name
);
470 int value
= ucontrol
->value
.integer
.value
[0];
475 if (value
>= pdata
->num_retune_mobile_cfgs
)
478 wm8994
->retune_mobile_cfg
[block
] = value
;
480 wm8994_set_retune_mobile(codec
, block
);
485 static int wm8994_get_retune_mobile_enum(struct snd_kcontrol
*kcontrol
,
486 struct snd_ctl_elem_value
*ucontrol
)
488 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
489 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
490 int block
= wm8994_get_retune_mobile_block(kcontrol
->id
.name
);
492 ucontrol
->value
.enumerated
.item
[0] = wm8994
->retune_mobile_cfg
[block
];
497 static const char *aif_chan_src_text
[] = {
501 static const struct soc_enum aif1adcl_src
=
502 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1
, 15, 2, aif_chan_src_text
);
504 static const struct soc_enum aif1adcr_src
=
505 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1
, 14, 2, aif_chan_src_text
);
507 static const struct soc_enum aif2adcl_src
=
508 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1
, 15, 2, aif_chan_src_text
);
510 static const struct soc_enum aif2adcr_src
=
511 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1
, 14, 2, aif_chan_src_text
);
513 static const struct soc_enum aif1dacl_src
=
514 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2
, 15, 2, aif_chan_src_text
);
516 static const struct soc_enum aif1dacr_src
=
517 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2
, 14, 2, aif_chan_src_text
);
519 static const struct soc_enum aif2dacl_src
=
520 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2
, 15, 2, aif_chan_src_text
);
522 static const struct soc_enum aif2dacr_src
=
523 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2
, 14, 2, aif_chan_src_text
);
525 static const char *osr_text
[] = {
526 "Low Power", "High Performance",
529 static const struct soc_enum dac_osr
=
530 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING
, 0, 2, osr_text
);
532 static const struct soc_enum adc_osr
=
533 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING
, 1, 2, osr_text
);
535 static const struct snd_kcontrol_new wm8994_snd_controls
[] = {
536 SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME
,
537 WM8994_AIF1_ADC1_RIGHT_VOLUME
,
538 1, 119, 0, digital_tlv
),
539 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME
,
540 WM8994_AIF1_ADC2_RIGHT_VOLUME
,
541 1, 119, 0, digital_tlv
),
542 SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME
,
543 WM8994_AIF2_ADC_RIGHT_VOLUME
,
544 1, 119, 0, digital_tlv
),
546 SOC_ENUM("AIF1ADCL Source", aif1adcl_src
),
547 SOC_ENUM("AIF1ADCR Source", aif1adcr_src
),
548 SOC_ENUM("AIF2ADCL Source", aif2adcl_src
),
549 SOC_ENUM("AIF2ADCR Source", aif2adcr_src
),
551 SOC_ENUM("AIF1DACL Source", aif1dacl_src
),
552 SOC_ENUM("AIF1DACR Source", aif1dacr_src
),
553 SOC_ENUM("AIF2DACL Source", aif2dacl_src
),
554 SOC_ENUM("AIF2DACR Source", aif2dacr_src
),
556 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME
,
557 WM8994_AIF1_DAC1_RIGHT_VOLUME
, 1, 96, 0, digital_tlv
),
558 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME
,
559 WM8994_AIF1_DAC2_RIGHT_VOLUME
, 1, 96, 0, digital_tlv
),
560 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME
,
561 WM8994_AIF2_DAC_RIGHT_VOLUME
, 1, 96, 0, digital_tlv
),
563 SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2
, 10, 3, 0, aif_tlv
),
564 SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2
, 10, 3, 0, aif_tlv
),
566 SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1
, 0, 1, 0),
567 SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1
, 0, 1, 0),
568 SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1
, 0, 1, 0),
570 WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1
, 2),
571 WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1
, 1),
572 WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1
, 0),
574 WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1
, 2),
575 WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1
, 1),
576 WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1
, 0),
578 WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1
, 2),
579 WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1
, 1),
580 WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1
, 0),
582 SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES
,
584 SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES
,
586 SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES
,
588 SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES
,
590 SOC_ENUM("Sidetone HPF Mux", sidetone_hpf
),
591 SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE
, 6, 1, 0),
593 SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf
),
594 SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS
, 12, 11, 1, 0),
596 SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf
),
597 SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS
, 12, 11, 1, 0),
599 SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf
),
600 SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS
, 12, 11, 1, 0),
602 SOC_ENUM("ADC OSR", adc_osr
),
603 SOC_ENUM("DAC OSR", dac_osr
),
605 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME
,
606 WM8994_DAC1_RIGHT_VOLUME
, 1, 96, 0, digital_tlv
),
607 SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME
,
608 WM8994_DAC1_RIGHT_VOLUME
, 9, 1, 1),
610 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME
,
611 WM8994_DAC2_RIGHT_VOLUME
, 1, 96, 0, digital_tlv
),
612 SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME
,
613 WM8994_DAC2_RIGHT_VOLUME
, 9, 1, 1),
615 SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION
,
616 6, 1, 1, wm_hubs_spkmix_tlv
),
617 SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION
,
618 2, 1, 1, wm_hubs_spkmix_tlv
),
620 SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION
,
621 6, 1, 1, wm_hubs_spkmix_tlv
),
622 SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION
,
623 2, 1, 1, wm_hubs_spkmix_tlv
),
625 SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2
,
626 10, 15, 0, wm8994_3d_tlv
),
627 SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2
,
629 SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2
,
630 10, 15, 0, wm8994_3d_tlv
),
631 SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2
,
633 SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2
,
634 10, 15, 0, wm8994_3d_tlv
),
635 SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2
,
639 static const struct snd_kcontrol_new wm8994_eq_controls
[] = {
640 SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1
, 11, 31, 0,
642 SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1
, 6, 31, 0,
644 SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1
, 1, 31, 0,
646 SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2
, 11, 31, 0,
648 SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2
, 6, 31, 0,
651 SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1
, 11, 31, 0,
653 SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1
, 6, 31, 0,
655 SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1
, 1, 31, 0,
657 SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2
, 11, 31, 0,
659 SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2
, 6, 31, 0,
662 SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1
, 11, 31, 0,
664 SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1
, 6, 31, 0,
666 SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1
, 1, 31, 0,
668 SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2
, 11, 31, 0,
670 SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2
, 6, 31, 0,
674 static const struct snd_kcontrol_new wm8994_drc_controls
[] = {
675 SND_SOC_BYTES_MASK("AIF1.1 DRC", WM8994_AIF1_DRC1_1
, 5,
676 WM8994_AIF1DAC1_DRC_ENA
| WM8994_AIF1ADC1L_DRC_ENA
|
677 WM8994_AIF1ADC1R_DRC_ENA
),
678 SND_SOC_BYTES_MASK("AIF1.2 DRC", WM8994_AIF1_DRC2_1
, 5,
679 WM8994_AIF1DAC2_DRC_ENA
| WM8994_AIF1ADC2L_DRC_ENA
|
680 WM8994_AIF1ADC2R_DRC_ENA
),
681 SND_SOC_BYTES_MASK("AIF2 DRC", WM8994_AIF2_DRC_1
, 5,
682 WM8994_AIF2DAC_DRC_ENA
| WM8994_AIF2ADCL_DRC_ENA
|
683 WM8994_AIF2ADCR_DRC_ENA
),
686 static const char *wm8958_ng_text
[] = {
687 "30ms", "125ms", "250ms", "500ms",
690 static const struct soc_enum wm8958_aif1dac1_ng_hold
=
691 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE
,
692 WM8958_AIF1DAC1_NG_THR_SHIFT
, 4, wm8958_ng_text
);
694 static const struct soc_enum wm8958_aif1dac2_ng_hold
=
695 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE
,
696 WM8958_AIF1DAC2_NG_THR_SHIFT
, 4, wm8958_ng_text
);
698 static const struct soc_enum wm8958_aif2dac_ng_hold
=
699 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE
,
700 WM8958_AIF2DAC_NG_THR_SHIFT
, 4, wm8958_ng_text
);
702 static const struct snd_kcontrol_new wm8958_snd_controls
[] = {
703 SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2
, 10, 3, 0, aif_tlv
),
705 SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE
,
706 WM8958_AIF1DAC1_NG_ENA_SHIFT
, 1, 0),
707 SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold
),
708 SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
709 WM8958_AIF1_DAC1_NOISE_GATE
, WM8958_AIF1DAC1_NG_THR_SHIFT
,
712 SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE
,
713 WM8958_AIF1DAC2_NG_ENA_SHIFT
, 1, 0),
714 SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold
),
715 SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
716 WM8958_AIF1_DAC2_NOISE_GATE
, WM8958_AIF1DAC2_NG_THR_SHIFT
,
719 SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE
,
720 WM8958_AIF2DAC_NG_ENA_SHIFT
, 1, 0),
721 SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold
),
722 SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
723 WM8958_AIF2_DAC_NOISE_GATE
, WM8958_AIF2DAC_NG_THR_SHIFT
,
727 static const struct snd_kcontrol_new wm1811_snd_controls
[] = {
728 SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1
, 7, 1, 0,
730 SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1
, 8, 1, 0,
734 /* We run all mode setting through a function to enforce audio mode */
735 static void wm1811_jackdet_set_mode(struct snd_soc_codec
*codec
, u16 mode
)
737 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
739 if (!wm8994
->jackdet
|| !wm8994
->micdet
[0].jack
)
742 if (wm8994
->active_refcount
)
743 mode
= WM1811_JACKDET_MODE_AUDIO
;
745 if (mode
== wm8994
->jackdet_mode
)
748 wm8994
->jackdet_mode
= mode
;
750 /* Always use audio mode to detect while the system is active */
751 if (mode
!= WM1811_JACKDET_MODE_NONE
)
752 mode
= WM1811_JACKDET_MODE_AUDIO
;
754 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
755 WM1811_JACKDET_MODE_MASK
, mode
);
758 static void active_reference(struct snd_soc_codec
*codec
)
760 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
762 mutex_lock(&wm8994
->accdet_lock
);
764 wm8994
->active_refcount
++;
766 dev_dbg(codec
->dev
, "Active refcount incremented, now %d\n",
767 wm8994
->active_refcount
);
769 /* If we're using jack detection go into audio mode */
770 wm1811_jackdet_set_mode(codec
, WM1811_JACKDET_MODE_AUDIO
);
772 mutex_unlock(&wm8994
->accdet_lock
);
775 static void active_dereference(struct snd_soc_codec
*codec
)
777 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
780 mutex_lock(&wm8994
->accdet_lock
);
782 wm8994
->active_refcount
--;
784 dev_dbg(codec
->dev
, "Active refcount decremented, now %d\n",
785 wm8994
->active_refcount
);
787 if (wm8994
->active_refcount
== 0) {
788 /* Go into appropriate detection only mode */
789 if (wm8994
->jack_mic
|| wm8994
->mic_detecting
)
790 mode
= WM1811_JACKDET_MODE_MIC
;
792 mode
= WM1811_JACKDET_MODE_JACK
;
794 wm1811_jackdet_set_mode(codec
, mode
);
797 mutex_unlock(&wm8994
->accdet_lock
);
800 static int clk_sys_event(struct snd_soc_dapm_widget
*w
,
801 struct snd_kcontrol
*kcontrol
, int event
)
803 struct snd_soc_codec
*codec
= w
->codec
;
804 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
807 case SND_SOC_DAPM_PRE_PMU
:
808 return configure_clock(codec
);
810 case SND_SOC_DAPM_POST_PMU
:
812 * JACKDET won't run until we start the clock and it
813 * only reports deltas, make sure we notify the state
814 * up the stack on startup. Use a *very* generous
815 * timeout for paranoia, there's no urgency and we
816 * don't want false reports.
818 if (wm8994
->jackdet
&& !wm8994
->clk_has_run
) {
819 schedule_delayed_work(&wm8994
->jackdet_bootstrap
,
820 msecs_to_jiffies(1000));
821 wm8994
->clk_has_run
= true;
825 case SND_SOC_DAPM_POST_PMD
:
826 configure_clock(codec
);
833 static void vmid_reference(struct snd_soc_codec
*codec
)
835 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
837 pm_runtime_get_sync(codec
->dev
);
839 wm8994
->vmid_refcount
++;
841 dev_dbg(codec
->dev
, "Referencing VMID, refcount is now %d\n",
842 wm8994
->vmid_refcount
);
844 if (wm8994
->vmid_refcount
== 1) {
845 snd_soc_update_bits(codec
, WM8994_ANTIPOP_1
,
846 WM8994_LINEOUT1_DISCH
|
847 WM8994_LINEOUT2_DISCH
, 0);
849 wm_hubs_vmid_ena(codec
);
851 switch (wm8994
->vmid_mode
) {
853 WARN_ON(NULL
== "Invalid VMID mode");
854 case WM8994_VMID_NORMAL
:
855 /* Startup bias, VMID ramp & buffer */
856 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
859 WM8994_STARTUP_BIAS_ENA
|
860 WM8994_VMID_BUF_ENA
|
861 WM8994_VMID_RAMP_MASK
,
863 WM8994_STARTUP_BIAS_ENA
|
864 WM8994_VMID_BUF_ENA
|
865 (0x2 << WM8994_VMID_RAMP_SHIFT
));
867 /* Main bias enable, VMID=2x40k */
868 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_1
,
870 WM8994_VMID_SEL_MASK
,
871 WM8994_BIAS_ENA
| 0x2);
875 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
876 WM8994_VMID_RAMP_MASK
|
881 case WM8994_VMID_FORCE
:
882 /* Startup bias, slow VMID ramp & buffer */
883 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
886 WM8994_STARTUP_BIAS_ENA
|
887 WM8994_VMID_BUF_ENA
|
888 WM8994_VMID_RAMP_MASK
,
890 WM8994_STARTUP_BIAS_ENA
|
891 WM8994_VMID_BUF_ENA
|
892 (0x2 << WM8994_VMID_RAMP_SHIFT
));
894 /* Main bias enable, VMID=2x40k */
895 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_1
,
897 WM8994_VMID_SEL_MASK
,
898 WM8994_BIAS_ENA
| 0x2);
902 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
903 WM8994_VMID_RAMP_MASK
|
911 static void vmid_dereference(struct snd_soc_codec
*codec
)
913 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
915 wm8994
->vmid_refcount
--;
917 dev_dbg(codec
->dev
, "Dereferencing VMID, refcount is now %d\n",
918 wm8994
->vmid_refcount
);
920 if (wm8994
->vmid_refcount
== 0) {
921 if (wm8994
->hubs
.lineout1_se
)
922 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_3
,
923 WM8994_LINEOUT1N_ENA
|
924 WM8994_LINEOUT1P_ENA
,
925 WM8994_LINEOUT1N_ENA
|
926 WM8994_LINEOUT1P_ENA
);
928 if (wm8994
->hubs
.lineout2_se
)
929 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_3
,
930 WM8994_LINEOUT2N_ENA
|
931 WM8994_LINEOUT2P_ENA
,
932 WM8994_LINEOUT2N_ENA
|
933 WM8994_LINEOUT2P_ENA
);
935 /* Start discharging VMID */
936 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
942 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_1
,
943 WM8994_VMID_SEL_MASK
, 0);
947 /* Active discharge */
948 snd_soc_update_bits(codec
, WM8994_ANTIPOP_1
,
949 WM8994_LINEOUT1_DISCH
|
950 WM8994_LINEOUT2_DISCH
,
951 WM8994_LINEOUT1_DISCH
|
952 WM8994_LINEOUT2_DISCH
);
954 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_3
,
955 WM8994_LINEOUT1N_ENA
|
956 WM8994_LINEOUT1P_ENA
|
957 WM8994_LINEOUT2N_ENA
|
958 WM8994_LINEOUT2P_ENA
, 0);
960 /* Switch off startup biases */
961 snd_soc_update_bits(codec
, WM8994_ANTIPOP_2
,
963 WM8994_STARTUP_BIAS_ENA
|
964 WM8994_VMID_BUF_ENA
|
965 WM8994_VMID_RAMP_MASK
, 0);
967 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_1
,
968 WM8994_VMID_SEL_MASK
, 0);
971 pm_runtime_put(codec
->dev
);
974 static int vmid_event(struct snd_soc_dapm_widget
*w
,
975 struct snd_kcontrol
*kcontrol
, int event
)
977 struct snd_soc_codec
*codec
= w
->codec
;
980 case SND_SOC_DAPM_PRE_PMU
:
981 vmid_reference(codec
);
984 case SND_SOC_DAPM_POST_PMD
:
985 vmid_dereference(codec
);
992 static bool wm8994_check_class_w_digital(struct snd_soc_codec
*codec
)
994 int source
= 0; /* GCC flow analysis can't track enable */
997 /* We also need the same AIF source for L/R and only one path */
998 reg
= snd_soc_read(codec
, WM8994_DAC1_LEFT_MIXER_ROUTING
);
1000 case WM8994_AIF2DACL_TO_DAC1L
:
1001 dev_vdbg(codec
->dev
, "Class W source AIF2DAC\n");
1002 source
= 2 << WM8994_CP_DYN_SRC_SEL_SHIFT
;
1004 case WM8994_AIF1DAC2L_TO_DAC1L
:
1005 dev_vdbg(codec
->dev
, "Class W source AIF1DAC2\n");
1006 source
= 1 << WM8994_CP_DYN_SRC_SEL_SHIFT
;
1008 case WM8994_AIF1DAC1L_TO_DAC1L
:
1009 dev_vdbg(codec
->dev
, "Class W source AIF1DAC1\n");
1010 source
= 0 << WM8994_CP_DYN_SRC_SEL_SHIFT
;
1013 dev_vdbg(codec
->dev
, "DAC mixer setting: %x\n", reg
);
1017 reg_r
= snd_soc_read(codec
, WM8994_DAC1_RIGHT_MIXER_ROUTING
);
1019 dev_vdbg(codec
->dev
, "Left and right DAC mixers different\n");
1023 /* Set the source up */
1024 snd_soc_update_bits(codec
, WM8994_CLASS_W_1
,
1025 WM8994_CP_DYN_SRC_SEL_MASK
, source
);
1030 static int aif1clk_ev(struct snd_soc_dapm_widget
*w
,
1031 struct snd_kcontrol
*kcontrol
, int event
)
1033 struct snd_soc_codec
*codec
= w
->codec
;
1034 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
1035 struct wm8994
*control
= codec
->control_data
;
1036 int mask
= WM8994_AIF1DAC1L_ENA
| WM8994_AIF1DAC1R_ENA
;
1042 switch (control
->type
) {
1045 mask
|= WM8994_AIF1DAC2L_ENA
| WM8994_AIF1DAC2R_ENA
;
1052 case SND_SOC_DAPM_PRE_PMU
:
1053 /* Don't enable timeslot 2 if not in use */
1054 if (wm8994
->channels
[0] <= 2)
1055 mask
&= ~(WM8994_AIF1DAC2L_ENA
| WM8994_AIF1DAC2R_ENA
);
1057 val
= snd_soc_read(codec
, WM8994_AIF1_CONTROL_1
);
1058 if ((val
& WM8994_AIF1ADCL_SRC
) &&
1059 (val
& WM8994_AIF1ADCR_SRC
))
1060 adc
= WM8994_AIF1ADC1R_ENA
| WM8994_AIF1ADC2R_ENA
;
1061 else if (!(val
& WM8994_AIF1ADCL_SRC
) &&
1062 !(val
& WM8994_AIF1ADCR_SRC
))
1063 adc
= WM8994_AIF1ADC1L_ENA
| WM8994_AIF1ADC2L_ENA
;
1065 adc
= WM8994_AIF1ADC1R_ENA
| WM8994_AIF1ADC2R_ENA
|
1066 WM8994_AIF1ADC1L_ENA
| WM8994_AIF1ADC2L_ENA
;
1068 val
= snd_soc_read(codec
, WM8994_AIF1_CONTROL_2
);
1069 if ((val
& WM8994_AIF1DACL_SRC
) &&
1070 (val
& WM8994_AIF1DACR_SRC
))
1071 dac
= WM8994_AIF1DAC1R_ENA
| WM8994_AIF1DAC2R_ENA
;
1072 else if (!(val
& WM8994_AIF1DACL_SRC
) &&
1073 !(val
& WM8994_AIF1DACR_SRC
))
1074 dac
= WM8994_AIF1DAC1L_ENA
| WM8994_AIF1DAC2L_ENA
;
1076 dac
= WM8994_AIF1DAC1R_ENA
| WM8994_AIF1DAC2R_ENA
|
1077 WM8994_AIF1DAC1L_ENA
| WM8994_AIF1DAC2L_ENA
;
1079 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
,
1081 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1083 snd_soc_update_bits(codec
, WM8994_CLOCKING_1
,
1084 WM8994_AIF1DSPCLK_ENA
|
1085 WM8994_SYSDSPCLK_ENA
,
1086 WM8994_AIF1DSPCLK_ENA
|
1087 WM8994_SYSDSPCLK_ENA
);
1088 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
, mask
,
1089 WM8994_AIF1ADC1R_ENA
|
1090 WM8994_AIF1ADC1L_ENA
|
1091 WM8994_AIF1ADC2R_ENA
|
1092 WM8994_AIF1ADC2L_ENA
);
1093 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
, mask
,
1094 WM8994_AIF1DAC1R_ENA
|
1095 WM8994_AIF1DAC1L_ENA
|
1096 WM8994_AIF1DAC2R_ENA
|
1097 WM8994_AIF1DAC2L_ENA
);
1100 case SND_SOC_DAPM_POST_PMU
:
1101 for (i
= 0; i
< ARRAY_SIZE(wm8994_vu_bits
); i
++)
1102 snd_soc_write(codec
, wm8994_vu_bits
[i
].reg
,
1104 wm8994_vu_bits
[i
].reg
));
1107 case SND_SOC_DAPM_PRE_PMD
:
1108 case SND_SOC_DAPM_POST_PMD
:
1109 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1111 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
,
1114 val
= snd_soc_read(codec
, WM8994_CLOCKING_1
);
1115 if (val
& WM8994_AIF2DSPCLK_ENA
)
1116 val
= WM8994_SYSDSPCLK_ENA
;
1119 snd_soc_update_bits(codec
, WM8994_CLOCKING_1
,
1120 WM8994_SYSDSPCLK_ENA
|
1121 WM8994_AIF1DSPCLK_ENA
, val
);
1128 static int aif2clk_ev(struct snd_soc_dapm_widget
*w
,
1129 struct snd_kcontrol
*kcontrol
, int event
)
1131 struct snd_soc_codec
*codec
= w
->codec
;
1138 case SND_SOC_DAPM_PRE_PMU
:
1139 val
= snd_soc_read(codec
, WM8994_AIF2_CONTROL_1
);
1140 if ((val
& WM8994_AIF2ADCL_SRC
) &&
1141 (val
& WM8994_AIF2ADCR_SRC
))
1142 adc
= WM8994_AIF2ADCR_ENA
;
1143 else if (!(val
& WM8994_AIF2ADCL_SRC
) &&
1144 !(val
& WM8994_AIF2ADCR_SRC
))
1145 adc
= WM8994_AIF2ADCL_ENA
;
1147 adc
= WM8994_AIF2ADCL_ENA
| WM8994_AIF2ADCR_ENA
;
1150 val
= snd_soc_read(codec
, WM8994_AIF2_CONTROL_2
);
1151 if ((val
& WM8994_AIF2DACL_SRC
) &&
1152 (val
& WM8994_AIF2DACR_SRC
))
1153 dac
= WM8994_AIF2DACR_ENA
;
1154 else if (!(val
& WM8994_AIF2DACL_SRC
) &&
1155 !(val
& WM8994_AIF2DACR_SRC
))
1156 dac
= WM8994_AIF2DACL_ENA
;
1158 dac
= WM8994_AIF2DACL_ENA
| WM8994_AIF2DACR_ENA
;
1160 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
,
1161 WM8994_AIF2ADCL_ENA
|
1162 WM8994_AIF2ADCR_ENA
, adc
);
1163 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1164 WM8994_AIF2DACL_ENA
|
1165 WM8994_AIF2DACR_ENA
, dac
);
1166 snd_soc_update_bits(codec
, WM8994_CLOCKING_1
,
1167 WM8994_AIF2DSPCLK_ENA
|
1168 WM8994_SYSDSPCLK_ENA
,
1169 WM8994_AIF2DSPCLK_ENA
|
1170 WM8994_SYSDSPCLK_ENA
);
1171 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
,
1172 WM8994_AIF2ADCL_ENA
|
1173 WM8994_AIF2ADCR_ENA
,
1174 WM8994_AIF2ADCL_ENA
|
1175 WM8994_AIF2ADCR_ENA
);
1176 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1177 WM8994_AIF2DACL_ENA
|
1178 WM8994_AIF2DACR_ENA
,
1179 WM8994_AIF2DACL_ENA
|
1180 WM8994_AIF2DACR_ENA
);
1183 case SND_SOC_DAPM_POST_PMU
:
1184 for (i
= 0; i
< ARRAY_SIZE(wm8994_vu_bits
); i
++)
1185 snd_soc_write(codec
, wm8994_vu_bits
[i
].reg
,
1187 wm8994_vu_bits
[i
].reg
));
1190 case SND_SOC_DAPM_PRE_PMD
:
1191 case SND_SOC_DAPM_POST_PMD
:
1192 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1193 WM8994_AIF2DACL_ENA
|
1194 WM8994_AIF2DACR_ENA
, 0);
1195 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_4
,
1196 WM8994_AIF2ADCL_ENA
|
1197 WM8994_AIF2ADCR_ENA
, 0);
1199 val
= snd_soc_read(codec
, WM8994_CLOCKING_1
);
1200 if (val
& WM8994_AIF1DSPCLK_ENA
)
1201 val
= WM8994_SYSDSPCLK_ENA
;
1204 snd_soc_update_bits(codec
, WM8994_CLOCKING_1
,
1205 WM8994_SYSDSPCLK_ENA
|
1206 WM8994_AIF2DSPCLK_ENA
, val
);
1213 static int aif1clk_late_ev(struct snd_soc_dapm_widget
*w
,
1214 struct snd_kcontrol
*kcontrol
, int event
)
1216 struct snd_soc_codec
*codec
= w
->codec
;
1217 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
1220 case SND_SOC_DAPM_PRE_PMU
:
1221 wm8994
->aif1clk_enable
= 1;
1223 case SND_SOC_DAPM_POST_PMD
:
1224 wm8994
->aif1clk_disable
= 1;
1231 static int aif2clk_late_ev(struct snd_soc_dapm_widget
*w
,
1232 struct snd_kcontrol
*kcontrol
, int event
)
1234 struct snd_soc_codec
*codec
= w
->codec
;
1235 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
1238 case SND_SOC_DAPM_PRE_PMU
:
1239 wm8994
->aif2clk_enable
= 1;
1241 case SND_SOC_DAPM_POST_PMD
:
1242 wm8994
->aif2clk_disable
= 1;
1249 static int late_enable_ev(struct snd_soc_dapm_widget
*w
,
1250 struct snd_kcontrol
*kcontrol
, int event
)
1252 struct snd_soc_codec
*codec
= w
->codec
;
1253 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
1256 case SND_SOC_DAPM_PRE_PMU
:
1257 if (wm8994
->aif1clk_enable
) {
1258 aif1clk_ev(w
, kcontrol
, SND_SOC_DAPM_PRE_PMU
);
1259 snd_soc_update_bits(codec
, WM8994_AIF1_CLOCKING_1
,
1260 WM8994_AIF1CLK_ENA_MASK
,
1261 WM8994_AIF1CLK_ENA
);
1262 aif1clk_ev(w
, kcontrol
, SND_SOC_DAPM_POST_PMU
);
1263 wm8994
->aif1clk_enable
= 0;
1265 if (wm8994
->aif2clk_enable
) {
1266 aif2clk_ev(w
, kcontrol
, SND_SOC_DAPM_PRE_PMU
);
1267 snd_soc_update_bits(codec
, WM8994_AIF2_CLOCKING_1
,
1268 WM8994_AIF2CLK_ENA_MASK
,
1269 WM8994_AIF2CLK_ENA
);
1270 aif2clk_ev(w
, kcontrol
, SND_SOC_DAPM_POST_PMU
);
1271 wm8994
->aif2clk_enable
= 0;
1276 /* We may also have postponed startup of DSP, handle that. */
1277 wm8958_aif_ev(w
, kcontrol
, event
);
1282 static int late_disable_ev(struct snd_soc_dapm_widget
*w
,
1283 struct snd_kcontrol
*kcontrol
, int event
)
1285 struct snd_soc_codec
*codec
= w
->codec
;
1286 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
1289 case SND_SOC_DAPM_POST_PMD
:
1290 if (wm8994
->aif1clk_disable
) {
1291 aif1clk_ev(w
, kcontrol
, SND_SOC_DAPM_PRE_PMD
);
1292 snd_soc_update_bits(codec
, WM8994_AIF1_CLOCKING_1
,
1293 WM8994_AIF1CLK_ENA_MASK
, 0);
1294 aif1clk_ev(w
, kcontrol
, SND_SOC_DAPM_POST_PMD
);
1295 wm8994
->aif1clk_disable
= 0;
1297 if (wm8994
->aif2clk_disable
) {
1298 aif2clk_ev(w
, kcontrol
, SND_SOC_DAPM_PRE_PMD
);
1299 snd_soc_update_bits(codec
, WM8994_AIF2_CLOCKING_1
,
1300 WM8994_AIF2CLK_ENA_MASK
, 0);
1301 aif2clk_ev(w
, kcontrol
, SND_SOC_DAPM_POST_PMD
);
1302 wm8994
->aif2clk_disable
= 0;
1310 static int adc_mux_ev(struct snd_soc_dapm_widget
*w
,
1311 struct snd_kcontrol
*kcontrol
, int event
)
1313 late_enable_ev(w
, kcontrol
, event
);
1317 static int micbias_ev(struct snd_soc_dapm_widget
*w
,
1318 struct snd_kcontrol
*kcontrol
, int event
)
1320 late_enable_ev(w
, kcontrol
, event
);
1324 static int dac_ev(struct snd_soc_dapm_widget
*w
,
1325 struct snd_kcontrol
*kcontrol
, int event
)
1327 struct snd_soc_codec
*codec
= w
->codec
;
1328 unsigned int mask
= 1 << w
->shift
;
1330 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_5
,
1335 static const char *adc_mux_text
[] = {
1340 static const struct soc_enum adc_enum
=
1341 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text
);
1343 static const struct snd_kcontrol_new adcl_mux
=
1344 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum
);
1346 static const struct snd_kcontrol_new adcr_mux
=
1347 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum
);
1349 static const struct snd_kcontrol_new left_speaker_mixer
[] = {
1350 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER
, 9, 1, 0),
1351 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER
, 7, 1, 0),
1352 SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER
, 5, 1, 0),
1353 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER
, 3, 1, 0),
1354 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER
, 1, 1, 0),
1357 static const struct snd_kcontrol_new right_speaker_mixer
[] = {
1358 SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER
, 8, 1, 0),
1359 SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER
, 6, 1, 0),
1360 SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER
, 4, 1, 0),
1361 SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER
, 2, 1, 0),
1362 SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER
, 0, 1, 0),
1365 /* Debugging; dump chip status after DAPM transitions */
1366 static int post_ev(struct snd_soc_dapm_widget
*w
,
1367 struct snd_kcontrol
*kcontrol
, int event
)
1369 struct snd_soc_codec
*codec
= w
->codec
;
1370 dev_dbg(codec
->dev
, "SRC status: %x\n",
1372 WM8994_RATE_STATUS
));
1376 static const struct snd_kcontrol_new aif1adc1l_mix
[] = {
1377 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING
,
1379 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING
,
1383 static const struct snd_kcontrol_new aif1adc1r_mix
[] = {
1384 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
1386 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
1390 static const struct snd_kcontrol_new aif1adc2l_mix
[] = {
1391 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING
,
1393 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING
,
1397 static const struct snd_kcontrol_new aif1adc2r_mix
[] = {
1398 SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
1400 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
1404 static const struct snd_kcontrol_new aif2dac2l_mix
[] = {
1405 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING
,
1407 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING
,
1409 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING
,
1411 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING
,
1413 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING
,
1417 static const struct snd_kcontrol_new aif2dac2r_mix
[] = {
1418 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING
,
1420 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING
,
1422 SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING
,
1424 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING
,
1426 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING
,
1430 #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1431 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1432 .info = snd_soc_info_volsw, \
1433 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1434 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1436 static int wm8994_put_class_w(struct snd_kcontrol
*kcontrol
,
1437 struct snd_ctl_elem_value
*ucontrol
)
1439 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1440 struct snd_soc_dapm_widget
*w
= wlist
->widgets
[0];
1441 struct snd_soc_codec
*codec
= w
->codec
;
1444 ret
= snd_soc_dapm_put_volsw(kcontrol
, ucontrol
);
1446 wm_hubs_update_class_w(codec
);
1451 static const struct snd_kcontrol_new dac1l_mix
[] = {
1452 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING
,
1454 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING
,
1456 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING
,
1458 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING
,
1460 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING
,
1464 static const struct snd_kcontrol_new dac1r_mix
[] = {
1465 WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING
,
1467 WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING
,
1469 WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING
,
1471 WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING
,
1473 WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING
,
1477 static const char *sidetone_text
[] = {
1478 "ADC/DMIC1", "DMIC2",
1481 static const struct soc_enum sidetone1_enum
=
1482 SOC_ENUM_SINGLE(WM8994_SIDETONE
, 0, 2, sidetone_text
);
1484 static const struct snd_kcontrol_new sidetone1_mux
=
1485 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum
);
1487 static const struct soc_enum sidetone2_enum
=
1488 SOC_ENUM_SINGLE(WM8994_SIDETONE
, 1, 2, sidetone_text
);
1490 static const struct snd_kcontrol_new sidetone2_mux
=
1491 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum
);
1493 static const char *aif1dac_text
[] = {
1494 "AIF1DACDAT", "AIF3DACDAT",
1497 static const char *loopback_text
[] = {
1501 static const struct soc_enum aif1_loopback_enum
=
1502 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2
, WM8994_AIF1_LOOPBACK_SHIFT
, 2,
1505 static const struct snd_kcontrol_new aif1_loopback
=
1506 SOC_DAPM_ENUM("AIF1 Loopback", aif1_loopback_enum
);
1508 static const struct soc_enum aif2_loopback_enum
=
1509 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2
, WM8994_AIF2_LOOPBACK_SHIFT
, 2,
1512 static const struct snd_kcontrol_new aif2_loopback
=
1513 SOC_DAPM_ENUM("AIF2 Loopback", aif2_loopback_enum
);
1515 static const struct soc_enum aif1dac_enum
=
1516 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 0, 2, aif1dac_text
);
1518 static const struct snd_kcontrol_new aif1dac_mux
=
1519 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum
);
1521 static const char *aif2dac_text
[] = {
1522 "AIF2DACDAT", "AIF3DACDAT",
1525 static const struct soc_enum aif2dac_enum
=
1526 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 1, 2, aif2dac_text
);
1528 static const struct snd_kcontrol_new aif2dac_mux
=
1529 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum
);
1531 static const char *aif2adc_text
[] = {
1532 "AIF2ADCDAT", "AIF3DACDAT",
1535 static const struct soc_enum aif2adc_enum
=
1536 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 2, 2, aif2adc_text
);
1538 static const struct snd_kcontrol_new aif2adc_mux
=
1539 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum
);
1541 static const char *aif3adc_text
[] = {
1542 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
1545 static const struct soc_enum wm8994_aif3adc_enum
=
1546 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 3, 3, aif3adc_text
);
1548 static const struct snd_kcontrol_new wm8994_aif3adc_mux
=
1549 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum
);
1551 static const struct soc_enum wm8958_aif3adc_enum
=
1552 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 3, 4, aif3adc_text
);
1554 static const struct snd_kcontrol_new wm8958_aif3adc_mux
=
1555 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum
);
1557 static const char *mono_pcm_out_text
[] = {
1558 "None", "AIF2ADCL", "AIF2ADCR",
1561 static const struct soc_enum mono_pcm_out_enum
=
1562 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 9, 3, mono_pcm_out_text
);
1564 static const struct snd_kcontrol_new mono_pcm_out_mux
=
1565 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum
);
1567 static const char *aif2dac_src_text
[] = {
1571 /* Note that these two control shouldn't be simultaneously switched to AIF3 */
1572 static const struct soc_enum aif2dacl_src_enum
=
1573 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 7, 2, aif2dac_src_text
);
1575 static const struct snd_kcontrol_new aif2dacl_src_mux
=
1576 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum
);
1578 static const struct soc_enum aif2dacr_src_enum
=
1579 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6
, 8, 2, aif2dac_src_text
);
1581 static const struct snd_kcontrol_new aif2dacr_src_mux
=
1582 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum
);
1584 static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets
[] = {
1585 SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM
, 0, 0, aif1clk_late_ev
,
1586 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
1587 SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM
, 0, 0, aif2clk_late_ev
,
1588 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
1590 SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1591 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1592 SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1593 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1594 SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1595 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1596 SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1597 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1598 SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1599 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1601 SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3
, 8, 0,
1602 left_speaker_mixer
, ARRAY_SIZE(left_speaker_mixer
),
1603 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1604 SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3
, 9, 0,
1605 right_speaker_mixer
, ARRAY_SIZE(right_speaker_mixer
),
1606 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1607 SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM
, 0, 0, &wm_hubs_hpl_mux
,
1608 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1609 SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM
, 0, 0, &wm_hubs_hpr_mux
,
1610 late_enable_ev
, SND_SOC_DAPM_PRE_PMU
),
1612 SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev
)
1615 static const struct snd_soc_dapm_widget wm8994_lateclk_widgets
[] = {
1616 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1
, 0, 0, aif1clk_ev
,
1617 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1618 SND_SOC_DAPM_PRE_PMD
),
1619 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1
, 0, 0, aif2clk_ev
,
1620 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1621 SND_SOC_DAPM_PRE_PMD
),
1622 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1623 SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3
, 8, 0,
1624 left_speaker_mixer
, ARRAY_SIZE(left_speaker_mixer
)),
1625 SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3
, 9, 0,
1626 right_speaker_mixer
, ARRAY_SIZE(right_speaker_mixer
)),
1627 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM
, 0, 0, &wm_hubs_hpl_mux
),
1628 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM
, 0, 0, &wm_hubs_hpr_mux
),
1631 static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets
[] = {
1632 SND_SOC_DAPM_DAC_E("DAC2L", NULL
, SND_SOC_NOPM
, 3, 0,
1633 dac_ev
, SND_SOC_DAPM_PRE_PMU
),
1634 SND_SOC_DAPM_DAC_E("DAC2R", NULL
, SND_SOC_NOPM
, 2, 0,
1635 dac_ev
, SND_SOC_DAPM_PRE_PMU
),
1636 SND_SOC_DAPM_DAC_E("DAC1L", NULL
, SND_SOC_NOPM
, 1, 0,
1637 dac_ev
, SND_SOC_DAPM_PRE_PMU
),
1638 SND_SOC_DAPM_DAC_E("DAC1R", NULL
, SND_SOC_NOPM
, 0, 0,
1639 dac_ev
, SND_SOC_DAPM_PRE_PMU
),
1642 static const struct snd_soc_dapm_widget wm8994_dac_widgets
[] = {
1643 SND_SOC_DAPM_DAC("DAC2L", NULL
, WM8994_POWER_MANAGEMENT_5
, 3, 0),
1644 SND_SOC_DAPM_DAC("DAC2R", NULL
, WM8994_POWER_MANAGEMENT_5
, 2, 0),
1645 SND_SOC_DAPM_DAC("DAC1L", NULL
, WM8994_POWER_MANAGEMENT_5
, 1, 0),
1646 SND_SOC_DAPM_DAC("DAC1R", NULL
, WM8994_POWER_MANAGEMENT_5
, 0, 0),
1649 static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets
[] = {
1650 SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4
, 1, 0, &adcl_mux
,
1651 adc_mux_ev
, SND_SOC_DAPM_PRE_PMU
),
1652 SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4
, 0, 0, &adcr_mux
,
1653 adc_mux_ev
, SND_SOC_DAPM_PRE_PMU
),
1656 static const struct snd_soc_dapm_widget wm8994_adc_widgets
[] = {
1657 SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4
, 1, 0, &adcl_mux
),
1658 SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4
, 0, 0, &adcr_mux
),
1661 static const struct snd_soc_dapm_widget wm8994_dapm_widgets
[] = {
1662 SND_SOC_DAPM_INPUT("DMIC1DAT"),
1663 SND_SOC_DAPM_INPUT("DMIC2DAT"),
1664 SND_SOC_DAPM_INPUT("Clock"),
1666 SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM
, 0, 0, micbias_ev
,
1667 SND_SOC_DAPM_PRE_PMU
),
1668 SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM
, 0, 0, vmid_event
,
1669 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
1671 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM
, 0, 0, clk_sys_event
,
1672 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1673 SND_SOC_DAPM_PRE_PMD
),
1675 SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM
, 3, 0, NULL
, 0),
1676 SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM
, 2, 0, NULL
, 0),
1677 SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM
, 1, 0, NULL
, 0),
1679 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL
,
1680 0, SND_SOC_NOPM
, 9, 0),
1681 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL
,
1682 0, SND_SOC_NOPM
, 8, 0),
1683 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL
, 0,
1684 SND_SOC_NOPM
, 9, 0, wm8958_aif_ev
,
1685 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1686 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL
, 0,
1687 SND_SOC_NOPM
, 8, 0, wm8958_aif_ev
,
1688 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1690 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL
,
1691 0, SND_SOC_NOPM
, 11, 0),
1692 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL
,
1693 0, SND_SOC_NOPM
, 10, 0),
1694 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL
, 0,
1695 SND_SOC_NOPM
, 11, 0, wm8958_aif_ev
,
1696 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1697 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL
, 0,
1698 SND_SOC_NOPM
, 10, 0, wm8958_aif_ev
,
1699 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1701 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM
, 0, 0,
1702 aif1adc1l_mix
, ARRAY_SIZE(aif1adc1l_mix
)),
1703 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM
, 0, 0,
1704 aif1adc1r_mix
, ARRAY_SIZE(aif1adc1r_mix
)),
1706 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM
, 0, 0,
1707 aif1adc2l_mix
, ARRAY_SIZE(aif1adc2l_mix
)),
1708 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM
, 0, 0,
1709 aif1adc2r_mix
, ARRAY_SIZE(aif1adc2r_mix
)),
1711 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM
, 0, 0,
1712 aif2dac2l_mix
, ARRAY_SIZE(aif2dac2l_mix
)),
1713 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM
, 0, 0,
1714 aif2dac2r_mix
, ARRAY_SIZE(aif2dac2r_mix
)),
1716 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone1_mux
),
1717 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone2_mux
),
1719 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM
, 0, 0,
1720 dac1l_mix
, ARRAY_SIZE(dac1l_mix
)),
1721 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM
, 0, 0,
1722 dac1r_mix
, ARRAY_SIZE(dac1r_mix
)),
1724 SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL
, 0,
1725 SND_SOC_NOPM
, 13, 0),
1726 SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL
, 0,
1727 SND_SOC_NOPM
, 12, 0),
1728 SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL
, 0,
1729 SND_SOC_NOPM
, 13, 0, wm8958_aif_ev
,
1730 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
1731 SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL
, 0,
1732 SND_SOC_NOPM
, 12, 0, wm8958_aif_ev
,
1733 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
1735 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1736 SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1737 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1738 SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1740 SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM
, 0, 0, &aif1dac_mux
),
1741 SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM
, 0, 0, &aif2dac_mux
),
1742 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM
, 0, 0, &aif2adc_mux
),
1744 SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1745 SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1747 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1
, 4, 0, NULL
, 0),
1749 SND_SOC_DAPM_ADC("DMIC2L", NULL
, WM8994_POWER_MANAGEMENT_4
, 5, 0),
1750 SND_SOC_DAPM_ADC("DMIC2R", NULL
, WM8994_POWER_MANAGEMENT_4
, 4, 0),
1751 SND_SOC_DAPM_ADC("DMIC1L", NULL
, WM8994_POWER_MANAGEMENT_4
, 3, 0),
1752 SND_SOC_DAPM_ADC("DMIC1R", NULL
, WM8994_POWER_MANAGEMENT_4
, 2, 0),
1754 /* Power is done with the muxes since the ADC power also controls the
1755 * downsampling chain, the chip will automatically manage the analogue
1756 * specific portions.
1758 SND_SOC_DAPM_ADC("ADCL", NULL
, SND_SOC_NOPM
, 1, 0),
1759 SND_SOC_DAPM_ADC("ADCR", NULL
, SND_SOC_NOPM
, 0, 0),
1761 SND_SOC_DAPM_MUX("AIF1 Loopback", SND_SOC_NOPM
, 0, 0, &aif1_loopback
),
1762 SND_SOC_DAPM_MUX("AIF2 Loopback", SND_SOC_NOPM
, 0, 0, &aif2_loopback
),
1764 SND_SOC_DAPM_POST("Debug log", post_ev
),
1767 static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets
[] = {
1768 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM
, 0, 0, &wm8994_aif3adc_mux
),
1771 static const struct snd_soc_dapm_widget wm8958_dapm_widgets
[] = {
1772 SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6
, 5, 1, NULL
, 0),
1773 SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM
, 0, 0, &mono_pcm_out_mux
),
1774 SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM
, 0, 0, &aif2dacl_src_mux
),
1775 SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM
, 0, 0, &aif2dacr_src_mux
),
1776 SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM
, 0, 0, &wm8958_aif3adc_mux
),
1779 static const struct snd_soc_dapm_route intercon
[] = {
1780 { "CLK_SYS", NULL
, "AIF1CLK", check_clk_sys
},
1781 { "CLK_SYS", NULL
, "AIF2CLK", check_clk_sys
},
1783 { "DSP1CLK", NULL
, "CLK_SYS" },
1784 { "DSP2CLK", NULL
, "CLK_SYS" },
1785 { "DSPINTCLK", NULL
, "CLK_SYS" },
1787 { "AIF1ADC1L", NULL
, "AIF1CLK" },
1788 { "AIF1ADC1L", NULL
, "DSP1CLK" },
1789 { "AIF1ADC1R", NULL
, "AIF1CLK" },
1790 { "AIF1ADC1R", NULL
, "DSP1CLK" },
1791 { "AIF1ADC1R", NULL
, "DSPINTCLK" },
1793 { "AIF1DAC1L", NULL
, "AIF1CLK" },
1794 { "AIF1DAC1L", NULL
, "DSP1CLK" },
1795 { "AIF1DAC1R", NULL
, "AIF1CLK" },
1796 { "AIF1DAC1R", NULL
, "DSP1CLK" },
1797 { "AIF1DAC1R", NULL
, "DSPINTCLK" },
1799 { "AIF1ADC2L", NULL
, "AIF1CLK" },
1800 { "AIF1ADC2L", NULL
, "DSP1CLK" },
1801 { "AIF1ADC2R", NULL
, "AIF1CLK" },
1802 { "AIF1ADC2R", NULL
, "DSP1CLK" },
1803 { "AIF1ADC2R", NULL
, "DSPINTCLK" },
1805 { "AIF1DAC2L", NULL
, "AIF1CLK" },
1806 { "AIF1DAC2L", NULL
, "DSP1CLK" },
1807 { "AIF1DAC2R", NULL
, "AIF1CLK" },
1808 { "AIF1DAC2R", NULL
, "DSP1CLK" },
1809 { "AIF1DAC2R", NULL
, "DSPINTCLK" },
1811 { "AIF2ADCL", NULL
, "AIF2CLK" },
1812 { "AIF2ADCL", NULL
, "DSP2CLK" },
1813 { "AIF2ADCR", NULL
, "AIF2CLK" },
1814 { "AIF2ADCR", NULL
, "DSP2CLK" },
1815 { "AIF2ADCR", NULL
, "DSPINTCLK" },
1817 { "AIF2DACL", NULL
, "AIF2CLK" },
1818 { "AIF2DACL", NULL
, "DSP2CLK" },
1819 { "AIF2DACR", NULL
, "AIF2CLK" },
1820 { "AIF2DACR", NULL
, "DSP2CLK" },
1821 { "AIF2DACR", NULL
, "DSPINTCLK" },
1823 { "DMIC1L", NULL
, "DMIC1DAT" },
1824 { "DMIC1L", NULL
, "CLK_SYS" },
1825 { "DMIC1R", NULL
, "DMIC1DAT" },
1826 { "DMIC1R", NULL
, "CLK_SYS" },
1827 { "DMIC2L", NULL
, "DMIC2DAT" },
1828 { "DMIC2L", NULL
, "CLK_SYS" },
1829 { "DMIC2R", NULL
, "DMIC2DAT" },
1830 { "DMIC2R", NULL
, "CLK_SYS" },
1832 { "ADCL", NULL
, "AIF1CLK" },
1833 { "ADCL", NULL
, "DSP1CLK" },
1834 { "ADCL", NULL
, "DSPINTCLK" },
1836 { "ADCR", NULL
, "AIF1CLK" },
1837 { "ADCR", NULL
, "DSP1CLK" },
1838 { "ADCR", NULL
, "DSPINTCLK" },
1840 { "ADCL Mux", "ADC", "ADCL" },
1841 { "ADCL Mux", "DMIC", "DMIC1L" },
1842 { "ADCR Mux", "ADC", "ADCR" },
1843 { "ADCR Mux", "DMIC", "DMIC1R" },
1845 { "DAC1L", NULL
, "AIF1CLK" },
1846 { "DAC1L", NULL
, "DSP1CLK" },
1847 { "DAC1L", NULL
, "DSPINTCLK" },
1849 { "DAC1R", NULL
, "AIF1CLK" },
1850 { "DAC1R", NULL
, "DSP1CLK" },
1851 { "DAC1R", NULL
, "DSPINTCLK" },
1853 { "DAC2L", NULL
, "AIF2CLK" },
1854 { "DAC2L", NULL
, "DSP2CLK" },
1855 { "DAC2L", NULL
, "DSPINTCLK" },
1857 { "DAC2R", NULL
, "AIF2DACR" },
1858 { "DAC2R", NULL
, "AIF2CLK" },
1859 { "DAC2R", NULL
, "DSP2CLK" },
1860 { "DAC2R", NULL
, "DSPINTCLK" },
1862 { "TOCLK", NULL
, "CLK_SYS" },
1864 { "AIF1DACDAT", NULL
, "AIF1 Playback" },
1865 { "AIF2DACDAT", NULL
, "AIF2 Playback" },
1866 { "AIF3DACDAT", NULL
, "AIF3 Playback" },
1868 { "AIF1 Capture", NULL
, "AIF1ADCDAT" },
1869 { "AIF2 Capture", NULL
, "AIF2ADCDAT" },
1870 { "AIF3 Capture", NULL
, "AIF3ADCDAT" },
1873 { "AIF1ADC1L", NULL
, "AIF1ADC1L Mixer" },
1874 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1875 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1877 { "AIF1ADC1R", NULL
, "AIF1ADC1R Mixer" },
1878 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1879 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1881 { "AIF1ADC2L", NULL
, "AIF1ADC2L Mixer" },
1882 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1883 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1885 { "AIF1ADC2R", NULL
, "AIF1ADC2R Mixer" },
1886 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1887 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1889 /* Pin level routing for AIF3 */
1890 { "AIF1DAC1L", NULL
, "AIF1DAC Mux" },
1891 { "AIF1DAC1R", NULL
, "AIF1DAC Mux" },
1892 { "AIF1DAC2L", NULL
, "AIF1DAC Mux" },
1893 { "AIF1DAC2R", NULL
, "AIF1DAC Mux" },
1895 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1 Loopback" },
1896 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1897 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2 Loopback" },
1898 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1899 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1900 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1901 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1904 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1905 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1906 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1907 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1908 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1910 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1911 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1912 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1913 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1914 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1916 /* DAC2/AIF2 outputs */
1917 { "AIF2ADCL", NULL
, "AIF2DAC2L Mixer" },
1918 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1919 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1920 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1921 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1922 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1924 { "AIF2ADCR", NULL
, "AIF2DAC2R Mixer" },
1925 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1926 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1927 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1928 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1929 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1931 { "AIF1ADCDAT", NULL
, "AIF1ADC1L" },
1932 { "AIF1ADCDAT", NULL
, "AIF1ADC1R" },
1933 { "AIF1ADCDAT", NULL
, "AIF1ADC2L" },
1934 { "AIF1ADCDAT", NULL
, "AIF1ADC2R" },
1936 { "AIF2ADCDAT", NULL
, "AIF2ADC Mux" },
1939 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1940 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1941 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1942 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1943 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1944 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1945 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1946 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1949 { "AIF1 Loopback", "ADCDAT", "AIF1ADCDAT" },
1950 { "AIF1 Loopback", "None", "AIF1DACDAT" },
1951 { "AIF2 Loopback", "ADCDAT", "AIF2ADCDAT" },
1952 { "AIF2 Loopback", "None", "AIF2DACDAT" },
1955 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1956 { "Left Sidetone", "DMIC2", "DMIC2L" },
1957 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1958 { "Right Sidetone", "DMIC2", "DMIC2R" },
1961 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1962 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1964 { "SPKL", "DAC1 Switch", "DAC1L" },
1965 { "SPKL", "DAC2 Switch", "DAC2L" },
1967 { "SPKR", "DAC1 Switch", "DAC1R" },
1968 { "SPKR", "DAC2 Switch", "DAC2R" },
1970 { "Left Headphone Mux", "DAC", "DAC1L" },
1971 { "Right Headphone Mux", "DAC", "DAC1R" },
1974 static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon
[] = {
1975 { "DAC1L", NULL
, "Late DAC1L Enable PGA" },
1976 { "Late DAC1L Enable PGA", NULL
, "DAC1L Mixer" },
1977 { "DAC1R", NULL
, "Late DAC1R Enable PGA" },
1978 { "Late DAC1R Enable PGA", NULL
, "DAC1R Mixer" },
1979 { "DAC2L", NULL
, "Late DAC2L Enable PGA" },
1980 { "Late DAC2L Enable PGA", NULL
, "AIF2DAC2L Mixer" },
1981 { "DAC2R", NULL
, "Late DAC2R Enable PGA" },
1982 { "Late DAC2R Enable PGA", NULL
, "AIF2DAC2R Mixer" }
1985 static const struct snd_soc_dapm_route wm8994_lateclk_intercon
[] = {
1986 { "DAC1L", NULL
, "DAC1L Mixer" },
1987 { "DAC1R", NULL
, "DAC1R Mixer" },
1988 { "DAC2L", NULL
, "AIF2DAC2L Mixer" },
1989 { "DAC2R", NULL
, "AIF2DAC2R Mixer" },
1992 static const struct snd_soc_dapm_route wm8994_revd_intercon
[] = {
1993 { "AIF1DACDAT", NULL
, "AIF2DACDAT" },
1994 { "AIF2DACDAT", NULL
, "AIF1DACDAT" },
1995 { "AIF1ADCDAT", NULL
, "AIF2ADCDAT" },
1996 { "AIF2ADCDAT", NULL
, "AIF1ADCDAT" },
1997 { "MICBIAS1", NULL
, "CLK_SYS" },
1998 { "MICBIAS1", NULL
, "MICBIAS Supply" },
1999 { "MICBIAS2", NULL
, "CLK_SYS" },
2000 { "MICBIAS2", NULL
, "MICBIAS Supply" },
2003 static const struct snd_soc_dapm_route wm8994_intercon
[] = {
2004 { "AIF2DACL", NULL
, "AIF2DAC Mux" },
2005 { "AIF2DACR", NULL
, "AIF2DAC Mux" },
2006 { "MICBIAS1", NULL
, "VMID" },
2007 { "MICBIAS2", NULL
, "VMID" },
2010 static const struct snd_soc_dapm_route wm8958_intercon
[] = {
2011 { "AIF2DACL", NULL
, "AIF2DACL Mux" },
2012 { "AIF2DACR", NULL
, "AIF2DACR Mux" },
2014 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
2015 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
2016 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
2017 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
2019 { "AIF3DACDAT", NULL
, "AIF3" },
2020 { "AIF3ADCDAT", NULL
, "AIF3" },
2022 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
2023 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
2025 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
2028 /* The size in bits of the FLL divide multiplied by 10
2029 * to allow rounding later */
2030 #define FIXED_FLL_SIZE ((1 << 16) * 10)
2041 static int wm8994_get_fll_config(struct wm8994
*control
, struct fll_div
*fll
,
2042 int freq_in
, int freq_out
)
2045 unsigned int K
, Ndiv
, Nmod
, gcd_fll
;
2047 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in
, freq_out
);
2049 /* Scale the input frequency down to <= 13.5MHz */
2050 fll
->clk_ref_div
= 0;
2051 while (freq_in
> 13500000) {
2055 if (fll
->clk_ref_div
> 3)
2058 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll
->clk_ref_div
, freq_in
);
2060 /* Scale the output to give 90MHz<=Fvco<=100MHz */
2062 while (freq_out
* (fll
->outdiv
+ 1) < 90000000) {
2064 if (fll
->outdiv
> 63)
2067 freq_out
*= fll
->outdiv
+ 1;
2068 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll
->outdiv
, freq_out
);
2070 if (freq_in
> 1000000) {
2071 fll
->fll_fratio
= 0;
2072 } else if (freq_in
> 256000) {
2073 fll
->fll_fratio
= 1;
2075 } else if (freq_in
> 128000) {
2076 fll
->fll_fratio
= 2;
2078 } else if (freq_in
> 64000) {
2079 fll
->fll_fratio
= 3;
2082 fll
->fll_fratio
= 4;
2085 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll
->fll_fratio
, freq_in
);
2087 /* Now, calculate N.K */
2088 Ndiv
= freq_out
/ freq_in
;
2091 Nmod
= freq_out
% freq_in
;
2092 pr_debug("Nmod=%d\n", Nmod
);
2094 switch (control
->type
) {
2096 /* Calculate fractional part - scale up so we can round. */
2097 Kpart
= FIXED_FLL_SIZE
* (long long)Nmod
;
2099 do_div(Kpart
, freq_in
);
2101 K
= Kpart
& 0xFFFFFFFF;
2106 /* Move down to proper range now rounding is done */
2110 pr_debug("N=%x K=%x\n", fll
->n
, fll
->k
);
2114 gcd_fll
= gcd(freq_out
, freq_in
);
2116 fll
->k
= (freq_out
- (freq_in
* fll
->n
)) / gcd_fll
;
2117 fll
->lambda
= freq_in
/ gcd_fll
;
2124 static int _wm8994_set_fll(struct snd_soc_codec
*codec
, int id
, int src
,
2125 unsigned int freq_in
, unsigned int freq_out
)
2127 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2128 struct wm8994
*control
= wm8994
->wm8994
;
2129 int reg_offset
, ret
;
2131 u16 reg
, clk1
, aif_reg
, aif_src
;
2132 unsigned long timeout
;
2150 reg
= snd_soc_read(codec
, WM8994_FLL1_CONTROL_1
+ reg_offset
);
2151 was_enabled
= reg
& WM8994_FLL1_ENA
;
2155 /* Allow no source specification when stopping */
2158 src
= wm8994
->fll
[id
].src
;
2160 case WM8994_FLL_SRC_MCLK1
:
2161 case WM8994_FLL_SRC_MCLK2
:
2162 case WM8994_FLL_SRC_LRCLK
:
2163 case WM8994_FLL_SRC_BCLK
:
2165 case WM8994_FLL_SRC_INTERNAL
:
2167 freq_out
= 12000000;
2173 /* Are we changing anything? */
2174 if (wm8994
->fll
[id
].src
== src
&&
2175 wm8994
->fll
[id
].in
== freq_in
&& wm8994
->fll
[id
].out
== freq_out
)
2178 /* If we're stopping the FLL redo the old config - no
2179 * registers will actually be written but we avoid GCC flow
2180 * analysis bugs spewing warnings.
2183 ret
= wm8994_get_fll_config(control
, &fll
, freq_in
, freq_out
);
2185 ret
= wm8994_get_fll_config(control
, &fll
, wm8994
->fll
[id
].in
,
2186 wm8994
->fll
[id
].out
);
2190 /* Make sure that we're not providing SYSCLK right now */
2191 clk1
= snd_soc_read(codec
, WM8994_CLOCKING_1
);
2192 if (clk1
& WM8994_SYSCLK_SRC
)
2193 aif_reg
= WM8994_AIF2_CLOCKING_1
;
2195 aif_reg
= WM8994_AIF1_CLOCKING_1
;
2196 reg
= snd_soc_read(codec
, aif_reg
);
2198 if ((reg
& WM8994_AIF1CLK_ENA
) &&
2199 (reg
& WM8994_AIF1CLK_SRC_MASK
) == aif_src
) {
2200 dev_err(codec
->dev
, "FLL%d is currently providing SYSCLK\n",
2205 /* We always need to disable the FLL while reconfiguring */
2206 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_1
+ reg_offset
,
2207 WM8994_FLL1_ENA
, 0);
2209 if (wm8994
->fll_byp
&& src
== WM8994_FLL_SRC_BCLK
&&
2210 freq_in
== freq_out
&& freq_out
) {
2211 dev_dbg(codec
->dev
, "Bypassing FLL%d\n", id
+ 1);
2212 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_5
+ reg_offset
,
2213 WM8958_FLL1_BYP
, WM8958_FLL1_BYP
);
2217 reg
= (fll
.outdiv
<< WM8994_FLL1_OUTDIV_SHIFT
) |
2218 (fll
.fll_fratio
<< WM8994_FLL1_FRATIO_SHIFT
);
2219 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_2
+ reg_offset
,
2220 WM8994_FLL1_OUTDIV_MASK
|
2221 WM8994_FLL1_FRATIO_MASK
, reg
);
2223 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_3
+ reg_offset
,
2224 WM8994_FLL1_K_MASK
, fll
.k
);
2226 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_4
+ reg_offset
,
2228 fll
.n
<< WM8994_FLL1_N_SHIFT
);
2231 snd_soc_update_bits(codec
, WM8958_FLL1_EFS_1
+ reg_offset
,
2232 WM8958_FLL1_LAMBDA_MASK
,
2234 snd_soc_update_bits(codec
, WM8958_FLL1_EFS_2
+ reg_offset
,
2235 WM8958_FLL1_EFS_ENA
, WM8958_FLL1_EFS_ENA
);
2237 snd_soc_update_bits(codec
, WM8958_FLL1_EFS_2
+ reg_offset
,
2238 WM8958_FLL1_EFS_ENA
, 0);
2241 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_5
+ reg_offset
,
2242 WM8994_FLL1_FRC_NCO
| WM8958_FLL1_BYP
|
2243 WM8994_FLL1_REFCLK_DIV_MASK
|
2244 WM8994_FLL1_REFCLK_SRC_MASK
,
2245 ((src
== WM8994_FLL_SRC_INTERNAL
)
2246 << WM8994_FLL1_FRC_NCO_SHIFT
) |
2247 (fll
.clk_ref_div
<< WM8994_FLL1_REFCLK_DIV_SHIFT
) |
2250 /* Clear any pending completion from a previous failure */
2251 try_wait_for_completion(&wm8994
->fll_locked
[id
]);
2253 /* Enable (with fractional mode if required) */
2255 /* Enable VMID if we need it */
2257 active_reference(codec
);
2259 switch (control
->type
) {
2261 vmid_reference(codec
);
2264 if (control
->revision
< 1)
2265 vmid_reference(codec
);
2272 reg
= WM8994_FLL1_ENA
;
2275 reg
|= WM8994_FLL1_FRAC
;
2276 if (src
== WM8994_FLL_SRC_INTERNAL
)
2277 reg
|= WM8994_FLL1_OSC_ENA
;
2279 snd_soc_update_bits(codec
, WM8994_FLL1_CONTROL_1
+ reg_offset
,
2280 WM8994_FLL1_ENA
| WM8994_FLL1_OSC_ENA
|
2281 WM8994_FLL1_FRAC
, reg
);
2283 if (wm8994
->fll_locked_irq
) {
2284 timeout
= wait_for_completion_timeout(&wm8994
->fll_locked
[id
],
2285 msecs_to_jiffies(10));
2287 dev_warn(codec
->dev
,
2288 "Timed out waiting for FLL lock\n");
2294 switch (control
->type
) {
2296 vmid_dereference(codec
);
2299 if (control
->revision
< 1)
2300 vmid_dereference(codec
);
2306 active_dereference(codec
);
2311 wm8994
->fll
[id
].in
= freq_in
;
2312 wm8994
->fll
[id
].out
= freq_out
;
2313 wm8994
->fll
[id
].src
= src
;
2315 configure_clock(codec
);
2318 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2321 if (max(wm8994
->aifclk
[0], wm8994
->aifclk
[1]) < 50000) {
2322 dev_dbg(codec
->dev
, "Configuring AIFs for 128fs\n");
2324 wm8994
->aifdiv
[0] = snd_soc_read(codec
, WM8994_AIF1_RATE
)
2325 & WM8994_AIF1CLK_RATE_MASK
;
2326 wm8994
->aifdiv
[1] = snd_soc_read(codec
, WM8994_AIF2_RATE
)
2327 & WM8994_AIF1CLK_RATE_MASK
;
2329 snd_soc_update_bits(codec
, WM8994_AIF1_RATE
,
2330 WM8994_AIF1CLK_RATE_MASK
, 0x1);
2331 snd_soc_update_bits(codec
, WM8994_AIF2_RATE
,
2332 WM8994_AIF2CLK_RATE_MASK
, 0x1);
2333 } else if (wm8994
->aifdiv
[0]) {
2334 snd_soc_update_bits(codec
, WM8994_AIF1_RATE
,
2335 WM8994_AIF1CLK_RATE_MASK
,
2337 snd_soc_update_bits(codec
, WM8994_AIF2_RATE
,
2338 WM8994_AIF2CLK_RATE_MASK
,
2341 wm8994
->aifdiv
[0] = 0;
2342 wm8994
->aifdiv
[1] = 0;
2348 static irqreturn_t
wm8994_fll_locked_irq(int irq
, void *data
)
2350 struct completion
*completion
= data
;
2352 complete(completion
);
2357 static int opclk_divs
[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
2359 static int wm8994_set_fll(struct snd_soc_dai
*dai
, int id
, int src
,
2360 unsigned int freq_in
, unsigned int freq_out
)
2362 return _wm8994_set_fll(dai
->codec
, id
, src
, freq_in
, freq_out
);
2365 static int wm8994_set_dai_sysclk(struct snd_soc_dai
*dai
,
2366 int clk_id
, unsigned int freq
, int dir
)
2368 struct snd_soc_codec
*codec
= dai
->codec
;
2369 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2378 /* AIF3 shares clocking with AIF1/2 */
2383 case WM8994_SYSCLK_MCLK1
:
2384 wm8994
->sysclk
[dai
->id
- 1] = WM8994_SYSCLK_MCLK1
;
2385 wm8994
->mclk
[0] = freq
;
2386 dev_dbg(dai
->dev
, "AIF%d using MCLK1 at %uHz\n",
2390 case WM8994_SYSCLK_MCLK2
:
2391 /* TODO: Set GPIO AF */
2392 wm8994
->sysclk
[dai
->id
- 1] = WM8994_SYSCLK_MCLK2
;
2393 wm8994
->mclk
[1] = freq
;
2394 dev_dbg(dai
->dev
, "AIF%d using MCLK2 at %uHz\n",
2398 case WM8994_SYSCLK_FLL1
:
2399 wm8994
->sysclk
[dai
->id
- 1] = WM8994_SYSCLK_FLL1
;
2400 dev_dbg(dai
->dev
, "AIF%d using FLL1\n", dai
->id
);
2403 case WM8994_SYSCLK_FLL2
:
2404 wm8994
->sysclk
[dai
->id
- 1] = WM8994_SYSCLK_FLL2
;
2405 dev_dbg(dai
->dev
, "AIF%d using FLL2\n", dai
->id
);
2408 case WM8994_SYSCLK_OPCLK
:
2409 /* Special case - a division (times 10) is given and
2410 * no effect on main clocking.
2413 for (i
= 0; i
< ARRAY_SIZE(opclk_divs
); i
++)
2414 if (opclk_divs
[i
] == freq
)
2416 if (i
== ARRAY_SIZE(opclk_divs
))
2418 snd_soc_update_bits(codec
, WM8994_CLOCKING_2
,
2419 WM8994_OPCLK_DIV_MASK
, i
);
2420 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_2
,
2421 WM8994_OPCLK_ENA
, WM8994_OPCLK_ENA
);
2423 snd_soc_update_bits(codec
, WM8994_POWER_MANAGEMENT_2
,
2424 WM8994_OPCLK_ENA
, 0);
2431 configure_clock(codec
);
2434 * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
2437 if (max(wm8994
->aifclk
[0], wm8994
->aifclk
[1]) < 50000) {
2438 dev_dbg(codec
->dev
, "Configuring AIFs for 128fs\n");
2440 wm8994
->aifdiv
[0] = snd_soc_read(codec
, WM8994_AIF1_RATE
)
2441 & WM8994_AIF1CLK_RATE_MASK
;
2442 wm8994
->aifdiv
[1] = snd_soc_read(codec
, WM8994_AIF2_RATE
)
2443 & WM8994_AIF1CLK_RATE_MASK
;
2445 snd_soc_update_bits(codec
, WM8994_AIF1_RATE
,
2446 WM8994_AIF1CLK_RATE_MASK
, 0x1);
2447 snd_soc_update_bits(codec
, WM8994_AIF2_RATE
,
2448 WM8994_AIF2CLK_RATE_MASK
, 0x1);
2449 } else if (wm8994
->aifdiv
[0]) {
2450 snd_soc_update_bits(codec
, WM8994_AIF1_RATE
,
2451 WM8994_AIF1CLK_RATE_MASK
,
2453 snd_soc_update_bits(codec
, WM8994_AIF2_RATE
,
2454 WM8994_AIF2CLK_RATE_MASK
,
2457 wm8994
->aifdiv
[0] = 0;
2458 wm8994
->aifdiv
[1] = 0;
2464 static int wm8994_set_bias_level(struct snd_soc_codec
*codec
,
2465 enum snd_soc_bias_level level
)
2467 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2468 struct wm8994
*control
= wm8994
->wm8994
;
2470 wm_hubs_set_bias_level(codec
, level
);
2473 case SND_SOC_BIAS_ON
:
2476 case SND_SOC_BIAS_PREPARE
:
2477 /* MICBIAS into regulating mode */
2478 switch (control
->type
) {
2481 snd_soc_update_bits(codec
, WM8958_MICBIAS1
,
2482 WM8958_MICB1_MODE
, 0);
2483 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
2484 WM8958_MICB2_MODE
, 0);
2490 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
2491 active_reference(codec
);
2494 case SND_SOC_BIAS_STANDBY
:
2495 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
2496 switch (control
->type
) {
2498 if (control
->revision
== 0) {
2499 /* Optimise performance for rev A */
2500 snd_soc_update_bits(codec
,
2501 WM8958_CHARGE_PUMP_2
,
2511 /* Discharge LINEOUT1 & 2 */
2512 snd_soc_update_bits(codec
, WM8994_ANTIPOP_1
,
2513 WM8994_LINEOUT1_DISCH
|
2514 WM8994_LINEOUT2_DISCH
,
2515 WM8994_LINEOUT1_DISCH
|
2516 WM8994_LINEOUT2_DISCH
);
2519 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_PREPARE
)
2520 active_dereference(codec
);
2522 /* MICBIAS into bypass mode on newer devices */
2523 switch (control
->type
) {
2526 snd_soc_update_bits(codec
, WM8958_MICBIAS1
,
2529 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
2538 case SND_SOC_BIAS_OFF
:
2539 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
2540 wm8994
->cur_fw
= NULL
;
2544 codec
->dapm
.bias_level
= level
;
2549 int wm8994_vmid_mode(struct snd_soc_codec
*codec
, enum wm8994_vmid_mode mode
)
2551 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2554 case WM8994_VMID_NORMAL
:
2555 if (wm8994
->hubs
.lineout1_se
) {
2556 snd_soc_dapm_disable_pin(&codec
->dapm
,
2557 "LINEOUT1N Driver");
2558 snd_soc_dapm_disable_pin(&codec
->dapm
,
2559 "LINEOUT1P Driver");
2561 if (wm8994
->hubs
.lineout2_se
) {
2562 snd_soc_dapm_disable_pin(&codec
->dapm
,
2563 "LINEOUT2N Driver");
2564 snd_soc_dapm_disable_pin(&codec
->dapm
,
2565 "LINEOUT2P Driver");
2568 /* Do the sync with the old mode to allow it to clean up */
2569 snd_soc_dapm_sync(&codec
->dapm
);
2570 wm8994
->vmid_mode
= mode
;
2573 case WM8994_VMID_FORCE
:
2574 if (wm8994
->hubs
.lineout1_se
) {
2575 snd_soc_dapm_force_enable_pin(&codec
->dapm
,
2576 "LINEOUT1N Driver");
2577 snd_soc_dapm_force_enable_pin(&codec
->dapm
,
2578 "LINEOUT1P Driver");
2580 if (wm8994
->hubs
.lineout2_se
) {
2581 snd_soc_dapm_force_enable_pin(&codec
->dapm
,
2582 "LINEOUT2N Driver");
2583 snd_soc_dapm_force_enable_pin(&codec
->dapm
,
2584 "LINEOUT2P Driver");
2587 wm8994
->vmid_mode
= mode
;
2588 snd_soc_dapm_sync(&codec
->dapm
);
2598 static int wm8994_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2600 struct snd_soc_codec
*codec
= dai
->codec
;
2601 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2602 struct wm8994
*control
= wm8994
->wm8994
;
2613 ms_reg
= WM8994_AIF1_MASTER_SLAVE
;
2614 aif1_reg
= WM8994_AIF1_CONTROL_1
;
2615 dac_reg
= WM8994_AIF1DAC_LRCLK
;
2616 adc_reg
= WM8994_AIF1ADC_LRCLK
;
2619 ms_reg
= WM8994_AIF2_MASTER_SLAVE
;
2620 aif1_reg
= WM8994_AIF2_CONTROL_1
;
2621 dac_reg
= WM8994_AIF1DAC_LRCLK
;
2622 adc_reg
= WM8994_AIF1ADC_LRCLK
;
2628 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2629 case SND_SOC_DAIFMT_CBS_CFS
:
2631 case SND_SOC_DAIFMT_CBM_CFM
:
2632 ms
= WM8994_AIF1_MSTR
;
2638 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2639 case SND_SOC_DAIFMT_DSP_B
:
2640 aif1
|= WM8994_AIF1_LRCLK_INV
;
2641 lrclk
|= WM8958_AIF1_LRCLK_INV
;
2642 case SND_SOC_DAIFMT_DSP_A
:
2645 case SND_SOC_DAIFMT_I2S
:
2648 case SND_SOC_DAIFMT_RIGHT_J
:
2650 case SND_SOC_DAIFMT_LEFT_J
:
2657 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2658 case SND_SOC_DAIFMT_DSP_A
:
2659 case SND_SOC_DAIFMT_DSP_B
:
2660 /* frame inversion not valid for DSP modes */
2661 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2662 case SND_SOC_DAIFMT_NB_NF
:
2664 case SND_SOC_DAIFMT_IB_NF
:
2665 aif1
|= WM8994_AIF1_BCLK_INV
;
2672 case SND_SOC_DAIFMT_I2S
:
2673 case SND_SOC_DAIFMT_RIGHT_J
:
2674 case SND_SOC_DAIFMT_LEFT_J
:
2675 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2676 case SND_SOC_DAIFMT_NB_NF
:
2678 case SND_SOC_DAIFMT_IB_IF
:
2679 aif1
|= WM8994_AIF1_BCLK_INV
| WM8994_AIF1_LRCLK_INV
;
2680 lrclk
|= WM8958_AIF1_LRCLK_INV
;
2682 case SND_SOC_DAIFMT_IB_NF
:
2683 aif1
|= WM8994_AIF1_BCLK_INV
;
2685 case SND_SOC_DAIFMT_NB_IF
:
2686 aif1
|= WM8994_AIF1_LRCLK_INV
;
2687 lrclk
|= WM8958_AIF1_LRCLK_INV
;
2697 /* The AIF2 format configuration needs to be mirrored to AIF3
2698 * on WM8958 if it's in use so just do it all the time. */
2699 switch (control
->type
) {
2703 snd_soc_update_bits(codec
, WM8958_AIF3_CONTROL_1
,
2704 WM8994_AIF1_LRCLK_INV
|
2705 WM8958_AIF3_FMT_MASK
, aif1
);
2712 snd_soc_update_bits(codec
, aif1_reg
,
2713 WM8994_AIF1_BCLK_INV
| WM8994_AIF1_LRCLK_INV
|
2714 WM8994_AIF1_FMT_MASK
,
2716 snd_soc_update_bits(codec
, ms_reg
, WM8994_AIF1_MSTR
,
2718 snd_soc_update_bits(codec
, dac_reg
,
2719 WM8958_AIF1_LRCLK_INV
, lrclk
);
2720 snd_soc_update_bits(codec
, adc_reg
,
2721 WM8958_AIF1_LRCLK_INV
, lrclk
);
2742 static int fs_ratios
[] = {
2743 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2746 static int bclk_divs
[] = {
2747 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2748 640, 880, 960, 1280, 1760, 1920
2751 static int wm8994_hw_params(struct snd_pcm_substream
*substream
,
2752 struct snd_pcm_hw_params
*params
,
2753 struct snd_soc_dai
*dai
)
2755 struct snd_soc_codec
*codec
= dai
->codec
;
2756 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2757 struct wm8994
*control
= wm8994
->wm8994
;
2758 struct wm8994_pdata
*pdata
= &control
->pdata
;
2769 int id
= dai
->id
- 1;
2771 int i
, cur_val
, best_val
, bclk_rate
, best
;
2775 aif1_reg
= WM8994_AIF1_CONTROL_1
;
2776 aif2_reg
= WM8994_AIF1_CONTROL_2
;
2777 bclk_reg
= WM8994_AIF1_BCLK
;
2778 rate_reg
= WM8994_AIF1_RATE
;
2779 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
||
2780 wm8994
->lrclk_shared
[0]) {
2781 lrclk_reg
= WM8994_AIF1DAC_LRCLK
;
2783 lrclk_reg
= WM8994_AIF1ADC_LRCLK
;
2784 dev_dbg(codec
->dev
, "AIF1 using split LRCLK\n");
2788 aif1_reg
= WM8994_AIF2_CONTROL_1
;
2789 aif2_reg
= WM8994_AIF2_CONTROL_2
;
2790 bclk_reg
= WM8994_AIF2_BCLK
;
2791 rate_reg
= WM8994_AIF2_RATE
;
2792 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
||
2793 wm8994
->lrclk_shared
[1]) {
2794 lrclk_reg
= WM8994_AIF2DAC_LRCLK
;
2796 lrclk_reg
= WM8994_AIF2ADC_LRCLK
;
2797 dev_dbg(codec
->dev
, "AIF2 using split LRCLK\n");
2804 bclk_rate
= params_rate(params
);
2805 switch (params_format(params
)) {
2806 case SNDRV_PCM_FORMAT_S16_LE
:
2809 case SNDRV_PCM_FORMAT_S20_3LE
:
2813 case SNDRV_PCM_FORMAT_S24_LE
:
2817 case SNDRV_PCM_FORMAT_S32_LE
:
2825 wm8994
->channels
[id
] = params_channels(params
);
2826 if (pdata
->max_channels_clocked
[id
] &&
2827 wm8994
->channels
[id
] > pdata
->max_channels_clocked
[id
]) {
2828 dev_dbg(dai
->dev
, "Constraining channels to %d from %d\n",
2829 pdata
->max_channels_clocked
[id
], wm8994
->channels
[id
]);
2830 wm8994
->channels
[id
] = pdata
->max_channels_clocked
[id
];
2833 switch (wm8994
->channels
[id
]) {
2843 /* Try to find an appropriate sample rate; look for an exact match. */
2844 for (i
= 0; i
< ARRAY_SIZE(srs
); i
++)
2845 if (srs
[i
].rate
== params_rate(params
))
2847 if (i
== ARRAY_SIZE(srs
))
2849 rate_val
|= srs
[i
].val
<< WM8994_AIF1_SR_SHIFT
;
2851 dev_dbg(dai
->dev
, "Sample rate is %dHz\n", srs
[i
].rate
);
2852 dev_dbg(dai
->dev
, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2853 dai
->id
, wm8994
->aifclk
[id
], bclk_rate
);
2855 if (wm8994
->channels
[id
] == 1 &&
2856 (snd_soc_read(codec
, aif1_reg
) & 0x18) == 0x18)
2857 aif2
|= WM8994_AIF1_MONO
;
2859 if (wm8994
->aifclk
[id
] == 0) {
2860 dev_err(dai
->dev
, "AIF%dCLK not configured\n", dai
->id
);
2864 /* AIFCLK/fs ratio; look for a close match in either direction */
2866 best_val
= abs((fs_ratios
[0] * params_rate(params
))
2867 - wm8994
->aifclk
[id
]);
2868 for (i
= 1; i
< ARRAY_SIZE(fs_ratios
); i
++) {
2869 cur_val
= abs((fs_ratios
[i
] * params_rate(params
))
2870 - wm8994
->aifclk
[id
]);
2871 if (cur_val
>= best_val
)
2876 dev_dbg(dai
->dev
, "Selected AIF%dCLK/fs = %d\n",
2877 dai
->id
, fs_ratios
[best
]);
2880 /* We may not get quite the right frequency if using
2881 * approximate clocks so look for the closest match that is
2882 * higher than the target (we need to ensure that there enough
2883 * BCLKs to clock out the samples).
2886 for (i
= 0; i
< ARRAY_SIZE(bclk_divs
); i
++) {
2887 cur_val
= (wm8994
->aifclk
[id
] * 10 / bclk_divs
[i
]) - bclk_rate
;
2888 if (cur_val
< 0) /* BCLK table is sorted */
2892 bclk_rate
= wm8994
->aifclk
[id
] * 10 / bclk_divs
[best
];
2893 dev_dbg(dai
->dev
, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2894 bclk_divs
[best
], bclk_rate
);
2895 bclk
|= best
<< WM8994_AIF1_BCLK_DIV_SHIFT
;
2897 lrclk
= bclk_rate
/ params_rate(params
);
2899 dev_err(dai
->dev
, "Unable to generate LRCLK from %dHz BCLK\n",
2903 dev_dbg(dai
->dev
, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2904 lrclk
, bclk_rate
/ lrclk
);
2906 snd_soc_update_bits(codec
, aif1_reg
, WM8994_AIF1_WL_MASK
, aif1
);
2907 snd_soc_update_bits(codec
, aif2_reg
, WM8994_AIF1_MONO
, aif2
);
2908 snd_soc_update_bits(codec
, bclk_reg
, WM8994_AIF1_BCLK_DIV_MASK
, bclk
);
2909 snd_soc_update_bits(codec
, lrclk_reg
, WM8994_AIF1DAC_RATE_MASK
,
2911 snd_soc_update_bits(codec
, rate_reg
, WM8994_AIF1_SR_MASK
|
2912 WM8994_AIF1CLK_RATE_MASK
, rate_val
);
2914 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
2917 wm8994
->dac_rates
[0] = params_rate(params
);
2918 wm8994_set_retune_mobile(codec
, 0);
2919 wm8994_set_retune_mobile(codec
, 1);
2922 wm8994
->dac_rates
[1] = params_rate(params
);
2923 wm8994_set_retune_mobile(codec
, 2);
2931 static int wm8994_aif3_hw_params(struct snd_pcm_substream
*substream
,
2932 struct snd_pcm_hw_params
*params
,
2933 struct snd_soc_dai
*dai
)
2935 struct snd_soc_codec
*codec
= dai
->codec
;
2936 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
2937 struct wm8994
*control
= wm8994
->wm8994
;
2943 switch (control
->type
) {
2946 aif1_reg
= WM8958_AIF3_CONTROL_1
;
2956 switch (params_format(params
)) {
2957 case SNDRV_PCM_FORMAT_S16_LE
:
2959 case SNDRV_PCM_FORMAT_S20_3LE
:
2962 case SNDRV_PCM_FORMAT_S24_LE
:
2965 case SNDRV_PCM_FORMAT_S32_LE
:
2972 return snd_soc_update_bits(codec
, aif1_reg
, WM8994_AIF1_WL_MASK
, aif1
);
2975 static int wm8994_aif_mute(struct snd_soc_dai
*codec_dai
, int mute
)
2977 struct snd_soc_codec
*codec
= codec_dai
->codec
;
2981 switch (codec_dai
->id
) {
2983 mute_reg
= WM8994_AIF1_DAC1_FILTERS_1
;
2986 mute_reg
= WM8994_AIF2_DAC_FILTERS_1
;
2993 reg
= WM8994_AIF1DAC1_MUTE
;
2997 snd_soc_update_bits(codec
, mute_reg
, WM8994_AIF1DAC1_MUTE
, reg
);
3002 static int wm8994_set_tristate(struct snd_soc_dai
*codec_dai
, int tristate
)
3004 struct snd_soc_codec
*codec
= codec_dai
->codec
;
3007 switch (codec_dai
->id
) {
3009 reg
= WM8994_AIF1_MASTER_SLAVE
;
3010 mask
= WM8994_AIF1_TRI
;
3013 reg
= WM8994_AIF2_MASTER_SLAVE
;
3014 mask
= WM8994_AIF2_TRI
;
3025 return snd_soc_update_bits(codec
, reg
, mask
, val
);
3028 static int wm8994_aif2_probe(struct snd_soc_dai
*dai
)
3030 struct snd_soc_codec
*codec
= dai
->codec
;
3032 /* Disable the pulls on the AIF if we're using it to save power. */
3033 snd_soc_update_bits(codec
, WM8994_GPIO_3
,
3034 WM8994_GPN_PU
| WM8994_GPN_PD
, 0);
3035 snd_soc_update_bits(codec
, WM8994_GPIO_4
,
3036 WM8994_GPN_PU
| WM8994_GPN_PD
, 0);
3037 snd_soc_update_bits(codec
, WM8994_GPIO_5
,
3038 WM8994_GPN_PU
| WM8994_GPN_PD
, 0);
3043 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
3045 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
3046 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
3048 static const struct snd_soc_dai_ops wm8994_aif1_dai_ops
= {
3049 .set_sysclk
= wm8994_set_dai_sysclk
,
3050 .set_fmt
= wm8994_set_dai_fmt
,
3051 .hw_params
= wm8994_hw_params
,
3052 .digital_mute
= wm8994_aif_mute
,
3053 .set_pll
= wm8994_set_fll
,
3054 .set_tristate
= wm8994_set_tristate
,
3057 static const struct snd_soc_dai_ops wm8994_aif2_dai_ops
= {
3058 .set_sysclk
= wm8994_set_dai_sysclk
,
3059 .set_fmt
= wm8994_set_dai_fmt
,
3060 .hw_params
= wm8994_hw_params
,
3061 .digital_mute
= wm8994_aif_mute
,
3062 .set_pll
= wm8994_set_fll
,
3063 .set_tristate
= wm8994_set_tristate
,
3066 static const struct snd_soc_dai_ops wm8994_aif3_dai_ops
= {
3067 .hw_params
= wm8994_aif3_hw_params
,
3070 static struct snd_soc_dai_driver wm8994_dai
[] = {
3072 .name
= "wm8994-aif1",
3075 .stream_name
= "AIF1 Playback",
3078 .rates
= WM8994_RATES
,
3079 .formats
= WM8994_FORMATS
,
3083 .stream_name
= "AIF1 Capture",
3086 .rates
= WM8994_RATES
,
3087 .formats
= WM8994_FORMATS
,
3090 .ops
= &wm8994_aif1_dai_ops
,
3093 .name
= "wm8994-aif2",
3096 .stream_name
= "AIF2 Playback",
3099 .rates
= WM8994_RATES
,
3100 .formats
= WM8994_FORMATS
,
3104 .stream_name
= "AIF2 Capture",
3107 .rates
= WM8994_RATES
,
3108 .formats
= WM8994_FORMATS
,
3111 .probe
= wm8994_aif2_probe
,
3112 .ops
= &wm8994_aif2_dai_ops
,
3115 .name
= "wm8994-aif3",
3118 .stream_name
= "AIF3 Playback",
3121 .rates
= WM8994_RATES
,
3122 .formats
= WM8994_FORMATS
,
3126 .stream_name
= "AIF3 Capture",
3129 .rates
= WM8994_RATES
,
3130 .formats
= WM8994_FORMATS
,
3133 .ops
= &wm8994_aif3_dai_ops
,
3138 static int wm8994_codec_suspend(struct snd_soc_codec
*codec
)
3140 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3143 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll
); i
++) {
3144 memcpy(&wm8994
->fll_suspend
[i
], &wm8994
->fll
[i
],
3145 sizeof(struct wm8994_fll_config
));
3146 ret
= _wm8994_set_fll(codec
, i
+ 1, 0, 0, 0);
3148 dev_warn(codec
->dev
, "Failed to stop FLL%d: %d\n",
3152 wm8994_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
3157 static int wm8994_codec_resume(struct snd_soc_codec
*codec
)
3159 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3162 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll
); i
++) {
3163 if (!wm8994
->fll_suspend
[i
].out
)
3166 ret
= _wm8994_set_fll(codec
, i
+ 1,
3167 wm8994
->fll_suspend
[i
].src
,
3168 wm8994
->fll_suspend
[i
].in
,
3169 wm8994
->fll_suspend
[i
].out
);
3171 dev_warn(codec
->dev
, "Failed to restore FLL%d: %d\n",
3178 #define wm8994_codec_suspend NULL
3179 #define wm8994_codec_resume NULL
3182 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv
*wm8994
)
3184 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3185 struct wm8994
*control
= wm8994
->wm8994
;
3186 struct wm8994_pdata
*pdata
= &control
->pdata
;
3187 struct snd_kcontrol_new controls
[] = {
3188 SOC_ENUM_EXT("AIF1.1 EQ Mode",
3189 wm8994
->retune_mobile_enum
,
3190 wm8994_get_retune_mobile_enum
,
3191 wm8994_put_retune_mobile_enum
),
3192 SOC_ENUM_EXT("AIF1.2 EQ Mode",
3193 wm8994
->retune_mobile_enum
,
3194 wm8994_get_retune_mobile_enum
,
3195 wm8994_put_retune_mobile_enum
),
3196 SOC_ENUM_EXT("AIF2 EQ Mode",
3197 wm8994
->retune_mobile_enum
,
3198 wm8994_get_retune_mobile_enum
,
3199 wm8994_put_retune_mobile_enum
),
3204 /* We need an array of texts for the enum API but the number
3205 * of texts is likely to be less than the number of
3206 * configurations due to the sample rate dependency of the
3207 * configurations. */
3208 wm8994
->num_retune_mobile_texts
= 0;
3209 wm8994
->retune_mobile_texts
= NULL
;
3210 for (i
= 0; i
< pdata
->num_retune_mobile_cfgs
; i
++) {
3211 for (j
= 0; j
< wm8994
->num_retune_mobile_texts
; j
++) {
3212 if (strcmp(pdata
->retune_mobile_cfgs
[i
].name
,
3213 wm8994
->retune_mobile_texts
[j
]) == 0)
3217 if (j
!= wm8994
->num_retune_mobile_texts
)
3220 /* Expand the array... */
3221 t
= krealloc(wm8994
->retune_mobile_texts
,
3223 (wm8994
->num_retune_mobile_texts
+ 1),
3228 /* ...store the new entry... */
3229 t
[wm8994
->num_retune_mobile_texts
] =
3230 pdata
->retune_mobile_cfgs
[i
].name
;
3232 /* ...and remember the new version. */
3233 wm8994
->num_retune_mobile_texts
++;
3234 wm8994
->retune_mobile_texts
= t
;
3237 dev_dbg(codec
->dev
, "Allocated %d unique ReTune Mobile names\n",
3238 wm8994
->num_retune_mobile_texts
);
3240 wm8994
->retune_mobile_enum
.max
= wm8994
->num_retune_mobile_texts
;
3241 wm8994
->retune_mobile_enum
.texts
= wm8994
->retune_mobile_texts
;
3243 ret
= snd_soc_add_codec_controls(wm8994
->hubs
.codec
, controls
,
3244 ARRAY_SIZE(controls
));
3246 dev_err(wm8994
->hubs
.codec
->dev
,
3247 "Failed to add ReTune Mobile controls: %d\n", ret
);
3250 static void wm8994_handle_pdata(struct wm8994_priv
*wm8994
)
3252 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3253 struct wm8994
*control
= wm8994
->wm8994
;
3254 struct wm8994_pdata
*pdata
= &control
->pdata
;
3260 wm_hubs_handle_analogue_pdata(codec
, pdata
->lineout1_diff
,
3261 pdata
->lineout2_diff
,
3268 pdata
->micbias1_lvl
,
3269 pdata
->micbias2_lvl
);
3271 dev_dbg(codec
->dev
, "%d DRC configurations\n", pdata
->num_drc_cfgs
);
3273 if (pdata
->num_drc_cfgs
) {
3274 struct snd_kcontrol_new controls
[] = {
3275 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994
->drc_enum
,
3276 wm8994_get_drc_enum
, wm8994_put_drc_enum
),
3277 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994
->drc_enum
,
3278 wm8994_get_drc_enum
, wm8994_put_drc_enum
),
3279 SOC_ENUM_EXT("AIF2DRC Mode", wm8994
->drc_enum
,
3280 wm8994_get_drc_enum
, wm8994_put_drc_enum
),
3283 /* We need an array of texts for the enum API */
3284 wm8994
->drc_texts
= devm_kzalloc(wm8994
->hubs
.codec
->dev
,
3285 sizeof(char *) * pdata
->num_drc_cfgs
, GFP_KERNEL
);
3286 if (!wm8994
->drc_texts
) {
3287 dev_err(wm8994
->hubs
.codec
->dev
,
3288 "Failed to allocate %d DRC config texts\n",
3289 pdata
->num_drc_cfgs
);
3293 for (i
= 0; i
< pdata
->num_drc_cfgs
; i
++)
3294 wm8994
->drc_texts
[i
] = pdata
->drc_cfgs
[i
].name
;
3296 wm8994
->drc_enum
.max
= pdata
->num_drc_cfgs
;
3297 wm8994
->drc_enum
.texts
= wm8994
->drc_texts
;
3299 ret
= snd_soc_add_codec_controls(wm8994
->hubs
.codec
, controls
,
3300 ARRAY_SIZE(controls
));
3301 for (i
= 0; i
< WM8994_NUM_DRC
; i
++)
3302 wm8994_set_drc(codec
, i
);
3304 ret
= snd_soc_add_codec_controls(wm8994
->hubs
.codec
,
3305 wm8994_drc_controls
,
3306 ARRAY_SIZE(wm8994_drc_controls
));
3310 dev_err(wm8994
->hubs
.codec
->dev
,
3311 "Failed to add DRC mode controls: %d\n", ret
);
3314 dev_dbg(codec
->dev
, "%d ReTune Mobile configurations\n",
3315 pdata
->num_retune_mobile_cfgs
);
3317 if (pdata
->num_retune_mobile_cfgs
)
3318 wm8994_handle_retune_mobile_pdata(wm8994
);
3320 snd_soc_add_codec_controls(wm8994
->hubs
.codec
, wm8994_eq_controls
,
3321 ARRAY_SIZE(wm8994_eq_controls
));
3323 for (i
= 0; i
< ARRAY_SIZE(pdata
->micbias
); i
++) {
3324 if (pdata
->micbias
[i
]) {
3325 snd_soc_write(codec
, WM8958_MICBIAS1
+ i
,
3326 pdata
->micbias
[i
] & 0xffff);
3332 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
3334 * @codec: WM8994 codec
3335 * @jack: jack to report detection events on
3336 * @micbias: microphone bias to detect on
3338 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
3339 * being used to bring out signals to the processor then only platform
3340 * data configuration is needed for WM8994 and processor GPIOs should
3341 * be configured using snd_soc_jack_add_gpios() instead.
3343 * Configuration of detection levels is available via the micbias1_lvl
3344 * and micbias2_lvl platform data members.
3346 int wm8994_mic_detect(struct snd_soc_codec
*codec
, struct snd_soc_jack
*jack
,
3349 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3350 struct wm8994_micdet
*micdet
;
3351 struct wm8994
*control
= wm8994
->wm8994
;
3354 if (control
->type
!= WM8994
) {
3355 dev_warn(codec
->dev
, "Not a WM8994\n");
3361 micdet
= &wm8994
->micdet
[0];
3363 ret
= snd_soc_dapm_force_enable_pin(&codec
->dapm
,
3366 ret
= snd_soc_dapm_disable_pin(&codec
->dapm
,
3370 micdet
= &wm8994
->micdet
[1];
3372 ret
= snd_soc_dapm_force_enable_pin(&codec
->dapm
,
3375 ret
= snd_soc_dapm_disable_pin(&codec
->dapm
,
3379 dev_warn(codec
->dev
, "Invalid MICBIAS %d\n", micbias
);
3384 dev_warn(codec
->dev
, "Failed to configure MICBIAS%d: %d\n",
3387 dev_dbg(codec
->dev
, "Configuring microphone detection on %d %p\n",
3390 /* Store the configuration */
3391 micdet
->jack
= jack
;
3392 micdet
->detecting
= true;
3394 /* If either of the jacks is set up then enable detection */
3395 if (wm8994
->micdet
[0].jack
|| wm8994
->micdet
[1].jack
)
3396 reg
= WM8994_MICD_ENA
;
3400 snd_soc_update_bits(codec
, WM8994_MICBIAS
, WM8994_MICD_ENA
, reg
);
3402 /* enable MICDET and MICSHRT deboune */
3403 snd_soc_update_bits(codec
, WM8994_IRQ_DEBOUNCE
,
3404 WM8994_MIC1_DET_DB_MASK
| WM8994_MIC1_SHRT_DB_MASK
|
3405 WM8994_MIC2_DET_DB_MASK
| WM8994_MIC2_SHRT_DB_MASK
,
3406 WM8994_MIC1_DET_DB
| WM8994_MIC1_SHRT_DB
);
3408 snd_soc_dapm_sync(&codec
->dapm
);
3412 EXPORT_SYMBOL_GPL(wm8994_mic_detect
);
3414 static void wm8994_mic_work(struct work_struct
*work
)
3416 struct wm8994_priv
*priv
= container_of(work
,
3419 struct regmap
*regmap
= priv
->wm8994
->regmap
;
3420 struct device
*dev
= priv
->wm8994
->dev
;
3425 pm_runtime_get_sync(dev
);
3427 ret
= regmap_read(regmap
, WM8994_INTERRUPT_RAW_STATUS_2
, ®
);
3429 dev_err(dev
, "Failed to read microphone status: %d\n",
3431 pm_runtime_put(dev
);
3435 dev_dbg(dev
, "Microphone status: %x\n", reg
);
3438 if (reg
& WM8994_MIC1_DET_STS
) {
3439 if (priv
->micdet
[0].detecting
)
3440 report
= SND_JACK_HEADSET
;
3442 if (reg
& WM8994_MIC1_SHRT_STS
) {
3443 if (priv
->micdet
[0].detecting
)
3444 report
= SND_JACK_HEADPHONE
;
3446 report
|= SND_JACK_BTN_0
;
3449 priv
->micdet
[0].detecting
= false;
3451 priv
->micdet
[0].detecting
= true;
3453 snd_soc_jack_report(priv
->micdet
[0].jack
, report
,
3454 SND_JACK_HEADSET
| SND_JACK_BTN_0
);
3457 if (reg
& WM8994_MIC2_DET_STS
) {
3458 if (priv
->micdet
[1].detecting
)
3459 report
= SND_JACK_HEADSET
;
3461 if (reg
& WM8994_MIC2_SHRT_STS
) {
3462 if (priv
->micdet
[1].detecting
)
3463 report
= SND_JACK_HEADPHONE
;
3465 report
|= SND_JACK_BTN_0
;
3468 priv
->micdet
[1].detecting
= false;
3470 priv
->micdet
[1].detecting
= true;
3472 snd_soc_jack_report(priv
->micdet
[1].jack
, report
,
3473 SND_JACK_HEADSET
| SND_JACK_BTN_0
);
3475 pm_runtime_put(dev
);
3478 static irqreturn_t
wm8994_mic_irq(int irq
, void *data
)
3480 struct wm8994_priv
*priv
= data
;
3481 struct snd_soc_codec
*codec
= priv
->hubs
.codec
;
3483 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3484 trace_snd_soc_jack_irq(dev_name(codec
->dev
));
3487 pm_wakeup_event(codec
->dev
, 300);
3489 schedule_delayed_work(&priv
->mic_work
, msecs_to_jiffies(250));
3494 static void wm1811_micd_stop(struct snd_soc_codec
*codec
)
3496 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3498 if (!wm8994
->jackdet
)
3501 mutex_lock(&wm8994
->accdet_lock
);
3503 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
, WM8958_MICD_ENA
, 0);
3505 wm1811_jackdet_set_mode(codec
, WM1811_JACKDET_MODE_JACK
);
3507 mutex_unlock(&wm8994
->accdet_lock
);
3509 if (wm8994
->wm8994
->pdata
.jd_ext_cap
)
3510 snd_soc_dapm_disable_pin(&codec
->dapm
,
3514 static void wm8958_button_det(struct snd_soc_codec
*codec
, u16 status
)
3516 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3521 report
|= SND_JACK_BTN_0
;
3524 report
|= SND_JACK_BTN_1
;
3527 report
|= SND_JACK_BTN_2
;
3530 report
|= SND_JACK_BTN_3
;
3533 report
|= SND_JACK_BTN_4
;
3536 report
|= SND_JACK_BTN_5
;
3538 snd_soc_jack_report(wm8994
->micdet
[0].jack
, report
,
3542 static void wm8958_open_circuit_work(struct work_struct
*work
)
3544 struct wm8994_priv
*wm8994
= container_of(work
,
3546 open_circuit_work
.work
);
3547 struct device
*dev
= wm8994
->wm8994
->dev
;
3549 wm1811_micd_stop(wm8994
->hubs
.codec
);
3551 mutex_lock(&wm8994
->accdet_lock
);
3553 dev_dbg(dev
, "Reporting open circuit\n");
3555 wm8994
->jack_mic
= false;
3556 wm8994
->mic_detecting
= true;
3558 wm8958_micd_set_rate(wm8994
->hubs
.codec
);
3560 snd_soc_jack_report(wm8994
->micdet
[0].jack
, 0,
3564 mutex_unlock(&wm8994
->accdet_lock
);
3567 static void wm8958_mic_id(void *data
, u16 status
)
3569 struct snd_soc_codec
*codec
= data
;
3570 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3572 /* Either nothing present or just starting detection */
3573 if (!(status
& WM8958_MICD_STS
)) {
3574 /* If nothing present then clear our statuses */
3575 dev_dbg(codec
->dev
, "Detected open circuit\n");
3577 schedule_delayed_work(&wm8994
->open_circuit_work
,
3578 msecs_to_jiffies(2500));
3582 /* If the measurement is showing a high impedence we've got a
3585 if (status
& 0x600) {
3586 dev_dbg(codec
->dev
, "Detected microphone\n");
3588 wm8994
->mic_detecting
= false;
3589 wm8994
->jack_mic
= true;
3591 wm8958_micd_set_rate(codec
);
3593 snd_soc_jack_report(wm8994
->micdet
[0].jack
, SND_JACK_HEADSET
,
3598 if (status
& 0xfc) {
3599 dev_dbg(codec
->dev
, "Detected headphone\n");
3600 wm8994
->mic_detecting
= false;
3602 wm8958_micd_set_rate(codec
);
3604 /* If we have jackdet that will detect removal */
3605 wm1811_micd_stop(codec
);
3607 snd_soc_jack_report(wm8994
->micdet
[0].jack
, SND_JACK_HEADPHONE
,
3612 /* Deferred mic detection to allow for extra settling time */
3613 static void wm1811_mic_work(struct work_struct
*work
)
3615 struct wm8994_priv
*wm8994
= container_of(work
, struct wm8994_priv
,
3617 struct wm8994
*control
= wm8994
->wm8994
;
3618 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3620 pm_runtime_get_sync(codec
->dev
);
3622 /* If required for an external cap force MICBIAS on */
3623 if (control
->pdata
.jd_ext_cap
) {
3624 snd_soc_dapm_force_enable_pin(&codec
->dapm
,
3626 snd_soc_dapm_sync(&codec
->dapm
);
3629 mutex_lock(&wm8994
->accdet_lock
);
3631 dev_dbg(codec
->dev
, "Starting mic detection\n");
3633 /* Use a user-supplied callback if we have one */
3634 if (wm8994
->micd_cb
) {
3635 wm8994
->micd_cb(wm8994
->micd_cb_data
);
3638 * Start off measument of microphone impedence to find out
3639 * what's actually there.
3641 wm8994
->mic_detecting
= true;
3642 wm1811_jackdet_set_mode(codec
, WM1811_JACKDET_MODE_MIC
);
3644 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
,
3645 WM8958_MICD_ENA
, WM8958_MICD_ENA
);
3648 mutex_unlock(&wm8994
->accdet_lock
);
3650 pm_runtime_put(codec
->dev
);
3653 static irqreturn_t
wm1811_jackdet_irq(int irq
, void *data
)
3655 struct wm8994_priv
*wm8994
= data
;
3656 struct wm8994
*control
= wm8994
->wm8994
;
3657 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3661 pm_runtime_get_sync(codec
->dev
);
3663 cancel_delayed_work_sync(&wm8994
->mic_complete_work
);
3665 mutex_lock(&wm8994
->accdet_lock
);
3667 reg
= snd_soc_read(codec
, WM1811_JACKDET_CTRL
);
3669 dev_err(codec
->dev
, "Failed to read jack status: %d\n", reg
);
3670 mutex_unlock(&wm8994
->accdet_lock
);
3671 pm_runtime_put(codec
->dev
);
3675 dev_dbg(codec
->dev
, "JACKDET %x\n", reg
);
3677 present
= reg
& WM1811_JACKDET_LVL
;
3680 dev_dbg(codec
->dev
, "Jack detected\n");
3682 wm8958_micd_set_rate(codec
);
3684 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
3685 WM8958_MICB2_DISCH
, 0);
3687 /* Disable debounce while inserted */
3688 snd_soc_update_bits(codec
, WM1811_JACKDET_CTRL
,
3689 WM1811_JACKDET_DB
, 0);
3691 delay
= control
->pdata
.micdet_delay
;
3692 schedule_delayed_work(&wm8994
->mic_work
,
3693 msecs_to_jiffies(delay
));
3695 dev_dbg(codec
->dev
, "Jack not detected\n");
3697 cancel_delayed_work_sync(&wm8994
->mic_work
);
3699 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
3700 WM8958_MICB2_DISCH
, WM8958_MICB2_DISCH
);
3702 /* Enable debounce while removed */
3703 snd_soc_update_bits(codec
, WM1811_JACKDET_CTRL
,
3704 WM1811_JACKDET_DB
, WM1811_JACKDET_DB
);
3706 wm8994
->mic_detecting
= false;
3707 wm8994
->jack_mic
= false;
3708 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
,
3709 WM8958_MICD_ENA
, 0);
3710 wm1811_jackdet_set_mode(codec
, WM1811_JACKDET_MODE_JACK
);
3713 mutex_unlock(&wm8994
->accdet_lock
);
3715 /* Turn off MICBIAS if it was on for an external cap */
3716 if (control
->pdata
.jd_ext_cap
&& !present
)
3717 snd_soc_dapm_disable_pin(&codec
->dapm
, "MICBIAS2");
3720 snd_soc_jack_report(wm8994
->micdet
[0].jack
,
3721 SND_JACK_MECHANICAL
, SND_JACK_MECHANICAL
);
3723 snd_soc_jack_report(wm8994
->micdet
[0].jack
, 0,
3724 SND_JACK_MECHANICAL
| SND_JACK_HEADSET
|
3727 /* Since we only report deltas force an update, ensures we
3728 * avoid bootstrapping issues with the core. */
3729 snd_soc_jack_report(wm8994
->micdet
[0].jack
, 0, 0);
3731 pm_runtime_put(codec
->dev
);
3735 static void wm1811_jackdet_bootstrap(struct work_struct
*work
)
3737 struct wm8994_priv
*wm8994
= container_of(work
,
3739 jackdet_bootstrap
.work
);
3740 wm1811_jackdet_irq(0, wm8994
);
3744 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3746 * @codec: WM8958 codec
3747 * @jack: jack to report detection events on
3749 * Enable microphone detection functionality for the WM8958. By
3750 * default simple detection which supports the detection of up to 6
3751 * buttons plus video and microphone functionality is supported.
3753 * The WM8958 has an advanced jack detection facility which is able to
3754 * support complex accessory detection, especially when used in
3755 * conjunction with external circuitry. In order to provide maximum
3756 * flexiblity a callback is provided which allows a completely custom
3757 * detection algorithm.
3759 int wm8958_mic_detect(struct snd_soc_codec
*codec
, struct snd_soc_jack
*jack
,
3760 wm1811_micdet_cb det_cb
, void *det_cb_data
,
3761 wm1811_mic_id_cb id_cb
, void *id_cb_data
)
3763 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3764 struct wm8994
*control
= wm8994
->wm8994
;
3767 switch (control
->type
) {
3776 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "CLK_SYS");
3777 snd_soc_dapm_sync(&codec
->dapm
);
3779 wm8994
->micdet
[0].jack
= jack
;
3782 wm8994
->micd_cb
= det_cb
;
3783 wm8994
->micd_cb_data
= det_cb_data
;
3785 wm8994
->mic_detecting
= true;
3786 wm8994
->jack_mic
= false;
3790 wm8994
->mic_id_cb
= id_cb
;
3791 wm8994
->mic_id_cb_data
= id_cb_data
;
3793 wm8994
->mic_id_cb
= wm8958_mic_id
;
3794 wm8994
->mic_id_cb_data
= codec
;
3797 wm8958_micd_set_rate(codec
);
3799 /* Detect microphones and short circuits by default */
3800 if (control
->pdata
.micd_lvl_sel
)
3801 micd_lvl_sel
= control
->pdata
.micd_lvl_sel
;
3803 micd_lvl_sel
= 0x41;
3805 wm8994
->btn_mask
= SND_JACK_BTN_0
| SND_JACK_BTN_1
|
3806 SND_JACK_BTN_2
| SND_JACK_BTN_3
|
3807 SND_JACK_BTN_4
| SND_JACK_BTN_5
;
3809 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_2
,
3810 WM8958_MICD_LVL_SEL_MASK
, micd_lvl_sel
);
3812 WARN_ON(codec
->dapm
.bias_level
> SND_SOC_BIAS_STANDBY
);
3815 * If we can use jack detection start off with that,
3816 * otherwise jump straight to microphone detection.
3818 if (wm8994
->jackdet
) {
3819 /* Disable debounce for the initial detect */
3820 snd_soc_update_bits(codec
, WM1811_JACKDET_CTRL
,
3821 WM1811_JACKDET_DB
, 0);
3823 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
3825 WM8958_MICB2_DISCH
);
3826 snd_soc_update_bits(codec
, WM8994_LDO_1
,
3827 WM8994_LDO1_DISCH
, 0);
3828 wm1811_jackdet_set_mode(codec
,
3829 WM1811_JACKDET_MODE_JACK
);
3831 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
,
3832 WM8958_MICD_ENA
, WM8958_MICD_ENA
);
3836 snd_soc_update_bits(codec
, WM8958_MIC_DETECT_1
,
3837 WM8958_MICD_ENA
, 0);
3838 wm1811_jackdet_set_mode(codec
, WM1811_JACKDET_MODE_NONE
);
3839 snd_soc_dapm_disable_pin(&codec
->dapm
, "CLK_SYS");
3840 snd_soc_dapm_sync(&codec
->dapm
);
3845 EXPORT_SYMBOL_GPL(wm8958_mic_detect
);
3847 static void wm8958_mic_work(struct work_struct
*work
)
3849 struct wm8994_priv
*wm8994
= container_of(work
,
3851 mic_complete_work
.work
);
3852 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3854 dev_crit(codec
->dev
, "MIC WORK %x\n", wm8994
->mic_status
);
3856 pm_runtime_get_sync(codec
->dev
);
3858 mutex_lock(&wm8994
->accdet_lock
);
3860 wm8994
->mic_id_cb(wm8994
->mic_id_cb_data
, wm8994
->mic_status
);
3862 mutex_unlock(&wm8994
->accdet_lock
);
3864 pm_runtime_put(codec
->dev
);
3866 dev_crit(codec
->dev
, "MIC WORK %x DONE\n", wm8994
->mic_status
);
3869 static irqreturn_t
wm8958_mic_irq(int irq
, void *data
)
3871 struct wm8994_priv
*wm8994
= data
;
3872 struct snd_soc_codec
*codec
= wm8994
->hubs
.codec
;
3873 int reg
, count
, ret
, id_delay
;
3876 * Jack detection may have detected a removal simulataneously
3877 * with an update of the MICDET status; if so it will have
3878 * stopped detection and we can ignore this interrupt.
3880 if (!(snd_soc_read(codec
, WM8958_MIC_DETECT_1
) & WM8958_MICD_ENA
))
3883 cancel_delayed_work_sync(&wm8994
->mic_complete_work
);
3884 cancel_delayed_work_sync(&wm8994
->open_circuit_work
);
3886 pm_runtime_get_sync(codec
->dev
);
3888 /* We may occasionally read a detection without an impedence
3889 * range being provided - if that happens loop again.
3893 reg
= snd_soc_read(codec
, WM8958_MIC_DETECT_3
);
3896 "Failed to read mic detect status: %d\n",
3898 pm_runtime_put(codec
->dev
);
3902 if (!(reg
& WM8958_MICD_VALID
)) {
3903 dev_dbg(codec
->dev
, "Mic detect data not valid\n");
3907 if (!(reg
& WM8958_MICD_STS
) || (reg
& WM8958_MICD_LVL_MASK
))
3914 dev_warn(codec
->dev
, "No impedance range reported for jack\n");
3916 #ifndef CONFIG_SND_SOC_WM8994_MODULE
3917 trace_snd_soc_jack_irq(dev_name(codec
->dev
));
3920 /* Avoid a transient report when the accessory is being removed */
3921 if (wm8994
->jackdet
) {
3922 ret
= snd_soc_read(codec
, WM1811_JACKDET_CTRL
);
3924 dev_err(codec
->dev
, "Failed to read jack status: %d\n",
3926 } else if (!(ret
& WM1811_JACKDET_LVL
)) {
3927 dev_dbg(codec
->dev
, "Ignoring removed jack\n");
3932 wm8994
->mic_status
= reg
;
3933 id_delay
= wm8994
->wm8994
->pdata
.mic_id_delay
;
3935 if (wm8994
->mic_detecting
)
3936 schedule_delayed_work(&wm8994
->mic_complete_work
,
3937 msecs_to_jiffies(id_delay
));
3939 wm8958_button_det(codec
, reg
);
3942 pm_runtime_put(codec
->dev
);
3946 static irqreturn_t
wm8994_fifo_error(int irq
, void *data
)
3948 struct snd_soc_codec
*codec
= data
;
3950 dev_err(codec
->dev
, "FIFO error\n");
3955 static irqreturn_t
wm8994_temp_warn(int irq
, void *data
)
3957 struct snd_soc_codec
*codec
= data
;
3959 dev_err(codec
->dev
, "Thermal warning\n");
3964 static irqreturn_t
wm8994_temp_shut(int irq
, void *data
)
3966 struct snd_soc_codec
*codec
= data
;
3968 dev_crit(codec
->dev
, "Thermal shutdown\n");
3973 static int wm8994_codec_probe(struct snd_soc_codec
*codec
)
3975 struct wm8994
*control
= dev_get_drvdata(codec
->dev
->parent
);
3976 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
3977 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3981 wm8994
->hubs
.codec
= codec
;
3982 codec
->control_data
= control
->regmap
;
3984 snd_soc_codec_set_cache_io(codec
, 16, 16, SND_SOC_REGMAP
);
3986 mutex_init(&wm8994
->accdet_lock
);
3987 INIT_DELAYED_WORK(&wm8994
->jackdet_bootstrap
,
3988 wm1811_jackdet_bootstrap
);
3989 INIT_DELAYED_WORK(&wm8994
->open_circuit_work
,
3990 wm8958_open_circuit_work
);
3992 switch (control
->type
) {
3994 INIT_DELAYED_WORK(&wm8994
->mic_work
, wm8994_mic_work
);
3997 INIT_DELAYED_WORK(&wm8994
->mic_work
, wm1811_mic_work
);
4003 INIT_DELAYED_WORK(&wm8994
->mic_complete_work
, wm8958_mic_work
);
4005 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll_locked
); i
++)
4006 init_completion(&wm8994
->fll_locked
[i
]);
4008 wm8994
->micdet_irq
= control
->pdata
.micdet_irq
;
4010 pm_runtime_enable(codec
->dev
);
4011 pm_runtime_idle(codec
->dev
);
4013 /* By default use idle_bias_off, will override for WM8994 */
4014 codec
->dapm
.idle_bias_off
= 1;
4016 /* Set revision-specific configuration */
4017 switch (control
->type
) {
4019 /* Single ended line outputs should have VMID on. */
4020 if (!control
->pdata
.lineout1_diff
||
4021 !control
->pdata
.lineout2_diff
)
4022 codec
->dapm
.idle_bias_off
= 0;
4024 switch (control
->revision
) {
4027 wm8994
->hubs
.dcs_codes_l
= -5;
4028 wm8994
->hubs
.dcs_codes_r
= -5;
4029 wm8994
->hubs
.hp_startup_mode
= 1;
4030 wm8994
->hubs
.dcs_readback_mode
= 1;
4031 wm8994
->hubs
.series_startup
= 1;
4034 wm8994
->hubs
.dcs_readback_mode
= 2;
4040 wm8994
->hubs
.dcs_readback_mode
= 1;
4041 wm8994
->hubs
.hp_startup_mode
= 1;
4043 switch (control
->revision
) {
4047 wm8994
->fll_byp
= true;
4053 wm8994
->hubs
.dcs_readback_mode
= 2;
4054 wm8994
->hubs
.no_series_update
= 1;
4055 wm8994
->hubs
.hp_startup_mode
= 1;
4056 wm8994
->hubs
.no_cache_dac_hp_direct
= true;
4057 wm8994
->fll_byp
= true;
4059 wm8994
->hubs
.dcs_codes_l
= -9;
4060 wm8994
->hubs
.dcs_codes_r
= -7;
4062 snd_soc_update_bits(codec
, WM8994_ANALOGUE_HP_1
,
4063 WM1811_HPOUT1_ATTN
, WM1811_HPOUT1_ATTN
);
4070 wm8994_request_irq(wm8994
->wm8994
, WM8994_IRQ_FIFOS_ERR
,
4071 wm8994_fifo_error
, "FIFO error", codec
);
4072 wm8994_request_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_WARN
,
4073 wm8994_temp_warn
, "Thermal warning", codec
);
4074 wm8994_request_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_SHUT
,
4075 wm8994_temp_shut
, "Thermal shutdown", codec
);
4077 ret
= wm8994_request_irq(wm8994
->wm8994
, WM8994_IRQ_DCS_DONE
,
4078 wm_hubs_dcs_done
, "DC servo done",
4081 wm8994
->hubs
.dcs_done_irq
= true;
4083 switch (control
->type
) {
4085 if (wm8994
->micdet_irq
) {
4086 ret
= request_threaded_irq(wm8994
->micdet_irq
, NULL
,
4088 IRQF_TRIGGER_RISING
,
4092 dev_warn(codec
->dev
,
4093 "Failed to request Mic1 detect IRQ: %d\n",
4097 ret
= wm8994_request_irq(wm8994
->wm8994
,
4098 WM8994_IRQ_MIC1_SHRT
,
4099 wm8994_mic_irq
, "Mic 1 short",
4102 dev_warn(codec
->dev
,
4103 "Failed to request Mic1 short IRQ: %d\n",
4106 ret
= wm8994_request_irq(wm8994
->wm8994
,
4107 WM8994_IRQ_MIC2_DET
,
4108 wm8994_mic_irq
, "Mic 2 detect",
4111 dev_warn(codec
->dev
,
4112 "Failed to request Mic2 detect IRQ: %d\n",
4115 ret
= wm8994_request_irq(wm8994
->wm8994
,
4116 WM8994_IRQ_MIC2_SHRT
,
4117 wm8994_mic_irq
, "Mic 2 short",
4120 dev_warn(codec
->dev
,
4121 "Failed to request Mic2 short IRQ: %d\n",
4127 if (wm8994
->micdet_irq
) {
4128 ret
= request_threaded_irq(wm8994
->micdet_irq
, NULL
,
4130 IRQF_TRIGGER_RISING
,
4134 dev_warn(codec
->dev
,
4135 "Failed to request Mic detect IRQ: %d\n",
4138 wm8994_request_irq(wm8994
->wm8994
, WM8994_IRQ_MIC1_DET
,
4139 wm8958_mic_irq
, "Mic detect",
4144 switch (control
->type
) {
4146 if (control
->cust_id
> 1 || control
->revision
> 1) {
4147 ret
= wm8994_request_irq(wm8994
->wm8994
,
4149 wm1811_jackdet_irq
, "JACKDET",
4152 wm8994
->jackdet
= true;
4159 wm8994
->fll_locked_irq
= true;
4160 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll_locked
); i
++) {
4161 ret
= wm8994_request_irq(wm8994
->wm8994
,
4162 WM8994_IRQ_FLL1_LOCK
+ i
,
4163 wm8994_fll_locked_irq
, "FLL lock",
4164 &wm8994
->fll_locked
[i
]);
4166 wm8994
->fll_locked_irq
= false;
4169 /* Make sure we can read from the GPIOs if they're inputs */
4170 pm_runtime_get_sync(codec
->dev
);
4172 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
4173 * configured on init - if a system wants to do this dynamically
4174 * at runtime we can deal with that then.
4176 ret
= regmap_read(control
->regmap
, WM8994_GPIO_1
, ®
);
4178 dev_err(codec
->dev
, "Failed to read GPIO1 state: %d\n", ret
);
4181 if ((reg
& WM8994_GPN_FN_MASK
) != WM8994_GP_FN_PIN_SPECIFIC
) {
4182 wm8994
->lrclk_shared
[0] = 1;
4183 wm8994_dai
[0].symmetric_rates
= 1;
4185 wm8994
->lrclk_shared
[0] = 0;
4188 ret
= regmap_read(control
->regmap
, WM8994_GPIO_6
, ®
);
4190 dev_err(codec
->dev
, "Failed to read GPIO6 state: %d\n", ret
);
4193 if ((reg
& WM8994_GPN_FN_MASK
) != WM8994_GP_FN_PIN_SPECIFIC
) {
4194 wm8994
->lrclk_shared
[1] = 1;
4195 wm8994_dai
[1].symmetric_rates
= 1;
4197 wm8994
->lrclk_shared
[1] = 0;
4200 pm_runtime_put(codec
->dev
);
4202 /* Latch volume update bits */
4203 for (i
= 0; i
< ARRAY_SIZE(wm8994_vu_bits
); i
++)
4204 snd_soc_update_bits(codec
, wm8994_vu_bits
[i
].reg
,
4205 wm8994_vu_bits
[i
].mask
,
4206 wm8994_vu_bits
[i
].mask
);
4208 /* Set the low bit of the 3D stereo depth so TLV matches */
4209 snd_soc_update_bits(codec
, WM8994_AIF1_DAC1_FILTERS_2
,
4210 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT
,
4211 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT
);
4212 snd_soc_update_bits(codec
, WM8994_AIF1_DAC2_FILTERS_2
,
4213 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT
,
4214 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT
);
4215 snd_soc_update_bits(codec
, WM8994_AIF2_DAC_FILTERS_2
,
4216 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT
,
4217 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT
);
4219 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
4220 * use this; it only affects behaviour on idle TDM clock
4222 switch (control
->type
) {
4225 snd_soc_update_bits(codec
, WM8994_AIF1_CONTROL_1
,
4226 WM8994_AIF1ADC_TDM
, WM8994_AIF1ADC_TDM
);
4232 /* Put MICBIAS into bypass mode by default on newer devices */
4233 switch (control
->type
) {
4236 snd_soc_update_bits(codec
, WM8958_MICBIAS1
,
4237 WM8958_MICB1_MODE
, WM8958_MICB1_MODE
);
4238 snd_soc_update_bits(codec
, WM8958_MICBIAS2
,
4239 WM8958_MICB2_MODE
, WM8958_MICB2_MODE
);
4245 wm8994
->hubs
.check_class_w_digital
= wm8994_check_class_w_digital
;
4246 wm_hubs_update_class_w(codec
);
4248 wm8994_handle_pdata(wm8994
);
4250 wm_hubs_add_analogue_controls(codec
);
4251 snd_soc_add_codec_controls(codec
, wm8994_snd_controls
,
4252 ARRAY_SIZE(wm8994_snd_controls
));
4253 snd_soc_dapm_new_controls(dapm
, wm8994_dapm_widgets
,
4254 ARRAY_SIZE(wm8994_dapm_widgets
));
4256 switch (control
->type
) {
4258 snd_soc_dapm_new_controls(dapm
, wm8994_specific_dapm_widgets
,
4259 ARRAY_SIZE(wm8994_specific_dapm_widgets
));
4260 if (control
->revision
< 4) {
4261 snd_soc_dapm_new_controls(dapm
, wm8994_lateclk_revd_widgets
,
4262 ARRAY_SIZE(wm8994_lateclk_revd_widgets
));
4263 snd_soc_dapm_new_controls(dapm
, wm8994_adc_revd_widgets
,
4264 ARRAY_SIZE(wm8994_adc_revd_widgets
));
4265 snd_soc_dapm_new_controls(dapm
, wm8994_dac_revd_widgets
,
4266 ARRAY_SIZE(wm8994_dac_revd_widgets
));
4268 snd_soc_dapm_new_controls(dapm
, wm8994_lateclk_widgets
,
4269 ARRAY_SIZE(wm8994_lateclk_widgets
));
4270 snd_soc_dapm_new_controls(dapm
, wm8994_adc_widgets
,
4271 ARRAY_SIZE(wm8994_adc_widgets
));
4272 snd_soc_dapm_new_controls(dapm
, wm8994_dac_widgets
,
4273 ARRAY_SIZE(wm8994_dac_widgets
));
4277 snd_soc_add_codec_controls(codec
, wm8958_snd_controls
,
4278 ARRAY_SIZE(wm8958_snd_controls
));
4279 snd_soc_dapm_new_controls(dapm
, wm8958_dapm_widgets
,
4280 ARRAY_SIZE(wm8958_dapm_widgets
));
4281 if (control
->revision
< 1) {
4282 snd_soc_dapm_new_controls(dapm
, wm8994_lateclk_revd_widgets
,
4283 ARRAY_SIZE(wm8994_lateclk_revd_widgets
));
4284 snd_soc_dapm_new_controls(dapm
, wm8994_adc_revd_widgets
,
4285 ARRAY_SIZE(wm8994_adc_revd_widgets
));
4286 snd_soc_dapm_new_controls(dapm
, wm8994_dac_revd_widgets
,
4287 ARRAY_SIZE(wm8994_dac_revd_widgets
));
4289 snd_soc_dapm_new_controls(dapm
, wm8994_lateclk_widgets
,
4290 ARRAY_SIZE(wm8994_lateclk_widgets
));
4291 snd_soc_dapm_new_controls(dapm
, wm8994_adc_widgets
,
4292 ARRAY_SIZE(wm8994_adc_widgets
));
4293 snd_soc_dapm_new_controls(dapm
, wm8994_dac_widgets
,
4294 ARRAY_SIZE(wm8994_dac_widgets
));
4299 snd_soc_add_codec_controls(codec
, wm8958_snd_controls
,
4300 ARRAY_SIZE(wm8958_snd_controls
));
4301 snd_soc_dapm_new_controls(dapm
, wm8958_dapm_widgets
,
4302 ARRAY_SIZE(wm8958_dapm_widgets
));
4303 snd_soc_dapm_new_controls(dapm
, wm8994_lateclk_widgets
,
4304 ARRAY_SIZE(wm8994_lateclk_widgets
));
4305 snd_soc_dapm_new_controls(dapm
, wm8994_adc_widgets
,
4306 ARRAY_SIZE(wm8994_adc_widgets
));
4307 snd_soc_dapm_new_controls(dapm
, wm8994_dac_widgets
,
4308 ARRAY_SIZE(wm8994_dac_widgets
));
4312 wm_hubs_add_analogue_routes(codec
, 0, 0);
4313 snd_soc_dapm_add_routes(dapm
, intercon
, ARRAY_SIZE(intercon
));
4315 switch (control
->type
) {
4317 snd_soc_dapm_add_routes(dapm
, wm8994_intercon
,
4318 ARRAY_SIZE(wm8994_intercon
));
4320 if (control
->revision
< 4) {
4321 snd_soc_dapm_add_routes(dapm
, wm8994_revd_intercon
,
4322 ARRAY_SIZE(wm8994_revd_intercon
));
4323 snd_soc_dapm_add_routes(dapm
, wm8994_lateclk_revd_intercon
,
4324 ARRAY_SIZE(wm8994_lateclk_revd_intercon
));
4326 snd_soc_dapm_add_routes(dapm
, wm8994_lateclk_intercon
,
4327 ARRAY_SIZE(wm8994_lateclk_intercon
));
4331 if (control
->revision
< 1) {
4332 snd_soc_dapm_add_routes(dapm
, wm8994_intercon
,
4333 ARRAY_SIZE(wm8994_intercon
));
4334 snd_soc_dapm_add_routes(dapm
, wm8994_revd_intercon
,
4335 ARRAY_SIZE(wm8994_revd_intercon
));
4336 snd_soc_dapm_add_routes(dapm
, wm8994_lateclk_revd_intercon
,
4337 ARRAY_SIZE(wm8994_lateclk_revd_intercon
));
4339 snd_soc_dapm_add_routes(dapm
, wm8994_lateclk_intercon
,
4340 ARRAY_SIZE(wm8994_lateclk_intercon
));
4341 snd_soc_dapm_add_routes(dapm
, wm8958_intercon
,
4342 ARRAY_SIZE(wm8958_intercon
));
4345 wm8958_dsp2_init(codec
);
4348 snd_soc_dapm_add_routes(dapm
, wm8994_lateclk_intercon
,
4349 ARRAY_SIZE(wm8994_lateclk_intercon
));
4350 snd_soc_dapm_add_routes(dapm
, wm8958_intercon
,
4351 ARRAY_SIZE(wm8958_intercon
));
4358 if (wm8994
->jackdet
)
4359 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_GPIO(6), wm8994
);
4360 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC2_SHRT
, wm8994
);
4361 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC2_DET
, wm8994
);
4362 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC1_SHRT
, wm8994
);
4363 if (wm8994
->micdet_irq
)
4364 free_irq(wm8994
->micdet_irq
, wm8994
);
4365 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll_locked
); i
++)
4366 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_FLL1_LOCK
+ i
,
4367 &wm8994
->fll_locked
[i
]);
4368 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_DCS_DONE
,
4370 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_FIFOS_ERR
, codec
);
4371 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_SHUT
, codec
);
4372 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_WARN
, codec
);
4377 static int wm8994_codec_remove(struct snd_soc_codec
*codec
)
4379 struct wm8994_priv
*wm8994
= snd_soc_codec_get_drvdata(codec
);
4380 struct wm8994
*control
= wm8994
->wm8994
;
4383 wm8994_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
4385 pm_runtime_disable(codec
->dev
);
4387 for (i
= 0; i
< ARRAY_SIZE(wm8994
->fll_locked
); i
++)
4388 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_FLL1_LOCK
+ i
,
4389 &wm8994
->fll_locked
[i
]);
4391 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_DCS_DONE
,
4393 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_FIFOS_ERR
, codec
);
4394 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_SHUT
, codec
);
4395 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_TEMP_WARN
, codec
);
4397 if (wm8994
->jackdet
)
4398 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_GPIO(6), wm8994
);
4400 switch (control
->type
) {
4402 if (wm8994
->micdet_irq
)
4403 free_irq(wm8994
->micdet_irq
, wm8994
);
4404 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC2_DET
,
4406 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC1_SHRT
,
4408 wm8994_free_irq(wm8994
->wm8994
, WM8994_IRQ_MIC1_DET
,
4414 if (wm8994
->micdet_irq
)
4415 free_irq(wm8994
->micdet_irq
, wm8994
);
4418 release_firmware(wm8994
->mbc
);
4419 release_firmware(wm8994
->mbc_vss
);
4420 release_firmware(wm8994
->enh_eq
);
4421 kfree(wm8994
->retune_mobile_texts
);
4425 static struct snd_soc_codec_driver soc_codec_dev_wm8994
= {
4426 .probe
= wm8994_codec_probe
,
4427 .remove
= wm8994_codec_remove
,
4428 .suspend
= wm8994_codec_suspend
,
4429 .resume
= wm8994_codec_resume
,
4430 .set_bias_level
= wm8994_set_bias_level
,
4433 static int wm8994_probe(struct platform_device
*pdev
)
4435 struct wm8994_priv
*wm8994
;
4437 wm8994
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm8994_priv
),
4441 platform_set_drvdata(pdev
, wm8994
);
4443 wm8994
->wm8994
= dev_get_drvdata(pdev
->dev
.parent
);
4445 return snd_soc_register_codec(&pdev
->dev
, &soc_codec_dev_wm8994
,
4446 wm8994_dai
, ARRAY_SIZE(wm8994_dai
));
4449 static int wm8994_remove(struct platform_device
*pdev
)
4451 snd_soc_unregister_codec(&pdev
->dev
);
4455 #ifdef CONFIG_PM_SLEEP
4456 static int wm8994_suspend(struct device
*dev
)
4458 struct wm8994_priv
*wm8994
= dev_get_drvdata(dev
);
4460 /* Drop down to power saving mode when system is suspended */
4461 if (wm8994
->jackdet
&& !wm8994
->active_refcount
)
4462 regmap_update_bits(wm8994
->wm8994
->regmap
, WM8994_ANTIPOP_2
,
4463 WM1811_JACKDET_MODE_MASK
,
4464 wm8994
->jackdet_mode
);
4469 static int wm8994_resume(struct device
*dev
)
4471 struct wm8994_priv
*wm8994
= dev_get_drvdata(dev
);
4473 if (wm8994
->jackdet
&& wm8994
->jackdet_mode
)
4474 regmap_update_bits(wm8994
->wm8994
->regmap
, WM8994_ANTIPOP_2
,
4475 WM1811_JACKDET_MODE_MASK
,
4476 WM1811_JACKDET_MODE_AUDIO
);
4482 static const struct dev_pm_ops wm8994_pm_ops
= {
4483 SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend
, wm8994_resume
)
4486 static struct platform_driver wm8994_codec_driver
= {
4488 .name
= "wm8994-codec",
4489 .owner
= THIS_MODULE
,
4490 .pm
= &wm8994_pm_ops
,
4492 .probe
= wm8994_probe
,
4493 .remove
= wm8994_remove
,
4496 module_platform_driver(wm8994_codec_driver
);
4498 MODULE_DESCRIPTION("ASoC WM8994 driver");
4499 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4500 MODULE_LICENSE("GPL");
4501 MODULE_ALIAS("platform:wm8994-codec");