2 * ALSA SoC WM9090 driver
4 * Copyright 2009, 2010 Wolfson Microelectronics
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 #include <linux/module.h>
24 #include <linux/errno.h>
25 #include <linux/device.h>
26 #include <linux/i2c.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <sound/initval.h>
30 #include <sound/soc.h>
31 #include <sound/tlv.h>
32 #include <sound/wm9090.h>
36 static const u16 wm9090_reg_defaults
[] = {
37 0x9093, /* R0 - Software Reset */
38 0x0006, /* R1 - Power Management (1) */
39 0x6000, /* R2 - Power Management (2) */
40 0x0000, /* R3 - Power Management (3) */
43 0x01C0, /* R6 - Clocking 1 */
59 0x0003, /* R22 - IN1 Line Control */
60 0x0003, /* R23 - IN2 Line Control */
61 0x0083, /* R24 - IN1 Line Input A Volume */
62 0x0083, /* R25 - IN1 Line Input B Volume */
63 0x0083, /* R26 - IN2 Line Input A Volume */
64 0x0083, /* R27 - IN2 Line Input B Volume */
65 0x002D, /* R28 - Left Output Volume */
66 0x002D, /* R29 - Right Output Volume */
71 0x0100, /* R34 - SPKMIXL Attenuation */
73 0x0010, /* R36 - SPKOUT Mixers */
74 0x0140, /* R37 - ClassD3 */
75 0x0039, /* R38 - Speaker Volume Left */
82 0x0000, /* R45 - Output Mixer1 */
83 0x0000, /* R46 - Output Mixer2 */
84 0x0100, /* R47 - Output Mixer3 */
85 0x0100, /* R48 - Output Mixer4 */
91 0x0000, /* R54 - Speaker Mixer */
94 0x000D, /* R57 - AntiPOP2 */
107 0x0000, /* R70 - Write Sequencer 0 */
108 0x0000, /* R71 - Write Sequencer 1 */
109 0x0000, /* R72 - Write Sequencer 2 */
110 0x0000, /* R73 - Write Sequencer 3 */
111 0x0000, /* R74 - Write Sequencer 4 */
112 0x0000, /* R75 - Write Sequencer 5 */
113 0x1F25, /* R76 - Charge Pump 1 */
121 0x0000, /* R84 - DC Servo 0 */
122 0x054A, /* R85 - DC Servo 1 */
124 0x0000, /* R87 - DC Servo 3 */
125 0x0000, /* R88 - DC Servo Readback 0 */
126 0x0000, /* R89 - DC Servo Readback 1 */
127 0x0000, /* R90 - DC Servo Readback 2 */
133 0x0100, /* R96 - Analogue HP 0 */
135 0x8640, /* R98 - AGC Control 0 */
136 0xC000, /* R99 - AGC Control 1 */
137 0x0200, /* R100 - AGC Control 2 */
140 /* This struct is used to save the context */
143 struct wm9090_platform_data pdata
;
147 static int wm9090_volatile(unsigned int reg
)
150 case WM9090_SOFTWARE_RESET
:
151 case WM9090_DC_SERVO_0
:
152 case WM9090_DC_SERVO_READBACK_0
:
153 case WM9090_DC_SERVO_READBACK_1
:
154 case WM9090_DC_SERVO_READBACK_2
:
162 static void wait_for_dc_servo(struct snd_soc_codec
*codec
)
167 dev_dbg(codec
->dev
, "Waiting for DC servo...\n");
171 reg
= snd_soc_read(codec
, WM9090_DC_SERVO_READBACK_0
);
172 dev_dbg(codec
->dev
, "DC servo status: %x\n", reg
);
173 } while ((reg
& WM9090_DCS_CAL_COMPLETE_MASK
)
174 != WM9090_DCS_CAL_COMPLETE_MASK
&& count
< 1000);
176 if ((reg
& WM9090_DCS_CAL_COMPLETE_MASK
)
177 != WM9090_DCS_CAL_COMPLETE_MASK
)
178 dev_err(codec
->dev
, "Timed out waiting for DC Servo\n");
181 static const unsigned int in_tlv
[] = {
182 TLV_DB_RANGE_HEAD(6),
183 0, 0, TLV_DB_SCALE_ITEM(-600, 0, 0),
184 1, 3, TLV_DB_SCALE_ITEM(-350, 350, 0),
185 4, 6, TLV_DB_SCALE_ITEM(600, 600, 0),
187 static const unsigned int mix_tlv
[] = {
188 TLV_DB_RANGE_HEAD(4),
189 0, 2, TLV_DB_SCALE_ITEM(-1200, 300, 0),
190 3, 3, TLV_DB_SCALE_ITEM(0, 0, 0),
192 static const DECLARE_TLV_DB_SCALE(out_tlv
, -5700, 100, 0);
193 static const unsigned int spkboost_tlv
[] = {
194 TLV_DB_RANGE_HEAD(7),
195 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
196 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
199 static const struct snd_kcontrol_new wm9090_controls
[] = {
200 SOC_SINGLE_TLV("IN1A Volume", WM9090_IN1_LINE_INPUT_A_VOLUME
, 0, 6, 0,
202 SOC_SINGLE("IN1A Switch", WM9090_IN1_LINE_INPUT_A_VOLUME
, 7, 1, 1),
203 SOC_SINGLE("IN1A ZC Switch", WM9090_IN1_LINE_INPUT_A_VOLUME
, 6, 1, 0),
205 SOC_SINGLE_TLV("IN2A Volume", WM9090_IN2_LINE_INPUT_A_VOLUME
, 0, 6, 0,
207 SOC_SINGLE("IN2A Switch", WM9090_IN2_LINE_INPUT_A_VOLUME
, 7, 1, 1),
208 SOC_SINGLE("IN2A ZC Switch", WM9090_IN2_LINE_INPUT_A_VOLUME
, 6, 1, 0),
210 SOC_SINGLE("MIXOUTL Switch", WM9090_OUTPUT_MIXER3
, 8, 1, 1),
211 SOC_SINGLE_TLV("MIXOUTL IN1A Volume", WM9090_OUTPUT_MIXER3
, 6, 3, 1,
213 SOC_SINGLE_TLV("MIXOUTL IN2A Volume", WM9090_OUTPUT_MIXER3
, 2, 3, 1,
216 SOC_SINGLE("MIXOUTR Switch", WM9090_OUTPUT_MIXER4
, 8, 1, 1),
217 SOC_SINGLE_TLV("MIXOUTR IN1A Volume", WM9090_OUTPUT_MIXER4
, 6, 3, 1,
219 SOC_SINGLE_TLV("MIXOUTR IN2A Volume", WM9090_OUTPUT_MIXER4
, 2, 3, 1,
222 SOC_SINGLE("SPKMIX Switch", WM9090_SPKMIXL_ATTENUATION
, 8, 1, 1),
223 SOC_SINGLE_TLV("SPKMIX IN1A Volume", WM9090_SPKMIXL_ATTENUATION
, 6, 3, 1,
225 SOC_SINGLE_TLV("SPKMIX IN2A Volume", WM9090_SPKMIXL_ATTENUATION
, 2, 3, 1,
228 SOC_DOUBLE_R_TLV("Headphone Volume", WM9090_LEFT_OUTPUT_VOLUME
,
229 WM9090_RIGHT_OUTPUT_VOLUME
, 0, 63, 0, out_tlv
),
230 SOC_DOUBLE_R("Headphone Switch", WM9090_LEFT_OUTPUT_VOLUME
,
231 WM9090_RIGHT_OUTPUT_VOLUME
, 6, 1, 1),
232 SOC_DOUBLE_R("Headphone ZC Switch", WM9090_LEFT_OUTPUT_VOLUME
,
233 WM9090_RIGHT_OUTPUT_VOLUME
, 7, 1, 0),
235 SOC_SINGLE_TLV("Speaker Volume", WM9090_SPEAKER_VOLUME_LEFT
, 0, 63, 0,
237 SOC_SINGLE("Speaker Switch", WM9090_SPEAKER_VOLUME_LEFT
, 6, 1, 1),
238 SOC_SINGLE("Speaker ZC Switch", WM9090_SPEAKER_VOLUME_LEFT
, 7, 1, 0),
239 SOC_SINGLE_TLV("Speaker Boost Volume", WM9090_CLASSD3
, 3, 7, 0, spkboost_tlv
),
242 static const struct snd_kcontrol_new wm9090_in1_se_controls
[] = {
243 SOC_SINGLE_TLV("IN1B Volume", WM9090_IN1_LINE_INPUT_B_VOLUME
, 0, 6, 0,
245 SOC_SINGLE("IN1B Switch", WM9090_IN1_LINE_INPUT_B_VOLUME
, 7, 1, 1),
246 SOC_SINGLE("IN1B ZC Switch", WM9090_IN1_LINE_INPUT_B_VOLUME
, 6, 1, 0),
248 SOC_SINGLE_TLV("SPKMIX IN1B Volume", WM9090_SPKMIXL_ATTENUATION
, 4, 3, 1,
250 SOC_SINGLE_TLV("MIXOUTL IN1B Volume", WM9090_OUTPUT_MIXER3
, 4, 3, 1,
252 SOC_SINGLE_TLV("MIXOUTR IN1B Volume", WM9090_OUTPUT_MIXER4
, 4, 3, 1,
256 static const struct snd_kcontrol_new wm9090_in2_se_controls
[] = {
257 SOC_SINGLE_TLV("IN2B Volume", WM9090_IN2_LINE_INPUT_B_VOLUME
, 0, 6, 0,
259 SOC_SINGLE("IN2B Switch", WM9090_IN2_LINE_INPUT_B_VOLUME
, 7, 1, 1),
260 SOC_SINGLE("IN2B ZC Switch", WM9090_IN2_LINE_INPUT_B_VOLUME
, 6, 1, 0),
262 SOC_SINGLE_TLV("SPKMIX IN2B Volume", WM9090_SPKMIXL_ATTENUATION
, 0, 3, 1,
264 SOC_SINGLE_TLV("MIXOUTL IN2B Volume", WM9090_OUTPUT_MIXER3
, 0, 3, 1,
266 SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4
, 0, 3, 1,
270 static int hp_ev(struct snd_soc_dapm_widget
*w
,
271 struct snd_kcontrol
*kcontrol
, int event
)
273 struct snd_soc_codec
*codec
= w
->codec
;
274 unsigned int reg
= snd_soc_read(codec
, WM9090_ANALOGUE_HP_0
);
277 case SND_SOC_DAPM_POST_PMU
:
278 snd_soc_update_bits(codec
, WM9090_CHARGE_PUMP_1
,
279 WM9090_CP_ENA
, WM9090_CP_ENA
);
283 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_1
,
284 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
,
285 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
);
287 reg
|= WM9090_HPOUT1L_DLY
| WM9090_HPOUT1R_DLY
;
288 snd_soc_write(codec
, WM9090_ANALOGUE_HP_0
, reg
);
290 /* Start the DC servo. We don't currently use the
291 * ability to save the state since we don't have full
292 * control of the analogue paths and they can change
293 * DC offsets; see the WM8904 driver for an example of
296 snd_soc_write(codec
, WM9090_DC_SERVO_0
,
297 WM9090_DCS_ENA_CHAN_0
|
298 WM9090_DCS_ENA_CHAN_1
|
299 WM9090_DCS_TRIG_STARTUP_1
|
300 WM9090_DCS_TRIG_STARTUP_0
);
301 wait_for_dc_servo(codec
);
303 reg
|= WM9090_HPOUT1R_OUTP
| WM9090_HPOUT1R_RMV_SHORT
|
304 WM9090_HPOUT1L_OUTP
| WM9090_HPOUT1L_RMV_SHORT
;
305 snd_soc_write(codec
, WM9090_ANALOGUE_HP_0
, reg
);
308 case SND_SOC_DAPM_PRE_PMD
:
309 reg
&= ~(WM9090_HPOUT1L_RMV_SHORT
|
311 WM9090_HPOUT1L_OUTP
|
312 WM9090_HPOUT1R_RMV_SHORT
|
314 WM9090_HPOUT1R_OUTP
);
316 snd_soc_write(codec
, WM9090_ANALOGUE_HP_0
, reg
);
318 snd_soc_write(codec
, WM9090_DC_SERVO_0
, 0);
320 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_1
,
321 WM9090_HPOUT1L_ENA
| WM9090_HPOUT1R_ENA
,
324 snd_soc_update_bits(codec
, WM9090_CHARGE_PUMP_1
,
332 static const struct snd_kcontrol_new spkmix
[] = {
333 SOC_DAPM_SINGLE("IN1A Switch", WM9090_SPEAKER_MIXER
, 6, 1, 0),
334 SOC_DAPM_SINGLE("IN1B Switch", WM9090_SPEAKER_MIXER
, 4, 1, 0),
335 SOC_DAPM_SINGLE("IN2A Switch", WM9090_SPEAKER_MIXER
, 2, 1, 0),
336 SOC_DAPM_SINGLE("IN2B Switch", WM9090_SPEAKER_MIXER
, 0, 1, 0),
339 static const struct snd_kcontrol_new spkout
[] = {
340 SOC_DAPM_SINGLE("Mixer Switch", WM9090_SPKOUT_MIXERS
, 4, 1, 0),
343 static const struct snd_kcontrol_new mixoutl
[] = {
344 SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER1
, 6, 1, 0),
345 SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER1
, 4, 1, 0),
346 SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER1
, 2, 1, 0),
347 SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER1
, 0, 1, 0),
350 static const struct snd_kcontrol_new mixoutr
[] = {
351 SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER2
, 6, 1, 0),
352 SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER2
, 4, 1, 0),
353 SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER2
, 2, 1, 0),
354 SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER2
, 0, 1, 0),
357 static const struct snd_soc_dapm_widget wm9090_dapm_widgets
[] = {
358 SND_SOC_DAPM_INPUT("IN1+"),
359 SND_SOC_DAPM_INPUT("IN1-"),
360 SND_SOC_DAPM_INPUT("IN2+"),
361 SND_SOC_DAPM_INPUT("IN2-"),
363 SND_SOC_DAPM_SUPPLY("OSC", WM9090_POWER_MANAGEMENT_1
, 3, 0, NULL
, 0),
365 SND_SOC_DAPM_PGA("IN1A PGA", WM9090_POWER_MANAGEMENT_2
, 7, 0, NULL
, 0),
366 SND_SOC_DAPM_PGA("IN1B PGA", WM9090_POWER_MANAGEMENT_2
, 6, 0, NULL
, 0),
367 SND_SOC_DAPM_PGA("IN2A PGA", WM9090_POWER_MANAGEMENT_2
, 5, 0, NULL
, 0),
368 SND_SOC_DAPM_PGA("IN2B PGA", WM9090_POWER_MANAGEMENT_2
, 4, 0, NULL
, 0),
370 SND_SOC_DAPM_MIXER("SPKMIX", WM9090_POWER_MANAGEMENT_3
, 3, 0,
371 spkmix
, ARRAY_SIZE(spkmix
)),
372 SND_SOC_DAPM_MIXER("MIXOUTL", WM9090_POWER_MANAGEMENT_3
, 5, 0,
373 mixoutl
, ARRAY_SIZE(mixoutl
)),
374 SND_SOC_DAPM_MIXER("MIXOUTR", WM9090_POWER_MANAGEMENT_3
, 4, 0,
375 mixoutr
, ARRAY_SIZE(mixoutr
)),
377 SND_SOC_DAPM_PGA_E("HP PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
378 hp_ev
, SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
380 SND_SOC_DAPM_PGA("SPKPGA", WM9090_POWER_MANAGEMENT_3
, 8, 0, NULL
, 0),
381 SND_SOC_DAPM_MIXER("SPKOUT", WM9090_POWER_MANAGEMENT_1
, 12, 0,
382 spkout
, ARRAY_SIZE(spkout
)),
384 SND_SOC_DAPM_OUTPUT("HPR"),
385 SND_SOC_DAPM_OUTPUT("HPL"),
386 SND_SOC_DAPM_OUTPUT("Speaker"),
389 static const struct snd_soc_dapm_route audio_map
[] = {
390 { "IN1A PGA", NULL
, "IN1+" },
391 { "IN2A PGA", NULL
, "IN2+" },
393 { "SPKMIX", "IN1A Switch", "IN1A PGA" },
394 { "SPKMIX", "IN2A Switch", "IN2A PGA" },
396 { "MIXOUTL", "IN1A Switch", "IN1A PGA" },
397 { "MIXOUTL", "IN2A Switch", "IN2A PGA" },
399 { "MIXOUTR", "IN1A Switch", "IN1A PGA" },
400 { "MIXOUTR", "IN2A Switch", "IN2A PGA" },
402 { "HP PGA", NULL
, "OSC" },
403 { "HP PGA", NULL
, "MIXOUTL" },
404 { "HP PGA", NULL
, "MIXOUTR" },
406 { "HPL", NULL
, "HP PGA" },
407 { "HPR", NULL
, "HP PGA" },
409 { "SPKPGA", NULL
, "OSC" },
410 { "SPKPGA", NULL
, "SPKMIX" },
412 { "SPKOUT", "Mixer Switch", "SPKPGA" },
414 { "Speaker", NULL
, "SPKOUT" },
417 static const struct snd_soc_dapm_route audio_map_in1_se
[] = {
418 { "IN1B PGA", NULL
, "IN1-" },
420 { "SPKMIX", "IN1B Switch", "IN1B PGA" },
421 { "MIXOUTL", "IN1B Switch", "IN1B PGA" },
422 { "MIXOUTR", "IN1B Switch", "IN1B PGA" },
425 static const struct snd_soc_dapm_route audio_map_in1_diff
[] = {
426 { "IN1A PGA", NULL
, "IN1-" },
429 static const struct snd_soc_dapm_route audio_map_in2_se
[] = {
430 { "IN2B PGA", NULL
, "IN2-" },
432 { "SPKMIX", "IN2B Switch", "IN2B PGA" },
433 { "MIXOUTL", "IN2B Switch", "IN2B PGA" },
434 { "MIXOUTR", "IN2B Switch", "IN2B PGA" },
437 static const struct snd_soc_dapm_route audio_map_in2_diff
[] = {
438 { "IN2A PGA", NULL
, "IN2-" },
441 static int wm9090_add_controls(struct snd_soc_codec
*codec
)
443 struct wm9090_priv
*wm9090
= snd_soc_codec_get_drvdata(codec
);
444 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
447 snd_soc_dapm_new_controls(dapm
, wm9090_dapm_widgets
,
448 ARRAY_SIZE(wm9090_dapm_widgets
));
450 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
452 snd_soc_add_controls(codec
, wm9090_controls
,
453 ARRAY_SIZE(wm9090_controls
));
455 if (wm9090
->pdata
.lin1_diff
) {
456 snd_soc_dapm_add_routes(dapm
, audio_map_in1_diff
,
457 ARRAY_SIZE(audio_map_in1_diff
));
459 snd_soc_dapm_add_routes(dapm
, audio_map_in1_se
,
460 ARRAY_SIZE(audio_map_in1_se
));
461 snd_soc_add_controls(codec
, wm9090_in1_se_controls
,
462 ARRAY_SIZE(wm9090_in1_se_controls
));
465 if (wm9090
->pdata
.lin2_diff
) {
466 snd_soc_dapm_add_routes(dapm
, audio_map_in2_diff
,
467 ARRAY_SIZE(audio_map_in2_diff
));
469 snd_soc_dapm_add_routes(dapm
, audio_map_in2_se
,
470 ARRAY_SIZE(audio_map_in2_se
));
471 snd_soc_add_controls(codec
, wm9090_in2_se_controls
,
472 ARRAY_SIZE(wm9090_in2_se_controls
));
475 if (wm9090
->pdata
.agc_ena
) {
476 for (i
= 0; i
< ARRAY_SIZE(wm9090
->pdata
.agc
); i
++)
477 snd_soc_write(codec
, WM9090_AGC_CONTROL_0
+ i
,
478 wm9090
->pdata
.agc
[i
]);
479 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_3
,
480 WM9090_AGC_ENA
, WM9090_AGC_ENA
);
482 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_3
,
491 * The machine driver should call this from their set_bias_level; if there
492 * isn't one then this can just be set as the set_bias_level function.
494 static int wm9090_set_bias_level(struct snd_soc_codec
*codec
,
495 enum snd_soc_bias_level level
)
497 u16
*reg_cache
= codec
->reg_cache
;
501 case SND_SOC_BIAS_ON
:
504 case SND_SOC_BIAS_PREPARE
:
505 snd_soc_update_bits(codec
, WM9090_ANTIPOP2
, WM9090_VMID_ENA
,
507 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_1
,
509 WM9090_VMID_RES_MASK
,
511 1 << WM9090_VMID_RES_SHIFT
);
512 msleep(1); /* Probably an overestimate */
515 case SND_SOC_BIAS_STANDBY
:
516 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
517 /* Restore the register cache */
518 for (i
= 1; i
< codec
->driver
->reg_cache_size
; i
++) {
519 if (reg_cache
[i
] == wm9090_reg_defaults
[i
])
521 if (wm9090_volatile(i
))
524 ret
= snd_soc_write(codec
, i
, reg_cache
[i
]);
527 "Failed to restore register %d: %d\n",
532 /* We keep VMID off during standby since the combination of
533 * ground referenced outputs and class D speaker mean that
534 * latency is not an issue.
536 snd_soc_update_bits(codec
, WM9090_POWER_MANAGEMENT_1
,
537 WM9090_BIAS_ENA
| WM9090_VMID_RES_MASK
, 0);
538 snd_soc_update_bits(codec
, WM9090_ANTIPOP2
,
542 case SND_SOC_BIAS_OFF
:
546 codec
->dapm
.bias_level
= level
;
551 static int wm9090_probe(struct snd_soc_codec
*codec
)
553 struct wm9090_priv
*wm9090
= snd_soc_codec_get_drvdata(codec
);
554 u16
*reg_cache
= codec
->reg_cache
;
557 codec
->control_data
= wm9090
->control_data
;
558 ret
= snd_soc_codec_set_cache_io(codec
, 8, 16, SND_SOC_I2C
);
560 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
564 ret
= snd_soc_read(codec
, WM9090_SOFTWARE_RESET
);
567 if (ret
!= wm9090_reg_defaults
[WM9090_SOFTWARE_RESET
]) {
568 dev_err(codec
->dev
, "Device is not a WM9090, ID=%x\n", ret
);
572 ret
= snd_soc_write(codec
, WM9090_SOFTWARE_RESET
, 0);
576 /* Configure some defaults; they will be written out when we
579 reg_cache
[WM9090_IN1_LINE_INPUT_A_VOLUME
] |= WM9090_IN1_VU
581 reg_cache
[WM9090_IN1_LINE_INPUT_B_VOLUME
] |= WM9090_IN1_VU
583 reg_cache
[WM9090_IN2_LINE_INPUT_A_VOLUME
] |= WM9090_IN2_VU
585 reg_cache
[WM9090_IN2_LINE_INPUT_B_VOLUME
] |= WM9090_IN2_VU
587 reg_cache
[WM9090_SPEAKER_VOLUME_LEFT
] |=
588 WM9090_SPKOUT_VU
| WM9090_SPKOUTL_ZC
;
589 reg_cache
[WM9090_LEFT_OUTPUT_VOLUME
] |=
590 WM9090_HPOUT1_VU
| WM9090_HPOUT1L_ZC
;
591 reg_cache
[WM9090_RIGHT_OUTPUT_VOLUME
] |=
592 WM9090_HPOUT1_VU
| WM9090_HPOUT1R_ZC
;
594 reg_cache
[WM9090_CLOCKING_1
] |= WM9090_TOCLK_ENA
;
596 wm9090_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
598 wm9090_add_controls(codec
);
604 static int wm9090_suspend(struct snd_soc_codec
*codec
, pm_message_t state
)
606 wm9090_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
611 static int wm9090_resume(struct snd_soc_codec
*codec
)
613 wm9090_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
618 #define wm9090_suspend NULL
619 #define wm9090_resume NULL
622 static int wm9090_remove(struct snd_soc_codec
*codec
)
624 wm9090_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
629 static struct snd_soc_codec_driver soc_codec_dev_wm9090
= {
630 .probe
= wm9090_probe
,
631 .remove
= wm9090_remove
,
632 .suspend
= wm9090_suspend
,
633 .resume
= wm9090_resume
,
634 .set_bias_level
= wm9090_set_bias_level
,
635 .reg_cache_size
= (WM9090_MAX_REGISTER
+ 1),
636 .reg_word_size
= sizeof(u16
),
637 .reg_cache_default
= wm9090_reg_defaults
,
638 .volatile_register
= wm9090_volatile
,
641 static int wm9090_i2c_probe(struct i2c_client
*i2c
,
642 const struct i2c_device_id
*id
)
644 struct wm9090_priv
*wm9090
;
647 wm9090
= kzalloc(sizeof(*wm9090
), GFP_KERNEL
);
648 if (wm9090
== NULL
) {
649 dev_err(&i2c
->dev
, "Can not allocate memory\n");
653 if (i2c
->dev
.platform_data
)
654 memcpy(&wm9090
->pdata
, i2c
->dev
.platform_data
,
655 sizeof(wm9090
->pdata
));
657 i2c_set_clientdata(i2c
, wm9090
);
658 wm9090
->control_data
= i2c
;
659 mutex_init(&wm9090
->mutex
);
661 ret
= snd_soc_register_codec(&i2c
->dev
,
662 &soc_codec_dev_wm9090
, NULL
, 0);
668 static int __devexit
wm9090_i2c_remove(struct i2c_client
*i2c
)
670 struct wm9090_priv
*wm9090
= i2c_get_clientdata(i2c
);
672 snd_soc_unregister_codec(&i2c
->dev
);
678 static const struct i2c_device_id wm9090_id
[] = {
682 MODULE_DEVICE_TABLE(i2c
, wm9090_id
);
684 static struct i2c_driver wm9090_i2c_driver
= {
686 .name
= "wm9090-codec",
687 .owner
= THIS_MODULE
,
689 .probe
= wm9090_i2c_probe
,
690 .remove
= __devexit_p(wm9090_i2c_remove
),
691 .id_table
= wm9090_id
,
694 static int __init
wm9090_init(void)
696 return i2c_add_driver(&wm9090_i2c_driver
);
698 module_init(wm9090_init
);
700 static void __exit
wm9090_exit(void)
702 i2c_del_driver(&wm9090_i2c_driver
);
704 module_exit(wm9090_exit
);
706 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
707 MODULE_DESCRIPTION("WM9090 ASoC driver");
708 MODULE_LICENSE("GPL");