Linux 2.6.37-rc1
[pandora-kernel.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         /* 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);
103
104         /* Apply correction to DC servo result */
105         if (hubs->dcs_codes) {
106                 dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
107                         hubs->dcs_codes);
108
109                 /* Different chips in the family support different
110                  * readback methods.
111                  */
112                 switch (hubs->dcs_readback_mode) {
113                 case 0:
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;
118                         break;
119                 case 1:
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;
124                         break;
125                 default:
126                         WARN(1, "Unknown DCS readback method");
127                         break;
128                 }
129
130                 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
131
132                 /* HPOUT1L */
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;
137
138                 /* HPOUT1R */
139                 if (reg_r + hubs->dcs_codes > 0 &&
140                     reg_r + hubs->dcs_codes < 0xff)
141                         reg_r += hubs->dcs_codes;
142                 dcs_cfg |= reg_r;
143
144                 dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
145
146                 /* Do it */
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);
151         }
152 }
153
154 /*
155  * Update the DC servo calibration on gain changes
156  */
157 static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
158                                struct snd_ctl_elem_value *ucontrol)
159 {
160         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
161         struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
162         int ret;
163
164         ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
165
166         /* If we're applying an offset correction then updating the
167          * callibration would be likely to introduce further offsets. */
168         if (hubs->dcs_codes)
169                 return ret;
170
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,
175                                     WM8993_DC_SERVO_0,
176                                     WM8993_DCS_TRIG_SINGLE_0 |
177                                     WM8993_DCS_TRIG_SINGLE_1,
178                                     WM8993_DCS_TRIG_SINGLE_0 |
179                                     WM8993_DCS_TRIG_SINGLE_1);
180
181         return ret;
182 }
183
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,
186                inpga_tlv),
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),
189
190 SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
191                inpga_tlv),
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),
194
195
196 SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
197                inpga_tlv),
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),
200
201 SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
202                inpga_tlv),
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),
205
206 SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
207                inmix_sw_tlv),
208 SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
209                inmix_sw_tlv),
210 SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
211                inmix_tlv),
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,
214                inmix_tlv),
215
216 SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
217                inmix_sw_tlv),
218 SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
219                inmix_sw_tlv),
220 SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
221                inmix_tlv),
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,
224                inmix_tlv),
225
226 SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
227                outmix_tlv),
228 SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
229                outmix_tlv),
230 SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
231                outmix_tlv),
232 SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
233                outmix_tlv),
234 SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
235                outmix_tlv),
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,
241                outmix_tlv),
242
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),
259
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),
266
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),
269
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),
276
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),
283
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,
292              6, 1, 0),
293 SOC_DOUBLE_R("Speaker ZC Switch",
294              WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
295              7, 1, 0),
296 SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 0, 3, 7, 0,
297                spkboost_tlv),
298 SOC_ENUM("Speaker Reference", speaker_ref),
299 SOC_ENUM("Speaker Mode", speaker_mode),
300
301 {
302         .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Volume",
303         .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
304                  SNDRV_CTL_ELEM_ACCESS_READWRITE,
305         .tlv.p = outpga_tlv,
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
312         },
313 },
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),
318
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,
322                line_tlv),
323
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,
327                line_tlv),
328 };
329
330 static int hp_supply_event(struct snd_soc_dapm_widget *w,
331                            struct snd_kcontrol *kcontrol, int event)
332 {
333         struct snd_soc_codec *codec = w->codec;
334         struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
335
336         switch (event) {
337         case SND_SOC_DAPM_PRE_PMU:
338                 switch (hubs->hp_startup_mode) {
339                 case 0:
340                         break;
341                 case 1:
342                         /* Enable the headphone amp */
343                         snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
344                                             WM8993_HPOUT1L_ENA |
345                                             WM8993_HPOUT1R_ENA,
346                                             WM8993_HPOUT1L_ENA |
347                                             WM8993_HPOUT1R_ENA);
348
349                         /* Enable the second stage */
350                         snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
351                                             WM8993_HPOUT1L_DLY |
352                                             WM8993_HPOUT1R_DLY,
353                                             WM8993_HPOUT1L_DLY |
354                                             WM8993_HPOUT1R_DLY);
355                         break;
356                 default:
357                         dev_err(codec->dev, "Unknown HP startup mode %d\n",
358                                 hubs->hp_startup_mode);
359                         break;
360                 }
361
362         case SND_SOC_DAPM_PRE_PMD:
363                 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
364                                     WM8993_CP_ENA, 0);
365                 break;
366         }
367
368         return 0;
369 }
370
371 static int hp_event(struct snd_soc_dapm_widget *w,
372                     struct snd_kcontrol *kcontrol, int event)
373 {
374         struct snd_soc_codec *codec = w->codec;
375         unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
376
377         switch (event) {
378         case SND_SOC_DAPM_POST_PMU:
379                 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
380                                     WM8993_CP_ENA, WM8993_CP_ENA);
381
382                 msleep(5);
383
384                 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
385                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
386                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
387
388                 reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
389                 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
390
391                 /* Smallest supported update interval */
392                 snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
393                                     WM8993_DCS_TIMER_PERIOD_01_MASK, 1);
394
395                 calibrate_dc_servo(codec);
396
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);
400                 break;
401
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);
408
409                 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
410                                     WM8993_HPOUT1L_DLY |
411                                     WM8993_HPOUT1R_DLY, 0);
412
413                 snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
414
415                 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
416                                     WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
417                                     0);
418                 break;
419         }
420
421         return 0;
422 }
423
424 static int earpiece_event(struct snd_soc_dapm_widget *w,
425                           struct snd_kcontrol *control, int event)
426 {
427         struct snd_soc_codec *codec = w->codec;
428         u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
429
430         switch (event) {
431         case SND_SOC_DAPM_PRE_PMU:
432                 reg |= WM8993_HPOUT2_IN_ENA;
433                 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
434                 udelay(50);
435                 break;
436
437         case SND_SOC_DAPM_POST_PMD:
438                 snd_soc_write(codec, WM8993_ANTIPOP1, reg);
439                 break;
440
441         default:
442                 BUG();
443                 break;
444         }
445
446         return 0;
447 }
448
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),
452 };
453
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),
457 };
458
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),
462 };
463
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),
467 };
468
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),
472 };
473
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),
477 };
478
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),
488 };
489
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),
499 };
500
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),
505 };
506
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),
511 };
512
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),
517 };
518
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),
523 };
524
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),
528 };
529
530 static const struct snd_kcontrol_new line1p_mix[] = {
531 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
532 };
533
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),
538 };
539
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),
543 };
544
545 static const struct snd_kcontrol_new line2p_mix[] = {
546 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
547 };
548
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"),
558
559 SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
560 SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
561
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)),
566
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)),
571
572 /* Dummy widgets to represent differential paths */
573 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
574
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)),
579
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)),
584
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),
587
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,
591                    NULL, 0,
592                    hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
593
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),
599
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)),
604
605 SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
606                  NULL, 0),
607 SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
608                  NULL, 0),
609
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)),
614
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)),
623
624 SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
625                  NULL, 0),
626 SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
627                  NULL, 0),
628 SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
629                  NULL, 0),
630 SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
631                  NULL, 0),
632
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"),
645 };
646
647 static const struct snd_soc_dapm_route analogue_routes[] = {
648         { "IN1L PGA", "IN1LP Switch", "IN1LP" },
649         { "IN1L PGA", "IN1LN Switch", "IN1LN" },
650
651         { "IN1R PGA", "IN1RP Switch", "IN1RP" },
652         { "IN1R PGA", "IN1RN Switch", "IN1RN" },
653
654         { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
655         { "IN2L PGA", "IN2LN Switch", "IN2LN" },
656
657         { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
658         { "IN2R PGA", "IN2RN Switch", "IN2RN" },
659
660         { "Direct Voice", NULL, "IN2LP:VXRN" },
661         { "Direct Voice", NULL, "IN2RP:VXRP" },
662
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" },
668
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" },
674
675         { "ADCL", NULL, "MIXINL" },
676         { "ADCR", NULL, "MIXINR" },
677
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" },
685
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" },
693
694         { "Left Output PGA", NULL, "Left Output Mixer" },
695         { "Left Output PGA", NULL, "TOCLK" },
696
697         { "Right Output PGA", NULL, "Right Output Mixer" },
698         { "Right Output PGA", NULL, "TOCLK" },
699
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" },
703
704         { "Earpiece Driver", NULL, "Earpiece Mixer" },
705         { "HPOUT2N", NULL, "Earpiece Driver" },
706         { "HPOUT2P", NULL, "Earpiece Driver" },
707
708         { "SPKL", "Input Switch", "MIXINL" },
709         { "SPKL", "IN1LP Switch", "IN1LP" },
710         { "SPKL", "Output Switch", "Left Output Mixer" },
711         { "SPKL", NULL, "TOCLK" },
712
713         { "SPKR", "Input Switch", "MIXINR" },
714         { "SPKR", "IN1RP Switch", "IN1RP" },
715         { "SPKR", "Output Switch", "Right Output Mixer" },
716         { "SPKR", NULL, "TOCLK" },
717
718         { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
719         { "SPKL Boost", "SPKL Switch", "SPKL" },
720         { "SPKL Boost", "SPKR Switch", "SPKR" },
721
722         { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
723         { "SPKR Boost", "SPKR Switch", "SPKR" },
724         { "SPKR Boost", "SPKL Switch", "SPKL" },
725
726         { "SPKL Driver", NULL, "SPKL Boost" },
727         { "SPKL Driver", NULL, "CLK_SYS" },
728
729         { "SPKR Driver", NULL, "SPKR Boost" },
730         { "SPKR Driver", NULL, "CLK_SYS" },
731
732         { "SPKOUTLP", NULL, "SPKL Driver" },
733         { "SPKOUTLN", NULL, "SPKL Driver" },
734         { "SPKOUTRP", NULL, "SPKR Driver" },
735         { "SPKOUTRN", NULL, "SPKR Driver" },
736
737         { "Left Headphone Mux", "Mixer", "Left Output Mixer" },
738         { "Right Headphone Mux", "Mixer", "Right Output Mixer" },
739
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" },
744
745         { "HPOUT1L", NULL, "Headphone PGA" },
746         { "HPOUT1R", NULL, "Headphone PGA" },
747
748         { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
749         { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
750         { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
751         { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
752 };
753
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" },
758
759         { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
760         { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
761 };
762
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" },
766
767         { "LINEOUT1P Mixer", "Left Output Switch", "Left Output Mixer" },
768
769         { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
770         { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
771 };
772
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" },
777
778         { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
779         { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
780 };
781
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" },
785
786         { "LINEOUT2P Mixer", "Right Output Switch", "Right Output Mixer" },
787
788         { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
789         { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
790 };
791
792 int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
793 {
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);
803
804         snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT,
805                             WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
806
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);
812
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);
818
819         snd_soc_add_controls(codec, analogue_snd_controls,
820                              ARRAY_SIZE(analogue_snd_controls));
821
822         snd_soc_dapm_new_controls(codec, analogue_dapm_widgets,
823                                   ARRAY_SIZE(analogue_dapm_widgets));
824         return 0;
825 }
826 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
827
828 int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
829                                 int lineout1_diff, int lineout2_diff)
830 {
831         snd_soc_dapm_add_routes(codec, analogue_routes,
832                                 ARRAY_SIZE(analogue_routes));
833
834         if (lineout1_diff)
835                 snd_soc_dapm_add_routes(codec,
836                                         lineout1_diff_routes,
837                                         ARRAY_SIZE(lineout1_diff_routes));
838         else
839                 snd_soc_dapm_add_routes(codec,
840                                         lineout1_se_routes,
841                                         ARRAY_SIZE(lineout1_se_routes));
842
843         if (lineout2_diff)
844                 snd_soc_dapm_add_routes(codec,
845                                         lineout2_diff_routes,
846                                         ARRAY_SIZE(lineout2_diff_routes));
847         else
848                 snd_soc_dapm_add_routes(codec,
849                                         lineout2_se_routes,
850                                         ARRAY_SIZE(lineout2_se_routes));
851
852         return 0;
853 }
854 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
855
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,
860                                   int micbias2_lvl)
861 {
862         if (!lineout1_diff)
863                 snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
864                                     WM8993_LINEOUT1_MODE,
865                                     WM8993_LINEOUT1_MODE);
866         if (!lineout2_diff)
867                 snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
868                                     WM8993_LINEOUT2_MODE,
869                                     WM8993_LINEOUT2_MODE);
870
871         /* If the line outputs are differential then we aren't presenting
872          * VMID as an output and can disable it.
873          */
874         if (lineout1_diff && lineout2_diff)
875                 codec->idle_bias_off = 1;
876
877         if (lineout1fb)
878                 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
879                                     WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
880
881         if (lineout2fb)
882                 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
883                                     WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
884
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 |
890                             micbias1_lvl |
891                             micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
892
893         return 0;
894 }
895 EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
896
897 MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
898 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
899 MODULE_LICENSE("GPL");