2 * wm_hubs.c -- WM8993/4 common code
4 * Copyright 2009 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26 #include <sound/initval.h>
27 #include <sound/tlv.h>
32 const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0);
33 EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv);
35 static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1650, 150, 0);
36 static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv, 0, 3000, 0);
37 static const DECLARE_TLV_DB_SCALE(inmix_tlv, -1500, 300, 1);
38 static const DECLARE_TLV_DB_SCALE(earpiece_tlv, -600, 600, 0);
39 static const DECLARE_TLV_DB_SCALE(outmix_tlv, -2100, 300, 0);
40 static const DECLARE_TLV_DB_SCALE(spkmixout_tlv, -1800, 600, 1);
41 static const DECLARE_TLV_DB_SCALE(outpga_tlv, -5700, 100, 0);
42 static const unsigned int spkboost_tlv[] = {
44 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
45 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
47 static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0);
49 static const char *speaker_ref_text[] = {
54 static const struct soc_enum speaker_ref =
55 SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text);
57 static const char *speaker_mode_text[] = {
62 static const struct soc_enum speaker_mode =
63 SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text);
65 static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
71 val = op | WM8993_DCS_ENA_CHAN_0 | WM8993_DCS_ENA_CHAN_1;
73 /* Trigger the command */
74 snd_soc_write(codec, WM8993_DC_SERVO_0, val);
76 dev_dbg(codec->dev, "Waiting for DC servo...\n");
81 reg = snd_soc_read(codec, WM8993_DC_SERVO_0);
82 dev_dbg(codec->dev, "DC servo: %x\n", reg);
83 } while (reg & op && count < 400);
86 dev_err(codec->dev, "Timed out waiting for DC Servo\n");
90 * Startup calibration of the DC servo
92 static void calibrate_dc_servo(struct snd_soc_codec *codec)
94 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
95 u16 reg, reg_l, reg_r, dcs_cfg;
97 /* Set for 32 series updates */
98 snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
99 WM8993_DCS_SERIES_NO_01_MASK,
100 32 << WM8993_DCS_SERIES_NO_01_SHIFT);
101 wait_for_dc_servo(codec,
102 WM8993_DCS_TRIG_SERIES_0 | WM8993_DCS_TRIG_SERIES_1);
104 /* Apply correction to DC servo result */
105 if (hubs->dcs_codes) {
106 dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
109 /* Different chips in the family support different
112 switch (hubs->dcs_readback_mode) {
114 reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1)
115 & WM8993_DCS_INTEG_CHAN_0_MASK;;
116 reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
117 & WM8993_DCS_INTEG_CHAN_1_MASK;
120 reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
121 reg_l = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
122 >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
123 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
126 WARN(1, "Unknown DCS readback method");
130 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
133 if (reg_l + hubs->dcs_codes > 0 &&
134 reg_l + hubs->dcs_codes < 0xff)
135 reg_l += hubs->dcs_codes;
136 dcs_cfg = reg_l << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
139 if (reg_r + hubs->dcs_codes > 0 &&
140 reg_r + hubs->dcs_codes < 0xff)
141 reg_r += hubs->dcs_codes;
144 dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
147 snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
148 wait_for_dc_servo(codec,
149 WM8993_DCS_TRIG_DAC_WR_0 |
150 WM8993_DCS_TRIG_DAC_WR_1);
155 * Update the DC servo calibration on gain changes
157 static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
158 struct snd_ctl_elem_value *ucontrol)
160 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
161 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
164 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
166 /* If we're applying an offset correction then updating the
167 * callibration would be likely to introduce further offsets. */
171 /* Only need to do this if the outputs are active */
172 if (snd_soc_read(codec, WM8993_POWER_MANAGEMENT_1)
173 & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA))
174 snd_soc_update_bits(codec,
176 WM8993_DCS_TRIG_SINGLE_0 |
177 WM8993_DCS_TRIG_SINGLE_1,
178 WM8993_DCS_TRIG_SINGLE_0 |
179 WM8993_DCS_TRIG_SINGLE_1);
184 static const struct snd_kcontrol_new analogue_snd_controls[] = {
185 SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
187 SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
188 SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
190 SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
192 SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
193 SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
196 SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
198 SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
199 SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
201 SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
203 SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
204 SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
206 SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
208 SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
210 SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
212 SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv),
213 SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0,
216 SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
218 SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
220 SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
222 SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv),
223 SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0,
226 SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
228 SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
230 SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
232 SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
234 SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
236 SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
237 WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv),
238 SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
239 WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv),
240 SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1,
243 SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
244 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
245 SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
246 WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv),
247 SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
248 WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv),
249 SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
250 WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv),
251 SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
252 WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv),
253 SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
254 WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv),
255 SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
256 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
257 SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
258 WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv),
260 SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME,
261 WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv),
262 SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME,
263 WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0),
264 SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME,
265 WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0),
267 SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1),
268 SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv),
270 SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION,
271 5, 1, 1, wm_hubs_spkmix_tlv),
272 SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION,
273 4, 1, 1, wm_hubs_spkmix_tlv),
274 SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION,
275 3, 1, 1, wm_hubs_spkmix_tlv),
277 SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION,
278 5, 1, 1, wm_hubs_spkmix_tlv),
279 SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION,
280 4, 1, 1, wm_hubs_spkmix_tlv),
281 SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION,
282 3, 1, 1, wm_hubs_spkmix_tlv),
284 SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
285 WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION,
286 0, 3, 1, spkmixout_tlv),
287 SOC_DOUBLE_R_TLV("Speaker Volume",
288 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
289 0, 63, 0, outpga_tlv),
290 SOC_DOUBLE_R("Speaker Switch",
291 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
293 SOC_DOUBLE_R("Speaker ZC Switch",
294 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
296 SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 0, 3, 7, 0,
298 SOC_ENUM("Speaker Reference", speaker_ref),
299 SOC_ENUM("Speaker Mode", speaker_mode),
302 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Volume",
303 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
304 SNDRV_CTL_ELEM_ACCESS_READWRITE,
306 .info = snd_soc_info_volsw_2r,
307 .get = snd_soc_get_volsw_2r, .put = wm8993_put_dc_servo,
308 .private_value = (unsigned long)&(struct soc_mixer_control) {
309 .reg = WM8993_LEFT_OUTPUT_VOLUME,
310 .rreg = WM8993_RIGHT_OUTPUT_VOLUME,
311 .shift = 0, .max = 63
314 SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
315 WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
316 SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
317 WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
319 SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
320 SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
321 SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
324 SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
325 SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
326 SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
330 static int hp_supply_event(struct snd_soc_dapm_widget *w,
331 struct snd_kcontrol *kcontrol, int event)
333 struct snd_soc_codec *codec = w->codec;
334 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
337 case SND_SOC_DAPM_PRE_PMU:
338 switch (hubs->hp_startup_mode) {
342 /* Enable the headphone amp */
343 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
349 /* Enable the second stage */
350 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
357 dev_err(codec->dev, "Unknown HP startup mode %d\n",
358 hubs->hp_startup_mode);
362 case SND_SOC_DAPM_PRE_PMD:
363 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
371 static int hp_event(struct snd_soc_dapm_widget *w,
372 struct snd_kcontrol *kcontrol, int event)
374 struct snd_soc_codec *codec = w->codec;
375 unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
378 case SND_SOC_DAPM_POST_PMU:
379 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
380 WM8993_CP_ENA, WM8993_CP_ENA);
384 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
385 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
386 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
388 reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
389 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
391 /* Smallest supported update interval */
392 snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
393 WM8993_DCS_TIMER_PERIOD_01_MASK, 1);
395 calibrate_dc_servo(codec);
397 reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT |
398 WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT;
399 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
402 case SND_SOC_DAPM_PRE_PMD:
403 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
404 WM8993_HPOUT1L_OUTP |
405 WM8993_HPOUT1R_OUTP |
406 WM8993_HPOUT1L_RMV_SHORT |
407 WM8993_HPOUT1R_RMV_SHORT, 0);
409 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
411 WM8993_HPOUT1R_DLY, 0);
413 snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
415 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
416 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
424 static int earpiece_event(struct snd_soc_dapm_widget *w,
425 struct snd_kcontrol *control, int event)
427 struct snd_soc_codec *codec = w->codec;
428 u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
431 case SND_SOC_DAPM_PRE_PMU:
432 reg |= WM8993_HPOUT2_IN_ENA;
433 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
437 case SND_SOC_DAPM_POST_PMD:
438 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
449 static const struct snd_kcontrol_new in1l_pga[] = {
450 SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
451 SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
454 static const struct snd_kcontrol_new in1r_pga[] = {
455 SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
456 SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
459 static const struct snd_kcontrol_new in2l_pga[] = {
460 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
461 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
464 static const struct snd_kcontrol_new in2r_pga[] = {
465 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
466 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
469 static const struct snd_kcontrol_new mixinl[] = {
470 SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
471 SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
474 static const struct snd_kcontrol_new mixinr[] = {
475 SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
476 SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
479 static const struct snd_kcontrol_new left_output_mixer[] = {
480 SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
481 SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
482 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
483 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
484 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
485 SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
486 SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
487 SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
490 static const struct snd_kcontrol_new right_output_mixer[] = {
491 SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
492 SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
493 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
494 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
495 SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
496 SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
497 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
498 SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
501 static const struct snd_kcontrol_new earpiece_mixer[] = {
502 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
503 SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
504 SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
507 static const struct snd_kcontrol_new left_speaker_boost[] = {
508 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
509 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
510 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
513 static const struct snd_kcontrol_new right_speaker_boost[] = {
514 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
515 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
516 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
519 static const struct snd_kcontrol_new line1_mix[] = {
520 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
521 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
522 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
525 static const struct snd_kcontrol_new line1n_mix[] = {
526 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
527 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
530 static const struct snd_kcontrol_new line1p_mix[] = {
531 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
534 static const struct snd_kcontrol_new line2_mix[] = {
535 SOC_DAPM_SINGLE("IN2R Switch", WM8993_LINE_MIXER2, 2, 1, 0),
536 SOC_DAPM_SINGLE("IN2L Switch", WM8993_LINE_MIXER2, 1, 1, 0),
537 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
540 static const struct snd_kcontrol_new line2n_mix[] = {
541 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
542 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
545 static const struct snd_kcontrol_new line2p_mix[] = {
546 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
549 static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
550 SND_SOC_DAPM_INPUT("IN1LN"),
551 SND_SOC_DAPM_INPUT("IN1LP"),
552 SND_SOC_DAPM_INPUT("IN2LN"),
553 SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
554 SND_SOC_DAPM_INPUT("IN1RN"),
555 SND_SOC_DAPM_INPUT("IN1RP"),
556 SND_SOC_DAPM_INPUT("IN2RN"),
557 SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
559 SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
560 SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
562 SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
563 in1l_pga, ARRAY_SIZE(in1l_pga)),
564 SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
565 in1r_pga, ARRAY_SIZE(in1r_pga)),
567 SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
568 in2l_pga, ARRAY_SIZE(in2l_pga)),
569 SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0,
570 in2r_pga, ARRAY_SIZE(in2r_pga)),
572 /* Dummy widgets to represent differential paths */
573 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
575 SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
576 mixinl, ARRAY_SIZE(mixinl)),
577 SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
578 mixinr, ARRAY_SIZE(mixinr)),
580 SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
581 left_output_mixer, ARRAY_SIZE(left_output_mixer)),
582 SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
583 right_output_mixer, ARRAY_SIZE(right_output_mixer)),
585 SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
586 SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
588 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event,
589 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
590 SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0,
592 hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
594 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
595 earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
596 SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0,
597 NULL, 0, earpiece_event,
598 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
600 SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
601 left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
602 SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
603 right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
605 SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
607 SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
610 SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
611 line1_mix, ARRAY_SIZE(line1_mix)),
612 SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
613 line2_mix, ARRAY_SIZE(line2_mix)),
615 SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
616 line1n_mix, ARRAY_SIZE(line1n_mix)),
617 SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
618 line1p_mix, ARRAY_SIZE(line1p_mix)),
619 SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
620 line2n_mix, ARRAY_SIZE(line2n_mix)),
621 SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
622 line2p_mix, ARRAY_SIZE(line2p_mix)),
624 SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
626 SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
628 SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
630 SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
633 SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
634 SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
635 SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
636 SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
637 SND_SOC_DAPM_OUTPUT("HPOUT1L"),
638 SND_SOC_DAPM_OUTPUT("HPOUT1R"),
639 SND_SOC_DAPM_OUTPUT("HPOUT2P"),
640 SND_SOC_DAPM_OUTPUT("HPOUT2N"),
641 SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
642 SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
643 SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
644 SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
647 static const struct snd_soc_dapm_route analogue_routes[] = {
648 { "IN1L PGA", "IN1LP Switch", "IN1LP" },
649 { "IN1L PGA", "IN1LN Switch", "IN1LN" },
651 { "IN1R PGA", "IN1RP Switch", "IN1RP" },
652 { "IN1R PGA", "IN1RN Switch", "IN1RN" },
654 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
655 { "IN2L PGA", "IN2LN Switch", "IN2LN" },
657 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
658 { "IN2R PGA", "IN2RN Switch", "IN2RN" },
660 { "Direct Voice", NULL, "IN2LP:VXRN" },
661 { "Direct Voice", NULL, "IN2RP:VXRP" },
663 { "MIXINL", "IN1L Switch", "IN1L PGA" },
664 { "MIXINL", "IN2L Switch", "IN2L PGA" },
665 { "MIXINL", NULL, "Direct Voice" },
666 { "MIXINL", NULL, "IN1LP" },
667 { "MIXINL", NULL, "Left Output Mixer" },
669 { "MIXINR", "IN1R Switch", "IN1R PGA" },
670 { "MIXINR", "IN2R Switch", "IN2R PGA" },
671 { "MIXINR", NULL, "Direct Voice" },
672 { "MIXINR", NULL, "IN1RP" },
673 { "MIXINR", NULL, "Right Output Mixer" },
675 { "ADCL", NULL, "MIXINL" },
676 { "ADCR", NULL, "MIXINR" },
678 { "Left Output Mixer", "Left Input Switch", "MIXINL" },
679 { "Left Output Mixer", "Right Input Switch", "MIXINR" },
680 { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
681 { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
682 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
683 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
684 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
686 { "Right Output Mixer", "Left Input Switch", "MIXINL" },
687 { "Right Output Mixer", "Right Input Switch", "MIXINR" },
688 { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
689 { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
690 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
691 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
692 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
694 { "Left Output PGA", NULL, "Left Output Mixer" },
695 { "Left Output PGA", NULL, "TOCLK" },
697 { "Right Output PGA", NULL, "Right Output Mixer" },
698 { "Right Output PGA", NULL, "TOCLK" },
700 { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
701 { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
702 { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
704 { "Earpiece Driver", NULL, "Earpiece Mixer" },
705 { "HPOUT2N", NULL, "Earpiece Driver" },
706 { "HPOUT2P", NULL, "Earpiece Driver" },
708 { "SPKL", "Input Switch", "MIXINL" },
709 { "SPKL", "IN1LP Switch", "IN1LP" },
710 { "SPKL", "Output Switch", "Left Output Mixer" },
711 { "SPKL", NULL, "TOCLK" },
713 { "SPKR", "Input Switch", "MIXINR" },
714 { "SPKR", "IN1RP Switch", "IN1RP" },
715 { "SPKR", "Output Switch", "Right Output Mixer" },
716 { "SPKR", NULL, "TOCLK" },
718 { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
719 { "SPKL Boost", "SPKL Switch", "SPKL" },
720 { "SPKL Boost", "SPKR Switch", "SPKR" },
722 { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
723 { "SPKR Boost", "SPKR Switch", "SPKR" },
724 { "SPKR Boost", "SPKL Switch", "SPKL" },
726 { "SPKL Driver", NULL, "SPKL Boost" },
727 { "SPKL Driver", NULL, "CLK_SYS" },
729 { "SPKR Driver", NULL, "SPKR Boost" },
730 { "SPKR Driver", NULL, "CLK_SYS" },
732 { "SPKOUTLP", NULL, "SPKL Driver" },
733 { "SPKOUTLN", NULL, "SPKL Driver" },
734 { "SPKOUTRP", NULL, "SPKR Driver" },
735 { "SPKOUTRN", NULL, "SPKR Driver" },
737 { "Left Headphone Mux", "Mixer", "Left Output Mixer" },
738 { "Right Headphone Mux", "Mixer", "Right Output Mixer" },
740 { "Headphone PGA", NULL, "Left Headphone Mux" },
741 { "Headphone PGA", NULL, "Right Headphone Mux" },
742 { "Headphone PGA", NULL, "CLK_SYS" },
743 { "Headphone PGA", NULL, "Headphone Supply" },
745 { "HPOUT1L", NULL, "Headphone PGA" },
746 { "HPOUT1R", NULL, "Headphone PGA" },
748 { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
749 { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
750 { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
751 { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
754 static const struct snd_soc_dapm_route lineout1_diff_routes[] = {
755 { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
756 { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
757 { "LINEOUT1 Mixer", "Output Switch", "Left Output Mixer" },
759 { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
760 { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
763 static const struct snd_soc_dapm_route lineout1_se_routes[] = {
764 { "LINEOUT1N Mixer", "Left Output Switch", "Left Output Mixer" },
765 { "LINEOUT1N Mixer", "Right Output Switch", "Left Output Mixer" },
767 { "LINEOUT1P Mixer", "Left Output Switch", "Left Output Mixer" },
769 { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
770 { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
773 static const struct snd_soc_dapm_route lineout2_diff_routes[] = {
774 { "LINEOUT2 Mixer", "IN2L Switch", "IN2L PGA" },
775 { "LINEOUT2 Mixer", "IN2R Switch", "IN2R PGA" },
776 { "LINEOUT2 Mixer", "Output Switch", "Right Output Mixer" },
778 { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
779 { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
782 static const struct snd_soc_dapm_route lineout2_se_routes[] = {
783 { "LINEOUT2N Mixer", "Left Output Switch", "Left Output Mixer" },
784 { "LINEOUT2N Mixer", "Right Output Switch", "Left Output Mixer" },
786 { "LINEOUT2P Mixer", "Right Output Switch", "Right Output Mixer" },
788 { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
789 { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
792 int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
794 /* Latch volume update bits & default ZC on */
795 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
796 WM8993_IN1_VU, WM8993_IN1_VU);
797 snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME,
798 WM8993_IN1_VU, WM8993_IN1_VU);
799 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME,
800 WM8993_IN2_VU, WM8993_IN2_VU);
801 snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME,
802 WM8993_IN2_VU, WM8993_IN2_VU);
804 snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT,
805 WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
807 snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME,
808 WM8993_HPOUT1L_ZC, WM8993_HPOUT1L_ZC);
809 snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME,
810 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC,
811 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC);
813 snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME,
814 WM8993_MIXOUTL_ZC, WM8993_MIXOUTL_ZC);
815 snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME,
816 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU,
817 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU);
819 snd_soc_add_controls(codec, analogue_snd_controls,
820 ARRAY_SIZE(analogue_snd_controls));
822 snd_soc_dapm_new_controls(codec, analogue_dapm_widgets,
823 ARRAY_SIZE(analogue_dapm_widgets));
826 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
828 int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
829 int lineout1_diff, int lineout2_diff)
831 snd_soc_dapm_add_routes(codec, analogue_routes,
832 ARRAY_SIZE(analogue_routes));
835 snd_soc_dapm_add_routes(codec,
836 lineout1_diff_routes,
837 ARRAY_SIZE(lineout1_diff_routes));
839 snd_soc_dapm_add_routes(codec,
841 ARRAY_SIZE(lineout1_se_routes));
844 snd_soc_dapm_add_routes(codec,
845 lineout2_diff_routes,
846 ARRAY_SIZE(lineout2_diff_routes));
848 snd_soc_dapm_add_routes(codec,
850 ARRAY_SIZE(lineout2_se_routes));
854 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
856 int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
857 int lineout1_diff, int lineout2_diff,
858 int lineout1fb, int lineout2fb,
859 int jd_scthr, int jd_thr, int micbias1_lvl,
863 snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
864 WM8993_LINEOUT1_MODE,
865 WM8993_LINEOUT1_MODE);
867 snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
868 WM8993_LINEOUT2_MODE,
869 WM8993_LINEOUT2_MODE);
871 /* If the line outputs are differential then we aren't presenting
872 * VMID as an output and can disable it.
874 if (lineout1_diff && lineout2_diff)
875 codec->idle_bias_off = 1;
878 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
879 WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
882 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
883 WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
885 snd_soc_update_bits(codec, WM8993_MICBIAS,
886 WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
887 WM8993_MICB1_LVL | WM8993_MICB2_LVL,
888 jd_scthr << WM8993_JD_SCTHR_SHIFT |
889 jd_thr << WM8993_JD_THR_SHIFT |
891 micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
895 EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
897 MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
898 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
899 MODULE_LICENSE("GPL");