blob: e0dadcf2030d6995197a47c025b085fb7b70a7e3 [file] [log] [blame]
Joseph Chanc577b8a2006-11-29 15:29:40 +01001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Lydia Wang8e865972009-10-10 19:08:52 +08004 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
Joseph Chanc577b8a2006-11-29 15:29:40 +01005 *
Lydia Wang8e865972009-10-10 19:08:52 +08006 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
Joseph Chanc577b8a2006-11-29 15:29:40 +01008 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
Lydia Wang377ff312009-10-10 19:08:55 +080025/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010026/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
Lydia Wang377ff312009-10-10 19:08:55 +080027/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
Joseph Chanc577b8a2006-11-29 15:29:40 +010029/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
Lydia Wang377ff312009-10-10 19:08:55 +080030/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
Harald Welte76d9b0d2008-09-09 15:50:37 +080032/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
Harald Weltefb4cb772008-09-09 15:53:36 +080033/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
Lydia Wang377ff312009-10-10 19:08:55 +080034/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */
Harald Welte98aa34c2008-09-09 16:02:09 +080037/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
Lydia Wang377ff312009-10-10 19:08:55 +080038/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
Lydia Wang8e865972009-10-10 19:08:52 +080039/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
Lydia Wang36dd5c42009-10-20 13:18:04 +080044/* 2009-09-19 Lydia Wang Add support for VT1818S */
Lydia Wang377ff312009-10-10 19:08:55 +080045/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010046/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47
48
Joseph Chanc577b8a2006-11-29 15:29:40 +010049#include <linux/init.h>
50#include <linux/delay.h>
51#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040052#include <linux/module.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010053#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080054#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010055#include "hda_codec.h"
56#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020057#include "hda_auto_parser.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020058#include "hda_jack.h"
Takashi Iwaib3f60082013-01-07 12:27:36 +010059#include "hda_generic.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010060
Joseph Chanc577b8a2006-11-29 15:29:40 +010061/* Pin Widget NID */
Harald Welted949cac2008-09-09 15:56:01 +080062#define VT1708_HP_PIN_NID 0x20
63#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010064
Harald Welted7426322008-09-15 22:43:23 +080065enum VIA_HDA_CODEC {
66 UNKNOWN = -1,
67 VT1708,
68 VT1709_10CH,
69 VT1709_6CH,
70 VT1708B_8CH,
71 VT1708B_4CH,
72 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080073 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080074 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080075 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080076 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080077 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +080078 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +080079 VT1802,
Lydia Wang43737e02012-12-10 18:28:11 +080080 VT1705CF,
Lydia Wang6121b842012-12-10 19:03:26 +080081 VT1808,
Harald Welted7426322008-09-15 22:43:23 +080082 CODEC_TYPES,
83};
84
Lydia Wang118909562011-03-23 17:57:34 +080085#define VT2002P_COMPATIBLE(spec) \
86 ((spec)->codec_type == VT2002P ||\
87 (spec)->codec_type == VT1812 ||\
88 (spec)->codec_type == VT1802)
89
Lydia Wang1f2e99f2009-10-10 19:08:17 +080090struct via_spec {
Takashi Iwaib3f60082013-01-07 12:27:36 +010091 struct hda_gen_spec gen;
92
Lydia Wang1f2e99f2009-10-10 19:08:17 +080093 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +020094 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +080095 unsigned int num_mixers;
96
Takashi Iwai90dd48a2011-05-02 12:38:19 +020097 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +080098 unsigned int num_iverbs;
99
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800100 /* HP mode source */
Lydia Wangf3db4232009-10-10 19:08:41 +0800101 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200102 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800103 enum VIA_HDA_CODEC codec_type;
104
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100105 /* analog low-power control */
106 bool alc_mode;
107
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800108 /* work to check hp jack state */
Takashi Iwai187d3332011-11-24 16:33:09 +0100109 int hp_work_active;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200110 int vt1708_jack_detect;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800111
112 void (*set_widgets_power_state)(struct hda_codec *codec);
Lydia Wang43737e02012-12-10 18:28:11 +0800113 unsigned int dac_stream_tag[4];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800114};
115
Lydia Wang0341ccd2011-03-22 16:25:03 +0800116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100117static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
118 struct hda_codec *codec,
119 struct snd_pcm_substream *substream,
120 int action);
121static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
122
123static struct via_spec *via_new_spec(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100124{
125 struct via_spec *spec;
126
127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
128 if (spec == NULL)
129 return NULL;
130
131 codec->spec = spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100132 snd_hda_gen_spec_init(&spec->gen);
Lydia Wang0341ccd2011-03-22 16:25:03 +0800133 spec->codec_type = get_codec_type(codec);
134 /* VT1708BCE & VT1708S are almost same */
135 if (spec->codec_type == VT1708BCE)
136 spec->codec_type = VT1708S;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100137 spec->no_pin_power_ctl = 1;
Takashi Iwai13961172013-01-21 15:15:55 +0100138 spec->gen.indep_hp = 1;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100139 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100140 return spec;
141}
142
Lydia Wang744ff5f2009-10-10 19:07:26 +0800143static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800144{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800145 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800146 u16 ven_id = vendor_id >> 16;
147 u16 dev_id = vendor_id & 0xffff;
148 enum VIA_HDA_CODEC codec_type;
149
150 /* get codec type */
151 if (ven_id != 0x1106)
152 codec_type = UNKNOWN;
153 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
154 codec_type = VT1708;
155 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
156 codec_type = VT1709_10CH;
157 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
158 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800159 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800160 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800161 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
162 codec_type = VT1708BCE;
163 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800164 codec_type = VT1708B_4CH;
165 else if ((dev_id & 0xfff) == 0x397
166 && (dev_id >> 12) < 8)
167 codec_type = VT1708S;
168 else if ((dev_id & 0xfff) == 0x398
169 && (dev_id >> 12) < 8)
170 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800171 else if ((dev_id & 0xfff) == 0x428
172 && (dev_id >> 12) < 8)
173 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800174 else if (dev_id == 0x0433 || dev_id == 0xa721)
175 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800176 else if (dev_id == 0x0441 || dev_id == 0x4441)
177 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800178 else if (dev_id == 0x0438 || dev_id == 0x4438)
179 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800180 else if (dev_id == 0x0448)
181 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800182 else if (dev_id == 0x0440)
183 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800184 else if ((dev_id & 0xfff) == 0x446)
185 codec_type = VT1802;
Lydia Wang43737e02012-12-10 18:28:11 +0800186 else if (dev_id == 0x4760)
187 codec_type = VT1705CF;
Lydia Wang6121b842012-12-10 19:03:26 +0800188 else if (dev_id == 0x4761 || dev_id == 0x4762)
189 codec_type = VT1808;
Harald Welted7426322008-09-15 22:43:23 +0800190 else
191 codec_type = UNKNOWN;
192 return codec_type;
193};
194
Takashi Iwaiada509e2011-06-20 15:40:19 +0200195static void analog_low_current_mode(struct hda_codec *codec);
196static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800197
Takashi Iwai187d3332011-11-24 16:33:09 +0100198#define hp_detect_with_aa(codec) \
199 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
200 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800201
Takashi Iwaib3f60082013-01-07 12:27:36 +0100202static void vt1708_stop_hp_work(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800203{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100204 struct via_spec *spec = codec->spec;
205 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800206 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100207 if (spec->hp_work_active) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100208 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
209 cancel_delayed_work_sync(&codec->jackpoll_work);
210 spec->hp_work_active = false;
211 codec->jackpoll_interval = 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100212 }
213}
214
Takashi Iwaib3f60082013-01-07 12:27:36 +0100215static void vt1708_update_hp_work(struct hda_codec *codec)
Takashi Iwai187d3332011-11-24 16:33:09 +0100216{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100217 struct via_spec *spec = codec->spec;
218 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800219 return;
David Henningsson05dc0fc2013-02-05 12:06:03 +0100220 if (spec->vt1708_jack_detect) {
Takashi Iwai187d3332011-11-24 16:33:09 +0100221 if (!spec->hp_work_active) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100222 codec->jackpoll_interval = msecs_to_jiffies(100);
223 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
224 queue_delayed_work(codec->bus->workq,
225 &codec->jackpoll_work, 0);
226 spec->hp_work_active = true;
Takashi Iwai187d3332011-11-24 16:33:09 +0100227 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100228 } else if (!hp_detect_with_aa(codec))
229 vt1708_stop_hp_work(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800230}
Lydia Wangf5271102009-10-10 19:07:35 +0800231
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800232static void set_widgets_power_state(struct hda_codec *codec)
233{
234 struct via_spec *spec = codec->spec;
235 if (spec->set_widgets_power_state)
236 spec->set_widgets_power_state(codec);
237}
Lydia Wang25eaba22009-10-10 19:08:43 +0800238
Takashi Iwai054d8672012-01-24 12:25:50 +0100239static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
240 unsigned int parm)
241{
Takashi Iwai9040d102013-01-24 17:47:17 +0100242 if (snd_hda_check_power_state(codec, nid, parm))
Takashi Iwai054d8672012-01-24 12:25:50 +0100243 return;
244 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
245}
246
Lydia Wang43737e02012-12-10 18:28:11 +0800247static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
248 unsigned int parm, unsigned int index)
249{
250 struct via_spec *spec = codec->spec;
251 unsigned int format;
Takashi Iwai9040d102013-01-24 17:47:17 +0100252
253 if (snd_hda_check_power_state(codec, nid, parm))
Lydia Wang43737e02012-12-10 18:28:11 +0800254 return;
255 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
256 if (format && (spec->dac_stream_tag[index] != format))
257 spec->dac_stream_tag[index] = format;
258
259 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
260 if (parm == AC_PWRST_D0) {
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (!format && (spec->dac_stream_tag[index] != format))
263 snd_hda_codec_write(codec, nid, 0,
264 AC_VERB_SET_CHANNEL_STREAMID,
265 spec->dac_stream_tag[index]);
266 }
267}
268
Takashi Iwaib3f60082013-01-07 12:27:36 +0100269static bool smart51_enabled(struct hda_codec *codec)
270{
271 struct via_spec *spec = codec->spec;
272 return spec->gen.ext_channel_count > 2;
273}
274
275static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
276{
277 struct via_spec *spec = codec->spec;
278 int i;
279
280 for (i = 0; i < spec->gen.multi_ios; i++)
281 if (spec->gen.multi_io[i].pin == pin)
282 return true;
283 return false;
284}
285
Lydia Wangf5271102009-10-10 19:07:35 +0800286static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
287 unsigned int *affected_parm)
288{
289 unsigned parm;
290 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
291 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
292 >> AC_DEFCFG_MISC_SHIFT
293 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800294 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200295 unsigned present = 0;
296
297 no_presence |= spec->no_pin_power_ctl;
298 if (!no_presence)
299 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100300 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800301 || ((no_presence || present)
302 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800303 *affected_parm = AC_PWRST_D0; /* if it's connected */
304 parm = AC_PWRST_D0;
305 } else
306 parm = AC_PWRST_D3;
307
Takashi Iwai054d8672012-01-24 12:25:50 +0100308 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800309}
310
Takashi Iwai24088a52011-06-17 16:59:21 +0200311static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_info *uinfo)
313{
Takashi Iwaidda415d2012-11-30 18:34:38 +0100314 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai24088a52011-06-17 16:59:21 +0200315}
316
317static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_value *ucontrol)
319{
320 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
321 struct via_spec *spec = codec->spec;
322 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
323 return 0;
324}
325
326static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
328{
329 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
330 struct via_spec *spec = codec->spec;
331 unsigned int val = !ucontrol->value.enumerated.item[0];
332
333 if (val == spec->no_pin_power_ctl)
334 return 0;
335 spec->no_pin_power_ctl = val;
336 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100337 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200338 return 1;
339}
340
Takashi Iwaib3f60082013-01-07 12:27:36 +0100341static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
342 {
Takashi Iwai24088a52011-06-17 16:59:21 +0200343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
344 .name = "Dynamic Power-Control",
345 .info = via_pin_power_ctl_info,
346 .get = via_pin_power_ctl_get,
347 .put = via_pin_power_ctl_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100348 },
349 {} /* terminator */
Takashi Iwai24088a52011-06-17 16:59:21 +0200350};
351
352
Takashi Iwaiada509e2011-06-20 15:40:19 +0200353/* check AA path's mute status */
354static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +0800355{
Lydia Wangf5271102009-10-10 19:07:35 +0800356 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200357 const struct hda_amp_list *p;
Takashi Iwai0186f4f2013-02-07 10:45:11 +0100358 int ch, v;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200359
Takashi Iwai0186f4f2013-02-07 10:45:11 +0100360 p = spec->gen.loopback.amplist;
361 if (!p)
362 return true;
363 for (; p->nid; p++) {
Takashi Iwaiada509e2011-06-20 15:40:19 +0200364 for (ch = 0; ch < 2; ch++) {
365 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
366 p->idx);
367 if (!(v & HDA_AMP_MUTE) && v > 0)
368 return false;
Lydia Wangf5271102009-10-10 19:07:35 +0800369 }
370 }
Takashi Iwaiada509e2011-06-20 15:40:19 +0200371 return true;
Lydia Wangf5271102009-10-10 19:07:35 +0800372}
373
374/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100375static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +0800376{
377 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200378 bool enable;
379 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +0800380
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100381 if (spec->no_pin_power_ctl)
382 enable = false;
383 else
Takashi Iwaib3f60082013-01-07 12:27:36 +0100384 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100385 if (enable == spec->alc_mode && !force)
386 return;
387 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +0800388
389 /* decide low current mode's verb & parameter */
390 switch (spec->codec_type) {
391 case VT1708B_8CH:
392 case VT1708B_4CH:
393 verb = 0xf70;
394 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
395 break;
396 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +0800397 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800398 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +0800399 verb = 0xf73;
400 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
401 break;
402 case VT1702:
403 verb = 0xf73;
404 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
405 break;
Lydia Wang25eaba22009-10-10 19:08:43 +0800406 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +0800407 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +0800408 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +0800409 verb = 0xf93;
410 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
411 break;
Lydia Wang43737e02012-12-10 18:28:11 +0800412 case VT1705CF:
Lydia Wang6121b842012-12-10 19:03:26 +0800413 case VT1808:
Lydia Wang43737e02012-12-10 18:28:11 +0800414 verb = 0xf82;
415 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
416 break;
Lydia Wangf5271102009-10-10 19:07:35 +0800417 default:
418 return; /* other codecs are not supported */
419 }
420 /* send verb */
421 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
422}
423
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100424static void analog_low_current_mode(struct hda_codec *codec)
425{
426 return __analog_low_current_mode(codec, false);
427}
428
Joseph Chanc577b8a2006-11-29 15:29:40 +0100429static int via_build_controls(struct hda_codec *codec)
430{
431 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100432 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100433
Takashi Iwaib3f60082013-01-07 12:27:36 +0100434 err = snd_hda_gen_build_controls(codec);
435 if (err < 0)
436 return err;
437
Takashi Iwai24088a52011-06-17 16:59:21 +0200438 if (spec->set_widgets_power_state)
Takashi Iwaib3f60082013-01-07 12:27:36 +0100439 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
Takashi Iwai24088a52011-06-17 16:59:21 +0200440
Joseph Chanc577b8a2006-11-29 15:29:40 +0100441 for (i = 0; i < spec->num_mixers; i++) {
442 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
443 if (err < 0)
444 return err;
445 }
446
Joseph Chanc577b8a2006-11-29 15:29:40 +0100447 return 0;
448}
449
Takashi Iwaib3f60082013-01-07 12:27:36 +0100450static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
451 struct hda_codec *codec,
452 struct snd_pcm_substream *substream,
453 int action)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100454{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100455 analog_low_current_mode(codec);
456 vt1708_update_hp_work(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100457}
458
459static void via_free(struct hda_codec *codec)
460{
461 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100462
463 if (!spec)
464 return;
465
Takashi Iwaib3f60082013-01-07 12:27:36 +0100466 vt1708_stop_hp_work(codec);
467 snd_hda_gen_spec_free(&spec->gen);
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200468 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100469}
470
Takashi Iwai2a439522011-07-26 09:52:50 +0200471#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200472static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800473{
474 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100475 vt1708_stop_hp_work(codec);
David Henningsson94c142a2012-08-09 10:56:12 +0200476
477 if (spec->codec_type == VT1802) {
478 /* Fix pop noise on headphones */
479 int i;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100480 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
481 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
David Henningsson94c142a2012-08-09 10:56:12 +0200482 }
483
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800484 return 0;
485}
486#endif
487
Takashi Iwai83012a72012-08-24 18:38:08 +0200488#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200489static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
490{
491 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100492 set_widgets_power_state(codec);
493 analog_low_current_mode(codec);
494 vt1708_update_hp_work(codec);
495 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200496}
497#endif
498
Joseph Chanc577b8a2006-11-29 15:29:40 +0100499/*
500 */
Takashi Iwai5d417622011-06-20 11:32:27 +0200501
502static int via_init(struct hda_codec *codec);
503
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200504static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100505 .build_controls = via_build_controls,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100506 .build_pcms = snd_hda_gen_build_pcms,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100507 .init = via_init,
508 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200509 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +0200510#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800511 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200512 .check_power_status = via_check_power_status,
513#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100514};
515
Takashi Iwai4a796162011-06-17 17:53:38 +0200516
Takashi Iwaib3f60082013-01-07 12:27:36 +0100517static const struct hda_verb vt1708_init_verbs[] = {
518 /* power down jack detect function */
519 {0x1, 0xf81, 0x1},
520 { }
Takashi Iwai3214b962011-07-18 12:49:25 +0200521};
Harald Welte76d9b0d2008-09-09 15:50:37 +0800522static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
523{
524 unsigned int def_conf;
525 unsigned char seqassoc;
526
Takashi Iwai2f334f92009-02-20 14:37:42 +0100527 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800528 seqassoc = (unsigned char) get_defcfg_association(def_conf);
529 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +0800530 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
531 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
532 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
533 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800534 }
535
536 return;
537}
538
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200539static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800540 struct snd_ctl_elem_value *ucontrol)
541{
542 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
543 struct via_spec *spec = codec->spec;
544
545 if (spec->codec_type != VT1708)
546 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200547 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800548 return 0;
549}
550
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200551static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800552 struct snd_ctl_elem_value *ucontrol)
553{
554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +0100556 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800557
558 if (spec->codec_type != VT1708)
559 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100560 val = !!ucontrol->value.integer.value[0];
561 if (spec->vt1708_jack_detect == val)
562 return 0;
563 spec->vt1708_jack_detect = val;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100564 vt1708_update_hp_work(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +0100565 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800566}
567
Takashi Iwaib3f60082013-01-07 12:27:36 +0100568static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
569 {
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
571 .name = "Jack Detect",
572 .count = 1,
573 .info = snd_ctl_boolean_mono_info,
574 .get = vt1708_jack_detect_get,
575 .put = vt1708_jack_detect_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100576 },
577 {} /* terminator */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800578};
579
Takashi Iwaib3f60082013-01-07 12:27:36 +0100580static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
David Henningsson4e2d16d2012-10-08 15:44:14 +0200581{
582 set_widgets_power_state(codec);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100583 snd_hda_gen_hp_automute(codec, tbl);
584}
585
586static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
587{
588 set_widgets_power_state(codec);
589 snd_hda_gen_line_automute(codec, tbl);
David Henningsson4e2d16d2012-10-08 15:44:14 +0200590}
591
592static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
593{
594 set_widgets_power_state(codec);
595}
596
Takashi Iwaib3f60082013-01-07 12:27:36 +0100597#define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
598
599static void via_set_jack_unsol_events(struct hda_codec *codec)
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200600{
601 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100602 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
603 hda_nid_t pin;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200604 int i;
605
Takashi Iwaib3f60082013-01-07 12:27:36 +0100606 spec->gen.hp_automute_hook = via_hp_automute;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200607 if (cfg->speaker_pins[0])
Takashi Iwaib3f60082013-01-07 12:27:36 +0100608 spec->gen.line_automute_hook = via_line_automute;
David Henningsson4e2d16d2012-10-08 15:44:14 +0200609
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200610 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100611 pin = cfg->line_out_pins[i];
612 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
613 is_jack_detectable(codec, pin))
614 snd_hda_jack_detect_enable_callback(codec, pin,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200615 VIA_JACK_EVENT,
616 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200617 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100618
619 for (i = 0; i < cfg->num_inputs; i++) {
620 pin = cfg->line_out_pins[i];
621 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
622 is_jack_detectable(codec, pin))
623 snd_hda_jack_detect_enable_callback(codec, pin,
624 VIA_JACK_EVENT,
625 via_jack_powerstate_event);
626 }
627}
628
Takashi Iwai4abdbd12013-03-22 15:11:07 +0100629static const struct badness_table via_main_out_badness = {
630 .no_primary_dac = 0x10000,
631 .no_dac = 0x4000,
632 .shared_primary = 0x10000,
633 .shared_surr = 0x20,
634 .shared_clfe = 0x20,
635 .shared_surr_main = 0x20,
636};
637static const struct badness_table via_extra_out_badness = {
638 .no_primary_dac = 0x4000,
639 .no_dac = 0x4000,
640 .shared_primary = 0x12,
641 .shared_surr = 0x20,
642 .shared_clfe = 0x20,
643 .shared_surr_main = 0x10,
644};
645
Takashi Iwaib3f60082013-01-07 12:27:36 +0100646static int via_parse_auto_config(struct hda_codec *codec)
647{
648 struct via_spec *spec = codec->spec;
649 int err;
650
Takashi Iwai4abdbd12013-03-22 15:11:07 +0100651 spec->gen.main_out_badness = &via_main_out_badness;
652 spec->gen.extra_out_badness = &via_extra_out_badness;
653
Takashi Iwaib3f60082013-01-07 12:27:36 +0100654 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
655 if (err < 0)
656 return err;
657
658 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
659 if (err < 0)
660 return err;
661
662 via_set_jack_unsol_events(codec);
663 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200664}
665
Takashi Iwai5d417622011-06-20 11:32:27 +0200666static int via_init(struct hda_codec *codec)
667{
668 struct via_spec *spec = codec->spec;
669 int i;
670
671 for (i = 0; i < spec->num_iverbs; i++)
672 snd_hda_sequence_write(codec, spec->init_verbs[i]);
673
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100674 /* init power states */
675 set_widgets_power_state(codec);
676 __analog_low_current_mode(codec, true);
677
Takashi Iwaib3f60082013-01-07 12:27:36 +0100678 snd_hda_gen_init(codec);
Lydia Wang118909562011-03-23 17:57:34 +0800679
Takashi Iwaib3f60082013-01-07 12:27:36 +0100680 vt1708_update_hp_work(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +0800681
Joseph Chanc577b8a2006-11-29 15:29:40 +0100682 return 0;
683}
684
David Henningssonf672f652013-02-05 12:06:02 +0100685static int vt1708_build_controls(struct hda_codec *codec)
686{
687 /* In order not to create "Phantom Jack" controls,
688 temporary enable jackpoll */
689 int err;
690 int old_interval = codec->jackpoll_interval;
691 codec->jackpoll_interval = msecs_to_jiffies(100);
692 err = via_build_controls(codec);
693 codec->jackpoll_interval = old_interval;
694 return err;
695}
696
Takashi Iwaib3f60082013-01-07 12:27:36 +0100697static int vt1708_build_pcms(struct hda_codec *codec)
Takashi Iwai337b9d02009-07-07 18:18:59 +0200698{
699 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100700 int i, err;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200701
Takashi Iwaib3f60082013-01-07 12:27:36 +0100702 err = snd_hda_gen_build_pcms(codec);
703 if (err < 0 || codec->vendor_id != 0x11061708)
704 return err;
705
706 /* We got noisy outputs on the right channel on VT1708 when
707 * 24bit samples are used. Until any workaround is found,
708 * disable the 24bit format, so far.
709 */
710 for (i = 0; i < codec->num_pcms; i++) {
711 struct hda_pcm *info = &spec->gen.pcm_rec[i];
712 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
713 info->pcm_type != HDA_PCM_TYPE_AUDIO)
714 continue;
715 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
716 SNDRV_PCM_FMTBIT_S16_LE;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200717 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100718
Takashi Iwai1c55d522009-07-08 07:45:46 +0200719 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200720}
721
Joseph Chanc577b8a2006-11-29 15:29:40 +0100722static int patch_vt1708(struct hda_codec *codec)
723{
724 struct via_spec *spec;
725 int err;
726
727 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100728 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100729 if (spec == NULL)
730 return -ENOMEM;
731
Takashi Iwaib3f60082013-01-07 12:27:36 +0100732 spec->gen.mixer_nid = 0x17;
733
734 /* set jackpoll_interval while parsing the codec */
735 codec->jackpoll_interval = msecs_to_jiffies(100);
736 spec->vt1708_jack_detect = 1;
737
738 /* don't support the input jack switching due to lack of unsol event */
739 /* (it may work with polling, though, but it needs testing) */
740 spec->gen.suppress_auto_mic = 1;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200741
Takashi Iwai12daef62011-06-18 17:45:49 +0200742 /* Add HP and CD pin config connect bit re-config action */
743 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
744 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
745
Joseph Chanc577b8a2006-11-29 15:29:40 +0100746 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200747 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100748 if (err < 0) {
749 via_free(codec);
750 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100751 }
752
Takashi Iwai12daef62011-06-18 17:45:49 +0200753 /* add jack detect on/off control */
Takashi Iwaib3f60082013-01-07 12:27:36 +0100754 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100755
Lydia Wange322a362011-06-29 13:52:02 +0800756 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
757
Joseph Chanc577b8a2006-11-29 15:29:40 +0100758 codec->patch_ops = via_patch_ops;
David Henningssonf672f652013-02-05 12:06:02 +0100759 codec->patch_ops.build_controls = vt1708_build_controls;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100760 codec->patch_ops.build_pcms = vt1708_build_pcms;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100761
Takashi Iwaib3f60082013-01-07 12:27:36 +0100762 /* clear jackpoll_interval again; it's set dynamically */
763 codec->jackpoll_interval = 0;
764
Joseph Chanc577b8a2006-11-29 15:29:40 +0100765 return 0;
766}
767
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200768static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100769{
770 struct via_spec *spec;
771 int err;
772
773 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100774 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100775 if (spec == NULL)
776 return -ENOMEM;
777
Takashi Iwaib3f60082013-01-07 12:27:36 +0100778 spec->gen.mixer_nid = 0x18;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200779
Takashi Iwai12daef62011-06-18 17:45:49 +0200780 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100781 if (err < 0) {
782 via_free(codec);
783 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100784 }
785
Joseph Chanc577b8a2006-11-29 15:29:40 +0100786 codec->patch_ops = via_patch_ops;
787
Josepch Chanf7278fd2007-12-13 16:40:40 +0100788 return 0;
789}
790
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800791static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
792{
793 struct via_spec *spec = codec->spec;
794 int imux_is_smixer;
795 unsigned int parm;
796 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +0800797 if ((spec->codec_type != VT1708B_4CH) &&
798 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800799 is_8ch = 1;
800
801 /* SW0 (17h) = stereo mixer */
802 imux_is_smixer =
803 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
804 == ((spec->codec_type == VT1708S) ? 5 : 0));
805 /* inputs */
806 /* PW 1/2/5 (1ah/1bh/1eh) */
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x1a, &parm);
809 set_pin_power_state(codec, 0x1b, &parm);
810 set_pin_power_state(codec, 0x1e, &parm);
811 if (imux_is_smixer)
812 parm = AC_PWRST_D0;
813 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100814 update_power_state(codec, 0x17, parm);
815 update_power_state(codec, 0x13, parm);
816 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800817
818 /* outputs */
819 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
820 parm = AC_PWRST_D3;
821 set_pin_power_state(codec, 0x19, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100822 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800823 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100824 update_power_state(codec, 0x18, parm);
825 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800826
827 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
828 if (is_8ch) {
829 parm = AC_PWRST_D3;
830 set_pin_power_state(codec, 0x22, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100831 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800832 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100833 update_power_state(codec, 0x26, parm);
834 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +0800835 } else if (codec->vendor_id == 0x11064397) {
836 /* PW7(23h), SW2(27h), AOW2(25h) */
837 parm = AC_PWRST_D3;
838 set_pin_power_state(codec, 0x23, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100839 if (smart51_enabled(codec))
Lydia Wangbc92df72011-03-23 17:56:05 +0800840 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100841 update_power_state(codec, 0x27, parm);
842 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800843 }
844
845 /* PW 3/4/7 (1ch/1dh/23h) */
846 parm = AC_PWRST_D3;
847 /* force to D0 for internal Speaker */
848 set_pin_power_state(codec, 0x1c, &parm);
849 set_pin_power_state(codec, 0x1d, &parm);
850 if (is_8ch)
851 set_pin_power_state(codec, 0x23, &parm);
852
853 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100854 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
855 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800856 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +0100857 update_power_state(codec, 0x25, parm);
858 update_power_state(codec, 0x27, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100859 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +0100860 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800861}
862
Lydia Wang518bf3b2009-10-10 19:07:29 +0800863static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200864static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +0100865{
866 struct via_spec *spec;
867 int err;
868
Lydia Wang518bf3b2009-10-10 19:07:29 +0800869 if (get_codec_type(codec) == VT1708BCE)
870 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200871
Josepch Chanf7278fd2007-12-13 16:40:40 +0100872 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100873 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100874 if (spec == NULL)
875 return -ENOMEM;
876
Takashi Iwaib3f60082013-01-07 12:27:36 +0100877 spec->gen.mixer_nid = 0x16;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200878
Josepch Chanf7278fd2007-12-13 16:40:40 +0100879 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200880 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100881 if (err < 0) {
882 via_free(codec);
883 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +0100884 }
885
Josepch Chanf7278fd2007-12-13 16:40:40 +0100886 codec->patch_ops = via_patch_ops;
887
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800888 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
889
Josepch Chanf7278fd2007-12-13 16:40:40 +0100890 return 0;
891}
892
Harald Welted949cac2008-09-09 15:56:01 +0800893/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +0200894static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +0800895 /* Enable Mic Boost Volume backdoor */
896 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800897 /* don't bybass mixer */
898 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +0800899 { }
900};
901
Lydia Wang6369bcf2009-10-10 19:08:31 +0800902static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
903 int offset, int num_steps, int step_size)
904{
905 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
906 (offset << AC_AMPCAP_OFFSET_SHIFT) |
907 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
908 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
909 (0 << AC_AMPCAP_MUTE_SHIFT));
910}
911
Harald Welted949cac2008-09-09 15:56:01 +0800912static int patch_vt1708S(struct hda_codec *codec)
913{
914 struct via_spec *spec;
915 int err;
916
917 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100918 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800919 if (spec == NULL)
920 return -ENOMEM;
921
Takashi Iwaib3f60082013-01-07 12:27:36 +0100922 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200923 override_mic_boost(codec, 0x1a, 0, 3, 40);
924 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +0200925
Lydia Wang518bf3b2009-10-10 19:07:29 +0800926 /* correct names for VT1708BCE */
927 if (get_codec_type(codec) == VT1708BCE) {
928 kfree(codec->chip_name);
929 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
930 snprintf(codec->bus->card->mixername,
931 sizeof(codec->bus->card->mixername),
932 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +0800933 }
Lydia Wangbc92df72011-03-23 17:56:05 +0800934 /* correct names for VT1705 */
935 if (codec->vendor_id == 0x11064397) {
936 kfree(codec->chip_name);
937 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
938 snprintf(codec->bus->card->mixername,
939 sizeof(codec->bus->card->mixername),
940 "%s %s", codec->vendor_name, codec->chip_name);
941 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100942
943 /* automatic parse from the BIOS config */
944 err = via_parse_auto_config(codec);
945 if (err < 0) {
946 via_free(codec);
947 return err;
948 }
949
950 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
951
952 codec->patch_ops = via_patch_ops;
953
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800954 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +0800955 return 0;
956}
957
958/* Patch for VT1702 */
959
Takashi Iwai096a8852011-06-20 12:09:02 +0200960static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800961 /* mixer enable */
962 {0x1, 0xF88, 0x3},
963 /* GPIO 0~2 */
964 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +0800965 { }
966};
967
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800968static void set_widgets_power_state_vt1702(struct hda_codec *codec)
969{
970 int imux_is_smixer =
971 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
972 unsigned int parm;
973 /* inputs */
974 /* PW 1/2/5 (14h/15h/18h) */
975 parm = AC_PWRST_D3;
976 set_pin_power_state(codec, 0x14, &parm);
977 set_pin_power_state(codec, 0x15, &parm);
978 set_pin_power_state(codec, 0x18, &parm);
979 if (imux_is_smixer)
980 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
981 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100982 update_power_state(codec, 0x13, parm);
983 update_power_state(codec, 0x12, parm);
984 update_power_state(codec, 0x1f, parm);
985 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800986
987 /* outputs */
988 /* PW 3/4 (16h/17h) */
989 parm = AC_PWRST_D3;
990 set_pin_power_state(codec, 0x17, &parm);
991 set_pin_power_state(codec, 0x16, &parm);
992 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100993 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
994 update_power_state(codec, 0x10, parm);
995 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800996}
997
Harald Welted949cac2008-09-09 15:56:01 +0800998static int patch_vt1702(struct hda_codec *codec)
999{
1000 struct via_spec *spec;
1001 int err;
Harald Welted949cac2008-09-09 15:56:01 +08001002
1003 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001004 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08001005 if (spec == NULL)
1006 return -ENOMEM;
1007
Takashi Iwaib3f60082013-01-07 12:27:36 +01001008 spec->gen.mixer_nid = 0x1a;
Takashi Iwai620e2b22011-06-17 17:19:19 +02001009
Takashi Iwai12daef62011-06-18 17:45:49 +02001010 /* limit AA path volume to 0 dB */
1011 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
1012 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1013 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1014 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1015 (1 << AC_AMPCAP_MUTE_SHIFT));
1016
Harald Welted949cac2008-09-09 15:56:01 +08001017 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001018 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08001019 if (err < 0) {
1020 via_free(codec);
1021 return err;
Harald Welted949cac2008-09-09 15:56:01 +08001022 }
1023
Takashi Iwai096a8852011-06-20 12:09:02 +02001024 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08001025
Harald Welted949cac2008-09-09 15:56:01 +08001026 codec->patch_ops = via_patch_ops;
1027
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001028 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08001029 return 0;
1030}
1031
Lydia Wangeb7188c2009-10-10 19:08:34 +08001032/* Patch for VT1718S */
1033
Takashi Iwai096a8852011-06-20 12:09:02 +02001034static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08001035 /* Enable MW0 adjust Gain 5 */
1036 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001037 /* Enable Boost Volume backdoor */
1038 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02001039
Lydia Wangeb7188c2009-10-10 19:08:34 +08001040 { }
1041};
1042
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001043static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1044{
1045 struct via_spec *spec = codec->spec;
1046 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02001047 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001048 /* MUX6 (1eh) = stereo mixer */
1049 imux_is_smixer =
1050 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1051 /* inputs */
1052 /* PW 5/6/7 (29h/2ah/2bh) */
1053 parm = AC_PWRST_D3;
1054 set_pin_power_state(codec, 0x29, &parm);
1055 set_pin_power_state(codec, 0x2a, &parm);
1056 set_pin_power_state(codec, 0x2b, &parm);
1057 if (imux_is_smixer)
1058 parm = AC_PWRST_D0;
1059 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001060 update_power_state(codec, 0x1e, parm);
1061 update_power_state(codec, 0x1f, parm);
1062 update_power_state(codec, 0x10, parm);
1063 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001064
1065 /* outputs */
1066 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1067 parm = AC_PWRST_D3;
1068 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001069 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02001070 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001071
1072 /* PW2 (26h), AOW2 (ah) */
1073 parm = AC_PWRST_D3;
1074 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001075 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001076 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001077 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001078
1079 /* PW0 (24h), AOW0 (8h) */
1080 parm = AC_PWRST_D3;
1081 set_pin_power_state(codec, 0x24, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001082 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001083 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001084 update_power_state(codec, 0x8, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001085 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Takashi Iwai61625522012-07-25 13:54:55 +02001086 parm = parm2;
1087 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001088 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001089 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001090
1091 /* PW1 (25h), AOW1 (9h) */
1092 parm = AC_PWRST_D3;
1093 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001094 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001095 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001096 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001097
Takashi Iwaib3f60082013-01-07 12:27:36 +01001098 if (spec->gen.indep_hp_enabled) {
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001099 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1100 parm = AC_PWRST_D3;
1101 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001102 update_power_state(codec, 0x1b, parm);
1103 update_power_state(codec, 0x34, parm);
1104 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001105 }
1106}
1107
Takashi Iwai30b45032011-07-11 17:05:04 +02001108/* Add a connection to the primary DAC from AA-mixer for some codecs
1109 * This isn't listed from the raw info, but the chip has a secret connection.
1110 */
1111static int add_secret_dac_path(struct hda_codec *codec)
1112{
1113 struct via_spec *spec = codec->spec;
1114 int i, nums;
1115 hda_nid_t conn[8];
1116 hda_nid_t nid;
1117
Takashi Iwaib3f60082013-01-07 12:27:36 +01001118 if (!spec->gen.mixer_nid)
Takashi Iwai30b45032011-07-11 17:05:04 +02001119 return 0;
Takashi Iwaib3f60082013-01-07 12:27:36 +01001120 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
Takashi Iwai30b45032011-07-11 17:05:04 +02001121 ARRAY_SIZE(conn) - 1);
1122 for (i = 0; i < nums; i++) {
1123 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1124 return 0;
1125 }
1126
1127 /* find the primary DAC and add to the connection list */
1128 nid = codec->start_nid;
1129 for (i = 0; i < codec->num_nodes; i++, nid++) {
1130 unsigned int caps = get_wcaps(codec, nid);
1131 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1132 !(caps & AC_WCAP_DIGITAL)) {
1133 conn[nums++] = nid;
1134 return snd_hda_override_conn_list(codec,
Takashi Iwaib3f60082013-01-07 12:27:36 +01001135 spec->gen.mixer_nid,
Takashi Iwai30b45032011-07-11 17:05:04 +02001136 nums, conn);
1137 }
1138 }
1139 return 0;
1140}
1141
1142
Lydia Wangeb7188c2009-10-10 19:08:34 +08001143static int patch_vt1718S(struct hda_codec *codec)
1144{
1145 struct via_spec *spec;
1146 int err;
1147
1148 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001149 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001150 if (spec == NULL)
1151 return -ENOMEM;
1152
Takashi Iwaib3f60082013-01-07 12:27:36 +01001153 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001154 override_mic_boost(codec, 0x2b, 0, 3, 40);
1155 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001156 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001157
Lydia Wangeb7188c2009-10-10 19:08:34 +08001158 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001159 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001160 if (err < 0) {
1161 via_free(codec);
1162 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001163 }
1164
Takashi Iwai096a8852011-06-20 12:09:02 +02001165 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001166
Lydia Wangeb7188c2009-10-10 19:08:34 +08001167 codec->patch_ops = via_patch_ops;
1168
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001169 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1170
Lydia Wangeb7188c2009-10-10 19:08:34 +08001171 return 0;
1172}
Lydia Wangf3db4232009-10-10 19:08:41 +08001173
1174/* Patch for VT1716S */
1175
1176static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1177 struct snd_ctl_elem_info *uinfo)
1178{
1179 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1180 uinfo->count = 1;
1181 uinfo->value.integer.min = 0;
1182 uinfo->value.integer.max = 1;
1183 return 0;
1184}
1185
1186static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1187 struct snd_ctl_elem_value *ucontrol)
1188{
1189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1190 int index = 0;
1191
1192 index = snd_hda_codec_read(codec, 0x26, 0,
1193 AC_VERB_GET_CONNECT_SEL, 0);
1194 if (index != -1)
1195 *ucontrol->value.integer.value = index;
1196
1197 return 0;
1198}
1199
1200static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1201 struct snd_ctl_elem_value *ucontrol)
1202{
1203 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1204 struct via_spec *spec = codec->spec;
1205 int index = *ucontrol->value.integer.value;
1206
1207 snd_hda_codec_write(codec, 0x26, 0,
1208 AC_VERB_SET_CONNECT_SEL, index);
1209 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001210 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001211 return 1;
1212}
1213
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001214static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001215 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1216 {
1217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1218 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001219 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08001220 .count = 1,
1221 .info = vt1716s_dmic_info,
1222 .get = vt1716s_dmic_get,
1223 .put = vt1716s_dmic_put,
1224 },
1225 {} /* end */
1226};
1227
1228
1229/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001230static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001231 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1232 { } /* end */
1233};
1234
Takashi Iwai096a8852011-06-20 12:09:02 +02001235static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001236 /* Enable Boost Volume backdoor */
1237 {0x1, 0xf8a, 0x80},
1238 /* don't bybass mixer */
1239 {0x1, 0xf88, 0xc0},
1240 /* Enable mono output */
1241 {0x1, 0xf90, 0x08},
1242 { }
1243};
1244
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001245static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1246{
1247 struct via_spec *spec = codec->spec;
1248 int imux_is_smixer;
1249 unsigned int parm;
1250 unsigned int mono_out, present;
1251 /* SW0 (17h) = stereo mixer */
1252 imux_is_smixer =
1253 (snd_hda_codec_read(codec, 0x17, 0,
1254 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1255 /* inputs */
1256 /* PW 1/2/5 (1ah/1bh/1eh) */
1257 parm = AC_PWRST_D3;
1258 set_pin_power_state(codec, 0x1a, &parm);
1259 set_pin_power_state(codec, 0x1b, &parm);
1260 set_pin_power_state(codec, 0x1e, &parm);
1261 if (imux_is_smixer)
1262 parm = AC_PWRST_D0;
1263 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001264 update_power_state(codec, 0x17, parm);
1265 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001266
1267 parm = AC_PWRST_D3;
1268 set_pin_power_state(codec, 0x1e, &parm);
1269 /* PW11 (22h) */
1270 if (spec->dmic_enabled)
1271 set_pin_power_state(codec, 0x22, &parm);
1272 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001273 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001274
1275 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001276 update_power_state(codec, 0x26, parm);
1277 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001278
1279 /* outputs */
1280 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1281 parm = AC_PWRST_D3;
1282 set_pin_power_state(codec, 0x19, &parm);
1283 /* Smart 5.1 PW2(1bh) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001284 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001285 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001286 update_power_state(codec, 0x18, parm);
1287 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001288
1289 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1290 parm = AC_PWRST_D3;
1291 set_pin_power_state(codec, 0x23, &parm);
1292 /* Smart 5.1 PW1(1ah) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001293 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001294 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001295 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001296
1297 /* Smart 5.1 PW5(1eh) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001298 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001299 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001300 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001301
1302 /* Mono out */
1303 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1304 present = snd_hda_jack_detect(codec, 0x1c);
1305
1306 if (present)
1307 mono_out = 0;
1308 else {
1309 present = snd_hda_jack_detect(codec, 0x1d);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001310 if (!spec->gen.indep_hp_enabled && present)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001311 mono_out = 0;
1312 else
1313 mono_out = 1;
1314 }
1315 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01001316 update_power_state(codec, 0x28, parm);
1317 update_power_state(codec, 0x29, parm);
1318 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001319
1320 /* PW 3/4 (1ch/1dh) */
1321 parm = AC_PWRST_D3;
1322 set_pin_power_state(codec, 0x1c, &parm);
1323 set_pin_power_state(codec, 0x1d, &parm);
1324 /* HP Independent Mode, power on AOW3 */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001325 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001326 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001327
1328 /* force to D0 for internal Speaker */
1329 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001330 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1331 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001332}
1333
Lydia Wangf3db4232009-10-10 19:08:41 +08001334static int patch_vt1716S(struct hda_codec *codec)
1335{
1336 struct via_spec *spec;
1337 int err;
1338
1339 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001340 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001341 if (spec == NULL)
1342 return -ENOMEM;
1343
Takashi Iwaib3f60082013-01-07 12:27:36 +01001344 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001345 override_mic_boost(codec, 0x1a, 0, 3, 40);
1346 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001347
Lydia Wangf3db4232009-10-10 19:08:41 +08001348 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001349 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001350 if (err < 0) {
1351 via_free(codec);
1352 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08001353 }
1354
Takashi Iwai096a8852011-06-20 12:09:02 +02001355 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08001356
Takashi Iwaib3f60082013-01-07 12:27:36 +01001357 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
Lydia Wangf3db4232009-10-10 19:08:41 +08001358 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1359
1360 codec->patch_ops = via_patch_ops;
1361
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001362 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08001363 return 0;
1364}
Lydia Wang25eaba22009-10-10 19:08:43 +08001365
1366/* for vt2002P */
1367
Takashi Iwai096a8852011-06-20 12:09:02 +02001368static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08001369 /* Class-D speaker related verbs */
1370 {0x1, 0xfe0, 0x4},
1371 {0x1, 0xfe9, 0x80},
1372 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08001373 /* Enable Boost Volume backdoor */
1374 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08001375 /* Enable AOW0 to MW9 */
1376 {0x1, 0xfb8, 0x88},
1377 { }
1378};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001379
Takashi Iwai096a8852011-06-20 12:09:02 +02001380static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08001381 /* Enable Boost Volume backdoor */
1382 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08001383 /* Enable AOW0 to MW9 */
1384 {0x1, 0xfb8, 0x88},
1385 { }
1386};
Lydia Wang25eaba22009-10-10 19:08:43 +08001387
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001388static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1389{
1390 struct via_spec *spec = codec->spec;
1391 int imux_is_smixer;
1392 unsigned int parm;
1393 unsigned int present;
1394 /* MUX9 (1eh) = stereo mixer */
1395 imux_is_smixer =
1396 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1397 /* inputs */
1398 /* PW 5/6/7 (29h/2ah/2bh) */
1399 parm = AC_PWRST_D3;
1400 set_pin_power_state(codec, 0x29, &parm);
1401 set_pin_power_state(codec, 0x2a, &parm);
1402 set_pin_power_state(codec, 0x2b, &parm);
1403 parm = AC_PWRST_D0;
1404 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001405 update_power_state(codec, 0x1e, parm);
1406 update_power_state(codec, 0x1f, parm);
1407 update_power_state(codec, 0x10, parm);
1408 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001409
1410 /* outputs */
1411 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001412 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001413
Lydia Wang118909562011-03-23 17:57:34 +08001414 if (spec->codec_type == VT1802) {
1415 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1416 parm = AC_PWRST_D3;
1417 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001418 update_power_state(codec, 0x18, parm);
1419 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001420 } else {
1421 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1422 parm = AC_PWRST_D3;
1423 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001424 update_power_state(codec, 0x1c, parm);
1425 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001426 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001427
Lydia Wang118909562011-03-23 17:57:34 +08001428 if (spec->codec_type == VT1802) {
1429 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1430 parm = AC_PWRST_D3;
1431 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001432 update_power_state(codec, 0x15, parm);
1433 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001434 } else {
1435 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1436 parm = AC_PWRST_D3;
1437 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001438 update_power_state(codec, 0x19, parm);
1439 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001440 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001441
Takashi Iwaib3f60082013-01-07 12:27:36 +01001442 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001443 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001444
1445 /* Class-D */
1446 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1447 present = snd_hda_jack_detect(codec, 0x25);
1448
1449 parm = AC_PWRST_D3;
1450 set_pin_power_state(codec, 0x24, &parm);
1451 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001452 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01001453 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001454 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001455 update_power_state(codec, 0x18, parm);
1456 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001457
1458 /* Mono Out */
1459 present = snd_hda_jack_detect(codec, 0x26);
1460
1461 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001462 if (spec->codec_type == VT1802) {
1463 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001464 update_power_state(codec, 0x33, parm);
1465 update_power_state(codec, 0x1c, parm);
1466 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001467 } else {
1468 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001469 update_power_state(codec, 0x31, parm);
1470 update_power_state(codec, 0x17, parm);
1471 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001472 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001473 /* MW9 (21h) */
1474 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01001475 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001476 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001477 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001478}
Lydia Wang25eaba22009-10-10 19:08:43 +08001479
David Henningsson4b527b62012-09-18 14:26:59 +02001480/*
1481 * pin fix-up
1482 */
1483enum {
1484 VIA_FIXUP_INTMIC_BOOST,
Takashi Iwaid5266122012-11-07 10:40:36 +01001485 VIA_FIXUP_ASUS_G75,
David Henningsson4b527b62012-09-18 14:26:59 +02001486};
1487
1488static void via_fixup_intmic_boost(struct hda_codec *codec,
1489 const struct hda_fixup *fix, int action)
1490{
1491 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1492 override_mic_boost(codec, 0x30, 0, 2, 40);
1493}
1494
1495static const struct hda_fixup via_fixups[] = {
1496 [VIA_FIXUP_INTMIC_BOOST] = {
1497 .type = HDA_FIXUP_FUNC,
1498 .v.func = via_fixup_intmic_boost,
1499 },
Takashi Iwaid5266122012-11-07 10:40:36 +01001500 [VIA_FIXUP_ASUS_G75] = {
1501 .type = HDA_FIXUP_PINS,
1502 .v.pins = (const struct hda_pintbl[]) {
1503 /* set 0x24 and 0x33 as speakers */
1504 { 0x24, 0x991301f0 },
1505 { 0x33, 0x991301f1 }, /* subwoofer */
1506 { }
1507 }
1508 },
David Henningsson4b527b62012-09-18 14:26:59 +02001509};
1510
1511static const struct snd_pci_quirk vt2002p_fixups[] = {
Takashi Iwaid5266122012-11-07 10:40:36 +01001512 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
David Henningsson4b527b62012-09-18 14:26:59 +02001513 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1514 {}
1515};
1516
Takashi Iwaief4da452012-11-07 10:37:48 +01001517/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1518 * Replace this with mixer NID 0x1c
1519 */
1520static void fix_vt1802_connections(struct hda_codec *codec)
1521{
1522 static hda_nid_t conn_24[] = { 0x14, 0x1c };
1523 static hda_nid_t conn_33[] = { 0x1c };
1524
1525 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1526 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1527}
1528
Lydia Wang25eaba22009-10-10 19:08:43 +08001529/* patch for vt2002P */
1530static int patch_vt2002P(struct hda_codec *codec)
1531{
1532 struct via_spec *spec;
1533 int err;
1534
1535 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001536 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001537 if (spec == NULL)
1538 return -ENOMEM;
1539
Takashi Iwaib3f60082013-01-07 12:27:36 +01001540 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001541 override_mic_boost(codec, 0x2b, 0, 3, 40);
1542 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwaief4da452012-11-07 10:37:48 +01001543 if (spec->codec_type == VT1802)
1544 fix_vt1802_connections(codec);
Takashi Iwai30b45032011-07-11 17:05:04 +02001545 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001546
David Henningsson4b527b62012-09-18 14:26:59 +02001547 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1548 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1549
Lydia Wang25eaba22009-10-10 19:08:43 +08001550 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001551 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001552 if (err < 0) {
1553 via_free(codec);
1554 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08001555 }
1556
Lydia Wang118909562011-03-23 17:57:34 +08001557 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001558 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001559 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001560 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001561
Lydia Wang25eaba22009-10-10 19:08:43 +08001562 codec->patch_ops = via_patch_ops;
1563
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001564 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08001565 return 0;
1566}
Lydia Wangab6734e2009-10-10 19:08:46 +08001567
1568/* for vt1812 */
1569
Takashi Iwai096a8852011-06-20 12:09:02 +02001570static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08001571 /* Enable Boost Volume backdoor */
1572 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08001573 /* Enable AOW0 to MW9 */
1574 {0x1, 0xfb8, 0xa8},
1575 { }
1576};
1577
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001578static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1579{
1580 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001581 unsigned int parm;
1582 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001583 /* inputs */
1584 /* PW 5/6/7 (29h/2ah/2bh) */
1585 parm = AC_PWRST_D3;
1586 set_pin_power_state(codec, 0x29, &parm);
1587 set_pin_power_state(codec, 0x2a, &parm);
1588 set_pin_power_state(codec, 0x2b, &parm);
1589 parm = AC_PWRST_D0;
1590 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001591 update_power_state(codec, 0x1e, parm);
1592 update_power_state(codec, 0x1f, parm);
1593 update_power_state(codec, 0x10, parm);
1594 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001595
1596 /* outputs */
1597 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001598 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001599
1600 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1601 parm = AC_PWRST_D3;
1602 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001603 update_power_state(codec, 0x18, parm);
1604 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001605
1606 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1607 parm = AC_PWRST_D3;
1608 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001609 update_power_state(codec, 0x15, parm);
1610 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001611 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001612 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001613
1614 /* Internal Speaker */
1615 /* PW0 (24h), MW0(14h), MUX0(34h) */
1616 present = snd_hda_jack_detect(codec, 0x25);
1617
1618 parm = AC_PWRST_D3;
1619 set_pin_power_state(codec, 0x24, &parm);
1620 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001621 update_power_state(codec, 0x14, AC_PWRST_D3);
1622 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001623 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001624 update_power_state(codec, 0x14, AC_PWRST_D0);
1625 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001626 }
1627
1628
1629 /* Mono Out */
1630 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1631 present = snd_hda_jack_detect(codec, 0x28);
1632
1633 parm = AC_PWRST_D3;
1634 set_pin_power_state(codec, 0x31, &parm);
1635 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001636 update_power_state(codec, 0x1c, AC_PWRST_D3);
1637 update_power_state(codec, 0x3c, AC_PWRST_D3);
1638 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001639 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001640 update_power_state(codec, 0x1c, AC_PWRST_D0);
1641 update_power_state(codec, 0x3c, AC_PWRST_D0);
1642 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001643 }
1644
1645 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1646 parm = AC_PWRST_D3;
1647 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001648 update_power_state(codec, 0x1d, parm);
1649 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001650
1651}
Lydia Wangab6734e2009-10-10 19:08:46 +08001652
1653/* patch for vt1812 */
1654static int patch_vt1812(struct hda_codec *codec)
1655{
1656 struct via_spec *spec;
1657 int err;
1658
1659 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001660 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001661 if (spec == NULL)
1662 return -ENOMEM;
1663
Takashi Iwaib3f60082013-01-07 12:27:36 +01001664 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001665 override_mic_boost(codec, 0x2b, 0, 3, 40);
1666 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001667 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001668
Lydia Wangab6734e2009-10-10 19:08:46 +08001669 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001670 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001671 if (err < 0) {
1672 via_free(codec);
1673 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08001674 }
1675
Takashi Iwai096a8852011-06-20 12:09:02 +02001676 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08001677
Lydia Wangab6734e2009-10-10 19:08:46 +08001678 codec->patch_ops = via_patch_ops;
1679
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001680 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08001681 return 0;
1682}
1683
Lydia Wang43737e02012-12-10 18:28:11 +08001684/* patch for vt3476 */
1685
1686static const struct hda_verb vt3476_init_verbs[] = {
1687 /* Enable DMic 8/16/32K */
1688 {0x1, 0xF7B, 0x30},
1689 /* Enable Boost Volume backdoor */
1690 {0x1, 0xFB9, 0x20},
1691 /* Enable AOW-MW9 path */
1692 {0x1, 0xFB8, 0x10},
1693 { }
1694};
1695
1696static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1697{
1698 struct via_spec *spec = codec->spec;
1699 int imux_is_smixer;
1700 unsigned int parm, parm2;
1701 /* MUX10 (1eh) = stereo mixer */
1702 imux_is_smixer =
1703 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1704 /* inputs */
1705 /* PW 5/6/7 (29h/2ah/2bh) */
1706 parm = AC_PWRST_D3;
1707 set_pin_power_state(codec, 0x29, &parm);
1708 set_pin_power_state(codec, 0x2a, &parm);
1709 set_pin_power_state(codec, 0x2b, &parm);
1710 if (imux_is_smixer)
1711 parm = AC_PWRST_D0;
1712 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1713 update_power_state(codec, 0x1e, parm);
1714 update_power_state(codec, 0x1f, parm);
1715 update_power_state(codec, 0x10, parm);
1716 update_power_state(codec, 0x11, parm);
1717
1718 /* outputs */
1719 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1720 if (spec->codec_type == VT1705CF) {
1721 parm = AC_PWRST_D3;
1722 update_power_state(codec, 0x27, parm);
1723 update_power_state(codec, 0x37, parm);
1724 } else {
1725 parm = AC_PWRST_D3;
1726 set_pin_power_state(codec, 0x27, &parm);
1727 update_power_state(codec, 0x37, parm);
1728 }
1729
1730 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1731 parm = AC_PWRST_D3;
1732 set_pin_power_state(codec, 0x26, &parm);
1733 update_power_state(codec, 0x36, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001734 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001735 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1736 set_pin_power_state(codec, 0x2b, &parm);
1737 update_power_state(codec, 0x3b, parm);
1738 update_power_state(codec, 0x1b, parm);
1739 }
1740 update_conv_power_state(codec, 0xa, parm, 2);
1741
1742 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1743 parm = AC_PWRST_D3;
1744 set_pin_power_state(codec, 0x25, &parm);
1745 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001746 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001747 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1748 set_pin_power_state(codec, 0x2a, &parm);
1749 update_power_state(codec, 0x3a, parm);
1750 update_power_state(codec, 0x1a, parm);
1751 }
1752 update_conv_power_state(codec, 0x9, parm, 1);
1753
1754 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1755 parm = AC_PWRST_D3;
1756 set_pin_power_state(codec, 0x28, &parm);
1757 update_power_state(codec, 0x38, parm);
1758 update_power_state(codec, 0x18, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001759 if (spec->gen.indep_hp_enabled)
Lydia Wang43737e02012-12-10 18:28:11 +08001760 update_conv_power_state(codec, 0xb, parm, 3);
1761 parm2 = parm; /* for pin 0x0b */
1762
1763 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1764 parm = AC_PWRST_D3;
1765 set_pin_power_state(codec, 0x24, &parm);
1766 update_power_state(codec, 0x34, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001767 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Lydia Wang43737e02012-12-10 18:28:11 +08001768 parm = parm2;
1769 update_conv_power_state(codec, 0x8, parm, 0);
1770 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1771 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1772}
1773
1774static int patch_vt3476(struct hda_codec *codec)
1775{
1776 struct via_spec *spec;
1777 int err;
1778
1779 /* create a codec specific record */
1780 spec = via_new_spec(codec);
1781 if (spec == NULL)
1782 return -ENOMEM;
1783
Takashi Iwaib3f60082013-01-07 12:27:36 +01001784 spec->gen.mixer_nid = 0x3f;
Lydia Wang43737e02012-12-10 18:28:11 +08001785 add_secret_dac_path(codec);
1786
1787 /* automatic parse from the BIOS config */
1788 err = via_parse_auto_config(codec);
1789 if (err < 0) {
1790 via_free(codec);
1791 return err;
1792 }
1793
1794 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1795
1796 codec->patch_ops = via_patch_ops;
1797
1798 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1799
1800 return 0;
1801}
1802
Joseph Chanc577b8a2006-11-29 15:29:40 +01001803/*
1804 * patch entries
1805 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001806static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01001807 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1808 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1809 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1810 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1811 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001812 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001813 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001814 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001815 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001816 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001817 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001818 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001819 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001820 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001821 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001822 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001823 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001824 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001825 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001826 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001827 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001828 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001829 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001830 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001831 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001832 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001833 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001834 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001835 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001836 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001837 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001838 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001839 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001840 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001841 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001842 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001843 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001844 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001845 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001846 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001847 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001848 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001849 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001850 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08001851 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08001852 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001853 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001854 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001855 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001856 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001857 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001858 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001859 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001860 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001861 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001862 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001863 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001864 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001865 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001866 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001867 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001868 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001869 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001870 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001871 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001872 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001873 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001874 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001875 { .id = 0x11060428, .name = "VT1718S",
1876 .patch = patch_vt1718S},
1877 { .id = 0x11064428, .name = "VT1718S",
1878 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08001879 { .id = 0x11060441, .name = "VT2020",
1880 .patch = patch_vt1718S},
1881 { .id = 0x11064441, .name = "VT1828S",
1882 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08001883 { .id = 0x11060433, .name = "VT1716S",
1884 .patch = patch_vt1716S},
1885 { .id = 0x1106a721, .name = "VT1716S",
1886 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08001887 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1888 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08001889 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08001890 { .id = 0x11060440, .name = "VT1818S",
1891 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08001892 { .id = 0x11060446, .name = "VT1802",
1893 .patch = patch_vt2002P},
1894 { .id = 0x11068446, .name = "VT1802",
1895 .patch = patch_vt2002P},
Lydia Wang43737e02012-12-10 18:28:11 +08001896 { .id = 0x11064760, .name = "VT1705CF",
1897 .patch = patch_vt3476},
Lydia Wang6121b842012-12-10 19:03:26 +08001898 { .id = 0x11064761, .name = "VT1708SCE",
1899 .patch = patch_vt3476},
1900 { .id = 0x11064762, .name = "VT1808",
1901 .patch = patch_vt3476},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001902 {} /* terminator */
1903};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001904
1905MODULE_ALIAS("snd-hda-codec-id:1106*");
1906
1907static struct hda_codec_preset_list via_list = {
1908 .preset = snd_hda_preset_via,
1909 .owner = THIS_MODULE,
1910};
1911
1912MODULE_LICENSE("GPL");
1913MODULE_DESCRIPTION("VIA HD-audio codec");
1914
1915static int __init patch_via_init(void)
1916{
1917 return snd_hda_add_codec_preset(&via_list);
1918}
1919
1920static void __exit patch_via_exit(void)
1921{
1922 snd_hda_delete_codec_preset(&via_list);
1923}
1924
1925module_init(patch_via_init)
1926module_exit(patch_via_exit)