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