2 * wm2000.c -- WM2000 ALSA Soc Audio driver
4 * Copyright 2008-2010 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
, int timeout
)
106 val
= wm2000_read(i2c
, reg
);
108 while (!(val
& mask
) && --timeout
) {
110 val
= wm2000_read(i2c
, reg
);
119 static int wm2000_power_up(struct i2c_client
*i2c
, int analogue
)
121 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
124 BUG_ON(wm2000
->anc_mode
!= ANC_OFF
);
126 dev_dbg(&i2c
->dev
, "Beginning power up\n");
128 if (!wm2000
->mclk_div
) {
129 dev_dbg(&i2c
->dev
, "Disabling MCLK divider\n");
130 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
131 WM2000_MCLK_DIV2_ENA_CLR
);
133 dev_dbg(&i2c
->dev
, "Enabling MCLK divider\n");
134 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
135 WM2000_MCLK_DIV2_ENA_SET
);
138 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_CLR
);
139 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_SET
);
141 /* Wait for ANC engine to become ready */
142 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
143 WM2000_ANC_ENG_IDLE
, 1)) {
144 dev_err(&i2c
->dev
, "ANC engine failed to reset\n");
148 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
149 WM2000_STATUS_BOOT_COMPLETE
, 1)) {
150 dev_err(&i2c
->dev
, "ANC engine failed to initialise\n");
154 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
156 /* Open code download of the data since it is the only bulk
158 dev_dbg(&i2c
->dev
, "Downloading %d bytes\n",
159 wm2000
->anc_download_size
- 2);
161 ret
= i2c_master_send(i2c
, wm2000
->anc_download
,
162 wm2000
->anc_download_size
);
164 dev_err(&i2c
->dev
, "i2c_transfer() failed: %d\n", ret
);
167 if (ret
!= wm2000
->anc_download_size
) {
168 dev_err(&i2c
->dev
, "i2c_transfer() failed, %d != %d\n",
169 ret
, wm2000
->anc_download_size
);
173 dev_dbg(&i2c
->dev
, "Download complete\n");
177 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, timeout
/ 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
);
186 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
187 WM2000_MODE_MOUSE_ENABLE
|
188 WM2000_MODE_THERMAL_ENABLE
);
191 ret
= wm2000_read(i2c
, WM2000_REG_SPEECH_CLARITY
);
192 if (wm2000
->speech_clarity
)
193 ret
&= ~WM2000_SPEECH_CLARITY
;
195 ret
|= WM2000_SPEECH_CLARITY
;
196 wm2000_write(i2c
, WM2000_REG_SPEECH_CLARITY
, ret
);
198 wm2000_write(i2c
, WM2000_REG_SYS_START0
, 0x33);
199 wm2000_write(i2c
, WM2000_REG_SYS_START1
, 0x02);
201 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
203 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
204 WM2000_STATUS_MOUSE_ACTIVE
, timeout
)) {
205 dev_err(&i2c
->dev
, "Timed out waiting for device after %dms\n",
210 dev_dbg(&i2c
->dev
, "ANC active\n");
212 dev_dbg(&i2c
->dev
, "Analogue active\n");
213 wm2000
->anc_mode
= ANC_ACTIVE
;
218 static int wm2000_power_down(struct i2c_client
*i2c
, int analogue
)
220 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
225 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, timeout
/ 4);
226 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
227 WM2000_MODE_ANA_SEQ_INCLUDE
|
228 WM2000_MODE_POWER_DOWN
);
231 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
232 WM2000_MODE_POWER_DOWN
);
235 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
236 WM2000_STATUS_POWER_DOWN_COMPLETE
, timeout
)) {
237 dev_err(&i2c
->dev
, "Timeout waiting for ANC power down\n");
241 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
242 WM2000_ANC_ENG_IDLE
, 1)) {
243 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
247 dev_dbg(&i2c
->dev
, "powered off\n");
248 wm2000
->anc_mode
= ANC_OFF
;
253 static int wm2000_enter_bypass(struct i2c_client
*i2c
, int analogue
)
255 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
257 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
260 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
261 WM2000_MODE_ANA_SEQ_INCLUDE
|
262 WM2000_MODE_THERMAL_ENABLE
|
263 WM2000_MODE_BYPASS_ENTRY
);
265 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
266 WM2000_MODE_THERMAL_ENABLE
|
267 WM2000_MODE_BYPASS_ENTRY
);
270 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
271 WM2000_STATUS_ANC_DISABLED
, 10)) {
272 dev_err(&i2c
->dev
, "Timeout waiting for ANC disable\n");
276 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
277 WM2000_ANC_ENG_IDLE
, 1)) {
278 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
282 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
283 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
285 wm2000
->anc_mode
= ANC_BYPASS
;
286 dev_dbg(&i2c
->dev
, "bypass enabled\n");
291 static int wm2000_exit_bypass(struct i2c_client
*i2c
, int analogue
)
293 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
295 BUG_ON(wm2000
->anc_mode
!= ANC_BYPASS
);
297 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
300 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
301 WM2000_MODE_ANA_SEQ_INCLUDE
|
302 WM2000_MODE_MOUSE_ENABLE
|
303 WM2000_MODE_THERMAL_ENABLE
);
305 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
306 WM2000_MODE_MOUSE_ENABLE
|
307 WM2000_MODE_THERMAL_ENABLE
);
310 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
311 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
313 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
314 WM2000_STATUS_MOUSE_ACTIVE
, 10)) {
315 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE\n");
319 wm2000
->anc_mode
= ANC_ACTIVE
;
320 dev_dbg(&i2c
->dev
, "MOUSE active\n");
325 static int wm2000_enter_standby(struct i2c_client
*i2c
, int analogue
)
327 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
330 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
334 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, timeout
/ 4);
336 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
337 WM2000_MODE_ANA_SEQ_INCLUDE
|
338 WM2000_MODE_THERMAL_ENABLE
|
339 WM2000_MODE_STANDBY_ENTRY
);
343 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
344 WM2000_MODE_THERMAL_ENABLE
|
345 WM2000_MODE_STANDBY_ENTRY
);
348 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
349 WM2000_STATUS_ANC_DISABLED
, timeout
)) {
351 "Timed out waiting for ANC disable after 1ms\n");
355 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
, WM2000_ANC_ENG_IDLE
,
358 "Timed out waiting for standby after %dms\n",
363 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
364 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
366 wm2000
->anc_mode
= ANC_STANDBY
;
367 dev_dbg(&i2c
->dev
, "standby\n");
369 dev_dbg(&i2c
->dev
, "Analogue disabled\n");
374 static int wm2000_exit_standby(struct i2c_client
*i2c
, int analogue
)
376 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
379 BUG_ON(wm2000
->anc_mode
!= ANC_STANDBY
);
381 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
385 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, timeout
/ 4);
387 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
388 WM2000_MODE_ANA_SEQ_INCLUDE
|
389 WM2000_MODE_THERMAL_ENABLE
|
390 WM2000_MODE_MOUSE_ENABLE
);
394 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
395 WM2000_MODE_THERMAL_ENABLE
|
396 WM2000_MODE_MOUSE_ENABLE
);
399 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
400 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
402 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
403 WM2000_STATUS_MOUSE_ACTIVE
, timeout
)) {
404 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE after %dms\n",
409 wm2000
->anc_mode
= ANC_ACTIVE
;
410 dev_dbg(&i2c
->dev
, "MOUSE active\n");
412 dev_dbg(&i2c
->dev
, "Analogue enabled\n");
417 typedef int (*wm2000_mode_fn
)(struct i2c_client
*i2c
, int analogue
);
420 enum wm2000_anc_mode source
;
421 enum wm2000_anc_mode dest
;
423 wm2000_mode_fn step
[2];
424 } anc_transitions
[] = {
438 wm2000_enter_standby
,
451 .source
= ANC_ACTIVE
,
459 .source
= ANC_ACTIVE
,
463 wm2000_enter_standby
,
467 .source
= ANC_ACTIVE
,
475 .source
= ANC_BYPASS
,
483 .source
= ANC_BYPASS
,
488 wm2000_enter_standby
,
492 .source
= ANC_BYPASS
,
500 .source
= ANC_STANDBY
,
508 .source
= ANC_STANDBY
,
517 .source
= ANC_STANDBY
,
526 static int wm2000_anc_transition(struct wm2000_priv
*wm2000
,
527 enum wm2000_anc_mode mode
)
529 struct i2c_client
*i2c
= wm2000
->i2c
;
533 if (wm2000
->anc_mode
== mode
)
536 for (i
= 0; i
< ARRAY_SIZE(anc_transitions
); i
++)
537 if (anc_transitions
[i
].source
== wm2000
->anc_mode
&&
538 anc_transitions
[i
].dest
== mode
)
540 if (i
== ARRAY_SIZE(anc_transitions
)) {
541 dev_err(&i2c
->dev
, "No transition for %d->%d\n",
542 wm2000
->anc_mode
, mode
);
546 for (j
= 0; j
< ARRAY_SIZE(anc_transitions
[j
].step
); j
++) {
547 if (!anc_transitions
[i
].step
[j
])
549 ret
= anc_transitions
[i
].step
[j
](i2c
,
550 anc_transitions
[i
].analogue
);
558 static int wm2000_anc_set_mode(struct wm2000_priv
*wm2000
)
560 struct i2c_client
*i2c
= wm2000
->i2c
;
561 enum wm2000_anc_mode mode
;
563 if (wm2000
->anc_eng_ena
&& wm2000
->spk_ena
)
564 if (wm2000
->anc_active
)
571 dev_dbg(&i2c
->dev
, "Set mode %d (enabled %d, mute %d, active %d)\n",
572 mode
, wm2000
->anc_eng_ena
, !wm2000
->spk_ena
,
575 return wm2000_anc_transition(wm2000
, mode
);
578 static int wm2000_anc_mode_get(struct snd_kcontrol
*kcontrol
,
579 struct snd_ctl_elem_value
*ucontrol
)
581 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
582 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
584 ucontrol
->value
.enumerated
.item
[0] = wm2000
->anc_active
;
589 static int wm2000_anc_mode_put(struct snd_kcontrol
*kcontrol
,
590 struct snd_ctl_elem_value
*ucontrol
)
592 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
593 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
594 int anc_active
= ucontrol
->value
.enumerated
.item
[0];
599 wm2000
->anc_active
= anc_active
;
601 return wm2000_anc_set_mode(wm2000
);
604 static int wm2000_speaker_get(struct snd_kcontrol
*kcontrol
,
605 struct snd_ctl_elem_value
*ucontrol
)
607 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
608 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
610 ucontrol
->value
.enumerated
.item
[0] = wm2000
->spk_ena
;
615 static int wm2000_speaker_put(struct snd_kcontrol
*kcontrol
,
616 struct snd_ctl_elem_value
*ucontrol
)
618 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
619 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
620 int val
= ucontrol
->value
.enumerated
.item
[0];
625 wm2000
->spk_ena
= val
;
627 return wm2000_anc_set_mode(wm2000
);
630 static const struct snd_kcontrol_new wm2000_controls
[] = {
631 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0,
633 wm2000_anc_mode_put
),
634 SOC_SINGLE_BOOL_EXT("WM2000 Switch", 0,
639 static int wm2000_anc_power_event(struct snd_soc_dapm_widget
*w
,
640 struct snd_kcontrol
*kcontrol
, int event
)
642 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
643 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
645 if (SND_SOC_DAPM_EVENT_ON(event
))
646 wm2000
->anc_eng_ena
= 1;
648 if (SND_SOC_DAPM_EVENT_OFF(event
))
649 wm2000
->anc_eng_ena
= 0;
651 return wm2000_anc_set_mode(wm2000
);
654 static const struct snd_soc_dapm_widget wm2000_dapm_widgets
[] = {
655 /* Externally visible pins */
656 SND_SOC_DAPM_OUTPUT("SPKN"),
657 SND_SOC_DAPM_OUTPUT("SPKP"),
659 SND_SOC_DAPM_INPUT("LINN"),
660 SND_SOC_DAPM_INPUT("LINP"),
662 SND_SOC_DAPM_PGA_E("ANC Engine", SND_SOC_NOPM
, 0, 0, NULL
, 0,
663 wm2000_anc_power_event
,
664 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
667 /* Target, Path, Source */
668 static const struct snd_soc_dapm_route wm2000_audio_map
[] = {
669 { "SPKN", NULL
, "ANC Engine" },
670 { "SPKP", NULL
, "ANC Engine" },
671 { "ANC Engine", NULL
, "LINN" },
672 { "ANC Engine", NULL
, "LINP" },
676 static int wm2000_suspend(struct snd_soc_codec
*codec
)
678 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
680 return wm2000_anc_transition(wm2000
, ANC_OFF
);
683 static int wm2000_resume(struct snd_soc_codec
*codec
)
685 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
687 return wm2000_anc_set_mode(wm2000
);
690 #define wm2000_suspend NULL
691 #define wm2000_resume NULL
694 static const struct regmap_config wm2000_regmap
= {
699 static int wm2000_probe(struct snd_soc_codec
*codec
)
701 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
703 /* This will trigger a transition to standby mode by default */
704 wm2000_anc_set_mode(wm2000
);
709 static int wm2000_remove(struct snd_soc_codec
*codec
)
711 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
713 return wm2000_anc_transition(wm2000
, ANC_OFF
);
716 static struct snd_soc_codec_driver soc_codec_dev_wm2000
= {
717 .probe
= wm2000_probe
,
718 .remove
= wm2000_remove
,
719 .suspend
= wm2000_suspend
,
720 .resume
= wm2000_resume
,
722 .dapm_widgets
= wm2000_dapm_widgets
,
723 .num_dapm_widgets
= ARRAY_SIZE(wm2000_dapm_widgets
),
724 .dapm_routes
= wm2000_audio_map
,
725 .num_dapm_routes
= ARRAY_SIZE(wm2000_audio_map
),
726 .controls
= wm2000_controls
,
727 .num_controls
= ARRAY_SIZE(wm2000_controls
),
730 static int __devinit
wm2000_i2c_probe(struct i2c_client
*i2c
,
731 const struct i2c_device_id
*i2c_id
)
733 struct wm2000_priv
*wm2000
;
734 struct wm2000_platform_data
*pdata
;
735 const char *filename
;
736 const struct firmware
*fw
= NULL
;
741 wm2000
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm2000_priv
),
743 if (wm2000
== NULL
) {
744 dev_err(&i2c
->dev
, "Unable to allocate private data\n");
748 dev_set_drvdata(&i2c
->dev
, wm2000
);
750 wm2000
->regmap
= regmap_init_i2c(i2c
, &wm2000_regmap
);
751 if (IS_ERR(wm2000
->regmap
)) {
752 ret
= PTR_ERR(wm2000
->regmap
);
753 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
758 /* Verify that this is a WM2000 */
759 reg
= wm2000_read(i2c
, WM2000_REG_ID1
);
761 reg
= wm2000_read(i2c
, WM2000_REG_ID2
);
765 dev_err(&i2c
->dev
, "Device is not a WM2000 - ID %x\n", id
);
767 goto out_regmap_exit
;
770 reg
= wm2000_read(i2c
, WM2000_REG_REVISON
);
771 dev_info(&i2c
->dev
, "revision %c\n", reg
+ 'A');
773 filename
= "wm2000_anc.bin";
774 pdata
= dev_get_platdata(&i2c
->dev
);
776 wm2000
->mclk_div
= pdata
->mclkdiv2
;
777 wm2000
->speech_clarity
= !pdata
->speech_enh_disable
;
779 if (pdata
->download_file
)
780 filename
= pdata
->download_file
;
783 ret
= request_firmware(&fw
, filename
, &i2c
->dev
);
785 dev_err(&i2c
->dev
, "Failed to acquire ANC data: %d\n", ret
);
786 goto out_regmap_exit
;
789 /* Pre-cook the concatenation of the register address onto the image */
790 wm2000
->anc_download_size
= fw
->size
+ 2;
791 wm2000
->anc_download
= devm_kzalloc(&i2c
->dev
,
792 wm2000
->anc_download_size
,
794 if (wm2000
->anc_download
== NULL
) {
795 dev_err(&i2c
->dev
, "Out of memory\n");
797 goto out_regmap_exit
;
800 wm2000
->anc_download
[0] = 0x80;
801 wm2000
->anc_download
[1] = 0x00;
802 memcpy(wm2000
->anc_download
+ 2, fw
->data
, fw
->size
);
804 wm2000
->anc_eng_ena
= 1;
805 wm2000
->anc_active
= 1;
809 wm2000_reset(wm2000
);
811 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_wm2000
, NULL
, 0);
816 regmap_exit(wm2000
->regmap
);
818 release_firmware(fw
);
822 static __devexit
int wm2000_i2c_remove(struct i2c_client
*i2c
)
824 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
826 snd_soc_unregister_codec(&i2c
->dev
);
827 regmap_exit(wm2000
->regmap
);
832 static const struct i2c_device_id wm2000_i2c_id
[] = {
836 MODULE_DEVICE_TABLE(i2c
, wm2000_i2c_id
);
838 static struct i2c_driver wm2000_i2c_driver
= {
841 .owner
= THIS_MODULE
,
843 .probe
= wm2000_i2c_probe
,
844 .remove
= __devexit_p(wm2000_i2c_remove
),
845 .id_table
= wm2000_i2c_id
,
848 static int __init
wm2000_init(void)
850 return i2c_add_driver(&wm2000_i2c_driver
);
852 module_init(wm2000_init
);
854 static void __exit
wm2000_exit(void)
856 i2c_del_driver(&wm2000_i2c_driver
);
858 module_exit(wm2000_exit
);
860 MODULE_DESCRIPTION("ASoC WM2000 driver");
861 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>");
862 MODULE_LICENSE("GPL");