2 * wm_hubs.c -- WM8993/4 common code
4 * Copyright 2009-12 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/mfd/wm8994/registers.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/initval.h>
26 #include <sound/tlv.h>
31 const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv
, -300, 300, 0);
32 EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv
);
34 static const DECLARE_TLV_DB_SCALE(inpga_tlv
, -1650, 150, 0);
35 static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv
, 0, 3000, 0);
36 static const DECLARE_TLV_DB_SCALE(inmix_tlv
, -1500, 300, 1);
37 static const DECLARE_TLV_DB_SCALE(earpiece_tlv
, -600, 600, 0);
38 static const DECLARE_TLV_DB_SCALE(outmix_tlv
, -2100, 300, 0);
39 static const DECLARE_TLV_DB_SCALE(spkmixout_tlv
, -1800, 600, 1);
40 static const DECLARE_TLV_DB_SCALE(outpga_tlv
, -5700, 100, 0);
41 static const unsigned int spkboost_tlv
[] = {
43 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
44 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
46 static const DECLARE_TLV_DB_SCALE(line_tlv
, -600, 600, 0);
48 static const char *speaker_ref_text
[] = {
53 static const struct soc_enum speaker_ref
=
54 SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER
, 8, 2, speaker_ref_text
);
56 static const char *speaker_mode_text
[] = {
61 static const struct soc_enum speaker_mode
=
62 SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION
, 8, 2, speaker_mode_text
);
64 static void wait_for_dc_servo(struct snd_soc_codec
*codec
, unsigned int op
)
66 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
72 val
= op
| WM8993_DCS_ENA_CHAN_0
| WM8993_DCS_ENA_CHAN_1
;
74 /* Trigger the command */
75 snd_soc_write(codec
, WM8993_DC_SERVO_0
, val
);
77 dev_dbg(codec
->dev
, "Waiting for DC servo...\n");
79 if (hubs
->dcs_done_irq
)
87 if (hubs
->dcs_done_irq
)
88 wait_for_completion_timeout(&hubs
->dcs_done
,
89 msecs_to_jiffies(250));
93 reg
= snd_soc_read(codec
, WM8993_DC_SERVO_0
);
94 dev_dbg(codec
->dev
, "DC servo: %x\n", reg
);
95 } while (reg
& op
&& count
< timeout
);
98 dev_err(codec
->dev
, "Timed out waiting for DC Servo %x\n",
102 irqreturn_t
wm_hubs_dcs_done(int irq
, void *data
)
104 struct wm_hubs_data
*hubs
= data
;
106 complete(&hubs
->dcs_done
);
110 EXPORT_SYMBOL_GPL(wm_hubs_dcs_done
);
112 static bool wm_hubs_dac_hp_direct(struct snd_soc_codec
*codec
)
116 /* If we're going via the mixer we'll need to do additional checks */
117 reg
= snd_soc_read(codec
, WM8993_OUTPUT_MIXER1
);
118 if (!(reg
& WM8993_DACL_TO_HPOUT1L
)) {
119 if (reg
& ~WM8993_DACL_TO_MIXOUTL
) {
120 dev_vdbg(codec
->dev
, "Analogue paths connected: %x\n",
121 reg
& ~WM8993_DACL_TO_HPOUT1L
);
124 dev_vdbg(codec
->dev
, "HPL connected to mixer\n");
127 dev_vdbg(codec
->dev
, "HPL connected to DAC\n");
130 reg
= snd_soc_read(codec
, WM8993_OUTPUT_MIXER2
);
131 if (!(reg
& WM8993_DACR_TO_HPOUT1R
)) {
132 if (reg
& ~WM8993_DACR_TO_MIXOUTR
) {
133 dev_vdbg(codec
->dev
, "Analogue paths connected: %x\n",
134 reg
& ~WM8993_DACR_TO_HPOUT1R
);
137 dev_vdbg(codec
->dev
, "HPR connected to mixer\n");
140 dev_vdbg(codec
->dev
, "HPR connected to DAC\n");
146 struct wm_hubs_dcs_cache
{
147 struct list_head list
;
153 static bool wm_hubs_dcs_cache_get(struct snd_soc_codec
*codec
,
154 struct wm_hubs_dcs_cache
**entry
)
156 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
157 struct wm_hubs_dcs_cache
*cache
;
158 unsigned int left
, right
;
160 left
= snd_soc_read(codec
, WM8993_LEFT_OUTPUT_VOLUME
);
161 left
&= WM8993_HPOUT1L_VOL_MASK
;
163 right
= snd_soc_read(codec
, WM8993_RIGHT_OUTPUT_VOLUME
);
164 right
&= WM8993_HPOUT1R_VOL_MASK
;
166 list_for_each_entry(cache
, &hubs
->dcs_cache
, list
) {
167 if (cache
->left
!= left
|| cache
->right
!= right
)
177 static void wm_hubs_dcs_cache_set(struct snd_soc_codec
*codec
, u16 dcs_cfg
)
179 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
180 struct wm_hubs_dcs_cache
*cache
;
182 if (hubs
->no_cache_dac_hp_direct
)
185 cache
= devm_kzalloc(codec
->dev
, sizeof(*cache
), GFP_KERNEL
);
187 dev_err(codec
->dev
, "Failed to allocate DCS cache entry\n");
191 cache
->left
= snd_soc_read(codec
, WM8993_LEFT_OUTPUT_VOLUME
);
192 cache
->left
&= WM8993_HPOUT1L_VOL_MASK
;
194 cache
->right
= snd_soc_read(codec
, WM8993_RIGHT_OUTPUT_VOLUME
);
195 cache
->right
&= WM8993_HPOUT1R_VOL_MASK
;
197 cache
->dcs_cfg
= dcs_cfg
;
199 list_add_tail(&cache
->list
, &hubs
->dcs_cache
);
203 * Startup calibration of the DC servo
205 static void calibrate_dc_servo(struct snd_soc_codec
*codec
)
207 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
208 struct wm_hubs_dcs_cache
*cache
;
210 u16 reg
, reg_l
, reg_r
, dcs_cfg
, dcs_reg
;
212 switch (hubs
->dcs_readback_mode
) {
214 dcs_reg
= WM8994_DC_SERVO_4E
;
217 dcs_reg
= WM8993_DC_SERVO_3
;
221 /* If we're using a digital only path and have a previously
222 * callibrated DC servo offset stored then use that. */
223 if (wm_hubs_dac_hp_direct(codec
) &&
224 wm_hubs_dcs_cache_get(codec
, &cache
)) {
225 dev_dbg(codec
->dev
, "Using cached DCS offset %x for %d,%d\n",
226 cache
->dcs_cfg
, cache
->left
, cache
->right
);
227 snd_soc_write(codec
, dcs_reg
, cache
->dcs_cfg
);
228 wait_for_dc_servo(codec
,
229 WM8993_DCS_TRIG_DAC_WR_0
|
230 WM8993_DCS_TRIG_DAC_WR_1
);
234 if (hubs
->series_startup
) {
235 /* Set for 32 series updates */
236 snd_soc_update_bits(codec
, WM8993_DC_SERVO_1
,
237 WM8993_DCS_SERIES_NO_01_MASK
,
238 32 << WM8993_DCS_SERIES_NO_01_SHIFT
);
239 wait_for_dc_servo(codec
,
240 WM8993_DCS_TRIG_SERIES_0
|
241 WM8993_DCS_TRIG_SERIES_1
);
243 wait_for_dc_servo(codec
,
244 WM8993_DCS_TRIG_STARTUP_0
|
245 WM8993_DCS_TRIG_STARTUP_1
);
248 /* Different chips in the family support different readback
251 switch (hubs
->dcs_readback_mode
) {
253 reg_l
= snd_soc_read(codec
, WM8993_DC_SERVO_READBACK_1
)
254 & WM8993_DCS_INTEG_CHAN_0_MASK
;
255 reg_r
= snd_soc_read(codec
, WM8993_DC_SERVO_READBACK_2
)
256 & WM8993_DCS_INTEG_CHAN_1_MASK
;
260 reg
= snd_soc_read(codec
, dcs_reg
);
261 reg_r
= (reg
& WM8993_DCS_DAC_WR_VAL_1_MASK
)
262 >> WM8993_DCS_DAC_WR_VAL_1_SHIFT
;
263 reg_l
= reg
& WM8993_DCS_DAC_WR_VAL_0_MASK
;
266 WARN(1, "Unknown DCS readback method\n");
270 dev_dbg(codec
->dev
, "DCS input: %x %x\n", reg_l
, reg_r
);
272 /* Apply correction to DC servo result */
273 if (hubs
->dcs_codes_l
|| hubs
->dcs_codes_r
) {
275 "Applying %d/%d code DC servo correction\n",
276 hubs
->dcs_codes_l
, hubs
->dcs_codes_r
);
280 offset
+= hubs
->dcs_codes_r
;
281 dcs_cfg
= (u8
)offset
<< WM8993_DCS_DAC_WR_VAL_1_SHIFT
;
285 offset
+= hubs
->dcs_codes_l
;
286 dcs_cfg
|= (u8
)offset
;
288 dev_dbg(codec
->dev
, "DCS result: %x\n", dcs_cfg
);
291 snd_soc_write(codec
, dcs_reg
, dcs_cfg
);
292 wait_for_dc_servo(codec
,
293 WM8993_DCS_TRIG_DAC_WR_0
|
294 WM8993_DCS_TRIG_DAC_WR_1
);
296 dcs_cfg
= reg_r
<< WM8993_DCS_DAC_WR_VAL_1_SHIFT
;
300 /* Save the callibrated offset if we're in class W mode and
301 * therefore don't have any analogue signal mixed in. */
302 if (wm_hubs_dac_hp_direct(codec
))
303 wm_hubs_dcs_cache_set(codec
, dcs_cfg
);
307 * Update the DC servo calibration on gain changes
309 static int wm8993_put_dc_servo(struct snd_kcontrol
*kcontrol
,
310 struct snd_ctl_elem_value
*ucontrol
)
312 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
313 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
316 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
318 /* If we're applying an offset correction then updating the
319 * callibration would be likely to introduce further offsets. */
320 if (hubs
->dcs_codes_l
|| hubs
->dcs_codes_r
|| hubs
->no_series_update
)
323 /* Only need to do this if the outputs are active */
324 if (snd_soc_read(codec
, WM8993_POWER_MANAGEMENT_1
)
325 & (WM8993_HPOUT1L_ENA
| WM8993_HPOUT1R_ENA
))
326 snd_soc_update_bits(codec
,
328 WM8993_DCS_TRIG_SINGLE_0
|
329 WM8993_DCS_TRIG_SINGLE_1
,
330 WM8993_DCS_TRIG_SINGLE_0
|
331 WM8993_DCS_TRIG_SINGLE_1
);
336 static const struct snd_kcontrol_new analogue_snd_controls
[] = {
337 SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME
, 0, 31, 0,
339 SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME
, 7, 1, 1),
340 SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME
, 6, 1, 0),
342 SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME
, 0, 31, 0,
344 SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME
, 7, 1, 1),
345 SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME
, 6, 1, 0),
348 SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME
, 0, 31, 0,
350 SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME
, 7, 1, 1),
351 SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME
, 6, 1, 0),
353 SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME
, 0, 31, 0,
355 SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME
, 7, 1, 1),
356 SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME
, 6, 1, 0),
358 SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3
, 7, 1, 0,
360 SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3
, 4, 1, 0,
362 SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3
, 0, 7, 0,
364 SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5
, 6, 7, 0, inmix_tlv
),
365 SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5
, 0, 6, 0,
368 SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4
, 7, 1, 0,
370 SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4
, 4, 1, 0,
372 SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4
, 0, 7, 0,
374 SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6
, 6, 7, 0, inmix_tlv
),
375 SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6
, 0, 6, 0,
378 SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5
, 6, 7, 1,
380 SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3
, 6, 7, 1,
382 SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3
, 9, 7, 1,
384 SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3
, 0, 7, 1,
386 SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3
, 3, 7, 1,
388 SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
389 WM8993_OUTPUT_MIXER5
, 3, 7, 1, outmix_tlv
),
390 SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
391 WM8993_OUTPUT_MIXER5
, 0, 7, 1, outmix_tlv
),
392 SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5
, 9, 7, 1,
395 SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
396 WM8993_OUTPUT_MIXER6
, 6, 7, 1, outmix_tlv
),
397 SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
398 WM8993_OUTPUT_MIXER4
, 6, 7, 1, outmix_tlv
),
399 SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
400 WM8993_OUTPUT_MIXER4
, 3, 7, 1, outmix_tlv
),
401 SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
402 WM8993_OUTPUT_MIXER4
, 0, 7, 1, outmix_tlv
),
403 SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
404 WM8993_OUTPUT_MIXER4
, 9, 7, 1, outmix_tlv
),
405 SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
406 WM8993_OUTPUT_MIXER6
, 3, 7, 1, outmix_tlv
),
407 SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
408 WM8993_OUTPUT_MIXER6
, 6, 7, 1, outmix_tlv
),
409 SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
410 WM8993_OUTPUT_MIXER6
, 9, 7, 1, outmix_tlv
),
412 SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME
,
413 WM8993_RIGHT_OPGA_VOLUME
, 0, 63, 0, outpga_tlv
),
414 SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME
,
415 WM8993_RIGHT_OPGA_VOLUME
, 6, 1, 0),
416 SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME
,
417 WM8993_RIGHT_OPGA_VOLUME
, 7, 1, 0),
419 SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME
, 5, 1, 1),
420 SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME
, 4, 1, 1, earpiece_tlv
),
422 SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION
,
423 5, 1, 1, wm_hubs_spkmix_tlv
),
424 SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION
,
425 4, 1, 1, wm_hubs_spkmix_tlv
),
426 SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION
,
427 3, 1, 1, wm_hubs_spkmix_tlv
),
429 SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION
,
430 5, 1, 1, wm_hubs_spkmix_tlv
),
431 SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION
,
432 4, 1, 1, wm_hubs_spkmix_tlv
),
433 SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION
,
434 3, 1, 1, wm_hubs_spkmix_tlv
),
436 SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
437 WM8993_SPKMIXL_ATTENUATION
, WM8993_SPKMIXR_ATTENUATION
,
438 0, 3, 1, spkmixout_tlv
),
439 SOC_DOUBLE_R_TLV("Speaker Volume",
440 WM8993_SPEAKER_VOLUME_LEFT
, WM8993_SPEAKER_VOLUME_RIGHT
,
441 0, 63, 0, outpga_tlv
),
442 SOC_DOUBLE_R("Speaker Switch",
443 WM8993_SPEAKER_VOLUME_LEFT
, WM8993_SPEAKER_VOLUME_RIGHT
,
445 SOC_DOUBLE_R("Speaker ZC Switch",
446 WM8993_SPEAKER_VOLUME_LEFT
, WM8993_SPEAKER_VOLUME_RIGHT
,
448 SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST
, 3, 0, 7, 0,
450 SOC_ENUM("Speaker Reference", speaker_ref
),
451 SOC_ENUM("Speaker Mode", speaker_mode
),
453 SOC_DOUBLE_R_EXT_TLV("Headphone Volume",
454 WM8993_LEFT_OUTPUT_VOLUME
, WM8993_RIGHT_OUTPUT_VOLUME
,
455 0, 63, 0, snd_soc_get_volsw
, wm8993_put_dc_servo
,
458 SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME
,
459 WM8993_RIGHT_OUTPUT_VOLUME
, 6, 1, 0),
460 SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME
,
461 WM8993_RIGHT_OUTPUT_VOLUME
, 7, 1, 0),
463 SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME
, 6, 1, 1),
464 SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME
, 5, 1, 1),
465 SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME
, 4, 1, 1,
468 SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME
, 2, 1, 1),
469 SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME
, 1, 1, 1),
470 SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME
, 0, 1, 1,
474 static int hp_supply_event(struct snd_soc_dapm_widget
*w
,
475 struct snd_kcontrol
*kcontrol
, int event
)
477 struct snd_soc_codec
*codec
= w
->codec
;
478 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
481 case SND_SOC_DAPM_PRE_PMU
:
482 switch (hubs
->hp_startup_mode
) {
486 /* Enable the headphone amp */
487 snd_soc_update_bits(codec
, WM8993_POWER_MANAGEMENT_1
,
493 /* Enable the second stage */
494 snd_soc_update_bits(codec
, WM8993_ANALOGUE_HP_0
,
501 dev_err(codec
->dev
, "Unknown HP startup mode %d\n",
502 hubs
->hp_startup_mode
);
506 case SND_SOC_DAPM_PRE_PMD
:
507 snd_soc_update_bits(codec
, WM8993_CHARGE_PUMP_1
,
515 static int hp_event(struct snd_soc_dapm_widget
*w
,
516 struct snd_kcontrol
*kcontrol
, int event
)
518 struct snd_soc_codec
*codec
= w
->codec
;
519 unsigned int reg
= snd_soc_read(codec
, WM8993_ANALOGUE_HP_0
);
522 case SND_SOC_DAPM_POST_PMU
:
523 snd_soc_update_bits(codec
, WM8993_CHARGE_PUMP_1
,
524 WM8993_CP_ENA
, WM8993_CP_ENA
);
528 snd_soc_update_bits(codec
, WM8993_POWER_MANAGEMENT_1
,
529 WM8993_HPOUT1L_ENA
| WM8993_HPOUT1R_ENA
,
530 WM8993_HPOUT1L_ENA
| WM8993_HPOUT1R_ENA
);
532 reg
|= WM8993_HPOUT1L_DLY
| WM8993_HPOUT1R_DLY
;
533 snd_soc_write(codec
, WM8993_ANALOGUE_HP_0
, reg
);
535 snd_soc_update_bits(codec
, WM8993_DC_SERVO_1
,
536 WM8993_DCS_TIMER_PERIOD_01_MASK
, 0);
538 calibrate_dc_servo(codec
);
540 reg
|= WM8993_HPOUT1R_OUTP
| WM8993_HPOUT1R_RMV_SHORT
|
541 WM8993_HPOUT1L_OUTP
| WM8993_HPOUT1L_RMV_SHORT
;
542 snd_soc_write(codec
, WM8993_ANALOGUE_HP_0
, reg
);
545 case SND_SOC_DAPM_PRE_PMD
:
546 snd_soc_update_bits(codec
, WM8993_ANALOGUE_HP_0
,
547 WM8993_HPOUT1L_OUTP
|
548 WM8993_HPOUT1R_OUTP
|
549 WM8993_HPOUT1L_RMV_SHORT
|
550 WM8993_HPOUT1R_RMV_SHORT
, 0);
552 snd_soc_update_bits(codec
, WM8993_ANALOGUE_HP_0
,
554 WM8993_HPOUT1R_DLY
, 0);
556 snd_soc_write(codec
, WM8993_DC_SERVO_0
, 0);
558 snd_soc_update_bits(codec
, WM8993_POWER_MANAGEMENT_1
,
559 WM8993_HPOUT1L_ENA
| WM8993_HPOUT1R_ENA
,
567 static int earpiece_event(struct snd_soc_dapm_widget
*w
,
568 struct snd_kcontrol
*control
, int event
)
570 struct snd_soc_codec
*codec
= w
->codec
;
571 u16 reg
= snd_soc_read(codec
, WM8993_ANTIPOP1
) & ~WM8993_HPOUT2_IN_ENA
;
574 case SND_SOC_DAPM_PRE_PMU
:
575 reg
|= WM8993_HPOUT2_IN_ENA
;
576 snd_soc_write(codec
, WM8993_ANTIPOP1
, reg
);
580 case SND_SOC_DAPM_POST_PMD
:
581 snd_soc_write(codec
, WM8993_ANTIPOP1
, reg
);
592 static int lineout_event(struct snd_soc_dapm_widget
*w
,
593 struct snd_kcontrol
*control
, int event
)
595 struct snd_soc_codec
*codec
= w
->codec
;
596 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
600 case WM8993_LINEOUT1N_ENA_SHIFT
:
601 flag
= &hubs
->lineout1n_ena
;
603 case WM8993_LINEOUT1P_ENA_SHIFT
:
604 flag
= &hubs
->lineout1p_ena
;
606 case WM8993_LINEOUT2N_ENA_SHIFT
:
607 flag
= &hubs
->lineout2n_ena
;
609 case WM8993_LINEOUT2P_ENA_SHIFT
:
610 flag
= &hubs
->lineout2p_ena
;
613 WARN(1, "Unknown line output");
617 *flag
= SND_SOC_DAPM_EVENT_ON(event
);
622 void wm_hubs_update_class_w(struct snd_soc_codec
*codec
)
624 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
625 int enable
= WM8993_CP_DYN_V
| WM8993_CP_DYN_FREQ
;
627 if (!wm_hubs_dac_hp_direct(codec
))
630 if (hubs
->check_class_w_digital
&& !hubs
->check_class_w_digital(codec
))
633 dev_vdbg(codec
->dev
, "Class W %s\n", enable
? "enabled" : "disabled");
635 snd_soc_update_bits(codec
, WM8993_CLASS_W_0
,
636 WM8993_CP_DYN_V
| WM8993_CP_DYN_FREQ
, enable
);
638 EXPORT_SYMBOL_GPL(wm_hubs_update_class_w
);
640 #define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \
641 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
642 .info = snd_soc_info_volsw, \
643 .get = snd_soc_dapm_get_volsw, .put = class_w_put_volsw, \
644 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
646 static int class_w_put_volsw(struct snd_kcontrol
*kcontrol
,
647 struct snd_ctl_elem_value
*ucontrol
)
649 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
650 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
651 struct snd_soc_codec
*codec
= widget
->codec
;
654 ret
= snd_soc_dapm_put_volsw(kcontrol
, ucontrol
);
656 wm_hubs_update_class_w(codec
);
661 #define WM_HUBS_ENUM_W(xname, xenum) \
662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
663 .info = snd_soc_info_enum_double, \
664 .get = snd_soc_dapm_get_enum_double, \
665 .put = class_w_put_double, \
666 .private_value = (unsigned long)&xenum }
668 static int class_w_put_double(struct snd_kcontrol
*kcontrol
,
669 struct snd_ctl_elem_value
*ucontrol
)
671 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
672 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
673 struct snd_soc_codec
*codec
= widget
->codec
;
676 ret
= snd_soc_dapm_put_enum_double(kcontrol
, ucontrol
);
678 wm_hubs_update_class_w(codec
);
683 static const char *hp_mux_text
[] = {
688 static const struct soc_enum hpl_enum
=
689 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1
, 8, 2, hp_mux_text
);
691 const struct snd_kcontrol_new wm_hubs_hpl_mux
=
692 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum
);
693 EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux
);
695 static const struct soc_enum hpr_enum
=
696 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2
, 8, 2, hp_mux_text
);
698 const struct snd_kcontrol_new wm_hubs_hpr_mux
=
699 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum
);
700 EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux
);
702 static const struct snd_kcontrol_new in1l_pga
[] = {
703 SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2
, 5, 1, 0),
704 SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2
, 4, 1, 0),
707 static const struct snd_kcontrol_new in1r_pga
[] = {
708 SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2
, 1, 1, 0),
709 SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2
, 0, 1, 0),
712 static const struct snd_kcontrol_new in2l_pga
[] = {
713 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2
, 7, 1, 0),
714 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2
, 6, 1, 0),
717 static const struct snd_kcontrol_new in2r_pga
[] = {
718 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2
, 3, 1, 0),
719 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2
, 2, 1, 0),
722 static const struct snd_kcontrol_new mixinl
[] = {
723 SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3
, 8, 1, 0),
724 SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3
, 5, 1, 0),
727 static const struct snd_kcontrol_new mixinr
[] = {
728 SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4
, 8, 1, 0),
729 SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4
, 5, 1, 0),
732 static const struct snd_kcontrol_new left_output_mixer
[] = {
733 WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1
, 7, 1, 0),
734 WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1
, 6, 1, 0),
735 WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1
, 5, 1, 0),
736 WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1
, 4, 1, 0),
737 WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1
, 1, 1, 0),
738 WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1
, 3, 1, 0),
739 WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1
, 2, 1, 0),
740 WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1
, 0, 1, 0),
743 static const struct snd_kcontrol_new right_output_mixer
[] = {
744 WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2
, 7, 1, 0),
745 WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2
, 6, 1, 0),
746 WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2
, 5, 1, 0),
747 WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2
, 4, 1, 0),
748 WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2
, 3, 1, 0),
749 WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2
, 2, 1, 0),
750 WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2
, 1, 1, 0),
751 WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2
, 0, 1, 0),
754 static const struct snd_kcontrol_new earpiece_mixer
[] = {
755 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER
, 5, 1, 0),
756 SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER
, 4, 1, 0),
757 SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER
, 3, 1, 0),
760 static const struct snd_kcontrol_new left_speaker_boost
[] = {
761 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS
, 5, 1, 0),
762 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS
, 4, 1, 0),
763 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS
, 3, 1, 0),
766 static const struct snd_kcontrol_new right_speaker_boost
[] = {
767 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS
, 2, 1, 0),
768 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS
, 1, 1, 0),
769 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS
, 0, 1, 0),
772 static const struct snd_kcontrol_new line1_mix
[] = {
773 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1
, 2, 1, 0),
774 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1
, 1, 1, 0),
775 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1
, 0, 1, 0),
778 static const struct snd_kcontrol_new line1n_mix
[] = {
779 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1
, 6, 1, 0),
780 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1
, 5, 1, 0),
783 static const struct snd_kcontrol_new line1p_mix
[] = {
784 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1
, 0, 1, 0),
787 static const struct snd_kcontrol_new line2_mix
[] = {
788 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER2
, 2, 1, 0),
789 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER2
, 1, 1, 0),
790 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2
, 0, 1, 0),
793 static const struct snd_kcontrol_new line2n_mix
[] = {
794 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2
, 5, 1, 0),
795 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2
, 6, 1, 0),
798 static const struct snd_kcontrol_new line2p_mix
[] = {
799 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2
, 0, 1, 0),
802 static const struct snd_soc_dapm_widget analogue_dapm_widgets
[] = {
803 SND_SOC_DAPM_INPUT("IN1LN"),
804 SND_SOC_DAPM_INPUT("IN1LP"),
805 SND_SOC_DAPM_INPUT("IN2LN"),
806 SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
807 SND_SOC_DAPM_INPUT("IN1RN"),
808 SND_SOC_DAPM_INPUT("IN1RP"),
809 SND_SOC_DAPM_INPUT("IN2RN"),
810 SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
812 SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8993_POWER_MANAGEMENT_1
, 5, 0, NULL
, 0),
813 SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8993_POWER_MANAGEMENT_1
, 4, 0, NULL
, 0),
815 SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2
, 6, 0,
816 in1l_pga
, ARRAY_SIZE(in1l_pga
)),
817 SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2
, 4, 0,
818 in1r_pga
, ARRAY_SIZE(in1r_pga
)),
820 SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2
, 7, 0,
821 in2l_pga
, ARRAY_SIZE(in2l_pga
)),
822 SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2
, 5, 0,
823 in2r_pga
, ARRAY_SIZE(in2r_pga
)),
825 SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2
, 9, 0,
826 mixinl
, ARRAY_SIZE(mixinl
)),
827 SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2
, 8, 0,
828 mixinr
, ARRAY_SIZE(mixinr
)),
830 SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3
, 5, 0,
831 left_output_mixer
, ARRAY_SIZE(left_output_mixer
)),
832 SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3
, 4, 0,
833 right_output_mixer
, ARRAY_SIZE(right_output_mixer
)),
835 SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3
, 7, 0, NULL
, 0),
836 SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3
, 6, 0, NULL
, 0),
838 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM
, 0, 0, hp_supply_event
,
839 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_PRE_PMD
),
840 SND_SOC_DAPM_OUT_DRV_E("Headphone PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
841 hp_event
, SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
843 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM
, 0, 0,
844 earpiece_mixer
, ARRAY_SIZE(earpiece_mixer
)),
845 SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1
, 11, 0,
846 NULL
, 0, earpiece_event
,
847 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
849 SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM
, 0, 0,
850 left_speaker_boost
, ARRAY_SIZE(left_speaker_boost
)),
851 SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM
, 0, 0,
852 right_speaker_boost
, ARRAY_SIZE(right_speaker_boost
)),
854 SND_SOC_DAPM_SUPPLY("TSHUT", WM8993_POWER_MANAGEMENT_2
, 14, 0, NULL
, 0),
855 SND_SOC_DAPM_OUT_DRV("SPKL Driver", WM8993_POWER_MANAGEMENT_1
, 12, 0,
857 SND_SOC_DAPM_OUT_DRV("SPKR Driver", WM8993_POWER_MANAGEMENT_1
, 13, 0,
860 SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM
, 0, 0,
861 line1_mix
, ARRAY_SIZE(line1_mix
)),
862 SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM
, 0, 0,
863 line2_mix
, ARRAY_SIZE(line2_mix
)),
865 SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM
, 0, 0,
866 line1n_mix
, ARRAY_SIZE(line1n_mix
)),
867 SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM
, 0, 0,
868 line1p_mix
, ARRAY_SIZE(line1p_mix
)),
869 SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM
, 0, 0,
870 line2n_mix
, ARRAY_SIZE(line2n_mix
)),
871 SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM
, 0, 0,
872 line2p_mix
, ARRAY_SIZE(line2p_mix
)),
874 SND_SOC_DAPM_OUT_DRV_E("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3
, 13, 0,
875 NULL
, 0, lineout_event
,
876 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
877 SND_SOC_DAPM_OUT_DRV_E("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3
, 12, 0,
878 NULL
, 0, lineout_event
,
879 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
880 SND_SOC_DAPM_OUT_DRV_E("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3
, 11, 0,
881 NULL
, 0, lineout_event
,
882 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
883 SND_SOC_DAPM_OUT_DRV_E("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3
, 10, 0,
884 NULL
, 0, lineout_event
,
885 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
887 SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
888 SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
889 SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
890 SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
891 SND_SOC_DAPM_OUTPUT("HPOUT1L"),
892 SND_SOC_DAPM_OUTPUT("HPOUT1R"),
893 SND_SOC_DAPM_OUTPUT("HPOUT2P"),
894 SND_SOC_DAPM_OUTPUT("HPOUT2N"),
895 SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
896 SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
897 SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
898 SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
901 static const struct snd_soc_dapm_route analogue_routes
[] = {
902 { "MICBIAS1", NULL
, "CLK_SYS" },
903 { "MICBIAS2", NULL
, "CLK_SYS" },
905 { "IN1L PGA", "IN1LP Switch", "IN1LP" },
906 { "IN1L PGA", "IN1LN Switch", "IN1LN" },
908 { "IN1L PGA", NULL
, "VMID" },
909 { "IN1R PGA", NULL
, "VMID" },
910 { "IN2L PGA", NULL
, "VMID" },
911 { "IN2R PGA", NULL
, "VMID" },
913 { "IN1R PGA", "IN1RP Switch", "IN1RP" },
914 { "IN1R PGA", "IN1RN Switch", "IN1RN" },
916 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
917 { "IN2L PGA", "IN2LN Switch", "IN2LN" },
919 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
920 { "IN2R PGA", "IN2RN Switch", "IN2RN" },
922 { "Direct Voice", NULL
, "IN2LP:VXRN" },
923 { "Direct Voice", NULL
, "IN2RP:VXRP" },
925 { "MIXINL", "IN1L Switch", "IN1L PGA" },
926 { "MIXINL", "IN2L Switch", "IN2L PGA" },
927 { "MIXINL", NULL
, "Direct Voice" },
928 { "MIXINL", NULL
, "IN1LP" },
929 { "MIXINL", NULL
, "Left Output Mixer" },
930 { "MIXINL", NULL
, "VMID" },
932 { "MIXINR", "IN1R Switch", "IN1R PGA" },
933 { "MIXINR", "IN2R Switch", "IN2R PGA" },
934 { "MIXINR", NULL
, "Direct Voice" },
935 { "MIXINR", NULL
, "IN1RP" },
936 { "MIXINR", NULL
, "Right Output Mixer" },
937 { "MIXINR", NULL
, "VMID" },
939 { "ADCL", NULL
, "MIXINL" },
940 { "ADCR", NULL
, "MIXINR" },
942 { "Left Output Mixer", "Left Input Switch", "MIXINL" },
943 { "Left Output Mixer", "Right Input Switch", "MIXINR" },
944 { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
945 { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
946 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
947 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
948 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
950 { "Right Output Mixer", "Left Input Switch", "MIXINL" },
951 { "Right Output Mixer", "Right Input Switch", "MIXINR" },
952 { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
953 { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
954 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
955 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
956 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
958 { "Left Output PGA", NULL
, "Left Output Mixer" },
959 { "Left Output PGA", NULL
, "TOCLK" },
961 { "Right Output PGA", NULL
, "Right Output Mixer" },
962 { "Right Output PGA", NULL
, "TOCLK" },
964 { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
965 { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
966 { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
968 { "Earpiece Driver", NULL
, "VMID" },
969 { "Earpiece Driver", NULL
, "Earpiece Mixer" },
970 { "HPOUT2N", NULL
, "Earpiece Driver" },
971 { "HPOUT2P", NULL
, "Earpiece Driver" },
973 { "SPKL", "Input Switch", "MIXINL" },
974 { "SPKL", "IN1LP Switch", "IN1LP" },
975 { "SPKL", "Output Switch", "Left Output PGA" },
976 { "SPKL", NULL
, "TOCLK" },
978 { "SPKR", "Input Switch", "MIXINR" },
979 { "SPKR", "IN1RP Switch", "IN1RP" },
980 { "SPKR", "Output Switch", "Right Output PGA" },
981 { "SPKR", NULL
, "TOCLK" },
983 { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
984 { "SPKL Boost", "SPKL Switch", "SPKL" },
985 { "SPKL Boost", "SPKR Switch", "SPKR" },
987 { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
988 { "SPKR Boost", "SPKR Switch", "SPKR" },
989 { "SPKR Boost", "SPKL Switch", "SPKL" },
991 { "SPKL Driver", NULL
, "VMID" },
992 { "SPKL Driver", NULL
, "SPKL Boost" },
993 { "SPKL Driver", NULL
, "CLK_SYS" },
994 { "SPKL Driver", NULL
, "TSHUT" },
996 { "SPKR Driver", NULL
, "VMID" },
997 { "SPKR Driver", NULL
, "SPKR Boost" },
998 { "SPKR Driver", NULL
, "CLK_SYS" },
999 { "SPKR Driver", NULL
, "TSHUT" },
1001 { "SPKOUTLP", NULL
, "SPKL Driver" },
1002 { "SPKOUTLN", NULL
, "SPKL Driver" },
1003 { "SPKOUTRP", NULL
, "SPKR Driver" },
1004 { "SPKOUTRN", NULL
, "SPKR Driver" },
1006 { "Left Headphone Mux", "Mixer", "Left Output PGA" },
1007 { "Right Headphone Mux", "Mixer", "Right Output PGA" },
1009 { "Headphone PGA", NULL
, "Left Headphone Mux" },
1010 { "Headphone PGA", NULL
, "Right Headphone Mux" },
1011 { "Headphone PGA", NULL
, "VMID" },
1012 { "Headphone PGA", NULL
, "CLK_SYS" },
1013 { "Headphone PGA", NULL
, "Headphone Supply" },
1015 { "HPOUT1L", NULL
, "Headphone PGA" },
1016 { "HPOUT1R", NULL
, "Headphone PGA" },
1018 { "LINEOUT1N Driver", NULL
, "VMID" },
1019 { "LINEOUT1P Driver", NULL
, "VMID" },
1020 { "LINEOUT2N Driver", NULL
, "VMID" },
1021 { "LINEOUT2P Driver", NULL
, "VMID" },
1023 { "LINEOUT1N", NULL
, "LINEOUT1N Driver" },
1024 { "LINEOUT1P", NULL
, "LINEOUT1P Driver" },
1025 { "LINEOUT2N", NULL
, "LINEOUT2N Driver" },
1026 { "LINEOUT2P", NULL
, "LINEOUT2P Driver" },
1029 static const struct snd_soc_dapm_route lineout1_diff_routes
[] = {
1030 { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
1031 { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
1032 { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" },
1034 { "LINEOUT1N Driver", NULL
, "LINEOUT1 Mixer" },
1035 { "LINEOUT1P Driver", NULL
, "LINEOUT1 Mixer" },
1038 static const struct snd_soc_dapm_route lineout1_se_routes
[] = {
1039 { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" },
1040 { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" },
1042 { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" },
1044 { "LINEOUT1N Driver", NULL
, "LINEOUT1N Mixer" },
1045 { "LINEOUT1P Driver", NULL
, "LINEOUT1P Mixer" },
1048 static const struct snd_soc_dapm_route lineout2_diff_routes
[] = {
1049 { "LINEOUT2 Mixer", "IN1L Switch", "IN1L PGA" },
1050 { "LINEOUT2 Mixer", "IN1R Switch", "IN1R PGA" },
1051 { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" },
1053 { "LINEOUT2N Driver", NULL
, "LINEOUT2 Mixer" },
1054 { "LINEOUT2P Driver", NULL
, "LINEOUT2 Mixer" },
1057 static const struct snd_soc_dapm_route lineout2_se_routes
[] = {
1058 { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" },
1059 { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" },
1061 { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" },
1063 { "LINEOUT2N Driver", NULL
, "LINEOUT2N Mixer" },
1064 { "LINEOUT2P Driver", NULL
, "LINEOUT2P Mixer" },
1067 int wm_hubs_add_analogue_controls(struct snd_soc_codec
*codec
)
1069 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
1071 /* Latch volume update bits & default ZC on */
1072 snd_soc_update_bits(codec
, WM8993_LEFT_LINE_INPUT_1_2_VOLUME
,
1073 WM8993_IN1_VU
, WM8993_IN1_VU
);
1074 snd_soc_update_bits(codec
, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME
,
1075 WM8993_IN1_VU
, WM8993_IN1_VU
);
1076 snd_soc_update_bits(codec
, WM8993_LEFT_LINE_INPUT_3_4_VOLUME
,
1077 WM8993_IN2_VU
, WM8993_IN2_VU
);
1078 snd_soc_update_bits(codec
, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME
,
1079 WM8993_IN2_VU
, WM8993_IN2_VU
);
1081 snd_soc_update_bits(codec
, WM8993_SPEAKER_VOLUME_LEFT
,
1082 WM8993_SPKOUT_VU
, WM8993_SPKOUT_VU
);
1083 snd_soc_update_bits(codec
, WM8993_SPEAKER_VOLUME_RIGHT
,
1084 WM8993_SPKOUT_VU
, WM8993_SPKOUT_VU
);
1086 snd_soc_update_bits(codec
, WM8993_LEFT_OUTPUT_VOLUME
,
1087 WM8993_HPOUT1_VU
| WM8993_HPOUT1L_ZC
,
1088 WM8993_HPOUT1_VU
| WM8993_HPOUT1L_ZC
);
1089 snd_soc_update_bits(codec
, WM8993_RIGHT_OUTPUT_VOLUME
,
1090 WM8993_HPOUT1_VU
| WM8993_HPOUT1R_ZC
,
1091 WM8993_HPOUT1_VU
| WM8993_HPOUT1R_ZC
);
1093 snd_soc_update_bits(codec
, WM8993_LEFT_OPGA_VOLUME
,
1094 WM8993_MIXOUTL_ZC
| WM8993_MIXOUT_VU
,
1095 WM8993_MIXOUTL_ZC
| WM8993_MIXOUT_VU
);
1096 snd_soc_update_bits(codec
, WM8993_RIGHT_OPGA_VOLUME
,
1097 WM8993_MIXOUTR_ZC
| WM8993_MIXOUT_VU
,
1098 WM8993_MIXOUTR_ZC
| WM8993_MIXOUT_VU
);
1100 snd_soc_add_codec_controls(codec
, analogue_snd_controls
,
1101 ARRAY_SIZE(analogue_snd_controls
));
1103 snd_soc_dapm_new_controls(dapm
, analogue_dapm_widgets
,
1104 ARRAY_SIZE(analogue_dapm_widgets
));
1107 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls
);
1109 int wm_hubs_add_analogue_routes(struct snd_soc_codec
*codec
,
1110 int lineout1_diff
, int lineout2_diff
)
1112 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
1113 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
1115 INIT_LIST_HEAD(&hubs
->dcs_cache
);
1116 init_completion(&hubs
->dcs_done
);
1118 snd_soc_dapm_add_routes(dapm
, analogue_routes
,
1119 ARRAY_SIZE(analogue_routes
));
1122 snd_soc_dapm_add_routes(dapm
,
1123 lineout1_diff_routes
,
1124 ARRAY_SIZE(lineout1_diff_routes
));
1126 snd_soc_dapm_add_routes(dapm
,
1128 ARRAY_SIZE(lineout1_se_routes
));
1131 snd_soc_dapm_add_routes(dapm
,
1132 lineout2_diff_routes
,
1133 ARRAY_SIZE(lineout2_diff_routes
));
1135 snd_soc_dapm_add_routes(dapm
,
1137 ARRAY_SIZE(lineout2_se_routes
));
1141 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes
);
1143 int wm_hubs_handle_analogue_pdata(struct snd_soc_codec
*codec
,
1144 int lineout1_diff
, int lineout2_diff
,
1145 int lineout1fb
, int lineout2fb
,
1146 int jd_scthr
, int jd_thr
, int micbias1_lvl
,
1149 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
1151 hubs
->lineout1_se
= !lineout1_diff
;
1152 hubs
->lineout2_se
= !lineout2_diff
;
1155 snd_soc_update_bits(codec
, WM8993_LINE_MIXER1
,
1156 WM8993_LINEOUT1_MODE
,
1157 WM8993_LINEOUT1_MODE
);
1159 snd_soc_update_bits(codec
, WM8993_LINE_MIXER2
,
1160 WM8993_LINEOUT2_MODE
,
1161 WM8993_LINEOUT2_MODE
);
1163 if (!lineout1_diff
&& !lineout2_diff
)
1164 snd_soc_update_bits(codec
, WM8993_ANTIPOP1
,
1165 WM8993_LINEOUT_VMID_BUF_ENA
,
1166 WM8993_LINEOUT_VMID_BUF_ENA
);
1169 snd_soc_update_bits(codec
, WM8993_ADDITIONAL_CONTROL
,
1170 WM8993_LINEOUT1_FB
, WM8993_LINEOUT1_FB
);
1173 snd_soc_update_bits(codec
, WM8993_ADDITIONAL_CONTROL
,
1174 WM8993_LINEOUT2_FB
, WM8993_LINEOUT2_FB
);
1176 snd_soc_update_bits(codec
, WM8993_MICBIAS
,
1177 WM8993_JD_SCTHR_MASK
| WM8993_JD_THR_MASK
|
1178 WM8993_MICB1_LVL
| WM8993_MICB2_LVL
,
1179 jd_scthr
<< WM8993_JD_SCTHR_SHIFT
|
1180 jd_thr
<< WM8993_JD_THR_SHIFT
|
1182 micbias2_lvl
<< WM8993_MICB2_LVL_SHIFT
);
1186 EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata
);
1188 void wm_hubs_vmid_ena(struct snd_soc_codec
*codec
)
1190 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
1193 if (hubs
->lineout1_se
)
1194 val
|= WM8993_LINEOUT1N_ENA
| WM8993_LINEOUT1P_ENA
;
1196 if (hubs
->lineout2_se
)
1197 val
|= WM8993_LINEOUT2N_ENA
| WM8993_LINEOUT2P_ENA
;
1199 /* Enable the line outputs while we power up */
1200 snd_soc_update_bits(codec
, WM8993_POWER_MANAGEMENT_3
, val
, val
);
1202 EXPORT_SYMBOL_GPL(wm_hubs_vmid_ena
);
1204 void wm_hubs_set_bias_level(struct snd_soc_codec
*codec
,
1205 enum snd_soc_bias_level level
)
1207 struct wm_hubs_data
*hubs
= snd_soc_codec_get_drvdata(codec
);
1211 case SND_SOC_BIAS_STANDBY
:
1212 /* Clamp the inputs to VMID while we ramp to charge caps */
1213 snd_soc_update_bits(codec
, WM8993_INPUTS_CLAMP_REG
,
1214 WM8993_INPUTS_CLAMP
, WM8993_INPUTS_CLAMP
);
1217 case SND_SOC_BIAS_ON
:
1218 /* Turn off any unneded single ended outputs */
1222 if (hubs
->lineout1_se
)
1223 mask
|= WM8993_LINEOUT1N_ENA
| WM8993_LINEOUT1P_ENA
;
1225 if (hubs
->lineout2_se
)
1226 mask
|= WM8993_LINEOUT2N_ENA
| WM8993_LINEOUT2P_ENA
;
1228 if (hubs
->lineout1_se
&& hubs
->lineout1n_ena
)
1229 val
|= WM8993_LINEOUT1N_ENA
;
1231 if (hubs
->lineout1_se
&& hubs
->lineout1p_ena
)
1232 val
|= WM8993_LINEOUT1P_ENA
;
1234 if (hubs
->lineout2_se
&& hubs
->lineout2n_ena
)
1235 val
|= WM8993_LINEOUT2N_ENA
;
1237 if (hubs
->lineout2_se
&& hubs
->lineout2p_ena
)
1238 val
|= WM8993_LINEOUT2P_ENA
;
1240 snd_soc_update_bits(codec
, WM8993_POWER_MANAGEMENT_3
,
1243 /* Remove the input clamps */
1244 snd_soc_update_bits(codec
, WM8993_INPUTS_CLAMP_REG
,
1245 WM8993_INPUTS_CLAMP
, 0);
1252 EXPORT_SYMBOL_GPL(wm_hubs_set_bias_level
);
1254 MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
1255 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1256 MODULE_LICENSE("GPL");