aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2006-10-06 12:37:32 -0400
committerJaroslav Kysela <perex@suse.cz>2007-02-09 03:00:23 -0500
commit10c5cf30446fe91b7173436b75c4f00dfb4cd9f8 (patch)
treeca3dcc7fc72a1a635bf6f786dc5c5c005cfc7bbb /sound/soc/codecs
parentabadfc928a27e1cf27c834e8e29e6b1f64ca2d55 (diff)
[ALSA] ASoC codecs: WM9712 support
This patch adds ASoC support for the WM9712 codec. Supported features:- o Capture/Playback/Sidetone/Bypass. o Aux DAC. o 8k - 48k sample rates. o DAPM. Signed-off-by: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Liam Girdwood <liam.girdwood@wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/wm9712.c778
-rw-r--r--sound/soc/codecs/wm9712.h14
2 files changed, 792 insertions, 0 deletions
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
new file mode 100644
index 000000000000..4850550e2e31
--- /dev/null
+++ b/sound/soc/codecs/wm9712.c
@@ -0,0 +1,778 @@
1/*
2 * wm9712.c -- ALSA Soc WM9712 codec support
3 *
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * Revision history
14 * 4th Feb 2006 Initial version.
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/version.h>
20#include <linux/kernel.h>
21#include <linux/device.h>
22#include <sound/driver.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/ac97_codec.h>
26#include <sound/initval.h>
27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29
30#define WM9712_VERSION "0.4"
31
32static unsigned int ac97_read(struct snd_soc_codec *codec,
33 unsigned int reg);
34static int ac97_write(struct snd_soc_codec *codec,
35 unsigned int reg, unsigned int val);
36
37#define AC97_DIR \
38 (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
39
40#define AC97_RATES \
41 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
42 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
43 SNDRV_PCM_RATE_48000)
44
45/* may need to expand this */
46static struct snd_soc_dai_mode ac97_modes[] = {
47 {0, 0, SNDRV_PCM_FMTBIT_S16_LE, AC97_RATES},
48 {0, 0, SNDRV_PCM_FMTBIT_S18_3LE, AC97_RATES},
49};
50
51/*
52 * WM9712 register cache
53 */
54static const u16 wm9712_reg[] = {
55 0x6174, 0x8000, 0x8000, 0x8000, // 6
56 0xf0f0, 0xaaa0, 0xc008, 0x6808, // e
57 0xe808, 0xaaa0, 0xad00, 0x8000, // 16
58 0xe808, 0x3000, 0x8000, 0x0000, // 1e
59 0x0000, 0x0000, 0x0000, 0x000f, // 26
60 0x0405, 0x0410, 0xbb80, 0xbb80, // 2e
61 0x0000, 0xbb80, 0x0000, 0x0000, // 36
62 0x0000, 0x2000, 0x0000, 0x0000, // 3e
63 0x0000, 0x0000, 0x0000, 0x0000, // 46
64 0x0000, 0x0000, 0xf83e, 0xffff, // 4e
65 0x0000, 0x0000, 0x0000, 0xf83e, // 56
66 0x0008, 0x0000, 0x0000, 0x0000, // 5e
67 0xb032, 0x3e00, 0x0000, 0x0000, // 66
68 0x0000, 0x0000, 0x0000, 0x0000, // 6e
69 0x0000, 0x0000, 0x0000, 0x0006, // 76
70 0x0001, 0x0000, 0x574d, 0x4c12, // 7e
71 0x0000, 0x0000 // virtual hp mixers
72};
73
74/* virtual HP mixers regs */
75#define HPL_MIXER 0x80
76#define HPR_MIXER 0x82
77
78static const char *wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"};
79static const char *wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"};
80static const char *wm9712_out3_src[] = {"Left", "VREF", "Left + Right",
81 "Mono"};
82static const char *wm9712_spk_src[] = {"Speaker Mix", "Headphone Mix"};
83static const char *wm9712_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
84static const char *wm9712_base[] = {"Linear Control", "Adaptive Boost"};
85static const char *wm9712_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
86static const char *wm9712_mic[] = {"Mic 1", "Differential", "Mic 2",
87 "Stereo"};
88static const char *wm9712_rec_sel[] = {"Mic", "NC", "NC", "Speaker Mixer",
89 "Line", "Headphone Mixer", "Phone Mixer", "Phone"};
90static const char *wm9712_ng_type[] = {"Constant Gain", "Mute"};
91static const char *wm9712_diff_sel[] = {"Mic", "Line"};
92
93static const struct soc_enum wm9712_enum[] = {
94SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9712_alc_select),
95SOC_ENUM_SINGLE(AC97_VIDEO, 12, 4, wm9712_alc_mux),
96SOC_ENUM_SINGLE(AC97_AUX, 9, 4, wm9712_out3_src),
97SOC_ENUM_SINGLE(AC97_AUX, 8, 2, wm9712_spk_src),
98SOC_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9712_rec_adc),
99SOC_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9712_base),
100SOC_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9712_rec_gain),
101SOC_ENUM_SINGLE(AC97_MIC, 5, 4, wm9712_mic),
102SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9712_rec_sel),
103SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9712_rec_sel),
104SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9712_ng_type),
105SOC_ENUM_SINGLE(0x5c, 8, 2, wm9712_diff_sel),
106};
107
108static const struct snd_kcontrol_new wm9712_snd_ac97_controls[] = {
109SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
110SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1),
111SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
112SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE,15, 1, 1),
113
114SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0),
115SOC_SINGLE("Speaker Playback Invert Switch", AC97_MASTER, 6, 1, 0),
116SOC_SINGLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 7, 1, 0),
117SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
118SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 0),
119
120SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
121SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
122SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
123SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
124SOC_ENUM("ALC Function", wm9712_enum[0]),
125SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
126SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
127SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
128SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
129SOC_ENUM("ALC NG Type", wm9712_enum[10]),
130SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
131
132SOC_SINGLE("Mic Headphone Volume", AC97_VIDEO, 12, 7, 1),
133SOC_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
134
135SOC_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
136SOC_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
137SOC_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
138
139SOC_SINGLE("PCBeep Bypass Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
140SOC_SINGLE("PCBeep Bypass Speaker Volume", AC97_PC_BEEP, 8, 7, 1),
141SOC_SINGLE("PCBeep Bypass Phone Volume", AC97_PC_BEEP, 4, 7, 1),
142
143SOC_SINGLE("Aux Playback Headphone Volume", AC97_CD, 12, 7, 1),
144SOC_SINGLE("Aux Playback Speaker Volume", AC97_CD, 8, 7, 1),
145SOC_SINGLE("Aux Playback Phone Volume", AC97_CD, 4, 7, 1),
146
147SOC_SINGLE("Phone Volume", AC97_PHONE, 0, 15, 0),
148SOC_DOUBLE("Line Capture Volume", AC97_LINE, 8, 0, 31, 1),
149
150SOC_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
151SOC_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
152
153SOC_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
154SOC_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
155SOC_SINGLE("3D Playback Volume", AC97_3D_CONTROL, 0, 15, 0),
156
157SOC_ENUM("Bass Control", wm9712_enum[5]),
158SOC_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
159SOC_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
160SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
161SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 0),
162SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 0),
163
164SOC_SINGLE("Capture ADC Switch", AC97_REC_GAIN, 15, 1, 1),
165SOC_ENUM("Capture Volume Steps", wm9712_enum[6]),
166SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
167SOC_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
168
169SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
170SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
171SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
172};
173
174/* add non dapm controls */
175static int wm9712_add_controls(struct snd_soc_codec *codec)
176{
177 int err, i;
178
179 for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) {
180 err = snd_ctl_add(codec->card,
181 snd_soc_cnew(&wm9712_snd_ac97_controls[i],codec, NULL));
182 if (err < 0)
183 return err;
184 }
185 return 0;
186}
187
188/* We have to create a fake left and right HP mixers because
189 * the codec only has a single control that is shared by both channels.
190 * This makes it impossible to determine the audio path.
191 */
192static int mixer_event (struct snd_soc_dapm_widget *w, int event)
193{
194 u16 l, r, beep, line, phone, mic, pcm, aux;
195
196 l = ac97_read(w->codec, HPL_MIXER);
197 r = ac97_read(w->codec, HPR_MIXER);
198 beep = ac97_read(w->codec, AC97_PC_BEEP);
199 mic = ac97_read(w->codec, AC97_VIDEO);
200 phone = ac97_read(w->codec, AC97_PHONE);
201 line = ac97_read(w->codec, AC97_LINE);
202 pcm = ac97_read(w->codec, AC97_PCM);
203 aux = ac97_read(w->codec, AC97_CD);
204
205 if (l & 0x1 || r & 0x1)
206 ac97_write(w->codec, AC97_VIDEO, mic & 0x7fff);
207 else
208 ac97_write(w->codec, AC97_VIDEO, mic | 0x8000);
209
210 if (l & 0x2 || r & 0x2)
211 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
212 else
213 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
214
215 if (l & 0x4 || r & 0x4)
216 ac97_write(w->codec, AC97_LINE, line & 0x7fff);
217 else
218 ac97_write(w->codec, AC97_LINE, line | 0x8000);
219
220 if (l & 0x8 || r & 0x8)
221 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff);
222 else
223 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
224
225 if (l & 0x10 || r & 0x10)
226 ac97_write(w->codec, AC97_CD, aux & 0x7fff);
227 else
228 ac97_write(w->codec, AC97_CD, aux | 0x8000);
229
230 if (l & 0x20 || r & 0x20)
231 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff);
232 else
233 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
234
235 return 0;
236}
237
238/* Left Headphone Mixers */
239static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = {
240 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPL_MIXER, 5, 1, 0),
241 SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 4, 1, 0),
242 SOC_DAPM_SINGLE("Phone Bypass Switch", HPL_MIXER, 3, 1, 0),
243 SOC_DAPM_SINGLE("Line Bypass Switch", HPL_MIXER, 2, 1, 0),
244 SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 1, 1, 0),
245 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPL_MIXER, 0, 1, 0),
246};
247
248/* Right Headphone Mixers */
249static const struct snd_kcontrol_new wm9712_hpr_mixer_controls[] = {
250 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPR_MIXER, 5, 1, 0),
251 SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 4, 1, 0),
252 SOC_DAPM_SINGLE("Phone Bypass Switch", HPR_MIXER, 3, 1, 0),
253 SOC_DAPM_SINGLE("Line Bypass Switch", HPR_MIXER, 2, 1, 0),
254 SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 1, 1, 0),
255 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPR_MIXER, 0, 1, 0),
256};
257
258/* Speaker Mixer */
259static const struct snd_kcontrol_new wm9712_speaker_mixer_controls[] = {
260 SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 11, 1, 1),
261 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 11, 1, 1),
262 SOC_DAPM_SINGLE("Phone Bypass Switch", AC97_PHONE, 14, 1, 1),
263 SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 14, 1, 1),
264 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 14, 1, 1),
265};
266
267/* Phone Mixer */
268static const struct snd_kcontrol_new wm9712_phone_mixer_controls[] = {
269 SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 7, 1, 1),
270 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 7, 1, 1),
271 SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 13, 1, 1),
272 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 13, 1, 1),
273 SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_MIC, 14, 1, 1),
274 SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_MIC, 13, 1, 1),
275};
276
277/* ALC headphone mux */
278static const struct snd_kcontrol_new wm9712_alc_mux_controls =
279SOC_DAPM_ENUM("Route", wm9712_enum[1]);
280
281/* out 3 mux */
282static const struct snd_kcontrol_new wm9712_out3_mux_controls =
283SOC_DAPM_ENUM("Route", wm9712_enum[2]);
284
285/* spk mux */
286static const struct snd_kcontrol_new wm9712_spk_mux_controls =
287SOC_DAPM_ENUM("Route", wm9712_enum[3]);
288
289/* Capture to Phone mux */
290static const struct snd_kcontrol_new wm9712_capture_phone_mux_controls =
291SOC_DAPM_ENUM("Route", wm9712_enum[4]);
292
293/* Capture left select */
294static const struct snd_kcontrol_new wm9712_capture_selectl_controls =
295SOC_DAPM_ENUM("Route", wm9712_enum[8]);
296
297/* Capture right select */
298static const struct snd_kcontrol_new wm9712_capture_selectr_controls =
299SOC_DAPM_ENUM("Route", wm9712_enum[9]);
300
301/* Mic select */
302static const struct snd_kcontrol_new wm9712_mic_src_controls =
303SOC_DAPM_ENUM("Route", wm9712_enum[7]);
304
305/* diff select */
306static const struct snd_kcontrol_new wm9712_diff_sel_controls =
307SOC_DAPM_ENUM("Route", wm9712_enum[11]);
308
309static const struct snd_soc_dapm_widget wm9712_dapm_widgets[] = {
310SND_SOC_DAPM_MUX("ALC Sidetone Mux", SND_SOC_NOPM, 0, 0,
311 &wm9712_alc_mux_controls),
312SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM, 0, 0,
313 &wm9712_out3_mux_controls),
314SND_SOC_DAPM_MUX("Speaker Mux", SND_SOC_NOPM, 0, 0,
315 &wm9712_spk_mux_controls),
316SND_SOC_DAPM_MUX("Capture Phone Mux", SND_SOC_NOPM, 0, 0,
317 &wm9712_capture_phone_mux_controls),
318SND_SOC_DAPM_MUX("Left Capture Select", SND_SOC_NOPM, 0, 0,
319 &wm9712_capture_selectl_controls),
320SND_SOC_DAPM_MUX("Right Capture Select", SND_SOC_NOPM, 0, 0,
321 &wm9712_capture_selectr_controls),
322SND_SOC_DAPM_MUX("Mic Select Source", SND_SOC_NOPM, 0, 0,
323 &wm9712_mic_src_controls),
324SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0,
325 &wm9712_diff_sel_controls),
326SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
327SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_INT_PAGING, 9, 1,
328 &wm9712_hpl_mixer_controls[0], ARRAY_SIZE(wm9712_hpl_mixer_controls),
329 mixer_event, SND_SOC_DAPM_POST_REG),
330SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_INT_PAGING, 8, 1,
331 &wm9712_hpr_mixer_controls[0], ARRAY_SIZE(wm9712_hpr_mixer_controls),
332 mixer_event, SND_SOC_DAPM_POST_REG),
333SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1,
334 &wm9712_phone_mixer_controls[0], ARRAY_SIZE(wm9712_phone_mixer_controls)),
335SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1,
336 &wm9712_speaker_mixer_controls[0],
337 ARRAY_SIZE(wm9712_speaker_mixer_controls)),
338SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
339SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_INT_PAGING, 14, 1),
340SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_INT_PAGING, 13, 1),
341SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", SND_SOC_NOPM, 0, 0),
342SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_INT_PAGING, 12, 1),
343SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_INT_PAGING, 11, 1),
344SND_SOC_DAPM_PGA("Headphone PGA", AC97_INT_PAGING, 4, 1, NULL, 0),
345SND_SOC_DAPM_PGA("Speaker PGA", AC97_INT_PAGING, 3, 1, NULL, 0),
346SND_SOC_DAPM_PGA("Out 3 PGA", AC97_INT_PAGING, 5, 1, NULL, 0),
347SND_SOC_DAPM_PGA("Line PGA", AC97_INT_PAGING, 2, 1, NULL, 0),
348SND_SOC_DAPM_PGA("Phone PGA", AC97_INT_PAGING, 1, 1, NULL, 0),
349SND_SOC_DAPM_PGA("Mic PGA", AC97_INT_PAGING, 0, 1, NULL, 0),
350SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_INT_PAGING, 10, 1),
351SND_SOC_DAPM_OUTPUT("MONOOUT"),
352SND_SOC_DAPM_OUTPUT("HPOUTL"),
353SND_SOC_DAPM_OUTPUT("HPOUTR"),
354SND_SOC_DAPM_OUTPUT("LOUT2"),
355SND_SOC_DAPM_OUTPUT("ROUT2"),
356SND_SOC_DAPM_OUTPUT("OUT3"),
357SND_SOC_DAPM_INPUT("LINEINL"),
358SND_SOC_DAPM_INPUT("LINEINR"),
359SND_SOC_DAPM_INPUT("PHONE"),
360SND_SOC_DAPM_INPUT("PCBEEP"),
361SND_SOC_DAPM_INPUT("MIC1"),
362SND_SOC_DAPM_INPUT("MIC2"),
363};
364
365static const char *audio_map[][3] = {
366 /* virtual mixer - mixes left & right channels for spk and mono */
367 {"AC97 Mixer", NULL, "Left DAC"},
368 {"AC97 Mixer", NULL, "Right DAC"},
369
370 /* Left HP mixer */
371 {"Left HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
372 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
373 {"Left HP Mixer", "Phone Bypass Switch", "Phone PGA"},
374 {"Left HP Mixer", "Line Bypass Switch", "Line PGA"},
375 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
376 {"Left HP Mixer", "Mic Sidetone Switch", "Mic PGA"},
377 {"Left HP Mixer", NULL, "ALC Sidetone Mux"},
378 //{"Right HP Mixer", NULL, "HP Mixer"},
379
380 /* Right HP mixer */
381 {"Right HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
382 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
383 {"Right HP Mixer", "Phone Bypass Switch", "Phone PGA"},
384 {"Right HP Mixer", "Line Bypass Switch", "Line PGA"},
385 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
386 {"Right HP Mixer", "Mic Sidetone Switch", "Mic PGA"},
387 {"Right HP Mixer", NULL, "ALC Sidetone Mux"},
388
389 /* speaker mixer */
390 {"Speaker Mixer", "PCBeep Bypass Switch", "PCBEEP"},
391 {"Speaker Mixer", "Line Bypass Switch", "Line PGA"},
392 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
393 {"Speaker Mixer", "Phone Bypass Switch", "Phone PGA"},
394 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
395
396 /* Phone mixer */
397 {"Phone Mixer", "PCBeep Bypass Switch", "PCBEEP"},
398 {"Phone Mixer", "Line Bypass Switch", "Line PGA"},
399 {"Phone Mixer", "Aux Playback Switch", "Aux DAC"},
400 {"Phone Mixer", "PCM Playback Switch", "AC97 Mixer"},
401 {"Phone Mixer", "Mic 1 Sidetone Switch", "Mic PGA"},
402 {"Phone Mixer", "Mic 2 Sidetone Switch", "Mic PGA"},
403
404 /* inputs */
405 {"Line PGA", NULL, "LINEINL"},
406 {"Line PGA", NULL, "LINEINR"},
407 {"Phone PGA", NULL, "PHONE"},
408 {"Mic PGA", NULL, "MIC1"},
409 {"Mic PGA", NULL, "MIC2"},
410
411 /* left capture selector */
412 {"Left Capture Select", "Mic", "MIC1"},
413 {"Left Capture Select", "Speaker Mixer", "Speaker Mixer"},
414 {"Left Capture Select", "Line", "LINEINL"},
415 {"Left Capture Select", "Headphone Mixer", "Left HP Mixer"},
416 {"Left Capture Select", "Phone Mixer", "Phone Mixer"},
417 {"Left Capture Select", "Phone", "PHONE"},
418
419 /* right capture selector */
420 {"Right Capture Select", "Mic", "MIC2"},
421 {"Right Capture Select", "Speaker Mixer", "Speaker Mixer"},
422 {"Right Capture Select", "Line", "LINEINR"},
423 {"Right Capture Select", "Headphone Mixer", "Right HP Mixer"},
424 {"Right Capture Select", "Phone Mixer", "Phone Mixer"},
425 {"Right Capture Select", "Phone", "PHONE"},
426
427 /* ALC Sidetone */
428 {"ALC Sidetone Mux", "Stereo", "Left Capture Select"},
429 {"ALC Sidetone Mux", "Stereo", "Right Capture Select"},
430 {"ALC Sidetone Mux", "Left", "Left Capture Select"},
431 {"ALC Sidetone Mux", "Right", "Right Capture Select"},
432
433 /* ADC's */
434 {"Left ADC", NULL, "Left Capture Select"},
435 {"Right ADC", NULL, "Right Capture Select"},
436
437 /* outputs */
438 {"MONOOUT", NULL, "Phone Mixer"},
439 {"HPOUTL", NULL, "Headphone PGA"},
440 {"Headphone PGA", NULL, "Left HP Mixer"},
441 {"HPOUTR", NULL, "Headphone PGA"},
442 {"Headphone PGA", NULL, "Right HP Mixer"},
443
444 /* mono hp mixer */
445 {"Mono HP Mixer", NULL, "Left HP Mixer"},
446 {"Mono HP Mixer", NULL, "Right HP Mixer"},
447
448 /* Out3 Mux */
449 {"Out3 Mux", "Left", "Left HP Mixer"},
450 {"Out3 Mux", "Mono", "Phone Mixer"},
451 {"Out3 Mux", "Left + Right", "Mono HP Mixer"},
452 {"Out 3 PGA", NULL, "Out3 Mux"},
453 {"OUT3", NULL, "Out 3 PGA"},
454
455 /* speaker Mux */
456 {"Speaker Mux", "Speaker Mix", "Speaker Mixer"},
457 {"Speaker Mux", "Headphone Mix", "Mono HP Mixer"},
458 {"Speaker PGA", NULL, "Speaker Mux"},
459 {"LOUT2", NULL, "Speaker PGA"},
460 {"ROUT2", NULL, "Speaker PGA"},
461
462 {NULL, NULL, NULL},
463};
464
465static int wm9712_add_widgets(struct snd_soc_codec *codec)
466{
467 int i;
468
469 for(i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++) {
470 snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]);
471 }
472
473 /* set up audio path audio_mapnects */
474 for(i = 0; audio_map[i][0] != NULL; i++) {
475 snd_soc_dapm_connect_input(codec, audio_map[i][0],
476 audio_map[i][1], audio_map[i][2]);
477 }
478
479 snd_soc_dapm_new_widgets(codec);
480 return 0;
481}
482
483static unsigned int ac97_read(struct snd_soc_codec *codec,
484 unsigned int reg)
485{
486 u16 *cache = codec->reg_cache;
487
488 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
489 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
490 reg == AC97_REC_GAIN)
491 return soc_ac97_ops.read(codec->ac97, reg);
492 else {
493 reg = reg >> 1;
494
495 if (reg > (ARRAY_SIZE(wm9712_reg)))
496 return -EIO;
497
498 return cache[reg];
499 }
500}
501
502static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
503 unsigned int val)
504{
505 u16 *cache = codec->reg_cache;
506
507 soc_ac97_ops.write(codec->ac97, reg, val);
508 reg = reg >> 1;
509 if (reg <= (ARRAY_SIZE(wm9712_reg)))
510 cache[reg] = val;
511
512 return 0;
513}
514
515static int ac97_prepare(struct snd_pcm_substream *substream)
516{
517 struct snd_pcm_runtime *runtime = substream->runtime;
518 struct snd_soc_pcm_runtime *rtd = substream->private_data;
519 struct snd_soc_device *socdev = rtd->socdev;
520 struct snd_soc_codec *codec = socdev->codec;
521 int reg;
522 u16 vra;
523
524 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
525 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
526
527 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
528 reg = AC97_PCM_FRONT_DAC_RATE;
529 else
530 reg = AC97_PCM_LR_ADC_RATE;
531
532 return ac97_write(codec, reg, runtime->rate);
533}
534
535static int ac97_aux_prepare(struct snd_pcm_substream *substream)
536{
537 struct snd_pcm_runtime *runtime = substream->runtime;
538 struct snd_soc_pcm_runtime *rtd = substream->private_data;
539 struct snd_soc_device *socdev = rtd->socdev;
540 struct snd_soc_codec *codec = socdev->codec;
541 u16 vra, xsle;
542
543 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
544 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
545 xsle = ac97_read(codec, AC97_PCI_SID);
546 ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
547
548 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
549 return -ENODEV;
550
551 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
552}
553
554struct snd_soc_codec_dai wm9712_dai[] = {
555{
556 .name = "AC97 HiFi",
557 .playback = {
558 .stream_name = "HiFi Playback",
559 .channels_min = 1,
560 .channels_max = 2,},
561 .capture = {
562 .stream_name = "HiFi Capture",
563 .channels_min = 1,
564 .channels_max = 2,},
565 .ops = {
566 .prepare = ac97_prepare,},
567 .caps = {
568 .num_modes = ARRAY_SIZE(ac97_modes),
569 .mode = ac97_modes,},
570 },
571 {
572 .name = "AC97 Aux",
573 .playback = {
574 .stream_name = "Aux Playback",
575 .channels_min = 1,
576 .channels_max = 1,},
577 .ops = {
578 .prepare = ac97_aux_prepare,},
579 .caps = {
580 .num_modes = ARRAY_SIZE(ac97_modes),
581 .mode = ac97_modes,},
582 },
583};
584EXPORT_SYMBOL_GPL(wm9712_dai);
585
586static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
587{
588 u16 reg;
589
590 switch (event) {
591 case SNDRV_CTL_POWER_D0: /* full On */
592 /* liam - maybe enable thermal shutdown */
593 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
594 ac97_write(codec, AC97_EXTENDED_MID, reg);
595 break;
596 case SNDRV_CTL_POWER_D1: /* partial On */
597 case SNDRV_CTL_POWER_D2: /* partial On */
598 break;
599 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
600 /* enable master bias and vmid */
601 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
602 ac97_write(codec, AC97_EXTENDED_MID, reg);
603 ac97_write(codec, AC97_POWERDOWN, 0x0000);
604 break;
605 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
606 /* disable everything including AC link */
607 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
608 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
609 ac97_write(codec, AC97_POWERDOWN, 0xffff);
610 break;
611 }
612 codec->dapm_state = event;
613 return 0;
614}
615
616static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
617{
618 if (try_warm && soc_ac97_ops.warm_reset) {
619 soc_ac97_ops.warm_reset(codec->ac97);
620 if (!(ac97_read(codec, 0) & 0x8000))
621 return 1;
622 }
623
624 soc_ac97_ops.reset(codec->ac97);
625 if (ac97_read(codec, 0) & 0x8000)
626 goto err;
627 return 0;
628
629err:
630 printk(KERN_ERR "WM9712 AC97 reset failed\n");
631 return -EIO;
632}
633
634static int wm9712_soc_suspend(struct platform_device *pdev,
635 pm_message_t state)
636{
637 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
638 struct snd_soc_codec *codec = socdev->codec;
639
640 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
641 return 0;
642}
643
644static int wm9712_soc_resume(struct platform_device *pdev)
645{
646 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
647 struct snd_soc_codec *codec = socdev->codec;
648 int i, ret;
649 u16 *cache = codec->reg_cache;
650
651 ret = wm9712_reset(codec, 1);
652 if (ret < 0){
653 printk(KERN_ERR "could not reset AC97 codec\n");
654 return ret;
655 }
656
657 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
658
659 if (ret == 0) {
660 /* Sync reg_cache with the hardware after cold reset */
661 for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i+=2) {
662 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN ||
663 (i > 0x58 && i != 0x5c))
664 continue;
665 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
666 }
667 }
668
669 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
670 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D0);
671
672 return ret;
673}
674
675static int wm9712_soc_probe(struct platform_device *pdev)
676{
677 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
678 struct snd_soc_codec *codec;
679 int ret = 0;
680
681 printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION);
682
683 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
684 if (socdev->codec == NULL)
685 return -ENOMEM;
686 codec = socdev->codec;
687 mutex_init(&codec->mutex);
688
689 codec->reg_cache =
690 kzalloc(sizeof(u16) * ARRAY_SIZE(wm9712_reg), GFP_KERNEL);
691 if (codec->reg_cache == NULL) {
692 kfree(codec->ac97);
693 kfree(socdev->codec);
694 socdev->codec = NULL;
695 return -ENOMEM;
696 }
697 memcpy(codec->reg_cache, wm9712_reg, sizeof(u16) * ARRAY_SIZE(wm9712_reg));
698 codec->reg_cache_size = sizeof(u16) * ARRAY_SIZE(wm9712_reg);
699 codec->reg_cache_step = 2;
700
701 codec->name = "WM9712";
702 codec->owner = THIS_MODULE;
703 codec->dai = wm9712_dai;
704 codec->num_dai = ARRAY_SIZE(wm9712_dai);
705 codec->write = ac97_write;
706 codec->read = ac97_read;
707 codec->dapm_event = wm9712_dapm_event;
708 INIT_LIST_HEAD(&codec->dapm_widgets);
709 INIT_LIST_HEAD(&codec->dapm_paths);
710
711 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
712 if (ret < 0)
713 goto err;
714
715 /* register pcms */
716 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
717 if (ret < 0)
718 goto pcm_err;
719
720 ret = wm9712_reset(codec, 0);
721 if (ret < 0) {
722 printk(KERN_ERR "AC97 link error\n");
723 goto reset_err;
724 }
725
726 /* set alc mux to none */
727 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
728
729 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
730 wm9712_add_controls(codec);
731 wm9712_add_widgets(codec);
732 ret = snd_soc_register_card(socdev);
733 if (ret < 0)
734 goto reset_err;
735
736 return 0;
737
738reset_err:
739 snd_soc_free_pcms(socdev);
740
741pcm_err:
742 snd_soc_free_ac97_codec(codec);
743
744err:
745 kfree(socdev->codec->reg_cache);
746 kfree(socdev->codec);
747 socdev->codec = NULL;
748 return ret;
749}
750
751static int wm9712_soc_remove(struct platform_device *pdev)
752{
753 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
754 struct snd_soc_codec *codec = socdev->codec;
755
756 if (codec == NULL)
757 return 0;
758
759 snd_soc_dapm_free(socdev);
760 snd_soc_free_pcms(socdev);
761 snd_soc_free_ac97_codec(codec);
762 kfree(codec->reg_cache);
763 kfree(codec);
764 return 0;
765}
766
767struct snd_soc_codec_device soc_codec_dev_wm9712 = {
768 .probe = wm9712_soc_probe,
769 .remove = wm9712_soc_remove,
770 .suspend = wm9712_soc_suspend,
771 .resume = wm9712_soc_resume,
772};
773
774EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
775
776MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver");
777MODULE_AUTHOR("Liam Girdwood");
778MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm9712.h b/sound/soc/codecs/wm9712.h
new file mode 100644
index 000000000000..719105d61e65
--- /dev/null
+++ b/sound/soc/codecs/wm9712.h
@@ -0,0 +1,14 @@
1/*
2 * wm9712.h -- WM9712 Soc Audio driver
3 */
4
5#ifndef _WM9712_H
6#define _WM9712_H
7
8#define WM9712_DAI_AC97_HIFI 0
9#define WM9712_DAI_AC97_AUX 1
10
11extern struct snd_soc_codec_dai wm9712_dai[2];
12extern struct snd_soc_codec_device soc_codec_dev_wm9712;
13
14#endif