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/slab.h>
20 #include <linux/module.h>
21 #include <linux/device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/ac97_codec.h>
25 #include <sound/initval.h>
26 #include <sound/pcm_params.h>
27 #include <sound/tlv.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
34 u32 pll_in
; /* PLL input frequency */
37 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
39 static int ac97_write(struct snd_soc_codec
*codec
,
40 unsigned int reg
, unsigned int val
);
43 * WM9713 register cache
44 * Reg 0x3c bit 15 is used by touch driver.
46 static const u16 wm9713_reg
[] = {
47 0x6174, 0x8080, 0x8080, 0x8080,
48 0xc880, 0xe808, 0xe808, 0x0808,
49 0x00da, 0x8000, 0xd600, 0xaaa0,
50 0xaaa0, 0xaaa0, 0x0000, 0x0000,
51 0x0f0f, 0x0040, 0x0000, 0x7f00,
52 0x0405, 0x0410, 0xbb80, 0xbb80,
53 0x0000, 0xbb80, 0x0000, 0x4523,
54 0x0000, 0x2000, 0x7eff, 0xffff,
55 0x0000, 0x0000, 0x0080, 0x0000,
56 0x0000, 0x0000, 0xfffe, 0xffff,
57 0x0000, 0x0000, 0x0000, 0xfffe,
58 0x4000, 0x0000, 0x0000, 0x0000,
59 0xb032, 0x3e00, 0x0000, 0x0000,
60 0x0000, 0x0000, 0x0000, 0x0000,
61 0x0000, 0x0000, 0x0000, 0x0006,
62 0x0001, 0x0000, 0x574d, 0x4c13,
63 0x0000, 0x0000, 0x0000
66 /* virtual HP mixers regs */
67 #define HPL_MIXER 0x80
68 #define HPR_MIXER 0x82
71 static const char *wm9713_mic_mixer
[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
72 static const char *wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
73 static const char *wm9713_rec_src
[] =
74 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
76 static const char *wm9713_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
77 static const char *wm9713_alc_select
[] = {"None", "Left", "Right", "Stereo"};
78 static const char *wm9713_mono_pga
[] = {"Vmid", "Zh", "Mono", "Inv",
79 "Mono Vmid", "Inv Vmid"};
80 static const char *wm9713_spk_pga
[] =
81 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
82 "Speaker Vmid", "Inv Vmid"};
83 static const char *wm9713_hp_pga
[] = {"Vmid", "Zh", "Headphone",
85 static const char *wm9713_out3_pga
[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
86 static const char *wm9713_out4_pga
[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
87 static const char *wm9713_dac_inv
[] =
88 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
89 "Headphone Mono", "NC", "Vmid"};
90 static const char *wm9713_bass
[] = {"Linear Control", "Adaptive Boost"};
91 static const char *wm9713_ng_type
[] = {"Constant Gain", "Mute"};
92 static const char *wm9713_mic_select
[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
93 static const char *wm9713_micb_select
[] = {"MPB", "MPA"};
95 static const struct soc_enum wm9713_enum
[] = {
96 SOC_ENUM_SINGLE(AC97_LINE
, 3, 4, wm9713_mic_mixer
), /* record mic mixer 0 */
97 SOC_ENUM_SINGLE(AC97_VIDEO
, 14, 4, wm9713_rec_mux
), /* record mux hp 1 */
98 SOC_ENUM_SINGLE(AC97_VIDEO
, 9, 4, wm9713_rec_mux
), /* record mux mono 2 */
99 SOC_ENUM_SINGLE(AC97_VIDEO
, 3, 8, wm9713_rec_src
), /* record mux left 3 */
100 SOC_ENUM_SINGLE(AC97_VIDEO
, 0, 8, wm9713_rec_src
), /* record mux right 4*/
101 SOC_ENUM_DOUBLE(AC97_CD
, 14, 6, 2, wm9713_rec_gain
), /* record step size 5 */
102 SOC_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9713_alc_select
), /* alc source select 6*/
103 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 14, 4, wm9713_mono_pga
), /* mono input select 7 */
104 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 11, 8, wm9713_spk_pga
), /* speaker left input select 8 */
105 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 8, 8, wm9713_spk_pga
), /* speaker right input select 9 */
106 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 6, 3, wm9713_hp_pga
), /* headphone left input 10 */
107 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 4, 3, wm9713_hp_pga
), /* headphone right input 11 */
108 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 2, 4, wm9713_out3_pga
), /* out 3 source 12 */
109 SOC_ENUM_SINGLE(AC97_REC_GAIN
, 0, 4, wm9713_out4_pga
), /* out 4 source 13 */
110 SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC
, 13, 8, wm9713_dac_inv
), /* dac invert 1 14 */
111 SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC
, 10, 8, wm9713_dac_inv
), /* dac invert 2 15 */
112 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE
, 15, 2, wm9713_bass
), /* bass control 16 */
113 SOC_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9713_ng_type
), /* noise gate type 17 */
114 SOC_ENUM_SINGLE(AC97_3D_CONTROL
, 12, 3, wm9713_mic_select
), /* mic selection 18 */
115 SOC_ENUM_SINGLE(MICB_MUX
, 0, 2, wm9713_micb_select
), /* mic selection 19 */
118 static const DECLARE_TLV_DB_SCALE(out_tlv
, -4650, 150, 0);
119 static const DECLARE_TLV_DB_SCALE(main_tlv
, -3450, 150, 0);
120 static const DECLARE_TLV_DB_SCALE(misc_tlv
, -1500, 300, 0);
121 static unsigned int mic_tlv
[] = {
122 TLV_DB_RANGE_HEAD(2),
123 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0),
124 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0),
127 static const struct snd_kcontrol_new wm9713_snd_ac97_controls
[] = {
128 SOC_DOUBLE_TLV("Speaker Playback Volume", AC97_MASTER
, 8, 0, 31, 1, out_tlv
),
129 SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER
, 15, 7, 1, 1),
130 SOC_DOUBLE_TLV("Headphone Playback Volume", AC97_HEADPHONE
, 8, 0, 31, 1,
132 SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE
, 15, 7, 1, 1),
133 SOC_DOUBLE_TLV("Line In Volume", AC97_PC_BEEP
, 8, 0, 31, 1, main_tlv
),
134 SOC_DOUBLE_TLV("PCM Playback Volume", AC97_PHONE
, 8, 0, 31, 1, main_tlv
),
135 SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC
, 8, 31, 1, main_tlv
),
136 SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC
, 0, 31, 1, main_tlv
),
137 SOC_SINGLE_TLV("Mic 1 Preamp Volume", AC97_3D_CONTROL
, 10, 3, 0, mic_tlv
),
138 SOC_SINGLE_TLV("Mic 2 Preamp Volume", AC97_3D_CONTROL
, 12, 3, 0, mic_tlv
),
140 SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE
, 5, 1, 0),
141 SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE
, 0, 7, 1),
143 SOC_SINGLE("Capture Switch", AC97_CD
, 15, 1, 1),
144 SOC_ENUM("Capture Volume Steps", wm9713_enum
[5]),
145 SOC_DOUBLE("Capture Volume", AC97_CD
, 8, 0, 31, 0),
146 SOC_SINGLE("Capture ZC Switch", AC97_CD
, 7, 1, 0),
148 SOC_SINGLE_TLV("Capture to Headphone Volume", AC97_VIDEO
, 11, 7, 1, misc_tlv
),
149 SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO
, 8, 1, 0),
150 SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO
, 6, 1, 0),
152 SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
153 SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
154 SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV
, 4, 15, 0),
155 SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
156 SOC_ENUM("ALC Function", wm9713_enum
[6]),
157 SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 0),
158 SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 0),
159 SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
160 SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
161 SOC_ENUM("ALC NG Type", wm9713_enum
[17]),
162 SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 0),
164 SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER
, 14, 6, 1, 0),
165 SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE
, 14, 6, 1, 0),
167 SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO
, 15, 1, 1),
168 SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO
, 14, 1, 0),
169 SOC_SINGLE_TLV("Out4 Playback Volume", AC97_MASTER_MONO
, 8, 31, 1, out_tlv
),
171 SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO
, 7, 1, 1),
172 SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO
, 6, 1, 0),
173 SOC_SINGLE_TLV("Out3 Playback Volume", AC97_MASTER_MONO
, 0, 31, 1, out_tlv
),
175 SOC_SINGLE_TLV("Mono Capture Volume", AC97_MASTER_TONE
, 8, 31, 1, main_tlv
),
176 SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE
, 7, 1, 1),
177 SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE
, 6, 1, 0),
178 SOC_SINGLE_TLV("Mono Playback Volume", AC97_MASTER_TONE
, 0, 31, 1, out_tlv
),
180 SOC_SINGLE_TLV("Headphone Mixer Beep Playback Volume", AC97_AUX
, 12, 7, 1,
182 SOC_SINGLE_TLV("Speaker Mixer Beep Playback Volume", AC97_AUX
, 8, 7, 1,
184 SOC_SINGLE_TLV("Mono Mixer Beep Playback Volume", AC97_AUX
, 4, 7, 1, misc_tlv
),
186 SOC_SINGLE_TLV("Voice Playback Headphone Volume", AC97_PCM
, 12, 7, 1,
188 SOC_SINGLE("Voice Playback Master Volume", AC97_PCM
, 8, 7, 1),
189 SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM
, 4, 7, 1),
191 SOC_SINGLE_TLV("Headphone Mixer Aux Playback Volume", AC97_REC_SEL
, 12, 7, 1,
194 SOC_SINGLE_TLV("Speaker Mixer Voice Playback Volume", AC97_PCM
, 8, 7, 1,
196 SOC_SINGLE_TLV("Speaker Mixer Aux Playback Volume", AC97_REC_SEL
, 8, 7, 1,
199 SOC_SINGLE_TLV("Mono Mixer Voice Playback Volume", AC97_PCM
, 4, 7, 1,
201 SOC_SINGLE_TLV("Mono Mixer Aux Playback Volume", AC97_REC_SEL
, 4, 7, 1,
204 SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL
, 12, 7, 1),
205 SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL
, 8, 7, 1),
207 SOC_ENUM("Bass Control", wm9713_enum
[16]),
208 SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE
, 12, 1, 1),
209 SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE
, 4, 1, 1),
210 SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE
, 6, 1, 0),
211 SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE
, 8, 15, 1),
212 SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE
, 0, 15, 1),
214 SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC
, 5, 1, 0),
215 SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC
, 4, 1, 0),
216 SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC
, 0, 15, 1),
219 static int wm9713_voice_shutdown(struct snd_soc_dapm_widget
*w
,
220 struct snd_kcontrol
*kcontrol
, int event
)
222 struct snd_soc_codec
*codec
= w
->codec
;
225 BUG_ON(event
!= SND_SOC_DAPM_PRE_PMD
);
227 /* Gracefully shut down the voice interface. */
228 status
= ac97_read(codec
, AC97_EXTENDED_MID
) | 0x1000;
229 rate
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xF0FF;
230 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0200);
231 schedule_timeout_interruptible(msecs_to_jiffies(1));
232 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0F00);
233 ac97_write(codec
, AC97_EXTENDED_MID
, status
);
239 /* We have to create a fake left and right HP mixers because
240 * the codec only has a single control that is shared by both channels.
241 * This makes it impossible to determine the audio path using the current
242 * register map, thus we add a new (virtual) register to help determine the
243 * audio route within the device.
245 static int mixer_event(struct snd_soc_dapm_widget
*w
,
246 struct snd_kcontrol
*kcontrol
, int event
)
248 u16 l
, r
, beep
, tone
, phone
, rec
, pcm
, aux
;
250 l
= ac97_read(w
->codec
, HPL_MIXER
);
251 r
= ac97_read(w
->codec
, HPR_MIXER
);
252 beep
= ac97_read(w
->codec
, AC97_PC_BEEP
);
253 tone
= ac97_read(w
->codec
, AC97_MASTER_TONE
);
254 phone
= ac97_read(w
->codec
, AC97_PHONE
);
255 rec
= ac97_read(w
->codec
, AC97_REC_SEL
);
256 pcm
= ac97_read(w
->codec
, AC97_PCM
);
257 aux
= ac97_read(w
->codec
, AC97_AUX
);
259 if (event
& SND_SOC_DAPM_PRE_REG
)
261 if ((l
& 0x1) || (r
& 0x1))
262 ac97_write(w
->codec
, AC97_PC_BEEP
, beep
& 0x7fff);
264 ac97_write(w
->codec
, AC97_PC_BEEP
, beep
| 0x8000);
266 if ((l
& 0x2) || (r
& 0x2))
267 ac97_write(w
->codec
, AC97_MASTER_TONE
, tone
& 0x7fff);
269 ac97_write(w
->codec
, AC97_MASTER_TONE
, tone
| 0x8000);
271 if ((l
& 0x4) || (r
& 0x4))
272 ac97_write(w
->codec
, AC97_PHONE
, phone
& 0x7fff);
274 ac97_write(w
->codec
, AC97_PHONE
, phone
| 0x8000);
276 if ((l
& 0x8) || (r
& 0x8))
277 ac97_write(w
->codec
, AC97_REC_SEL
, rec
& 0x7fff);
279 ac97_write(w
->codec
, AC97_REC_SEL
, rec
| 0x8000);
281 if ((l
& 0x10) || (r
& 0x10))
282 ac97_write(w
->codec
, AC97_PCM
, pcm
& 0x7fff);
284 ac97_write(w
->codec
, AC97_PCM
, pcm
| 0x8000);
286 if ((l
& 0x20) || (r
& 0x20))
287 ac97_write(w
->codec
, AC97_AUX
, aux
& 0x7fff);
289 ac97_write(w
->codec
, AC97_AUX
, aux
| 0x8000);
294 /* Left Headphone Mixers */
295 static const struct snd_kcontrol_new wm9713_hpl_mixer_controls
[] = {
296 SOC_DAPM_SINGLE("Beep Playback Switch", HPL_MIXER
, 5, 1, 0),
297 SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER
, 4, 1, 0),
298 SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER
, 3, 1, 0),
299 SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER
, 2, 1, 0),
300 SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER
, 1, 1, 0),
301 SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER
, 0, 1, 0),
304 /* Right Headphone Mixers */
305 static const struct snd_kcontrol_new wm9713_hpr_mixer_controls
[] = {
306 SOC_DAPM_SINGLE("Beep Playback Switch", HPR_MIXER
, 5, 1, 0),
307 SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER
, 4, 1, 0),
308 SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER
, 3, 1, 0),
309 SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER
, 2, 1, 0),
310 SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER
, 1, 1, 0),
311 SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER
, 0, 1, 0),
314 /* headphone capture mux */
315 static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls
=
316 SOC_DAPM_ENUM("Route", wm9713_enum
[1]);
318 /* headphone mic mux */
319 static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls
=
320 SOC_DAPM_ENUM("Route", wm9713_enum
[0]);
323 static const struct snd_kcontrol_new wm9713_speaker_mixer_controls
[] = {
324 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 11, 1, 1),
325 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 11, 1, 1),
326 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 11, 1, 1),
327 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 14, 1, 1),
328 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 14, 1, 1),
329 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 14, 1, 1),
333 static const struct snd_kcontrol_new wm9713_mono_mixer_controls
[] = {
334 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 7, 1, 1),
335 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 7, 1, 1),
336 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 7, 1, 1),
337 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 13, 1, 1),
338 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 13, 1, 1),
339 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 13, 1, 1),
340 SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE
, 7, 1, 1),
341 SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE
, 6, 1, 1),
345 static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls
=
346 SOC_DAPM_ENUM("Route", wm9713_enum
[2]);
348 /* mono output mux */
349 static const struct snd_kcontrol_new wm9713_mono_mux_controls
=
350 SOC_DAPM_ENUM("Route", wm9713_enum
[7]);
352 /* speaker left output mux */
353 static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls
=
354 SOC_DAPM_ENUM("Route", wm9713_enum
[8]);
356 /* speaker right output mux */
357 static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls
=
358 SOC_DAPM_ENUM("Route", wm9713_enum
[9]);
360 /* headphone left output mux */
361 static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls
=
362 SOC_DAPM_ENUM("Route", wm9713_enum
[10]);
364 /* headphone right output mux */
365 static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls
=
366 SOC_DAPM_ENUM("Route", wm9713_enum
[11]);
369 static const struct snd_kcontrol_new wm9713_out3_mux_controls
=
370 SOC_DAPM_ENUM("Route", wm9713_enum
[12]);
373 static const struct snd_kcontrol_new wm9713_out4_mux_controls
=
374 SOC_DAPM_ENUM("Route", wm9713_enum
[13]);
377 static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls
=
378 SOC_DAPM_ENUM("Route", wm9713_enum
[14]);
381 static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls
=
382 SOC_DAPM_ENUM("Route", wm9713_enum
[15]);
384 /* Capture source left */
385 static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls
=
386 SOC_DAPM_ENUM("Route", wm9713_enum
[3]);
388 /* Capture source right */
389 static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls
=
390 SOC_DAPM_ENUM("Route", wm9713_enum
[4]);
393 static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls
=
394 SOC_DAPM_ENUM("Route", wm9713_enum
[18]);
396 /* mic source B virtual control */
397 static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls
=
398 SOC_DAPM_ENUM("Route", wm9713_enum
[19]);
400 static const struct snd_soc_dapm_widget wm9713_dapm_widgets
[] = {
401 SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM
, 0, 0,
402 &wm9713_hp_rec_mux_controls
),
403 SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM
, 0, 0,
404 &wm9713_hp_mic_mux_controls
),
405 SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM
, 0, 0,
406 &wm9713_mono_mic_mux_controls
),
407 SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM
, 0, 0,
408 &wm9713_mono_mux_controls
),
409 SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
410 &wm9713_hp_spkl_mux_controls
),
411 SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
412 &wm9713_hp_spkr_mux_controls
),
413 SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
414 &wm9713_hpl_out_mux_controls
),
415 SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
416 &wm9713_hpr_out_mux_controls
),
417 SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM
, 0, 0,
418 &wm9713_out3_mux_controls
),
419 SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM
, 0, 0,
420 &wm9713_out4_mux_controls
),
421 SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM
, 0, 0,
422 &wm9713_dac_inv1_mux_controls
),
423 SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM
, 0, 0,
424 &wm9713_dac_inv2_mux_controls
),
425 SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM
, 0, 0,
426 &wm9713_rec_srcl_mux_controls
),
427 SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM
, 0, 0,
428 &wm9713_rec_srcr_mux_controls
),
429 SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM
, 0, 0,
430 &wm9713_mic_sel_mux_controls
),
431 SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM
, 0, 0,
432 &wm9713_micb_sel_mux_controls
),
433 SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID
, 3, 1,
434 &wm9713_hpl_mixer_controls
[0], ARRAY_SIZE(wm9713_hpl_mixer_controls
),
435 mixer_event
, SND_SOC_DAPM_POST_REG
),
436 SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID
, 2, 1,
437 &wm9713_hpr_mixer_controls
[0], ARRAY_SIZE(wm9713_hpr_mixer_controls
),
438 mixer_event
, SND_SOC_DAPM_POST_REG
),
439 SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID
, 0, 1,
440 &wm9713_mono_mixer_controls
[0], ARRAY_SIZE(wm9713_mono_mixer_controls
)),
441 SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID
, 1, 1,
442 &wm9713_speaker_mixer_controls
[0],
443 ARRAY_SIZE(wm9713_speaker_mixer_controls
)),
444 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID
, 7, 1),
445 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID
, 6, 1),
446 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
447 SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
448 SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
449 SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
450 SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID
, 12, 1,
451 wm9713_voice_shutdown
, SND_SOC_DAPM_PRE_PMD
),
452 SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID
, 11, 1),
453 SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID
, 5, 1, NULL
, 0),
454 SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID
, 4, 1, NULL
, 0),
455 SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM
, 0, 0),
456 SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM
, 0, 0),
457 SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM
, 0, 0),
458 SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM
, 0, 0),
459 SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS
, 10, 1, NULL
, 0),
460 SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS
, 9, 1, NULL
, 0),
461 SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS
, 8, 1, NULL
, 0),
462 SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS
, 7, 1, NULL
, 0),
463 SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS
, 11, 1, NULL
, 0),
464 SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS
, 12, 1, NULL
, 0),
465 SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS
, 13, 1, NULL
, 0),
466 SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS
, 6, 1, NULL
, 0),
467 SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS
, 5, 1, NULL
, 0),
468 SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS
, 4, 1, NULL
, 0),
469 SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS
, 3, 1, NULL
, 0),
470 SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS
, 2, 1, NULL
, 0),
471 SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS
, 1, 1, NULL
, 0),
472 SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS
, 0, 1, NULL
, 0),
473 SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS
, 14, 1),
474 SND_SOC_DAPM_OUTPUT("MONO"),
475 SND_SOC_DAPM_OUTPUT("HPL"),
476 SND_SOC_DAPM_OUTPUT("HPR"),
477 SND_SOC_DAPM_OUTPUT("SPKL"),
478 SND_SOC_DAPM_OUTPUT("SPKR"),
479 SND_SOC_DAPM_OUTPUT("OUT3"),
480 SND_SOC_DAPM_OUTPUT("OUT4"),
481 SND_SOC_DAPM_INPUT("LINEL"),
482 SND_SOC_DAPM_INPUT("LINER"),
483 SND_SOC_DAPM_INPUT("MONOIN"),
484 SND_SOC_DAPM_INPUT("PCBEEP"),
485 SND_SOC_DAPM_INPUT("MIC1"),
486 SND_SOC_DAPM_INPUT("MIC2A"),
487 SND_SOC_DAPM_INPUT("MIC2B"),
488 SND_SOC_DAPM_VMID("VMID"),
491 static const struct snd_soc_dapm_route audio_map
[] = {
493 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
494 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
495 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
496 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
497 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
498 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
499 {"Left HP Mixer", NULL
, "Capture Headphone Mux"},
502 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
503 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
504 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
505 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
506 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
507 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
508 {"Right HP Mixer", NULL
, "Capture Headphone Mux"},
510 /* virtual mixer - mixes left & right channels for spk and mono */
511 {"AC97 Mixer", NULL
, "Left DAC"},
512 {"AC97 Mixer", NULL
, "Right DAC"},
513 {"Line Mixer", NULL
, "Right Line In"},
514 {"Line Mixer", NULL
, "Left Line In"},
515 {"HP Mixer", NULL
, "Left HP Mixer"},
516 {"HP Mixer", NULL
, "Right HP Mixer"},
517 {"Capture Mixer", NULL
, "Left Capture Source"},
518 {"Capture Mixer", NULL
, "Right Capture Source"},
521 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
522 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
523 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
524 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
525 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
526 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
529 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
530 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
531 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
532 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
533 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
534 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
535 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
536 {"Mono Mixer", NULL
, "Capture Mono Mux"},
539 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
540 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
541 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
542 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
543 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
546 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
547 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
548 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
549 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
550 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
552 /* headphone left mux */
553 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
555 /* headphone right mux */
556 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
558 /* speaker left mux */
559 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
560 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
561 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
563 /* speaker right mux */
564 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
565 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
566 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
569 {"Mono Out Mux", "Mono", "Mono Mixer"},
570 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
573 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
576 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
579 {"HPL", NULL
, "Left Headphone"},
580 {"Left Headphone", NULL
, "Left Headphone Out Mux"},
581 {"HPR", NULL
, "Right Headphone"},
582 {"Right Headphone", NULL
, "Right Headphone Out Mux"},
583 {"OUT3", NULL
, "Out 3"},
584 {"Out 3", NULL
, "Out 3 Mux"},
585 {"OUT4", NULL
, "Out 4"},
586 {"Out 4", NULL
, "Out 4 Mux"},
587 {"SPKL", NULL
, "Left Speaker"},
588 {"Left Speaker", NULL
, "Left Speaker Out Mux"},
589 {"SPKR", NULL
, "Right Speaker"},
590 {"Right Speaker", NULL
, "Right Speaker Out Mux"},
591 {"MONO", NULL
, "Mono Out"},
592 {"Mono Out", NULL
, "Mono Out Mux"},
595 {"Left Line In", NULL
, "LINEL"},
596 {"Right Line In", NULL
, "LINER"},
597 {"Mono In", NULL
, "MONOIN"},
598 {"Mic A PGA", NULL
, "Mic A Pre Amp"},
599 {"Mic B PGA", NULL
, "Mic B Pre Amp"},
601 /* left capture select */
602 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
603 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
604 {"Left Capture Source", "Line", "LINEL"},
605 {"Left Capture Source", "Mono In", "MONOIN"},
606 {"Left Capture Source", "Headphone", "Left HP Mixer"},
607 {"Left Capture Source", "Speaker", "Speaker Mixer"},
608 {"Left Capture Source", "Mono Out", "Mono Mixer"},
610 /* right capture select */
611 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
612 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
613 {"Right Capture Source", "Line", "LINER"},
614 {"Right Capture Source", "Mono In", "MONOIN"},
615 {"Right Capture Source", "Headphone", "Right HP Mixer"},
616 {"Right Capture Source", "Speaker", "Speaker Mixer"},
617 {"Right Capture Source", "Mono Out", "Mono Mixer"},
620 {"Left ADC", NULL
, "Left Capture Source"},
621 {"Left Voice ADC", NULL
, "Left ADC"},
622 {"Left HiFi ADC", NULL
, "Left ADC"},
625 {"Right ADC", NULL
, "Right Capture Source"},
626 {"Right Voice ADC", NULL
, "Right ADC"},
627 {"Right HiFi ADC", NULL
, "Right ADC"},
630 {"Mic A Pre Amp", NULL
, "Mic A Source"},
631 {"Mic A Source", "Mic 1", "MIC1"},
632 {"Mic A Source", "Mic 2 A", "MIC2A"},
633 {"Mic A Source", "Mic 2 B", "Mic B Source"},
634 {"Mic B Pre Amp", "MPB", "Mic B Source"},
635 {"Mic B Source", NULL
, "MIC2B"},
637 /* headphone capture */
638 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
639 {"Capture Headphone Mux", "Left", "Left Capture Source"},
640 {"Capture Headphone Mux", "Right", "Right Capture Source"},
643 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
644 {"Capture Mono Mux", "Left", "Left Capture Source"},
645 {"Capture Mono Mux", "Right", "Right Capture Source"},
648 static int wm9713_add_widgets(struct snd_soc_codec
*codec
)
650 snd_soc_dapm_new_controls(codec
, wm9713_dapm_widgets
,
651 ARRAY_SIZE(wm9713_dapm_widgets
));
653 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
658 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
661 u16
*cache
= codec
->reg_cache
;
663 if (reg
== AC97_RESET
|| reg
== AC97_GPIO_STATUS
||
664 reg
== AC97_VENDOR_ID1
|| reg
== AC97_VENDOR_ID2
||
666 return soc_ac97_ops
.read(codec
->ac97
, reg
);
670 if (reg
>= (ARRAY_SIZE(wm9713_reg
)))
677 static int ac97_write(struct snd_soc_codec
*codec
, unsigned int reg
,
680 u16
*cache
= codec
->reg_cache
;
682 soc_ac97_ops
.write(codec
->ac97
, reg
, val
);
684 if (reg
< (ARRAY_SIZE(wm9713_reg
)))
699 /* The size in bits of the PLL divide multiplied by 10
700 * to allow rounding later */
701 #define FIXED_PLL_SIZE ((1 << 22) * 10)
703 static void pll_factors(struct _pll_div
*pll_div
, unsigned int source
)
706 unsigned int K
, Ndiv
, Nmod
, target
;
708 /* The the PLL output is always 98.304MHz. */
711 /* If the input frequency is over 14.4MHz then scale it down. */
712 if (source
> 14400000) {
716 if (source
> 14400000) {
727 /* Low frequency sources require an additional divide in the
730 if (source
< 8192000) {
736 Ndiv
= target
/ source
;
737 if ((Ndiv
< 5) || (Ndiv
> 12))
739 "WM9713 PLL N value %u out of recommended range!\n",
743 Nmod
= target
% source
;
744 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
746 do_div(Kpart
, source
);
748 K
= Kpart
& 0xFFFFFFFF;
750 /* Check if we need to round */
754 /* Move down to proper range now rounding is done */
761 * Please note that changing the PLL input frequency may require
762 * resynchronisation with the AC97 controller.
764 static int wm9713_set_pll(struct snd_soc_codec
*codec
,
765 int pll_id
, unsigned int freq_in
, unsigned int freq_out
)
767 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
769 struct _pll_div pll_div
;
773 /* disable PLL power and select ext source */
774 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
775 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| 0x0080);
776 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
777 ac97_write(codec
, AC97_EXTENDED_MID
, reg
| 0x0200);
782 pll_factors(&pll_div
, freq_in
);
784 if (pll_div
.k
== 0) {
785 reg
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) |
786 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
787 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
789 /* write the fractional k to the reg 0x46 pages */
790 reg2
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) | (1 << 10) |
791 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
794 reg
= reg2
| (0x5 << 4) | (pll_div
.k
>> 20);
795 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
798 reg
= reg2
| (0x4 << 4) | ((pll_div
.k
>> 16) & 0xf);
799 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
802 reg
= reg2
| (0x3 << 4) | ((pll_div
.k
>> 12) & 0xf);
803 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
806 reg
= reg2
| (0x2 << 4) | ((pll_div
.k
>> 8) & 0xf);
807 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
810 reg
= reg2
| (0x1 << 4) | ((pll_div
.k
>> 4) & 0xf);
811 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
813 reg
= reg2
| (0x0 << 4) | (pll_div
.k
& 0xf); /* K [3:0] */
814 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
817 /* turn PLL on and select as source */
818 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
819 ac97_write(codec
, AC97_EXTENDED_MID
, reg
& 0xfdff);
820 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
821 ac97_write(codec
, AC97_HANDSET_RATE
, reg
& 0xff7f);
822 wm9713
->pll_in
= freq_in
;
824 /* wait 10ms AC97 link frames for the link to stabilise */
825 schedule_timeout_interruptible(msecs_to_jiffies(10));
829 static int wm9713_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
830 int source
, unsigned int freq_in
, unsigned int freq_out
)
832 struct snd_soc_codec
*codec
= codec_dai
->codec
;
833 return wm9713_set_pll(codec
, pll_id
, freq_in
, freq_out
);
837 * Tristate the PCM DAI lines, tristate can be disabled by calling
838 * wm9713_set_dai_fmt()
840 static int wm9713_set_dai_tristate(struct snd_soc_dai
*codec_dai
,
843 struct snd_soc_codec
*codec
= codec_dai
->codec
;
844 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0x9fff;
847 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
853 * Configure WM9713 clock dividers.
854 * Voice DAC needs 256 FS
856 static int wm9713_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
859 struct snd_soc_codec
*codec
= codec_dai
->codec
;
863 case WM9713_PCMCLK_DIV
:
864 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xf0ff;
865 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
867 case WM9713_CLKA_MULT
:
868 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffd;
869 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
871 case WM9713_CLKB_MULT
:
872 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffb;
873 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
875 case WM9713_HIFI_DIV
:
876 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0x8fff;
877 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
879 case WM9713_PCMBCLK_DIV
:
880 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xf1ff;
881 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
| div
);
883 case WM9713_PCMCLK_PLL_DIV
:
884 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
885 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x60 | div
);
887 case WM9713_HIFI_PLL_DIV
:
888 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
889 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x70 | div
);
898 static int wm9713_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
901 struct snd_soc_codec
*codec
= codec_dai
->codec
;
902 u16 gpio
= ac97_read(codec
, AC97_GPIO_CFG
) & 0xffc5;
906 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
907 case SND_SOC_DAIFMT_CBM_CFM
:
911 case SND_SOC_DAIFMT_CBM_CFS
:
915 case SND_SOC_DAIFMT_CBS_CFS
:
919 case SND_SOC_DAIFMT_CBS_CFM
:
924 /* clock inversion */
925 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
926 case SND_SOC_DAIFMT_IB_IF
:
929 case SND_SOC_DAIFMT_IB_NF
:
932 case SND_SOC_DAIFMT_NB_IF
:
938 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
939 case SND_SOC_DAIFMT_I2S
:
942 case SND_SOC_DAIFMT_RIGHT_J
:
944 case SND_SOC_DAIFMT_LEFT_J
:
947 case SND_SOC_DAIFMT_DSP_A
:
950 case SND_SOC_DAIFMT_DSP_B
:
955 ac97_write(codec
, AC97_GPIO_CFG
, gpio
);
956 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
960 static int wm9713_pcm_hw_params(struct snd_pcm_substream
*substream
,
961 struct snd_pcm_hw_params
*params
,
962 struct snd_soc_dai
*dai
)
964 struct snd_soc_codec
*codec
= dai
->codec
;
965 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xfff3;
967 switch (params_format(params
)) {
968 case SNDRV_PCM_FORMAT_S16_LE
:
970 case SNDRV_PCM_FORMAT_S20_3LE
:
973 case SNDRV_PCM_FORMAT_S24_LE
:
976 case SNDRV_PCM_FORMAT_S32_LE
:
981 /* enable PCM interface in master mode */
982 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
986 static int ac97_hifi_prepare(struct snd_pcm_substream
*substream
,
987 struct snd_soc_dai
*dai
)
989 struct snd_soc_codec
*codec
= dai
->codec
;
990 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
994 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
995 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
997 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
998 reg
= AC97_PCM_FRONT_DAC_RATE
;
1000 reg
= AC97_PCM_LR_ADC_RATE
;
1002 return ac97_write(codec
, reg
, runtime
->rate
);
1005 static int ac97_aux_prepare(struct snd_pcm_substream
*substream
,
1006 struct snd_soc_dai
*dai
)
1008 struct snd_soc_codec
*codec
= dai
->codec
;
1009 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1012 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
1013 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
1014 xsle
= ac97_read(codec
, AC97_PCI_SID
);
1015 ac97_write(codec
, AC97_PCI_SID
, xsle
| 0x8000);
1017 if (substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1020 return ac97_write(codec
, AC97_PCM_SURR_DAC_RATE
, runtime
->rate
);
1023 #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \
1024 SNDRV_PCM_RATE_11025 | \
1025 SNDRV_PCM_RATE_22050 | \
1026 SNDRV_PCM_RATE_44100 | \
1027 SNDRV_PCM_RATE_48000)
1029 #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \
1030 SNDRV_PCM_RATE_11025 | \
1031 SNDRV_PCM_RATE_16000 | \
1032 SNDRV_PCM_RATE_22050 | \
1033 SNDRV_PCM_RATE_44100 | \
1034 SNDRV_PCM_RATE_48000)
1036 #define WM9713_PCM_FORMATS \
1037 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1038 SNDRV_PCM_FORMAT_S24_LE)
1040 static struct snd_soc_dai_ops wm9713_dai_ops_hifi
= {
1041 .prepare
= ac97_hifi_prepare
,
1042 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1043 .set_pll
= wm9713_set_dai_pll
,
1046 static struct snd_soc_dai_ops wm9713_dai_ops_aux
= {
1047 .prepare
= ac97_aux_prepare
,
1048 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1049 .set_pll
= wm9713_set_dai_pll
,
1052 static struct snd_soc_dai_ops wm9713_dai_ops_voice
= {
1053 .hw_params
= wm9713_pcm_hw_params
,
1054 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1055 .set_pll
= wm9713_set_dai_pll
,
1056 .set_fmt
= wm9713_set_dai_fmt
,
1057 .set_tristate
= wm9713_set_dai_tristate
,
1060 struct snd_soc_dai wm9713_dai
[] = {
1062 .name
= "AC97 HiFi",
1065 .stream_name
= "HiFi Playback",
1068 .rates
= WM9713_RATES
,
1069 .formats
= SND_SOC_STD_AC97_FMTS
,},
1071 .stream_name
= "HiFi Capture",
1074 .rates
= WM9713_RATES
,
1075 .formats
= SND_SOC_STD_AC97_FMTS
,},
1076 .ops
= &wm9713_dai_ops_hifi
,
1081 .stream_name
= "Aux Playback",
1084 .rates
= WM9713_RATES
,
1085 .formats
= SND_SOC_STD_AC97_FMTS
,},
1086 .ops
= &wm9713_dai_ops_aux
,
1089 .name
= "WM9713 Voice",
1091 .stream_name
= "Voice Playback",
1094 .rates
= WM9713_PCM_RATES
,
1095 .formats
= WM9713_PCM_FORMATS
,},
1097 .stream_name
= "Voice Capture",
1100 .rates
= WM9713_PCM_RATES
,
1101 .formats
= WM9713_PCM_FORMATS
,},
1102 .ops
= &wm9713_dai_ops_voice
,
1103 .symmetric_rates
= 1,
1106 EXPORT_SYMBOL_GPL(wm9713_dai
);
1108 int wm9713_reset(struct snd_soc_codec
*codec
, int try_warm
)
1110 if (try_warm
&& soc_ac97_ops
.warm_reset
) {
1111 soc_ac97_ops
.warm_reset(codec
->ac97
);
1112 if (ac97_read(codec
, 0) == wm9713_reg
[0])
1116 soc_ac97_ops
.reset(codec
->ac97
);
1117 if (soc_ac97_ops
.warm_reset
)
1118 soc_ac97_ops
.warm_reset(codec
->ac97
);
1119 if (ac97_read(codec
, 0) != wm9713_reg
[0])
1123 EXPORT_SYMBOL_GPL(wm9713_reset
);
1125 static int wm9713_set_bias_level(struct snd_soc_codec
*codec
,
1126 enum snd_soc_bias_level level
)
1131 case SND_SOC_BIAS_ON
:
1132 /* enable thermal shutdown */
1133 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x1bff;
1134 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1136 case SND_SOC_BIAS_PREPARE
:
1138 case SND_SOC_BIAS_STANDBY
:
1139 /* enable master bias and vmid */
1140 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x3bff;
1141 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1142 ac97_write(codec
, AC97_POWERDOWN
, 0x0000);
1144 case SND_SOC_BIAS_OFF
:
1145 /* disable everything including AC link */
1146 ac97_write(codec
, AC97_EXTENDED_MID
, 0xffff);
1147 ac97_write(codec
, AC97_EXTENDED_MSTATUS
, 0xffff);
1148 ac97_write(codec
, AC97_POWERDOWN
, 0xffff);
1151 codec
->bias_level
= level
;
1155 static int wm9713_soc_suspend(struct platform_device
*pdev
,
1158 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1159 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1162 /* Disable everything except touchpanel - that will be handled
1163 * by the touch driver and left disabled if touch is not in
1165 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
1166 ac97_write(codec
, AC97_EXTENDED_MID
, reg
| 0x7fff);
1167 ac97_write(codec
, AC97_EXTENDED_MSTATUS
, 0xffff);
1168 ac97_write(codec
, AC97_POWERDOWN
, 0x6f00);
1169 ac97_write(codec
, AC97_POWERDOWN
, 0xffff);
1174 static int wm9713_soc_resume(struct platform_device
*pdev
)
1176 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1177 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1178 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
1180 u16
*cache
= codec
->reg_cache
;
1182 ret
= wm9713_reset(codec
, 1);
1184 printk(KERN_ERR
"could not reset AC97 codec\n");
1188 wm9713_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1190 /* do we need to re-start the PLL ? */
1192 wm9713_set_pll(codec
, 0, wm9713
->pll_in
, 0);
1194 /* only synchronise the codec if warm reset failed */
1196 for (i
= 2; i
< ARRAY_SIZE(wm9713_reg
) << 1; i
+= 2) {
1197 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_MID
||
1198 i
== AC97_EXTENDED_MSTATUS
|| i
> 0x66)
1200 soc_ac97_ops
.write(codec
->ac97
, i
, cache
[i
>>1]);
1207 static int wm9713_soc_probe(struct platform_device
*pdev
)
1209 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1210 struct snd_soc_codec
*codec
;
1213 socdev
->card
->codec
= kzalloc(sizeof(struct snd_soc_codec
),
1215 if (socdev
->card
->codec
== NULL
)
1217 codec
= socdev
->card
->codec
;
1218 mutex_init(&codec
->mutex
);
1220 codec
->reg_cache
= kmemdup(wm9713_reg
, sizeof(wm9713_reg
), GFP_KERNEL
);
1221 if (codec
->reg_cache
== NULL
) {
1225 codec
->reg_cache_size
= sizeof(wm9713_reg
);
1226 codec
->reg_cache_step
= 2;
1228 snd_soc_codec_set_drvdata(codec
, kzalloc(sizeof(struct wm9713_priv
),
1230 if (snd_soc_codec_get_drvdata(codec
) == NULL
) {
1235 codec
->name
= "WM9713";
1236 codec
->owner
= THIS_MODULE
;
1237 codec
->dai
= wm9713_dai
;
1238 codec
->num_dai
= ARRAY_SIZE(wm9713_dai
);
1239 codec
->write
= ac97_write
;
1240 codec
->read
= ac97_read
;
1241 codec
->set_bias_level
= wm9713_set_bias_level
;
1242 INIT_LIST_HEAD(&codec
->dapm_widgets
);
1243 INIT_LIST_HEAD(&codec
->dapm_paths
);
1245 ret
= snd_soc_new_ac97_codec(codec
, &soc_ac97_ops
, 0);
1250 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
1254 /* do a cold reset for the controller and then try
1255 * a warm reset followed by an optional cold reset for codec */
1256 wm9713_reset(codec
, 0);
1257 ret
= wm9713_reset(codec
, 1);
1259 printk(KERN_ERR
"Failed to reset WM9713: AC97 link error\n");
1263 wm9713_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1265 /* unmute the adc - move to kcontrol */
1266 reg
= ac97_read(codec
, AC97_CD
) & 0x7fff;
1267 ac97_write(codec
, AC97_CD
, reg
);
1269 snd_soc_add_controls(codec
, wm9713_snd_ac97_controls
,
1270 ARRAY_SIZE(wm9713_snd_ac97_controls
));
1271 wm9713_add_widgets(codec
);
1276 snd_soc_free_pcms(socdev
);
1278 snd_soc_free_ac97_codec(codec
);
1281 kfree(snd_soc_codec_get_drvdata(codec
));
1284 kfree(codec
->reg_cache
);
1287 kfree(socdev
->card
->codec
);
1288 socdev
->card
->codec
= NULL
;
1292 static int wm9713_soc_remove(struct platform_device
*pdev
)
1294 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
1295 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1300 snd_soc_dapm_free(socdev
);
1301 snd_soc_free_pcms(socdev
);
1302 snd_soc_free_ac97_codec(codec
);
1303 kfree(snd_soc_codec_get_drvdata(codec
));
1304 kfree(codec
->reg_cache
);
1309 struct snd_soc_codec_device soc_codec_dev_wm9713
= {
1310 .probe
= wm9713_soc_probe
,
1311 .remove
= wm9713_soc_remove
,
1312 .suspend
= wm9713_soc_suspend
,
1313 .resume
= wm9713_soc_resume
,
1315 EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713
);
1317 MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1318 MODULE_AUTHOR("Liam Girdwood");
1319 MODULE_LICENSE("GPL");