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/clk.h>
30 #include <linux/delay.h>
32 #include <linux/i2c.h>
33 #include <linux/regmap.h>
34 #include <linux/debugfs.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/slab.h>
37 #include <sound/core.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/soc.h>
41 #include <sound/initval.h>
42 #include <sound/tlv.h>
44 #include <sound/wm2000.h>
48 #define WM2000_NUM_SUPPLIES 3
50 static const char *wm2000_supplies
[WM2000_NUM_SUPPLIES
] = {
56 enum wm2000_anc_mode
{
64 struct i2c_client
*i2c
;
65 struct regmap
*regmap
;
68 struct regulator_bulk_data supplies
[WM2000_NUM_SUPPLIES
];
70 enum wm2000_anc_mode anc_mode
;
72 unsigned int anc_active
:1;
73 unsigned int anc_eng_ena
:1;
74 unsigned int spk_ena
:1;
76 unsigned int speech_clarity
:1;
78 int anc_download_size
;
84 static int wm2000_write(struct i2c_client
*i2c
, unsigned int reg
,
87 struct wm2000_priv
*wm2000
= i2c_get_clientdata(i2c
);
88 return regmap_write(wm2000
->regmap
, reg
, value
);
91 static unsigned int wm2000_read(struct i2c_client
*i2c
, unsigned int r
)
93 struct wm2000_priv
*wm2000
= i2c_get_clientdata(i2c
);
97 ret
= regmap_read(wm2000
->regmap
, r
, &val
);
104 static void wm2000_reset(struct wm2000_priv
*wm2000
)
106 struct i2c_client
*i2c
= wm2000
->i2c
;
108 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_CLR
);
109 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
110 wm2000_write(i2c
, WM2000_REG_ID1
, 0);
112 wm2000
->anc_mode
= ANC_OFF
;
115 static int wm2000_poll_bit(struct i2c_client
*i2c
,
116 unsigned int reg
, u8 mask
)
121 val
= wm2000_read(i2c
, reg
);
123 while (!(val
& mask
) && --timeout
) {
125 val
= wm2000_read(i2c
, reg
);
134 static int wm2000_power_up(struct i2c_client
*i2c
, int analogue
)
136 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
140 BUG_ON(wm2000
->anc_mode
!= ANC_OFF
);
142 dev_dbg(&i2c
->dev
, "Beginning power up\n");
144 ret
= regulator_bulk_enable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
146 dev_err(&i2c
->dev
, "Failed to enable supplies: %d\n", ret
);
150 rate
= clk_get_rate(wm2000
->mclk
);
151 if (rate
<= 13500000) {
152 dev_dbg(&i2c
->dev
, "Disabling MCLK divider\n");
153 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
154 WM2000_MCLK_DIV2_ENA_CLR
);
156 dev_dbg(&i2c
->dev
, "Enabling MCLK divider\n");
157 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
,
158 WM2000_MCLK_DIV2_ENA_SET
);
161 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_CLR
);
162 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_ENG_SET
);
164 /* Wait for ANC engine to become ready */
165 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
166 WM2000_ANC_ENG_IDLE
)) {
167 dev_err(&i2c
->dev
, "ANC engine failed to reset\n");
168 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
172 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
173 WM2000_STATUS_BOOT_COMPLETE
)) {
174 dev_err(&i2c
->dev
, "ANC engine failed to initialise\n");
175 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
179 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
181 /* Open code download of the data since it is the only bulk
183 dev_dbg(&i2c
->dev
, "Downloading %d bytes\n",
184 wm2000
->anc_download_size
- 2);
186 ret
= i2c_master_send(i2c
, wm2000
->anc_download
,
187 wm2000
->anc_download_size
);
189 dev_err(&i2c
->dev
, "i2c_transfer() failed: %d\n", ret
);
190 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
193 if (ret
!= wm2000
->anc_download_size
) {
194 dev_err(&i2c
->dev
, "i2c_transfer() failed, %d != %d\n",
195 ret
, wm2000
->anc_download_size
);
196 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
200 dev_dbg(&i2c
->dev
, "Download complete\n");
203 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, 248 / 4);
205 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
206 WM2000_MODE_ANA_SEQ_INCLUDE
|
207 WM2000_MODE_MOUSE_ENABLE
|
208 WM2000_MODE_THERMAL_ENABLE
);
210 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
211 WM2000_MODE_MOUSE_ENABLE
|
212 WM2000_MODE_THERMAL_ENABLE
);
215 ret
= wm2000_read(i2c
, WM2000_REG_SPEECH_CLARITY
);
216 if (wm2000
->speech_clarity
)
217 ret
|= WM2000_SPEECH_CLARITY
;
219 ret
&= ~WM2000_SPEECH_CLARITY
;
220 wm2000_write(i2c
, WM2000_REG_SPEECH_CLARITY
, ret
);
222 wm2000_write(i2c
, WM2000_REG_SYS_START0
, 0x33);
223 wm2000_write(i2c
, WM2000_REG_SYS_START1
, 0x02);
225 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
227 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
228 WM2000_STATUS_MOUSE_ACTIVE
)) {
229 dev_err(&i2c
->dev
, "Timed out waiting for device\n");
230 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
234 dev_dbg(&i2c
->dev
, "ANC active\n");
236 dev_dbg(&i2c
->dev
, "Analogue active\n");
237 wm2000
->anc_mode
= ANC_ACTIVE
;
242 static int wm2000_power_down(struct i2c_client
*i2c
, int analogue
)
244 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
247 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, 248 / 4);
248 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
249 WM2000_MODE_ANA_SEQ_INCLUDE
|
250 WM2000_MODE_POWER_DOWN
);
252 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
253 WM2000_MODE_POWER_DOWN
);
256 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
257 WM2000_STATUS_POWER_DOWN_COMPLETE
)) {
258 dev_err(&i2c
->dev
, "Timeout waiting for ANC power down\n");
262 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
263 WM2000_ANC_ENG_IDLE
)) {
264 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
268 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
270 dev_dbg(&i2c
->dev
, "powered off\n");
271 wm2000
->anc_mode
= ANC_OFF
;
276 static int wm2000_enter_bypass(struct i2c_client
*i2c
, int analogue
)
278 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
280 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
283 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
284 WM2000_MODE_ANA_SEQ_INCLUDE
|
285 WM2000_MODE_THERMAL_ENABLE
|
286 WM2000_MODE_BYPASS_ENTRY
);
288 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
289 WM2000_MODE_THERMAL_ENABLE
|
290 WM2000_MODE_BYPASS_ENTRY
);
293 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
294 WM2000_STATUS_ANC_DISABLED
)) {
295 dev_err(&i2c
->dev
, "Timeout waiting for ANC disable\n");
299 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
,
300 WM2000_ANC_ENG_IDLE
)) {
301 dev_err(&i2c
->dev
, "Timeout waiting for ANC engine idle\n");
305 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
306 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
308 wm2000
->anc_mode
= ANC_BYPASS
;
309 dev_dbg(&i2c
->dev
, "bypass enabled\n");
314 static int wm2000_exit_bypass(struct i2c_client
*i2c
, int analogue
)
316 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
318 BUG_ON(wm2000
->anc_mode
!= ANC_BYPASS
);
320 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
323 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
324 WM2000_MODE_ANA_SEQ_INCLUDE
|
325 WM2000_MODE_MOUSE_ENABLE
|
326 WM2000_MODE_THERMAL_ENABLE
);
328 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
329 WM2000_MODE_MOUSE_ENABLE
|
330 WM2000_MODE_THERMAL_ENABLE
);
333 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
334 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
336 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
337 WM2000_STATUS_MOUSE_ACTIVE
)) {
338 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE\n");
342 wm2000
->anc_mode
= ANC_ACTIVE
;
343 dev_dbg(&i2c
->dev
, "MOUSE active\n");
348 static int wm2000_enter_standby(struct i2c_client
*i2c
, int analogue
)
350 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
352 BUG_ON(wm2000
->anc_mode
!= ANC_ACTIVE
);
355 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PD_TIME
, 248 / 4);
357 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
358 WM2000_MODE_ANA_SEQ_INCLUDE
|
359 WM2000_MODE_THERMAL_ENABLE
|
360 WM2000_MODE_STANDBY_ENTRY
);
362 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
363 WM2000_MODE_THERMAL_ENABLE
|
364 WM2000_MODE_STANDBY_ENTRY
);
367 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
368 WM2000_STATUS_ANC_DISABLED
)) {
370 "Timed out waiting for ANC disable after 1ms\n");
374 if (!wm2000_poll_bit(i2c
, WM2000_REG_ANC_STAT
, WM2000_ANC_ENG_IDLE
)) {
376 "Timed out waiting for standby\n");
380 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, WM2000_SYS_STBY
);
381 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_CLR
);
383 wm2000
->anc_mode
= ANC_STANDBY
;
384 dev_dbg(&i2c
->dev
, "standby\n");
386 dev_dbg(&i2c
->dev
, "Analogue disabled\n");
391 static int wm2000_exit_standby(struct i2c_client
*i2c
, int analogue
)
393 struct wm2000_priv
*wm2000
= dev_get_drvdata(&i2c
->dev
);
395 BUG_ON(wm2000
->anc_mode
!= ANC_STANDBY
);
397 wm2000_write(i2c
, WM2000_REG_SYS_CTL1
, 0);
400 wm2000_write(i2c
, WM2000_REG_ANA_VMID_PU_TIME
, 248 / 4);
402 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
403 WM2000_MODE_ANA_SEQ_INCLUDE
|
404 WM2000_MODE_THERMAL_ENABLE
|
405 WM2000_MODE_MOUSE_ENABLE
);
407 wm2000_write(i2c
, WM2000_REG_SYS_MODE_CNTRL
,
408 WM2000_MODE_THERMAL_ENABLE
|
409 WM2000_MODE_MOUSE_ENABLE
);
412 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_RAM_SET
);
413 wm2000_write(i2c
, WM2000_REG_SYS_CTL2
, WM2000_ANC_INT_N_CLR
);
415 if (!wm2000_poll_bit(i2c
, WM2000_REG_SYS_STATUS
,
416 WM2000_STATUS_MOUSE_ACTIVE
)) {
417 dev_err(&i2c
->dev
, "Timed out waiting for MOUSE\n");
421 wm2000
->anc_mode
= ANC_ACTIVE
;
422 dev_dbg(&i2c
->dev
, "MOUSE active\n");
424 dev_dbg(&i2c
->dev
, "Analogue enabled\n");
429 typedef int (*wm2000_mode_fn
)(struct i2c_client
*i2c
, int analogue
);
432 enum wm2000_anc_mode source
;
433 enum wm2000_anc_mode dest
;
435 wm2000_mode_fn step
[2];
436 } anc_transitions
[] = {
450 wm2000_enter_standby
,
463 .source
= ANC_ACTIVE
,
471 .source
= ANC_ACTIVE
,
475 wm2000_enter_standby
,
479 .source
= ANC_ACTIVE
,
487 .source
= ANC_BYPASS
,
495 .source
= ANC_BYPASS
,
500 wm2000_enter_standby
,
504 .source
= ANC_BYPASS
,
512 .source
= ANC_STANDBY
,
520 .source
= ANC_STANDBY
,
529 .source
= ANC_STANDBY
,
538 static int wm2000_anc_transition(struct wm2000_priv
*wm2000
,
539 enum wm2000_anc_mode mode
)
541 struct i2c_client
*i2c
= wm2000
->i2c
;
545 if (wm2000
->anc_mode
== mode
)
548 for (i
= 0; i
< ARRAY_SIZE(anc_transitions
); i
++)
549 if (anc_transitions
[i
].source
== wm2000
->anc_mode
&&
550 anc_transitions
[i
].dest
== mode
)
552 if (i
== ARRAY_SIZE(anc_transitions
)) {
553 dev_err(&i2c
->dev
, "No transition for %d->%d\n",
554 wm2000
->anc_mode
, mode
);
558 /* Maintain clock while active */
559 if (anc_transitions
[i
].source
== ANC_OFF
) {
560 ret
= clk_prepare_enable(wm2000
->mclk
);
562 dev_err(&i2c
->dev
, "Failed to enable MCLK: %d\n", ret
);
567 for (j
= 0; j
< ARRAY_SIZE(anc_transitions
[j
].step
); j
++) {
568 if (!anc_transitions
[i
].step
[j
])
570 ret
= anc_transitions
[i
].step
[j
](i2c
,
571 anc_transitions
[i
].analogue
);
576 if (anc_transitions
[i
].dest
== ANC_OFF
)
577 clk_disable_unprepare(wm2000
->mclk
);
582 static int wm2000_anc_set_mode(struct wm2000_priv
*wm2000
)
584 struct i2c_client
*i2c
= wm2000
->i2c
;
585 enum wm2000_anc_mode mode
;
587 if (wm2000
->anc_eng_ena
&& wm2000
->spk_ena
)
588 if (wm2000
->anc_active
)
595 dev_dbg(&i2c
->dev
, "Set mode %d (enabled %d, mute %d, active %d)\n",
596 mode
, wm2000
->anc_eng_ena
, !wm2000
->spk_ena
,
599 return wm2000_anc_transition(wm2000
, mode
);
602 static int wm2000_anc_mode_get(struct snd_kcontrol
*kcontrol
,
603 struct snd_ctl_elem_value
*ucontrol
)
605 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
606 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
608 ucontrol
->value
.enumerated
.item
[0] = wm2000
->anc_active
;
613 static int wm2000_anc_mode_put(struct snd_kcontrol
*kcontrol
,
614 struct snd_ctl_elem_value
*ucontrol
)
616 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
617 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
618 int anc_active
= ucontrol
->value
.enumerated
.item
[0];
624 mutex_lock(&wm2000
->lock
);
626 wm2000
->anc_active
= anc_active
;
628 ret
= wm2000_anc_set_mode(wm2000
);
630 mutex_unlock(&wm2000
->lock
);
635 static int wm2000_speaker_get(struct snd_kcontrol
*kcontrol
,
636 struct snd_ctl_elem_value
*ucontrol
)
638 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
639 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
641 ucontrol
->value
.enumerated
.item
[0] = wm2000
->spk_ena
;
646 static int wm2000_speaker_put(struct snd_kcontrol
*kcontrol
,
647 struct snd_ctl_elem_value
*ucontrol
)
649 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
650 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
651 int val
= ucontrol
->value
.enumerated
.item
[0];
657 mutex_lock(&wm2000
->lock
);
659 wm2000
->spk_ena
= val
;
661 ret
= wm2000_anc_set_mode(wm2000
);
663 mutex_unlock(&wm2000
->lock
);
668 static const struct snd_kcontrol_new wm2000_controls
[] = {
669 SOC_SINGLE("ANC Volume", WM2000_REG_ANC_GAIN_CTRL
, 0, 255, 0),
670 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0,
672 wm2000_anc_mode_put
),
673 SOC_SINGLE_BOOL_EXT("WM2000 Switch", 0,
678 static int wm2000_anc_power_event(struct snd_soc_dapm_widget
*w
,
679 struct snd_kcontrol
*kcontrol
, int event
)
681 struct snd_soc_codec
*codec
= w
->codec
;
682 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
685 mutex_lock(&wm2000
->lock
);
687 if (SND_SOC_DAPM_EVENT_ON(event
))
688 wm2000
->anc_eng_ena
= 1;
690 if (SND_SOC_DAPM_EVENT_OFF(event
))
691 wm2000
->anc_eng_ena
= 0;
693 ret
= wm2000_anc_set_mode(wm2000
);
695 mutex_unlock(&wm2000
->lock
);
700 static const struct snd_soc_dapm_widget wm2000_dapm_widgets
[] = {
701 /* Externally visible pins */
702 SND_SOC_DAPM_OUTPUT("SPKN"),
703 SND_SOC_DAPM_OUTPUT("SPKP"),
705 SND_SOC_DAPM_INPUT("LINN"),
706 SND_SOC_DAPM_INPUT("LINP"),
708 SND_SOC_DAPM_PGA_E("ANC Engine", SND_SOC_NOPM
, 0, 0, NULL
, 0,
709 wm2000_anc_power_event
,
710 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
713 /* Target, Path, Source */
714 static const struct snd_soc_dapm_route wm2000_audio_map
[] = {
715 { "SPKN", NULL
, "ANC Engine" },
716 { "SPKP", NULL
, "ANC Engine" },
717 { "ANC Engine", NULL
, "LINN" },
718 { "ANC Engine", NULL
, "LINP" },
722 static int wm2000_suspend(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 int wm2000_resume(struct snd_soc_codec
*codec
)
731 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
733 return wm2000_anc_set_mode(wm2000
);
736 #define wm2000_suspend NULL
737 #define wm2000_resume NULL
740 static bool wm2000_readable_reg(struct device
*dev
, unsigned int reg
)
743 case WM2000_REG_SYS_START
:
744 case WM2000_REG_ANC_GAIN_CTRL
:
745 case WM2000_REG_MSE_TH1
:
746 case WM2000_REG_MSE_TH2
:
747 case WM2000_REG_SPEECH_CLARITY
:
748 case WM2000_REG_SYS_WATCHDOG
:
749 case WM2000_REG_ANA_VMID_PD_TIME
:
750 case WM2000_REG_ANA_VMID_PU_TIME
:
751 case WM2000_REG_CAT_FLTR_INDX
:
752 case WM2000_REG_CAT_GAIN_0
:
753 case WM2000_REG_SYS_STATUS
:
754 case WM2000_REG_SYS_MODE_CNTRL
:
755 case WM2000_REG_SYS_START0
:
756 case WM2000_REG_SYS_START1
:
759 case WM2000_REG_REVISON
:
760 case WM2000_REG_SYS_CTL1
:
761 case WM2000_REG_SYS_CTL2
:
762 case WM2000_REG_ANC_STAT
:
763 case WM2000_REG_IF_CTL
:
764 case WM2000_REG_ANA_MIC_CTL
:
765 case WM2000_REG_SPK_CTL
:
772 static const struct regmap_config wm2000_regmap
= {
776 .max_register
= WM2000_REG_SPK_CTL
,
777 .readable_reg
= wm2000_readable_reg
,
780 static int wm2000_probe(struct snd_soc_codec
*codec
)
782 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
784 snd_soc_codec_set_cache_io(codec
, 16, 8, SND_SOC_REGMAP
);
786 /* This will trigger a transition to standby mode by default */
787 wm2000_anc_set_mode(wm2000
);
792 static int wm2000_remove(struct snd_soc_codec
*codec
)
794 struct wm2000_priv
*wm2000
= dev_get_drvdata(codec
->dev
);
796 return wm2000_anc_transition(wm2000
, ANC_OFF
);
799 static struct snd_soc_codec_driver soc_codec_dev_wm2000
= {
800 .probe
= wm2000_probe
,
801 .remove
= wm2000_remove
,
802 .suspend
= wm2000_suspend
,
803 .resume
= wm2000_resume
,
805 .dapm_widgets
= wm2000_dapm_widgets
,
806 .num_dapm_widgets
= ARRAY_SIZE(wm2000_dapm_widgets
),
807 .dapm_routes
= wm2000_audio_map
,
808 .num_dapm_routes
= ARRAY_SIZE(wm2000_audio_map
),
809 .controls
= wm2000_controls
,
810 .num_controls
= ARRAY_SIZE(wm2000_controls
),
813 static int wm2000_i2c_probe(struct i2c_client
*i2c
,
814 const struct i2c_device_id
*i2c_id
)
816 struct wm2000_priv
*wm2000
;
817 struct wm2000_platform_data
*pdata
;
818 const char *filename
;
819 const struct firmware
*fw
= NULL
;
824 wm2000
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm2000_priv
),
826 if (wm2000
== NULL
) {
827 dev_err(&i2c
->dev
, "Unable to allocate private data\n");
831 mutex_init(&wm2000
->lock
);
833 dev_set_drvdata(&i2c
->dev
, wm2000
);
835 wm2000
->regmap
= devm_regmap_init_i2c(i2c
, &wm2000_regmap
);
836 if (IS_ERR(wm2000
->regmap
)) {
837 ret
= PTR_ERR(wm2000
->regmap
);
838 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
843 for (i
= 0; i
< WM2000_NUM_SUPPLIES
; i
++)
844 wm2000
->supplies
[i
].supply
= wm2000_supplies
[i
];
846 ret
= devm_regulator_bulk_get(&i2c
->dev
, WM2000_NUM_SUPPLIES
,
849 dev_err(&i2c
->dev
, "Failed to get supplies: %d\n", ret
);
853 ret
= regulator_bulk_enable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
855 dev_err(&i2c
->dev
, "Failed to enable supplies: %d\n", ret
);
859 /* Verify that this is a WM2000 */
860 reg
= wm2000_read(i2c
, WM2000_REG_ID1
);
862 reg
= wm2000_read(i2c
, WM2000_REG_ID2
);
866 dev_err(&i2c
->dev
, "Device is not a WM2000 - ID %x\n", id
);
871 reg
= wm2000_read(i2c
, WM2000_REG_REVISON
);
872 dev_info(&i2c
->dev
, "revision %c\n", reg
+ 'A');
874 wm2000
->mclk
= devm_clk_get(&i2c
->dev
, "MCLK");
875 if (IS_ERR(wm2000
->mclk
)) {
876 ret
= PTR_ERR(wm2000
->mclk
);
877 dev_err(&i2c
->dev
, "Failed to get MCLK: %d\n", ret
);
881 filename
= "wm2000_anc.bin";
882 pdata
= dev_get_platdata(&i2c
->dev
);
884 wm2000
->speech_clarity
= !pdata
->speech_enh_disable
;
886 if (pdata
->download_file
)
887 filename
= pdata
->download_file
;
890 ret
= request_firmware(&fw
, filename
, &i2c
->dev
);
892 dev_err(&i2c
->dev
, "Failed to acquire ANC data: %d\n", ret
);
896 /* Pre-cook the concatenation of the register address onto the image */
897 wm2000
->anc_download_size
= fw
->size
+ 2;
898 wm2000
->anc_download
= devm_kzalloc(&i2c
->dev
,
899 wm2000
->anc_download_size
,
901 if (wm2000
->anc_download
== NULL
) {
902 dev_err(&i2c
->dev
, "Out of memory\n");
907 wm2000
->anc_download
[0] = 0x80;
908 wm2000
->anc_download
[1] = 0x00;
909 memcpy(wm2000
->anc_download
+ 2, fw
->data
, fw
->size
);
911 wm2000
->anc_eng_ena
= 1;
912 wm2000
->anc_active
= 1;
916 wm2000_reset(wm2000
);
918 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_wm2000
, NULL
, 0);
921 regulator_bulk_disable(WM2000_NUM_SUPPLIES
, wm2000
->supplies
);
924 release_firmware(fw
);
928 static int wm2000_i2c_remove(struct i2c_client
*i2c
)
930 snd_soc_unregister_codec(&i2c
->dev
);
935 static const struct i2c_device_id wm2000_i2c_id
[] = {
939 MODULE_DEVICE_TABLE(i2c
, wm2000_i2c_id
);
941 static struct i2c_driver wm2000_i2c_driver
= {
944 .owner
= THIS_MODULE
,
946 .probe
= wm2000_i2c_probe
,
947 .remove
= wm2000_i2c_remove
,
948 .id_table
= wm2000_i2c_id
,
951 module_i2c_driver(wm2000_i2c_driver
);
953 MODULE_DESCRIPTION("ASoC WM2000 driver");
954 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>");
955 MODULE_LICENSE("GPL");