2 * wm9713.c -- ALSA Soc WM9713 codec support
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
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.
14 * o Support for AC97 Codec, Voice DAC and Aux DAC
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/tlv.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dapm.h>
33 u32 pll_in
; /* PLL input frequency */
36 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
38 static int ac97_write(struct snd_soc_codec
*codec
,
39 unsigned int reg
, unsigned int val
);
42 * WM9713 register cache
43 * Reg 0x3c bit 15 is used by touch driver.
45 static const u16 wm9713_reg
[] = {
46 0x6174, 0x8080, 0x8080, 0x8080,
47 0xc880, 0xe808, 0xe808, 0x0808,
48 0x00da, 0x8000, 0xd600, 0xaaa0,
49 0xaaa0, 0xaaa0, 0x0000, 0x0000,
50 0x0f0f, 0x0040, 0x0000, 0x7f00,
51 0x0405, 0x0410, 0xbb80, 0xbb80,
52 0x0000, 0xbb80, 0x0000, 0x4523,
53 0x0000, 0x2000, 0x7eff, 0xffff,
54 0x0000, 0x0000, 0x0080, 0x0000,
55 0x0000, 0x0000, 0xfffe, 0xffff,
56 0x0000, 0x0000, 0x0000, 0xfffe,
57 0x4000, 0x0000, 0x0000, 0x0000,
58 0xb032, 0x3e00, 0x0000, 0x0000,
59 0x0000, 0x0000, 0x0000, 0x0000,
60 0x0000, 0x0000, 0x0000, 0x0006,
61 0x0001, 0x0000, 0x574d, 0x4c13,
62 0x0000, 0x0000, 0x0000
65 /* virtual HP mixers regs */
66 #define HPL_MIXER 0x80
67 #define HPR_MIXER 0x82
70 static const char *wm9713_mic_mixer
[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
71 static const char *wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
72 static const char *wm9713_rec_src
[] =
73 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
75 static const char *wm9713_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
76 static const char *wm9713_alc_select
[] = {"None", "Left", "Right", "Stereo"};
77 static const char *wm9713_mono_pga
[] = {"Vmid", "Zh", "Mono", "Inv",
78 "Mono Vmid", "Inv Vmid"};
79 static const char *wm9713_spk_pga
[] =
80 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
81 "Speaker Vmid", "Inv Vmid"};
82 static const char *wm9713_hp_pga
[] = {"Vmid", "Zh", "Headphone",
84 static const char *wm9713_out3_pga
[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
85 static const char *wm9713_out4_pga
[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
86 static const char *wm9713_dac_inv
[] =
87 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
88 "Headphone Mono", "NC", "Vmid"};
89 static const char *wm9713_bass
[] = {"Linear Control", "Adaptive Boost"};
90 static const char *wm9713_ng_type
[] = {"Constant Gain", "Mute"};
91 static const char *wm9713_mic_select
[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
92 static const char *wm9713_micb_select
[] = {"MPB", "MPA"};
94 static const struct soc_enum wm9713_enum
[] = {
95 SOC_ENUM_SINGLE(AC97_LINE
, 3, 4, wm9713_mic_mixer
), /* record mic mixer 0 */
96 SOC_ENUM_SINGLE(AC97_VIDEO
, 14, 4, wm9713_rec_mux
), /* record mux hp 1 */
97 SOC_ENUM_SINGLE(AC97_VIDEO
, 9, 4, wm9713_rec_mux
), /* record mux mono 2 */
98 SOC_ENUM_SINGLE(AC97_VIDEO
, 3, 8, wm9713_rec_src
), /* record mux left 3 */
99 SOC_ENUM_SINGLE(AC97_VIDEO
, 0, 8, wm9713_rec_src
), /* record mux right 4*/
100 SOC_ENUM_DOUBLE(AC97_CD
, 14, 6, 2, wm9713_rec_gain
), /* record step size 5 */
101 SOC_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9713_alc_select
), /* alc source select 6*/
102 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 14, 4, wm9713_mono_pga
), /* mono input select 7 */
103 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 11, 8, wm9713_spk_pga
), /* speaker left input select 8 */
104 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 8, 8, wm9713_spk_pga
), /* speaker right input select 9 */
105 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 6, 3, wm9713_hp_pga
), /* headphone left input 10 */
106 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 4, 3, wm9713_hp_pga
), /* headphone right input 11 */
107 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 2, 4, wm9713_out3_pga
), /* out 3 source 12 */
108 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 0, 4, wm9713_out4_pga
), /* out 4 source 13 */
109 SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC
, 13, 8, wm9713_dac_inv
), /* dac invert 1 14 */
110 SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC
, 10, 8, wm9713_dac_inv
), /* dac invert 2 15 */
111 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE
, 15, 2, wm9713_bass
), /* bass control 16 */
112 SOC_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9713_ng_type
), /* noise gate type 17 */
113 SOC_ENUM_SINGLE(AC97_3D_CONTROL
, 12, 3, wm9713_mic_select
), /* mic selection 18 */
114 SOC_ENUM_SINGLE(MICB_MUX
, 0, 2, wm9713_micb_select
), /* mic selection 19 */
117 static const DECLARE_TLV_DB_SCALE(out_tlv
, -4650, 150, 0);
118 static const DECLARE_TLV_DB_SCALE(main_tlv
, -3450, 150, 0);
119 static const DECLARE_TLV_DB_SCALE(misc_tlv
, -1500, 300, 0);
120 static unsigned int mic_tlv
[] = {
121 TLV_DB_RANGE_HEAD(2),
122 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0),
123 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0),
126 static const struct snd_kcontrol_new wm9713_snd_ac97_controls
[] = {
127 SOC_DOUBLE_TLV("Speaker Playback Volume", AC97_MASTER
, 8, 0, 31, 1, out_tlv
),
128 SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER
, 15, 7, 1, 1),
129 SOC_DOUBLE_TLV("Headphone Playback Volume", AC97_HEADPHONE
, 8, 0, 31, 1,
131 SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE
, 15, 7, 1, 1),
132 SOC_DOUBLE_TLV("Line In Volume", AC97_PC_BEEP
, 8, 0, 31, 1, main_tlv
),
133 SOC_DOUBLE_TLV("PCM Playback Volume", AC97_PHONE
, 8, 0, 31, 1, main_tlv
),
134 SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC
, 8, 31, 1, main_tlv
),
135 SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC
, 0, 31, 1, main_tlv
),
136 SOC_SINGLE_TLV("Mic 1 Preamp Volume", AC97_3D_CONTROL
, 10, 3, 0, mic_tlv
),
137 SOC_SINGLE_TLV("Mic 2 Preamp Volume", AC97_3D_CONTROL
, 12, 3, 0, mic_tlv
),
139 SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE
, 5, 1, 0),
140 SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE
, 0, 7, 1),
142 SOC_SINGLE("Capture Switch", AC97_CD
, 15, 1, 1),
143 SOC_ENUM("Capture Volume Steps", wm9713_enum
[5]),
144 SOC_DOUBLE("Capture Volume", AC97_CD
, 8, 0, 31, 0),
145 SOC_SINGLE("Capture ZC Switch", AC97_CD
, 7, 1, 0),
147 SOC_SINGLE_TLV("Capture to Headphone Volume", AC97_VIDEO
, 11, 7, 1, misc_tlv
),
148 SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO
, 8, 1, 0),
149 SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO
, 6, 1, 0),
151 SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
152 SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
153 SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV
, 4, 15, 0),
154 SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
155 SOC_ENUM("ALC Function", wm9713_enum
[6]),
156 SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 0),
157 SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 0),
158 SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
159 SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
160 SOC_ENUM("ALC NG Type", wm9713_enum
[17]),
161 SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 0),
163 SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER
, 14, 6, 1, 0),
164 SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE
, 14, 6, 1, 0),
166 SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO
, 15, 1, 1),
167 SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO
, 14, 1, 0),
168 SOC_SINGLE_TLV("Out4 Playback Volume", AC97_MASTER_MONO
, 8, 31, 1, out_tlv
),
170 SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO
, 7, 1, 1),
171 SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO
, 6, 1, 0),
172 SOC_SINGLE_TLV("Out3 Playback Volume", AC97_MASTER_MONO
, 0, 31, 1, out_tlv
),
174 SOC_SINGLE_TLV("Mono Capture Volume", AC97_MASTER_TONE
, 8, 31, 1, main_tlv
),
175 SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE
, 7, 1, 1),
176 SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE
, 6, 1, 0),
177 SOC_SINGLE_TLV("Mono Playback Volume", AC97_MASTER_TONE
, 0, 31, 1, out_tlv
),
179 SOC_SINGLE_TLV("Headphone Mixer Beep Playback Volume", AC97_AUX
, 12, 7, 1,
181 SOC_SINGLE_TLV("Speaker Mixer Beep Playback Volume", AC97_AUX
, 8, 7, 1,
183 SOC_SINGLE_TLV("Mono Mixer Beep Playback Volume", AC97_AUX
, 4, 7, 1, misc_tlv
),
185 SOC_SINGLE_TLV("Voice Playback Headphone Volume", AC97_PCM
, 12, 7, 1,
187 SOC_SINGLE("Voice Playback Master Volume", AC97_PCM
, 8, 7, 1),
188 SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM
, 4, 7, 1),
190 SOC_SINGLE_TLV("Headphone Mixer Aux Playback Volume", AC97_REC_SEL
, 12, 7, 1,
193 SOC_SINGLE_TLV("Speaker Mixer Voice Playback Volume", AC97_PCM
, 8, 7, 1,
195 SOC_SINGLE_TLV("Speaker Mixer Aux Playback Volume", AC97_REC_SEL
, 8, 7, 1,
198 SOC_SINGLE_TLV("Mono Mixer Voice Playback Volume", AC97_PCM
, 4, 7, 1,
200 SOC_SINGLE_TLV("Mono Mixer Aux Playback Volume", AC97_REC_SEL
, 4, 7, 1,
203 SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL
, 12, 7, 1),
204 SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL
, 8, 7, 1),
206 SOC_ENUM("Bass Control", wm9713_enum
[16]),
207 SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE
, 12, 1, 1),
208 SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE
, 4, 1, 1),
209 SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE
, 6, 1, 0),
210 SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE
, 8, 15, 1),
211 SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE
, 0, 15, 1),
213 SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC
, 5, 1, 0),
214 SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC
, 4, 1, 0),
215 SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC
, 0, 15, 1),
218 static int wm9713_voice_shutdown(struct snd_soc_dapm_widget
*w
,
219 struct snd_kcontrol
*kcontrol
, int event
)
221 struct snd_soc_codec
*codec
= w
->codec
;
224 BUG_ON(event
!= SND_SOC_DAPM_PRE_PMD
);
226 /* Gracefully shut down the voice interface. */
227 status
= ac97_read(codec
, AC97_EXTENDED_MID
) | 0x1000;
228 rate
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xF0FF;
229 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0200);
230 schedule_timeout_interruptible(msecs_to_jiffies(1));
231 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0F00);
232 ac97_write(codec
, AC97_EXTENDED_MID
, status
);
238 /* We have to create a fake left and right HP mixers because
239 * the codec only has a single control that is shared by both channels.
240 * This makes it impossible to determine the audio path using the current
241 * register map, thus we add a new (virtual) register to help determine the
242 * audio route within the device.
244 static int mixer_event(struct snd_soc_dapm_widget
*w
,
245 struct snd_kcontrol
*kcontrol
, int event
)
247 u16 l
, r
, beep
, tone
, phone
, rec
, pcm
, aux
;
249 l
= ac97_read(w
->codec
, HPL_MIXER
);
250 r
= ac97_read(w
->codec
, HPR_MIXER
);
251 beep
= ac97_read(w
->codec
, AC97_PC_BEEP
);
252 tone
= ac97_read(w
->codec
, AC97_MASTER_TONE
);
253 phone
= ac97_read(w
->codec
, AC97_PHONE
);
254 rec
= ac97_read(w
->codec
, AC97_REC_SEL
);
255 pcm
= ac97_read(w
->codec
, AC97_PCM
);
256 aux
= ac97_read(w
->codec
, AC97_AUX
);
258 if (event
& SND_SOC_DAPM_PRE_REG
)
260 if ((l
& 0x1) || (r
& 0x1))
261 ac97_write(w
->codec
, AC97_PC_BEEP
, beep
& 0x7fff);
263 ac97_write(w
->codec
, AC97_PC_BEEP
, beep
| 0x8000);
265 if ((l
& 0x2) || (r
& 0x2))
266 ac97_write(w
->codec
, AC97_MASTER_TONE
, tone
& 0x7fff);
268 ac97_write(w
->codec
, AC97_MASTER_TONE
, tone
| 0x8000);
270 if ((l
& 0x4) || (r
& 0x4))
271 ac97_write(w
->codec
, AC97_PHONE
, phone
& 0x7fff);
273 ac97_write(w
->codec
, AC97_PHONE
, phone
| 0x8000);
275 if ((l
& 0x8) || (r
& 0x8))
276 ac97_write(w
->codec
, AC97_REC_SEL
, rec
& 0x7fff);
278 ac97_write(w
->codec
, AC97_REC_SEL
, rec
| 0x8000);
280 if ((l
& 0x10) || (r
& 0x10))
281 ac97_write(w
->codec
, AC97_PCM
, pcm
& 0x7fff);
283 ac97_write(w
->codec
, AC97_PCM
, pcm
| 0x8000);
285 if ((l
& 0x20) || (r
& 0x20))
286 ac97_write(w
->codec
, AC97_AUX
, aux
& 0x7fff);
288 ac97_write(w
->codec
, AC97_AUX
, aux
| 0x8000);
293 /* Left Headphone Mixers */
294 static const struct snd_kcontrol_new wm9713_hpl_mixer_controls
[] = {
295 SOC_DAPM_SINGLE("Beep Playback Switch", HPL_MIXER
, 5, 1, 0),
296 SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER
, 4, 1, 0),
297 SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER
, 3, 1, 0),
298 SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER
, 2, 1, 0),
299 SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER
, 1, 1, 0),
300 SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER
, 0, 1, 0),
303 /* Right Headphone Mixers */
304 static const struct snd_kcontrol_new wm9713_hpr_mixer_controls
[] = {
305 SOC_DAPM_SINGLE("Beep Playback Switch", HPR_MIXER
, 5, 1, 0),
306 SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER
, 4, 1, 0),
307 SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER
, 3, 1, 0),
308 SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER
, 2, 1, 0),
309 SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER
, 1, 1, 0),
310 SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER
, 0, 1, 0),
313 /* headphone capture mux */
314 static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls
=
315 SOC_DAPM_ENUM("Route", wm9713_enum
[1]);
317 /* headphone mic mux */
318 static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls
=
319 SOC_DAPM_ENUM("Route", wm9713_enum
[0]);
322 static const struct snd_kcontrol_new wm9713_speaker_mixer_controls
[] = {
323 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 11, 1, 1),
324 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 11, 1, 1),
325 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 11, 1, 1),
326 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 14, 1, 1),
327 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 14, 1, 1),
328 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 14, 1, 1),
332 static const struct snd_kcontrol_new wm9713_mono_mixer_controls
[] = {
333 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 7, 1, 1),
334 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 7, 1, 1),
335 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 7, 1, 1),
336 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 13, 1, 1),
337 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 13, 1, 1),
338 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 13, 1, 1),
339 SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE
, 7, 1, 1),
340 SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE
, 6, 1, 1),
344 static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls
=
345 SOC_DAPM_ENUM("Route", wm9713_enum
[2]);
347 /* mono output mux */
348 static const struct snd_kcontrol_new wm9713_mono_mux_controls
=
349 SOC_DAPM_ENUM("Route", wm9713_enum
[7]);
351 /* speaker left output mux */
352 static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls
=
353 SOC_DAPM_ENUM("Route", wm9713_enum
[8]);
355 /* speaker right output mux */
356 static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls
=
357 SOC_DAPM_ENUM("Route", wm9713_enum
[9]);
359 /* headphone left output mux */
360 static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls
=
361 SOC_DAPM_ENUM("Route", wm9713_enum
[10]);
363 /* headphone right output mux */
364 static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls
=
365 SOC_DAPM_ENUM("Route", wm9713_enum
[11]);
368 static const struct snd_kcontrol_new wm9713_out3_mux_controls
=
369 SOC_DAPM_ENUM("Route", wm9713_enum
[12]);
372 static const struct snd_kcontrol_new wm9713_out4_mux_controls
=
373 SOC_DAPM_ENUM("Route", wm9713_enum
[13]);
376 static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls
=
377 SOC_DAPM_ENUM("Route", wm9713_enum
[14]);
380 static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls
=
381 SOC_DAPM_ENUM("Route", wm9713_enum
[15]);
383 /* Capture source left */
384 static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls
=
385 SOC_DAPM_ENUM("Route", wm9713_enum
[3]);
387 /* Capture source right */
388 static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls
=
389 SOC_DAPM_ENUM("Route", wm9713_enum
[4]);
392 static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls
=
393 SOC_DAPM_ENUM("Route", wm9713_enum
[18]);
395 /* mic source B virtual control */
396 static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls
=
397 SOC_DAPM_ENUM("Route", wm9713_enum
[19]);
399 static const struct snd_soc_dapm_widget wm9713_dapm_widgets
[] = {
400 SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM
, 0, 0,
401 &wm9713_hp_rec_mux_controls
),
402 SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM
, 0, 0,
403 &wm9713_hp_mic_mux_controls
),
404 SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM
, 0, 0,
405 &wm9713_mono_mic_mux_controls
),
406 SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM
, 0, 0,
407 &wm9713_mono_mux_controls
),
408 SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
409 &wm9713_hp_spkl_mux_controls
),
410 SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
411 &wm9713_hp_spkr_mux_controls
),
412 SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
413 &wm9713_hpl_out_mux_controls
),
414 SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
415 &wm9713_hpr_out_mux_controls
),
416 SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM
, 0, 0,
417 &wm9713_out3_mux_controls
),
418 SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM
, 0, 0,
419 &wm9713_out4_mux_controls
),
420 SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM
, 0, 0,
421 &wm9713_dac_inv1_mux_controls
),
422 SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM
, 0, 0,
423 &wm9713_dac_inv2_mux_controls
),
424 SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM
, 0, 0,
425 &wm9713_rec_srcl_mux_controls
),
426 SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM
, 0, 0,
427 &wm9713_rec_srcr_mux_controls
),
428 SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM
, 0, 0,
429 &wm9713_mic_sel_mux_controls
),
430 SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM
, 0, 0,
431 &wm9713_micb_sel_mux_controls
),
432 SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID
, 3, 1,
433 &wm9713_hpl_mixer_controls
[0], ARRAY_SIZE(wm9713_hpl_mixer_controls
),
434 mixer_event
, SND_SOC_DAPM_POST_REG
),
435 SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID
, 2, 1,
436 &wm9713_hpr_mixer_controls
[0], ARRAY_SIZE(wm9713_hpr_mixer_controls
),
437 mixer_event
, SND_SOC_DAPM_POST_REG
),
438 SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID
, 0, 1,
439 &wm9713_mono_mixer_controls
[0], ARRAY_SIZE(wm9713_mono_mixer_controls
)),
440 SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID
, 1, 1,
441 &wm9713_speaker_mixer_controls
[0],
442 ARRAY_SIZE(wm9713_speaker_mixer_controls
)),
443 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID
, 7, 1),
444 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID
, 6, 1),
445 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
446 SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
447 SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
448 SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
449 SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID
, 12, 1,
450 wm9713_voice_shutdown
, SND_SOC_DAPM_PRE_PMD
),
451 SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID
, 11, 1),
452 SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID
, 5, 1, NULL
, 0),
453 SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID
, 4, 1, NULL
, 0),
454 SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM
, 0, 0),
455 SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM
, 0, 0),
456 SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM
, 0, 0),
457 SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM
, 0, 0),
458 SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS
, 10, 1, NULL
, 0),
459 SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS
, 9, 1, NULL
, 0),
460 SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS
, 8, 1, NULL
, 0),
461 SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS
, 7, 1, NULL
, 0),
462 SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS
, 11, 1, NULL
, 0),
463 SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS
, 12, 1, NULL
, 0),
464 SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS
, 13, 1, NULL
, 0),
465 SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS
, 6, 1, NULL
, 0),
466 SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS
, 5, 1, NULL
, 0),
467 SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS
, 4, 1, NULL
, 0),
468 SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS
, 3, 1, NULL
, 0),
469 SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS
, 2, 1, NULL
, 0),
470 SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS
, 1, 1, NULL
, 0),
471 SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS
, 0, 1, NULL
, 0),
472 SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS
, 14, 1),
473 SND_SOC_DAPM_OUTPUT("MONO"),
474 SND_SOC_DAPM_OUTPUT("HPL"),
475 SND_SOC_DAPM_OUTPUT("HPR"),
476 SND_SOC_DAPM_OUTPUT("SPKL"),
477 SND_SOC_DAPM_OUTPUT("SPKR"),
478 SND_SOC_DAPM_OUTPUT("OUT3"),
479 SND_SOC_DAPM_OUTPUT("OUT4"),
480 SND_SOC_DAPM_INPUT("LINEL"),
481 SND_SOC_DAPM_INPUT("LINER"),
482 SND_SOC_DAPM_INPUT("MONOIN"),
483 SND_SOC_DAPM_INPUT("PCBEEP"),
484 SND_SOC_DAPM_INPUT("MIC1"),
485 SND_SOC_DAPM_INPUT("MIC2A"),
486 SND_SOC_DAPM_INPUT("MIC2B"),
487 SND_SOC_DAPM_VMID("VMID"),
490 static const struct snd_soc_dapm_route audio_map
[] = {
492 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
493 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
494 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
495 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
496 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
497 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
498 {"Left HP Mixer", NULL
, "Capture Headphone Mux"},
501 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
502 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
503 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
504 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
505 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
506 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
507 {"Right HP Mixer", NULL
, "Capture Headphone Mux"},
509 /* virtual mixer - mixes left & right channels for spk and mono */
510 {"AC97 Mixer", NULL
, "Left DAC"},
511 {"AC97 Mixer", NULL
, "Right DAC"},
512 {"Line Mixer", NULL
, "Right Line In"},
513 {"Line Mixer", NULL
, "Left Line In"},
514 {"HP Mixer", NULL
, "Left HP Mixer"},
515 {"HP Mixer", NULL
, "Right HP Mixer"},
516 {"Capture Mixer", NULL
, "Left Capture Source"},
517 {"Capture Mixer", NULL
, "Right Capture Source"},
520 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
521 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
522 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
523 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
524 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
525 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
528 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
529 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
530 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
531 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
532 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
533 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
534 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
535 {"Mono Mixer", NULL
, "Capture Mono Mux"},
538 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
539 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
540 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
541 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
542 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
545 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
546 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
547 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
548 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
549 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
551 /* headphone left mux */
552 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
554 /* headphone right mux */
555 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
557 /* speaker left mux */
558 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
559 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
560 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
562 /* speaker right mux */
563 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
564 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
565 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
568 {"Mono Out Mux", "Mono", "Mono Mixer"},
569 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
572 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
575 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
578 {"HPL", NULL
, "Left Headphone"},
579 {"Left Headphone", NULL
, "Left Headphone Out Mux"},
580 {"HPR", NULL
, "Right Headphone"},
581 {"Right Headphone", NULL
, "Right Headphone Out Mux"},
582 {"OUT3", NULL
, "Out 3"},
583 {"Out 3", NULL
, "Out 3 Mux"},
584 {"OUT4", NULL
, "Out 4"},
585 {"Out 4", NULL
, "Out 4 Mux"},
586 {"SPKL", NULL
, "Left Speaker"},
587 {"Left Speaker", NULL
, "Left Speaker Out Mux"},
588 {"SPKR", NULL
, "Right Speaker"},
589 {"Right Speaker", NULL
, "Right Speaker Out Mux"},
590 {"MONO", NULL
, "Mono Out"},
591 {"Mono Out", NULL
, "Mono Out Mux"},
594 {"Left Line In", NULL
, "LINEL"},
595 {"Right Line In", NULL
, "LINER"},
596 {"Mono In", NULL
, "MONOIN"},
597 {"Mic A PGA", NULL
, "Mic A Pre Amp"},
598 {"Mic B PGA", NULL
, "Mic B Pre Amp"},
600 /* left capture select */
601 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
602 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
603 {"Left Capture Source", "Line", "LINEL"},
604 {"Left Capture Source", "Mono In", "MONOIN"},
605 {"Left Capture Source", "Headphone", "Left HP Mixer"},
606 {"Left Capture Source", "Speaker", "Speaker Mixer"},
607 {"Left Capture Source", "Mono Out", "Mono Mixer"},
609 /* right capture select */
610 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
611 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
612 {"Right Capture Source", "Line", "LINER"},
613 {"Right Capture Source", "Mono In", "MONOIN"},
614 {"Right Capture Source", "Headphone", "Right HP Mixer"},
615 {"Right Capture Source", "Speaker", "Speaker Mixer"},
616 {"Right Capture Source", "Mono Out", "Mono Mixer"},
619 {"Left ADC", NULL
, "Left Capture Source"},
620 {"Left Voice ADC", NULL
, "Left ADC"},
621 {"Left HiFi ADC", NULL
, "Left ADC"},
624 {"Right ADC", NULL
, "Right Capture Source"},
625 {"Right Voice ADC", NULL
, "Right ADC"},
626 {"Right HiFi ADC", NULL
, "Right ADC"},
629 {"Mic A Pre Amp", NULL
, "Mic A Source"},
630 {"Mic A Source", "Mic 1", "MIC1"},
631 {"Mic A Source", "Mic 2 A", "MIC2A"},
632 {"Mic A Source", "Mic 2 B", "Mic B Source"},
633 {"Mic B Pre Amp", "MPB", "Mic B Source"},
634 {"Mic B Source", NULL
, "MIC2B"},
636 /* headphone capture */
637 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
638 {"Capture Headphone Mux", "Left", "Left Capture Source"},
639 {"Capture Headphone Mux", "Right", "Right Capture Source"},
642 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
643 {"Capture Mono Mux", "Left", "Left Capture Source"},
644 {"Capture Mono Mux", "Right", "Right Capture Source"},
647 static int wm9713_add_widgets(struct snd_soc_codec
*codec
)
649 snd_soc_dapm_new_controls(codec
, wm9713_dapm_widgets
,
650 ARRAY_SIZE(wm9713_dapm_widgets
));
652 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
657 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
660 u16
*cache
= codec
->reg_cache
;
662 if (reg
== AC97_RESET
|| reg
== AC97_GPIO_STATUS
||
663 reg
== AC97_VENDOR_ID1
|| reg
== AC97_VENDOR_ID2
||
665 return soc_ac97_ops
.read(codec
->ac97
, reg
);
669 if (reg
>= (ARRAY_SIZE(wm9713_reg
)))
676 static int ac97_write(struct snd_soc_codec
*codec
, unsigned int reg
,
679 u16
*cache
= codec
->reg_cache
;
681 soc_ac97_ops
.write(codec
->ac97
, reg
, val
);
683 if (reg
< (ARRAY_SIZE(wm9713_reg
)))
698 /* The size in bits of the PLL divide multiplied by 10
699 * to allow rounding later */
700 #define FIXED_PLL_SIZE ((1 << 22) * 10)
702 static void pll_factors(struct _pll_div
*pll_div
, unsigned int source
)
705 unsigned int K
, Ndiv
, Nmod
, target
;
707 /* The the PLL output is always 98.304MHz. */
710 /* If the input frequency is over 14.4MHz then scale it down. */
711 if (source
> 14400000) {
715 if (source
> 14400000) {
726 /* Low frequency sources require an additional divide in the
729 if (source
< 8192000) {
735 Ndiv
= target
/ source
;
736 if ((Ndiv
< 5) || (Ndiv
> 12))
738 "WM9713 PLL N value %u out of recommended range!\n",
742 Nmod
= target
% source
;
743 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
745 do_div(Kpart
, source
);
747 K
= Kpart
& 0xFFFFFFFF;
749 /* Check if we need to round */
753 /* Move down to proper range now rounding is done */
760 * Please note that changing the PLL input frequency may require
761 * resynchronisation with the AC97 controller.
763 static int wm9713_set_pll(struct snd_soc_codec
*codec
,
764 int pll_id
, unsigned int freq_in
, unsigned int freq_out
)
766 struct wm9713_priv
*wm9713
= codec
->private_data
;
768 struct _pll_div pll_div
;
772 /* disable PLL power and select ext source */
773 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
774 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| 0x0080);
775 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
776 ac97_write(codec
, AC97_EXTENDED_MID
, reg
| 0x0200);
781 pll_factors(&pll_div
, freq_in
);
783 if (pll_div
.k
== 0) {
784 reg
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) |
785 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
786 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
788 /* write the fractional k to the reg 0x46 pages */
789 reg2
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) | (1 << 10) |
790 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
793 reg
= reg2
| (0x5 << 4) | (pll_div
.k
>> 20);
794 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
797 reg
= reg2
| (0x4 << 4) | ((pll_div
.k
>> 16) & 0xf);
798 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
801 reg
= reg2
| (0x3 << 4) | ((pll_div
.k
>> 12) & 0xf);
802 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
805 reg
= reg2
| (0x2 << 4) | ((pll_div
.k
>> 8) & 0xf);
806 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
809 reg
= reg2
| (0x1 << 4) | ((pll_div
.k
>> 4) & 0xf);
810 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
812 reg
= reg2
| (0x0 << 4) | (pll_div
.k
& 0xf); /* K [3:0] */
813 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
816 /* turn PLL on and select as source */
817 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
818 ac97_write(codec
, AC97_EXTENDED_MID
, reg
& 0xfdff);
819 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
820 ac97_write(codec
, AC97_HANDSET_RATE
, reg
& 0xff7f);
821 wm9713
->pll_in
= freq_in
;
823 /* wait 10ms AC97 link frames for the link to stabilise */
824 schedule_timeout_interruptible(msecs_to_jiffies(10));
828 static int wm9713_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
829 int source
, unsigned int freq_in
, unsigned int freq_out
)
831 struct snd_soc_codec
*codec
= codec_dai
->codec
;
832 return wm9713_set_pll(codec
, pll_id
, freq_in
, freq_out
);
836 * Tristate the PCM DAI lines, tristate can be disabled by calling
837 * wm9713_set_dai_fmt()
839 static int wm9713_set_dai_tristate(struct snd_soc_dai
*codec_dai
,
842 struct snd_soc_codec
*codec
= codec_dai
->codec
;
843 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0x9fff;
846 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
852 * Configure WM9713 clock dividers.
853 * Voice DAC needs 256 FS
855 static int wm9713_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
858 struct snd_soc_codec
*codec
= codec_dai
->codec
;
862 case WM9713_PCMCLK_DIV
:
863 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xf0ff;
864 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
866 case WM9713_CLKA_MULT
:
867 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffd;
868 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
870 case WM9713_CLKB_MULT
:
871 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffb;
872 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
874 case WM9713_HIFI_DIV
:
875 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0x8fff;
876 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
878 case WM9713_PCMBCLK_DIV
:
879 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xf1ff;
880 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
| div
);
882 case WM9713_PCMCLK_PLL_DIV
:
883 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
884 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x60 | div
);
886 case WM9713_HIFI_PLL_DIV
:
887 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
888 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x70 | div
);
897 static int wm9713_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
900 struct snd_soc_codec
*codec
= codec_dai
->codec
;
901 u16 gpio
= ac97_read(codec
, AC97_GPIO_CFG
) & 0xffc5;
905 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
906 case SND_SOC_DAIFMT_CBM_CFM
:
910 case SND_SOC_DAIFMT_CBM_CFS
:
914 case SND_SOC_DAIFMT_CBS_CFS
:
918 case SND_SOC_DAIFMT_CBS_CFM
:
923 /* clock inversion */
924 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
925 case SND_SOC_DAIFMT_IB_IF
:
928 case SND_SOC_DAIFMT_IB_NF
:
931 case SND_SOC_DAIFMT_NB_IF
:
937 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
938 case SND_SOC_DAIFMT_I2S
:
941 case SND_SOC_DAIFMT_RIGHT_J
:
943 case SND_SOC_DAIFMT_LEFT_J
:
946 case SND_SOC_DAIFMT_DSP_A
:
949 case SND_SOC_DAIFMT_DSP_B
:
954 ac97_write(codec
, AC97_GPIO_CFG
, gpio
);
955 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
959 static int wm9713_pcm_hw_params(struct snd_pcm_substream
*substream
,
960 struct snd_pcm_hw_params
*params
,
961 struct snd_soc_dai
*dai
)
963 struct snd_soc_codec
*codec
= dai
->codec
;
964 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xfff3;
966 switch (params_format(params
)) {
967 case SNDRV_PCM_FORMAT_S16_LE
:
969 case SNDRV_PCM_FORMAT_S20_3LE
:
972 case SNDRV_PCM_FORMAT_S24_LE
:
975 case SNDRV_PCM_FORMAT_S32_LE
:
980 /* enable PCM interface in master mode */
981 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
985 static int ac97_hifi_prepare(struct snd_pcm_substream
*substream
,
986 struct snd_soc_dai
*dai
)
988 struct snd_soc_codec
*codec
= dai
->codec
;
989 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
993 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
994 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
996 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
997 reg
= AC97_PCM_FRONT_DAC_RATE
;
999 reg
= AC97_PCM_LR_ADC_RATE
;
1001 return ac97_write(codec
, reg
, runtime
->rate
);
1004 static int ac97_aux_prepare(struct snd_pcm_substream
*substream
,
1005 struct snd_soc_dai
*dai
)
1007 struct snd_soc_codec
*codec
= dai
->codec
;
1008 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1011 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
1012 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
1013 xsle
= ac97_read(codec
, AC97_PCI_SID
);
1014 ac97_write(codec
, AC97_PCI_SID
, xsle
| 0x8000);
1016 if (substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1019 return ac97_write(codec
, AC97_PCM_SURR_DAC_RATE
, runtime
->rate
);
1022 #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \
1023 SNDRV_PCM_RATE_11025 | \
1024 SNDRV_PCM_RATE_22050 | \
1025 SNDRV_PCM_RATE_44100 | \
1026 SNDRV_PCM_RATE_48000)
1028 #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \
1029 SNDRV_PCM_RATE_11025 | \
1030 SNDRV_PCM_RATE_16000 | \
1031 SNDRV_PCM_RATE_22050 | \
1032 SNDRV_PCM_RATE_44100 | \
1033 SNDRV_PCM_RATE_48000)
1035 #define WM9713_PCM_FORMATS \
1036 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1037 SNDRV_PCM_FORMAT_S24_LE)
1039 static struct snd_soc_dai_ops wm9713_dai_ops_hifi
= {
1040 .prepare
= ac97_hifi_prepare
,
1041 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1042 .set_pll
= wm9713_set_dai_pll
,
1045 static struct snd_soc_dai_ops wm9713_dai_ops_aux
= {
1046 .prepare
= ac97_aux_prepare
,
1047 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1048 .set_pll
= wm9713_set_dai_pll
,
1051 static struct snd_soc_dai_ops wm9713_dai_ops_voice
= {
1052 .hw_params
= wm9713_pcm_hw_params
,
1053 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1054 .set_pll
= wm9713_set_dai_pll
,
1055 .set_fmt
= wm9713_set_dai_fmt
,
1056 .set_tristate
= wm9713_set_dai_tristate
,
1059 struct snd_soc_dai wm9713_dai
[] = {
1061 .name
= "AC97 HiFi",
1064 .stream_name
= "HiFi Playback",
1067 .rates
= WM9713_RATES
,
1068 .formats
= SND_SOC_STD_AC97_FMTS
,},
1070 .stream_name
= "HiFi Capture",
1073 .rates
= WM9713_RATES
,
1074 .formats
= SND_SOC_STD_AC97_FMTS
,},
1075 .ops
= &wm9713_dai_ops_hifi
,
1080 .stream_name
= "Aux Playback",
1083 .rates
= WM9713_RATES
,
1084 .formats
= SND_SOC_STD_AC97_FMTS
,},
1085 .ops
= &wm9713_dai_ops_aux
,
1088 .name
= "WM9713 Voice",
1090 .stream_name
= "Voice Playback",
1093 .rates
= WM9713_PCM_RATES
,
1094 .formats
= WM9713_PCM_FORMATS
,},
1096 .stream_name
= "Voice Capture",
1099 .rates
= WM9713_PCM_RATES
,
1100 .formats
= WM9713_PCM_FORMATS
,},
1101 .ops
= &wm9713_dai_ops_voice
,
1102 .symmetric_rates
= 1,
1105 EXPORT_SYMBOL_GPL(wm9713_dai
);
1107 int wm9713_reset(struct snd_soc_codec
*codec
, int try_warm
)
1109 if (try_warm
&& soc_ac97_ops
.warm_reset
) {
1110 soc_ac97_ops
.warm_reset(codec
->ac97
);
1111 if (ac97_read(codec
, 0) == wm9713_reg
[0])
1115 soc_ac97_ops
.reset(codec
->ac97
);
1116 if (soc_ac97_ops
.warm_reset
)
1117 soc_ac97_ops
.warm_reset(codec
->ac97
);
1118 if (ac97_read(codec
, 0) != wm9713_reg
[0])
1122 EXPORT_SYMBOL_GPL(wm9713_reset
);
1124 static int wm9713_set_bias_level(struct snd_soc_codec
*codec
,
1125 enum snd_soc_bias_level level
)
1130 case SND_SOC_BIAS_ON
:
1131 /* enable thermal shutdown */
1132 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x1bff;
1133 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1135 case SND_SOC_BIAS_PREPARE
:
1137 case SND_SOC_BIAS_STANDBY
:
1138 /* enable master bias and vmid */
1139 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x3bff;
1140 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1141 ac97_write(codec
, AC97_POWERDOWN
, 0x0000);
1143 case SND_SOC_BIAS_OFF
:
1144 /* disable everything including AC link */
1145 ac97_write(codec
, AC97_EXTENDED_MID
, 0xffff);
1146 ac97_write(codec
, AC97_EXTENDED_MSTATUS
, 0xffff);
1147 ac97_write(codec
, AC97_POWERDOWN
, 0xffff);
1150 codec
->bias_level
= level
;
1154 static int wm9713_soc_suspend(struct platform_device
*pdev
,
1157 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1158 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1161 /* Disable everything except touchpanel - that will be handled
1162 * by the touch driver and left disabled if touch is not in
1164 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
1165 ac97_write(codec
, AC97_EXTENDED_MID
, reg
| 0x7fff);
1166 ac97_write(codec
, AC97_EXTENDED_MSTATUS
, 0xffff);
1167 ac97_write(codec
, AC97_POWERDOWN
, 0x6f00);
1168 ac97_write(codec
, AC97_POWERDOWN
, 0xffff);
1173 static int wm9713_soc_resume(struct platform_device
*pdev
)
1175 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1176 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1177 struct wm9713_priv
*wm9713
= codec
->private_data
;
1179 u16
*cache
= codec
->reg_cache
;
1181 ret
= wm9713_reset(codec
, 1);
1183 printk(KERN_ERR
"could not reset AC97 codec\n");
1187 wm9713_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1189 /* do we need to re-start the PLL ? */
1191 wm9713_set_pll(codec
, 0, wm9713
->pll_in
, 0);
1193 /* only synchronise the codec if warm reset failed */
1195 for (i
= 2; i
< ARRAY_SIZE(wm9713_reg
) << 1; i
+= 2) {
1196 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_MID
||
1197 i
== AC97_EXTENDED_MSTATUS
|| i
> 0x66)
1199 soc_ac97_ops
.write(codec
->ac97
, i
, cache
[i
>>1]);
1203 if (codec
->suspend_bias_level
== SND_SOC_BIAS_ON
)
1204 wm9713_set_bias_level(codec
, SND_SOC_BIAS_ON
);
1209 static int wm9713_soc_probe(struct platform_device
*pdev
)
1211 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1212 struct snd_soc_codec
*codec
;
1215 socdev
->card
->codec
= kzalloc(sizeof(struct snd_soc_codec
),
1217 if (socdev
->card
->codec
== NULL
)
1219 codec
= socdev
->card
->codec
;
1220 mutex_init(&codec
->mutex
);
1222 codec
->reg_cache
= kmemdup(wm9713_reg
, sizeof(wm9713_reg
), GFP_KERNEL
);
1223 if (codec
->reg_cache
== NULL
) {
1227 codec
->reg_cache_size
= sizeof(wm9713_reg
);
1228 codec
->reg_cache_step
= 2;
1230 codec
->private_data
= kzalloc(sizeof(struct wm9713_priv
), GFP_KERNEL
);
1231 if (codec
->private_data
== NULL
) {
1236 codec
->name
= "WM9713";
1237 codec
->owner
= THIS_MODULE
;
1238 codec
->dai
= wm9713_dai
;
1239 codec
->num_dai
= ARRAY_SIZE(wm9713_dai
);
1240 codec
->write
= ac97_write
;
1241 codec
->read
= ac97_read
;
1242 codec
->set_bias_level
= wm9713_set_bias_level
;
1243 INIT_LIST_HEAD(&codec
->dapm_widgets
);
1244 INIT_LIST_HEAD(&codec
->dapm_paths
);
1246 ret
= snd_soc_new_ac97_codec(codec
, &soc_ac97_ops
, 0);
1251 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
1255 /* do a cold reset for the controller and then try
1256 * a warm reset followed by an optional cold reset for codec */
1257 wm9713_reset(codec
, 0);
1258 ret
= wm9713_reset(codec
, 1);
1260 printk(KERN_ERR
"Failed to reset WM9713: AC97 link error\n");
1264 wm9713_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1266 /* unmute the adc - move to kcontrol */
1267 reg
= ac97_read(codec
, AC97_CD
) & 0x7fff;
1268 ac97_write(codec
, AC97_CD
, reg
);
1270 snd_soc_add_controls(codec
, wm9713_snd_ac97_controls
,
1271 ARRAY_SIZE(wm9713_snd_ac97_controls
));
1272 wm9713_add_widgets(codec
);
1277 snd_soc_free_pcms(socdev
);
1279 snd_soc_free_ac97_codec(codec
);
1282 kfree(codec
->private_data
);
1285 kfree(codec
->reg_cache
);
1288 kfree(socdev
->card
->codec
);
1289 socdev
->card
->codec
= NULL
;
1293 static int wm9713_soc_remove(struct platform_device
*pdev
)
1295 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1296 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1301 snd_soc_dapm_free(socdev
);
1302 snd_soc_free_pcms(socdev
);
1303 snd_soc_free_ac97_codec(codec
);
1304 kfree(codec
->private_data
);
1305 kfree(codec
->reg_cache
);
1310 struct snd_soc_codec_device soc_codec_dev_wm9713
= {
1311 .probe
= wm9713_soc_probe
,
1312 .remove
= wm9713_soc_remove
,
1313 .suspend
= wm9713_soc_suspend
,
1314 .resume
= wm9713_soc_resume
,
1316 EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713
);
1318 MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1319 MODULE_AUTHOR("Liam Girdwood");
1320 MODULE_LICENSE("GPL");