2 * wm9712.c -- ALSA Soc WM9712 codec support
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
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.
14 * 4th Feb 2006 Initial version.
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>
30 #define WM9712_VERSION "0.4"
32 static unsigned int ac97_read(struct snd_soc_codec *codec,
34 static int ac97_write(struct snd_soc_codec *codec,
35 unsigned int reg, unsigned int val);
38 (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
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 | \
45 /* may need to expand this */
46 static struct snd_soc_dai_mode ac97_modes[] = {
48 .pcmfmt = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S18_3LE,
49 .pcmrate = AC97_RATES,
55 * WM9712 register cache
57 static const u16 wm9712_reg[] = {
58 0x6174, 0x8000, 0x8000, 0x8000, // 6
59 0xf0f0, 0xaaa0, 0xc008, 0x6808, // e
60 0xe808, 0xaaa0, 0xad00, 0x8000, // 16
61 0xe808, 0x3000, 0x8000, 0x0000, // 1e
62 0x0000, 0x0000, 0x0000, 0x000f, // 26
63 0x0405, 0x0410, 0xbb80, 0xbb80, // 2e
64 0x0000, 0xbb80, 0x0000, 0x0000, // 36
65 0x0000, 0x2000, 0x0000, 0x0000, // 3e
66 0x0000, 0x0000, 0x0000, 0x0000, // 46
67 0x0000, 0x0000, 0xf83e, 0xffff, // 4e
68 0x0000, 0x0000, 0x0000, 0xf83e, // 56
69 0x0008, 0x0000, 0x0000, 0x0000, // 5e
70 0xb032, 0x3e00, 0x0000, 0x0000, // 66
71 0x0000, 0x0000, 0x0000, 0x0000, // 6e
72 0x0000, 0x0000, 0x0000, 0x0006, // 76
73 0x0001, 0x0000, 0x574d, 0x4c12, // 7e
74 0x0000, 0x0000 // virtual hp mixers
77 /* virtual HP mixers regs */
78 #define HPL_MIXER 0x80
79 #define HPR_MIXER 0x82
81 static const char *wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"};
82 static const char *wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"};
83 static const char *wm9712_out3_src[] = {"Left", "VREF", "Left + Right",
85 static const char *wm9712_spk_src[] = {"Speaker Mix", "Headphone Mix"};
86 static const char *wm9712_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
87 static const char *wm9712_base[] = {"Linear Control", "Adaptive Boost"};
88 static const char *wm9712_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
89 static const char *wm9712_mic[] = {"Mic 1", "Differential", "Mic 2",
91 static const char *wm9712_rec_sel[] = {"Mic", "NC", "NC", "Speaker Mixer",
92 "Line", "Headphone Mixer", "Phone Mixer", "Phone"};
93 static const char *wm9712_ng_type[] = {"Constant Gain", "Mute"};
94 static const char *wm9712_diff_sel[] = {"Mic", "Line"};
96 static const struct soc_enum wm9712_enum[] = {
97 SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9712_alc_select),
98 SOC_ENUM_SINGLE(AC97_VIDEO, 12, 4, wm9712_alc_mux),
99 SOC_ENUM_SINGLE(AC97_AUX, 9, 4, wm9712_out3_src),
100 SOC_ENUM_SINGLE(AC97_AUX, 8, 2, wm9712_spk_src),
101 SOC_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9712_rec_adc),
102 SOC_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9712_base),
103 SOC_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9712_rec_gain),
104 SOC_ENUM_SINGLE(AC97_MIC, 5, 4, wm9712_mic),
105 SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9712_rec_sel),
106 SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9712_rec_sel),
107 SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9712_ng_type),
108 SOC_ENUM_SINGLE(0x5c, 8, 2, wm9712_diff_sel),
111 static const struct snd_kcontrol_new wm9712_snd_ac97_controls[] = {
112 SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
113 SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1),
114 SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
115 SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE,15, 1, 1),
117 SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0),
118 SOC_SINGLE("Speaker Playback Invert Switch", AC97_MASTER, 6, 1, 0),
119 SOC_SINGLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 7, 1, 0),
120 SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
121 SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 0),
123 SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
124 SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
125 SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
126 SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
127 SOC_ENUM("ALC Function", wm9712_enum[0]),
128 SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
129 SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
130 SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
131 SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
132 SOC_ENUM("ALC NG Type", wm9712_enum[10]),
133 SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
135 SOC_SINGLE("Mic Headphone Volume", AC97_VIDEO, 12, 7, 1),
136 SOC_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
138 SOC_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
139 SOC_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
140 SOC_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
142 SOC_SINGLE("PCBeep Bypass Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
143 SOC_SINGLE("PCBeep Bypass Speaker Volume", AC97_PC_BEEP, 8, 7, 1),
144 SOC_SINGLE("PCBeep Bypass Phone Volume", AC97_PC_BEEP, 4, 7, 1),
146 SOC_SINGLE("Aux Playback Headphone Volume", AC97_CD, 12, 7, 1),
147 SOC_SINGLE("Aux Playback Speaker Volume", AC97_CD, 8, 7, 1),
148 SOC_SINGLE("Aux Playback Phone Volume", AC97_CD, 4, 7, 1),
150 SOC_SINGLE("Phone Volume", AC97_PHONE, 0, 15, 0),
151 SOC_DOUBLE("Line Capture Volume", AC97_LINE, 8, 0, 31, 1),
153 SOC_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
154 SOC_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
156 SOC_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
157 SOC_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
158 SOC_SINGLE("3D Playback Volume", AC97_3D_CONTROL, 0, 15, 0),
160 SOC_ENUM("Bass Control", wm9712_enum[5]),
161 SOC_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
162 SOC_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
163 SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
164 SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 0),
165 SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 0),
167 SOC_SINGLE("Capture ADC Switch", AC97_REC_GAIN, 15, 1, 1),
168 SOC_ENUM("Capture Volume Steps", wm9712_enum[6]),
169 SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
170 SOC_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
172 SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
173 SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
174 SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
177 /* add non dapm controls */
178 static int wm9712_add_controls(struct snd_soc_codec *codec)
182 for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) {
183 err = snd_ctl_add(codec->card,
184 snd_soc_cnew(&wm9712_snd_ac97_controls[i],codec, NULL));
191 /* We have to create a fake left and right HP mixers because
192 * the codec only has a single control that is shared by both channels.
193 * This makes it impossible to determine the audio path.
195 static int mixer_event (struct snd_soc_dapm_widget *w, int event)
197 u16 l, r, beep, line, phone, mic, pcm, aux;
199 l = ac97_read(w->codec, HPL_MIXER);
200 r = ac97_read(w->codec, HPR_MIXER);
201 beep = ac97_read(w->codec, AC97_PC_BEEP);
202 mic = ac97_read(w->codec, AC97_VIDEO);
203 phone = ac97_read(w->codec, AC97_PHONE);
204 line = ac97_read(w->codec, AC97_LINE);
205 pcm = ac97_read(w->codec, AC97_PCM);
206 aux = ac97_read(w->codec, AC97_CD);
208 if (l & 0x1 || r & 0x1)
209 ac97_write(w->codec, AC97_VIDEO, mic & 0x7fff);
211 ac97_write(w->codec, AC97_VIDEO, mic | 0x8000);
213 if (l & 0x2 || r & 0x2)
214 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
216 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
218 if (l & 0x4 || r & 0x4)
219 ac97_write(w->codec, AC97_LINE, line & 0x7fff);
221 ac97_write(w->codec, AC97_LINE, line | 0x8000);
223 if (l & 0x8 || r & 0x8)
224 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff);
226 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
228 if (l & 0x10 || r & 0x10)
229 ac97_write(w->codec, AC97_CD, aux & 0x7fff);
231 ac97_write(w->codec, AC97_CD, aux | 0x8000);
233 if (l & 0x20 || r & 0x20)
234 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff);
236 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
241 /* Left Headphone Mixers */
242 static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = {
243 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPL_MIXER, 5, 1, 0),
244 SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 4, 1, 0),
245 SOC_DAPM_SINGLE("Phone Bypass Switch", HPL_MIXER, 3, 1, 0),
246 SOC_DAPM_SINGLE("Line Bypass Switch", HPL_MIXER, 2, 1, 0),
247 SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 1, 1, 0),
248 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPL_MIXER, 0, 1, 0),
251 /* Right Headphone Mixers */
252 static const struct snd_kcontrol_new wm9712_hpr_mixer_controls[] = {
253 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPR_MIXER, 5, 1, 0),
254 SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 4, 1, 0),
255 SOC_DAPM_SINGLE("Phone Bypass Switch", HPR_MIXER, 3, 1, 0),
256 SOC_DAPM_SINGLE("Line Bypass Switch", HPR_MIXER, 2, 1, 0),
257 SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 1, 1, 0),
258 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPR_MIXER, 0, 1, 0),
262 static const struct snd_kcontrol_new wm9712_speaker_mixer_controls[] = {
263 SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 11, 1, 1),
264 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 11, 1, 1),
265 SOC_DAPM_SINGLE("Phone Bypass Switch", AC97_PHONE, 14, 1, 1),
266 SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 14, 1, 1),
267 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 14, 1, 1),
271 static const struct snd_kcontrol_new wm9712_phone_mixer_controls[] = {
272 SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 7, 1, 1),
273 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 7, 1, 1),
274 SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 13, 1, 1),
275 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 13, 1, 1),
276 SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_MIC, 14, 1, 1),
277 SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_MIC, 13, 1, 1),
280 /* ALC headphone mux */
281 static const struct snd_kcontrol_new wm9712_alc_mux_controls =
282 SOC_DAPM_ENUM("Route", wm9712_enum[1]);
285 static const struct snd_kcontrol_new wm9712_out3_mux_controls =
286 SOC_DAPM_ENUM("Route", wm9712_enum[2]);
289 static const struct snd_kcontrol_new wm9712_spk_mux_controls =
290 SOC_DAPM_ENUM("Route", wm9712_enum[3]);
292 /* Capture to Phone mux */
293 static const struct snd_kcontrol_new wm9712_capture_phone_mux_controls =
294 SOC_DAPM_ENUM("Route", wm9712_enum[4]);
296 /* Capture left select */
297 static const struct snd_kcontrol_new wm9712_capture_selectl_controls =
298 SOC_DAPM_ENUM("Route", wm9712_enum[8]);
300 /* Capture right select */
301 static const struct snd_kcontrol_new wm9712_capture_selectr_controls =
302 SOC_DAPM_ENUM("Route", wm9712_enum[9]);
305 static const struct snd_kcontrol_new wm9712_mic_src_controls =
306 SOC_DAPM_ENUM("Route", wm9712_enum[7]);
309 static const struct snd_kcontrol_new wm9712_diff_sel_controls =
310 SOC_DAPM_ENUM("Route", wm9712_enum[11]);
312 static const struct snd_soc_dapm_widget wm9712_dapm_widgets[] = {
313 SND_SOC_DAPM_MUX("ALC Sidetone Mux", SND_SOC_NOPM, 0, 0,
314 &wm9712_alc_mux_controls),
315 SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM, 0, 0,
316 &wm9712_out3_mux_controls),
317 SND_SOC_DAPM_MUX("Speaker Mux", SND_SOC_NOPM, 0, 0,
318 &wm9712_spk_mux_controls),
319 SND_SOC_DAPM_MUX("Capture Phone Mux", SND_SOC_NOPM, 0, 0,
320 &wm9712_capture_phone_mux_controls),
321 SND_SOC_DAPM_MUX("Left Capture Select", SND_SOC_NOPM, 0, 0,
322 &wm9712_capture_selectl_controls),
323 SND_SOC_DAPM_MUX("Right Capture Select", SND_SOC_NOPM, 0, 0,
324 &wm9712_capture_selectr_controls),
325 SND_SOC_DAPM_MUX("Mic Select Source", SND_SOC_NOPM, 0, 0,
326 &wm9712_mic_src_controls),
327 SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0,
328 &wm9712_diff_sel_controls),
329 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
330 SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_INT_PAGING, 9, 1,
331 &wm9712_hpl_mixer_controls[0], ARRAY_SIZE(wm9712_hpl_mixer_controls),
332 mixer_event, SND_SOC_DAPM_POST_REG),
333 SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_INT_PAGING, 8, 1,
334 &wm9712_hpr_mixer_controls[0], ARRAY_SIZE(wm9712_hpr_mixer_controls),
335 mixer_event, SND_SOC_DAPM_POST_REG),
336 SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1,
337 &wm9712_phone_mixer_controls[0], ARRAY_SIZE(wm9712_phone_mixer_controls)),
338 SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1,
339 &wm9712_speaker_mixer_controls[0],
340 ARRAY_SIZE(wm9712_speaker_mixer_controls)),
341 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
342 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_INT_PAGING, 14, 1),
343 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_INT_PAGING, 13, 1),
344 SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", SND_SOC_NOPM, 0, 0),
345 SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_INT_PAGING, 12, 1),
346 SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_INT_PAGING, 11, 1),
347 SND_SOC_DAPM_PGA("Headphone PGA", AC97_INT_PAGING, 4, 1, NULL, 0),
348 SND_SOC_DAPM_PGA("Speaker PGA", AC97_INT_PAGING, 3, 1, NULL, 0),
349 SND_SOC_DAPM_PGA("Out 3 PGA", AC97_INT_PAGING, 5, 1, NULL, 0),
350 SND_SOC_DAPM_PGA("Line PGA", AC97_INT_PAGING, 2, 1, NULL, 0),
351 SND_SOC_DAPM_PGA("Phone PGA", AC97_INT_PAGING, 1, 1, NULL, 0),
352 SND_SOC_DAPM_PGA("Mic PGA", AC97_INT_PAGING, 0, 1, NULL, 0),
353 SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_INT_PAGING, 10, 1),
354 SND_SOC_DAPM_OUTPUT("MONOOUT"),
355 SND_SOC_DAPM_OUTPUT("HPOUTL"),
356 SND_SOC_DAPM_OUTPUT("HPOUTR"),
357 SND_SOC_DAPM_OUTPUT("LOUT2"),
358 SND_SOC_DAPM_OUTPUT("ROUT2"),
359 SND_SOC_DAPM_OUTPUT("OUT3"),
360 SND_SOC_DAPM_INPUT("LINEINL"),
361 SND_SOC_DAPM_INPUT("LINEINR"),
362 SND_SOC_DAPM_INPUT("PHONE"),
363 SND_SOC_DAPM_INPUT("PCBEEP"),
364 SND_SOC_DAPM_INPUT("MIC1"),
365 SND_SOC_DAPM_INPUT("MIC2"),
368 static const char *audio_map[][3] = {
369 /* virtual mixer - mixes left & right channels for spk and mono */
370 {"AC97 Mixer", NULL, "Left DAC"},
371 {"AC97 Mixer", NULL, "Right DAC"},
374 {"Left HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
375 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
376 {"Left HP Mixer", "Phone Bypass Switch", "Phone PGA"},
377 {"Left HP Mixer", "Line Bypass Switch", "Line PGA"},
378 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
379 {"Left HP Mixer", "Mic Sidetone Switch", "Mic PGA"},
380 {"Left HP Mixer", NULL, "ALC Sidetone Mux"},
381 //{"Right HP Mixer", NULL, "HP Mixer"},
384 {"Right HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
385 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
386 {"Right HP Mixer", "Phone Bypass Switch", "Phone PGA"},
387 {"Right HP Mixer", "Line Bypass Switch", "Line PGA"},
388 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
389 {"Right HP Mixer", "Mic Sidetone Switch", "Mic PGA"},
390 {"Right HP Mixer", NULL, "ALC Sidetone Mux"},
393 {"Speaker Mixer", "PCBeep Bypass Switch", "PCBEEP"},
394 {"Speaker Mixer", "Line Bypass Switch", "Line PGA"},
395 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
396 {"Speaker Mixer", "Phone Bypass Switch", "Phone PGA"},
397 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
400 {"Phone Mixer", "PCBeep Bypass Switch", "PCBEEP"},
401 {"Phone Mixer", "Line Bypass Switch", "Line PGA"},
402 {"Phone Mixer", "Aux Playback Switch", "Aux DAC"},
403 {"Phone Mixer", "PCM Playback Switch", "AC97 Mixer"},
404 {"Phone Mixer", "Mic 1 Sidetone Switch", "Mic PGA"},
405 {"Phone Mixer", "Mic 2 Sidetone Switch", "Mic PGA"},
408 {"Line PGA", NULL, "LINEINL"},
409 {"Line PGA", NULL, "LINEINR"},
410 {"Phone PGA", NULL, "PHONE"},
411 {"Mic PGA", NULL, "MIC1"},
412 {"Mic PGA", NULL, "MIC2"},
414 /* left capture selector */
415 {"Left Capture Select", "Mic", "MIC1"},
416 {"Left Capture Select", "Speaker Mixer", "Speaker Mixer"},
417 {"Left Capture Select", "Line", "LINEINL"},
418 {"Left Capture Select", "Headphone Mixer", "Left HP Mixer"},
419 {"Left Capture Select", "Phone Mixer", "Phone Mixer"},
420 {"Left Capture Select", "Phone", "PHONE"},
422 /* right capture selector */
423 {"Right Capture Select", "Mic", "MIC2"},
424 {"Right Capture Select", "Speaker Mixer", "Speaker Mixer"},
425 {"Right Capture Select", "Line", "LINEINR"},
426 {"Right Capture Select", "Headphone Mixer", "Right HP Mixer"},
427 {"Right Capture Select", "Phone Mixer", "Phone Mixer"},
428 {"Right Capture Select", "Phone", "PHONE"},
431 {"ALC Sidetone Mux", "Stereo", "Left Capture Select"},
432 {"ALC Sidetone Mux", "Stereo", "Right Capture Select"},
433 {"ALC Sidetone Mux", "Left", "Left Capture Select"},
434 {"ALC Sidetone Mux", "Right", "Right Capture Select"},
437 {"Left ADC", NULL, "Left Capture Select"},
438 {"Right ADC", NULL, "Right Capture Select"},
441 {"MONOOUT", NULL, "Phone Mixer"},
442 {"HPOUTL", NULL, "Headphone PGA"},
443 {"Headphone PGA", NULL, "Left HP Mixer"},
444 {"HPOUTR", NULL, "Headphone PGA"},
445 {"Headphone PGA", NULL, "Right HP Mixer"},
448 {"Mono HP Mixer", NULL, "Left HP Mixer"},
449 {"Mono HP Mixer", NULL, "Right HP Mixer"},
452 {"Out3 Mux", "Left", "Left HP Mixer"},
453 {"Out3 Mux", "Mono", "Phone Mixer"},
454 {"Out3 Mux", "Left + Right", "Mono HP Mixer"},
455 {"Out 3 PGA", NULL, "Out3 Mux"},
456 {"OUT3", NULL, "Out 3 PGA"},
459 {"Speaker Mux", "Speaker Mix", "Speaker Mixer"},
460 {"Speaker Mux", "Headphone Mix", "Mono HP Mixer"},
461 {"Speaker PGA", NULL, "Speaker Mux"},
462 {"LOUT2", NULL, "Speaker PGA"},
463 {"ROUT2", NULL, "Speaker PGA"},
468 static int wm9712_add_widgets(struct snd_soc_codec *codec)
472 for(i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++) {
473 snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]);
476 /* set up audio path audio_mapnects */
477 for(i = 0; audio_map[i][0] != NULL; i++) {
478 snd_soc_dapm_connect_input(codec, audio_map[i][0],
479 audio_map[i][1], audio_map[i][2]);
482 snd_soc_dapm_new_widgets(codec);
486 static unsigned int ac97_read(struct snd_soc_codec *codec,
489 u16 *cache = codec->reg_cache;
491 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
492 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
493 reg == AC97_REC_GAIN)
494 return soc_ac97_ops.read(codec->ac97, reg);
498 if (reg > (ARRAY_SIZE(wm9712_reg)))
505 static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
508 u16 *cache = codec->reg_cache;
510 soc_ac97_ops.write(codec->ac97, reg, val);
512 if (reg <= (ARRAY_SIZE(wm9712_reg)))
518 static int ac97_prepare(struct snd_pcm_substream *substream)
520 struct snd_pcm_runtime *runtime = substream->runtime;
521 struct snd_soc_pcm_runtime *rtd = substream->private_data;
522 struct snd_soc_device *socdev = rtd->socdev;
523 struct snd_soc_codec *codec = socdev->codec;
527 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
528 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
530 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
531 reg = AC97_PCM_FRONT_DAC_RATE;
533 reg = AC97_PCM_LR_ADC_RATE;
535 return ac97_write(codec, reg, runtime->rate);
538 static int ac97_aux_prepare(struct snd_pcm_substream *substream)
540 struct snd_pcm_runtime *runtime = substream->runtime;
541 struct snd_soc_pcm_runtime *rtd = substream->private_data;
542 struct snd_soc_device *socdev = rtd->socdev;
543 struct snd_soc_codec *codec = socdev->codec;
546 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
547 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
548 xsle = ac97_read(codec, AC97_PCI_SID);
549 ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
551 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
554 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
557 struct snd_soc_codec_dai wm9712_dai[] = {
561 .stream_name = "HiFi Playback",
565 .stream_name = "HiFi Capture",
569 .prepare = ac97_prepare,},
571 .num_modes = ARRAY_SIZE(ac97_modes),
572 .mode = ac97_modes,},
577 .stream_name = "Aux Playback",
581 .prepare = ac97_aux_prepare,},
583 .num_modes = ARRAY_SIZE(ac97_modes),
584 .mode = ac97_modes,},
587 EXPORT_SYMBOL_GPL(wm9712_dai);
589 static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
594 case SNDRV_CTL_POWER_D0: /* full On */
595 /* liam - maybe enable thermal shutdown */
596 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
597 ac97_write(codec, AC97_EXTENDED_MID, reg);
599 case SNDRV_CTL_POWER_D1: /* partial On */
600 case SNDRV_CTL_POWER_D2: /* partial On */
602 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
603 /* enable master bias and vmid */
604 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
605 ac97_write(codec, AC97_EXTENDED_MID, reg);
606 ac97_write(codec, AC97_POWERDOWN, 0x0000);
608 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
609 /* disable everything including AC link */
610 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
611 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
612 ac97_write(codec, AC97_POWERDOWN, 0xffff);
615 codec->dapm_state = event;
619 static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
621 if (try_warm && soc_ac97_ops.warm_reset) {
622 soc_ac97_ops.warm_reset(codec->ac97);
623 if (!(ac97_read(codec, 0) & 0x8000))
627 soc_ac97_ops.reset(codec->ac97);
628 if (ac97_read(codec, 0) & 0x8000)
633 printk(KERN_ERR "WM9712 AC97 reset failed\n");
637 static int wm9712_soc_suspend(struct platform_device *pdev,
640 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
641 struct snd_soc_codec *codec = socdev->codec;
643 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
647 static int wm9712_soc_resume(struct platform_device *pdev)
649 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
650 struct snd_soc_codec *codec = socdev->codec;
652 u16 *cache = codec->reg_cache;
654 ret = wm9712_reset(codec, 1);
656 printk(KERN_ERR "could not reset AC97 codec\n");
660 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
663 /* Sync reg_cache with the hardware after cold reset */
664 for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i+=2) {
665 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN ||
666 (i > 0x58 && i != 0x5c))
668 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
672 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
673 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D0);
678 static int wm9712_soc_probe(struct platform_device *pdev)
680 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
681 struct snd_soc_codec *codec;
684 printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION);
686 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
687 if (socdev->codec == NULL)
689 codec = socdev->codec;
690 mutex_init(&codec->mutex);
693 kzalloc(sizeof(u16) * ARRAY_SIZE(wm9712_reg), GFP_KERNEL);
694 if (codec->reg_cache == NULL) {
696 kfree(socdev->codec);
697 socdev->codec = NULL;
700 memcpy(codec->reg_cache, wm9712_reg, sizeof(u16) * ARRAY_SIZE(wm9712_reg));
701 codec->reg_cache_size = sizeof(u16) * ARRAY_SIZE(wm9712_reg);
702 codec->reg_cache_step = 2;
704 codec->name = "WM9712";
705 codec->owner = THIS_MODULE;
706 codec->dai = wm9712_dai;
707 codec->num_dai = ARRAY_SIZE(wm9712_dai);
708 codec->write = ac97_write;
709 codec->read = ac97_read;
710 codec->dapm_event = wm9712_dapm_event;
711 INIT_LIST_HEAD(&codec->dapm_widgets);
712 INIT_LIST_HEAD(&codec->dapm_paths);
714 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
719 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
723 ret = wm9712_reset(codec, 0);
725 printk(KERN_ERR "AC97 link error\n");
729 /* set alc mux to none */
730 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
732 wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
733 wm9712_add_controls(codec);
734 wm9712_add_widgets(codec);
735 ret = snd_soc_register_card(socdev);
742 snd_soc_free_pcms(socdev);
745 snd_soc_free_ac97_codec(codec);
748 kfree(socdev->codec->reg_cache);
749 kfree(socdev->codec);
750 socdev->codec = NULL;
754 static int wm9712_soc_remove(struct platform_device *pdev)
756 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
757 struct snd_soc_codec *codec = socdev->codec;
762 snd_soc_dapm_free(socdev);
763 snd_soc_free_pcms(socdev);
764 snd_soc_free_ac97_codec(codec);
765 kfree(codec->reg_cache);
770 struct snd_soc_codec_device soc_codec_dev_wm9712 = {
771 .probe = wm9712_soc_probe,
772 .remove = wm9712_soc_remove,
773 .suspend = wm9712_soc_suspend,
774 .resume = wm9712_soc_resume,
777 EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
779 MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver");
780 MODULE_AUTHOR("Liam Girdwood");
781 MODULE_LICENSE("GPL");