blob: 7e4822185febeac4ae7d2d601f3a76c7659ff924 [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>
Robert Jarzmik700dadf2015-11-01 20:23:39 +010022#include <linux/regmap.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010023#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/ac97_codec.h>
26#include <sound/initval.h>
27#include <sound/pcm_params.h>
Mark Browne03a8d22010-01-28 12:36:07 +000028#include <sound/tlv.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010029#include <sound/soc.h>
Liam Girdwood83ac08c2008-02-15 16:43:11 +010030
31#include "wm9713.h"
32
Lars-Peter Clausen310398f2015-07-21 21:53:06 +020033#define WM9713_VENDOR_ID 0x574d4c13
34#define WM9713_VENDOR_ID_MASK 0xffffffff
35
Liam Girdwood83ac08c2008-02-15 16:43:11 +010036struct wm9713_priv {
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010037 struct snd_ac97 *ac97;
Liam Girdwood83ac08c2008-02-15 16:43:11 +010038 u32 pll_in; /* PLL input frequency */
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +010039 unsigned int hp_mixer[2];
40 struct mutex lock;
Liam Girdwood83ac08c2008-02-15 16:43:11 +010041};
42
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +010043#define HPL_MIXER 0
44#define HPR_MIXER 1
Liam Girdwood83ac08c2008-02-15 16:43:11 +010045
46static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
47static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
48static const char *wm9713_rec_src[] =
49 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
50 "Mono Out", "Zh"};
51static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
52static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
Matt Reimera7f0b832014-05-19 09:35:47 -070053static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv"};
Liam Girdwood83ac08c2008-02-15 16:43:11 +010054static const char *wm9713_spk_pga[] =
55 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
56 "Speaker Vmid", "Inv Vmid"};
57static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone",
58 "Headphone Vmid"};
59static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
60static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
61static const char *wm9713_dac_inv[] =
62 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
63 "Headphone Mono", "NC", "Vmid"};
64static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
65static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"};
66static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
67static const char *wm9713_micb_select[] = {"MPB", "MPA"};
68
69static const struct soc_enum wm9713_enum[] = {
70SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
71SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
72SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */
73SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */
74SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/
75SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
76SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
77SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
78SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
79SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
80SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */
81SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */
82SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
83SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
84SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */
85SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
86SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
87SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
88SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
Lars-Peter Clausen5bc39b52014-10-30 21:01:10 +010089SOC_ENUM_SINGLE_VIRT(2, wm9713_micb_select), /* mic selection 19 */
Liam Girdwood83ac08c2008-02-15 16:43:11 +010090};
91
Mark Browne03a8d22010-01-28 12:36:07 +000092static const DECLARE_TLV_DB_SCALE(out_tlv, -4650, 150, 0);
93static const DECLARE_TLV_DB_SCALE(main_tlv, -3450, 150, 0);
94static const DECLARE_TLV_DB_SCALE(misc_tlv, -1500, 300, 0);
Lars-Peter Clausen5092e762015-08-02 17:20:09 +020095static const DECLARE_TLV_DB_RANGE(mic_tlv,
Mark Browne03a8d22010-01-28 12:36:07 +000096 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0),
Lars-Peter Clausen5092e762015-08-02 17:20:09 +020097 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0)
98);
Mark Browne03a8d22010-01-28 12:36:07 +000099
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100100static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
Mark Browne03a8d22010-01-28 12:36:07 +0000101SOC_DOUBLE_TLV("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100102SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
Mark Browne03a8d22010-01-28 12:36:07 +0000103SOC_DOUBLE_TLV("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1,
104 out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100105SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1),
Mark Browne03a8d22010-01-28 12:36:07 +0000106SOC_DOUBLE_TLV("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1, main_tlv),
107SOC_DOUBLE_TLV("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1, main_tlv),
108SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC, 8, 31, 1, main_tlv),
109SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC, 0, 31, 1, main_tlv),
110SOC_SINGLE_TLV("Mic 1 Preamp Volume", AC97_3D_CONTROL, 10, 3, 0, mic_tlv),
111SOC_SINGLE_TLV("Mic 2 Preamp Volume", AC97_3D_CONTROL, 12, 3, 0, mic_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100112
113SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
114SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
115
116SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
117SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
118SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0),
119SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
120
Mark Browne03a8d22010-01-28 12:36:07 +0000121SOC_SINGLE_TLV("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1, misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100122SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
123SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
124
125SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
126SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
Mark Brown13d622b2008-10-30 12:37:10 +0000127SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100128SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
129SOC_ENUM("ALC Function", wm9713_enum[6]),
130SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
131SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
132SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
133SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
134SOC_ENUM("ALC NG Type", wm9713_enum[17]),
135SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
136
137SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
138SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
139
140SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
141SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000142SOC_SINGLE_TLV("Out4 Playback Volume", AC97_MASTER_MONO, 8, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100143
144SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1),
145SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000146SOC_SINGLE_TLV("Out3 Playback Volume", AC97_MASTER_MONO, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100147
Mark Browne03a8d22010-01-28 12:36:07 +0000148SOC_SINGLE_TLV("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1, main_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100149SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
150SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
Mark Browne03a8d22010-01-28 12:36:07 +0000151SOC_SINGLE_TLV("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1, out_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100152
Mark Browne03a8d22010-01-28 12:36:07 +0000153SOC_SINGLE_TLV("Headphone Mixer Beep Playback Volume", AC97_AUX, 12, 7, 1,
154 misc_tlv),
155SOC_SINGLE_TLV("Speaker Mixer Beep Playback Volume", AC97_AUX, 8, 7, 1,
156 misc_tlv),
157SOC_SINGLE_TLV("Mono Mixer Beep Playback Volume", AC97_AUX, 4, 7, 1, misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100158
Mark Browne03a8d22010-01-28 12:36:07 +0000159SOC_SINGLE_TLV("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1,
160 misc_tlv),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100161SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
162SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
163
Mark Browne03a8d22010-01-28 12:36:07 +0000164SOC_SINGLE_TLV("Headphone Mixer Aux Playback Volume", AC97_REC_SEL, 12, 7, 1,
165 misc_tlv),
166
167SOC_SINGLE_TLV("Speaker Mixer Voice Playback Volume", AC97_PCM, 8, 7, 1,
168 misc_tlv),
169SOC_SINGLE_TLV("Speaker Mixer Aux Playback Volume", AC97_REC_SEL, 8, 7, 1,
170 misc_tlv),
171
172SOC_SINGLE_TLV("Mono Mixer Voice Playback Volume", AC97_PCM, 4, 7, 1,
173 misc_tlv),
174SOC_SINGLE_TLV("Mono Mixer Aux Playback Volume", AC97_REC_SEL, 4, 7, 1,
175 misc_tlv),
176
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100177SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
178SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100179
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{
Lars-Peter Clausenff705082015-01-13 10:27:33 +0100195 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Mark Brown6bbcb452009-04-13 11:29:10 +0100196
Takashi Iwaifb2e3e72013-11-05 18:39:59 +0100197 if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD))
198 return -EINVAL;
Mark Brown6bbcb452009-04-13 11:29:10 +0100199
200 /* Gracefully shut down the voice interface. */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100201 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0f00, 0x0200);
Mark Brown6bbcb452009-04-13 11:29:10 +0100202 schedule_timeout_interruptible(msecs_to_jiffies(1));
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100203 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0f00, 0x0f00);
204 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0x1000, 0x1000);
Mark Brown6bbcb452009-04-13 11:29:10 +0100205
206 return 0;
207}
208
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100209static const unsigned int wm9713_mixer_mute_regs[] = {
210 AC97_PC_BEEP,
211 AC97_MASTER_TONE,
212 AC97_PHONE,
213 AC97_REC_SEL,
214 AC97_PCM,
215 AC97_AUX,
216};
Mark Brown6bbcb452009-04-13 11:29:10 +0100217
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100218/* We have to create a fake left and right HP mixers because
219 * the codec only has a single control that is shared by both channels.
220 * This makes it impossible to determine the audio path using the current
221 * register map, thus we add a new (virtual) register to help determine the
222 * audio route within the device.
223 */
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100224static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol,
225 struct snd_ctl_elem_value *ucontrol)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100226{
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100227 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
228 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
229 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Takashi Iwai87a8b282015-03-10 12:39:16 +0100230 unsigned int val = ucontrol->value.integer.value[0];
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100231 struct soc_mixer_control *mc =
232 (struct soc_mixer_control *)kcontrol->private_value;
233 unsigned int mixer, mask, shift, old;
Chen-Yu Tsaie411b0b2016-11-02 15:35:58 +0800234 struct snd_soc_dapm_update update = { 0 };
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100235 bool change;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100236
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100237 mixer = mc->shift >> 8;
238 shift = mc->shift & 0xff;
239 mask = (1 << shift);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100240
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100241 mutex_lock(&wm9713->lock);
242 old = wm9713->hp_mixer[mixer];
Takashi Iwai87a8b282015-03-10 12:39:16 +0100243 if (ucontrol->value.integer.value[0])
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100244 wm9713->hp_mixer[mixer] |= mask;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100245 else
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100246 wm9713->hp_mixer[mixer] &= ~mask;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100247
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100248 change = old != wm9713->hp_mixer[mixer];
249 if (change) {
250 update.kcontrol = kcontrol;
251 update.reg = wm9713_mixer_mute_regs[shift];
252 update.mask = 0x8000;
253 if ((wm9713->hp_mixer[0] & mask) ||
254 (wm9713->hp_mixer[1] & mask))
255 update.val = 0x0;
256 else
257 update.val = 0x8000;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100258
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100259 snd_soc_dapm_mixer_update_power(dapm, kcontrol, val,
260 &update);
261 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100262
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100263 mutex_unlock(&wm9713->lock);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100264
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100265 return change;
266}
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100267
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100268static int wm9713_hp_mixer_get(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol)
270{
271 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
272 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
273 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
274 struct soc_mixer_control *mc =
275 (struct soc_mixer_control *)kcontrol->private_value;
276 unsigned int mixer, shift;
277
278 mixer = mc->shift >> 8;
279 shift = mc->shift & 0xff;
280
Takashi Iwai87a8b282015-03-10 12:39:16 +0100281 ucontrol->value.integer.value[0] =
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100282 (wm9713->hp_mixer[mixer] >> shift) & 1;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100283
284 return 0;
285}
286
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100287#define WM9713_HP_MIXER_CTRL(xname, xmixer, xshift) { \
288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
289 .info = snd_soc_info_volsw, \
290 .get = wm9713_hp_mixer_get, .put = wm9713_hp_mixer_put, \
291 .private_value = SOC_DOUBLE_VALUE(SND_SOC_NOPM, \
292 xshift, xmixer, 1, 0, 0) \
293}
294
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100295/* Left Headphone Mixers */
296static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100297WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER, 5),
298WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER, 4),
299WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 3),
300WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 2),
301WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER, 1),
302WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100303};
304
305/* Right Headphone Mixers */
306static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100307WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER, 5),
308WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER, 4),
309WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 3),
310WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 2),
311WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER, 1),
312WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100313};
314
315/* headphone capture mux */
316static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls =
317SOC_DAPM_ENUM("Route", wm9713_enum[1]);
318
319/* headphone mic mux */
320static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls =
321SOC_DAPM_ENUM("Route", wm9713_enum[0]);
322
323/* Speaker Mixer */
324static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100325SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100326SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
327SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
328SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
329SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
330SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
331};
332
333/* Mono Mixer */
334static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100335SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100336SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
337SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
338SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
339SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
340SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
341SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
342SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
343};
344
345/* mono mic mux */
346static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls =
347SOC_DAPM_ENUM("Route", wm9713_enum[2]);
348
349/* mono output mux */
350static const struct snd_kcontrol_new wm9713_mono_mux_controls =
351SOC_DAPM_ENUM("Route", wm9713_enum[7]);
352
353/* speaker left output mux */
354static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls =
355SOC_DAPM_ENUM("Route", wm9713_enum[8]);
356
357/* speaker right output mux */
358static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls =
359SOC_DAPM_ENUM("Route", wm9713_enum[9]);
360
361/* headphone left output mux */
362static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls =
363SOC_DAPM_ENUM("Route", wm9713_enum[10]);
364
365/* headphone right output mux */
366static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls =
367SOC_DAPM_ENUM("Route", wm9713_enum[11]);
368
369/* Out3 mux */
370static const struct snd_kcontrol_new wm9713_out3_mux_controls =
371SOC_DAPM_ENUM("Route", wm9713_enum[12]);
372
373/* Out4 mux */
374static const struct snd_kcontrol_new wm9713_out4_mux_controls =
375SOC_DAPM_ENUM("Route", wm9713_enum[13]);
376
377/* DAC inv mux 1 */
378static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls =
379SOC_DAPM_ENUM("Route", wm9713_enum[14]);
380
381/* DAC inv mux 2 */
382static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls =
383SOC_DAPM_ENUM("Route", wm9713_enum[15]);
384
385/* Capture source left */
386static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls =
387SOC_DAPM_ENUM("Route", wm9713_enum[3]);
388
389/* Capture source right */
390static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls =
391SOC_DAPM_ENUM("Route", wm9713_enum[4]);
392
393/* mic source */
394static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls =
395SOC_DAPM_ENUM("Route", wm9713_enum[18]);
396
397/* mic source B virtual control */
398static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls =
399SOC_DAPM_ENUM("Route", wm9713_enum[19]);
400
401static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
402SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0,
403 &wm9713_hp_rec_mux_controls),
404SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0,
405 &wm9713_hp_mic_mux_controls),
406SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0,
407 &wm9713_mono_mic_mux_controls),
408SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0,
409 &wm9713_mono_mux_controls),
410SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0,
411 &wm9713_hp_spkl_mux_controls),
412SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0,
413 &wm9713_hp_spkr_mux_controls),
414SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0,
415 &wm9713_hpl_out_mux_controls),
416SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0,
417 &wm9713_hpr_out_mux_controls),
418SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0,
419 &wm9713_out3_mux_controls),
420SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0,
421 &wm9713_out4_mux_controls),
422SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0,
423 &wm9713_dac_inv1_mux_controls),
424SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0,
425 &wm9713_dac_inv2_mux_controls),
426SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
427 &wm9713_rec_srcl_mux_controls),
428SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
429 &wm9713_rec_srcr_mux_controls),
430SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
431 &wm9713_mic_sel_mux_controls),
432SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
433 &wm9713_micb_sel_mux_controls),
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +0100434SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
435 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls)),
436SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
437 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls)),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100438SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
439 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
440SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
441 &wm9713_speaker_mixer_controls[0],
442 ARRAY_SIZE(wm9713_speaker_mixer_controls)),
443SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1),
444SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1),
445SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
446SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
447SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
448SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
Mark Brown6bbcb452009-04-13 11:29:10 +0100449SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1,
450 wm9713_voice_shutdown, SND_SOC_DAPM_PRE_PMD),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100451SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1),
Mark Brownccbc3012008-09-15 15:51:13 +0100452SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0),
453SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0),
454SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
455SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
456SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM, 0, 0),
457SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM, 0, 0),
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100458SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
459SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
460SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
461SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
462SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
463SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
464SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
465SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
466SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
467SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
468SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
469SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
470SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
471SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
472SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
473SND_SOC_DAPM_OUTPUT("MONO"),
474SND_SOC_DAPM_OUTPUT("HPL"),
475SND_SOC_DAPM_OUTPUT("HPR"),
476SND_SOC_DAPM_OUTPUT("SPKL"),
477SND_SOC_DAPM_OUTPUT("SPKR"),
478SND_SOC_DAPM_OUTPUT("OUT3"),
479SND_SOC_DAPM_OUTPUT("OUT4"),
480SND_SOC_DAPM_INPUT("LINEL"),
481SND_SOC_DAPM_INPUT("LINER"),
482SND_SOC_DAPM_INPUT("MONOIN"),
483SND_SOC_DAPM_INPUT("PCBEEP"),
484SND_SOC_DAPM_INPUT("MIC1"),
485SND_SOC_DAPM_INPUT("MIC2A"),
486SND_SOC_DAPM_INPUT("MIC2B"),
487SND_SOC_DAPM_VMID("VMID"),
488};
489
Lu Guanqun7ad7dd12011-03-30 21:53:11 +0800490static const struct snd_soc_dapm_route wm9713_audio_map[] = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100491 /* left HP mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100492 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100493 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
494 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
495 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
496 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
497 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
498 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
499
500 /* right HP mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100501 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100502 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
503 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
504 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
505 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
506 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
507 {"Right HP Mixer", NULL, "Capture Headphone Mux"},
508
509 /* virtual mixer - mixes left & right channels for spk and mono */
510 {"AC97 Mixer", NULL, "Left DAC"},
511 {"AC97 Mixer", NULL, "Right DAC"},
512 {"Line Mixer", NULL, "Right Line In"},
513 {"Line Mixer", NULL, "Left Line In"},
514 {"HP Mixer", NULL, "Left HP Mixer"},
515 {"HP Mixer", NULL, "Right HP Mixer"},
516 {"Capture Mixer", NULL, "Left Capture Source"},
517 {"Capture Mixer", NULL, "Right Capture Source"},
518
519 /* speaker mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100520 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100521 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
522 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
523 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
524 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
525 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
526
527 /* mono mixer */
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100528 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100529 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
530 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
531 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
532 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
Robert Jarzmikc0bbf482008-03-18 12:08:35 +0100533 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
534 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100535 {"Mono Mixer", NULL, "Capture Mono Mux"},
536
537 /* DAC inv mux 1 */
538 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
539 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
540 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
541 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
542 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
543
544 /* DAC inv mux 2 */
545 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
546 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
547 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
548 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
549 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
550
551 /* headphone left mux */
552 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
553
554 /* headphone right mux */
555 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
556
557 /* speaker left mux */
558 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
559 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
560 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
561
562 /* speaker right mux */
563 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
564 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
565 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
566
567 /* mono mux */
568 {"Mono Out Mux", "Mono", "Mono Mixer"},
569 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
570
571 /* out 3 mux */
572 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
573
574 /* out 4 mux */
575 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
576
577 /* output pga */
578 {"HPL", NULL, "Left Headphone"},
579 {"Left Headphone", NULL, "Left Headphone Out Mux"},
580 {"HPR", NULL, "Right Headphone"},
581 {"Right Headphone", NULL, "Right Headphone Out Mux"},
582 {"OUT3", NULL, "Out 3"},
583 {"Out 3", NULL, "Out 3 Mux"},
584 {"OUT4", NULL, "Out 4"},
585 {"Out 4", NULL, "Out 4 Mux"},
586 {"SPKL", NULL, "Left Speaker"},
587 {"Left Speaker", NULL, "Left Speaker Out Mux"},
588 {"SPKR", NULL, "Right Speaker"},
589 {"Right Speaker", NULL, "Right Speaker Out Mux"},
590 {"MONO", NULL, "Mono Out"},
591 {"Mono Out", NULL, "Mono Out Mux"},
592
593 /* input pga */
594 {"Left Line In", NULL, "LINEL"},
595 {"Right Line In", NULL, "LINER"},
596 {"Mono In", NULL, "MONOIN"},
597 {"Mic A PGA", NULL, "Mic A Pre Amp"},
598 {"Mic B PGA", NULL, "Mic B Pre Amp"},
599
600 /* left capture select */
601 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
602 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
603 {"Left Capture Source", "Line", "LINEL"},
604 {"Left Capture Source", "Mono In", "MONOIN"},
605 {"Left Capture Source", "Headphone", "Left HP Mixer"},
606 {"Left Capture Source", "Speaker", "Speaker Mixer"},
607 {"Left Capture Source", "Mono Out", "Mono Mixer"},
608
609 /* right capture select */
610 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
611 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
612 {"Right Capture Source", "Line", "LINER"},
613 {"Right Capture Source", "Mono In", "MONOIN"},
614 {"Right Capture Source", "Headphone", "Right HP Mixer"},
615 {"Right Capture Source", "Speaker", "Speaker Mixer"},
616 {"Right Capture Source", "Mono Out", "Mono Mixer"},
617
618 /* left ADC */
619 {"Left ADC", NULL, "Left Capture Source"},
Mark Brownccbc3012008-09-15 15:51:13 +0100620 {"Left Voice ADC", NULL, "Left ADC"},
621 {"Left HiFi ADC", NULL, "Left ADC"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100622
623 /* right ADC */
624 {"Right ADC", NULL, "Right Capture Source"},
Mark Brownccbc3012008-09-15 15:51:13 +0100625 {"Right Voice ADC", NULL, "Right ADC"},
626 {"Right HiFi ADC", NULL, "Right ADC"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100627
628 /* mic */
629 {"Mic A Pre Amp", NULL, "Mic A Source"},
630 {"Mic A Source", "Mic 1", "MIC1"},
631 {"Mic A Source", "Mic 2 A", "MIC2A"},
632 {"Mic A Source", "Mic 2 B", "Mic B Source"},
633 {"Mic B Pre Amp", "MPB", "Mic B Source"},
634 {"Mic B Source", NULL, "MIC2B"},
635
636 /* headphone capture */
637 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
638 {"Capture Headphone Mux", "Left", "Left Capture Source"},
639 {"Capture Headphone Mux", "Right", "Right Capture Source"},
640
641 /* mono capture */
642 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
643 {"Capture Mono Mux", "Left", "Left Capture Source"},
644 {"Capture Mono Mux", "Right", "Right Capture Source"},
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100645};
646
Robert Jarzmik700dadf2015-11-01 20:23:39 +0100647static bool wm9713_readable_reg(struct device *dev, unsigned int reg)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100648{
Robert Jarzmik700dadf2015-11-01 20:23:39 +0100649 switch (reg) {
650 case AC97_RESET ... AC97_PCM_SURR_DAC_RATE:
651 case AC97_PCM_LR_ADC_RATE:
652 case AC97_CENTER_LFE_MASTER:
653 case AC97_SPDIF ... AC97_LINE1_LEVEL:
654 case AC97_GPIO_CFG ... 0x5c:
655 case AC97_CODEC_CLASS_REV ... AC97_PCI_SID:
656 case 0x74 ... AC97_VENDOR_ID2:
657 return true;
658 default:
659 return false;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100660 }
661}
662
Robert Jarzmik700dadf2015-11-01 20:23:39 +0100663static bool wm9713_writeable_reg(struct device *dev, unsigned int reg)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100664{
Robert Jarzmik700dadf2015-11-01 20:23:39 +0100665 switch (reg) {
666 case AC97_VENDOR_ID1:
667 case AC97_VENDOR_ID2:
668 return false;
669 default:
670 return wm9713_readable_reg(dev, reg);
671 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100672}
673
Robert Jarzmik700dadf2015-11-01 20:23:39 +0100674static const struct reg_default wm9713_reg_defaults[] = {
675 { 0x02, 0x8080 }, /* Speaker Output Volume */
676 { 0x04, 0x8080 }, /* Headphone Output Volume */
677 { 0x06, 0x8080 }, /* Out3/OUT4 Volume */
678 { 0x08, 0xc880 }, /* Mono Volume */
679 { 0x0a, 0xe808 }, /* LINEIN Volume */
680 { 0x0c, 0xe808 }, /* DAC PGA Volume */
681 { 0x0e, 0x0808 }, /* MIC PGA Volume */
682 { 0x10, 0x00da }, /* MIC Routing Control */
683 { 0x12, 0x8000 }, /* Record PGA Volume */
684 { 0x14, 0xd600 }, /* Record Routing */
685 { 0x16, 0xaaa0 }, /* PCBEEP Volume */
686 { 0x18, 0xaaa0 }, /* VxDAC Volume */
687 { 0x1a, 0xaaa0 }, /* AUXDAC Volume */
688 { 0x1c, 0x0000 }, /* Output PGA Mux */
689 { 0x1e, 0x0000 }, /* DAC 3D control */
690 { 0x20, 0x0f0f }, /* DAC Tone Control*/
691 { 0x22, 0x0040 }, /* MIC Input Select & Bias */
692 { 0x24, 0x0000 }, /* Output Volume Mapping & Jack */
693 { 0x26, 0x7f00 }, /* Powerdown Ctrl/Stat*/
694 { 0x28, 0x0405 }, /* Extended Audio ID */
695 { 0x2a, 0x0410 }, /* Extended Audio Start/Ctrl */
696 { 0x2c, 0xbb80 }, /* Audio DACs Sample Rate */
697 { 0x2e, 0xbb80 }, /* AUXDAC Sample Rate */
698 { 0x32, 0xbb80 }, /* Audio ADCs Sample Rate */
699 { 0x36, 0x4523 }, /* PCM codec control */
700 { 0x3a, 0x2000 }, /* SPDIF control */
701 { 0x3c, 0xfdff }, /* Powerdown 1 */
702 { 0x3e, 0xffff }, /* Powerdown 2 */
703 { 0x40, 0x0000 }, /* General Purpose */
704 { 0x42, 0x0000 }, /* Fast Power-Up Control */
705 { 0x44, 0x0080 }, /* MCLK/PLL Control */
706 { 0x46, 0x0000 }, /* MCLK/PLL Control */
707 { 0x4c, 0xfffe }, /* GPIO Pin Configuration */
708 { 0x4e, 0xffff }, /* GPIO Pin Polarity / Type */
709 { 0x50, 0x0000 }, /* GPIO Pin Sticky */
710 { 0x52, 0x0000 }, /* GPIO Pin Wake-Up */
711 /* GPIO Pin Status */
712 { 0x56, 0xfffe }, /* GPIO Pin Sharing */
713 { 0x58, 0x4000 }, /* GPIO PullUp/PullDown */
714 { 0x5a, 0x0000 }, /* Additional Functions 1 */
715 { 0x5c, 0x0000 }, /* Additional Functions 2 */
716 { 0x60, 0xb032 }, /* ALC Control */
717 { 0x62, 0x3e00 }, /* ALC / Noise Gate Control */
718 { 0x64, 0x0000 }, /* AUXDAC input control */
719 { 0x74, 0x0000 }, /* Digitiser Reg 1 */
720 { 0x76, 0x0006 }, /* Digitiser Reg 2 */
721 { 0x78, 0x0001 }, /* Digitiser Reg 3 */
722 { 0x7a, 0x0000 }, /* Digitiser Read Back */
723};
724
725static const struct regmap_config wm9713_regmap_config = {
726 .reg_bits = 16,
727 .reg_stride = 2,
728 .val_bits = 16,
729 .max_register = 0x7e,
730 .cache_type = REGCACHE_RBTREE,
731
732 .reg_defaults = wm9713_reg_defaults,
733 .num_reg_defaults = ARRAY_SIZE(wm9713_reg_defaults),
734 .volatile_reg = regmap_ac97_default_volatile,
735 .readable_reg = wm9713_readable_reg,
736 .writeable_reg = wm9713_writeable_reg,
737};
738
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100739/* PLL divisors */
740struct _pll_div {
741 u32 divsel:1;
742 u32 divctl:1;
743 u32 lf:1;
744 u32 n:4;
745 u32 k:24;
746};
747
748/* The size in bits of the PLL divide multiplied by 10
749 * to allow rounding later */
750#define FIXED_PLL_SIZE ((1 << 22) * 10)
751
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100752static void pll_factors(struct snd_soc_codec *codec,
753 struct _pll_div *pll_div, unsigned int source)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100754{
755 u64 Kpart;
756 unsigned int K, Ndiv, Nmod, target;
757
758 /* The the PLL output is always 98.304MHz. */
759 target = 98304000;
760
761 /* If the input frequency is over 14.4MHz then scale it down. */
762 if (source > 14400000) {
763 source >>= 1;
764 pll_div->divsel = 1;
765
766 if (source > 14400000) {
767 source >>= 1;
768 pll_div->divctl = 1;
769 } else
770 pll_div->divctl = 0;
771
772 } else {
773 pll_div->divsel = 0;
774 pll_div->divctl = 0;
775 }
776
777 /* Low frequency sources require an additional divide in the
778 * loop.
779 */
780 if (source < 8192000) {
781 pll_div->lf = 1;
782 target >>= 2;
783 } else
784 pll_div->lf = 0;
785
786 Ndiv = target / source;
787 if ((Ndiv < 5) || (Ndiv > 12))
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100788 dev_warn(codec->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700789 "WM9713 PLL N value %u out of recommended range!\n",
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100790 Ndiv);
791
792 pll_div->n = Ndiv;
793 Nmod = target % source;
794 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
795
796 do_div(Kpart, source);
797
798 K = Kpart & 0xFFFFFFFF;
799
800 /* Check if we need to round */
801 if ((K % 10) >= 5)
802 K += 5;
803
804 /* Move down to proper range now rounding is done */
805 K /= 10;
806
807 pll_div->k = K;
808}
809
810/**
811 * Please note that changing the PLL input frequency may require
812 * resynchronisation with the AC97 controller.
813 */
814static int wm9713_set_pll(struct snd_soc_codec *codec,
815 int pll_id, unsigned int freq_in, unsigned int freq_out)
816{
Mark Brownb2c812e2010-04-14 15:35:19 +0900817 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100818 u16 reg, reg2;
819 struct _pll_div pll_div;
820
821 /* turn PLL off ? */
Mark Brownc42f69b2009-01-16 16:31:03 +0000822 if (freq_in == 0) {
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100823 /* disable PLL power and select ext source */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100824 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0080, 0x0080);
825 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0x0200, 0x0200);
Mark Brownc42f69b2009-01-16 16:31:03 +0000826 wm9713->pll_in = 0;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100827 return 0;
828 }
829
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +0100830 pll_factors(codec, &pll_div, freq_in);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100831
832 if (pll_div.k == 0) {
833 reg = (pll_div.n << 12) | (pll_div.lf << 11) |
834 (pll_div.divsel << 9) | (pll_div.divctl << 8);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100835 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100836 } else {
837 /* write the fractional k to the reg 0x46 pages */
838 reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) |
839 (pll_div.divsel << 9) | (pll_div.divctl << 8);
840
841 /* K [21:20] */
842 reg = reg2 | (0x5 << 4) | (pll_div.k >> 20);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100843 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100844
845 /* K [19:16] */
846 reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100847 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100848
849 /* K [15:12] */
850 reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100851 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100852
853 /* K [11:8] */
854 reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100855 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100856
857 /* K [7:4] */
858 reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf);
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100859 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100860
861 reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100862 snd_soc_write(codec, AC97_LINE1_LEVEL, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100863 }
864
865 /* turn PLL on and select as source */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100866 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0x0200, 0x0000);
867 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0080, 0x0000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100868 wm9713->pll_in = freq_in;
869
870 /* wait 10ms AC97 link frames for the link to stabilise */
871 schedule_timeout_interruptible(msecs_to_jiffies(10));
872 return 0;
873}
874
Mark Brown85488032009-09-05 18:52:16 +0100875static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
876 int source, unsigned int freq_in, unsigned int freq_out)
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100877{
878 struct snd_soc_codec *codec = codec_dai->codec;
879 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
880}
881
882/*
883 * Tristate the PCM DAI lines, tristate can be disabled by calling
884 * wm9713_set_dai_fmt()
885 */
Liam Girdwoode550e172008-07-07 16:07:52 +0100886static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100887 int tristate)
888{
889 struct snd_soc_codec *codec = codec_dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100890
891 if (tristate)
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100892 snd_soc_update_bits(codec, AC97_CENTER_LFE_MASTER,
893 0x6000, 0x0000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100894
895 return 0;
896}
897
898/*
899 * Configure WM9713 clock dividers.
900 * Voice DAC needs 256 FS
901 */
Liam Girdwoode550e172008-07-07 16:07:52 +0100902static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100903 int div_id, int div)
904{
905 struct snd_soc_codec *codec = codec_dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100906
907 switch (div_id) {
908 case WM9713_PCMCLK_DIV:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100909 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0f00, div);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100910 break;
911 case WM9713_CLKA_MULT:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100912 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0002, div);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100913 break;
914 case WM9713_CLKB_MULT:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100915 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x0004, div);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100916 break;
917 case WM9713_HIFI_DIV:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100918 snd_soc_update_bits(codec, AC97_HANDSET_RATE, 0x7000, div);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100919 break;
920 case WM9713_PCMBCLK_DIV:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100921 snd_soc_update_bits(codec, AC97_CENTER_LFE_MASTER, 0x0e00, div);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100922 break;
923 case WM9713_PCMCLK_PLL_DIV:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100924 snd_soc_update_bits(codec, AC97_LINE1_LEVEL,
925 0x007f, div | 0x60);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100926 break;
927 case WM9713_HIFI_PLL_DIV:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100928 snd_soc_update_bits(codec, AC97_LINE1_LEVEL,
929 0x007f, div | 0x70);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100930 break;
931 default:
932 return -EINVAL;
933 }
934
935 return 0;
936}
937
Liam Girdwoode550e172008-07-07 16:07:52 +0100938static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai,
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100939 unsigned int fmt)
940{
941 struct snd_soc_codec *codec = codec_dai->codec;
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100942 u16 gpio = snd_soc_read(codec, AC97_GPIO_CFG) & 0xffc5;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100943 u16 reg = 0x8000;
944
945 /* clock masters */
946 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
947 case SND_SOC_DAIFMT_CBM_CFM:
948 reg |= 0x4000;
949 gpio |= 0x0010;
950 break;
951 case SND_SOC_DAIFMT_CBM_CFS:
952 reg |= 0x6000;
953 gpio |= 0x0018;
954 break;
955 case SND_SOC_DAIFMT_CBS_CFS:
Mark Brownd133b0c2008-06-11 13:47:11 +0100956 reg |= 0x2000;
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100957 gpio |= 0x001a;
958 break;
959 case SND_SOC_DAIFMT_CBS_CFM:
960 gpio |= 0x0012;
961 break;
962 }
963
964 /* clock inversion */
965 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
966 case SND_SOC_DAIFMT_IB_IF:
967 reg |= 0x00c0;
968 break;
969 case SND_SOC_DAIFMT_IB_NF:
970 reg |= 0x0080;
971 break;
972 case SND_SOC_DAIFMT_NB_IF:
973 reg |= 0x0040;
974 break;
975 }
976
977 /* DAI format */
978 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
979 case SND_SOC_DAIFMT_I2S:
980 reg |= 0x0002;
981 break;
982 case SND_SOC_DAIFMT_RIGHT_J:
983 break;
984 case SND_SOC_DAIFMT_LEFT_J:
985 reg |= 0x0001;
986 break;
987 case SND_SOC_DAIFMT_DSP_A:
988 reg |= 0x0003;
989 break;
990 case SND_SOC_DAIFMT_DSP_B:
991 reg |= 0x0043;
992 break;
993 }
994
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +0100995 snd_soc_write(codec, AC97_GPIO_CFG, gpio);
996 snd_soc_write(codec, AC97_CENTER_LFE_MASTER, reg);
Liam Girdwood83ac08c2008-02-15 16:43:11 +0100997 return 0;
998}
999
1000static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +00001001 struct snd_pcm_hw_params *params,
1002 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001003{
Mark Brown55b8bac2008-11-24 14:05:29 +00001004 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001005
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001006 /* enable PCM interface in master mode */
Mark Brown563fe712014-07-31 12:55:23 +01001007 switch (params_width(params)) {
1008 case 16:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001009 break;
Mark Brown563fe712014-07-31 12:55:23 +01001010 case 20:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001011 snd_soc_update_bits(codec, AC97_CENTER_LFE_MASTER,
1012 0x000c, 0x0004);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001013 break;
Mark Brown563fe712014-07-31 12:55:23 +01001014 case 24:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001015 snd_soc_update_bits(codec, AC97_CENTER_LFE_MASTER,
1016 0x000c, 0x0008);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001017 break;
Mark Brown563fe712014-07-31 12:55:23 +01001018 case 32:
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001019 snd_soc_update_bits(codec, AC97_CENTER_LFE_MASTER,
1020 0x000c, 0x000c);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001021 break;
1022 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001023 return 0;
1024}
1025
Mark Browndee89c42008-11-18 22:11:38 +00001026static int ac97_hifi_prepare(struct snd_pcm_substream *substream,
1027 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001028{
Mark Brown55b8bac2008-11-24 14:05:29 +00001029 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001030 struct snd_pcm_runtime *runtime = substream->runtime;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001031 int reg;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001032
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001033 snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x0001, 0x0001);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001034
1035 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1036 reg = AC97_PCM_FRONT_DAC_RATE;
1037 else
1038 reg = AC97_PCM_LR_ADC_RATE;
1039
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001040 return snd_soc_write(codec, reg, runtime->rate);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001041}
1042
Mark Browndee89c42008-11-18 22:11:38 +00001043static int ac97_aux_prepare(struct snd_pcm_substream *substream,
1044 struct snd_soc_dai *dai)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001045{
Mark Brown55b8bac2008-11-24 14:05:29 +00001046 struct snd_soc_codec *codec = dai->codec;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001047 struct snd_pcm_runtime *runtime = substream->runtime;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001048
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001049 snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x0001, 0x0001);
1050 snd_soc_update_bits(codec, AC97_PCI_SID, 0x8000, 0x8000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001051
1052 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
1053 return -ENODEV;
1054
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001055 return snd_soc_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001056}
1057
Mark Brown54155522008-07-02 11:51:19 +01001058#define WM9713_RATES (SNDRV_PCM_RATE_8000 | \
1059 SNDRV_PCM_RATE_11025 | \
1060 SNDRV_PCM_RATE_22050 | \
1061 SNDRV_PCM_RATE_44100 | \
1062 SNDRV_PCM_RATE_48000)
1063
1064#define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \
1065 SNDRV_PCM_RATE_11025 | \
1066 SNDRV_PCM_RATE_16000 | \
1067 SNDRV_PCM_RATE_22050 | \
1068 SNDRV_PCM_RATE_44100 | \
1069 SNDRV_PCM_RATE_48000)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001070
1071#define WM9713_PCM_FORMATS \
Maciej S. Szmigieroe712bfc2015-05-23 18:32:29 +02001072 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1073 SNDRV_PCM_FMTBIT_S24_LE)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001074
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001075static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = {
Eric Miao6335d052009-03-03 09:41:00 +08001076 .prepare = ac97_hifi_prepare,
1077 .set_clkdiv = wm9713_set_dai_clkdiv,
1078 .set_pll = wm9713_set_dai_pll,
1079};
1080
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001081static const struct snd_soc_dai_ops wm9713_dai_ops_aux = {
Eric Miao6335d052009-03-03 09:41:00 +08001082 .prepare = ac97_aux_prepare,
1083 .set_clkdiv = wm9713_set_dai_clkdiv,
1084 .set_pll = wm9713_set_dai_pll,
1085};
1086
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001087static const struct snd_soc_dai_ops wm9713_dai_ops_voice = {
Eric Miao6335d052009-03-03 09:41:00 +08001088 .hw_params = wm9713_pcm_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +08001089 .set_clkdiv = wm9713_set_dai_clkdiv,
1090 .set_pll = wm9713_set_dai_pll,
1091 .set_fmt = wm9713_set_dai_fmt,
1092 .set_tristate = wm9713_set_dai_tristate,
1093};
1094
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001095static struct snd_soc_dai_driver wm9713_dai[] = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001096{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001097 .name = "wm9713-hifi",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001098 .playback = {
1099 .stream_name = "HiFi Playback",
1100 .channels_min = 1,
1101 .channels_max = 2,
1102 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001103 .formats = SND_SOC_STD_AC97_FMTS,},
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001104 .capture = {
1105 .stream_name = "HiFi Capture",
1106 .channels_min = 1,
1107 .channels_max = 2,
1108 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001109 .formats = SND_SOC_STD_AC97_FMTS,},
Eric Miao6335d052009-03-03 09:41:00 +08001110 .ops = &wm9713_dai_ops_hifi,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001111 },
1112 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001113 .name = "wm9713-aux",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001114 .playback = {
1115 .stream_name = "Aux Playback",
1116 .channels_min = 1,
1117 .channels_max = 1,
1118 .rates = WM9713_RATES,
Mark Brown33f503c2009-05-02 12:24:55 +01001119 .formats = SND_SOC_STD_AC97_FMTS,},
Eric Miao6335d052009-03-03 09:41:00 +08001120 .ops = &wm9713_dai_ops_aux,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001121 },
1122 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001123 .name = "wm9713-voice",
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001124 .playback = {
1125 .stream_name = "Voice Playback",
1126 .channels_min = 1,
1127 .channels_max = 1,
Mark Brown54155522008-07-02 11:51:19 +01001128 .rates = WM9713_PCM_RATES,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001129 .formats = WM9713_PCM_FORMATS,},
1130 .capture = {
1131 .stream_name = "Voice Capture",
1132 .channels_min = 1,
1133 .channels_max = 2,
Mark Brown54155522008-07-02 11:51:19 +01001134 .rates = WM9713_PCM_RATES,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001135 .formats = WM9713_PCM_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +08001136 .ops = &wm9713_dai_ops_voice,
Mark Brownf4976112009-04-13 10:53:02 +01001137 .symmetric_rates = 1,
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001138 },
1139};
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001140
Mark Brown0be98982008-05-19 12:31:28 +02001141static int wm9713_set_bias_level(struct snd_soc_codec *codec,
1142 enum snd_soc_bias_level level)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001143{
Mark Brown0be98982008-05-19 12:31:28 +02001144 switch (level) {
1145 case SND_SOC_BIAS_ON:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001146 /* enable thermal shutdown */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001147 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0xe400, 0x0000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001148 break;
Mark Brown0be98982008-05-19 12:31:28 +02001149 case SND_SOC_BIAS_PREPARE:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001150 break;
Mark Brown0be98982008-05-19 12:31:28 +02001151 case SND_SOC_BIAS_STANDBY:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001152 /* enable master bias and vmid */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001153 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0xc400, 0x0000);
1154 snd_soc_write(codec, AC97_POWERDOWN, 0x0000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001155 break;
Mark Brown0be98982008-05-19 12:31:28 +02001156 case SND_SOC_BIAS_OFF:
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001157 /* disable everything including AC link */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001158 snd_soc_write(codec, AC97_EXTENDED_MID, 0xffff);
1159 snd_soc_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1160 snd_soc_write(codec, AC97_POWERDOWN, 0xffff);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001161 break;
1162 }
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001163 return 0;
1164}
1165
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01001166static int wm9713_soc_suspend(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001167{
Mark Brown87b57fe2008-04-14 15:27:30 +02001168 /* Disable everything except touchpanel - that will be handled
1169 * by the touch driver and left disabled if touch is not in
1170 * use. */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001171 snd_soc_update_bits(codec, AC97_EXTENDED_MID, 0x7fff,
1172 0x7fff);
1173 snd_soc_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1174 snd_soc_write(codec, AC97_POWERDOWN, 0x6f00);
1175 snd_soc_write(codec, AC97_POWERDOWN, 0xffff);
Mark Brown87b57fe2008-04-14 15:27:30 +02001176
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001177 return 0;
1178}
1179
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001180static int wm9713_soc_resume(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001181{
Mark Brownb2c812e2010-04-14 15:35:19 +09001182 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Robert Jarzmik700dadf2015-11-01 20:23:39 +01001183 int ret;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001184
Lars-Peter Clausen310398f2015-07-21 21:53:06 +02001185 ret = snd_ac97_reset(wm9713->ac97, true, WM9713_VENDOR_ID,
1186 WM9713_VENDOR_ID_MASK);
Lars-Peter Clausena6c2b072014-10-30 21:01:07 +01001187 if (ret < 0)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001188 return ret;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001189
Lars-Peter Clausenbd1204c2015-04-27 22:13:24 +02001190 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001191
1192 /* do we need to re-start the PLL ? */
Mark Brownc42f69b2009-01-16 16:31:03 +00001193 if (wm9713->pll_in)
1194 wm9713_set_pll(codec, 0, wm9713->pll_in, 0);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001195
1196 /* only synchronise the codec if warm reset failed */
1197 if (ret == 0) {
Robert Jarzmik700dadf2015-11-01 20:23:39 +01001198 regcache_mark_dirty(codec->component.regmap);
1199 snd_soc_cache_sync(codec);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001200 }
1201
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001202 return ret;
1203}
1204
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001205static int wm9713_soc_probe(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001206{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001207 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
Robert Jarzmik700dadf2015-11-01 20:23:39 +01001208 struct regmap *regmap;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001209
Lars-Peter Clausen310398f2015-07-21 21:53:06 +02001210 wm9713->ac97 = snd_soc_new_ac97_codec(codec, WM9713_VENDOR_ID,
1211 WM9713_VENDOR_ID_MASK);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001212 if (IS_ERR(wm9713->ac97))
1213 return PTR_ERR(wm9713->ac97);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001214
Robert Jarzmikda9b9302016-02-22 23:35:44 +01001215 regmap = regmap_init_ac97(wm9713->ac97, &wm9713_regmap_config);
Robert Jarzmik700dadf2015-11-01 20:23:39 +01001216 if (IS_ERR(regmap)) {
1217 snd_soc_free_ac97_codec(wm9713->ac97);
1218 return PTR_ERR(regmap);
1219 }
1220
1221 snd_soc_codec_init_regmap(codec, regmap);
1222
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001223 /* unmute the adc - move to kcontrol */
Robert Jarzmikfa1a51f2015-11-01 20:23:40 +01001224 snd_soc_update_bits(codec, AC97_CD, 0x7fff, 0x0000);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001225
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001226 return 0;
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001227}
1228
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001229static int wm9713_soc_remove(struct snd_soc_codec *codec)
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001230{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001231 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1232
Robert Jarzmik700dadf2015-11-01 20:23:39 +01001233 snd_soc_codec_exit_regmap(codec);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +01001234 snd_soc_free_ac97_codec(wm9713->ac97);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001235 return 0;
1236}
1237
Julia Lawallf802d6c2016-08-31 23:52:27 +02001238static const struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001239 .probe = wm9713_soc_probe,
1240 .remove = wm9713_soc_remove,
1241 .suspend = wm9713_soc_suspend,
1242 .resume = wm9713_soc_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001243 .set_bias_level = wm9713_set_bias_level,
Lars-Peter Clausenc1359ca2014-10-30 21:01:08 +01001244
Kuninori Morimoto2c452dd2016-08-08 09:36:29 +00001245 .component_driver = {
1246 .controls = wm9713_snd_ac97_controls,
1247 .num_controls = ARRAY_SIZE(wm9713_snd_ac97_controls),
1248 .dapm_widgets = wm9713_dapm_widgets,
1249 .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets),
1250 .dapm_routes = wm9713_audio_map,
1251 .num_dapm_routes = ARRAY_SIZE(wm9713_audio_map),
1252 },
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001253};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001254
Bill Pemberton7a79e942012-12-07 09:26:37 -05001255static int wm9713_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001256{
Lars-Peter Clausen5efe89d2014-10-30 21:01:09 +01001257 struct wm9713_priv *wm9713;
1258
1259 wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL);
1260 if (wm9713 == NULL)
1261 return -ENOMEM;
1262
Lars-Peter Clausencf1f2eb2014-11-03 19:33:03 +01001263 mutex_init(&wm9713->lock);
1264
Lars-Peter Clausen5efe89d2014-10-30 21:01:09 +01001265 platform_set_drvdata(pdev, wm9713);
1266
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001267 return snd_soc_register_codec(&pdev->dev,
1268 &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai));
1269}
1270
Bill Pemberton7a79e942012-12-07 09:26:37 -05001271static int wm9713_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001272{
1273 snd_soc_unregister_codec(&pdev->dev);
1274 return 0;
1275}
1276
1277static struct platform_driver wm9713_codec_driver = {
1278 .driver = {
1279 .name = "wm9713-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001280 },
1281
1282 .probe = wm9713_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001283 .remove = wm9713_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001284};
1285
Mark Brown5bbcc3c2011-11-23 22:52:08 +00001286module_platform_driver(wm9713_codec_driver);
Liam Girdwood83ac08c2008-02-15 16:43:11 +01001287
1288MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1289MODULE_AUTHOR("Liam Girdwood");
1290MODULE_LICENSE("GPL");