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