1 // SPDX-License-Identifier: GPL-2.0-only
3 * ALSA SoC WM9090 driver
5 * Copyright 2009-12 Wolfson Microelectronics
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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>
15 #include <linux/regmap.h>
16 #include <linux/slab.h>
17 #include <sound/initval.h>
18 #include <sound/soc.h>
19 #include <sound/tlv.h>
20 #include <sound/wm9090.h>
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 */
62 /* This struct is used to save the context */
64 struct wm9090_platform_data pdata
;
65 struct regmap
*regmap
;
68 static bool wm9090_volatile(struct device
*dev
, unsigned int 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
:
83 static bool wm9090_readable(struct device
*dev
, unsigned int 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
:
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
:
133 static void wait_for_dc_servo(struct snd_soc_component
*component
)
138 dev_dbg(component
->dev
, "Waiting for DC servo...\n");
142 reg
= snd_soc_component_read32(component
, WM9090_DC_SERVO_READBACK_0
);
143 dev_dbg(component
->dev
, "DC servo status: %x\n", reg
);
144 } while ((reg
& WM9090_DCS_CAL_COMPLETE_MASK
)
145 != WM9090_DCS_CAL_COMPLETE_MASK
&& count
< 1000);
147 if ((reg
& WM9090_DCS_CAL_COMPLETE_MASK
)
148 != WM9090_DCS_CAL_COMPLETE_MASK
)
149 dev_err(component
->dev
, "Timed out waiting for DC Servo\n");
152 static const DECLARE_TLV_DB_RANGE(in_tlv
,
153 0, 0, TLV_DB_SCALE_ITEM(-600, 0, 0),
154 1, 3, TLV_DB_SCALE_ITEM(-350, 350, 0),
155 4, 6, TLV_DB_SCALE_ITEM(600, 600, 0)
157 static const DECLARE_TLV_DB_RANGE(mix_tlv
,
158 0, 2, TLV_DB_SCALE_ITEM(-1200, 300, 0),
159 3, 3, TLV_DB_SCALE_ITEM(0, 0, 0)
161 static const DECLARE_TLV_DB_SCALE(out_tlv
, -5700, 100, 0);
162 static const DECLARE_TLV_DB_RANGE(spkboost_tlv
,
163 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
164 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0)
167 static const struct snd_kcontrol_new wm9090_controls
[] = {
168 SOC_SINGLE_TLV("IN1A Volume", WM9090_IN1_LINE_INPUT_A_VOLUME
, 0, 6, 0,
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),
173 SOC_SINGLE_TLV("IN2A Volume", WM9090_IN2_LINE_INPUT_A_VOLUME
, 0, 6, 0,
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),
178 SOC_SINGLE("MIXOUTL Switch", WM9090_OUTPUT_MIXER3
, 8, 1, 1),
179 SOC_SINGLE_TLV("MIXOUTL IN1A Volume", WM9090_OUTPUT_MIXER3
, 6, 3, 1,
181 SOC_SINGLE_TLV("MIXOUTL IN2A Volume", WM9090_OUTPUT_MIXER3
, 2, 3, 1,
184 SOC_SINGLE("MIXOUTR Switch", WM9090_OUTPUT_MIXER4
, 8, 1, 1),
185 SOC_SINGLE_TLV("MIXOUTR IN1A Volume", WM9090_OUTPUT_MIXER4
, 6, 3, 1,
187 SOC_SINGLE_TLV("MIXOUTR IN2A Volume", WM9090_OUTPUT_MIXER4
, 2, 3, 1,
190 SOC_SINGLE("SPKMIX Switch", WM9090_SPKMIXL_ATTENUATION
, 8, 1, 1),
191 SOC_SINGLE_TLV("SPKMIX IN1A Volume", WM9090_SPKMIXL_ATTENUATION
, 6, 3, 1,
193 SOC_SINGLE_TLV("SPKMIX IN2A Volume", WM9090_SPKMIXL_ATTENUATION
, 2, 3, 1,
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),
203 SOC_SINGLE_TLV("Speaker Volume", WM9090_SPEAKER_VOLUME_LEFT
, 0, 63, 0,
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
),
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,
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),
216 SOC_SINGLE_TLV("SPKMIX IN1B Volume", WM9090_SPKMIXL_ATTENUATION
, 4, 3, 1,
218 SOC_SINGLE_TLV("MIXOUTL IN1B Volume", WM9090_OUTPUT_MIXER3
, 4, 3, 1,
220 SOC_SINGLE_TLV("MIXOUTR IN1B Volume", WM9090_OUTPUT_MIXER4
, 4, 3, 1,
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,
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),
230 SOC_SINGLE_TLV("SPKMIX IN2B Volume", WM9090_SPKMIXL_ATTENUATION
, 0, 3, 1,
232 SOC_SINGLE_TLV("MIXOUTL IN2B Volume", WM9090_OUTPUT_MIXER3
, 0, 3, 1,
234 SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4
, 0, 3, 1,
238 static int hp_ev(struct snd_soc_dapm_widget
*w
,
239 struct snd_kcontrol
*kcontrol
, int event
)
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
);
245 case SND_SOC_DAPM_POST_PMU
:
246 snd_soc_component_update_bits(component
, WM9090_CHARGE_PUMP_1
,
247 WM9090_CP_ENA
, WM9090_CP_ENA
);
251 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_1
,
252 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
,
253 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
);
255 reg
|= WM9090_HPOUT1L_DLY
| WM9090_HPOUT1R_DLY
;
256 snd_soc_component_write(component
, WM9090_ANALOGUE_HP_0
, reg
);
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
264 snd_soc_component_write(component
, WM9090_DC_SERVO_0
,
265 WM9090_DCS_ENA_CHAN_0
|
266 WM9090_DCS_ENA_CHAN_1
|
267 WM9090_DCS_TRIG_STARTUP_1
|
268 WM9090_DCS_TRIG_STARTUP_0
);
269 wait_for_dc_servo(component
);
271 reg
|= WM9090_HPOUT1R_OUTP
| WM9090_HPOUT1R_RMV_SHORT
|
272 WM9090_HPOUT1L_OUTP
| WM9090_HPOUT1L_RMV_SHORT
;
273 snd_soc_component_write(component
, WM9090_ANALOGUE_HP_0
, reg
);
276 case SND_SOC_DAPM_PRE_PMD
:
277 reg
&= ~(WM9090_HPOUT1L_RMV_SHORT
|
279 WM9090_HPOUT1L_OUTP
|
280 WM9090_HPOUT1R_RMV_SHORT
|
282 WM9090_HPOUT1R_OUTP
);
284 snd_soc_component_write(component
, WM9090_ANALOGUE_HP_0
, reg
);
286 snd_soc_component_write(component
, WM9090_DC_SERVO_0
, 0);
288 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_1
,
289 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
,
292 snd_soc_component_update_bits(component
, WM9090_CHARGE_PUMP_1
,
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),
307 static const struct snd_kcontrol_new spkout
[] = {
308 SOC_DAPM_SINGLE("Mixer Switch", WM9090_SPKOUT_MIXERS
, 4, 1, 0),
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),
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),
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-"),
331 SND_SOC_DAPM_SUPPLY("OSC", WM9090_POWER_MANAGEMENT_1
, 3, 0, NULL
, 0),
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),
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
)),
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
),
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
)),
352 SND_SOC_DAPM_OUTPUT("HPR"),
353 SND_SOC_DAPM_OUTPUT("HPL"),
354 SND_SOC_DAPM_OUTPUT("Speaker"),
357 static const struct snd_soc_dapm_route audio_map
[] = {
358 { "IN1A PGA", NULL
, "IN1+" },
359 { "IN2A PGA", NULL
, "IN2+" },
361 { "SPKMIX", "IN1A Switch", "IN1A PGA" },
362 { "SPKMIX", "IN2A Switch", "IN2A PGA" },
364 { "MIXOUTL", "IN1A Switch", "IN1A PGA" },
365 { "MIXOUTL", "IN2A Switch", "IN2A PGA" },
367 { "MIXOUTR", "IN1A Switch", "IN1A PGA" },
368 { "MIXOUTR", "IN2A Switch", "IN2A PGA" },
370 { "HP PGA", NULL
, "OSC" },
371 { "HP PGA", NULL
, "MIXOUTL" },
372 { "HP PGA", NULL
, "MIXOUTR" },
374 { "HPL", NULL
, "HP PGA" },
375 { "HPR", NULL
, "HP PGA" },
377 { "SPKPGA", NULL
, "OSC" },
378 { "SPKPGA", NULL
, "SPKMIX" },
380 { "SPKOUT", "Mixer Switch", "SPKPGA" },
382 { "Speaker", NULL
, "SPKOUT" },
385 static const struct snd_soc_dapm_route audio_map_in1_se
[] = {
386 { "IN1B PGA", NULL
, "IN1-" },
388 { "SPKMIX", "IN1B Switch", "IN1B PGA" },
389 { "MIXOUTL", "IN1B Switch", "IN1B PGA" },
390 { "MIXOUTR", "IN1B Switch", "IN1B PGA" },
393 static const struct snd_soc_dapm_route audio_map_in1_diff
[] = {
394 { "IN1A PGA", NULL
, "IN1-" },
397 static const struct snd_soc_dapm_route audio_map_in2_se
[] = {
398 { "IN2B PGA", NULL
, "IN2-" },
400 { "SPKMIX", "IN2B Switch", "IN2B PGA" },
401 { "MIXOUTL", "IN2B Switch", "IN2B PGA" },
402 { "MIXOUTR", "IN2B Switch", "IN2B PGA" },
405 static const struct snd_soc_dapm_route audio_map_in2_diff
[] = {
406 { "IN2A PGA", NULL
, "IN2-" },
409 static int wm9090_add_controls(struct snd_soc_component
*component
)
411 struct wm9090_priv
*wm9090
= snd_soc_component_get_drvdata(component
);
412 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(component
);
415 snd_soc_dapm_new_controls(dapm
, wm9090_dapm_widgets
,
416 ARRAY_SIZE(wm9090_dapm_widgets
));
418 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
420 snd_soc_add_component_controls(component
, wm9090_controls
,
421 ARRAY_SIZE(wm9090_controls
));
423 if (wm9090
->pdata
.lin1_diff
) {
424 snd_soc_dapm_add_routes(dapm
, audio_map_in1_diff
,
425 ARRAY_SIZE(audio_map_in1_diff
));
427 snd_soc_dapm_add_routes(dapm
, audio_map_in1_se
,
428 ARRAY_SIZE(audio_map_in1_se
));
429 snd_soc_add_component_controls(component
, wm9090_in1_se_controls
,
430 ARRAY_SIZE(wm9090_in1_se_controls
));
433 if (wm9090
->pdata
.lin2_diff
) {
434 snd_soc_dapm_add_routes(dapm
, audio_map_in2_diff
,
435 ARRAY_SIZE(audio_map_in2_diff
));
437 snd_soc_dapm_add_routes(dapm
, audio_map_in2_se
,
438 ARRAY_SIZE(audio_map_in2_se
));
439 snd_soc_add_component_controls(component
, wm9090_in2_se_controls
,
440 ARRAY_SIZE(wm9090_in2_se_controls
));
443 if (wm9090
->pdata
.agc_ena
) {
444 for (i
= 0; i
< ARRAY_SIZE(wm9090
->pdata
.agc
); i
++)
445 snd_soc_component_write(component
, WM9090_AGC_CONTROL_0
+ i
,
446 wm9090
->pdata
.agc
[i
]);
447 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_3
,
448 WM9090_AGC_ENA
, WM9090_AGC_ENA
);
450 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_3
,
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.
462 static int wm9090_set_bias_level(struct snd_soc_component
*component
,
463 enum snd_soc_bias_level level
)
465 struct wm9090_priv
*wm9090
= snd_soc_component_get_drvdata(component
);
468 case SND_SOC_BIAS_ON
:
471 case SND_SOC_BIAS_PREPARE
:
472 snd_soc_component_update_bits(component
, WM9090_ANTIPOP2
, WM9090_VMID_ENA
,
474 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_1
,
476 WM9090_VMID_RES_MASK
,
478 1 << WM9090_VMID_RES_SHIFT
);
479 msleep(1); /* Probably an overestimate */
482 case SND_SOC_BIAS_STANDBY
:
483 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
484 /* Restore the register cache */
485 regcache_sync(wm9090
->regmap
);
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.
492 snd_soc_component_update_bits(component
, WM9090_POWER_MANAGEMENT_1
,
493 WM9090_BIAS_ENA
| WM9090_VMID_RES_MASK
, 0);
494 snd_soc_component_update_bits(component
, WM9090_ANTIPOP2
,
498 case SND_SOC_BIAS_OFF
:
505 static int wm9090_probe(struct snd_soc_component
*component
)
507 /* Configure some defaults; they will be written out when we
510 snd_soc_component_update_bits(component
, WM9090_IN1_LINE_INPUT_A_VOLUME
,
511 WM9090_IN1_VU
| WM9090_IN1A_ZC
,
512 WM9090_IN1_VU
| WM9090_IN1A_ZC
);
513 snd_soc_component_update_bits(component
, WM9090_IN1_LINE_INPUT_B_VOLUME
,
514 WM9090_IN1_VU
| WM9090_IN1B_ZC
,
515 WM9090_IN1_VU
| WM9090_IN1B_ZC
);
516 snd_soc_component_update_bits(component
, WM9090_IN2_LINE_INPUT_A_VOLUME
,
517 WM9090_IN2_VU
| WM9090_IN2A_ZC
,
518 WM9090_IN2_VU
| WM9090_IN2A_ZC
);
519 snd_soc_component_update_bits(component
, WM9090_IN2_LINE_INPUT_B_VOLUME
,
520 WM9090_IN2_VU
| WM9090_IN2B_ZC
,
521 WM9090_IN2_VU
| WM9090_IN2B_ZC
);
522 snd_soc_component_update_bits(component
, WM9090_SPEAKER_VOLUME_LEFT
,
523 WM9090_SPKOUT_VU
| WM9090_SPKOUTL_ZC
,
524 WM9090_SPKOUT_VU
| WM9090_SPKOUTL_ZC
);
525 snd_soc_component_update_bits(component
, WM9090_LEFT_OUTPUT_VOLUME
,
526 WM9090_HPOUT1_VU
| WM9090_HPOUT1L_ZC
,
527 WM9090_HPOUT1_VU
| WM9090_HPOUT1L_ZC
);
528 snd_soc_component_update_bits(component
, WM9090_RIGHT_OUTPUT_VOLUME
,
529 WM9090_HPOUT1_VU
| WM9090_HPOUT1R_ZC
,
530 WM9090_HPOUT1_VU
| WM9090_HPOUT1R_ZC
);
532 snd_soc_component_update_bits(component
, WM9090_CLOCKING_1
,
533 WM9090_TOCLK_ENA
, WM9090_TOCLK_ENA
);
535 wm9090_add_controls(component
);
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,
545 .use_pmdown_time
= 1,
547 .non_legacy_dai_naming
= 1,
550 static const struct regmap_config wm9090_regmap
= {
554 .max_register
= WM9090_MAX_REGISTER
,
555 .volatile_reg
= wm9090_volatile
,
556 .readable_reg
= wm9090_readable
,
558 .cache_type
= REGCACHE_RBTREE
,
559 .reg_defaults
= wm9090_reg_defaults
,
560 .num_reg_defaults
= ARRAY_SIZE(wm9090_reg_defaults
),
564 static int wm9090_i2c_probe(struct i2c_client
*i2c
,
565 const struct i2c_device_id
*id
)
567 struct wm9090_priv
*wm9090
;
571 wm9090
= devm_kzalloc(&i2c
->dev
, sizeof(*wm9090
), GFP_KERNEL
);
575 wm9090
->regmap
= devm_regmap_init_i2c(i2c
, &wm9090_regmap
);
576 if (IS_ERR(wm9090
->regmap
)) {
577 ret
= PTR_ERR(wm9090
->regmap
);
578 dev_err(&i2c
->dev
, "Failed to allocate regmap: %d\n", ret
);
582 ret
= regmap_read(wm9090
->regmap
, WM9090_SOFTWARE_RESET
, ®
);
587 dev_err(&i2c
->dev
, "Device is not a WM9090, ID=%x\n", reg
);
591 ret
= regmap_write(wm9090
->regmap
, WM9090_SOFTWARE_RESET
, 0);
595 if (i2c
->dev
.platform_data
)
596 memcpy(&wm9090
->pdata
, i2c
->dev
.platform_data
,
597 sizeof(wm9090
->pdata
));
599 i2c_set_clientdata(i2c
, wm9090
);
601 ret
= devm_snd_soc_register_component(&i2c
->dev
,
602 &soc_component_dev_wm9090
, NULL
, 0);
604 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
611 static const struct i2c_device_id wm9090_id
[] = {
616 MODULE_DEVICE_TABLE(i2c
, wm9090_id
);
618 static struct i2c_driver wm9090_i2c_driver
= {
622 .probe
= wm9090_i2c_probe
,
623 .id_table
= wm9090_id
,
626 module_i2c_driver(wm9090_i2c_driver
);
628 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
629 MODULE_DESCRIPTION("WM9090 ASoC driver");
630 MODULE_LICENSE("GPL");