blob: 19ca782ac970f1956243862534e5df1df12a3113 [file] [log] [blame]
Mark Browna2342ae2009-07-29 21:21:49 +01001/*
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>
Mark Browna2342ae2009-07-29 21:21:49 +010021#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
32const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0);
33EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv);
34
35static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1650, 150, 0);
36static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv, 0, 3000, 0);
37static const DECLARE_TLV_DB_SCALE(inmix_tlv, -1500, 300, 1);
38static const DECLARE_TLV_DB_SCALE(earpiece_tlv, -600, 600, 0);
39static const DECLARE_TLV_DB_SCALE(outmix_tlv, -2100, 300, 0);
40static const DECLARE_TLV_DB_SCALE(spkmixout_tlv, -1800, 600, 1);
41static const DECLARE_TLV_DB_SCALE(outpga_tlv, -5700, 100, 0);
42static 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};
47static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0);
48
49static const char *speaker_ref_text[] = {
50 "SPKVDD/2",
51 "VMID",
52};
53
54static const struct soc_enum speaker_ref =
55 SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text);
56
57static const char *speaker_mode_text[] = {
58 "Class D",
59 "Class AB",
60};
61
62static const struct soc_enum speaker_mode =
63 SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text);
64
Mark Brown4dcc93d2010-03-29 17:18:41 +010065static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
Mark Browna2342ae2009-07-29 21:21:49 +010066{
67 unsigned int reg;
68 int count = 0;
Mark Brown4dcc93d2010-03-29 17:18:41 +010069 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);
Mark Browna2342ae2009-07-29 21:21:49 +010075
76 dev_dbg(codec->dev, "Waiting for DC servo...\n");
Mark Brown3ed70742010-01-20 17:39:45 +000077
Mark Browna2342ae2009-07-29 21:21:49 +010078 do {
79 count++;
80 msleep(1);
Mark Brown4dcc93d2010-03-29 17:18:41 +010081 reg = snd_soc_read(codec, WM8993_DC_SERVO_0);
Mark Brown3ed70742010-01-20 17:39:45 +000082 dev_dbg(codec->dev, "DC servo: %x\n", reg);
Mark Brown4dcc93d2010-03-29 17:18:41 +010083 } while (reg & op && count < 400);
Mark Browna2342ae2009-07-29 21:21:49 +010084
Mark Brown4dcc93d2010-03-29 17:18:41 +010085 if (reg & op)
Mark Browna2342ae2009-07-29 21:21:49 +010086 dev_err(codec->dev, "Timed out waiting for DC Servo\n");
87}
88
89/*
Mark Brown3ed70742010-01-20 17:39:45 +000090 * Startup calibration of the DC servo
91 */
92static void calibrate_dc_servo(struct snd_soc_codec *codec)
93{
Mark Brownb2c812e2010-04-14 15:35:19 +090094 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
Mark Brown8437f702010-03-29 17:09:45 +010095 u16 reg, reg_l, reg_r, dcs_cfg;
Mark Brown3ed70742010-01-20 17:39:45 +000096
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);
Mark Brown4dcc93d2010-03-29 17:18:41 +0100101 wait_for_dc_servo(codec,
102 WM8993_DCS_TRIG_SERIES_0 | WM8993_DCS_TRIG_SERIES_1);
Mark Brown3ed70742010-01-20 17:39:45 +0000103
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
Mark Brown8437f702010-03-29 17:09:45 +0100109 /* 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:
Joe Perches5a0b0742010-10-30 14:08:56 -0700126 WARN(1, "Unknown DCS readback method\n");
Mark Brown8437f702010-03-29 17:09:45 +0100127 break;
128 }
129
Mark Brown3254d282010-05-10 14:56:03 +0100130 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
131
Mark Brown3ed70742010-01-20 17:39:45 +0000132 /* HPOUT1L */
Mark Brown8437f702010-03-29 17:09:45 +0100133 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;
Mark Brown3ed70742010-01-20 17:39:45 +0000137
138 /* HPOUT1R */
Mark Brown8437f702010-03-29 17:09:45 +0100139 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;
Mark Brown3ed70742010-01-20 17:39:45 +0000143
Mark Brown3254d282010-05-10 14:56:03 +0100144 dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
145
Mark Brown3ed70742010-01-20 17:39:45 +0000146 /* Do it */
147 snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
Mark Brown4dcc93d2010-03-29 17:18:41 +0100148 wait_for_dc_servo(codec,
149 WM8993_DCS_TRIG_DAC_WR_0 |
150 WM8993_DCS_TRIG_DAC_WR_1);
Mark Brown3ed70742010-01-20 17:39:45 +0000151 }
152}
153
154/*
Mark Browna2342ae2009-07-29 21:21:49 +0100155 * Update the DC servo calibration on gain changes
156 */
157static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
Mark Brown3ed70742010-01-20 17:39:45 +0000158 struct snd_ctl_elem_value *ucontrol)
Mark Browna2342ae2009-07-29 21:21:49 +0100159{
160 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900161 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
Mark Browna2342ae2009-07-29 21:21:49 +0100162 int ret;
163
164 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
165
Mark Brownae9d8602010-03-29 16:34:42 +0100166 /* 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
Mark Browna2342ae2009-07-29 21:21:49 +0100171 /* 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
184static const struct snd_kcontrol_new analogue_snd_controls[] = {
185SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
186 inpga_tlv),
187SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
188SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
189
190SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
191 inpga_tlv),
192SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
193SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 0),
194
195
196SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
197 inpga_tlv),
198SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
199SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
200
201SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
202 inpga_tlv),
203SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
204SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 0),
205
206SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
207 inmix_sw_tlv),
208SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
209 inmix_sw_tlv),
210SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
211 inmix_tlv),
212SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv),
213SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0,
214 inmix_tlv),
215
216SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
217 inmix_sw_tlv),
218SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
219 inmix_sw_tlv),
220SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
221 inmix_tlv),
222SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv),
223SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0,
224 inmix_tlv),
225
226SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
227 outmix_tlv),
228SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
229 outmix_tlv),
230SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
231 outmix_tlv),
232SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
233 outmix_tlv),
234SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
235 outmix_tlv),
236SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
237 WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv),
238SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
239 WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv),
240SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1,
241 outmix_tlv),
242
243SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
244 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
245SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
246 WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv),
247SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
248 WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv),
249SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
250 WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv),
251SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
252 WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv),
253SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
254 WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv),
255SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
256 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
257SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
258 WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv),
259
260SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME,
261 WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv),
262SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME,
263 WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0),
264SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME,
265 WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0),
266
267SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1),
268SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv),
269
270SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION,
271 5, 1, 1, wm_hubs_spkmix_tlv),
272SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION,
273 4, 1, 1, wm_hubs_spkmix_tlv),
274SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION,
275 3, 1, 1, wm_hubs_spkmix_tlv),
276
277SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION,
278 5, 1, 1, wm_hubs_spkmix_tlv),
279SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION,
280 4, 1, 1, wm_hubs_spkmix_tlv),
281SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION,
282 3, 1, 1, wm_hubs_spkmix_tlv),
283
284SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
285 WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION,
286 0, 3, 1, spkmixout_tlv),
287SOC_DOUBLE_R_TLV("Speaker Volume",
288 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
289 0, 63, 0, outpga_tlv),
290SOC_DOUBLE_R("Speaker Switch",
291 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
292 6, 1, 0),
293SOC_DOUBLE_R("Speaker ZC Switch",
294 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
295 7, 1, 0),
296SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 0, 3, 7, 0,
297 spkboost_tlv),
298SOC_ENUM("Speaker Reference", speaker_ref),
299SOC_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},
314SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
315 WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
316SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
317 WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
318
319SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
320SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
321SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
322 line_tlv),
323
324SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
325SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
326SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
327 line_tlv),
328};
329
Mark Brown3ed70742010-01-20 17:39:45 +0000330static 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;
Mark Brownb2c812e2010-04-14 15:35:19 +0900334 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
Mark Brown3ed70742010-01-20 17:39:45 +0000335
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
Mark Browna2342ae2009-07-29 21:21:49 +0100371static 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
Mark Brown3ed70742010-01-20 17:39:45 +0000391 /* 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);
Mark Browna2342ae2009-07-29 21:21:49 +0100396
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:
Mark Brown3ed70742010-01-20 17:39:45 +0000403 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
Mark Brown6adb26b2010-05-10 16:13:11 +0100404 WM8993_HPOUT1L_OUTP |
405 WM8993_HPOUT1R_OUTP |
Mark Brown3ed70742010-01-20 17:39:45 +0000406 WM8993_HPOUT1L_RMV_SHORT |
407 WM8993_HPOUT1R_RMV_SHORT, 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100408
Mark Brown3ed70742010-01-20 17:39:45 +0000409 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
Mark Brown6adb26b2010-05-10 16:13:11 +0100410 WM8993_HPOUT1L_DLY |
411 WM8993_HPOUT1R_DLY, 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100412
Mark Brown395e4b72010-05-10 21:06:14 +0100413 snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
414
Mark Browna2342ae2009-07-29 21:21:49 +0100415 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
416 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
417 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100418 break;
419 }
420
421 return 0;
422}
423
424static 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
449static const struct snd_kcontrol_new in1l_pga[] = {
450SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
451SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
452};
453
454static const struct snd_kcontrol_new in1r_pga[] = {
455SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
456SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
457};
458
459static const struct snd_kcontrol_new in2l_pga[] = {
460SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
461SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
462};
463
464static const struct snd_kcontrol_new in2r_pga[] = {
465SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
466SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
467};
468
469static const struct snd_kcontrol_new mixinl[] = {
470SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
471SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
472};
473
474static const struct snd_kcontrol_new mixinr[] = {
475SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
476SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
477};
478
479static const struct snd_kcontrol_new left_output_mixer[] = {
480SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
481SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
482SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
483SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
484SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
485SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
486SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
487SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
488};
489
490static const struct snd_kcontrol_new right_output_mixer[] = {
491SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
492SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
493SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
494SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
495SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
496SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
497SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
498SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
499};
500
501static const struct snd_kcontrol_new earpiece_mixer[] = {
502SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
503SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
504SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
505};
506
507static const struct snd_kcontrol_new left_speaker_boost[] = {
508SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
509SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
510SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
511};
512
513static const struct snd_kcontrol_new right_speaker_boost[] = {
514SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
515SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
516SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
517};
518
519static const struct snd_kcontrol_new line1_mix[] = {
520SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
521SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
522SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
523};
524
525static const struct snd_kcontrol_new line1n_mix[] = {
526SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
527SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
528};
529
530static const struct snd_kcontrol_new line1p_mix[] = {
531SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
532};
533
534static const struct snd_kcontrol_new line2_mix[] = {
535SOC_DAPM_SINGLE("IN2R Switch", WM8993_LINE_MIXER2, 2, 1, 0),
536SOC_DAPM_SINGLE("IN2L Switch", WM8993_LINE_MIXER2, 1, 1, 0),
537SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
538};
539
540static const struct snd_kcontrol_new line2n_mix[] = {
541SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
542SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
543};
544
545static const struct snd_kcontrol_new line2p_mix[] = {
546SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
547};
548
549static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
550SND_SOC_DAPM_INPUT("IN1LN"),
551SND_SOC_DAPM_INPUT("IN1LP"),
552SND_SOC_DAPM_INPUT("IN2LN"),
Joonyoung Shim34825942009-12-04 15:12:10 +0900553SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
Mark Browna2342ae2009-07-29 21:21:49 +0100554SND_SOC_DAPM_INPUT("IN1RN"),
555SND_SOC_DAPM_INPUT("IN1RP"),
556SND_SOC_DAPM_INPUT("IN2RN"),
Joonyoung Shim34825942009-12-04 15:12:10 +0900557SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
Mark Browna2342ae2009-07-29 21:21:49 +0100558
559SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
560SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
561
562SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
563 in1l_pga, ARRAY_SIZE(in1l_pga)),
564SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
565 in1r_pga, ARRAY_SIZE(in1r_pga)),
566
567SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
568 in2l_pga, ARRAY_SIZE(in2l_pga)),
569SND_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 */
573SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
574
575SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
576 mixinl, ARRAY_SIZE(mixinl)),
577SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
578 mixinr, ARRAY_SIZE(mixinr)),
579
Mark Browna2342ae2009-07-29 21:21:49 +0100580SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
581 left_output_mixer, ARRAY_SIZE(left_output_mixer)),
582SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
583 right_output_mixer, ARRAY_SIZE(right_output_mixer)),
584
585SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
586SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
587
Mark Brown3ed70742010-01-20 17:39:45 +0000588SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event,
589 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Browna2342ae2009-07-29 21:21:49 +0100590SND_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
594SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
595 earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
596SND_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
600SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
601 left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
602SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
603 right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
604
605SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
606 NULL, 0),
607SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
608 NULL, 0),
609
610SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
611 line1_mix, ARRAY_SIZE(line1_mix)),
612SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
613 line2_mix, ARRAY_SIZE(line2_mix)),
614
615SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
616 line1n_mix, ARRAY_SIZE(line1n_mix)),
617SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
618 line1p_mix, ARRAY_SIZE(line1p_mix)),
619SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
620 line2n_mix, ARRAY_SIZE(line2n_mix)),
621SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
622 line2p_mix, ARRAY_SIZE(line2p_mix)),
623
624SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
625 NULL, 0),
626SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
627 NULL, 0),
628SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
629 NULL, 0),
630SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
631 NULL, 0),
632
633SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
634SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
635SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
636SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
637SND_SOC_DAPM_OUTPUT("HPOUT1L"),
638SND_SOC_DAPM_OUTPUT("HPOUT1R"),
639SND_SOC_DAPM_OUTPUT("HPOUT2P"),
640SND_SOC_DAPM_OUTPUT("HPOUT2N"),
641SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
642SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
643SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
644SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
645};
646
647static 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
Joonyoung Shim34825942009-12-04 15:12:10 +0900654 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
Mark Browna2342ae2009-07-29 21:21:49 +0100655 { "IN2L PGA", "IN2LN Switch", "IN2LN" },
656
Joonyoung Shim34825942009-12-04 15:12:10 +0900657 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +0100658 { "IN2R PGA", "IN2RN Switch", "IN2RN" },
659
Joonyoung Shim34825942009-12-04 15:12:10 +0900660 { "Direct Voice", NULL, "IN2LP:VXRN" },
661 { "Direct Voice", NULL, "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +0100662
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" },
Joonyoung Shim34825942009-12-04 15:12:10 +0900682 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
Mark Browna2342ae2009-07-29 21:21:49 +0100683 { "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" },
Joonyoung Shim34825942009-12-04 15:12:10 +0900690 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +0100691 { "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" },
Mark Brown3ed70742010-01-20 17:39:45 +0000743 { "Headphone PGA", NULL, "Headphone Supply" },
Mark Browna2342ae2009-07-29 21:21:49 +0100744
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
754static 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
763static 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
773static 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
782static 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
792int 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}
826EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
827
828int 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}
854EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
855
Mark Brownaa983d92009-09-30 14:16:11 +0100856int 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
Mark Brown821dd912010-01-21 11:33:20 +0000871 /* 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
Mark Brownaa983d92009-09-30 14:16:11 +0100877 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}
895EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
896
Mark Browna2342ae2009-07-29 21:21:49 +0100897MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
898MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
899MODULE_LICENSE("GPL");