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