2 * wm9713.c -- ALSA Soc WM9713 codec support
4 * Copyright 2006-10 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>
32 #define WM9713_VENDOR_ID 0x574d4c13
33 #define WM9713_VENDOR_ID_MASK 0xffffffff
36 struct snd_ac97
*ac97
;
37 u32 pll_in
; /* PLL input frequency */
38 unsigned int hp_mixer
[2];
42 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
44 static int ac97_write(struct snd_soc_codec
*codec
,
45 unsigned int reg
, unsigned int val
);
48 * WM9713 register cache
49 * Reg 0x3c bit 15 is used by touch driver.
51 static const u16 wm9713_reg
[] = {
52 0x6174, 0x8080, 0x8080, 0x8080,
53 0xc880, 0xe808, 0xe808, 0x0808,
54 0x00da, 0x8000, 0xd600, 0xaaa0,
55 0xaaa0, 0xaaa0, 0x0000, 0x0000,
56 0x0f0f, 0x0040, 0x0000, 0x7f00,
57 0x0405, 0x0410, 0xbb80, 0xbb80,
58 0x0000, 0xbb80, 0x0000, 0x4523,
59 0x0000, 0x2000, 0x7eff, 0xffff,
60 0x0000, 0x0000, 0x0080, 0x0000,
61 0x0000, 0x0000, 0xfffe, 0xffff,
62 0x0000, 0x0000, 0x0000, 0xfffe,
63 0x4000, 0x0000, 0x0000, 0x0000,
64 0xb032, 0x3e00, 0x0000, 0x0000,
65 0x0000, 0x0000, 0x0000, 0x0000,
66 0x0000, 0x0000, 0x0000, 0x0006,
67 0x0001, 0x0000, 0x574d, 0x4c13,
73 static const char *wm9713_mic_mixer
[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
74 static const char *wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
75 static const char *wm9713_rec_src
[] =
76 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
78 static const char *wm9713_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
79 static const char *wm9713_alc_select
[] = {"None", "Left", "Right", "Stereo"};
80 static const char *wm9713_mono_pga
[] = {"Vmid", "Zh", "Mono", "Inv"};
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",
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"};
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_VIRT(2, wm9713_micb_select
), /* mic selection 19 */
119 static const DECLARE_TLV_DB_SCALE(out_tlv
, -4650, 150, 0);
120 static const DECLARE_TLV_DB_SCALE(main_tlv
, -3450, 150, 0);
121 static const DECLARE_TLV_DB_SCALE(misc_tlv
, -1500, 300, 0);
122 static const DECLARE_TLV_DB_RANGE(mic_tlv
,
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
= snd_soc_dapm_to_codec(w
->dapm
);
225 if (WARN_ON(event
!= SND_SOC_DAPM_PRE_PMD
))
228 /* Gracefully shut down the voice interface. */
229 status
= ac97_read(codec
, AC97_EXTENDED_MID
) | 0x1000;
230 rate
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xF0FF;
231 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0200);
232 schedule_timeout_interruptible(msecs_to_jiffies(1));
233 ac97_write(codec
, AC97_HANDSET_RATE
, rate
| 0x0F00);
234 ac97_write(codec
, AC97_EXTENDED_MID
, status
);
239 static const unsigned int wm9713_mixer_mute_regs
[] = {
248 /* We have to create a fake left and right HP mixers because
249 * the codec only has a single control that is shared by both channels.
250 * This makes it impossible to determine the audio path using the current
251 * register map, thus we add a new (virtual) register to help determine the
252 * audio route within the device.
254 static int wm9713_hp_mixer_put(struct snd_kcontrol
*kcontrol
,
255 struct snd_ctl_elem_value
*ucontrol
)
257 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
258 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(dapm
);
259 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
260 unsigned int val
= ucontrol
->value
.integer
.value
[0];
261 struct soc_mixer_control
*mc
=
262 (struct soc_mixer_control
*)kcontrol
->private_value
;
263 unsigned int mixer
, mask
, shift
, old
;
264 struct snd_soc_dapm_update update
;
267 mixer
= mc
->shift
>> 8;
268 shift
= mc
->shift
& 0xff;
271 mutex_lock(&wm9713
->lock
);
272 old
= wm9713
->hp_mixer
[mixer
];
273 if (ucontrol
->value
.integer
.value
[0])
274 wm9713
->hp_mixer
[mixer
] |= mask
;
276 wm9713
->hp_mixer
[mixer
] &= ~mask
;
278 change
= old
!= wm9713
->hp_mixer
[mixer
];
280 update
.kcontrol
= kcontrol
;
281 update
.reg
= wm9713_mixer_mute_regs
[shift
];
282 update
.mask
= 0x8000;
283 if ((wm9713
->hp_mixer
[0] & mask
) ||
284 (wm9713
->hp_mixer
[1] & mask
))
289 snd_soc_dapm_mixer_update_power(dapm
, kcontrol
, val
,
293 mutex_unlock(&wm9713
->lock
);
298 static int wm9713_hp_mixer_get(struct snd_kcontrol
*kcontrol
,
299 struct snd_ctl_elem_value
*ucontrol
)
301 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
302 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(dapm
);
303 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
304 struct soc_mixer_control
*mc
=
305 (struct soc_mixer_control
*)kcontrol
->private_value
;
306 unsigned int mixer
, shift
;
308 mixer
= mc
->shift
>> 8;
309 shift
= mc
->shift
& 0xff;
311 ucontrol
->value
.integer
.value
[0] =
312 (wm9713
->hp_mixer
[mixer
] >> shift
) & 1;
317 #define WM9713_HP_MIXER_CTRL(xname, xmixer, xshift) { \
318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
319 .info = snd_soc_info_volsw, \
320 .get = wm9713_hp_mixer_get, .put = wm9713_hp_mixer_put, \
321 .private_value = SOC_DOUBLE_VALUE(SND_SOC_NOPM, \
322 xshift, xmixer, 1, 0, 0) \
325 /* Left Headphone Mixers */
326 static const struct snd_kcontrol_new wm9713_hpl_mixer_controls
[] = {
327 WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER
, 5),
328 WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER
, 4),
329 WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER
, 3),
330 WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER
, 2),
331 WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER
, 1),
332 WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER
, 0),
335 /* Right Headphone Mixers */
336 static const struct snd_kcontrol_new wm9713_hpr_mixer_controls
[] = {
337 WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER
, 5),
338 WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER
, 4),
339 WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER
, 3),
340 WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER
, 2),
341 WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER
, 1),
342 WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER
, 0),
345 /* headphone capture mux */
346 static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls
=
347 SOC_DAPM_ENUM("Route", wm9713_enum
[1]);
349 /* headphone mic mux */
350 static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls
=
351 SOC_DAPM_ENUM("Route", wm9713_enum
[0]);
354 static const struct snd_kcontrol_new wm9713_speaker_mixer_controls
[] = {
355 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 11, 1, 1),
356 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 11, 1, 1),
357 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 11, 1, 1),
358 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 14, 1, 1),
359 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 14, 1, 1),
360 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 14, 1, 1),
364 static const struct snd_kcontrol_new wm9713_mono_mixer_controls
[] = {
365 SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX
, 7, 1, 1),
366 SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM
, 7, 1, 1),
367 SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL
, 7, 1, 1),
368 SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE
, 13, 1, 1),
369 SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE
, 13, 1, 1),
370 SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP
, 13, 1, 1),
371 SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE
, 7, 1, 1),
372 SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE
, 6, 1, 1),
376 static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls
=
377 SOC_DAPM_ENUM("Route", wm9713_enum
[2]);
379 /* mono output mux */
380 static const struct snd_kcontrol_new wm9713_mono_mux_controls
=
381 SOC_DAPM_ENUM("Route", wm9713_enum
[7]);
383 /* speaker left output mux */
384 static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls
=
385 SOC_DAPM_ENUM("Route", wm9713_enum
[8]);
387 /* speaker right output mux */
388 static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls
=
389 SOC_DAPM_ENUM("Route", wm9713_enum
[9]);
391 /* headphone left output mux */
392 static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls
=
393 SOC_DAPM_ENUM("Route", wm9713_enum
[10]);
395 /* headphone right output mux */
396 static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls
=
397 SOC_DAPM_ENUM("Route", wm9713_enum
[11]);
400 static const struct snd_kcontrol_new wm9713_out3_mux_controls
=
401 SOC_DAPM_ENUM("Route", wm9713_enum
[12]);
404 static const struct snd_kcontrol_new wm9713_out4_mux_controls
=
405 SOC_DAPM_ENUM("Route", wm9713_enum
[13]);
408 static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls
=
409 SOC_DAPM_ENUM("Route", wm9713_enum
[14]);
412 static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls
=
413 SOC_DAPM_ENUM("Route", wm9713_enum
[15]);
415 /* Capture source left */
416 static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls
=
417 SOC_DAPM_ENUM("Route", wm9713_enum
[3]);
419 /* Capture source right */
420 static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls
=
421 SOC_DAPM_ENUM("Route", wm9713_enum
[4]);
424 static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls
=
425 SOC_DAPM_ENUM("Route", wm9713_enum
[18]);
427 /* mic source B virtual control */
428 static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls
=
429 SOC_DAPM_ENUM("Route", wm9713_enum
[19]);
431 static const struct snd_soc_dapm_widget wm9713_dapm_widgets
[] = {
432 SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM
, 0, 0,
433 &wm9713_hp_rec_mux_controls
),
434 SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM
, 0, 0,
435 &wm9713_hp_mic_mux_controls
),
436 SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM
, 0, 0,
437 &wm9713_mono_mic_mux_controls
),
438 SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM
, 0, 0,
439 &wm9713_mono_mux_controls
),
440 SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
441 &wm9713_hp_spkl_mux_controls
),
442 SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM
, 0, 0,
443 &wm9713_hp_spkr_mux_controls
),
444 SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
445 &wm9713_hpl_out_mux_controls
),
446 SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM
, 0, 0,
447 &wm9713_hpr_out_mux_controls
),
448 SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM
, 0, 0,
449 &wm9713_out3_mux_controls
),
450 SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM
, 0, 0,
451 &wm9713_out4_mux_controls
),
452 SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM
, 0, 0,
453 &wm9713_dac_inv1_mux_controls
),
454 SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM
, 0, 0,
455 &wm9713_dac_inv2_mux_controls
),
456 SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM
, 0, 0,
457 &wm9713_rec_srcl_mux_controls
),
458 SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM
, 0, 0,
459 &wm9713_rec_srcr_mux_controls
),
460 SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM
, 0, 0,
461 &wm9713_mic_sel_mux_controls
),
462 SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM
, 0, 0,
463 &wm9713_micb_sel_mux_controls
),
464 SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID
, 3, 1,
465 &wm9713_hpl_mixer_controls
[0], ARRAY_SIZE(wm9713_hpl_mixer_controls
)),
466 SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID
, 2, 1,
467 &wm9713_hpr_mixer_controls
[0], ARRAY_SIZE(wm9713_hpr_mixer_controls
)),
468 SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID
, 0, 1,
469 &wm9713_mono_mixer_controls
[0], ARRAY_SIZE(wm9713_mono_mixer_controls
)),
470 SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID
, 1, 1,
471 &wm9713_speaker_mixer_controls
[0],
472 ARRAY_SIZE(wm9713_speaker_mixer_controls
)),
473 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID
, 7, 1),
474 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID
, 6, 1),
475 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
476 SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
477 SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
478 SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
479 SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID
, 12, 1,
480 wm9713_voice_shutdown
, SND_SOC_DAPM_PRE_PMD
),
481 SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID
, 11, 1),
482 SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID
, 5, 1, NULL
, 0),
483 SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID
, 4, 1, NULL
, 0),
484 SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM
, 0, 0),
485 SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM
, 0, 0),
486 SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM
, 0, 0),
487 SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM
, 0, 0),
488 SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS
, 10, 1, NULL
, 0),
489 SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS
, 9, 1, NULL
, 0),
490 SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS
, 8, 1, NULL
, 0),
491 SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS
, 7, 1, NULL
, 0),
492 SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS
, 11, 1, NULL
, 0),
493 SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS
, 12, 1, NULL
, 0),
494 SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS
, 13, 1, NULL
, 0),
495 SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS
, 6, 1, NULL
, 0),
496 SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS
, 5, 1, NULL
, 0),
497 SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS
, 4, 1, NULL
, 0),
498 SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS
, 3, 1, NULL
, 0),
499 SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS
, 2, 1, NULL
, 0),
500 SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS
, 1, 1, NULL
, 0),
501 SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS
, 0, 1, NULL
, 0),
502 SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS
, 14, 1),
503 SND_SOC_DAPM_OUTPUT("MONO"),
504 SND_SOC_DAPM_OUTPUT("HPL"),
505 SND_SOC_DAPM_OUTPUT("HPR"),
506 SND_SOC_DAPM_OUTPUT("SPKL"),
507 SND_SOC_DAPM_OUTPUT("SPKR"),
508 SND_SOC_DAPM_OUTPUT("OUT3"),
509 SND_SOC_DAPM_OUTPUT("OUT4"),
510 SND_SOC_DAPM_INPUT("LINEL"),
511 SND_SOC_DAPM_INPUT("LINER"),
512 SND_SOC_DAPM_INPUT("MONOIN"),
513 SND_SOC_DAPM_INPUT("PCBEEP"),
514 SND_SOC_DAPM_INPUT("MIC1"),
515 SND_SOC_DAPM_INPUT("MIC2A"),
516 SND_SOC_DAPM_INPUT("MIC2B"),
517 SND_SOC_DAPM_VMID("VMID"),
520 static const struct snd_soc_dapm_route wm9713_audio_map
[] = {
522 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
523 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
524 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
525 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
526 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
527 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
528 {"Left HP Mixer", NULL
, "Capture Headphone Mux"},
531 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
532 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
533 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
534 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
535 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
536 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
537 {"Right HP Mixer", NULL
, "Capture Headphone Mux"},
539 /* virtual mixer - mixes left & right channels for spk and mono */
540 {"AC97 Mixer", NULL
, "Left DAC"},
541 {"AC97 Mixer", NULL
, "Right DAC"},
542 {"Line Mixer", NULL
, "Right Line In"},
543 {"Line Mixer", NULL
, "Left Line In"},
544 {"HP Mixer", NULL
, "Left HP Mixer"},
545 {"HP Mixer", NULL
, "Right HP Mixer"},
546 {"Capture Mixer", NULL
, "Left Capture Source"},
547 {"Capture Mixer", NULL
, "Right Capture Source"},
550 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
551 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
552 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
553 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
554 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
555 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
558 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
559 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
560 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
561 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
562 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
563 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
564 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
565 {"Mono Mixer", NULL
, "Capture Mono Mux"},
568 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
569 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
570 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
571 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
572 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
575 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
576 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
577 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
578 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
579 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
581 /* headphone left mux */
582 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
584 /* headphone right mux */
585 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
587 /* speaker left mux */
588 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
589 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
590 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
592 /* speaker right mux */
593 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
594 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
595 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
598 {"Mono Out Mux", "Mono", "Mono Mixer"},
599 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
602 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
605 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
608 {"HPL", NULL
, "Left Headphone"},
609 {"Left Headphone", NULL
, "Left Headphone Out Mux"},
610 {"HPR", NULL
, "Right Headphone"},
611 {"Right Headphone", NULL
, "Right Headphone Out Mux"},
612 {"OUT3", NULL
, "Out 3"},
613 {"Out 3", NULL
, "Out 3 Mux"},
614 {"OUT4", NULL
, "Out 4"},
615 {"Out 4", NULL
, "Out 4 Mux"},
616 {"SPKL", NULL
, "Left Speaker"},
617 {"Left Speaker", NULL
, "Left Speaker Out Mux"},
618 {"SPKR", NULL
, "Right Speaker"},
619 {"Right Speaker", NULL
, "Right Speaker Out Mux"},
620 {"MONO", NULL
, "Mono Out"},
621 {"Mono Out", NULL
, "Mono Out Mux"},
624 {"Left Line In", NULL
, "LINEL"},
625 {"Right Line In", NULL
, "LINER"},
626 {"Mono In", NULL
, "MONOIN"},
627 {"Mic A PGA", NULL
, "Mic A Pre Amp"},
628 {"Mic B PGA", NULL
, "Mic B Pre Amp"},
630 /* left capture select */
631 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
632 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
633 {"Left Capture Source", "Line", "LINEL"},
634 {"Left Capture Source", "Mono In", "MONOIN"},
635 {"Left Capture Source", "Headphone", "Left HP Mixer"},
636 {"Left Capture Source", "Speaker", "Speaker Mixer"},
637 {"Left Capture Source", "Mono Out", "Mono Mixer"},
639 /* right capture select */
640 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
641 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
642 {"Right Capture Source", "Line", "LINER"},
643 {"Right Capture Source", "Mono In", "MONOIN"},
644 {"Right Capture Source", "Headphone", "Right HP Mixer"},
645 {"Right Capture Source", "Speaker", "Speaker Mixer"},
646 {"Right Capture Source", "Mono Out", "Mono Mixer"},
649 {"Left ADC", NULL
, "Left Capture Source"},
650 {"Left Voice ADC", NULL
, "Left ADC"},
651 {"Left HiFi ADC", NULL
, "Left ADC"},
654 {"Right ADC", NULL
, "Right Capture Source"},
655 {"Right Voice ADC", NULL
, "Right ADC"},
656 {"Right HiFi ADC", NULL
, "Right ADC"},
659 {"Mic A Pre Amp", NULL
, "Mic A Source"},
660 {"Mic A Source", "Mic 1", "MIC1"},
661 {"Mic A Source", "Mic 2 A", "MIC2A"},
662 {"Mic A Source", "Mic 2 B", "Mic B Source"},
663 {"Mic B Pre Amp", "MPB", "Mic B Source"},
664 {"Mic B Source", NULL
, "MIC2B"},
666 /* headphone capture */
667 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
668 {"Capture Headphone Mux", "Left", "Left Capture Source"},
669 {"Capture Headphone Mux", "Right", "Right Capture Source"},
672 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
673 {"Capture Mono Mux", "Left", "Left Capture Source"},
674 {"Capture Mono Mux", "Right", "Right Capture Source"},
677 static unsigned int ac97_read(struct snd_soc_codec
*codec
,
680 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
681 u16
*cache
= codec
->reg_cache
;
683 if (reg
== AC97_RESET
|| reg
== AC97_GPIO_STATUS
||
684 reg
== AC97_VENDOR_ID1
|| reg
== AC97_VENDOR_ID2
||
686 return soc_ac97_ops
->read(wm9713
->ac97
, reg
);
690 if (reg
>= (ARRAY_SIZE(wm9713_reg
)))
697 static int ac97_write(struct snd_soc_codec
*codec
, unsigned int reg
,
700 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
702 u16
*cache
= codec
->reg_cache
;
703 soc_ac97_ops
->write(wm9713
->ac97
, reg
, val
);
705 if (reg
< (ARRAY_SIZE(wm9713_reg
)))
720 /* The size in bits of the PLL divide multiplied by 10
721 * to allow rounding later */
722 #define FIXED_PLL_SIZE ((1 << 22) * 10)
724 static void pll_factors(struct snd_soc_codec
*codec
,
725 struct _pll_div
*pll_div
, unsigned int source
)
728 unsigned int K
, Ndiv
, Nmod
, target
;
730 /* The the PLL output is always 98.304MHz. */
733 /* If the input frequency is over 14.4MHz then scale it down. */
734 if (source
> 14400000) {
738 if (source
> 14400000) {
749 /* Low frequency sources require an additional divide in the
752 if (source
< 8192000) {
758 Ndiv
= target
/ source
;
759 if ((Ndiv
< 5) || (Ndiv
> 12))
761 "WM9713 PLL N value %u out of recommended range!\n",
765 Nmod
= target
% source
;
766 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
768 do_div(Kpart
, source
);
770 K
= Kpart
& 0xFFFFFFFF;
772 /* Check if we need to round */
776 /* Move down to proper range now rounding is done */
783 * Please note that changing the PLL input frequency may require
784 * resynchronisation with the AC97 controller.
786 static int wm9713_set_pll(struct snd_soc_codec
*codec
,
787 int pll_id
, unsigned int freq_in
, unsigned int freq_out
)
789 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
791 struct _pll_div pll_div
;
795 /* disable PLL power and select ext source */
796 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
797 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| 0x0080);
798 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
799 ac97_write(codec
, AC97_EXTENDED_MID
, reg
| 0x0200);
804 pll_factors(codec
, &pll_div
, freq_in
);
806 if (pll_div
.k
== 0) {
807 reg
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) |
808 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
809 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
811 /* write the fractional k to the reg 0x46 pages */
812 reg2
= (pll_div
.n
<< 12) | (pll_div
.lf
<< 11) | (1 << 10) |
813 (pll_div
.divsel
<< 9) | (pll_div
.divctl
<< 8);
816 reg
= reg2
| (0x5 << 4) | (pll_div
.k
>> 20);
817 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
820 reg
= reg2
| (0x4 << 4) | ((pll_div
.k
>> 16) & 0xf);
821 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
824 reg
= reg2
| (0x3 << 4) | ((pll_div
.k
>> 12) & 0xf);
825 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
828 reg
= reg2
| (0x2 << 4) | ((pll_div
.k
>> 8) & 0xf);
829 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
832 reg
= reg2
| (0x1 << 4) | ((pll_div
.k
>> 4) & 0xf);
833 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
835 reg
= reg2
| (0x0 << 4) | (pll_div
.k
& 0xf); /* K [3:0] */
836 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
);
839 /* turn PLL on and select as source */
840 reg
= ac97_read(codec
, AC97_EXTENDED_MID
);
841 ac97_write(codec
, AC97_EXTENDED_MID
, reg
& 0xfdff);
842 reg
= ac97_read(codec
, AC97_HANDSET_RATE
);
843 ac97_write(codec
, AC97_HANDSET_RATE
, reg
& 0xff7f);
844 wm9713
->pll_in
= freq_in
;
846 /* wait 10ms AC97 link frames for the link to stabilise */
847 schedule_timeout_interruptible(msecs_to_jiffies(10));
851 static int wm9713_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
852 int source
, unsigned int freq_in
, unsigned int freq_out
)
854 struct snd_soc_codec
*codec
= codec_dai
->codec
;
855 return wm9713_set_pll(codec
, pll_id
, freq_in
, freq_out
);
859 * Tristate the PCM DAI lines, tristate can be disabled by calling
860 * wm9713_set_dai_fmt()
862 static int wm9713_set_dai_tristate(struct snd_soc_dai
*codec_dai
,
865 struct snd_soc_codec
*codec
= codec_dai
->codec
;
866 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0x9fff;
869 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
875 * Configure WM9713 clock dividers.
876 * Voice DAC needs 256 FS
878 static int wm9713_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
881 struct snd_soc_codec
*codec
= codec_dai
->codec
;
885 case WM9713_PCMCLK_DIV
:
886 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xf0ff;
887 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
889 case WM9713_CLKA_MULT
:
890 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffd;
891 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
893 case WM9713_CLKB_MULT
:
894 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0xfffb;
895 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
897 case WM9713_HIFI_DIV
:
898 reg
= ac97_read(codec
, AC97_HANDSET_RATE
) & 0x8fff;
899 ac97_write(codec
, AC97_HANDSET_RATE
, reg
| div
);
901 case WM9713_PCMBCLK_DIV
:
902 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xf1ff;
903 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
| div
);
905 case WM9713_PCMCLK_PLL_DIV
:
906 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
907 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x60 | div
);
909 case WM9713_HIFI_PLL_DIV
:
910 reg
= ac97_read(codec
, AC97_LINE1_LEVEL
) & 0xff80;
911 ac97_write(codec
, AC97_LINE1_LEVEL
, reg
| 0x70 | div
);
920 static int wm9713_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
923 struct snd_soc_codec
*codec
= codec_dai
->codec
;
924 u16 gpio
= ac97_read(codec
, AC97_GPIO_CFG
) & 0xffc5;
928 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
929 case SND_SOC_DAIFMT_CBM_CFM
:
933 case SND_SOC_DAIFMT_CBM_CFS
:
937 case SND_SOC_DAIFMT_CBS_CFS
:
941 case SND_SOC_DAIFMT_CBS_CFM
:
946 /* clock inversion */
947 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
948 case SND_SOC_DAIFMT_IB_IF
:
951 case SND_SOC_DAIFMT_IB_NF
:
954 case SND_SOC_DAIFMT_NB_IF
:
960 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
961 case SND_SOC_DAIFMT_I2S
:
964 case SND_SOC_DAIFMT_RIGHT_J
:
966 case SND_SOC_DAIFMT_LEFT_J
:
969 case SND_SOC_DAIFMT_DSP_A
:
972 case SND_SOC_DAIFMT_DSP_B
:
977 ac97_write(codec
, AC97_GPIO_CFG
, gpio
);
978 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
982 static int wm9713_pcm_hw_params(struct snd_pcm_substream
*substream
,
983 struct snd_pcm_hw_params
*params
,
984 struct snd_soc_dai
*dai
)
986 struct snd_soc_codec
*codec
= dai
->codec
;
987 u16 reg
= ac97_read(codec
, AC97_CENTER_LFE_MASTER
) & 0xfff3;
989 switch (params_width(params
)) {
1003 /* enable PCM interface in master mode */
1004 ac97_write(codec
, AC97_CENTER_LFE_MASTER
, reg
);
1008 static int ac97_hifi_prepare(struct snd_pcm_substream
*substream
,
1009 struct snd_soc_dai
*dai
)
1011 struct snd_soc_codec
*codec
= dai
->codec
;
1012 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1016 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
1017 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
1019 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1020 reg
= AC97_PCM_FRONT_DAC_RATE
;
1022 reg
= AC97_PCM_LR_ADC_RATE
;
1024 return ac97_write(codec
, reg
, runtime
->rate
);
1027 static int ac97_aux_prepare(struct snd_pcm_substream
*substream
,
1028 struct snd_soc_dai
*dai
)
1030 struct snd_soc_codec
*codec
= dai
->codec
;
1031 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1034 vra
= ac97_read(codec
, AC97_EXTENDED_STATUS
);
1035 ac97_write(codec
, AC97_EXTENDED_STATUS
, vra
| 0x1);
1036 xsle
= ac97_read(codec
, AC97_PCI_SID
);
1037 ac97_write(codec
, AC97_PCI_SID
, xsle
| 0x8000);
1039 if (substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1042 return ac97_write(codec
, AC97_PCM_SURR_DAC_RATE
, runtime
->rate
);
1045 #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \
1046 SNDRV_PCM_RATE_11025 | \
1047 SNDRV_PCM_RATE_22050 | \
1048 SNDRV_PCM_RATE_44100 | \
1049 SNDRV_PCM_RATE_48000)
1051 #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \
1052 SNDRV_PCM_RATE_11025 | \
1053 SNDRV_PCM_RATE_16000 | \
1054 SNDRV_PCM_RATE_22050 | \
1055 SNDRV_PCM_RATE_44100 | \
1056 SNDRV_PCM_RATE_48000)
1058 #define WM9713_PCM_FORMATS \
1059 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1060 SNDRV_PCM_FMTBIT_S24_LE)
1062 static const struct snd_soc_dai_ops wm9713_dai_ops_hifi
= {
1063 .prepare
= ac97_hifi_prepare
,
1064 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1065 .set_pll
= wm9713_set_dai_pll
,
1068 static const struct snd_soc_dai_ops wm9713_dai_ops_aux
= {
1069 .prepare
= ac97_aux_prepare
,
1070 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1071 .set_pll
= wm9713_set_dai_pll
,
1074 static const struct snd_soc_dai_ops wm9713_dai_ops_voice
= {
1075 .hw_params
= wm9713_pcm_hw_params
,
1076 .set_clkdiv
= wm9713_set_dai_clkdiv
,
1077 .set_pll
= wm9713_set_dai_pll
,
1078 .set_fmt
= wm9713_set_dai_fmt
,
1079 .set_tristate
= wm9713_set_dai_tristate
,
1082 static struct snd_soc_dai_driver wm9713_dai
[] = {
1084 .name
= "wm9713-hifi",
1086 .stream_name
= "HiFi Playback",
1089 .rates
= WM9713_RATES
,
1090 .formats
= SND_SOC_STD_AC97_FMTS
,},
1092 .stream_name
= "HiFi Capture",
1095 .rates
= WM9713_RATES
,
1096 .formats
= SND_SOC_STD_AC97_FMTS
,},
1097 .ops
= &wm9713_dai_ops_hifi
,
1100 .name
= "wm9713-aux",
1102 .stream_name
= "Aux Playback",
1105 .rates
= WM9713_RATES
,
1106 .formats
= SND_SOC_STD_AC97_FMTS
,},
1107 .ops
= &wm9713_dai_ops_aux
,
1110 .name
= "wm9713-voice",
1112 .stream_name
= "Voice Playback",
1115 .rates
= WM9713_PCM_RATES
,
1116 .formats
= WM9713_PCM_FORMATS
,},
1118 .stream_name
= "Voice Capture",
1121 .rates
= WM9713_PCM_RATES
,
1122 .formats
= WM9713_PCM_FORMATS
,},
1123 .ops
= &wm9713_dai_ops_voice
,
1124 .symmetric_rates
= 1,
1128 static int wm9713_set_bias_level(struct snd_soc_codec
*codec
,
1129 enum snd_soc_bias_level level
)
1134 case SND_SOC_BIAS_ON
:
1135 /* enable thermal shutdown */
1136 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x1bff;
1137 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1139 case SND_SOC_BIAS_PREPARE
:
1141 case SND_SOC_BIAS_STANDBY
:
1142 /* enable master bias and vmid */
1143 reg
= ac97_read(codec
, AC97_EXTENDED_MID
) & 0x3bff;
1144 ac97_write(codec
, AC97_EXTENDED_MID
, reg
);
1145 ac97_write(codec
, AC97_POWERDOWN
, 0x0000);
1147 case SND_SOC_BIAS_OFF
:
1148 /* disable everything including AC link */
1149 ac97_write(codec
, AC97_EXTENDED_MID
, 0xffff);
1150 ac97_write(codec
, AC97_EXTENDED_MSTATUS
, 0xffff);
1151 ac97_write(codec
, AC97_POWERDOWN
, 0xffff);
1157 static int wm9713_soc_suspend(struct snd_soc_codec
*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 snd_soc_codec
*codec
)
1175 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
1177 u16
*cache
= codec
->reg_cache
;
1179 ret
= snd_ac97_reset(wm9713
->ac97
, true, WM9713_VENDOR_ID
,
1180 WM9713_VENDOR_ID_MASK
);
1184 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1186 /* do we need to re-start the PLL ? */
1188 wm9713_set_pll(codec
, 0, wm9713
->pll_in
, 0);
1190 /* only synchronise the codec if warm reset failed */
1192 for (i
= 2; i
< ARRAY_SIZE(wm9713_reg
) << 1; i
+= 2) {
1193 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_MID
||
1194 i
== AC97_EXTENDED_MSTATUS
|| i
> 0x66)
1196 soc_ac97_ops
->write(wm9713
->ac97
, i
, cache
[i
>>1]);
1203 static int wm9713_soc_probe(struct snd_soc_codec
*codec
)
1205 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
1208 wm9713
->ac97
= snd_soc_new_ac97_codec(codec
, WM9713_VENDOR_ID
,
1209 WM9713_VENDOR_ID_MASK
);
1210 if (IS_ERR(wm9713
->ac97
))
1211 return PTR_ERR(wm9713
->ac97
);
1213 /* unmute the adc - move to kcontrol */
1214 reg
= ac97_read(codec
, AC97_CD
) & 0x7fff;
1215 ac97_write(codec
, AC97_CD
, reg
);
1220 static int wm9713_soc_remove(struct snd_soc_codec
*codec
)
1222 struct wm9713_priv
*wm9713
= snd_soc_codec_get_drvdata(codec
);
1224 snd_soc_free_ac97_codec(wm9713
->ac97
);
1228 static struct snd_soc_codec_driver soc_codec_dev_wm9713
= {
1229 .probe
= wm9713_soc_probe
,
1230 .remove
= wm9713_soc_remove
,
1231 .suspend
= wm9713_soc_suspend
,
1232 .resume
= wm9713_soc_resume
,
1234 .write
= ac97_write
,
1235 .set_bias_level
= wm9713_set_bias_level
,
1236 .reg_cache_size
= ARRAY_SIZE(wm9713_reg
),
1237 .reg_word_size
= sizeof(u16
),
1238 .reg_cache_step
= 2,
1239 .reg_cache_default
= wm9713_reg
,
1241 .controls
= wm9713_snd_ac97_controls
,
1242 .num_controls
= ARRAY_SIZE(wm9713_snd_ac97_controls
),
1243 .dapm_widgets
= wm9713_dapm_widgets
,
1244 .num_dapm_widgets
= ARRAY_SIZE(wm9713_dapm_widgets
),
1245 .dapm_routes
= wm9713_audio_map
,
1246 .num_dapm_routes
= ARRAY_SIZE(wm9713_audio_map
),
1249 static int wm9713_probe(struct platform_device
*pdev
)
1251 struct wm9713_priv
*wm9713
;
1253 wm9713
= devm_kzalloc(&pdev
->dev
, sizeof(*wm9713
), GFP_KERNEL
);
1257 mutex_init(&wm9713
->lock
);
1259 platform_set_drvdata(pdev
, wm9713
);
1261 return snd_soc_register_codec(&pdev
->dev
,
1262 &soc_codec_dev_wm9713
, wm9713_dai
, ARRAY_SIZE(wm9713_dai
));
1265 static int wm9713_remove(struct platform_device
*pdev
)
1267 snd_soc_unregister_codec(&pdev
->dev
);
1271 static struct platform_driver wm9713_codec_driver
= {
1273 .name
= "wm9713-codec",
1276 .probe
= wm9713_probe
,
1277 .remove
= wm9713_remove
,
1280 module_platform_driver(wm9713_codec_driver
);
1282 MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1283 MODULE_AUTHOR("Liam Girdwood");
1284 MODULE_LICENSE("GPL");