blob: 4083a5130cbd192a37fbfd8895b47b7cce2fc46f [file] [log] [blame]
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001/*
2 * wm9713.c -- ALSA Soc WM9713 codec support
3 *
Mark Brown656baae2012-05-23 12:39:07 +01004 * Copyright 2006-10 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010020#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>
Mark Browne03a8d22010-01-28 12:36:07 +000027#include <sound/tlv.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010028#include <sound/soc.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010029
30#include "wm9713.h"
31
Lars-Peter Clausen310398f2015-07-21 21:53:06 +020032#define WM9713_VENDOR_ID 0x574d4c13
33#define WM9713_VENDOR_ID_MASK 0xffffffff
34
Liam Girdwood83ac08c2008-02-15 16:43:11 +010035struct wm9713_priv {
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010036 struct snd_ac97 *ac97;
Liam Girdwood83ac08c2008-02-15 16:43:11 +010037 u32 pll_in; /* PLL input frequency */
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +010038 unsigned int hp_mixer[2];
39 struct mutex lock;
Liam Girdwood83ac08c2008-02-15 16:43:11 +010040};
41
42static unsigned int ac97_read(struct snd_soc_codec *codec,
43 unsigned int reg);
44static int ac97_write(struct snd_soc_codec *codec,
45 unsigned int reg, unsigned int val);
46
47/*
48 * WM9713 register cache
49 * Reg 0x3c bit 15 is used by touch driver.
50 */
51static 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,
Liam Girdwood83ac08c2008-02-15 16:43:11 +010068};
69
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +010070#define HPL_MIXER 0
71#define HPR_MIXER 1
Liam Girdwood83ac08c2008-02-15 16:43:11 +010072
73static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
74static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
75static const char *wm9713_rec_src[] =
76 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
77 "Mono Out", "Zh"};
78static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
79static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
Matt Reimera7f0b832014-05-19 09:35:47 -070080static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv"};
Liam Girdwood83ac08c2008-02-15 16:43:11 +010081static const char *wm9713_spk_pga[] =
82 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
83 "Speaker Vmid", "Inv Vmid"};
84static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone",
85 "Headphone Vmid"};
86static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
87static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
88static const char *wm9713_dac_inv[] =
89 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
90 "Headphone Mono", "NC", "Vmid"};
91static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
92static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"};
93static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
94static const char *wm9713_micb_select[] = {"MPB", "MPA"};
95
96static const struct soc_enum wm9713_enum[] = {
97SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
98SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
99SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */
100SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */
101SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/
102SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
103SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
104SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
105SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
106SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
107SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */
108SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */
109SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
110SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
111SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */
112SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
113SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
114SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
115SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
Lars-Peter Clausen5bc39b52014-10-30 21:01:10 +0100116SOC_ENUM_SINGLE_VIRT(2, wm9713_micb_select), /* mic selection 19 */
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100117};
118
Mark Browne03a8d22010-01-28 12:36:07 +0000119static const DECLARE_TLV_DB_SCALE(out_tlv, -4650, 150, 0);
120static const DECLARE_TLV_DB_SCALE(main_tlv, -3450, 150, 0);
121static const DECLARE_TLV_DB_SCALE(misc_tlv, -1500, 300, 0);
Lars-Peter Clausen5092e762015-08-02 17:20:09 +0200122static const DECLARE_TLV_DB_RANGE(mic_tlv,
Mark Browne03a8d22010-01-28 12:36:07 +0000123 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0),
Lars-Peter Clausen5092e762015-08-02 17:20:09 +0200124 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0)
125);
Mark Browne03a8d22010-01-28 12:36:07 +0000126
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100127static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
Mark Browne03a8d22010-01-28 12:36:07 +0000128SOC_DOUBLE_TLV("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100129SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
Mark Browne03a8d22010-01-28 12:36:07 +0000130SOC_DOUBLE_TLV("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1,
131 out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100132SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1),
Mark Browne03a8d22010-01-28 12:36:07 +0000133SOC_DOUBLE_TLV("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1, main_tlv),
134SOC_DOUBLE_TLV("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1, main_tlv),
135SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC, 8, 31, 1, main_tlv),
136SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC, 0, 31, 1, main_tlv),
137SOC_SINGLE_TLV("Mic 1 Preamp Volume", AC97_3D_CONTROL, 10, 3, 0, mic_tlv),
138SOC_SINGLE_TLV("Mic 2 Preamp Volume", AC97_3D_CONTROL, 12, 3, 0, mic_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100139
140SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
141SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
142
143SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
144SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
145SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0),
146SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
147
Mark Browne03a8d22010-01-28 12:36:07 +0000148SOC_SINGLE_TLV("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1, misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100149SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
150SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
151
152SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
153SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
Mark Brown13d622b2008-10-30 12:37:10 +0000154SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100155SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
156SOC_ENUM("ALC Function", wm9713_enum[6]),
157SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
158SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
159SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
160SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
161SOC_ENUM("ALC NG Type", wm9713_enum[17]),
162SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
163
164SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
165SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
166
167SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
168SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000169SOC_SINGLE_TLV("Out4 Playback Volume", AC97_MASTER_MONO, 8, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100170
171SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1),
172SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000173SOC_SINGLE_TLV("Out3 Playback Volume", AC97_MASTER_MONO, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100174
Mark Browne03a8d22010-01-28 12:36:07 +0000175SOC_SINGLE_TLV("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1, main_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100176SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
177SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000178SOC_SINGLE_TLV("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100179
Mark Browne03a8d22010-01-28 12:36:07 +0000180SOC_SINGLE_TLV("Headphone Mixer Beep Playback Volume", AC97_AUX, 12, 7, 1,
181 misc_tlv),
182SOC_SINGLE_TLV("Speaker Mixer Beep Playback Volume", AC97_AUX, 8, 7, 1,
183 misc_tlv),
184SOC_SINGLE_TLV("Mono Mixer Beep Playback Volume", AC97_AUX, 4, 7, 1, misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100185
Mark Browne03a8d22010-01-28 12:36:07 +0000186SOC_SINGLE_TLV("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1,
187 misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100188SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
189SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
190
Mark Browne03a8d22010-01-28 12:36:07 +0000191SOC_SINGLE_TLV("Headphone Mixer Aux Playback Volume", AC97_REC_SEL, 12, 7, 1,
192 misc_tlv),
193
194SOC_SINGLE_TLV("Speaker Mixer Voice Playback Volume", AC97_PCM, 8, 7, 1,
195 misc_tlv),
196SOC_SINGLE_TLV("Speaker Mixer Aux Playback Volume", AC97_REC_SEL, 8, 7, 1,
197 misc_tlv),
198
199SOC_SINGLE_TLV("Mono Mixer Voice Playback Volume", AC97_PCM, 4, 7, 1,
200 misc_tlv),
201SOC_SINGLE_TLV("Mono Mixer Aux Playback Volume", AC97_REC_SEL, 4, 7, 1,
202 misc_tlv),
203
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100204SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
205SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100206
207SOC_ENUM("Bass Control", wm9713_enum[16]),
208SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
209SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
210SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
211SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
212SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
213
214SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
215SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
216SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
217};
218
Mark Brown6bbcb452009-04-13 11:29:10 +0100219static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w,
220 struct snd_kcontrol *kcontrol, int event)
221{
Lars-Peter Clausenff705082015-01-13 10:27:33 +0100222 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Mark Brown6bbcb452009-04-13 11:29:10 +0100223 u16 status, rate;
224
Takashi Iwaifb2e3e72013-11-05 18:39:59 +0100225 if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD))
226 return -EINVAL;
Mark Brown6bbcb452009-04-13 11:29:10 +0100227
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);
235
236 return 0;
237}
238
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100239static const unsigned int wm9713_mixer_mute_regs[] = {
240 AC97_PC_BEEP,
241 AC97_MASTER_TONE,
242 AC97_PHONE,
243 AC97_REC_SEL,
244 AC97_PCM,
245 AC97_AUX,
246};
Mark Brown6bbcb452009-04-13 11:29:10 +0100247
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100248/* 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.
253 */
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100254static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100256{
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100257 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);
Takashi Iwai87a8b282015-03-10 12:39:16 +0100260 unsigned int val = ucontrol->value.integer.value[0];
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100261 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;
265 bool change;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100266
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100267 mixer = mc->shift >> 8;
268 shift = mc->shift & 0xff;
269 mask = (1 << shift);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100270
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100271 mutex_lock(&wm9713->lock);
272 old = wm9713->hp_mixer[mixer];
Takashi Iwai87a8b282015-03-10 12:39:16 +0100273 if (ucontrol->value.integer.value[0])
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100274 wm9713->hp_mixer[mixer] |= mask;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100275 else
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100276 wm9713->hp_mixer[mixer] &= ~mask;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100277
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100278 change = old != wm9713->hp_mixer[mixer];
279 if (change) {
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))
285 update.val = 0x0;
286 else
287 update.val = 0x8000;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100288
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100289 snd_soc_dapm_mixer_update_power(dapm, kcontrol, val,
290 &update);
291 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100292
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100293 mutex_unlock(&wm9713->lock);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100294
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100295 return change;
296}
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100297
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100298static int wm9713_hp_mixer_get(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol)
300{
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;
307
308 mixer = mc->shift >> 8;
309 shift = mc->shift & 0xff;
310
Takashi Iwai87a8b282015-03-10 12:39:16 +0100311 ucontrol->value.integer.value[0] =
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100312 (wm9713->hp_mixer[mixer] >> shift) & 1;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100313
314 return 0;
315}
316
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100317#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) \
323}
324
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100325/* Left Headphone Mixers */
326static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100327WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER, 5),
328WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER, 4),
329WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 3),
330WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 2),
331WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER, 1),
332WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100333};
334
335/* Right Headphone Mixers */
336static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100337WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER, 5),
338WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER, 4),
339WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 3),
340WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 2),
341WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER, 1),
342WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100343};
344
345/* headphone capture mux */
346static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls =
347SOC_DAPM_ENUM("Route", wm9713_enum[1]);
348
349/* headphone mic mux */
350static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls =
351SOC_DAPM_ENUM("Route", wm9713_enum[0]);
352
353/* Speaker Mixer */
354static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100355SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100356SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
357SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
358SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
359SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
360SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
361};
362
363/* Mono Mixer */
364static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100365SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100366SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
367SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
368SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
369SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
370SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
371SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
372SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
373};
374
375/* mono mic mux */
376static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls =
377SOC_DAPM_ENUM("Route", wm9713_enum[2]);
378
379/* mono output mux */
380static const struct snd_kcontrol_new wm9713_mono_mux_controls =
381SOC_DAPM_ENUM("Route", wm9713_enum[7]);
382
383/* speaker left output mux */
384static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls =
385SOC_DAPM_ENUM("Route", wm9713_enum[8]);
386
387/* speaker right output mux */
388static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls =
389SOC_DAPM_ENUM("Route", wm9713_enum[9]);
390
391/* headphone left output mux */
392static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls =
393SOC_DAPM_ENUM("Route", wm9713_enum[10]);
394
395/* headphone right output mux */
396static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls =
397SOC_DAPM_ENUM("Route", wm9713_enum[11]);
398
399/* Out3 mux */
400static const struct snd_kcontrol_new wm9713_out3_mux_controls =
401SOC_DAPM_ENUM("Route", wm9713_enum[12]);
402
403/* Out4 mux */
404static const struct snd_kcontrol_new wm9713_out4_mux_controls =
405SOC_DAPM_ENUM("Route", wm9713_enum[13]);
406
407/* DAC inv mux 1 */
408static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls =
409SOC_DAPM_ENUM("Route", wm9713_enum[14]);
410
411/* DAC inv mux 2 */
412static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls =
413SOC_DAPM_ENUM("Route", wm9713_enum[15]);
414
415/* Capture source left */
416static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls =
417SOC_DAPM_ENUM("Route", wm9713_enum[3]);
418
419/* Capture source right */
420static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls =
421SOC_DAPM_ENUM("Route", wm9713_enum[4]);
422
423/* mic source */
424static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls =
425SOC_DAPM_ENUM("Route", wm9713_enum[18]);
426
427/* mic source B virtual control */
428static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls =
429SOC_DAPM_ENUM("Route", wm9713_enum[19]);
430
431static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
432SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0,
433 &wm9713_hp_rec_mux_controls),
434SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0,
435 &wm9713_hp_mic_mux_controls),
436SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0,
437 &wm9713_mono_mic_mux_controls),
438SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0,
439 &wm9713_mono_mux_controls),
440SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0,
441 &wm9713_hp_spkl_mux_controls),
442SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0,
443 &wm9713_hp_spkr_mux_controls),
444SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0,
445 &wm9713_hpl_out_mux_controls),
446SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0,
447 &wm9713_hpr_out_mux_controls),
448SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0,
449 &wm9713_out3_mux_controls),
450SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0,
451 &wm9713_out4_mux_controls),
452SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0,
453 &wm9713_dac_inv1_mux_controls),
454SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0,
455 &wm9713_dac_inv2_mux_controls),
456SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
457 &wm9713_rec_srcl_mux_controls),
458SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
459 &wm9713_rec_srcr_mux_controls),
460SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
461 &wm9713_mic_sel_mux_controls),
462SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
463 &wm9713_micb_sel_mux_controls),
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100464SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
465 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls)),
466SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
467 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls)),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100468SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
469 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
470SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
471 &wm9713_speaker_mixer_controls[0],
472 ARRAY_SIZE(wm9713_speaker_mixer_controls)),
473SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1),
474SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1),
475SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
476SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
477SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
478SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
Mark Brown6bbcb452009-04-13 11:29:10 +0100479SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1,
480 wm9713_voice_shutdown, SND_SOC_DAPM_PRE_PMD),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100481SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1),
Mark Brownccbc3012008-09-15 15:51:13 +0100482SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0),
483SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0),
484SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
485SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
486SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM, 0, 0),
487SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM, 0, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100488SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
489SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
490SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
491SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
492SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
493SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
494SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
495SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
496SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
497SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
498SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
499SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
500SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
501SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
502SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
503SND_SOC_DAPM_OUTPUT("MONO"),
504SND_SOC_DAPM_OUTPUT("HPL"),
505SND_SOC_DAPM_OUTPUT("HPR"),
506SND_SOC_DAPM_OUTPUT("SPKL"),
507SND_SOC_DAPM_OUTPUT("SPKR"),
508SND_SOC_DAPM_OUTPUT("OUT3"),
509SND_SOC_DAPM_OUTPUT("OUT4"),
510SND_SOC_DAPM_INPUT("LINEL"),
511SND_SOC_DAPM_INPUT("LINER"),
512SND_SOC_DAPM_INPUT("MONOIN"),
513SND_SOC_DAPM_INPUT("PCBEEP"),
514SND_SOC_DAPM_INPUT("MIC1"),
515SND_SOC_DAPM_INPUT("MIC2A"),
516SND_SOC_DAPM_INPUT("MIC2B"),
517SND_SOC_DAPM_VMID("VMID"),
518};
519
Lu Guanqun7ad7dd12011-03-30 21:53:11 +0800520static const struct snd_soc_dapm_route wm9713_audio_map[] = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100521 /* left HP mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100522 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100523 {"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"},
529
530 /* right HP mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100531 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100532 {"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"},
538
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"},
548
549 /* speaker mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100550 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100551 {"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"},
556
557 /* mono mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100558 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100559 {"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"},
Robert Jarzmikc0bbf482008-03-18 12:08:35 +0100563 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
564 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100565 {"Mono Mixer", NULL, "Capture Mono Mux"},
566
567 /* DAC inv mux 1 */
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"},
573
574 /* DAC inv mux 2 */
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"},
580
581 /* headphone left mux */
582 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
583
584 /* headphone right mux */
585 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
586
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"},
591
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"},
596
597 /* mono mux */
598 {"Mono Out Mux", "Mono", "Mono Mixer"},
599 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
600
601 /* out 3 mux */
602 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
603
604 /* out 4 mux */
605 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
606
607 /* output pga */
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"},
622
623 /* input pga */
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"},
629
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"},
638
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"},
647
648 /* left ADC */
649 {"Left ADC", NULL, "Left Capture Source"},
Mark Brownccbc3012008-09-15 15:51:13 +0100650 {"Left Voice ADC", NULL, "Left ADC"},
651 {"Left HiFi ADC", NULL, "Left ADC"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100652
653 /* right ADC */
654 {"Right ADC", NULL, "Right Capture Source"},
Mark Brownccbc3012008-09-15 15:51:13 +0100655 {"Right Voice ADC", NULL, "Right ADC"},
656 {"Right HiFi ADC", NULL, "Right ADC"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100657
658 /* mic */
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"},
665
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"},
670
671 /* mono capture */
672 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
673 {"Capture Mono Mux", "Left", "Left Capture Source"},
674 {"Capture Mono Mux", "Right", "Right Capture Source"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100675};
676
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100677static unsigned int ac97_read(struct snd_soc_codec *codec,
678 unsigned int reg)
679{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +0100680 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100681 u16 *cache = codec->reg_cache;
682
683 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
684 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
685 reg == AC97_CD)
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +0100686 return soc_ac97_ops->read(wm9713->ac97, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100687 else {
688 reg = reg >> 1;
689
Ian Molton91432e92009-01-17 17:44:23 +0000690 if (reg >= (ARRAY_SIZE(wm9713_reg)))
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100691 return -EIO;
692
693 return cache[reg];
694 }
695}
696
697static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
698 unsigned int val)
699{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +0100700 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
701
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100702 u16 *cache = codec->reg_cache;
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +0100703 soc_ac97_ops->write(wm9713->ac97, reg, val);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100704 reg = reg >> 1;
Ian Molton91432e92009-01-17 17:44:23 +0000705 if (reg < (ARRAY_SIZE(wm9713_reg)))
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100706 cache[reg] = val;
707
708 return 0;
709}
710
711/* PLL divisors */
712struct _pll_div {
713 u32 divsel:1;
714 u32 divctl:1;
715 u32 lf:1;
716 u32 n:4;
717 u32 k:24;
718};
719
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)
723
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100724static void pll_factors(struct snd_soc_codec *codec,
725 struct _pll_div *pll_div, unsigned int source)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100726{
727 u64 Kpart;
728 unsigned int K, Ndiv, Nmod, target;
729
730 /* The the PLL output is always 98.304MHz. */
731 target = 98304000;
732
733 /* If the input frequency is over 14.4MHz then scale it down. */
734 if (source > 14400000) {
735 source >>= 1;
736 pll_div->divsel = 1;
737
738 if (source > 14400000) {
739 source >>= 1;
740 pll_div->divctl = 1;
741 } else
742 pll_div->divctl = 0;
743
744 } else {
745 pll_div->divsel = 0;
746 pll_div->divctl = 0;
747 }
748
749 /* Low frequency sources require an additional divide in the
750 * loop.
751 */
752 if (source < 8192000) {
753 pll_div->lf = 1;
754 target >>= 2;
755 } else
756 pll_div->lf = 0;
757
758 Ndiv = target / source;
759 if ((Ndiv < 5) || (Ndiv > 12))
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100760 dev_warn(codec->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700761 "WM9713 PLL N value %u out of recommended range!\n",
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100762 Ndiv);
763
764 pll_div->n = Ndiv;
765 Nmod = target % source;
766 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
767
768 do_div(Kpart, source);
769
770 K = Kpart & 0xFFFFFFFF;
771
772 /* Check if we need to round */
773 if ((K % 10) >= 5)
774 K += 5;
775
776 /* Move down to proper range now rounding is done */
777 K /= 10;
778
779 pll_div->k = K;
780}
781
782/**
783 * Please note that changing the PLL input frequency may require
784 * resynchronisation with the AC97 controller.
785 */
786static int wm9713_set_pll(struct snd_soc_codec *codec,
787 int pll_id, unsigned int freq_in, unsigned int freq_out)
788{
Mark Brownb2c812e2010-04-14 15:35:19 +0900789 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100790 u16 reg, reg2;
791 struct _pll_div pll_div;
792
793 /* turn PLL off ? */
Mark Brownc42f69b2009-01-16 16:31:03 +0000794 if (freq_in == 0) {
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100795 /* 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);
Mark Brownc42f69b2009-01-16 16:31:03 +0000800 wm9713->pll_in = 0;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100801 return 0;
802 }
803
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100804 pll_factors(codec, &pll_div, freq_in);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100805
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);
810 } else {
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);
814
815 /* K [21:20] */
816 reg = reg2 | (0x5 << 4) | (pll_div.k >> 20);
817 ac97_write(codec, AC97_LINE1_LEVEL, reg);
818
819 /* K [19:16] */
820 reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf);
821 ac97_write(codec, AC97_LINE1_LEVEL, reg);
822
823 /* K [15:12] */
824 reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf);
825 ac97_write(codec, AC97_LINE1_LEVEL, reg);
826
827 /* K [11:8] */
828 reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf);
829 ac97_write(codec, AC97_LINE1_LEVEL, reg);
830
831 /* K [7:4] */
832 reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf);
833 ac97_write(codec, AC97_LINE1_LEVEL, reg);
834
835 reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */
836 ac97_write(codec, AC97_LINE1_LEVEL, reg);
837 }
838
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);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100844 wm9713->pll_in = freq_in;
845
846 /* wait 10ms AC97 link frames for the link to stabilise */
847 schedule_timeout_interruptible(msecs_to_jiffies(10));
848 return 0;
849}
850
Mark Brown85488032009-09-05 18:52:16 +0100851static 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)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100853{
854 struct snd_soc_codec *codec = codec_dai->codec;
855 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
856}
857
858/*
859 * Tristate the PCM DAI lines, tristate can be disabled by calling
860 * wm9713_set_dai_fmt()
861 */
Liam Girdwoode550e172008-07-07 16:07:52 +0100862static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100863 int tristate)
864{
865 struct snd_soc_codec *codec = codec_dai->codec;
866 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff;
867
868 if (tristate)
869 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
870
871 return 0;
872}
873
874/*
875 * Configure WM9713 clock dividers.
876 * Voice DAC needs 256 FS
877 */
Liam Girdwoode550e172008-07-07 16:07:52 +0100878static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100879 int div_id, int div)
880{
881 struct snd_soc_codec *codec = codec_dai->codec;
882 u16 reg;
883
884 switch (div_id) {
885 case WM9713_PCMCLK_DIV:
886 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff;
887 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
888 break;
889 case WM9713_CLKA_MULT:
890 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd;
891 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
892 break;
893 case WM9713_CLKB_MULT:
894 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb;
895 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
896 break;
897 case WM9713_HIFI_DIV:
898 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff;
899 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
900 break;
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);
904 break;
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);
908 break;
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);
912 break;
913 default:
914 return -EINVAL;
915 }
916
917 return 0;
918}
919
Liam Girdwoode550e172008-07-07 16:07:52 +0100920static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100921 unsigned int fmt)
922{
923 struct snd_soc_codec *codec = codec_dai->codec;
924 u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5;
925 u16 reg = 0x8000;
926
927 /* clock masters */
928 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
929 case SND_SOC_DAIFMT_CBM_CFM:
930 reg |= 0x4000;
931 gpio |= 0x0010;
932 break;
933 case SND_SOC_DAIFMT_CBM_CFS:
934 reg |= 0x6000;
935 gpio |= 0x0018;
936 break;
937 case SND_SOC_DAIFMT_CBS_CFS:
Mark Brownd133b0c2008-06-11 13:47:11 +0100938 reg |= 0x2000;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100939 gpio |= 0x001a;
940 break;
941 case SND_SOC_DAIFMT_CBS_CFM:
942 gpio |= 0x0012;
943 break;
944 }
945
946 /* clock inversion */
947 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
948 case SND_SOC_DAIFMT_IB_IF:
949 reg |= 0x00c0;
950 break;
951 case SND_SOC_DAIFMT_IB_NF:
952 reg |= 0x0080;
953 break;
954 case SND_SOC_DAIFMT_NB_IF:
955 reg |= 0x0040;
956 break;
957 }
958
959 /* DAI format */
960 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
961 case SND_SOC_DAIFMT_I2S:
962 reg |= 0x0002;
963 break;
964 case SND_SOC_DAIFMT_RIGHT_J:
965 break;
966 case SND_SOC_DAIFMT_LEFT_J:
967 reg |= 0x0001;
968 break;
969 case SND_SOC_DAIFMT_DSP_A:
970 reg |= 0x0003;
971 break;
972 case SND_SOC_DAIFMT_DSP_B:
973 reg |= 0x0043;
974 break;
975 }
976
977 ac97_write(codec, AC97_GPIO_CFG, gpio);
978 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
979 return 0;
980}
981
982static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000983 struct snd_pcm_hw_params *params,
984 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100985{
Mark Brown55b8bac2008-11-24 14:05:29 +0000986 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100987 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3;
988
Mark Brown563fe712014-07-31 12:55:23 +0100989 switch (params_width(params)) {
990 case 16:
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100991 break;
Mark Brown563fe712014-07-31 12:55:23 +0100992 case 20:
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100993 reg |= 0x0004;
994 break;
Mark Brown563fe712014-07-31 12:55:23 +0100995 case 24:
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100996 reg |= 0x0008;
997 break;
Mark Brown563fe712014-07-31 12:55:23 +0100998 case 32:
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100999 reg |= 0x000c;
1000 break;
1001 }
1002
1003 /* enable PCM interface in master mode */
1004 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
1005 return 0;
1006}
1007
Mark Browndee89c42008-11-18 22:11:38 +00001008static int ac97_hifi_prepare(struct snd_pcm_substream *substream,
1009 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001010{
Mark Brown55b8bac2008-11-24 14:05:29 +00001011 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001012 struct snd_pcm_runtime *runtime = substream->runtime;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001013 int reg;
1014 u16 vra;
1015
1016 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
1017 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
1018
1019 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1020 reg = AC97_PCM_FRONT_DAC_RATE;
1021 else
1022 reg = AC97_PCM_LR_ADC_RATE;
1023
1024 return ac97_write(codec, reg, runtime->rate);
1025}
1026
Mark Browndee89c42008-11-18 22:11:38 +00001027static int ac97_aux_prepare(struct snd_pcm_substream *substream,
1028 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001029{
Mark Brown55b8bac2008-11-24 14:05:29 +00001030 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001031 struct snd_pcm_runtime *runtime = substream->runtime;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001032 u16 vra, xsle;
1033
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);
1038
1039 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
1040 return -ENODEV;
1041
1042 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
1043}
1044
Mark Brown54155522008-07-02 11:51:19 +01001045#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)
1050
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)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001057
1058#define WM9713_PCM_FORMATS \
Maciej S. Szmigieroe712bfc2015-05-23 18:32:29 +02001059 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1060 SNDRV_PCM_FMTBIT_S24_LE)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001061
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001062static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = {
Eric Miao6335d052009-03-03 09:41:00 +08001063 .prepare = ac97_hifi_prepare,
1064 .set_clkdiv = wm9713_set_dai_clkdiv,
1065 .set_pll = wm9713_set_dai_pll,
1066};
1067
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001068static const struct snd_soc_dai_ops wm9713_dai_ops_aux = {
Eric Miao6335d052009-03-03 09:41:00 +08001069 .prepare = ac97_aux_prepare,
1070 .set_clkdiv = wm9713_set_dai_clkdiv,
1071 .set_pll = wm9713_set_dai_pll,
1072};
1073
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001074static const struct snd_soc_dai_ops wm9713_dai_ops_voice = {
Eric Miao6335d052009-03-03 09:41:00 +08001075 .hw_params = wm9713_pcm_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +08001076 .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,
1080};
1081
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001082static struct snd_soc_dai_driver wm9713_dai[] = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001083{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001084 .name = "wm9713-hifi",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001085 .playback = {
1086 .stream_name = "HiFi Playback",
1087 .channels_min = 1,
1088 .channels_max = 2,
1089 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001090 .formats = SND_SOC_STD_AC97_FMTS,},
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001091 .capture = {
1092 .stream_name = "HiFi Capture",
1093 .channels_min = 1,
1094 .channels_max = 2,
1095 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001096 .formats = SND_SOC_STD_AC97_FMTS,},
Eric Miao6335d052009-03-03 09:41:00 +08001097 .ops = &wm9713_dai_ops_hifi,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001098 },
1099 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001100 .name = "wm9713-aux",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001101 .playback = {
1102 .stream_name = "Aux Playback",
1103 .channels_min = 1,
1104 .channels_max = 1,
1105 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001106 .formats = SND_SOC_STD_AC97_FMTS,},
Eric Miao6335d052009-03-03 09:41:00 +08001107 .ops = &wm9713_dai_ops_aux,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001108 },
1109 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001110 .name = "wm9713-voice",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001111 .playback = {
1112 .stream_name = "Voice Playback",
1113 .channels_min = 1,
1114 .channels_max = 1,
Mark Brown54155522008-07-02 11:51:19 +01001115 .rates = WM9713_PCM_RATES,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001116 .formats = WM9713_PCM_FORMATS,},
1117 .capture = {
1118 .stream_name = "Voice Capture",
1119 .channels_min = 1,
1120 .channels_max = 2,
Mark Brown54155522008-07-02 11:51:19 +01001121 .rates = WM9713_PCM_RATES,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001122 .formats = WM9713_PCM_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +08001123 .ops = &wm9713_dai_ops_voice,
Mark Brownf4976112009-04-13 10:53:02 +01001124 .symmetric_rates = 1,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001125 },
1126};
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001127
Mark Brown0be98982008-05-19 12:31:28 +02001128static int wm9713_set_bias_level(struct snd_soc_codec *codec,
1129 enum snd_soc_bias_level level)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001130{
1131 u16 reg;
1132
Mark Brown0be98982008-05-19 12:31:28 +02001133 switch (level) {
1134 case SND_SOC_BIAS_ON:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001135 /* enable thermal shutdown */
1136 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff;
1137 ac97_write(codec, AC97_EXTENDED_MID, reg);
1138 break;
Mark Brown0be98982008-05-19 12:31:28 +02001139 case SND_SOC_BIAS_PREPARE:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001140 break;
Mark Brown0be98982008-05-19 12:31:28 +02001141 case SND_SOC_BIAS_STANDBY:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001142 /* 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);
1146 break;
Mark Brown0be98982008-05-19 12:31:28 +02001147 case SND_SOC_BIAS_OFF:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001148 /* 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);
1152 break;
1153 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001154 return 0;
1155}
1156
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01001157static int wm9713_soc_suspend(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001158{
Mark Brown87b57fe2008-04-14 15:27:30 +02001159 u16 reg;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001160
Mark Brown87b57fe2008-04-14 15:27:30 +02001161 /* Disable everything except touchpanel - that will be handled
1162 * by the touch driver and left disabled if touch is not in
1163 * use. */
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);
1169
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001170 return 0;
1171}
1172
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001173static int wm9713_soc_resume(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001174{
Mark Brownb2c812e2010-04-14 15:35:19 +09001175 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001176 int i, ret;
1177 u16 *cache = codec->reg_cache;
1178
Lars-Peter Clausen310398f2015-07-21 21:53:06 +02001179 ret = snd_ac97_reset(wm9713->ac97, true, WM9713_VENDOR_ID,
1180 WM9713_VENDOR_ID_MASK);
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +01001181 if (ret < 0)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001182 return ret;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001183
Lars-Peter Clausenbd1204c2015-04-27 22:13:24 +02001184 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001185
1186 /* do we need to re-start the PLL ? */
Mark Brownc42f69b2009-01-16 16:31:03 +00001187 if (wm9713->pll_in)
1188 wm9713_set_pll(codec, 0, wm9713->pll_in, 0);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001189
1190 /* only synchronise the codec if warm reset failed */
1191 if (ret == 0) {
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)
1195 continue;
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001196 soc_ac97_ops->write(wm9713->ac97, i, cache[i>>1]);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001197 }
1198 }
1199
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001200 return ret;
1201}
1202
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001203static int wm9713_soc_probe(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001204{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001205 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausen310398f2015-07-21 21:53:06 +02001206 int reg;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001207
Lars-Peter Clausen310398f2015-07-21 21:53:06 +02001208 wm9713->ac97 = snd_soc_new_ac97_codec(codec, WM9713_VENDOR_ID,
1209 WM9713_VENDOR_ID_MASK);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001210 if (IS_ERR(wm9713->ac97))
1211 return PTR_ERR(wm9713->ac97);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001212
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001213 /* unmute the adc - move to kcontrol */
1214 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1215 ac97_write(codec, AC97_CD, reg);
1216
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001217 return 0;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001218}
1219
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001220static int wm9713_soc_remove(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001221{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001222 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1223
1224 snd_soc_free_ac97_codec(wm9713->ac97);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001225 return 0;
1226}
1227
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001228static struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001229 .probe = wm9713_soc_probe,
1230 .remove = wm9713_soc_remove,
1231 .suspend = wm9713_soc_suspend,
1232 .resume = wm9713_soc_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001233 .read = ac97_read,
1234 .write = ac97_write,
1235 .set_bias_level = wm9713_set_bias_level,
Dimitris Papastamose5eec342010-09-10 18:14:56 +01001236 .reg_cache_size = ARRAY_SIZE(wm9713_reg),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001237 .reg_word_size = sizeof(u16),
1238 .reg_cache_step = 2,
1239 .reg_cache_default = wm9713_reg,
Lars-Peter Clausenc1359ca2014-10-30 21:01:08 +01001240
1241 .controls = wm9713_snd_ac97_controls,
1242 .num_controls = ARRAY_SIZE(wm9713_snd_ac97_controls),
Lu Guanqun7ad7dd12011-03-30 21:53:11 +08001243 .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),
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001247};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001248
Bill Pemberton7a79e942012-12-07 09:26:37 -05001249static int wm9713_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001250{
Lars-Peter Clausen5efe89d2014-10-30 21:01:09 +01001251 struct wm9713_priv *wm9713;
1252
1253 wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL);
1254 if (wm9713 == NULL)
1255 return -ENOMEM;
1256
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +01001257 mutex_init(&wm9713->lock);
1258
Lars-Peter Clausen5efe89d2014-10-30 21:01:09 +01001259 platform_set_drvdata(pdev, wm9713);
1260
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001261 return snd_soc_register_codec(&pdev->dev,
1262 &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai));
1263}
1264
Bill Pemberton7a79e942012-12-07 09:26:37 -05001265static int wm9713_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001266{
1267 snd_soc_unregister_codec(&pdev->dev);
1268 return 0;
1269}
1270
1271static struct platform_driver wm9713_codec_driver = {
1272 .driver = {
1273 .name = "wm9713-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001274 },
1275
1276 .probe = wm9713_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001277 .remove = wm9713_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001278};
1279
Mark Brown5bbcc3c2011-11-23 22:52:08 +00001280module_platform_driver(wm9713_codec_driver);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001281
1282MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1283MODULE_AUTHOR("Liam Girdwood");
1284MODULE_LICENSE("GPL");