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