]>
Commit | Line | Data |
---|---|---|
2b27bdcc | 1 | // SPDX-License-Identifier: GPL-2.0-only |
39b8eab7 MB |
2 | /* |
3 | * ALSA SoC WM9090 driver | |
4 | * | |
656baaeb | 5 | * Copyright 2009-12 Wolfson Microelectronics |
39b8eab7 MB |
6 | * |
7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | |
39b8eab7 MB |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/errno.h> | |
12 | #include <linux/device.h> | |
13 | #include <linux/i2c.h> | |
14 | #include <linux/delay.h> | |
ec2c0fec | 15 | #include <linux/regmap.h> |
39b8eab7 MB |
16 | #include <linux/slab.h> |
17 | #include <sound/initval.h> | |
18 | #include <sound/soc.h> | |
39b8eab7 MB |
19 | #include <sound/tlv.h> |
20 | #include <sound/wm9090.h> | |
21 | ||
22 | #include "wm9090.h" | |
23 | ||
ec2c0fec MB |
24 | static const struct reg_default wm9090_reg_defaults[] = { |
25 | { 1, 0x0006 }, /* R1 - Power Management (1) */ | |
26 | { 2, 0x6000 }, /* R2 - Power Management (2) */ | |
27 | { 3, 0x0000 }, /* R3 - Power Management (3) */ | |
28 | { 6, 0x01C0 }, /* R6 - Clocking 1 */ | |
29 | { 22, 0x0003 }, /* R22 - IN1 Line Control */ | |
30 | { 23, 0x0003 }, /* R23 - IN2 Line Control */ | |
31 | { 24, 0x0083 }, /* R24 - IN1 Line Input A Volume */ | |
32 | { 25, 0x0083 }, /* R25 - IN1 Line Input B Volume */ | |
33 | { 26, 0x0083 }, /* R26 - IN2 Line Input A Volume */ | |
34 | { 27, 0x0083 }, /* R27 - IN2 Line Input B Volume */ | |
35 | { 28, 0x002D }, /* R28 - Left Output Volume */ | |
36 | { 29, 0x002D }, /* R29 - Right Output Volume */ | |
37 | { 34, 0x0100 }, /* R34 - SPKMIXL Attenuation */ | |
38 | { 35, 0x0010 }, /* R36 - SPKOUT Mixers */ | |
39 | { 37, 0x0140 }, /* R37 - ClassD3 */ | |
40 | { 38, 0x0039 }, /* R38 - Speaker Volume Left */ | |
41 | { 45, 0x0000 }, /* R45 - Output Mixer1 */ | |
42 | { 46, 0x0000 }, /* R46 - Output Mixer2 */ | |
43 | { 47, 0x0100 }, /* R47 - Output Mixer3 */ | |
44 | { 48, 0x0100 }, /* R48 - Output Mixer4 */ | |
45 | { 54, 0x0000 }, /* R54 - Speaker Mixer */ | |
46 | { 57, 0x000D }, /* R57 - AntiPOP2 */ | |
47 | { 70, 0x0000 }, /* R70 - Write Sequencer 0 */ | |
48 | { 71, 0x0000 }, /* R71 - Write Sequencer 1 */ | |
49 | { 72, 0x0000 }, /* R72 - Write Sequencer 2 */ | |
50 | { 73, 0x0000 }, /* R73 - Write Sequencer 3 */ | |
51 | { 74, 0x0000 }, /* R74 - Write Sequencer 4 */ | |
52 | { 75, 0x0000 }, /* R75 - Write Sequencer 5 */ | |
53 | { 76, 0x1F25 }, /* R76 - Charge Pump 1 */ | |
54 | { 85, 0x054A }, /* R85 - DC Servo 1 */ | |
55 | { 87, 0x0000 }, /* R87 - DC Servo 3 */ | |
56 | { 96, 0x0100 }, /* R96 - Analogue HP 0 */ | |
57 | { 98, 0x8640 }, /* R98 - AGC Control 0 */ | |
58 | { 99, 0xC000 }, /* R99 - AGC Control 1 */ | |
59 | { 100, 0x0200 }, /* R100 - AGC Control 2 */ | |
39b8eab7 MB |
60 | }; |
61 | ||
62 | /* This struct is used to save the context */ | |
63 | struct wm9090_priv { | |
39b8eab7 | 64 | struct wm9090_platform_data pdata; |
ec2c0fec | 65 | struct regmap *regmap; |
39b8eab7 MB |
66 | }; |
67 | ||
ec2c0fec | 68 | static bool wm9090_volatile(struct device *dev, unsigned int reg) |
39b8eab7 MB |
69 | { |
70 | switch (reg) { | |
71 | case WM9090_SOFTWARE_RESET: | |
72 | case WM9090_DC_SERVO_0: | |
73 | case WM9090_DC_SERVO_READBACK_0: | |
74 | case WM9090_DC_SERVO_READBACK_1: | |
75 | case WM9090_DC_SERVO_READBACK_2: | |
ec2c0fec | 76 | return true; |
39b8eab7 MB |
77 | |
78 | default: | |
ec2c0fec MB |
79 | return false; |
80 | } | |
81 | } | |
82 | ||
83 | static bool wm9090_readable(struct device *dev, unsigned int reg) | |
84 | { | |
85 | switch (reg) { | |
86 | case WM9090_SOFTWARE_RESET: | |
87 | case WM9090_POWER_MANAGEMENT_1: | |
88 | case WM9090_POWER_MANAGEMENT_2: | |
89 | case WM9090_POWER_MANAGEMENT_3: | |
90 | case WM9090_CLOCKING_1: | |
91 | case WM9090_IN1_LINE_CONTROL: | |
92 | case WM9090_IN2_LINE_CONTROL: | |
93 | case WM9090_IN1_LINE_INPUT_A_VOLUME: | |
94 | case WM9090_IN1_LINE_INPUT_B_VOLUME: | |
95 | case WM9090_IN2_LINE_INPUT_A_VOLUME: | |
96 | case WM9090_IN2_LINE_INPUT_B_VOLUME: | |
97 | case WM9090_LEFT_OUTPUT_VOLUME: | |
98 | case WM9090_RIGHT_OUTPUT_VOLUME: | |
99 | case WM9090_SPKMIXL_ATTENUATION: | |
100 | case WM9090_SPKOUT_MIXERS: | |
101 | case WM9090_CLASSD3: | |
102 | case WM9090_SPEAKER_VOLUME_LEFT: | |
103 | case WM9090_OUTPUT_MIXER1: | |
104 | case WM9090_OUTPUT_MIXER2: | |
105 | case WM9090_OUTPUT_MIXER3: | |
106 | case WM9090_OUTPUT_MIXER4: | |
107 | case WM9090_SPEAKER_MIXER: | |
108 | case WM9090_ANTIPOP2: | |
109 | case WM9090_WRITE_SEQUENCER_0: | |
110 | case WM9090_WRITE_SEQUENCER_1: | |
111 | case WM9090_WRITE_SEQUENCER_2: | |
112 | case WM9090_WRITE_SEQUENCER_3: | |
113 | case WM9090_WRITE_SEQUENCER_4: | |
114 | case WM9090_WRITE_SEQUENCER_5: | |
115 | case WM9090_CHARGE_PUMP_1: | |
116 | case WM9090_DC_SERVO_0: | |
117 | case WM9090_DC_SERVO_1: | |
118 | case WM9090_DC_SERVO_3: | |
119 | case WM9090_DC_SERVO_READBACK_0: | |
120 | case WM9090_DC_SERVO_READBACK_1: | |
121 | case WM9090_DC_SERVO_READBACK_2: | |
122 | case WM9090_ANALOGUE_HP_0: | |
123 | case WM9090_AGC_CONTROL_0: | |
124 | case WM9090_AGC_CONTROL_1: | |
125 | case WM9090_AGC_CONTROL_2: | |
126 | return true; | |
127 | ||
128 | default: | |
129 | return false; | |
39b8eab7 MB |
130 | } |
131 | } | |
132 | ||
2822e66b | 133 | static void wait_for_dc_servo(struct snd_soc_component *component) |
39b8eab7 MB |
134 | { |
135 | unsigned int reg; | |
136 | int count = 0; | |
137 | ||
2822e66b | 138 | dev_dbg(component->dev, "Waiting for DC servo...\n"); |
39b8eab7 MB |
139 | do { |
140 | count++; | |
141 | msleep(1); | |
2822e66b KM |
142 | reg = snd_soc_component_read32(component, WM9090_DC_SERVO_READBACK_0); |
143 | dev_dbg(component->dev, "DC servo status: %x\n", reg); | |
39b8eab7 MB |
144 | } while ((reg & WM9090_DCS_CAL_COMPLETE_MASK) |
145 | != WM9090_DCS_CAL_COMPLETE_MASK && count < 1000); | |
146 | ||
147 | if ((reg & WM9090_DCS_CAL_COMPLETE_MASK) | |
148 | != WM9090_DCS_CAL_COMPLETE_MASK) | |
2822e66b | 149 | dev_err(component->dev, "Timed out waiting for DC Servo\n"); |
39b8eab7 MB |
150 | } |
151 | ||
0894e2b3 | 152 | static const DECLARE_TLV_DB_RANGE(in_tlv, |
39b8eab7 MB |
153 | 0, 0, TLV_DB_SCALE_ITEM(-600, 0, 0), |
154 | 1, 3, TLV_DB_SCALE_ITEM(-350, 350, 0), | |
0894e2b3 LPC |
155 | 4, 6, TLV_DB_SCALE_ITEM(600, 600, 0) |
156 | ); | |
157 | static const DECLARE_TLV_DB_RANGE(mix_tlv, | |
39b8eab7 | 158 | 0, 2, TLV_DB_SCALE_ITEM(-1200, 300, 0), |
0894e2b3 LPC |
159 | 3, 3, TLV_DB_SCALE_ITEM(0, 0, 0) |
160 | ); | |
39b8eab7 | 161 | static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0); |
0894e2b3 | 162 | static const DECLARE_TLV_DB_RANGE(spkboost_tlv, |
39b8eab7 | 163 | 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0), |
0894e2b3 LPC |
164 | 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0) |
165 | ); | |
39b8eab7 MB |
166 | |
167 | static const struct snd_kcontrol_new wm9090_controls[] = { | |
168 | SOC_SINGLE_TLV("IN1A Volume", WM9090_IN1_LINE_INPUT_A_VOLUME, 0, 6, 0, | |
169 | in_tlv), | |
170 | SOC_SINGLE("IN1A Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 7, 1, 1), | |
171 | SOC_SINGLE("IN1A ZC Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 6, 1, 0), | |
172 | ||
173 | SOC_SINGLE_TLV("IN2A Volume", WM9090_IN2_LINE_INPUT_A_VOLUME, 0, 6, 0, | |
174 | in_tlv), | |
175 | SOC_SINGLE("IN2A Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 7, 1, 1), | |
176 | SOC_SINGLE("IN2A ZC Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 6, 1, 0), | |
177 | ||
178 | SOC_SINGLE("MIXOUTL Switch", WM9090_OUTPUT_MIXER3, 8, 1, 1), | |
179 | SOC_SINGLE_TLV("MIXOUTL IN1A Volume", WM9090_OUTPUT_MIXER3, 6, 3, 1, | |
180 | mix_tlv), | |
181 | SOC_SINGLE_TLV("MIXOUTL IN2A Volume", WM9090_OUTPUT_MIXER3, 2, 3, 1, | |
182 | mix_tlv), | |
183 | ||
184 | SOC_SINGLE("MIXOUTR Switch", WM9090_OUTPUT_MIXER4, 8, 1, 1), | |
185 | SOC_SINGLE_TLV("MIXOUTR IN1A Volume", WM9090_OUTPUT_MIXER4, 6, 3, 1, | |
186 | mix_tlv), | |
187 | SOC_SINGLE_TLV("MIXOUTR IN2A Volume", WM9090_OUTPUT_MIXER4, 2, 3, 1, | |
188 | mix_tlv), | |
189 | ||
190 | SOC_SINGLE("SPKMIX Switch", WM9090_SPKMIXL_ATTENUATION, 8, 1, 1), | |
191 | SOC_SINGLE_TLV("SPKMIX IN1A Volume", WM9090_SPKMIXL_ATTENUATION, 6, 3, 1, | |
192 | mix_tlv), | |
193 | SOC_SINGLE_TLV("SPKMIX IN2A Volume", WM9090_SPKMIXL_ATTENUATION, 2, 3, 1, | |
194 | mix_tlv), | |
195 | ||
196 | SOC_DOUBLE_R_TLV("Headphone Volume", WM9090_LEFT_OUTPUT_VOLUME, | |
197 | WM9090_RIGHT_OUTPUT_VOLUME, 0, 63, 0, out_tlv), | |
198 | SOC_DOUBLE_R("Headphone Switch", WM9090_LEFT_OUTPUT_VOLUME, | |
199 | WM9090_RIGHT_OUTPUT_VOLUME, 6, 1, 1), | |
200 | SOC_DOUBLE_R("Headphone ZC Switch", WM9090_LEFT_OUTPUT_VOLUME, | |
201 | WM9090_RIGHT_OUTPUT_VOLUME, 7, 1, 0), | |
202 | ||
203 | SOC_SINGLE_TLV("Speaker Volume", WM9090_SPEAKER_VOLUME_LEFT, 0, 63, 0, | |
204 | out_tlv), | |
205 | SOC_SINGLE("Speaker Switch", WM9090_SPEAKER_VOLUME_LEFT, 6, 1, 1), | |
206 | SOC_SINGLE("Speaker ZC Switch", WM9090_SPEAKER_VOLUME_LEFT, 7, 1, 0), | |
207 | SOC_SINGLE_TLV("Speaker Boost Volume", WM9090_CLASSD3, 3, 7, 0, spkboost_tlv), | |
208 | }; | |
209 | ||
210 | static const struct snd_kcontrol_new wm9090_in1_se_controls[] = { | |
211 | SOC_SINGLE_TLV("IN1B Volume", WM9090_IN1_LINE_INPUT_B_VOLUME, 0, 6, 0, | |
212 | in_tlv), | |
213 | SOC_SINGLE("IN1B Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 7, 1, 1), | |
214 | SOC_SINGLE("IN1B ZC Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 6, 1, 0), | |
215 | ||
216 | SOC_SINGLE_TLV("SPKMIX IN1B Volume", WM9090_SPKMIXL_ATTENUATION, 4, 3, 1, | |
217 | mix_tlv), | |
218 | SOC_SINGLE_TLV("MIXOUTL IN1B Volume", WM9090_OUTPUT_MIXER3, 4, 3, 1, | |
219 | mix_tlv), | |
220 | SOC_SINGLE_TLV("MIXOUTR IN1B Volume", WM9090_OUTPUT_MIXER4, 4, 3, 1, | |
221 | mix_tlv), | |
222 | }; | |
223 | ||
224 | static const struct snd_kcontrol_new wm9090_in2_se_controls[] = { | |
225 | SOC_SINGLE_TLV("IN2B Volume", WM9090_IN2_LINE_INPUT_B_VOLUME, 0, 6, 0, | |
226 | in_tlv), | |
227 | SOC_SINGLE("IN2B Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 7, 1, 1), | |
228 | SOC_SINGLE("IN2B ZC Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 6, 1, 0), | |
229 | ||
230 | SOC_SINGLE_TLV("SPKMIX IN2B Volume", WM9090_SPKMIXL_ATTENUATION, 0, 3, 1, | |
231 | mix_tlv), | |
232 | SOC_SINGLE_TLV("MIXOUTL IN2B Volume", WM9090_OUTPUT_MIXER3, 0, 3, 1, | |
233 | mix_tlv), | |
234 | SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4, 0, 3, 1, | |
235 | mix_tlv), | |
236 | }; | |
237 | ||
238 | static int hp_ev(struct snd_soc_dapm_widget *w, | |
239 | struct snd_kcontrol *kcontrol, int event) | |
240 | { | |
2822e66b KM |
241 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
242 | unsigned int reg = snd_soc_component_read32(component, WM9090_ANALOGUE_HP_0); | |
39b8eab7 MB |
243 | |
244 | switch (event) { | |
245 | case SND_SOC_DAPM_POST_PMU: | |
2822e66b | 246 | snd_soc_component_update_bits(component, WM9090_CHARGE_PUMP_1, |
39b8eab7 MB |
247 | WM9090_CP_ENA, WM9090_CP_ENA); |
248 | ||
249 | msleep(5); | |
250 | ||
2822e66b | 251 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, |
39b8eab7 MB |
252 | WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA, |
253 | WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA); | |
254 | ||
255 | reg |= WM9090_HPOUT1L_DLY | WM9090_HPOUT1R_DLY; | |
2822e66b | 256 | snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); |
39b8eab7 MB |
257 | |
258 | /* Start the DC servo. We don't currently use the | |
259 | * ability to save the state since we don't have full | |
260 | * control of the analogue paths and they can change | |
261 | * DC offsets; see the WM8904 driver for an example of | |
262 | * doing so. | |
263 | */ | |
2822e66b | 264 | snd_soc_component_write(component, WM9090_DC_SERVO_0, |
39b8eab7 MB |
265 | WM9090_DCS_ENA_CHAN_0 | |
266 | WM9090_DCS_ENA_CHAN_1 | | |
267 | WM9090_DCS_TRIG_STARTUP_1 | | |
268 | WM9090_DCS_TRIG_STARTUP_0); | |
2822e66b | 269 | wait_for_dc_servo(component); |
39b8eab7 MB |
270 | |
271 | reg |= WM9090_HPOUT1R_OUTP | WM9090_HPOUT1R_RMV_SHORT | | |
272 | WM9090_HPOUT1L_OUTP | WM9090_HPOUT1L_RMV_SHORT; | |
2822e66b | 273 | snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); |
39b8eab7 MB |
274 | break; |
275 | ||
276 | case SND_SOC_DAPM_PRE_PMD: | |
277 | reg &= ~(WM9090_HPOUT1L_RMV_SHORT | | |
278 | WM9090_HPOUT1L_DLY | | |
279 | WM9090_HPOUT1L_OUTP | | |
280 | WM9090_HPOUT1R_RMV_SHORT | | |
281 | WM9090_HPOUT1R_DLY | | |
282 | WM9090_HPOUT1R_OUTP); | |
283 | ||
2822e66b | 284 | snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); |
39b8eab7 | 285 | |
2822e66b | 286 | snd_soc_component_write(component, WM9090_DC_SERVO_0, 0); |
39b8eab7 | 287 | |
2822e66b | 288 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, |
39b8eab7 MB |
289 | WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA, |
290 | 0); | |
291 | ||
2822e66b | 292 | snd_soc_component_update_bits(component, WM9090_CHARGE_PUMP_1, |
39b8eab7 MB |
293 | WM9090_CP_ENA, 0); |
294 | break; | |
295 | } | |
296 | ||
297 | return 0; | |
298 | } | |
299 | ||
300 | static const struct snd_kcontrol_new spkmix[] = { | |
301 | SOC_DAPM_SINGLE("IN1A Switch", WM9090_SPEAKER_MIXER, 6, 1, 0), | |
302 | SOC_DAPM_SINGLE("IN1B Switch", WM9090_SPEAKER_MIXER, 4, 1, 0), | |
303 | SOC_DAPM_SINGLE("IN2A Switch", WM9090_SPEAKER_MIXER, 2, 1, 0), | |
304 | SOC_DAPM_SINGLE("IN2B Switch", WM9090_SPEAKER_MIXER, 0, 1, 0), | |
305 | }; | |
306 | ||
307 | static const struct snd_kcontrol_new spkout[] = { | |
308 | SOC_DAPM_SINGLE("Mixer Switch", WM9090_SPKOUT_MIXERS, 4, 1, 0), | |
309 | }; | |
310 | ||
311 | static const struct snd_kcontrol_new mixoutl[] = { | |
312 | SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER1, 6, 1, 0), | |
313 | SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER1, 4, 1, 0), | |
314 | SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER1, 2, 1, 0), | |
315 | SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER1, 0, 1, 0), | |
316 | }; | |
317 | ||
318 | static const struct snd_kcontrol_new mixoutr[] = { | |
319 | SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER2, 6, 1, 0), | |
320 | SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER2, 4, 1, 0), | |
321 | SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER2, 2, 1, 0), | |
322 | SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER2, 0, 1, 0), | |
323 | }; | |
324 | ||
325 | static const struct snd_soc_dapm_widget wm9090_dapm_widgets[] = { | |
326 | SND_SOC_DAPM_INPUT("IN1+"), | |
327 | SND_SOC_DAPM_INPUT("IN1-"), | |
328 | SND_SOC_DAPM_INPUT("IN2+"), | |
329 | SND_SOC_DAPM_INPUT("IN2-"), | |
330 | ||
331 | SND_SOC_DAPM_SUPPLY("OSC", WM9090_POWER_MANAGEMENT_1, 3, 0, NULL, 0), | |
332 | ||
333 | SND_SOC_DAPM_PGA("IN1A PGA", WM9090_POWER_MANAGEMENT_2, 7, 0, NULL, 0), | |
334 | SND_SOC_DAPM_PGA("IN1B PGA", WM9090_POWER_MANAGEMENT_2, 6, 0, NULL, 0), | |
335 | SND_SOC_DAPM_PGA("IN2A PGA", WM9090_POWER_MANAGEMENT_2, 5, 0, NULL, 0), | |
336 | SND_SOC_DAPM_PGA("IN2B PGA", WM9090_POWER_MANAGEMENT_2, 4, 0, NULL, 0), | |
337 | ||
338 | SND_SOC_DAPM_MIXER("SPKMIX", WM9090_POWER_MANAGEMENT_3, 3, 0, | |
339 | spkmix, ARRAY_SIZE(spkmix)), | |
340 | SND_SOC_DAPM_MIXER("MIXOUTL", WM9090_POWER_MANAGEMENT_3, 5, 0, | |
341 | mixoutl, ARRAY_SIZE(mixoutl)), | |
342 | SND_SOC_DAPM_MIXER("MIXOUTR", WM9090_POWER_MANAGEMENT_3, 4, 0, | |
343 | mixoutr, ARRAY_SIZE(mixoutr)), | |
344 | ||
345 | SND_SOC_DAPM_PGA_E("HP PGA", SND_SOC_NOPM, 0, 0, NULL, 0, | |
346 | hp_ev, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | |
347 | ||
348 | SND_SOC_DAPM_PGA("SPKPGA", WM9090_POWER_MANAGEMENT_3, 8, 0, NULL, 0), | |
349 | SND_SOC_DAPM_MIXER("SPKOUT", WM9090_POWER_MANAGEMENT_1, 12, 0, | |
350 | spkout, ARRAY_SIZE(spkout)), | |
351 | ||
352 | SND_SOC_DAPM_OUTPUT("HPR"), | |
353 | SND_SOC_DAPM_OUTPUT("HPL"), | |
354 | SND_SOC_DAPM_OUTPUT("Speaker"), | |
355 | }; | |
356 | ||
357 | static const struct snd_soc_dapm_route audio_map[] = { | |
358 | { "IN1A PGA", NULL, "IN1+" }, | |
359 | { "IN2A PGA", NULL, "IN2+" }, | |
360 | ||
361 | { "SPKMIX", "IN1A Switch", "IN1A PGA" }, | |
362 | { "SPKMIX", "IN2A Switch", "IN2A PGA" }, | |
363 | ||
364 | { "MIXOUTL", "IN1A Switch", "IN1A PGA" }, | |
365 | { "MIXOUTL", "IN2A Switch", "IN2A PGA" }, | |
366 | ||
367 | { "MIXOUTR", "IN1A Switch", "IN1A PGA" }, | |
368 | { "MIXOUTR", "IN2A Switch", "IN2A PGA" }, | |
369 | ||
370 | { "HP PGA", NULL, "OSC" }, | |
371 | { "HP PGA", NULL, "MIXOUTL" }, | |
372 | { "HP PGA", NULL, "MIXOUTR" }, | |
373 | ||
374 | { "HPL", NULL, "HP PGA" }, | |
375 | { "HPR", NULL, "HP PGA" }, | |
376 | ||
377 | { "SPKPGA", NULL, "OSC" }, | |
378 | { "SPKPGA", NULL, "SPKMIX" }, | |
379 | ||
380 | { "SPKOUT", "Mixer Switch", "SPKPGA" }, | |
381 | ||
382 | { "Speaker", NULL, "SPKOUT" }, | |
383 | }; | |
384 | ||
385 | static const struct snd_soc_dapm_route audio_map_in1_se[] = { | |
386 | { "IN1B PGA", NULL, "IN1-" }, | |
387 | ||
388 | { "SPKMIX", "IN1B Switch", "IN1B PGA" }, | |
389 | { "MIXOUTL", "IN1B Switch", "IN1B PGA" }, | |
390 | { "MIXOUTR", "IN1B Switch", "IN1B PGA" }, | |
391 | }; | |
392 | ||
393 | static const struct snd_soc_dapm_route audio_map_in1_diff[] = { | |
394 | { "IN1A PGA", NULL, "IN1-" }, | |
395 | }; | |
396 | ||
397 | static const struct snd_soc_dapm_route audio_map_in2_se[] = { | |
398 | { "IN2B PGA", NULL, "IN2-" }, | |
399 | ||
400 | { "SPKMIX", "IN2B Switch", "IN2B PGA" }, | |
401 | { "MIXOUTL", "IN2B Switch", "IN2B PGA" }, | |
402 | { "MIXOUTR", "IN2B Switch", "IN2B PGA" }, | |
403 | }; | |
404 | ||
405 | static const struct snd_soc_dapm_route audio_map_in2_diff[] = { | |
406 | { "IN2A PGA", NULL, "IN2-" }, | |
407 | }; | |
408 | ||
2822e66b | 409 | static int wm9090_add_controls(struct snd_soc_component *component) |
39b8eab7 | 410 | { |
2822e66b KM |
411 | struct wm9090_priv *wm9090 = snd_soc_component_get_drvdata(component); |
412 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); | |
39b8eab7 MB |
413 | int i; |
414 | ||
ce6120cc | 415 | snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets, |
39b8eab7 MB |
416 | ARRAY_SIZE(wm9090_dapm_widgets)); |
417 | ||
ce6120cc | 418 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
39b8eab7 | 419 | |
2822e66b | 420 | snd_soc_add_component_controls(component, wm9090_controls, |
39b8eab7 MB |
421 | ARRAY_SIZE(wm9090_controls)); |
422 | ||
423 | if (wm9090->pdata.lin1_diff) { | |
ce6120cc | 424 | snd_soc_dapm_add_routes(dapm, audio_map_in1_diff, |
39b8eab7 MB |
425 | ARRAY_SIZE(audio_map_in1_diff)); |
426 | } else { | |
ce6120cc | 427 | snd_soc_dapm_add_routes(dapm, audio_map_in1_se, |
39b8eab7 | 428 | ARRAY_SIZE(audio_map_in1_se)); |
2822e66b | 429 | snd_soc_add_component_controls(component, wm9090_in1_se_controls, |
39b8eab7 MB |
430 | ARRAY_SIZE(wm9090_in1_se_controls)); |
431 | } | |
432 | ||
433 | if (wm9090->pdata.lin2_diff) { | |
ce6120cc | 434 | snd_soc_dapm_add_routes(dapm, audio_map_in2_diff, |
39b8eab7 MB |
435 | ARRAY_SIZE(audio_map_in2_diff)); |
436 | } else { | |
ce6120cc | 437 | snd_soc_dapm_add_routes(dapm, audio_map_in2_se, |
39b8eab7 | 438 | ARRAY_SIZE(audio_map_in2_se)); |
2822e66b | 439 | snd_soc_add_component_controls(component, wm9090_in2_se_controls, |
39b8eab7 MB |
440 | ARRAY_SIZE(wm9090_in2_se_controls)); |
441 | } | |
442 | ||
443 | if (wm9090->pdata.agc_ena) { | |
444 | for (i = 0; i < ARRAY_SIZE(wm9090->pdata.agc); i++) | |
2822e66b | 445 | snd_soc_component_write(component, WM9090_AGC_CONTROL_0 + i, |
39b8eab7 | 446 | wm9090->pdata.agc[i]); |
2822e66b | 447 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_3, |
39b8eab7 MB |
448 | WM9090_AGC_ENA, WM9090_AGC_ENA); |
449 | } else { | |
2822e66b | 450 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_3, |
39b8eab7 MB |
451 | WM9090_AGC_ENA, 0); |
452 | } | |
453 | ||
454 | return 0; | |
455 | ||
456 | } | |
457 | ||
458 | /* | |
459 | * The machine driver should call this from their set_bias_level; if there | |
460 | * isn't one then this can just be set as the set_bias_level function. | |
461 | */ | |
2822e66b | 462 | static int wm9090_set_bias_level(struct snd_soc_component *component, |
39b8eab7 MB |
463 | enum snd_soc_bias_level level) |
464 | { | |
2822e66b | 465 | struct wm9090_priv *wm9090 = snd_soc_component_get_drvdata(component); |
39b8eab7 MB |
466 | |
467 | switch (level) { | |
468 | case SND_SOC_BIAS_ON: | |
469 | break; | |
470 | ||
471 | case SND_SOC_BIAS_PREPARE: | |
2822e66b | 472 | snd_soc_component_update_bits(component, WM9090_ANTIPOP2, WM9090_VMID_ENA, |
39b8eab7 | 473 | WM9090_VMID_ENA); |
2822e66b | 474 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, |
39b8eab7 MB |
475 | WM9090_BIAS_ENA | |
476 | WM9090_VMID_RES_MASK, | |
477 | WM9090_BIAS_ENA | | |
478 | 1 << WM9090_VMID_RES_SHIFT); | |
479 | msleep(1); /* Probably an overestimate */ | |
480 | break; | |
481 | ||
482 | case SND_SOC_BIAS_STANDBY: | |
2822e66b | 483 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { |
39b8eab7 | 484 | /* Restore the register cache */ |
ec2c0fec | 485 | regcache_sync(wm9090->regmap); |
39b8eab7 MB |
486 | } |
487 | ||
488 | /* We keep VMID off during standby since the combination of | |
489 | * ground referenced outputs and class D speaker mean that | |
490 | * latency is not an issue. | |
491 | */ | |
2822e66b | 492 | snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, |
39b8eab7 | 493 | WM9090_BIAS_ENA | WM9090_VMID_RES_MASK, 0); |
2822e66b | 494 | snd_soc_component_update_bits(component, WM9090_ANTIPOP2, |
39b8eab7 MB |
495 | WM9090_VMID_ENA, 0); |
496 | break; | |
497 | ||
498 | case SND_SOC_BIAS_OFF: | |
499 | break; | |
500 | } | |
501 | ||
39b8eab7 MB |
502 | return 0; |
503 | } | |
504 | ||
2822e66b | 505 | static int wm9090_probe(struct snd_soc_component *component) |
39b8eab7 | 506 | { |
f0fba2ad LG |
507 | /* Configure some defaults; they will be written out when we |
508 | * bring the bias up. | |
509 | */ | |
2822e66b | 510 | snd_soc_component_update_bits(component, WM9090_IN1_LINE_INPUT_A_VOLUME, |
a1b3b5ee MB |
511 | WM9090_IN1_VU | WM9090_IN1A_ZC, |
512 | WM9090_IN1_VU | WM9090_IN1A_ZC); | |
2822e66b | 513 | snd_soc_component_update_bits(component, WM9090_IN1_LINE_INPUT_B_VOLUME, |
a1b3b5ee MB |
514 | WM9090_IN1_VU | WM9090_IN1B_ZC, |
515 | WM9090_IN1_VU | WM9090_IN1B_ZC); | |
2822e66b | 516 | snd_soc_component_update_bits(component, WM9090_IN2_LINE_INPUT_A_VOLUME, |
a1b3b5ee MB |
517 | WM9090_IN2_VU | WM9090_IN2A_ZC, |
518 | WM9090_IN2_VU | WM9090_IN2A_ZC); | |
2822e66b | 519 | snd_soc_component_update_bits(component, WM9090_IN2_LINE_INPUT_B_VOLUME, |
a1b3b5ee MB |
520 | WM9090_IN2_VU | WM9090_IN2B_ZC, |
521 | WM9090_IN2_VU | WM9090_IN2B_ZC); | |
2822e66b | 522 | snd_soc_component_update_bits(component, WM9090_SPEAKER_VOLUME_LEFT, |
a1b3b5ee MB |
523 | WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC, |
524 | WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC); | |
2822e66b | 525 | snd_soc_component_update_bits(component, WM9090_LEFT_OUTPUT_VOLUME, |
a1b3b5ee MB |
526 | WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC, |
527 | WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC); | |
2822e66b | 528 | snd_soc_component_update_bits(component, WM9090_RIGHT_OUTPUT_VOLUME, |
a1b3b5ee MB |
529 | WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC, |
530 | WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC); | |
531 | ||
2822e66b | 532 | snd_soc_component_update_bits(component, WM9090_CLOCKING_1, |
a1b3b5ee | 533 | WM9090_TOCLK_ENA, WM9090_TOCLK_ENA); |
f0fba2ad | 534 | |
2822e66b | 535 | wm9090_add_controls(component); |
39b8eab7 MB |
536 | |
537 | return 0; | |
39b8eab7 MB |
538 | } |
539 | ||
2822e66b KM |
540 | static const struct snd_soc_component_driver soc_component_dev_wm9090 = { |
541 | .probe = wm9090_probe, | |
542 | .set_bias_level = wm9090_set_bias_level, | |
543 | .suspend_bias_off = 1, | |
544 | .idle_bias_on = 1, | |
545 | .use_pmdown_time = 1, | |
546 | .endianness = 1, | |
547 | .non_legacy_dai_naming = 1, | |
39b8eab7 | 548 | }; |
39b8eab7 | 549 | |
ec2c0fec MB |
550 | static const struct regmap_config wm9090_regmap = { |
551 | .reg_bits = 8, | |
552 | .val_bits = 16, | |
553 | ||
554 | .max_register = WM9090_MAX_REGISTER, | |
555 | .volatile_reg = wm9090_volatile, | |
556 | .readable_reg = wm9090_readable, | |
557 | ||
558 | .cache_type = REGCACHE_RBTREE, | |
559 | .reg_defaults = wm9090_reg_defaults, | |
560 | .num_reg_defaults = ARRAY_SIZE(wm9090_reg_defaults), | |
561 | }; | |
562 | ||
563 | ||
39b8eab7 MB |
564 | static int wm9090_i2c_probe(struct i2c_client *i2c, |
565 | const struct i2c_device_id *id) | |
566 | { | |
567 | struct wm9090_priv *wm9090; | |
391d9e4e | 568 | unsigned int reg; |
39b8eab7 MB |
569 | int ret; |
570 | ||
455b91bf | 571 | wm9090 = devm_kzalloc(&i2c->dev, sizeof(*wm9090), GFP_KERNEL); |
0463585c | 572 | if (!wm9090) |
39b8eab7 | 573 | return -ENOMEM; |
39b8eab7 | 574 | |
be7eaf53 | 575 | wm9090->regmap = devm_regmap_init_i2c(i2c, &wm9090_regmap); |
ec2c0fec MB |
576 | if (IS_ERR(wm9090->regmap)) { |
577 | ret = PTR_ERR(wm9090->regmap); | |
578 | dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); | |
579 | return ret; | |
580 | } | |
581 | ||
391d9e4e MB |
582 | ret = regmap_read(wm9090->regmap, WM9090_SOFTWARE_RESET, ®); |
583 | if (ret < 0) | |
be7eaf53 SK |
584 | return ret; |
585 | ||
391d9e4e | 586 | if (reg != 0x9093) { |
905b4195 | 587 | dev_err(&i2c->dev, "Device is not a WM9090, ID=%x\n", reg); |
be7eaf53 | 588 | return -ENODEV; |
391d9e4e MB |
589 | } |
590 | ||
591 | ret = regmap_write(wm9090->regmap, WM9090_SOFTWARE_RESET, 0); | |
592 | if (ret < 0) | |
be7eaf53 | 593 | return ret; |
391d9e4e | 594 | |
39b8eab7 MB |
595 | if (i2c->dev.platform_data) |
596 | memcpy(&wm9090->pdata, i2c->dev.platform_data, | |
597 | sizeof(wm9090->pdata)); | |
598 | ||
39b8eab7 MB |
599 | i2c_set_clientdata(i2c, wm9090); |
600 | ||
2822e66b KM |
601 | ret = devm_snd_soc_register_component(&i2c->dev, |
602 | &soc_component_dev_wm9090, NULL, 0); | |
ec2c0fec MB |
603 | if (ret != 0) { |
604 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); | |
be7eaf53 | 605 | return ret; |
ec2c0fec MB |
606 | } |
607 | ||
608 | return 0; | |
39b8eab7 MB |
609 | } |
610 | ||
39b8eab7 MB |
611 | static const struct i2c_device_id wm9090_id[] = { |
612 | { "wm9090", 0 }, | |
644f1ff4 | 613 | { "wm9093", 0 }, |
39b8eab7 MB |
614 | { } |
615 | }; | |
616 | MODULE_DEVICE_TABLE(i2c, wm9090_id); | |
617 | ||
618 | static struct i2c_driver wm9090_i2c_driver = { | |
619 | .driver = { | |
091edccf | 620 | .name = "wm9090", |
39b8eab7 MB |
621 | }, |
622 | .probe = wm9090_i2c_probe, | |
39b8eab7 MB |
623 | .id_table = wm9090_id, |
624 | }; | |
625 | ||
96124c29 | 626 | module_i2c_driver(wm9090_i2c_driver); |
39b8eab7 MB |
627 | |
628 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | |
629 | MODULE_DESCRIPTION("WM9090 ASoC driver"); | |
630 | MODULE_LICENSE("GPL"); |