Commit | Line | Data |
---|---|---|
83ac08c0 LG |
1 | /* |
2 | * wm9713.c -- ALSA Soc WM9713 codec support | |
3 | * | |
4 | * Copyright 2006 Wolfson Microelectronics PLC. | |
d331124d | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
83ac08c0 LG |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. | |
11 | * | |
83ac08c0 LG |
12 | * Features:- |
13 | * | |
14 | * o Support for AC97 Codec, Voice DAC and Aux DAC | |
15 | * o Support for DAPM | |
16 | */ | |
17 | ||
18 | #include <linux/init.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/device.h> | |
21 | #include <sound/core.h> | |
22 | #include <sound/pcm.h> | |
23 | #include <sound/ac97_codec.h> | |
24 | #include <sound/initval.h> | |
25 | #include <sound/pcm_params.h> | |
26 | #include <sound/soc.h> | |
27 | #include <sound/soc-dapm.h> | |
28 | ||
29 | #include "wm9713.h" | |
30 | ||
31 | #define WM9713_VERSION "0.15" | |
32 | ||
33 | struct wm9713_priv { | |
34 | u32 pll_in; /* PLL input frequency */ | |
35 | u32 pll_out; /* PLL output frequency */ | |
36 | }; | |
37 | ||
38 | static unsigned int ac97_read(struct snd_soc_codec *codec, | |
39 | unsigned int reg); | |
40 | static int ac97_write(struct snd_soc_codec *codec, | |
41 | unsigned int reg, unsigned int val); | |
42 | ||
43 | /* | |
44 | * WM9713 register cache | |
45 | * Reg 0x3c bit 15 is used by touch driver. | |
46 | */ | |
47 | static const u16 wm9713_reg[] = { | |
48 | 0x6174, 0x8080, 0x8080, 0x8080, | |
49 | 0xc880, 0xe808, 0xe808, 0x0808, | |
50 | 0x00da, 0x8000, 0xd600, 0xaaa0, | |
51 | 0xaaa0, 0xaaa0, 0x0000, 0x0000, | |
52 | 0x0f0f, 0x0040, 0x0000, 0x7f00, | |
53 | 0x0405, 0x0410, 0xbb80, 0xbb80, | |
54 | 0x0000, 0xbb80, 0x0000, 0x4523, | |
55 | 0x0000, 0x2000, 0x7eff, 0xffff, | |
56 | 0x0000, 0x0000, 0x0080, 0x0000, | |
57 | 0x0000, 0x0000, 0xfffe, 0xffff, | |
58 | 0x0000, 0x0000, 0x0000, 0xfffe, | |
59 | 0x4000, 0x0000, 0x0000, 0x0000, | |
60 | 0xb032, 0x3e00, 0x0000, 0x0000, | |
61 | 0x0000, 0x0000, 0x0000, 0x0000, | |
62 | 0x0000, 0x0000, 0x0000, 0x0006, | |
63 | 0x0001, 0x0000, 0x574d, 0x4c13, | |
64 | 0x0000, 0x0000, 0x0000 | |
65 | }; | |
66 | ||
67 | /* virtual HP mixers regs */ | |
68 | #define HPL_MIXER 0x80 | |
69 | #define HPR_MIXER 0x82 | |
70 | #define MICB_MUX 0x82 | |
71 | ||
72 | static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; | |
73 | static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; | |
74 | static const char *wm9713_rec_src[] = | |
75 | {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker", | |
76 | "Mono Out", "Zh"}; | |
77 | static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; | |
78 | static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; | |
79 | static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv", | |
80 | "Mono Vmid", "Inv Vmid"}; | |
81 | static const char *wm9713_spk_pga[] = | |
82 | {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid", | |
83 | "Speaker Vmid", "Inv Vmid"}; | |
84 | static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone", | |
85 | "Headphone Vmid"}; | |
86 | static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"}; | |
87 | static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"}; | |
88 | static const char *wm9713_dac_inv[] = | |
89 | {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone", | |
90 | "Headphone Mono", "NC", "Vmid"}; | |
91 | static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"}; | |
92 | static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"}; | |
93 | static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"}; | |
94 | static const char *wm9713_micb_select[] = {"MPB", "MPA"}; | |
95 | ||
96 | static const struct soc_enum wm9713_enum[] = { | |
97 | SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */ | |
98 | SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */ | |
99 | SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */ | |
100 | SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */ | |
101 | SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/ | |
102 | SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */ | |
103 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/ | |
104 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */ | |
105 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */ | |
106 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */ | |
107 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */ | |
108 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */ | |
109 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */ | |
110 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */ | |
111 | SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */ | |
112 | SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */ | |
113 | SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */ | |
114 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */ | |
115 | SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */ | |
116 | SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */ | |
117 | }; | |
118 | ||
119 | static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = { | |
120 | SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1), | |
121 | SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1), | |
122 | SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), | |
123 | SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1), | |
124 | SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), | |
125 | SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), | |
126 | SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), | |
127 | SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), | |
128 | ||
129 | SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), | |
130 | SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), | |
131 | ||
132 | SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), | |
133 | SOC_ENUM("Capture Volume Steps", wm9713_enum[5]), | |
134 | SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0), | |
135 | SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), | |
136 | ||
137 | SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), | |
138 | SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), | |
139 | SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), | |
140 | ||
141 | SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), | |
142 | SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), | |
13d622b3 | 143 | SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), |
83ac08c0 LG |
144 | SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
145 | SOC_ENUM("ALC Function", wm9713_enum[6]), | |
146 | SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), | |
147 | SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), | |
148 | SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), | |
149 | SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), | |
150 | SOC_ENUM("ALC NG Type", wm9713_enum[17]), | |
151 | SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), | |
152 | ||
153 | SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0), | |
154 | SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), | |
155 | ||
156 | SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1), | |
157 | SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0), | |
158 | SOC_SINGLE("Out4 Playback Volume", AC97_MASTER_MONO, 8, 63, 1), | |
159 | ||
160 | SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1), | |
161 | SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0), | |
162 | SOC_SINGLE("Out3 Playback Volume", AC97_MASTER_MONO, 0, 63, 1), | |
163 | ||
164 | SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1), | |
165 | SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1), | |
166 | SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0), | |
167 | SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1), | |
168 | ||
169 | SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1), | |
170 | SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1), | |
171 | SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1), | |
172 | ||
173 | SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1), | |
174 | SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1), | |
175 | SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1), | |
176 | ||
177 | SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1), | |
178 | SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1), | |
179 | SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1), | |
180 | ||
181 | SOC_ENUM("Bass Control", wm9713_enum[16]), | |
182 | SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), | |
183 | SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), | |
184 | SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), | |
185 | SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), | |
186 | SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), | |
187 | ||
188 | SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), | |
189 | SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), | |
190 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), | |
191 | }; | |
192 | ||
83ac08c0 LG |
193 | /* We have to create a fake left and right HP mixers because |
194 | * the codec only has a single control that is shared by both channels. | |
195 | * This makes it impossible to determine the audio path using the current | |
196 | * register map, thus we add a new (virtual) register to help determine the | |
197 | * audio route within the device. | |
198 | */ | |
199 | static int mixer_event(struct snd_soc_dapm_widget *w, | |
200 | struct snd_kcontrol *kcontrol, int event) | |
201 | { | |
202 | u16 l, r, beep, tone, phone, rec, pcm, aux; | |
203 | ||
204 | l = ac97_read(w->codec, HPL_MIXER); | |
205 | r = ac97_read(w->codec, HPR_MIXER); | |
206 | beep = ac97_read(w->codec, AC97_PC_BEEP); | |
207 | tone = ac97_read(w->codec, AC97_MASTER_TONE); | |
208 | phone = ac97_read(w->codec, AC97_PHONE); | |
209 | rec = ac97_read(w->codec, AC97_REC_SEL); | |
210 | pcm = ac97_read(w->codec, AC97_PCM); | |
211 | aux = ac97_read(w->codec, AC97_AUX); | |
212 | ||
213 | if (event & SND_SOC_DAPM_PRE_REG) | |
214 | return 0; | |
215 | if ((l & 0x1) || (r & 0x1)) | |
216 | ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff); | |
217 | else | |
218 | ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000); | |
219 | ||
220 | if ((l & 0x2) || (r & 0x2)) | |
221 | ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff); | |
222 | else | |
223 | ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000); | |
224 | ||
225 | if ((l & 0x4) || (r & 0x4)) | |
226 | ac97_write(w->codec, AC97_PHONE, phone & 0x7fff); | |
227 | else | |
228 | ac97_write(w->codec, AC97_PHONE, phone | 0x8000); | |
229 | ||
230 | if ((l & 0x8) || (r & 0x8)) | |
231 | ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff); | |
232 | else | |
233 | ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000); | |
234 | ||
235 | if ((l & 0x10) || (r & 0x10)) | |
236 | ac97_write(w->codec, AC97_PCM, pcm & 0x7fff); | |
237 | else | |
238 | ac97_write(w->codec, AC97_PCM, pcm | 0x8000); | |
239 | ||
240 | if ((l & 0x20) || (r & 0x20)) | |
241 | ac97_write(w->codec, AC97_AUX, aux & 0x7fff); | |
242 | else | |
243 | ac97_write(w->codec, AC97_AUX, aux | 0x8000); | |
244 | ||
245 | return 0; | |
246 | } | |
247 | ||
248 | /* Left Headphone Mixers */ | |
249 | static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { | |
250 | SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0), | |
251 | SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0), | |
252 | SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0), | |
253 | SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0), | |
254 | SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0), | |
255 | SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0), | |
256 | }; | |
257 | ||
258 | /* Right Headphone Mixers */ | |
259 | static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { | |
260 | SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0), | |
261 | SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0), | |
262 | SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0), | |
263 | SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0), | |
264 | SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0), | |
265 | SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0), | |
266 | }; | |
267 | ||
268 | /* headphone capture mux */ | |
269 | static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls = | |
270 | SOC_DAPM_ENUM("Route", wm9713_enum[1]); | |
271 | ||
272 | /* headphone mic mux */ | |
273 | static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls = | |
274 | SOC_DAPM_ENUM("Route", wm9713_enum[0]); | |
275 | ||
276 | /* Speaker Mixer */ | |
277 | static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { | |
278 | SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1), | |
279 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1), | |
280 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1), | |
281 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), | |
282 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1), | |
283 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1), | |
284 | }; | |
285 | ||
286 | /* Mono Mixer */ | |
287 | static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { | |
288 | SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1), | |
289 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1), | |
290 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1), | |
291 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), | |
292 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1), | |
293 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1), | |
294 | SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1), | |
295 | SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1), | |
296 | }; | |
297 | ||
298 | /* mono mic mux */ | |
299 | static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls = | |
300 | SOC_DAPM_ENUM("Route", wm9713_enum[2]); | |
301 | ||
302 | /* mono output mux */ | |
303 | static const struct snd_kcontrol_new wm9713_mono_mux_controls = | |
304 | SOC_DAPM_ENUM("Route", wm9713_enum[7]); | |
305 | ||
306 | /* speaker left output mux */ | |
307 | static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls = | |
308 | SOC_DAPM_ENUM("Route", wm9713_enum[8]); | |
309 | ||
310 | /* speaker right output mux */ | |
311 | static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls = | |
312 | SOC_DAPM_ENUM("Route", wm9713_enum[9]); | |
313 | ||
314 | /* headphone left output mux */ | |
315 | static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls = | |
316 | SOC_DAPM_ENUM("Route", wm9713_enum[10]); | |
317 | ||
318 | /* headphone right output mux */ | |
319 | static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls = | |
320 | SOC_DAPM_ENUM("Route", wm9713_enum[11]); | |
321 | ||
322 | /* Out3 mux */ | |
323 | static const struct snd_kcontrol_new wm9713_out3_mux_controls = | |
324 | SOC_DAPM_ENUM("Route", wm9713_enum[12]); | |
325 | ||
326 | /* Out4 mux */ | |
327 | static const struct snd_kcontrol_new wm9713_out4_mux_controls = | |
328 | SOC_DAPM_ENUM("Route", wm9713_enum[13]); | |
329 | ||
330 | /* DAC inv mux 1 */ | |
331 | static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls = | |
332 | SOC_DAPM_ENUM("Route", wm9713_enum[14]); | |
333 | ||
334 | /* DAC inv mux 2 */ | |
335 | static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls = | |
336 | SOC_DAPM_ENUM("Route", wm9713_enum[15]); | |
337 | ||
338 | /* Capture source left */ | |
339 | static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls = | |
340 | SOC_DAPM_ENUM("Route", wm9713_enum[3]); | |
341 | ||
342 | /* Capture source right */ | |
343 | static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls = | |
344 | SOC_DAPM_ENUM("Route", wm9713_enum[4]); | |
345 | ||
346 | /* mic source */ | |
347 | static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls = | |
348 | SOC_DAPM_ENUM("Route", wm9713_enum[18]); | |
349 | ||
350 | /* mic source B virtual control */ | |
351 | static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls = | |
352 | SOC_DAPM_ENUM("Route", wm9713_enum[19]); | |
353 | ||
354 | static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = { | |
355 | SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0, | |
356 | &wm9713_hp_rec_mux_controls), | |
357 | SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0, | |
358 | &wm9713_hp_mic_mux_controls), | |
359 | SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0, | |
360 | &wm9713_mono_mic_mux_controls), | |
361 | SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0, | |
362 | &wm9713_mono_mux_controls), | |
363 | SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0, | |
364 | &wm9713_hp_spkl_mux_controls), | |
365 | SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0, | |
366 | &wm9713_hp_spkr_mux_controls), | |
367 | SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0, | |
368 | &wm9713_hpl_out_mux_controls), | |
369 | SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0, | |
370 | &wm9713_hpr_out_mux_controls), | |
371 | SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0, | |
372 | &wm9713_out3_mux_controls), | |
373 | SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0, | |
374 | &wm9713_out4_mux_controls), | |
375 | SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0, | |
376 | &wm9713_dac_inv1_mux_controls), | |
377 | SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0, | |
378 | &wm9713_dac_inv2_mux_controls), | |
379 | SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, | |
380 | &wm9713_rec_srcl_mux_controls), | |
381 | SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, | |
382 | &wm9713_rec_srcr_mux_controls), | |
383 | SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0, | |
384 | &wm9713_mic_sel_mux_controls), | |
385 | SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0, | |
386 | &wm9713_micb_sel_mux_controls), | |
387 | SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, | |
388 | &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls), | |
389 | mixer_event, SND_SOC_DAPM_POST_REG), | |
390 | SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, | |
391 | &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls), | |
392 | mixer_event, SND_SOC_DAPM_POST_REG), | |
393 | SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, | |
394 | &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)), | |
395 | SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, | |
396 | &wm9713_speaker_mixer_controls[0], | |
397 | ARRAY_SIZE(wm9713_speaker_mixer_controls)), | |
398 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1), | |
399 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1), | |
400 | SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | |
401 | SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | |
402 | SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | |
403 | SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | |
404 | SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1), | |
405 | SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1), | |
ccbc301e MB |
406 | SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0), |
407 | SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0), | |
408 | SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), | |
409 | SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), | |
410 | SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM, 0, 0), | |
411 | SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM, 0, 0), | |
83ac08c0 LG |
412 | SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0), |
413 | SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0), | |
414 | SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0), | |
415 | SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0), | |
416 | SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0), | |
417 | SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0), | |
418 | SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0), | |
419 | SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0), | |
420 | SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0), | |
421 | SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0), | |
422 | SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0), | |
423 | SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0), | |
424 | SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0), | |
425 | SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0), | |
426 | SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1), | |
427 | SND_SOC_DAPM_OUTPUT("MONO"), | |
428 | SND_SOC_DAPM_OUTPUT("HPL"), | |
429 | SND_SOC_DAPM_OUTPUT("HPR"), | |
430 | SND_SOC_DAPM_OUTPUT("SPKL"), | |
431 | SND_SOC_DAPM_OUTPUT("SPKR"), | |
432 | SND_SOC_DAPM_OUTPUT("OUT3"), | |
433 | SND_SOC_DAPM_OUTPUT("OUT4"), | |
434 | SND_SOC_DAPM_INPUT("LINEL"), | |
435 | SND_SOC_DAPM_INPUT("LINER"), | |
436 | SND_SOC_DAPM_INPUT("MONOIN"), | |
437 | SND_SOC_DAPM_INPUT("PCBEEP"), | |
438 | SND_SOC_DAPM_INPUT("MIC1"), | |
439 | SND_SOC_DAPM_INPUT("MIC2A"), | |
440 | SND_SOC_DAPM_INPUT("MIC2B"), | |
441 | SND_SOC_DAPM_VMID("VMID"), | |
442 | }; | |
443 | ||
a65f0568 | 444 | static const struct snd_soc_dapm_route audio_map[] = { |
83ac08c0 LG |
445 | /* left HP mixer */ |
446 | {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, | |
447 | {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, | |
448 | {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, | |
449 | {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, | |
450 | {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, | |
451 | {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"}, | |
452 | {"Left HP Mixer", NULL, "Capture Headphone Mux"}, | |
453 | ||
454 | /* right HP mixer */ | |
455 | {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, | |
456 | {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, | |
457 | {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, | |
458 | {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, | |
459 | {"Right HP Mixer", "PCM Playback Switch", "Right DAC"}, | |
460 | {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"}, | |
461 | {"Right HP Mixer", NULL, "Capture Headphone Mux"}, | |
462 | ||
463 | /* virtual mixer - mixes left & right channels for spk and mono */ | |
464 | {"AC97 Mixer", NULL, "Left DAC"}, | |
465 | {"AC97 Mixer", NULL, "Right DAC"}, | |
466 | {"Line Mixer", NULL, "Right Line In"}, | |
467 | {"Line Mixer", NULL, "Left Line In"}, | |
468 | {"HP Mixer", NULL, "Left HP Mixer"}, | |
469 | {"HP Mixer", NULL, "Right HP Mixer"}, | |
470 | {"Capture Mixer", NULL, "Left Capture Source"}, | |
471 | {"Capture Mixer", NULL, "Right Capture Source"}, | |
472 | ||
473 | /* speaker mixer */ | |
474 | {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"}, | |
475 | {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, | |
476 | {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, | |
477 | {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, | |
478 | {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"}, | |
479 | {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, | |
480 | ||
481 | /* mono mixer */ | |
482 | {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"}, | |
483 | {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, | |
484 | {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, | |
485 | {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, | |
486 | {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"}, | |
c0bbf48d RJ |
487 | {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"}, |
488 | {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"}, | |
83ac08c0 LG |
489 | {"Mono Mixer", NULL, "Capture Mono Mux"}, |
490 | ||
491 | /* DAC inv mux 1 */ | |
492 | {"DAC Inv Mux 1", "Mono", "Mono Mixer"}, | |
493 | {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"}, | |
494 | {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"}, | |
495 | {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"}, | |
496 | {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"}, | |
497 | ||
498 | /* DAC inv mux 2 */ | |
499 | {"DAC Inv Mux 2", "Mono", "Mono Mixer"}, | |
500 | {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"}, | |
501 | {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"}, | |
502 | {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"}, | |
503 | {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"}, | |
504 | ||
505 | /* headphone left mux */ | |
506 | {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"}, | |
507 | ||
508 | /* headphone right mux */ | |
509 | {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"}, | |
510 | ||
511 | /* speaker left mux */ | |
512 | {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"}, | |
513 | {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"}, | |
514 | {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"}, | |
515 | ||
516 | /* speaker right mux */ | |
517 | {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"}, | |
518 | {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"}, | |
519 | {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"}, | |
520 | ||
521 | /* mono mux */ | |
522 | {"Mono Out Mux", "Mono", "Mono Mixer"}, | |
523 | {"Mono Out Mux", "Inv", "DAC Inv Mux 1"}, | |
524 | ||
525 | /* out 3 mux */ | |
526 | {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"}, | |
527 | ||
528 | /* out 4 mux */ | |
529 | {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"}, | |
530 | ||
531 | /* output pga */ | |
532 | {"HPL", NULL, "Left Headphone"}, | |
533 | {"Left Headphone", NULL, "Left Headphone Out Mux"}, | |
534 | {"HPR", NULL, "Right Headphone"}, | |
535 | {"Right Headphone", NULL, "Right Headphone Out Mux"}, | |
536 | {"OUT3", NULL, "Out 3"}, | |
537 | {"Out 3", NULL, "Out 3 Mux"}, | |
538 | {"OUT4", NULL, "Out 4"}, | |
539 | {"Out 4", NULL, "Out 4 Mux"}, | |
540 | {"SPKL", NULL, "Left Speaker"}, | |
541 | {"Left Speaker", NULL, "Left Speaker Out Mux"}, | |
542 | {"SPKR", NULL, "Right Speaker"}, | |
543 | {"Right Speaker", NULL, "Right Speaker Out Mux"}, | |
544 | {"MONO", NULL, "Mono Out"}, | |
545 | {"Mono Out", NULL, "Mono Out Mux"}, | |
546 | ||
547 | /* input pga */ | |
548 | {"Left Line In", NULL, "LINEL"}, | |
549 | {"Right Line In", NULL, "LINER"}, | |
550 | {"Mono In", NULL, "MONOIN"}, | |
551 | {"Mic A PGA", NULL, "Mic A Pre Amp"}, | |
552 | {"Mic B PGA", NULL, "Mic B Pre Amp"}, | |
553 | ||
554 | /* left capture select */ | |
555 | {"Left Capture Source", "Mic 1", "Mic A Pre Amp"}, | |
556 | {"Left Capture Source", "Mic 2", "Mic B Pre Amp"}, | |
557 | {"Left Capture Source", "Line", "LINEL"}, | |
558 | {"Left Capture Source", "Mono In", "MONOIN"}, | |
559 | {"Left Capture Source", "Headphone", "Left HP Mixer"}, | |
560 | {"Left Capture Source", "Speaker", "Speaker Mixer"}, | |
561 | {"Left Capture Source", "Mono Out", "Mono Mixer"}, | |
562 | ||
563 | /* right capture select */ | |
564 | {"Right Capture Source", "Mic 1", "Mic A Pre Amp"}, | |
565 | {"Right Capture Source", "Mic 2", "Mic B Pre Amp"}, | |
566 | {"Right Capture Source", "Line", "LINER"}, | |
567 | {"Right Capture Source", "Mono In", "MONOIN"}, | |
568 | {"Right Capture Source", "Headphone", "Right HP Mixer"}, | |
569 | {"Right Capture Source", "Speaker", "Speaker Mixer"}, | |
570 | {"Right Capture Source", "Mono Out", "Mono Mixer"}, | |
571 | ||
572 | /* left ADC */ | |
573 | {"Left ADC", NULL, "Left Capture Source"}, | |
ccbc301e MB |
574 | {"Left Voice ADC", NULL, "Left ADC"}, |
575 | {"Left HiFi ADC", NULL, "Left ADC"}, | |
83ac08c0 LG |
576 | |
577 | /* right ADC */ | |
578 | {"Right ADC", NULL, "Right Capture Source"}, | |
ccbc301e MB |
579 | {"Right Voice ADC", NULL, "Right ADC"}, |
580 | {"Right HiFi ADC", NULL, "Right ADC"}, | |
83ac08c0 LG |
581 | |
582 | /* mic */ | |
583 | {"Mic A Pre Amp", NULL, "Mic A Source"}, | |
584 | {"Mic A Source", "Mic 1", "MIC1"}, | |
585 | {"Mic A Source", "Mic 2 A", "MIC2A"}, | |
586 | {"Mic A Source", "Mic 2 B", "Mic B Source"}, | |
587 | {"Mic B Pre Amp", "MPB", "Mic B Source"}, | |
588 | {"Mic B Source", NULL, "MIC2B"}, | |
589 | ||
590 | /* headphone capture */ | |
591 | {"Capture Headphone Mux", "Stereo", "Capture Mixer"}, | |
592 | {"Capture Headphone Mux", "Left", "Left Capture Source"}, | |
593 | {"Capture Headphone Mux", "Right", "Right Capture Source"}, | |
594 | ||
595 | /* mono capture */ | |
596 | {"Capture Mono Mux", "Stereo", "Capture Mixer"}, | |
597 | {"Capture Mono Mux", "Left", "Left Capture Source"}, | |
598 | {"Capture Mono Mux", "Right", "Right Capture Source"}, | |
83ac08c0 LG |
599 | }; |
600 | ||
601 | static int wm9713_add_widgets(struct snd_soc_codec *codec) | |
602 | { | |
a65f0568 MB |
603 | snd_soc_dapm_new_controls(codec, wm9713_dapm_widgets, |
604 | ARRAY_SIZE(wm9713_dapm_widgets)); | |
83ac08c0 | 605 | |
a65f0568 | 606 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
83ac08c0 LG |
607 | |
608 | snd_soc_dapm_new_widgets(codec); | |
609 | return 0; | |
610 | } | |
611 | ||
612 | static unsigned int ac97_read(struct snd_soc_codec *codec, | |
613 | unsigned int reg) | |
614 | { | |
615 | u16 *cache = codec->reg_cache; | |
616 | ||
617 | if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || | |
618 | reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || | |
619 | reg == AC97_CD) | |
620 | return soc_ac97_ops.read(codec->ac97, reg); | |
621 | else { | |
622 | reg = reg >> 1; | |
623 | ||
624 | if (reg > (ARRAY_SIZE(wm9713_reg))) | |
625 | return -EIO; | |
626 | ||
627 | return cache[reg]; | |
628 | } | |
629 | } | |
630 | ||
631 | static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |
632 | unsigned int val) | |
633 | { | |
634 | u16 *cache = codec->reg_cache; | |
635 | if (reg < 0x7c) | |
636 | soc_ac97_ops.write(codec->ac97, reg, val); | |
637 | reg = reg >> 1; | |
638 | if (reg <= (ARRAY_SIZE(wm9713_reg))) | |
639 | cache[reg] = val; | |
640 | ||
641 | return 0; | |
642 | } | |
643 | ||
644 | /* PLL divisors */ | |
645 | struct _pll_div { | |
646 | u32 divsel:1; | |
647 | u32 divctl:1; | |
648 | u32 lf:1; | |
649 | u32 n:4; | |
650 | u32 k:24; | |
651 | }; | |
652 | ||
653 | /* The size in bits of the PLL divide multiplied by 10 | |
654 | * to allow rounding later */ | |
655 | #define FIXED_PLL_SIZE ((1 << 22) * 10) | |
656 | ||
657 | static void pll_factors(struct _pll_div *pll_div, unsigned int source) | |
658 | { | |
659 | u64 Kpart; | |
660 | unsigned int K, Ndiv, Nmod, target; | |
661 | ||
662 | /* The the PLL output is always 98.304MHz. */ | |
663 | target = 98304000; | |
664 | ||
665 | /* If the input frequency is over 14.4MHz then scale it down. */ | |
666 | if (source > 14400000) { | |
667 | source >>= 1; | |
668 | pll_div->divsel = 1; | |
669 | ||
670 | if (source > 14400000) { | |
671 | source >>= 1; | |
672 | pll_div->divctl = 1; | |
673 | } else | |
674 | pll_div->divctl = 0; | |
675 | ||
676 | } else { | |
677 | pll_div->divsel = 0; | |
678 | pll_div->divctl = 0; | |
679 | } | |
680 | ||
681 | /* Low frequency sources require an additional divide in the | |
682 | * loop. | |
683 | */ | |
684 | if (source < 8192000) { | |
685 | pll_div->lf = 1; | |
686 | target >>= 2; | |
687 | } else | |
688 | pll_div->lf = 0; | |
689 | ||
690 | Ndiv = target / source; | |
691 | if ((Ndiv < 5) || (Ndiv > 12)) | |
692 | printk(KERN_WARNING | |
693 | "WM9713 PLL N value %d out of recommended range!\n", | |
694 | Ndiv); | |
695 | ||
696 | pll_div->n = Ndiv; | |
697 | Nmod = target % source; | |
698 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; | |
699 | ||
700 | do_div(Kpart, source); | |
701 | ||
702 | K = Kpart & 0xFFFFFFFF; | |
703 | ||
704 | /* Check if we need to round */ | |
705 | if ((K % 10) >= 5) | |
706 | K += 5; | |
707 | ||
708 | /* Move down to proper range now rounding is done */ | |
709 | K /= 10; | |
710 | ||
711 | pll_div->k = K; | |
712 | } | |
713 | ||
714 | /** | |
715 | * Please note that changing the PLL input frequency may require | |
716 | * resynchronisation with the AC97 controller. | |
717 | */ | |
718 | static int wm9713_set_pll(struct snd_soc_codec *codec, | |
719 | int pll_id, unsigned int freq_in, unsigned int freq_out) | |
720 | { | |
721 | struct wm9713_priv *wm9713 = codec->private_data; | |
722 | u16 reg, reg2; | |
723 | struct _pll_div pll_div; | |
724 | ||
725 | /* turn PLL off ? */ | |
726 | if (freq_in == 0 || freq_out == 0) { | |
727 | /* disable PLL power and select ext source */ | |
728 | reg = ac97_read(codec, AC97_HANDSET_RATE); | |
729 | ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); | |
730 | reg = ac97_read(codec, AC97_EXTENDED_MID); | |
731 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); | |
732 | wm9713->pll_out = 0; | |
733 | return 0; | |
734 | } | |
735 | ||
736 | pll_factors(&pll_div, freq_in); | |
737 | ||
738 | if (pll_div.k == 0) { | |
739 | reg = (pll_div.n << 12) | (pll_div.lf << 11) | | |
740 | (pll_div.divsel << 9) | (pll_div.divctl << 8); | |
741 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
742 | } else { | |
743 | /* write the fractional k to the reg 0x46 pages */ | |
744 | reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) | | |
745 | (pll_div.divsel << 9) | (pll_div.divctl << 8); | |
746 | ||
747 | /* K [21:20] */ | |
748 | reg = reg2 | (0x5 << 4) | (pll_div.k >> 20); | |
749 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
750 | ||
751 | /* K [19:16] */ | |
752 | reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf); | |
753 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
754 | ||
755 | /* K [15:12] */ | |
756 | reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf); | |
757 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
758 | ||
759 | /* K [11:8] */ | |
760 | reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf); | |
761 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
762 | ||
763 | /* K [7:4] */ | |
764 | reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf); | |
765 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
766 | ||
767 | reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */ | |
768 | ac97_write(codec, AC97_LINE1_LEVEL, reg); | |
769 | } | |
770 | ||
771 | /* turn PLL on and select as source */ | |
772 | reg = ac97_read(codec, AC97_EXTENDED_MID); | |
773 | ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); | |
774 | reg = ac97_read(codec, AC97_HANDSET_RATE); | |
775 | ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); | |
776 | wm9713->pll_out = freq_out; | |
777 | wm9713->pll_in = freq_in; | |
778 | ||
779 | /* wait 10ms AC97 link frames for the link to stabilise */ | |
780 | schedule_timeout_interruptible(msecs_to_jiffies(10)); | |
781 | return 0; | |
782 | } | |
783 | ||
e550e17f | 784 | static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, |
83ac08c0 LG |
785 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
786 | { | |
787 | struct snd_soc_codec *codec = codec_dai->codec; | |
788 | return wm9713_set_pll(codec, pll_id, freq_in, freq_out); | |
789 | } | |
790 | ||
791 | /* | |
792 | * Tristate the PCM DAI lines, tristate can be disabled by calling | |
793 | * wm9713_set_dai_fmt() | |
794 | */ | |
e550e17f | 795 | static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai, |
83ac08c0 LG |
796 | int tristate) |
797 | { | |
798 | struct snd_soc_codec *codec = codec_dai->codec; | |
799 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff; | |
800 | ||
801 | if (tristate) | |
802 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); | |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | /* | |
808 | * Configure WM9713 clock dividers. | |
809 | * Voice DAC needs 256 FS | |
810 | */ | |
e550e17f | 811 | static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai, |
83ac08c0 LG |
812 | int div_id, int div) |
813 | { | |
814 | struct snd_soc_codec *codec = codec_dai->codec; | |
815 | u16 reg; | |
816 | ||
817 | switch (div_id) { | |
818 | case WM9713_PCMCLK_DIV: | |
819 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff; | |
820 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); | |
821 | break; | |
822 | case WM9713_CLKA_MULT: | |
823 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd; | |
824 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); | |
825 | break; | |
826 | case WM9713_CLKB_MULT: | |
827 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb; | |
828 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); | |
829 | break; | |
830 | case WM9713_HIFI_DIV: | |
831 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff; | |
832 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); | |
833 | break; | |
834 | case WM9713_PCMBCLK_DIV: | |
835 | reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff; | |
836 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div); | |
837 | break; | |
838 | case WM9713_PCMCLK_PLL_DIV: | |
839 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; | |
840 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div); | |
841 | break; | |
842 | case WM9713_HIFI_PLL_DIV: | |
843 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; | |
844 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div); | |
845 | break; | |
846 | default: | |
847 | return -EINVAL; | |
848 | } | |
849 | ||
850 | return 0; | |
851 | } | |
852 | ||
e550e17f | 853 | static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai, |
83ac08c0 LG |
854 | unsigned int fmt) |
855 | { | |
856 | struct snd_soc_codec *codec = codec_dai->codec; | |
857 | u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5; | |
858 | u16 reg = 0x8000; | |
859 | ||
860 | /* clock masters */ | |
861 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | |
862 | case SND_SOC_DAIFMT_CBM_CFM: | |
863 | reg |= 0x4000; | |
864 | gpio |= 0x0010; | |
865 | break; | |
866 | case SND_SOC_DAIFMT_CBM_CFS: | |
867 | reg |= 0x6000; | |
868 | gpio |= 0x0018; | |
869 | break; | |
870 | case SND_SOC_DAIFMT_CBS_CFS: | |
d133b0ce | 871 | reg |= 0x2000; |
83ac08c0 LG |
872 | gpio |= 0x001a; |
873 | break; | |
874 | case SND_SOC_DAIFMT_CBS_CFM: | |
875 | gpio |= 0x0012; | |
876 | break; | |
877 | } | |
878 | ||
879 | /* clock inversion */ | |
880 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | |
881 | case SND_SOC_DAIFMT_IB_IF: | |
882 | reg |= 0x00c0; | |
883 | break; | |
884 | case SND_SOC_DAIFMT_IB_NF: | |
885 | reg |= 0x0080; | |
886 | break; | |
887 | case SND_SOC_DAIFMT_NB_IF: | |
888 | reg |= 0x0040; | |
889 | break; | |
890 | } | |
891 | ||
892 | /* DAI format */ | |
893 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
894 | case SND_SOC_DAIFMT_I2S: | |
895 | reg |= 0x0002; | |
896 | break; | |
897 | case SND_SOC_DAIFMT_RIGHT_J: | |
898 | break; | |
899 | case SND_SOC_DAIFMT_LEFT_J: | |
900 | reg |= 0x0001; | |
901 | break; | |
902 | case SND_SOC_DAIFMT_DSP_A: | |
903 | reg |= 0x0003; | |
904 | break; | |
905 | case SND_SOC_DAIFMT_DSP_B: | |
906 | reg |= 0x0043; | |
907 | break; | |
908 | } | |
909 | ||
910 | ac97_write(codec, AC97_GPIO_CFG, gpio); | |
911 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); | |
912 | return 0; | |
913 | } | |
914 | ||
915 | static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, | |
dee89c4d MB |
916 | struct snd_pcm_hw_params *params, |
917 | struct snd_soc_dai *dai) | |
83ac08c0 | 918 | { |
55b8bac5 | 919 | struct snd_soc_codec *codec = dai->codec; |
83ac08c0 LG |
920 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3; |
921 | ||
922 | switch (params_format(params)) { | |
923 | case SNDRV_PCM_FORMAT_S16_LE: | |
924 | break; | |
925 | case SNDRV_PCM_FORMAT_S20_3LE: | |
926 | reg |= 0x0004; | |
927 | break; | |
928 | case SNDRV_PCM_FORMAT_S24_LE: | |
929 | reg |= 0x0008; | |
930 | break; | |
931 | case SNDRV_PCM_FORMAT_S32_LE: | |
932 | reg |= 0x000c; | |
933 | break; | |
934 | } | |
935 | ||
936 | /* enable PCM interface in master mode */ | |
937 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); | |
938 | return 0; | |
939 | } | |
940 | ||
dee89c4d MB |
941 | static void wm9713_voiceshutdown(struct snd_pcm_substream *substream, |
942 | struct snd_soc_dai *dai) | |
83ac08c0 | 943 | { |
55b8bac5 | 944 | struct snd_soc_codec *codec = dai->codec; |
d540de4c MB |
945 | u16 status; |
946 | ||
947 | /* Gracefully shut down the voice interface. */ | |
948 | status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; | |
949 | ac97_write(codec, AC97_HANDSET_RATE, 0x0280); | |
950 | schedule_timeout_interruptible(msecs_to_jiffies(1)); | |
951 | ac97_write(codec, AC97_HANDSET_RATE, 0x0F80); | |
952 | ac97_write(codec, AC97_EXTENDED_MID, status); | |
83ac08c0 LG |
953 | } |
954 | ||
dee89c4d MB |
955 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream, |
956 | struct snd_soc_dai *dai) | |
83ac08c0 | 957 | { |
55b8bac5 | 958 | struct snd_soc_codec *codec = dai->codec; |
83ac08c0 | 959 | struct snd_pcm_runtime *runtime = substream->runtime; |
83ac08c0 LG |
960 | int reg; |
961 | u16 vra; | |
962 | ||
963 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | |
964 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); | |
965 | ||
966 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
967 | reg = AC97_PCM_FRONT_DAC_RATE; | |
968 | else | |
969 | reg = AC97_PCM_LR_ADC_RATE; | |
970 | ||
971 | return ac97_write(codec, reg, runtime->rate); | |
972 | } | |
973 | ||
dee89c4d MB |
974 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
975 | struct snd_soc_dai *dai) | |
83ac08c0 | 976 | { |
55b8bac5 | 977 | struct snd_soc_codec *codec = dai->codec; |
83ac08c0 | 978 | struct snd_pcm_runtime *runtime = substream->runtime; |
83ac08c0 LG |
979 | u16 vra, xsle; |
980 | ||
981 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | |
982 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); | |
983 | xsle = ac97_read(codec, AC97_PCI_SID); | |
984 | ac97_write(codec, AC97_PCI_SID, xsle | 0x8000); | |
985 | ||
986 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) | |
987 | return -ENODEV; | |
988 | ||
989 | return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate); | |
990 | } | |
991 | ||
5415552d MB |
992 | #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \ |
993 | SNDRV_PCM_RATE_11025 | \ | |
994 | SNDRV_PCM_RATE_22050 | \ | |
995 | SNDRV_PCM_RATE_44100 | \ | |
996 | SNDRV_PCM_RATE_48000) | |
997 | ||
998 | #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \ | |
999 | SNDRV_PCM_RATE_11025 | \ | |
1000 | SNDRV_PCM_RATE_16000 | \ | |
1001 | SNDRV_PCM_RATE_22050 | \ | |
1002 | SNDRV_PCM_RATE_44100 | \ | |
1003 | SNDRV_PCM_RATE_48000) | |
83ac08c0 LG |
1004 | |
1005 | #define WM9713_PCM_FORMATS \ | |
1006 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ | |
1007 | SNDRV_PCM_FORMAT_S24_LE) | |
1008 | ||
e550e17f | 1009 | struct snd_soc_dai wm9713_dai[] = { |
83ac08c0 LG |
1010 | { |
1011 | .name = "AC97 HiFi", | |
3ba9e10a | 1012 | .ac97_control = 1, |
83ac08c0 LG |
1013 | .playback = { |
1014 | .stream_name = "HiFi Playback", | |
1015 | .channels_min = 1, | |
1016 | .channels_max = 2, | |
1017 | .rates = WM9713_RATES, | |
1018 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
1019 | .capture = { | |
1020 | .stream_name = "HiFi Capture", | |
1021 | .channels_min = 1, | |
1022 | .channels_max = 2, | |
1023 | .rates = WM9713_RATES, | |
1024 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
1025 | .ops = { | |
dee89c4d | 1026 | .prepare = ac97_hifi_prepare, |
83ac08c0 LG |
1027 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1028 | .set_pll = wm9713_set_dai_pll,}, | |
1029 | }, | |
1030 | { | |
1031 | .name = "AC97 Aux", | |
1032 | .playback = { | |
1033 | .stream_name = "Aux Playback", | |
1034 | .channels_min = 1, | |
1035 | .channels_max = 1, | |
1036 | .rates = WM9713_RATES, | |
1037 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
1038 | .ops = { | |
dee89c4d | 1039 | .prepare = ac97_aux_prepare, |
83ac08c0 LG |
1040 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1041 | .set_pll = wm9713_set_dai_pll,}, | |
1042 | }, | |
1043 | { | |
1044 | .name = "WM9713 Voice", | |
1045 | .playback = { | |
1046 | .stream_name = "Voice Playback", | |
1047 | .channels_min = 1, | |
1048 | .channels_max = 1, | |
5415552d | 1049 | .rates = WM9713_PCM_RATES, |
83ac08c0 LG |
1050 | .formats = WM9713_PCM_FORMATS,}, |
1051 | .capture = { | |
1052 | .stream_name = "Voice Capture", | |
1053 | .channels_min = 1, | |
1054 | .channels_max = 2, | |
5415552d | 1055 | .rates = WM9713_PCM_RATES, |
83ac08c0 LG |
1056 | .formats = WM9713_PCM_FORMATS,}, |
1057 | .ops = { | |
1058 | .hw_params = wm9713_pcm_hw_params, | |
dee89c4d | 1059 | .shutdown = wm9713_voiceshutdown, |
83ac08c0 LG |
1060 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1061 | .set_pll = wm9713_set_dai_pll, | |
1062 | .set_fmt = wm9713_set_dai_fmt, | |
1063 | .set_tristate = wm9713_set_dai_tristate, | |
1064 | }, | |
1065 | }, | |
1066 | }; | |
1067 | EXPORT_SYMBOL_GPL(wm9713_dai); | |
1068 | ||
1069 | int wm9713_reset(struct snd_soc_codec *codec, int try_warm) | |
1070 | { | |
1071 | if (try_warm && soc_ac97_ops.warm_reset) { | |
1072 | soc_ac97_ops.warm_reset(codec->ac97); | |
abb68c26 | 1073 | if (ac97_read(codec, 0) == wm9713_reg[0]) |
83ac08c0 LG |
1074 | return 1; |
1075 | } | |
1076 | ||
1077 | soc_ac97_ops.reset(codec->ac97); | |
e775f6c0 MB |
1078 | if (soc_ac97_ops.warm_reset) |
1079 | soc_ac97_ops.warm_reset(codec->ac97); | |
abb68c26 | 1080 | if (ac97_read(codec, 0) != wm9713_reg[0]) |
83ac08c0 LG |
1081 | return -EIO; |
1082 | return 0; | |
1083 | } | |
1084 | EXPORT_SYMBOL_GPL(wm9713_reset); | |
1085 | ||
0be9898a MB |
1086 | static int wm9713_set_bias_level(struct snd_soc_codec *codec, |
1087 | enum snd_soc_bias_level level) | |
83ac08c0 LG |
1088 | { |
1089 | u16 reg; | |
1090 | ||
0be9898a MB |
1091 | switch (level) { |
1092 | case SND_SOC_BIAS_ON: | |
83ac08c0 LG |
1093 | /* enable thermal shutdown */ |
1094 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff; | |
1095 | ac97_write(codec, AC97_EXTENDED_MID, reg); | |
1096 | break; | |
0be9898a | 1097 | case SND_SOC_BIAS_PREPARE: |
83ac08c0 | 1098 | break; |
0be9898a | 1099 | case SND_SOC_BIAS_STANDBY: |
83ac08c0 LG |
1100 | /* enable master bias and vmid */ |
1101 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff; | |
1102 | ac97_write(codec, AC97_EXTENDED_MID, reg); | |
1103 | ac97_write(codec, AC97_POWERDOWN, 0x0000); | |
1104 | break; | |
0be9898a | 1105 | case SND_SOC_BIAS_OFF: |
83ac08c0 LG |
1106 | /* disable everything including AC link */ |
1107 | ac97_write(codec, AC97_EXTENDED_MID, 0xffff); | |
1108 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); | |
1109 | ac97_write(codec, AC97_POWERDOWN, 0xffff); | |
1110 | break; | |
1111 | } | |
0be9898a | 1112 | codec->bias_level = level; |
83ac08c0 LG |
1113 | return 0; |
1114 | } | |
1115 | ||
1116 | static int wm9713_soc_suspend(struct platform_device *pdev, | |
1117 | pm_message_t state) | |
1118 | { | |
1119 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
1120 | struct snd_soc_codec *codec = socdev->codec; | |
87b57fe2 MB |
1121 | u16 reg; |
1122 | ||
1123 | /* Disable everything except touchpanel - that will be handled | |
1124 | * by the touch driver and left disabled if touch is not in | |
1125 | * use. */ | |
1126 | reg = ac97_read(codec, AC97_EXTENDED_MID); | |
1127 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff); | |
1128 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); | |
1129 | ac97_write(codec, AC97_POWERDOWN, 0x6f00); | |
1130 | ac97_write(codec, AC97_POWERDOWN, 0xffff); | |
83ac08c0 | 1131 | |
83ac08c0 LG |
1132 | return 0; |
1133 | } | |
1134 | ||
1135 | static int wm9713_soc_resume(struct platform_device *pdev) | |
1136 | { | |
1137 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
1138 | struct snd_soc_codec *codec = socdev->codec; | |
1139 | struct wm9713_priv *wm9713 = codec->private_data; | |
1140 | int i, ret; | |
1141 | u16 *cache = codec->reg_cache; | |
1142 | ||
1143 | ret = wm9713_reset(codec, 1); | |
1144 | if (ret < 0) { | |
1145 | printk(KERN_ERR "could not reset AC97 codec\n"); | |
1146 | return ret; | |
1147 | } | |
1148 | ||
0be9898a | 1149 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
83ac08c0 LG |
1150 | |
1151 | /* do we need to re-start the PLL ? */ | |
1152 | if (wm9713->pll_out) | |
1153 | wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out); | |
1154 | ||
1155 | /* only synchronise the codec if warm reset failed */ | |
1156 | if (ret == 0) { | |
1157 | for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) { | |
1158 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID || | |
1159 | i == AC97_EXTENDED_MSTATUS || i > 0x66) | |
1160 | continue; | |
1161 | soc_ac97_ops.write(codec->ac97, i, cache[i>>1]); | |
1162 | } | |
1163 | } | |
1164 | ||
0be9898a MB |
1165 | if (codec->suspend_bias_level == SND_SOC_BIAS_ON) |
1166 | wm9713_set_bias_level(codec, SND_SOC_BIAS_ON); | |
83ac08c0 LG |
1167 | |
1168 | return ret; | |
1169 | } | |
1170 | ||
1171 | static int wm9713_soc_probe(struct platform_device *pdev) | |
1172 | { | |
1173 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
1174 | struct snd_soc_codec *codec; | |
1175 | int ret = 0, reg; | |
1176 | ||
1177 | printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION); | |
1178 | ||
1179 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | |
1180 | if (socdev->codec == NULL) | |
1181 | return -ENOMEM; | |
1182 | codec = socdev->codec; | |
1183 | mutex_init(&codec->mutex); | |
1184 | ||
1185 | codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); | |
1186 | if (codec->reg_cache == NULL) { | |
1187 | ret = -ENOMEM; | |
1188 | goto cache_err; | |
1189 | } | |
1190 | codec->reg_cache_size = sizeof(wm9713_reg); | |
1191 | codec->reg_cache_step = 2; | |
1192 | ||
1193 | codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL); | |
1194 | if (codec->private_data == NULL) { | |
1195 | ret = -ENOMEM; | |
1196 | goto priv_err; | |
1197 | } | |
1198 | ||
1199 | codec->name = "WM9713"; | |
1200 | codec->owner = THIS_MODULE; | |
1201 | codec->dai = wm9713_dai; | |
1202 | codec->num_dai = ARRAY_SIZE(wm9713_dai); | |
1203 | codec->write = ac97_write; | |
1204 | codec->read = ac97_read; | |
0be9898a | 1205 | codec->set_bias_level = wm9713_set_bias_level; |
83ac08c0 LG |
1206 | INIT_LIST_HEAD(&codec->dapm_widgets); |
1207 | INIT_LIST_HEAD(&codec->dapm_paths); | |
1208 | ||
1209 | ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); | |
1210 | if (ret < 0) | |
1211 | goto codec_err; | |
1212 | ||
1213 | /* register pcms */ | |
1214 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | |
1215 | if (ret < 0) | |
1216 | goto pcm_err; | |
1217 | ||
1218 | /* do a cold reset for the controller and then try | |
1219 | * a warm reset followed by an optional cold reset for codec */ | |
1220 | wm9713_reset(codec, 0); | |
1221 | ret = wm9713_reset(codec, 1); | |
1222 | if (ret < 0) { | |
39639fab | 1223 | printk(KERN_ERR "Failed to reset WM9713: AC97 link error\n"); |
83ac08c0 LG |
1224 | goto reset_err; |
1225 | } | |
1226 | ||
0be9898a | 1227 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
83ac08c0 LG |
1228 | |
1229 | /* unmute the adc - move to kcontrol */ | |
1230 | reg = ac97_read(codec, AC97_CD) & 0x7fff; | |
1231 | ac97_write(codec, AC97_CD, reg); | |
1232 | ||
3e8e1952 IM |
1233 | snd_soc_add_controls(codec, wm9713_snd_ac97_controls, |
1234 | ARRAY_SIZE(wm9713_snd_ac97_controls)); | |
83ac08c0 | 1235 | wm9713_add_widgets(codec); |
968a6025 | 1236 | ret = snd_soc_init_card(socdev); |
83ac08c0 LG |
1237 | if (ret < 0) |
1238 | goto reset_err; | |
1239 | return 0; | |
1240 | ||
1241 | reset_err: | |
1242 | snd_soc_free_pcms(socdev); | |
1243 | ||
1244 | pcm_err: | |
1245 | snd_soc_free_ac97_codec(codec); | |
1246 | ||
1247 | codec_err: | |
1248 | kfree(codec->private_data); | |
1249 | ||
1250 | priv_err: | |
1251 | kfree(codec->reg_cache); | |
1252 | ||
1253 | cache_err: | |
1254 | kfree(socdev->codec); | |
1255 | socdev->codec = NULL; | |
1256 | return ret; | |
1257 | } | |
1258 | ||
1259 | static int wm9713_soc_remove(struct platform_device *pdev) | |
1260 | { | |
1261 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
1262 | struct snd_soc_codec *codec = socdev->codec; | |
1263 | ||
1264 | if (codec == NULL) | |
1265 | return 0; | |
1266 | ||
1267 | snd_soc_dapm_free(socdev); | |
1268 | snd_soc_free_pcms(socdev); | |
1269 | snd_soc_free_ac97_codec(codec); | |
1270 | kfree(codec->private_data); | |
1271 | kfree(codec->reg_cache); | |
83ac08c0 LG |
1272 | kfree(codec); |
1273 | return 0; | |
1274 | } | |
1275 | ||
1276 | struct snd_soc_codec_device soc_codec_dev_wm9713 = { | |
1277 | .probe = wm9713_soc_probe, | |
1278 | .remove = wm9713_soc_remove, | |
1279 | .suspend = wm9713_soc_suspend, | |
1280 | .resume = wm9713_soc_resume, | |
1281 | }; | |
1282 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713); | |
1283 | ||
1284 | MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver"); | |
1285 | MODULE_AUTHOR("Liam Girdwood"); | |
1286 | MODULE_LICENSE("GPL"); |