ASoC: Decouple DAPM from CODECs
[linux-2.6.git] / sound / soc / codecs / wm_hubs.c
1 /*
2  * wm_hubs.c  --  WM8993/4 common code
3  *
4  * Copyright 2009 Wolfson Microelectronics plc
5  *
6  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7  *
8  *
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.
12  */
13
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/pm.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>
28
29 #include "wm8993.h"
30 #include "wm_hubs.h"
31
32 const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0);
33 EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv);
34
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[] = {
43         TLV_DB_RANGE_HEAD(7),
44         0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
45         7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
46 };
47 static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0);
48
49 static const char *speaker_ref_text[] = {
50         "SPKVDD/2",
51         "VMID",
52 };
53
54 static const struct soc_enum speaker_ref =
55         SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text);
56
57 static const char *speaker_mode_text[] = {
58         "Class D",
59         "Class AB",
60 };
61
62 static const struct soc_enum speaker_mode =
63         SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text);
64
65 static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
66 {
67         unsigned int reg;
68         int count = 0;
69         unsigned int val;
70
71         val = op | WM8993_DCS_ENA_CHAN_0 | WM8993_DCS_ENA_CHAN_1;
72
73         /* Trigger the command */
74         snd_soc_write(codec, WM8993_DC_SERVO_0, val);
75
76         dev_dbg(codec->dev, "Waiting for DC servo...\n");
77
78         do {
79                 count++;
80                 msleep(1);
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);
84
85         if (reg & op)
86                 dev_err(codec->dev, "Timed out waiting for DC Servo\n");
87 }
88
89 /*
90  * Startup calibration of the DC servo
91  */
92 static void calibrate_dc_servo(struct snd_soc_codec *codec)
93 {
94         struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
95         u16 reg, reg_l, reg_r, dcs_cfg;
96
97         /* If we're using a digital only path and have a previously
98          * callibrated DC servo offset stored then use that. */
99         if (hubs->class_w && hubs->class_w_dcs) {
100                 dev_dbg(codec->dev, "Using cached DC servo offset %x\n",
101                         hubs->class_w_dcs);
102                 snd_soc_write(codec, WM8993_DC_SERVO_3, hubs->class_w_dcs);
103                 wait_for_dc_servo(codec,
104                                   WM8993_DCS_TRIG_DAC_WR_0 |
105                                   WM8993_DCS_TRIG_DAC_WR_1);
106                 return;
107         }
108
109         /* Set for 32 series updates */
110         snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
111                             WM8993_DCS_SERIES_NO_01_MASK,
112                             32 << WM8993_DCS_SERIES_NO_01_SHIFT);
113         wait_for_dc_servo(codec,
114                           WM8993_DCS_TRIG_SERIES_0 | WM8993_DCS_TRIG_SERIES_1);
115
116         /* Different chips in the family support different readback
117          * methods.
118          */
119         switch (hubs->dcs_readback_mode) {
120         case 0:
121                 reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1)
122                         & WM8993_DCS_INTEG_CHAN_0_MASK;;
123                 reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
124                         & WM8993_DCS_INTEG_CHAN_1_MASK;
125                 break;
126         case 1:
127                 reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
128                 reg_l = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
129                         >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
130                 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
131                 break;
132         default:
133                 WARN(1, "Unknown DCS readback method\n");
134                 break;
135         }
136
137         dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
138
139         /* Apply correction to DC servo result */
140         if (hubs->dcs_codes) {
141                 dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
142                         hubs->dcs_codes);
143
144                 /* HPOUT1L */
145                 if (reg_l + hubs->dcs_codes > 0 &&
146                     reg_l + hubs->dcs_codes < 0xff)
147                         reg_l += hubs->dcs_codes;
148                 dcs_cfg = reg_l << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
149
150                 /* HPOUT1R */
151                 if (reg_r + hubs->dcs_codes > 0 &&
152                     reg_r + hubs->dcs_codes < 0xff)
153                         reg_r += hubs->dcs_codes;
154                 dcs_cfg |= reg_r;
155
156                 dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
157
158                 /* Do it */
159                 snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
160                 wait_for_dc_servo(codec,
161                                   WM8993_DCS_TRIG_DAC_WR_0 |
162                                   WM8993_DCS_TRIG_DAC_WR_1);
163         } else {
164                 dcs_cfg = reg_l << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
165                 dcs_cfg |= reg_r;
166         }
167
168         /* Save the callibrated offset if we're in class W mode and
169          * therefore don't have any analogue signal mixed in. */
170         if (hubs->class_w)
171                 hubs->class_w_dcs = dcs_cfg;
172 }
173
174 /*
175  * Update the DC servo calibration on gain changes
176  */
177 static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
178                                struct snd_ctl_elem_value *ucontrol)
179 {
180         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
181         struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
182         int ret;
183
184         ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
185
186         /* Updating the analogue gains invalidates the DC servo cache */
187         hubs->class_w_dcs = 0;
188
189         /* If we're applying an offset correction then updating the
190          * callibration would be likely to introduce further offsets. */
191         if (hubs->dcs_codes)
192                 return ret;
193
194         /* Only need to do this if the outputs are active */
195         if (snd_soc_read(codec, WM8993_POWER_MANAGEMENT_1)
196             & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA))
197                 snd_soc_update_bits(codec,
198                                     WM8993_DC_SERVO_0,
199                                     WM8993_DCS_TRIG_SINGLE_0 |
200                                     WM8993_DCS_TRIG_SINGLE_1,
201                                     WM8993_DCS_TRIG_SINGLE_0 |
202                                     WM8993_DCS_TRIG_SINGLE_1);
203
204         return ret;
205 }
206
207 static const struct snd_kcontrol_new analogue_snd_controls[] = {
208 SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
209                inpga_tlv),
210 SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
211 SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
212
213 SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
214                inpga_tlv),
215 SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
216 SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
217
218
219 SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
220                inpga_tlv),
221 SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
222 SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
223
224 SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
225                inpga_tlv),
226 SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
227 SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
228
229 SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
230                inmix_sw_tlv),
231 SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
232                inmix_sw_tlv),
233 SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
234                inmix_tlv),
235 SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv),
236 SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0,
237                inmix_tlv),
238
239 SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
240                inmix_sw_tlv),
241 SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
242                inmix_sw_tlv),
243 SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
244                inmix_tlv),
245 SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv),
246 SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0,
247                inmix_tlv),
248
249 SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
250                outmix_tlv),
251 SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
252                outmix_tlv),
253 SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
254                outmix_tlv),
255 SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
256                outmix_tlv),
257 SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
258                outmix_tlv),
259 SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
260                WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv),
261 SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
262                WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv),
263 SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1,
264                outmix_tlv),
265
266 SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
267                WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
268 SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
269                WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv),
270 SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
271                WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv),
272 SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
273                WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv),
274 SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
275                WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv),
276 SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
277                WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv),
278 SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
279                WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
280 SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
281                WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv),
282
283 SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME,
284                  WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv),
285 SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME,
286              WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0),
287 SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME,
288              WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0),
289
290 SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1),
291 SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv),
292
293 SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION,
294                5, 1, 1, wm_hubs_spkmix_tlv),
295 SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION,
296                4, 1, 1, wm_hubs_spkmix_tlv),
297 SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION,
298                3, 1, 1, wm_hubs_spkmix_tlv),
299
300 SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION,
301                5, 1, 1, wm_hubs_spkmix_tlv),
302 SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION,
303                4, 1, 1, wm_hubs_spkmix_tlv),
304 SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION,
305                3, 1, 1, wm_hubs_spkmix_tlv),
306
307 SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
308                  WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION,
309                  0, 3, 1, spkmixout_tlv),
310 SOC_DOUBLE_R_TLV("Speaker Volume",
311                  WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
312                  0, 63, 0, outpga_tlv),
313 SOC_DOUBLE_R("Speaker Switch",
314              WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
315              6, 1, 0),
316 SOC_DOUBLE_R("Speaker ZC Switch",
317              WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
318              7, 1, 0),
319 SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 0, 3, 7, 0,
320                spkboost_tlv),
321 SOC_ENUM("Speaker Reference", speaker_ref),
322 SOC_ENUM("Speaker Mode", speaker_mode),
323
324 {
325         .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Volume",
326         .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
327                  SNDRV_CTL_ELEM_ACCESS_READWRITE,
328         .tlv.p = outpga_tlv,
329         .info = snd_soc_info_volsw_2r,
330         .get = snd_soc_get_volsw_2r, .put = wm8993_put_dc_servo,
331         .private_value = (unsigned long)&(struct soc_mixer_control) {
332                 .reg = WM8993_LEFT_OUTPUT_VOLUME,
333                 .rreg = WM8993_RIGHT_OUTPUT_VOLUME,
334                 .shift = 0, .max = 63
335         },
336 },
337 SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
338              WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
339 SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
340              WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
341
342 SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
343 SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
344 SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
345                line_tlv),
346
347 SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
348 SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
349 SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
350                line_tlv),
351 };
352
353 static int hp_supply_event(struct snd_soc_dapm_widget *w,
354                            struct snd_kcontrol *kcontrol, int event)
355 {
356         struct snd_soc_codec *codec = w->codec;
357         struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
358
359         switch (event) {
360         case SND_SOC_DAPM_PRE_PMU:
361                 switch (hubs->hp_startup_mode) {
362                 case 0:
363                         break;
364                 case 1:
365                         /* Enable the headphone amp */
366                         snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
367                                             WM8993_HPOUT1L_ENA |
368                                             WM8993_HPOUT1R_ENA,
369                                             WM8993_HPOUT1L_ENA |
370                                             WM8993_HPOUT1R_ENA);
371
372                         /* Enable the second stage */
373                         snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
374                                             WM8993_HPOUT1L_DLY |
375                                             WM8993_HPOUT1R_DLY,
376                                             WM8993_HPOUT1L_DLY |
377                                             WM8993_HPOUT1R_DLY);
378                         break;
379                 default:
380                         dev_err(codec->dev, "Unknown HP startup mode %d\n",
381                                 hubs->hp_startup_mode);
382                         break;
383                 }
384
385         case SND_SOC_DAPM_PRE_PMD:
386                 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
387                                     WM8993_CP_ENA, 0);
388                 break;
389         }
390
391         return 0;
392 }
393
394 static int hp_event(struct snd_soc_dapm_widget *w,
395                     struct snd_kcontrol *kcontrol, int event)
396 {
397         struct snd_soc_codec *codec = w->codec;
398         unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
399
400         switch (event) {
401         case SND_SOC_DAPM_POST_PMU:
402                 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
403                                     WM8993_CP_ENA, WM8993_CP_ENA);
404
405                 msleep(5);
406
407                 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
408                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
409                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
410
411                 reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
412                 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
413
414                 /* Smallest supported update interval */
415                 snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
416                                     WM8993_DCS_TIMER_PERIOD_01_MASK, 1);
417
418                 calibrate_dc_servo(codec);
419
420                 reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT |
421                         WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT;
422                 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
423                 break;
424
425         case SND_SOC_DAPM_PRE_PMD:
426                 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
427                                     WM8993_HPOUT1L_OUTP |
428                                     WM8993_HPOUT1R_OUTP |
429                                     WM8993_HPOUT1L_RMV_SHORT |
430                                     WM8993_HPOUT1R_RMV_SHORT, 0);
431
432                 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
433                                     WM8993_HPOUT1L_DLY |
434                                     WM8993_HPOUT1R_DLY, 0);
435
436                 snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
437
438                 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
439                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
440                                     0);
441                 break;
442         }
443
444         return 0;
445 }
446
447 static int earpiece_event(struct snd_soc_dapm_widget *w,
448                           struct snd_kcontrol *control, int event)
449 {
450         struct snd_soc_codec *codec = w->codec;
451         u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
452
453         switch (event) {
454         case SND_SOC_DAPM_PRE_PMU:
455                 reg |= WM8993_HPOUT2_IN_ENA;
456                 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
457                 udelay(50);
458                 break;
459
460         case SND_SOC_DAPM_POST_PMD:
461                 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
462                 break;
463
464         default:
465                 BUG();
466                 break;
467         }
468
469         return 0;
470 }
471
472 static const struct snd_kcontrol_new in1l_pga[] = {
473 SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
474 SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
475 };
476
477 static const struct snd_kcontrol_new in1r_pga[] = {
478 SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
479 SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
480 };
481
482 static const struct snd_kcontrol_new in2l_pga[] = {
483 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
484 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
485 };
486
487 static const struct snd_kcontrol_new in2r_pga[] = {
488 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
489 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
490 };
491
492 static const struct snd_kcontrol_new mixinl[] = {
493 SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
494 SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
495 };
496
497 static const struct snd_kcontrol_new mixinr[] = {
498 SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
499 SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
500 };
501
502 static const struct snd_kcontrol_new left_output_mixer[] = {
503 SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
504 SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
505 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
506 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
507 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
508 SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
509 SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
510 SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
511 };
512
513 static const struct snd_kcontrol_new right_output_mixer[] = {
514 SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
515 SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
516 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
517 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
518 SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
519 SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
520 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
521 SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
522 };
523
524 static const struct snd_kcontrol_new earpiece_mixer[] = {
525 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
526 SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
527 SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
528 };
529
530 static const struct snd_kcontrol_new left_speaker_boost[] = {
531 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
532 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
533 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
534 };
535
536 static const struct snd_kcontrol_new right_speaker_boost[] = {
537 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
538 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
539 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
540 };
541
542 static const struct snd_kcontrol_new line1_mix[] = {
543 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
544 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
545 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
546 };
547
548 static const struct snd_kcontrol_new line1n_mix[] = {
549 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
550 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
551 };
552
553 static const struct snd_kcontrol_new line1p_mix[] = {
554 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
555 };
556
557 static const struct snd_kcontrol_new line2_mix[] = {
558 SOC_DAPM_SINGLE("IN2R Switch", WM8993_LINE_MIXER2, 2, 1, 0),
559 SOC_DAPM_SINGLE("IN2L Switch", WM8993_LINE_MIXER2, 1, 1, 0),
560 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
561 };
562
563 static const struct snd_kcontrol_new line2n_mix[] = {
564 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
565 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
566 };
567
568 static const struct snd_kcontrol_new line2p_mix[] = {
569 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
570 };
571
572 static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
573 SND_SOC_DAPM_INPUT("IN1LN"),
574 SND_SOC_DAPM_INPUT("IN1LP"),
575 SND_SOC_DAPM_INPUT("IN2LN"),
576 SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
577 SND_SOC_DAPM_INPUT("IN1RN"),
578 SND_SOC_DAPM_INPUT("IN1RP"),
579 SND_SOC_DAPM_INPUT("IN2RN"),
580 SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
581
582 SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
583 SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
584
585 SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
586                    in1l_pga, ARRAY_SIZE(in1l_pga)),
587 SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
588                    in1r_pga, ARRAY_SIZE(in1r_pga)),
589
590 SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
591                    in2l_pga, ARRAY_SIZE(in2l_pga)),
592 SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0,
593                    in2r_pga, ARRAY_SIZE(in2r_pga)),
594
595 /* Dummy widgets to represent differential paths */
596 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
597
598 SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
599                    mixinl, ARRAY_SIZE(mixinl)),
600 SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
601                    mixinr, ARRAY_SIZE(mixinr)),
602
603 SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
604                    left_output_mixer, ARRAY_SIZE(left_output_mixer)),
605 SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
606                    right_output_mixer, ARRAY_SIZE(right_output_mixer)),
607
608 SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
609 SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
610
611 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event, 
612                     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
613 SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0,
614                    NULL, 0,
615                    hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
616
617 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
618                    earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
619 SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0,
620                    NULL, 0, earpiece_event,
621                    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
622
623 SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
624                    left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
625 SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
626                    right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
627
628 SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
629                  NULL, 0),
630 SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
631                  NULL, 0),
632
633 SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
634                    line1_mix, ARRAY_SIZE(line1_mix)),
635 SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
636                    line2_mix, ARRAY_SIZE(line2_mix)),
637
638 SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
639                    line1n_mix, ARRAY_SIZE(line1n_mix)),
640 SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
641                    line1p_mix, ARRAY_SIZE(line1p_mix)),
642 SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
643                    line2n_mix, ARRAY_SIZE(line2n_mix)),
644 SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
645                    line2p_mix, ARRAY_SIZE(line2p_mix)),
646
647 SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
648                  NULL, 0),
649 SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
650                  NULL, 0),
651 SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
652                  NULL, 0),
653 SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
654                  NULL, 0),
655
656 SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
657 SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
658 SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
659 SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
660 SND_SOC_DAPM_OUTPUT("HPOUT1L"),
661 SND_SOC_DAPM_OUTPUT("HPOUT1R"),
662 SND_SOC_DAPM_OUTPUT("HPOUT2P"),
663 SND_SOC_DAPM_OUTPUT("HPOUT2N"),
664 SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
665 SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
666 SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
667 SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
668 };
669
670 static const struct snd_soc_dapm_route analogue_routes[] = {
671         { "IN1L PGA", "IN1LP Switch", "IN1LP" },
672         { "IN1L PGA", "IN1LN Switch", "IN1LN" },
673
674         { "IN1R PGA", "IN1RP Switch", "IN1RP" },
675         { "IN1R PGA", "IN1RN Switch", "IN1RN" },
676
677         { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
678         { "IN2L PGA", "IN2LN Switch", "IN2LN" },
679
680         { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
681         { "IN2R PGA", "IN2RN Switch", "IN2RN" },
682
683         { "Direct Voice", NULL, "IN2LP:VXRN" },
684         { "Direct Voice", NULL, "IN2RP:VXRP" },
685
686         { "MIXINL", "IN1L Switch", "IN1L PGA" },
687         { "MIXINL", "IN2L Switch", "IN2L PGA" },
688         { "MIXINL", NULL, "Direct Voice" },
689         { "MIXINL", NULL, "IN1LP" },
690         { "MIXINL", NULL, "Left Output Mixer" },
691
692         { "MIXINR", "IN1R Switch", "IN1R PGA" },
693         { "MIXINR", "IN2R Switch", "IN2R PGA" },
694         { "MIXINR", NULL, "Direct Voice" },
695         { "MIXINR", NULL, "IN1RP" },
696         { "MIXINR", NULL, "Right Output Mixer" },
697
698         { "ADCL", NULL, "MIXINL" },
699         { "ADCR", NULL, "MIXINR" },
700
701         { "Left Output Mixer", "Left Input Switch", "MIXINL" },
702         { "Left Output Mixer", "Right Input Switch", "MIXINR" },
703         { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
704         { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
705         { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
706         { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
707         { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
708
709         { "Right Output Mixer", "Left Input Switch", "MIXINL" },
710         { "Right Output Mixer", "Right Input Switch", "MIXINR" },
711         { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
712         { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
713         { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
714         { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
715         { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
716
717         { "Left Output PGA", NULL, "Left Output Mixer" },
718         { "Left Output PGA", NULL, "TOCLK" },
719
720         { "Right Output PGA", NULL, "Right Output Mixer" },
721         { "Right Output PGA", NULL, "TOCLK" },
722
723         { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
724         { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
725         { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
726
727         { "Earpiece Driver", NULL, "Earpiece Mixer" },
728         { "HPOUT2N", NULL, "Earpiece Driver" },
729         { "HPOUT2P", NULL, "Earpiece Driver" },
730
731         { "SPKL", "Input Switch", "MIXINL" },
732         { "SPKL", "IN1LP Switch", "IN1LP" },
733         { "SPKL", "Output Switch", "Left Output Mixer" },
734         { "SPKL", NULL, "TOCLK" },
735
736         { "SPKR", "Input Switch", "MIXINR" },
737         { "SPKR", "IN1RP Switch", "IN1RP" },
738         { "SPKR", "Output Switch", "Right Output Mixer" },
739         { "SPKR", NULL, "TOCLK" },
740
741         { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
742         { "SPKL Boost", "SPKL Switch", "SPKL" },
743         { "SPKL Boost", "SPKR Switch", "SPKR" },
744
745         { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
746         { "SPKR Boost", "SPKR Switch", "SPKR" },
747         { "SPKR Boost", "SPKL Switch", "SPKL" },
748
749         { "SPKL Driver", NULL, "SPKL Boost" },
750         { "SPKL Driver", NULL, "CLK_SYS" },
751
752         { "SPKR Driver", NULL, "SPKR Boost" },
753         { "SPKR Driver", NULL, "CLK_SYS" },
754
755         { "SPKOUTLP", NULL, "SPKL Driver" },
756         { "SPKOUTLN", NULL, "SPKL Driver" },
757         { "SPKOUTRP", NULL, "SPKR Driver" },
758         { "SPKOUTRN", NULL, "SPKR Driver" },
759
760         { "Left Headphone Mux", "Mixer", "Left Output Mixer" },
761         { "Right Headphone Mux", "Mixer", "Right Output Mixer" },
762
763         { "Headphone PGA", NULL, "Left Headphone Mux" },
764         { "Headphone PGA", NULL, "Right Headphone Mux" },
765         { "Headphone PGA", NULL, "CLK_SYS" },
766         { "Headphone PGA", NULL, "Headphone Supply" },
767
768         { "HPOUT1L", NULL, "Headphone PGA" },
769         { "HPOUT1R", NULL, "Headphone PGA" },
770
771         { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
772         { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
773         { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
774         { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
775 };
776
777 static const struct snd_soc_dapm_route lineout1_diff_routes[] = {
778         { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
779         { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
780         { "LINEOUT1 Mixer", "Output Switch", "Left Output Mixer" },
781
782         { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
783         { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
784 };
785
786 static const struct snd_soc_dapm_route lineout1_se_routes[] = {
787         { "LINEOUT1N Mixer", "Left Output Switch", "Left Output Mixer" },
788         { "LINEOUT1N Mixer", "Right Output Switch", "Left Output Mixer" },
789
790         { "LINEOUT1P Mixer", "Left Output Switch", "Left Output Mixer" },
791
792         { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
793         { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
794 };
795
796 static const struct snd_soc_dapm_route lineout2_diff_routes[] = {
797         { "LINEOUT2 Mixer", "IN2L Switch", "IN2L PGA" },
798         { "LINEOUT2 Mixer", "IN2R Switch", "IN2R PGA" },
799         { "LINEOUT2 Mixer", "Output Switch", "Right Output Mixer" },
800
801         { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
802         { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
803 };
804
805 static const struct snd_soc_dapm_route lineout2_se_routes[] = {
806         { "LINEOUT2N Mixer", "Left Output Switch", "Left Output Mixer" },
807         { "LINEOUT2N Mixer", "Right Output Switch", "Left Output Mixer" },
808
809         { "LINEOUT2P Mixer", "Right Output Switch", "Right Output Mixer" },
810
811         { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
812         { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
813 };
814
815 int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
816 {
817         struct snd_soc_dapm_context *dapm = &codec->dapm;
818
819         /* Latch volume update bits & default ZC on */
820         snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
821                             WM8993_IN1_VU, WM8993_IN1_VU);
822         snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME,
823                             WM8993_IN1_VU, WM8993_IN1_VU);
824         snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME,
825                             WM8993_IN2_VU, WM8993_IN2_VU);
826         snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME,
827                             WM8993_IN2_VU, WM8993_IN2_VU);
828
829         snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT,
830                             WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
831
832         snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME,
833                             WM8993_HPOUT1L_ZC, WM8993_HPOUT1L_ZC);
834         snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME,
835                             WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC,
836                             WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC);
837
838         snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME,
839                             WM8993_MIXOUTL_ZC, WM8993_MIXOUTL_ZC);
840         snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME,
841                             WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU,
842                             WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU);
843
844         snd_soc_add_controls(codec, analogue_snd_controls,
845                              ARRAY_SIZE(analogue_snd_controls));
846
847         snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets,
848                                   ARRAY_SIZE(analogue_dapm_widgets));
849         return 0;
850 }
851 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
852
853 int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
854                                 int lineout1_diff, int lineout2_diff)
855 {
856         struct snd_soc_dapm_context *dapm = &codec->dapm;
857
858         snd_soc_dapm_add_routes(dapm, analogue_routes,
859                                 ARRAY_SIZE(analogue_routes));
860
861         if (lineout1_diff)
862                 snd_soc_dapm_add_routes(dapm,
863                                         lineout1_diff_routes,
864                                         ARRAY_SIZE(lineout1_diff_routes));
865         else
866                 snd_soc_dapm_add_routes(dapm,
867                                         lineout1_se_routes,
868                                         ARRAY_SIZE(lineout1_se_routes));
869
870         if (lineout2_diff)
871                 snd_soc_dapm_add_routes(dapm,
872                                         lineout2_diff_routes,
873                                         ARRAY_SIZE(lineout2_diff_routes));
874         else
875                 snd_soc_dapm_add_routes(dapm,
876                                         lineout2_se_routes,
877                                         ARRAY_SIZE(lineout2_se_routes));
878
879         return 0;
880 }
881 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
882
883 int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
884                                   int lineout1_diff, int lineout2_diff,
885                                   int lineout1fb, int lineout2fb,
886                                   int jd_scthr, int jd_thr, int micbias1_lvl,
887                                   int micbias2_lvl)
888 {
889         if (!lineout1_diff)
890                 snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
891                                     WM8993_LINEOUT1_MODE,
892                                     WM8993_LINEOUT1_MODE);
893         if (!lineout2_diff)
894                 snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
895                                     WM8993_LINEOUT2_MODE,
896                                     WM8993_LINEOUT2_MODE);
897
898         /* If the line outputs are differential then we aren't presenting
899          * VMID as an output and can disable it.
900          */
901         if (lineout1_diff && lineout2_diff)
902                 codec->dapm.idle_bias_off = 1;
903
904         if (lineout1fb)
905                 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
906                                     WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
907
908         if (lineout2fb)
909                 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
910                                     WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
911
912         snd_soc_update_bits(codec, WM8993_MICBIAS,
913                             WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
914                             WM8993_MICB1_LVL | WM8993_MICB2_LVL,
915                             jd_scthr << WM8993_JD_SCTHR_SHIFT |
916                             jd_thr << WM8993_JD_THR_SHIFT |
917                             micbias1_lvl |
918                             micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
919
920         return 0;
921 }
922 EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
923
924 MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
925 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
926 MODULE_LICENSE("GPL");