2 * wm2000.c -- WM2000 ALSA Soc Audio driver
4 * Copyright 2008-2011 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * The download image for the WM2000 will be requested as
13 * 'wm2000_anc.bin' by default (overridable via platform data) at
14 * runtime and is expected to be in flat binary format. This is
15 * generated by Wolfson configuration tools and includes
16 * system-specific callibration information. If supplied as a
17 * sequence of ASCII-encoded hexidecimal bytes this can be converted
18 * into a flat binary with a command such as this on the command line:
20 * perl -e 'while (<>) { s/[\r\n]+// ; printf("%c", hex($_)); }'
21 * < file > wm2000_anc.bin
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/firmware.h>
29 #include <linux/delay.h>
31 #include <linux/i2c.h>
32 #include <linux/regmap.h>
33 #include <linux/debugfs.h>
34 #include <linux/slab.h>
35 #include <sound/core.h>
36 #include <sound/pcm.h>
37 #include <sound/pcm_params.h>
38 #include <sound/soc.h>
39 #include <sound/initval.h>
40 #include <sound/tlv.h>
42 #include <sound/wm2000.h>
46 enum wm2000_anc_mode
{
54 struct i2c_client
*i2c
;
55 struct regmap
*regmap
;
57 enum wm2000_anc_mode anc_mode
;
59 unsigned int anc_active
:1;
60 unsigned int anc_eng_ena
:1;
61 unsigned int spk_ena
:1;
63 unsigned int mclk_div
:1;
64 unsigned int speech_clarity
:1;
66 int anc_download_size
;
70 static int wm2000_write(struct i2c_client
*i2c
, unsigned int reg
,
73 struct wm2000_priv
*wm2000
= i2c_get_clientdata(i2c
);
74 return regmap_write(wm2000
->regmap
, reg
, value
);
77 static unsigned int wm2000_read(struct i2c_client
*i2c
, unsigned int r
)
79 struct wm2000_priv
*wm2000
= i2c_get_clientdata(i2c
);
83 ret
= regmap_read(wm2000
->regmap
, r
, &val
);
90 static void wm2000_reset(struct wm2000_priv
*wm2000
)
92 struct i2c_client
*i2c
= wm2000
->i2c
;
94 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_CLR
);
95 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
96 wm2000_write(i2c
, WM2000_REG_ID1
, 0);
98 wm2000
->anc_mode
= ANC_OFF
;
101 static int wm2000_poll_bit(struct i2c_client
*i2c
,
102 unsigned int reg
, u8 mask
)
107 val
= wm2000_read(i2c
, reg
);
109 while (!(val
& mask
) && --timeout
) {
111 val
= wm2000_read(i2c
, reg
);
120 static int wm2000_power_up(struct i2c_client
*i2c
, int analogue
)
122 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
125 BUG_ON(wm2000
->anc_mode
!= ANC_OFF
);
127 dev_dbg(&i2c
->dev
, "Beginning power up\n");
129 if (!wm2000
->mclk_div
) {
130 dev_dbg(&i2c
->dev
, "Disabling MCLK divider\n");
131 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
132 WM2000_MCLK_DIV2_ENA_CLR
);
134 dev_dbg(&i2c
->dev
, "Enabling MCLK divider\n");
135 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
136 WM2000_MCLK_DIV2_ENA_SET
);
139 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_CLR
);
140 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_SET
);
142 /* Wait for ANC engine to become ready */
143 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
144 WM2000_ANC_ENG_IDLE
)) {
145 dev_err(&i2c
->dev
, "ANC engine failed to reset\n");
149 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
150 WM2000_STATUS_BOOT_COMPLETE
)) {
151 dev_err(&i2c
->dev
, "ANC engine failed to initialise\n");
155 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
157 /* Open code download of the data since it is the only bulk
159 dev_dbg(&i2c
->dev
, "Downloading %d bytes\n",
160 wm2000
->anc_download_size
- 2);
162 ret
= i2c_master_send(i2c
, wm2000
->anc_download
,
163 wm2000
->anc_download_size
);
165 dev_err(&i2c
->dev
, "i2c_transfer() failed: %d\n", ret
);
168 if (ret
!= wm2000
->anc_download_size
) {
169 dev_err(&i2c
->dev
, "i2c_transfer() failed, %d != %d\n",
170 ret
, wm2000
->anc_download_size
);
174 dev_dbg(&i2c
->dev
, "Download complete\n");
177 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, 248 / 4);
179 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
180 WM2000_MODE_ANA_SEQ_INCLUDE
|
181 WM2000_MODE_MOUSE_ENABLE
|
182 WM2000_MODE_THERMAL_ENABLE
);
184 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
185 WM2000_MODE_MOUSE_ENABLE
|
186 WM2000_MODE_THERMAL_ENABLE
);
189 ret
= wm2000_read(i2c
, WM2000_REG_SPEECH_CLARITY
);
190 if (wm2000
->speech_clarity
)
191 ret
&= ~WM2000_SPEECH_CLARITY
;
193 ret
|= WM2000_SPEECH_CLARITY
;
194 wm2000_write(i2c
, WM2000_REG_SPEECH_CLARITY
, ret
);
196 wm2000_write(i2c
, WM2000_REG_SYS_START0
, 0x33);
197 wm2000_write(i2c
, WM2000_REG_SYS_START1
, 0x02);
199 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
201 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
202 WM2000_STATUS_MOUSE_ACTIVE
)) {
203 dev_err(&i2c
->dev
, "Timed out waiting for device\n");
207 dev_dbg(&i2c
->dev
, "ANC active\n");
209 dev_dbg(&i2c
->dev
, "Analogue active\n");
210 wm2000
->anc_mode
= ANC_ACTIVE
;
215 static int wm2000_power_down(struct i2c_client
*i2c
, int analogue
)
217 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
220 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, 248 / 4);
221 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
222 WM2000_MODE_ANA_SEQ_INCLUDE
|
223 WM2000_MODE_POWER_DOWN
);
225 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
226 WM2000_MODE_POWER_DOWN
);
229 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
230 WM2000_STATUS_POWER_DOWN_COMPLETE
)) {
231 dev_err(&i2c
->dev
, "Timeout waiting for ANC power down\n");
235 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
236 WM2000_ANC_ENG_IDLE
)) {
237 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
241 dev_dbg(&i2c
->dev
, "powered off\n");
242 wm2000
->anc_mode
= ANC_OFF
;
247 static int wm2000_enter_bypass(struct i2c_client
*i2c
, int analogue
)
249 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
251 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
254 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
255 WM2000_MODE_ANA_SEQ_INCLUDE
|
256 WM2000_MODE_THERMAL_ENABLE
|
257 WM2000_MODE_BYPASS_ENTRY
);
259 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
260 WM2000_MODE_THERMAL_ENABLE
|
261 WM2000_MODE_BYPASS_ENTRY
);
264 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
265 WM2000_STATUS_ANC_DISABLED
)) {
266 dev_err(&i2c
->dev
, "Timeout waiting for ANC disable\n");
270 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
271 WM2000_ANC_ENG_IDLE
)) {
272 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
276 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
277 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
279 wm2000
->anc_mode
= ANC_BYPASS
;
280 dev_dbg(&i2c
->dev
, "bypass enabled\n");
285 static int wm2000_exit_bypass(struct i2c_client
*i2c
, int analogue
)
287 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
289 BUG_ON(wm2000
->anc_mode
!= ANC_BYPASS
);
291 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
294 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
295 WM2000_MODE_ANA_SEQ_INCLUDE
|
296 WM2000_MODE_MOUSE_ENABLE
|
297 WM2000_MODE_THERMAL_ENABLE
);
299 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
300 WM2000_MODE_MOUSE_ENABLE
|
301 WM2000_MODE_THERMAL_ENABLE
);
304 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
305 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
307 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
308 WM2000_STATUS_MOUSE_ACTIVE
)) {
309 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE\n");
313 wm2000
->anc_mode
= ANC_ACTIVE
;
314 dev_dbg(&i2c
->dev
, "MOUSE active\n");
319 static int wm2000_enter_standby(struct i2c_client
*i2c
, int analogue
)
321 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
323 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
326 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, 248 / 4);
328 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
329 WM2000_MODE_ANA_SEQ_INCLUDE
|
330 WM2000_MODE_THERMAL_ENABLE
|
331 WM2000_MODE_STANDBY_ENTRY
);
333 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
334 WM2000_MODE_THERMAL_ENABLE
|
335 WM2000_MODE_STANDBY_ENTRY
);
338 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
339 WM2000_STATUS_ANC_DISABLED
)) {
341 "Timed out waiting for ANC disable after 1ms\n");
345 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
, WM2000_ANC_ENG_IDLE
)) {
347 "Timed out waiting for standby\n");
351 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
352 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
354 wm2000
->anc_mode
= ANC_STANDBY
;
355 dev_dbg(&i2c
->dev
, "standby\n");
357 dev_dbg(&i2c
->dev
, "Analogue disabled\n");
362 static int wm2000_exit_standby(struct i2c_client
*i2c
, int analogue
)
364 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
366 BUG_ON(wm2000
->anc_mode
!= ANC_STANDBY
);
368 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
371 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, 248 / 4);
373 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
374 WM2000_MODE_ANA_SEQ_INCLUDE
|
375 WM2000_MODE_THERMAL_ENABLE
|
376 WM2000_MODE_MOUSE_ENABLE
);
378 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
379 WM2000_MODE_THERMAL_ENABLE
|
380 WM2000_MODE_MOUSE_ENABLE
);
383 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
384 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
386 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
387 WM2000_STATUS_MOUSE_ACTIVE
)) {
388 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE\n");
392 wm2000
->anc_mode
= ANC_ACTIVE
;
393 dev_dbg(&i2c
->dev
, "MOUSE active\n");
395 dev_dbg(&i2c
->dev
, "Analogue enabled\n");
400 typedef int (*wm2000_mode_fn
)(struct i2c_client
*i2c
, int analogue
);
403 enum wm2000_anc_mode source
;
404 enum wm2000_anc_mode dest
;
406 wm2000_mode_fn step
[2];
407 } anc_transitions
[] = {
421 wm2000_enter_standby
,
434 .source
= ANC_ACTIVE
,
442 .source
= ANC_ACTIVE
,
446 wm2000_enter_standby
,
450 .source
= ANC_ACTIVE
,
458 .source
= ANC_BYPASS
,
466 .source
= ANC_BYPASS
,
471 wm2000_enter_standby
,
475 .source
= ANC_BYPASS
,
483 .source
= ANC_STANDBY
,
491 .source
= ANC_STANDBY
,
500 .source
= ANC_STANDBY
,
509 static int wm2000_anc_transition(struct wm2000_priv
*wm2000
,
510 enum wm2000_anc_mode mode
)
512 struct i2c_client
*i2c
= wm2000
->i2c
;
516 if (wm2000
->anc_mode
== mode
)
519 for (i
= 0; i
< ARRAY_SIZE(anc_transitions
); i
++)
520 if (anc_transitions
[i
].source
== wm2000
->anc_mode
&&
521 anc_transitions
[i
].dest
== mode
)
523 if (i
== ARRAY_SIZE(anc_transitions
)) {
524 dev_err(&i2c
->dev
, "No transition for %d->%d\n",
525 wm2000
->anc_mode
, mode
);
529 for (j
= 0; j
< ARRAY_SIZE(anc_transitions
[j
].step
); j
++) {
530 if (!anc_transitions
[i
].step
[j
])
532 ret
= anc_transitions
[i
].step
[j
](i2c
,
533 anc_transitions
[i
].analogue
);
541 static int wm2000_anc_set_mode(struct wm2000_priv
*wm2000
)
543 struct i2c_client
*i2c
= wm2000
->i2c
;
544 enum wm2000_anc_mode mode
;
546 if (wm2000
->anc_eng_ena
&& wm2000
->spk_ena
)
547 if (wm2000
->anc_active
)
554 dev_dbg(&i2c
->dev
, "Set mode %d (enabled %d, mute %d, active %d)\n",
555 mode
, wm2000
->anc_eng_ena
, !wm2000
->spk_ena
,
558 return wm2000_anc_transition(wm2000
, mode
);
561 static int wm2000_anc_mode_get(struct snd_kcontrol
*kcontrol
,
562 struct snd_ctl_elem_value
*ucontrol
)
564 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
565 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
567 ucontrol
->value
.enumerated
.item
[0] = wm2000
->anc_active
;
572 static int wm2000_anc_mode_put(struct snd_kcontrol
*kcontrol
,
573 struct snd_ctl_elem_value
*ucontrol
)
575 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
576 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
577 int anc_active
= ucontrol
->value
.enumerated
.item
[0];
582 wm2000
->anc_active
= anc_active
;
584 return wm2000_anc_set_mode(wm2000
);
587 static int wm2000_speaker_get(struct snd_kcontrol
*kcontrol
,
588 struct snd_ctl_elem_value
*ucontrol
)
590 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
591 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
593 ucontrol
->value
.enumerated
.item
[0] = wm2000
->spk_ena
;
598 static int wm2000_speaker_put(struct snd_kcontrol
*kcontrol
,
599 struct snd_ctl_elem_value
*ucontrol
)
601 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
602 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
603 int val
= ucontrol
->value
.enumerated
.item
[0];
608 wm2000
->spk_ena
= val
;
610 return wm2000_anc_set_mode(wm2000
);
613 static const struct snd_kcontrol_new wm2000_controls
[] = {
614 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0,
616 wm2000_anc_mode_put
),
617 SOC_SINGLE_BOOL_EXT("WM2000 Switch", 0,
622 static int wm2000_anc_power_event(struct snd_soc_dapm_widget
*w
,
623 struct snd_kcontrol
*kcontrol
, int event
)
625 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
626 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
628 if (SND_SOC_DAPM_EVENT_ON(event
))
629 wm2000
->anc_eng_ena
= 1;
631 if (SND_SOC_DAPM_EVENT_OFF(event
))
632 wm2000
->anc_eng_ena
= 0;
634 return wm2000_anc_set_mode(wm2000
);
637 static const struct snd_soc_dapm_widget wm2000_dapm_widgets
[] = {
638 /* Externally visible pins */
639 SND_SOC_DAPM_OUTPUT("SPKN"),
640 SND_SOC_DAPM_OUTPUT("SPKP"),
642 SND_SOC_DAPM_INPUT("LINN"),
643 SND_SOC_DAPM_INPUT("LINP"),
645 SND_SOC_DAPM_PGA_E("ANC Engine", SND_SOC_NOPM
, 0, 0, NULL
, 0,
646 wm2000_anc_power_event
,
647 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
650 /* Target, Path, Source */
651 static const struct snd_soc_dapm_route wm2000_audio_map
[] = {
652 { "SPKN", NULL
, "ANC Engine" },
653 { "SPKP", NULL
, "ANC Engine" },
654 { "ANC Engine", NULL
, "LINN" },
655 { "ANC Engine", NULL
, "LINP" },
659 static int wm2000_suspend(struct snd_soc_codec
*codec
)
661 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
663 return wm2000_anc_transition(wm2000
, ANC_OFF
);
666 static int wm2000_resume(struct snd_soc_codec
*codec
)
668 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
670 return wm2000_anc_set_mode(wm2000
);
673 #define wm2000_suspend NULL
674 #define wm2000_resume NULL
677 static bool wm2000_readable_reg(struct device
*dev
, unsigned int reg
)
680 case WM2000_REG_SYS_START
:
681 case WM2000_REG_SPEECH_CLARITY
:
682 case WM2000_REG_SYS_WATCHDOG
:
683 case WM2000_REG_ANA_VMID_PD_TIME
:
684 case WM2000_REG_ANA_VMID_PU_TIME
:
685 case WM2000_REG_CAT_FLTR_INDX
:
686 case WM2000_REG_CAT_GAIN_0
:
687 case WM2000_REG_SYS_STATUS
:
688 case WM2000_REG_SYS_MODE_CNTRL
:
689 case WM2000_REG_SYS_START0
:
690 case WM2000_REG_SYS_START1
:
693 case WM2000_REG_REVISON
:
694 case WM2000_REG_SYS_CTL1
:
695 case WM2000_REG_SYS_CTL2
:
696 case WM2000_REG_ANC_STAT
:
697 case WM2000_REG_IF_CTL
:
704 static const struct regmap_config wm2000_regmap
= {
708 .max_register
= WM2000_REG_IF_CTL
,
709 .readable_reg
= wm2000_readable_reg
,
712 static int wm2000_probe(struct snd_soc_codec
*codec
)
714 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
716 /* This will trigger a transition to standby mode by default */
717 wm2000_anc_set_mode(wm2000
);
722 static int wm2000_remove(struct snd_soc_codec
*codec
)
724 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
726 return wm2000_anc_transition(wm2000
, ANC_OFF
);
729 static struct snd_soc_codec_driver soc_codec_dev_wm2000
= {
730 .probe
= wm2000_probe
,
731 .remove
= wm2000_remove
,
732 .suspend
= wm2000_suspend
,
733 .resume
= wm2000_resume
,
735 .dapm_widgets
= wm2000_dapm_widgets
,
736 .num_dapm_widgets
= ARRAY_SIZE(wm2000_dapm_widgets
),
737 .dapm_routes
= wm2000_audio_map
,
738 .num_dapm_routes
= ARRAY_SIZE(wm2000_audio_map
),
739 .controls
= wm2000_controls
,
740 .num_controls
= ARRAY_SIZE(wm2000_controls
),
743 static int __devinit
wm2000_i2c_probe(struct i2c_client
*i2c
,
744 const struct i2c_device_id
*i2c_id
)
746 struct wm2000_priv
*wm2000
;
747 struct wm2000_platform_data
*pdata
;
748 const char *filename
;
749 const struct firmware
*fw
= NULL
;
754 wm2000
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm2000_priv
),
756 if (wm2000
== NULL
) {
757 dev_err(&i2c
->dev
, "Unable to allocate private data\n");
761 dev_set_drvdata(&i2c
->dev
, wm2000
);
763 wm2000
->regmap
= regmap_init_i2c(i2c
, &wm2000_regmap
);
764 if (IS_ERR(wm2000
->regmap
)) {
765 ret
= PTR_ERR(wm2000
->regmap
);
766 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
771 /* Verify that this is a WM2000 */
772 reg
= wm2000_read(i2c
, WM2000_REG_ID1
);
774 reg
= wm2000_read(i2c
, WM2000_REG_ID2
);
778 dev_err(&i2c
->dev
, "Device is not a WM2000 - ID %x\n", id
);
780 goto out_regmap_exit
;
783 reg
= wm2000_read(i2c
, WM2000_REG_REVISON
);
784 dev_info(&i2c
->dev
, "revision %c\n", reg
+ 'A');
786 filename
= "wm2000_anc.bin";
787 pdata
= dev_get_platdata(&i2c
->dev
);
789 wm2000
->mclk_div
= pdata
->mclkdiv2
;
790 wm2000
->speech_clarity
= !pdata
->speech_enh_disable
;
792 if (pdata
->download_file
)
793 filename
= pdata
->download_file
;
796 ret
= request_firmware(&fw
, filename
, &i2c
->dev
);
798 dev_err(&i2c
->dev
, "Failed to acquire ANC data: %d\n", ret
);
799 goto out_regmap_exit
;
802 /* Pre-cook the concatenation of the register address onto the image */
803 wm2000
->anc_download_size
= fw
->size
+ 2;
804 wm2000
->anc_download
= devm_kzalloc(&i2c
->dev
,
805 wm2000
->anc_download_size
,
807 if (wm2000
->anc_download
== NULL
) {
808 dev_err(&i2c
->dev
, "Out of memory\n");
810 goto out_regmap_exit
;
813 wm2000
->anc_download
[0] = 0x80;
814 wm2000
->anc_download
[1] = 0x00;
815 memcpy(wm2000
->anc_download
+ 2, fw
->data
, fw
->size
);
817 wm2000
->anc_eng_ena
= 1;
818 wm2000
->anc_active
= 1;
822 wm2000_reset(wm2000
);
824 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_wm2000
, NULL
, 0);
829 regmap_exit(wm2000
->regmap
);
831 release_firmware(fw
);
835 static __devexit
int wm2000_i2c_remove(struct i2c_client
*i2c
)
837 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
839 snd_soc_unregister_codec(&i2c
->dev
);
840 regmap_exit(wm2000
->regmap
);
845 static const struct i2c_device_id wm2000_i2c_id
[] = {
849 MODULE_DEVICE_TABLE(i2c
, wm2000_i2c_id
);
851 static struct i2c_driver wm2000_i2c_driver
= {
854 .owner
= THIS_MODULE
,
856 .probe
= wm2000_i2c_probe
,
857 .remove
= __devexit_p(wm2000_i2c_remove
),
858 .id_table
= wm2000_i2c_id
,
861 static int __init
wm2000_init(void)
863 return i2c_add_driver(&wm2000_i2c_driver
);
865 module_init(wm2000_init
);
867 static void __exit
wm2000_exit(void)
869 i2c_del_driver(&wm2000_i2c_driver
);
871 module_exit(wm2000_exit
);
873 MODULE_DESCRIPTION("ASoC WM2000 driver");
874 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>");
875 MODULE_LICENSE("GPL");