xref: /linux/sound/pci/hda/patch_via.c (revision 93d90ad708b8da6efc0e487b66111aa9db7f70c7)
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5  *
6  *  (C) 2006-2009 VIA Technology, Inc.
7  *  (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8  *
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 * * * * * * * * * * * * * * * * */
25 /*									     */
26 /* 2006-03-03  Lydia Wang  Create the basic patch to support VT1708 codec    */
27 /* 2006-03-14  Lydia Wang  Modify hard code for some pin widget nid	     */
28 /* 2006-08-02  Lydia Wang  Add support to VT1709 codec			     */
29 /* 2006-09-08  Lydia Wang  Fix internal loopback recording source select bug */
30 /* 2007-09-12  Lydia Wang  Add EAPD enable during driver initialization	     */
31 /* 2007-09-17  Lydia Wang  Add VT1708B codec support			    */
32 /* 2007-11-14  Lydia Wang  Add VT1708A codec HP and CD pin connect config    */
33 /* 2008-02-03  Lydia Wang  Fix Rear channels and Back channels inverse issue */
34 /* 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			     */
37 /* 2008-05-28  Lydia Wang  Add second S/PDIF Out support for VT1702	     */
38 /* 2008-09-15  Logan Li	   Add VT1708S Mic Boost workaround/backdoor	     */
39 /* 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			     */
44 /* 2009-09-19  Lydia Wang  Add support for VT1818S			     */
45 /*									     */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47 
48 
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
53 #include <sound/core.h>
54 #include <sound/asoundef.h>
55 #include "hda_codec.h"
56 #include "hda_local.h"
57 #include "hda_auto_parser.h"
58 #include "hda_jack.h"
59 #include "hda_generic.h"
60 
61 /* Pin Widget NID */
62 #define VT1708_HP_PIN_NID	0x20
63 #define VT1708_CD_PIN_NID	0x24
64 
65 enum VIA_HDA_CODEC {
66 	UNKNOWN = -1,
67 	VT1708,
68 	VT1709_10CH,
69 	VT1709_6CH,
70 	VT1708B_8CH,
71 	VT1708B_4CH,
72 	VT1708S,
73 	VT1708BCE,
74 	VT1702,
75 	VT1718S,
76 	VT1716S,
77 	VT2002P,
78 	VT1812,
79 	VT1802,
80 	VT1705CF,
81 	VT1808,
82 	CODEC_TYPES,
83 };
84 
85 #define VT2002P_COMPATIBLE(spec) \
86 	((spec)->codec_type == VT2002P ||\
87 	 (spec)->codec_type == VT1812 ||\
88 	 (spec)->codec_type == VT1802)
89 
90 struct via_spec {
91 	struct hda_gen_spec gen;
92 
93 	/* codec parameterization */
94 	const struct snd_kcontrol_new *mixers[6];
95 	unsigned int num_mixers;
96 
97 	const struct hda_verb *init_verbs[5];
98 	unsigned int num_iverbs;
99 
100 	/* HP mode source */
101 	unsigned int dmic_enabled;
102 	unsigned int no_pin_power_ctl;
103 	enum VIA_HDA_CODEC codec_type;
104 
105 	/* analog low-power control */
106 	bool alc_mode;
107 
108 	/* work to check hp jack state */
109 	int hp_work_active;
110 	int vt1708_jack_detect;
111 
112 	void (*set_widgets_power_state)(struct hda_codec *codec);
113 	unsigned int dac_stream_tag[4];
114 };
115 
116 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
117 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
118 				  struct hda_codec *codec,
119 				  struct snd_pcm_substream *substream,
120 				  int action);
121 
122 static struct via_spec *via_new_spec(struct hda_codec *codec)
123 {
124 	struct via_spec *spec;
125 
126 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
127 	if (spec == NULL)
128 		return NULL;
129 
130 	codec->spec = spec;
131 	snd_hda_gen_spec_init(&spec->gen);
132 	spec->codec_type = get_codec_type(codec);
133 	/* VT1708BCE & VT1708S are almost same */
134 	if (spec->codec_type == VT1708BCE)
135 		spec->codec_type = VT1708S;
136 	spec->no_pin_power_ctl = 1;
137 	spec->gen.indep_hp = 1;
138 	spec->gen.keep_eapd_on = 1;
139 	spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140 	spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
141 	return spec;
142 }
143 
144 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
145 {
146 	u32 vendor_id = codec->vendor_id;
147 	u16 ven_id = vendor_id >> 16;
148 	u16 dev_id = vendor_id & 0xffff;
149 	enum VIA_HDA_CODEC codec_type;
150 
151 	/* get codec type */
152 	if (ven_id != 0x1106)
153 		codec_type = UNKNOWN;
154 	else if (dev_id >= 0x1708 && dev_id <= 0x170b)
155 		codec_type = VT1708;
156 	else if (dev_id >= 0xe710 && dev_id <= 0xe713)
157 		codec_type = VT1709_10CH;
158 	else if (dev_id >= 0xe714 && dev_id <= 0xe717)
159 		codec_type = VT1709_6CH;
160 	else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
161 		codec_type = VT1708B_8CH;
162 		if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
163 			codec_type = VT1708BCE;
164 	} else if (dev_id >= 0xe724 && dev_id <= 0xe727)
165 		codec_type = VT1708B_4CH;
166 	else if ((dev_id & 0xfff) == 0x397
167 		 && (dev_id >> 12) < 8)
168 		codec_type = VT1708S;
169 	else if ((dev_id & 0xfff) == 0x398
170 		 && (dev_id >> 12) < 8)
171 		codec_type = VT1702;
172 	else if ((dev_id & 0xfff) == 0x428
173 		 && (dev_id >> 12) < 8)
174 		codec_type = VT1718S;
175 	else if (dev_id == 0x0433 || dev_id == 0xa721)
176 		codec_type = VT1716S;
177 	else if (dev_id == 0x0441 || dev_id == 0x4441)
178 		codec_type = VT1718S;
179 	else if (dev_id == 0x0438 || dev_id == 0x4438)
180 		codec_type = VT2002P;
181 	else if (dev_id == 0x0448)
182 		codec_type = VT1812;
183 	else if (dev_id == 0x0440)
184 		codec_type = VT1708S;
185 	else if ((dev_id & 0xfff) == 0x446)
186 		codec_type = VT1802;
187 	else if (dev_id == 0x4760)
188 		codec_type = VT1705CF;
189 	else if (dev_id == 0x4761 || dev_id == 0x4762)
190 		codec_type = VT1808;
191 	else
192 		codec_type = UNKNOWN;
193 	return codec_type;
194 };
195 
196 static void analog_low_current_mode(struct hda_codec *codec);
197 static bool is_aa_path_mute(struct hda_codec *codec);
198 
199 #define hp_detect_with_aa(codec) \
200 	(snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
201 	 !is_aa_path_mute(codec))
202 
203 static void vt1708_stop_hp_work(struct hda_codec *codec)
204 {
205 	struct via_spec *spec = codec->spec;
206 	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
207 		return;
208 	if (spec->hp_work_active) {
209 		snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
210 		codec->jackpoll_interval = 0;
211 		cancel_delayed_work_sync(&codec->jackpoll_work);
212 		spec->hp_work_active = false;
213 	}
214 }
215 
216 static void vt1708_update_hp_work(struct hda_codec *codec)
217 {
218 	struct via_spec *spec = codec->spec;
219 	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
220 		return;
221 	if (spec->vt1708_jack_detect) {
222 		if (!spec->hp_work_active) {
223 			codec->jackpoll_interval = msecs_to_jiffies(100);
224 			snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225 			queue_delayed_work(codec->bus->workq,
226 					   &codec->jackpoll_work, 0);
227 			spec->hp_work_active = true;
228 		}
229 	} else if (!hp_detect_with_aa(codec))
230 		vt1708_stop_hp_work(codec);
231 }
232 
233 static void set_widgets_power_state(struct hda_codec *codec)
234 {
235 #if 0 /* FIXME: the assumed connections don't match always with the
236        * actual routes by the generic parser, so better to disable
237        * the control for safety.
238        */
239 	struct via_spec *spec = codec->spec;
240 	if (spec->set_widgets_power_state)
241 		spec->set_widgets_power_state(codec);
242 #endif
243 }
244 
245 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
246 			       unsigned int parm)
247 {
248 	if (snd_hda_check_power_state(codec, nid, parm))
249 		return;
250 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
251 }
252 
253 static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
254 			       unsigned int parm, unsigned int index)
255 {
256 	struct via_spec *spec = codec->spec;
257 	unsigned int format;
258 
259 	if (snd_hda_check_power_state(codec, nid, parm))
260 		return;
261 	format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 	if (format && (spec->dac_stream_tag[index] != format))
263 		spec->dac_stream_tag[index] = format;
264 
265 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
266 	if (parm == AC_PWRST_D0) {
267 		format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
268 		if (!format && (spec->dac_stream_tag[index] != format))
269 			snd_hda_codec_write(codec, nid, 0,
270 						  AC_VERB_SET_CHANNEL_STREAMID,
271 						  spec->dac_stream_tag[index]);
272 	}
273 }
274 
275 static bool smart51_enabled(struct hda_codec *codec)
276 {
277 	struct via_spec *spec = codec->spec;
278 	return spec->gen.ext_channel_count > 2;
279 }
280 
281 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
282 {
283 	struct via_spec *spec = codec->spec;
284 	int i;
285 
286 	for (i = 0; i < spec->gen.multi_ios; i++)
287 		if (spec->gen.multi_io[i].pin == pin)
288 			return true;
289 	return false;
290 }
291 
292 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
293 				unsigned int *affected_parm)
294 {
295 	unsigned parm;
296 	unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
297 	unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
298 		>> AC_DEFCFG_MISC_SHIFT
299 		& AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
300 	struct via_spec *spec = codec->spec;
301 	unsigned present = 0;
302 
303 	no_presence |= spec->no_pin_power_ctl;
304 	if (!no_presence)
305 		present = snd_hda_jack_detect(codec, nid);
306 	if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
307 	    || ((no_presence || present)
308 		&& get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
309 		*affected_parm = AC_PWRST_D0; /* if it's connected */
310 		parm = AC_PWRST_D0;
311 	} else
312 		parm = AC_PWRST_D3;
313 
314 	update_power_state(codec, nid, parm);
315 }
316 
317 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
318 				  struct snd_ctl_elem_info *uinfo)
319 {
320 	return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
321 }
322 
323 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
324 				 struct snd_ctl_elem_value *ucontrol)
325 {
326 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 	struct via_spec *spec = codec->spec;
328 	ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
329 	return 0;
330 }
331 
332 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
333 				 struct snd_ctl_elem_value *ucontrol)
334 {
335 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 	struct via_spec *spec = codec->spec;
337 	unsigned int val = !ucontrol->value.enumerated.item[0];
338 
339 	if (val == spec->no_pin_power_ctl)
340 		return 0;
341 	spec->no_pin_power_ctl = val;
342 	set_widgets_power_state(codec);
343 	analog_low_current_mode(codec);
344 	return 1;
345 }
346 
347 static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
348 	{
349 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
350 	.name = "Dynamic Power-Control",
351 	.info = via_pin_power_ctl_info,
352 	.get = via_pin_power_ctl_get,
353 	.put = via_pin_power_ctl_put,
354 	},
355 	{} /* terminator */
356 };
357 
358 
359 /* check AA path's mute status */
360 static bool is_aa_path_mute(struct hda_codec *codec)
361 {
362 	struct via_spec *spec = codec->spec;
363 	const struct hda_amp_list *p;
364 	int ch, v;
365 
366 	p = spec->gen.loopback.amplist;
367 	if (!p)
368 		return true;
369 	for (; p->nid; p++) {
370 		for (ch = 0; ch < 2; ch++) {
371 			v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
372 						   p->idx);
373 			if (!(v & HDA_AMP_MUTE) && v > 0)
374 				return false;
375 		}
376 	}
377 	return true;
378 }
379 
380 /* enter/exit analog low-current mode */
381 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
382 {
383 	struct via_spec *spec = codec->spec;
384 	bool enable;
385 	unsigned int verb, parm;
386 
387 	if (spec->no_pin_power_ctl)
388 		enable = false;
389 	else
390 		enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
391 	if (enable == spec->alc_mode && !force)
392 		return;
393 	spec->alc_mode = enable;
394 
395 	/* decide low current mode's verb & parameter */
396 	switch (spec->codec_type) {
397 	case VT1708B_8CH:
398 	case VT1708B_4CH:
399 		verb = 0xf70;
400 		parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
401 		break;
402 	case VT1708S:
403 	case VT1718S:
404 	case VT1716S:
405 		verb = 0xf73;
406 		parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
407 		break;
408 	case VT1702:
409 		verb = 0xf73;
410 		parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
411 		break;
412 	case VT2002P:
413 	case VT1812:
414 	case VT1802:
415 		verb = 0xf93;
416 		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
417 		break;
418 	case VT1705CF:
419 	case VT1808:
420 		verb = 0xf82;
421 		parm = enable ? 0x00 : 0xe0;  /* 0x00: 4/40x, 0xe0: 1x */
422 		break;
423 	default:
424 		return;		/* other codecs are not supported */
425 	}
426 	/* send verb */
427 	snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
428 }
429 
430 static void analog_low_current_mode(struct hda_codec *codec)
431 {
432 	return __analog_low_current_mode(codec, false);
433 }
434 
435 static int via_build_controls(struct hda_codec *codec)
436 {
437 	struct via_spec *spec = codec->spec;
438 	int err, i;
439 
440 	err = snd_hda_gen_build_controls(codec);
441 	if (err < 0)
442 		return err;
443 
444 	if (spec->set_widgets_power_state)
445 		spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
446 
447 	for (i = 0; i < spec->num_mixers; i++) {
448 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
449 		if (err < 0)
450 			return err;
451 	}
452 
453 	return 0;
454 }
455 
456 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
457 				  struct hda_codec *codec,
458 				  struct snd_pcm_substream *substream,
459 				  int action)
460 {
461 	analog_low_current_mode(codec);
462 	vt1708_update_hp_work(codec);
463 }
464 
465 static void via_free(struct hda_codec *codec)
466 {
467 	vt1708_stop_hp_work(codec);
468 	snd_hda_gen_free(codec);
469 }
470 
471 #ifdef CONFIG_PM
472 static int via_suspend(struct hda_codec *codec)
473 {
474 	struct via_spec *spec = codec->spec;
475 	vt1708_stop_hp_work(codec);
476 
477 	/* Fix pop noise on headphones */
478 	if (spec->codec_type == VT1802)
479 		snd_hda_shutup_pins(codec);
480 
481 	return 0;
482 }
483 #endif
484 
485 #ifdef CONFIG_PM
486 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
487 {
488 	struct via_spec *spec = codec->spec;
489 	set_widgets_power_state(codec);
490 	analog_low_current_mode(codec);
491 	vt1708_update_hp_work(codec);
492 	return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
493 }
494 #endif
495 
496 /*
497  */
498 
499 static int via_init(struct hda_codec *codec);
500 
501 static const struct hda_codec_ops via_patch_ops = {
502 	.build_controls = via_build_controls,
503 	.build_pcms = snd_hda_gen_build_pcms,
504 	.init = via_init,
505 	.free = via_free,
506 	.unsol_event = snd_hda_jack_unsol_event,
507 #ifdef CONFIG_PM
508 	.suspend = via_suspend,
509 	.check_power_status = via_check_power_status,
510 #endif
511 };
512 
513 
514 static const struct hda_verb vt1708_init_verbs[] = {
515 	/* power down jack detect function */
516 	{0x1, 0xf81, 0x1},
517 	{ }
518 };
519 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
520 {
521 	unsigned int def_conf;
522 	unsigned char seqassoc;
523 
524 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
525 	seqassoc = (unsigned char) get_defcfg_association(def_conf);
526 	seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
527 	if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
528 	    && (seqassoc == 0xf0 || seqassoc == 0xff)) {
529 		def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
530 		snd_hda_codec_set_pincfg(codec, nid, def_conf);
531 	}
532 
533 	return;
534 }
535 
536 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
537 				     struct snd_ctl_elem_value *ucontrol)
538 {
539 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
540 	struct via_spec *spec = codec->spec;
541 
542 	if (spec->codec_type != VT1708)
543 		return 0;
544 	ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
545 	return 0;
546 }
547 
548 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
549 				     struct snd_ctl_elem_value *ucontrol)
550 {
551 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
552 	struct via_spec *spec = codec->spec;
553 	int val;
554 
555 	if (spec->codec_type != VT1708)
556 		return 0;
557 	val = !!ucontrol->value.integer.value[0];
558 	if (spec->vt1708_jack_detect == val)
559 		return 0;
560 	spec->vt1708_jack_detect = val;
561 	vt1708_update_hp_work(codec);
562 	return 1;
563 }
564 
565 static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
566 	{
567 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
568 	.name = "Jack Detect",
569 	.count = 1,
570 	.info = snd_ctl_boolean_mono_info,
571 	.get = vt1708_jack_detect_get,
572 	.put = vt1708_jack_detect_put,
573 	},
574 	{} /* terminator */
575 };
576 
577 static void via_jack_powerstate_event(struct hda_codec *codec,
578 				      struct hda_jack_callback *tbl)
579 {
580 	set_widgets_power_state(codec);
581 }
582 
583 static void via_set_jack_unsol_events(struct hda_codec *codec)
584 {
585 	struct via_spec *spec = codec->spec;
586 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
587 	hda_nid_t pin;
588 	int i;
589 
590 	for (i = 0; i < cfg->line_outs; i++) {
591 		pin = cfg->line_out_pins[i];
592 		if (pin && is_jack_detectable(codec, pin))
593 			snd_hda_jack_detect_enable_callback(codec, pin,
594 							    via_jack_powerstate_event);
595 	}
596 
597 	for (i = 0; i < cfg->num_inputs; i++) {
598 		pin = cfg->line_out_pins[i];
599 		if (pin && is_jack_detectable(codec, pin))
600 			snd_hda_jack_detect_enable_callback(codec, pin,
601 							    via_jack_powerstate_event);
602 	}
603 }
604 
605 static const struct badness_table via_main_out_badness = {
606 	.no_primary_dac = 0x10000,
607 	.no_dac = 0x4000,
608 	.shared_primary = 0x10000,
609 	.shared_surr = 0x20,
610 	.shared_clfe = 0x20,
611 	.shared_surr_main = 0x20,
612 };
613 static const struct badness_table via_extra_out_badness = {
614 	.no_primary_dac = 0x4000,
615 	.no_dac = 0x4000,
616 	.shared_primary = 0x12,
617 	.shared_surr = 0x20,
618 	.shared_clfe = 0x20,
619 	.shared_surr_main = 0x10,
620 };
621 
622 static int via_parse_auto_config(struct hda_codec *codec)
623 {
624 	struct via_spec *spec = codec->spec;
625 	int err;
626 
627 	spec->gen.main_out_badness = &via_main_out_badness;
628 	spec->gen.extra_out_badness = &via_extra_out_badness;
629 
630 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
631 	if (err < 0)
632 		return err;
633 
634 	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
635 	if (err < 0)
636 		return err;
637 
638 	via_set_jack_unsol_events(codec);
639 	return 0;
640 }
641 
642 static int via_init(struct hda_codec *codec)
643 {
644 	struct via_spec *spec = codec->spec;
645 	int i;
646 
647 	for (i = 0; i < spec->num_iverbs; i++)
648 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
649 
650 	/* init power states */
651 	set_widgets_power_state(codec);
652 	__analog_low_current_mode(codec, true);
653 
654 	snd_hda_gen_init(codec);
655 
656 	vt1708_update_hp_work(codec);
657 
658 	return 0;
659 }
660 
661 static int vt1708_build_controls(struct hda_codec *codec)
662 {
663 	/* In order not to create "Phantom Jack" controls,
664 	   temporary enable jackpoll */
665 	int err;
666 	int old_interval = codec->jackpoll_interval;
667 	codec->jackpoll_interval = msecs_to_jiffies(100);
668 	err = via_build_controls(codec);
669 	codec->jackpoll_interval = old_interval;
670 	return err;
671 }
672 
673 static int vt1708_build_pcms(struct hda_codec *codec)
674 {
675 	struct via_spec *spec = codec->spec;
676 	int i, err;
677 
678 	err = snd_hda_gen_build_pcms(codec);
679 	if (err < 0 || codec->vendor_id != 0x11061708)
680 		return err;
681 
682 	/* We got noisy outputs on the right channel on VT1708 when
683 	 * 24bit samples are used.  Until any workaround is found,
684 	 * disable the 24bit format, so far.
685 	 */
686 	for (i = 0; i < codec->num_pcms; i++) {
687 		struct hda_pcm *info = &spec->gen.pcm_rec[i];
688 		if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
689 		    info->pcm_type != HDA_PCM_TYPE_AUDIO)
690 			continue;
691 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
692 			SNDRV_PCM_FMTBIT_S16_LE;
693 	}
694 
695 	return 0;
696 }
697 
698 static int patch_vt1708(struct hda_codec *codec)
699 {
700 	struct via_spec *spec;
701 	int err;
702 
703 	/* create a codec specific record */
704 	spec = via_new_spec(codec);
705 	if (spec == NULL)
706 		return -ENOMEM;
707 
708 	spec->gen.mixer_nid = 0x17;
709 
710 	/* set jackpoll_interval while parsing the codec */
711 	codec->jackpoll_interval = msecs_to_jiffies(100);
712 	spec->vt1708_jack_detect = 1;
713 
714 	/* don't support the input jack switching due to lack of unsol event */
715 	/* (it may work with polling, though, but it needs testing) */
716 	spec->gen.suppress_auto_mic = 1;
717 	/* Some machines show the broken speaker mute */
718 	spec->gen.auto_mute_via_amp = 1;
719 
720 	/* Add HP and CD pin config connect bit re-config action */
721 	vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
722 	vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
723 
724 	/* automatic parse from the BIOS config */
725 	err = via_parse_auto_config(codec);
726 	if (err < 0) {
727 		via_free(codec);
728 		return err;
729 	}
730 
731 	/* add jack detect on/off control */
732 	spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
733 
734 	spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
735 
736 	codec->patch_ops = via_patch_ops;
737 	codec->patch_ops.build_controls = vt1708_build_controls;
738 	codec->patch_ops.build_pcms = vt1708_build_pcms;
739 
740 	/* clear jackpoll_interval again; it's set dynamically */
741 	codec->jackpoll_interval = 0;
742 
743 	return 0;
744 }
745 
746 static int patch_vt1709(struct hda_codec *codec)
747 {
748 	struct via_spec *spec;
749 	int err;
750 
751 	/* create a codec specific record */
752 	spec = via_new_spec(codec);
753 	if (spec == NULL)
754 		return -ENOMEM;
755 
756 	spec->gen.mixer_nid = 0x18;
757 
758 	err = via_parse_auto_config(codec);
759 	if (err < 0) {
760 		via_free(codec);
761 		return err;
762 	}
763 
764 	codec->patch_ops = via_patch_ops;
765 
766 	return 0;
767 }
768 
769 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
770 {
771 	struct via_spec *spec = codec->spec;
772 	int imux_is_smixer;
773 	unsigned int parm;
774 	int is_8ch = 0;
775 	if ((spec->codec_type != VT1708B_4CH) &&
776 	    (codec->vendor_id != 0x11064397))
777 		is_8ch = 1;
778 
779 	/* SW0 (17h) = stereo mixer */
780 	imux_is_smixer =
781 	(snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
782 	 == ((spec->codec_type == VT1708S) ? 5 : 0));
783 	/* inputs */
784 	/* PW 1/2/5 (1ah/1bh/1eh) */
785 	parm = AC_PWRST_D3;
786 	set_pin_power_state(codec, 0x1a, &parm);
787 	set_pin_power_state(codec, 0x1b, &parm);
788 	set_pin_power_state(codec, 0x1e, &parm);
789 	if (imux_is_smixer)
790 		parm = AC_PWRST_D0;
791 	/* SW0 (17h), AIW 0/1 (13h/14h) */
792 	update_power_state(codec, 0x17, parm);
793 	update_power_state(codec, 0x13, parm);
794 	update_power_state(codec, 0x14, parm);
795 
796 	/* outputs */
797 	/* PW0 (19h), SW1 (18h), AOW1 (11h) */
798 	parm = AC_PWRST_D3;
799 	set_pin_power_state(codec, 0x19, &parm);
800 	if (smart51_enabled(codec))
801 		set_pin_power_state(codec, 0x1b, &parm);
802 	update_power_state(codec, 0x18, parm);
803 	update_power_state(codec, 0x11, parm);
804 
805 	/* PW6 (22h), SW2 (26h), AOW2 (24h) */
806 	if (is_8ch) {
807 		parm = AC_PWRST_D3;
808 		set_pin_power_state(codec, 0x22, &parm);
809 		if (smart51_enabled(codec))
810 			set_pin_power_state(codec, 0x1a, &parm);
811 		update_power_state(codec, 0x26, parm);
812 		update_power_state(codec, 0x24, parm);
813 	} else if (codec->vendor_id == 0x11064397) {
814 		/* PW7(23h), SW2(27h), AOW2(25h) */
815 		parm = AC_PWRST_D3;
816 		set_pin_power_state(codec, 0x23, &parm);
817 		if (smart51_enabled(codec))
818 			set_pin_power_state(codec, 0x1a, &parm);
819 		update_power_state(codec, 0x27, parm);
820 		update_power_state(codec, 0x25, parm);
821 	}
822 
823 	/* PW 3/4/7 (1ch/1dh/23h) */
824 	parm = AC_PWRST_D3;
825 	/* force to D0 for internal Speaker */
826 	set_pin_power_state(codec, 0x1c, &parm);
827 	set_pin_power_state(codec, 0x1d, &parm);
828 	if (is_8ch)
829 		set_pin_power_state(codec, 0x23, &parm);
830 
831 	/* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
832 	update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
833 	update_power_state(codec, 0x10, parm);
834 	if (is_8ch) {
835 		update_power_state(codec, 0x25, parm);
836 		update_power_state(codec, 0x27, parm);
837 	} else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
838 		update_power_state(codec, 0x25, parm);
839 }
840 
841 static int patch_vt1708S(struct hda_codec *codec);
842 static int patch_vt1708B(struct hda_codec *codec)
843 {
844 	struct via_spec *spec;
845 	int err;
846 
847 	if (get_codec_type(codec) == VT1708BCE)
848 		return patch_vt1708S(codec);
849 
850 	/* create a codec specific record */
851 	spec = via_new_spec(codec);
852 	if (spec == NULL)
853 		return -ENOMEM;
854 
855 	spec->gen.mixer_nid = 0x16;
856 
857 	/* automatic parse from the BIOS config */
858 	err = via_parse_auto_config(codec);
859 	if (err < 0) {
860 		via_free(codec);
861 		return err;
862 	}
863 
864 	codec->patch_ops = via_patch_ops;
865 
866 	spec->set_widgets_power_state =  set_widgets_power_state_vt1708B;
867 
868 	return 0;
869 }
870 
871 /* Patch for VT1708S */
872 static const struct hda_verb vt1708S_init_verbs[] = {
873 	/* Enable Mic Boost Volume backdoor */
874 	{0x1, 0xf98, 0x1},
875 	/* don't bybass mixer */
876 	{0x1, 0xf88, 0xc0},
877 	{ }
878 };
879 
880 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
881 			       int offset, int num_steps, int step_size)
882 {
883 	snd_hda_override_wcaps(codec, pin,
884 			       get_wcaps(codec, pin) | AC_WCAP_IN_AMP);
885 	snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
886 				  (offset << AC_AMPCAP_OFFSET_SHIFT) |
887 				  (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
888 				  (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
889 				  (0 << AC_AMPCAP_MUTE_SHIFT));
890 }
891 
892 static int patch_vt1708S(struct hda_codec *codec)
893 {
894 	struct via_spec *spec;
895 	int err;
896 
897 	/* create a codec specific record */
898 	spec = via_new_spec(codec);
899 	if (spec == NULL)
900 		return -ENOMEM;
901 
902 	spec->gen.mixer_nid = 0x16;
903 	override_mic_boost(codec, 0x1a, 0, 3, 40);
904 	override_mic_boost(codec, 0x1e, 0, 3, 40);
905 
906 	/* correct names for VT1708BCE */
907 	if (get_codec_type(codec) == VT1708BCE)	{
908 		kfree(codec->chip_name);
909 		codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
910 		snprintf(codec->bus->card->mixername,
911 			 sizeof(codec->bus->card->mixername),
912 			 "%s %s", codec->vendor_name, codec->chip_name);
913 	}
914 	/* correct names for VT1705 */
915 	if (codec->vendor_id == 0x11064397)	{
916 		kfree(codec->chip_name);
917 		codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
918 		snprintf(codec->bus->card->mixername,
919 			 sizeof(codec->bus->card->mixername),
920 			 "%s %s", codec->vendor_name, codec->chip_name);
921 	}
922 
923 	/* automatic parse from the BIOS config */
924 	err = via_parse_auto_config(codec);
925 	if (err < 0) {
926 		via_free(codec);
927 		return err;
928 	}
929 
930 	spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931 
932 	codec->patch_ops = via_patch_ops;
933 
934 	spec->set_widgets_power_state =  set_widgets_power_state_vt1708B;
935 	return 0;
936 }
937 
938 /* Patch for VT1702 */
939 
940 static const struct hda_verb vt1702_init_verbs[] = {
941 	/* mixer enable */
942 	{0x1, 0xF88, 0x3},
943 	/* GPIO 0~2 */
944 	{0x1, 0xF82, 0x3F},
945 	{ }
946 };
947 
948 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
949 {
950 	int imux_is_smixer =
951 	snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
952 	unsigned int parm;
953 	/* inputs */
954 	/* PW 1/2/5 (14h/15h/18h) */
955 	parm = AC_PWRST_D3;
956 	set_pin_power_state(codec, 0x14, &parm);
957 	set_pin_power_state(codec, 0x15, &parm);
958 	set_pin_power_state(codec, 0x18, &parm);
959 	if (imux_is_smixer)
960 		parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
961 	/* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
962 	update_power_state(codec, 0x13, parm);
963 	update_power_state(codec, 0x12, parm);
964 	update_power_state(codec, 0x1f, parm);
965 	update_power_state(codec, 0x20, parm);
966 
967 	/* outputs */
968 	/* PW 3/4 (16h/17h) */
969 	parm = AC_PWRST_D3;
970 	set_pin_power_state(codec, 0x17, &parm);
971 	set_pin_power_state(codec, 0x16, &parm);
972 	/* MW0 (1ah), AOW 0/1 (10h/1dh) */
973 	update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
974 	update_power_state(codec, 0x10, parm);
975 	update_power_state(codec, 0x1d, parm);
976 }
977 
978 static int patch_vt1702(struct hda_codec *codec)
979 {
980 	struct via_spec *spec;
981 	int err;
982 
983 	/* create a codec specific record */
984 	spec = via_new_spec(codec);
985 	if (spec == NULL)
986 		return -ENOMEM;
987 
988 	spec->gen.mixer_nid = 0x1a;
989 
990 	/* limit AA path volume to 0 dB */
991 	snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
992 				  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
993 				  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
994 				  (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
995 				  (1 << AC_AMPCAP_MUTE_SHIFT));
996 
997 	/* automatic parse from the BIOS config */
998 	err = via_parse_auto_config(codec);
999 	if (err < 0) {
1000 		via_free(codec);
1001 		return err;
1002 	}
1003 
1004 	spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1005 
1006 	codec->patch_ops = via_patch_ops;
1007 
1008 	spec->set_widgets_power_state =  set_widgets_power_state_vt1702;
1009 	return 0;
1010 }
1011 
1012 /* Patch for VT1718S */
1013 
1014 static const struct hda_verb vt1718S_init_verbs[] = {
1015 	/* Enable MW0 adjust Gain 5 */
1016 	{0x1, 0xfb2, 0x10},
1017 	/* Enable Boost Volume backdoor */
1018 	{0x1, 0xf88, 0x8},
1019 
1020 	{ }
1021 };
1022 
1023 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1024 {
1025 	struct via_spec *spec = codec->spec;
1026 	int imux_is_smixer;
1027 	unsigned int parm, parm2;
1028 	/* MUX6 (1eh) = stereo mixer */
1029 	imux_is_smixer =
1030 	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1031 	/* inputs */
1032 	/* PW 5/6/7 (29h/2ah/2bh) */
1033 	parm = AC_PWRST_D3;
1034 	set_pin_power_state(codec, 0x29, &parm);
1035 	set_pin_power_state(codec, 0x2a, &parm);
1036 	set_pin_power_state(codec, 0x2b, &parm);
1037 	if (imux_is_smixer)
1038 		parm = AC_PWRST_D0;
1039 	/* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1040 	update_power_state(codec, 0x1e, parm);
1041 	update_power_state(codec, 0x1f, parm);
1042 	update_power_state(codec, 0x10, parm);
1043 	update_power_state(codec, 0x11, parm);
1044 
1045 	/* outputs */
1046 	/* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1047 	parm = AC_PWRST_D3;
1048 	set_pin_power_state(codec, 0x27, &parm);
1049 	update_power_state(codec, 0x1a, parm);
1050 	parm2 = parm; /* for pin 0x0b */
1051 
1052 	/* PW2 (26h), AOW2 (ah) */
1053 	parm = AC_PWRST_D3;
1054 	set_pin_power_state(codec, 0x26, &parm);
1055 	if (smart51_enabled(codec))
1056 		set_pin_power_state(codec, 0x2b, &parm);
1057 	update_power_state(codec, 0xa, parm);
1058 
1059 	/* PW0 (24h), AOW0 (8h) */
1060 	parm = AC_PWRST_D3;
1061 	set_pin_power_state(codec, 0x24, &parm);
1062 	if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1063 		set_pin_power_state(codec, 0x28, &parm);
1064 	update_power_state(codec, 0x8, parm);
1065 	if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1066 		parm = parm2;
1067 	update_power_state(codec, 0xb, parm);
1068 	/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1069 	update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1070 
1071 	/* PW1 (25h), AOW1 (9h) */
1072 	parm = AC_PWRST_D3;
1073 	set_pin_power_state(codec, 0x25, &parm);
1074 	if (smart51_enabled(codec))
1075 		set_pin_power_state(codec, 0x2a, &parm);
1076 	update_power_state(codec, 0x9, parm);
1077 
1078 	if (spec->gen.indep_hp_enabled) {
1079 		/* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1080 		parm = AC_PWRST_D3;
1081 		set_pin_power_state(codec, 0x28, &parm);
1082 		update_power_state(codec, 0x1b, parm);
1083 		update_power_state(codec, 0x34, parm);
1084 		update_power_state(codec, 0xc, parm);
1085 	}
1086 }
1087 
1088 /* Add a connection to the primary DAC from AA-mixer for some codecs
1089  * This isn't listed from the raw info, but the chip has a secret connection.
1090  */
1091 static int add_secret_dac_path(struct hda_codec *codec)
1092 {
1093 	struct via_spec *spec = codec->spec;
1094 	int i, nums;
1095 	hda_nid_t conn[8];
1096 	hda_nid_t nid;
1097 
1098 	if (!spec->gen.mixer_nid)
1099 		return 0;
1100 	nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
1101 				       ARRAY_SIZE(conn) - 1);
1102 	for (i = 0; i < nums; i++) {
1103 		if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1104 			return 0;
1105 	}
1106 
1107 	/* find the primary DAC and add to the connection list */
1108 	nid = codec->start_nid;
1109 	for (i = 0; i < codec->num_nodes; i++, nid++) {
1110 		unsigned int caps = get_wcaps(codec, nid);
1111 		if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1112 		    !(caps & AC_WCAP_DIGITAL)) {
1113 			conn[nums++] = nid;
1114 			return snd_hda_override_conn_list(codec,
1115 							  spec->gen.mixer_nid,
1116 							  nums, conn);
1117 		}
1118 	}
1119 	return 0;
1120 }
1121 
1122 
1123 static int patch_vt1718S(struct hda_codec *codec)
1124 {
1125 	struct via_spec *spec;
1126 	int err;
1127 
1128 	/* create a codec specific record */
1129 	spec = via_new_spec(codec);
1130 	if (spec == NULL)
1131 		return -ENOMEM;
1132 
1133 	spec->gen.mixer_nid = 0x21;
1134 	override_mic_boost(codec, 0x2b, 0, 3, 40);
1135 	override_mic_boost(codec, 0x29, 0, 3, 40);
1136 	add_secret_dac_path(codec);
1137 
1138 	/* automatic parse from the BIOS config */
1139 	err = via_parse_auto_config(codec);
1140 	if (err < 0) {
1141 		via_free(codec);
1142 		return err;
1143 	}
1144 
1145 	spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1146 
1147 	codec->patch_ops = via_patch_ops;
1148 
1149 	spec->set_widgets_power_state =  set_widgets_power_state_vt1718S;
1150 
1151 	return 0;
1152 }
1153 
1154 /* Patch for VT1716S */
1155 
1156 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1157 			    struct snd_ctl_elem_info *uinfo)
1158 {
1159 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1160 	uinfo->count = 1;
1161 	uinfo->value.integer.min = 0;
1162 	uinfo->value.integer.max = 1;
1163 	return 0;
1164 }
1165 
1166 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1167 			   struct snd_ctl_elem_value *ucontrol)
1168 {
1169 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1170 	int index = 0;
1171 
1172 	index = snd_hda_codec_read(codec, 0x26, 0,
1173 					       AC_VERB_GET_CONNECT_SEL, 0);
1174 	if (index != -1)
1175 		*ucontrol->value.integer.value = index;
1176 
1177 	return 0;
1178 }
1179 
1180 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1181 			   struct snd_ctl_elem_value *ucontrol)
1182 {
1183 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1184 	struct via_spec *spec = codec->spec;
1185 	int index = *ucontrol->value.integer.value;
1186 
1187 	snd_hda_codec_write(codec, 0x26, 0,
1188 					       AC_VERB_SET_CONNECT_SEL, index);
1189 	spec->dmic_enabled = index;
1190 	set_widgets_power_state(codec);
1191 	return 1;
1192 }
1193 
1194 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
1195 	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1196 	{
1197 	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1198 	 .name = "Digital Mic Capture Switch",
1199 	 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
1200 	 .count = 1,
1201 	 .info = vt1716s_dmic_info,
1202 	 .get = vt1716s_dmic_get,
1203 	 .put = vt1716s_dmic_put,
1204 	 },
1205 	{}			/* end */
1206 };
1207 
1208 
1209 /* mono-out mixer elements */
1210 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
1211 	HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1212 	{ } /* end */
1213 };
1214 
1215 static const struct hda_verb vt1716S_init_verbs[] = {
1216 	/* Enable Boost Volume backdoor */
1217 	{0x1, 0xf8a, 0x80},
1218 	/* don't bybass mixer */
1219 	{0x1, 0xf88, 0xc0},
1220 	/* Enable mono output */
1221 	{0x1, 0xf90, 0x08},
1222 	{ }
1223 };
1224 
1225 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1226 {
1227 	struct via_spec *spec = codec->spec;
1228 	int imux_is_smixer;
1229 	unsigned int parm;
1230 	unsigned int mono_out, present;
1231 	/* SW0 (17h) = stereo mixer */
1232 	imux_is_smixer =
1233 	(snd_hda_codec_read(codec, 0x17, 0,
1234 			    AC_VERB_GET_CONNECT_SEL, 0x00) ==  5);
1235 	/* inputs */
1236 	/* PW 1/2/5 (1ah/1bh/1eh) */
1237 	parm = AC_PWRST_D3;
1238 	set_pin_power_state(codec, 0x1a, &parm);
1239 	set_pin_power_state(codec, 0x1b, &parm);
1240 	set_pin_power_state(codec, 0x1e, &parm);
1241 	if (imux_is_smixer)
1242 		parm = AC_PWRST_D0;
1243 	/* SW0 (17h), AIW0(13h) */
1244 	update_power_state(codec, 0x17, parm);
1245 	update_power_state(codec, 0x13, parm);
1246 
1247 	parm = AC_PWRST_D3;
1248 	set_pin_power_state(codec, 0x1e, &parm);
1249 	/* PW11 (22h) */
1250 	if (spec->dmic_enabled)
1251 		set_pin_power_state(codec, 0x22, &parm);
1252 	else
1253 		update_power_state(codec, 0x22, AC_PWRST_D3);
1254 
1255 	/* SW2(26h), AIW1(14h) */
1256 	update_power_state(codec, 0x26, parm);
1257 	update_power_state(codec, 0x14, parm);
1258 
1259 	/* outputs */
1260 	/* PW0 (19h), SW1 (18h), AOW1 (11h) */
1261 	parm = AC_PWRST_D3;
1262 	set_pin_power_state(codec, 0x19, &parm);
1263 	/* Smart 5.1 PW2(1bh) */
1264 	if (smart51_enabled(codec))
1265 		set_pin_power_state(codec, 0x1b, &parm);
1266 	update_power_state(codec, 0x18, parm);
1267 	update_power_state(codec, 0x11, parm);
1268 
1269 	/* PW7 (23h), SW3 (27h), AOW3 (25h) */
1270 	parm = AC_PWRST_D3;
1271 	set_pin_power_state(codec, 0x23, &parm);
1272 	/* Smart 5.1 PW1(1ah) */
1273 	if (smart51_enabled(codec))
1274 		set_pin_power_state(codec, 0x1a, &parm);
1275 	update_power_state(codec, 0x27, parm);
1276 
1277 	/* Smart 5.1 PW5(1eh) */
1278 	if (smart51_enabled(codec))
1279 		set_pin_power_state(codec, 0x1e, &parm);
1280 	update_power_state(codec, 0x25, parm);
1281 
1282 	/* Mono out */
1283 	/* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1284 	present = snd_hda_jack_detect(codec, 0x1c);
1285 
1286 	if (present)
1287 		mono_out = 0;
1288 	else {
1289 		present = snd_hda_jack_detect(codec, 0x1d);
1290 		if (!spec->gen.indep_hp_enabled && present)
1291 			mono_out = 0;
1292 		else
1293 			mono_out = 1;
1294 	}
1295 	parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1296 	update_power_state(codec, 0x28, parm);
1297 	update_power_state(codec, 0x29, parm);
1298 	update_power_state(codec, 0x2a, parm);
1299 
1300 	/* PW 3/4 (1ch/1dh) */
1301 	parm = AC_PWRST_D3;
1302 	set_pin_power_state(codec, 0x1c, &parm);
1303 	set_pin_power_state(codec, 0x1d, &parm);
1304 	/* HP Independent Mode, power on AOW3 */
1305 	if (spec->gen.indep_hp_enabled)
1306 		update_power_state(codec, 0x25, parm);
1307 
1308 	/* force to D0 for internal Speaker */
1309 	/* MW0 (16h), AOW0 (10h) */
1310 	update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1311 	update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1312 }
1313 
1314 static int patch_vt1716S(struct hda_codec *codec)
1315 {
1316 	struct via_spec *spec;
1317 	int err;
1318 
1319 	/* create a codec specific record */
1320 	spec = via_new_spec(codec);
1321 	if (spec == NULL)
1322 		return -ENOMEM;
1323 
1324 	spec->gen.mixer_nid = 0x16;
1325 	override_mic_boost(codec, 0x1a, 0, 3, 40);
1326 	override_mic_boost(codec, 0x1e, 0, 3, 40);
1327 
1328 	/* automatic parse from the BIOS config */
1329 	err = via_parse_auto_config(codec);
1330 	if (err < 0) {
1331 		via_free(codec);
1332 		return err;
1333 	}
1334 
1335 	spec->init_verbs[spec->num_iverbs++]  = vt1716S_init_verbs;
1336 
1337 	spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
1338 	spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1339 
1340 	codec->patch_ops = via_patch_ops;
1341 
1342 	spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1343 	return 0;
1344 }
1345 
1346 /* for vt2002P */
1347 
1348 static const struct hda_verb vt2002P_init_verbs[] = {
1349 	/* Class-D speaker related verbs */
1350 	{0x1, 0xfe0, 0x4},
1351 	{0x1, 0xfe9, 0x80},
1352 	{0x1, 0xfe2, 0x22},
1353 	/* Enable Boost Volume backdoor */
1354 	{0x1, 0xfb9, 0x24},
1355 	/* Enable AOW0 to MW9 */
1356 	{0x1, 0xfb8, 0x88},
1357 	{ }
1358 };
1359 
1360 static const struct hda_verb vt1802_init_verbs[] = {
1361 	/* Enable Boost Volume backdoor */
1362 	{0x1, 0xfb9, 0x24},
1363 	/* Enable AOW0 to MW9 */
1364 	{0x1, 0xfb8, 0x88},
1365 	{ }
1366 };
1367 
1368 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1369 {
1370 	struct via_spec *spec = codec->spec;
1371 	int imux_is_smixer;
1372 	unsigned int parm;
1373 	unsigned int present;
1374 	/* MUX9 (1eh) = stereo mixer */
1375 	imux_is_smixer =
1376 	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1377 	/* inputs */
1378 	/* PW 5/6/7 (29h/2ah/2bh) */
1379 	parm = AC_PWRST_D3;
1380 	set_pin_power_state(codec, 0x29, &parm);
1381 	set_pin_power_state(codec, 0x2a, &parm);
1382 	set_pin_power_state(codec, 0x2b, &parm);
1383 	parm = AC_PWRST_D0;
1384 	/* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1385 	update_power_state(codec, 0x1e, parm);
1386 	update_power_state(codec, 0x1f, parm);
1387 	update_power_state(codec, 0x10, parm);
1388 	update_power_state(codec, 0x11, parm);
1389 
1390 	/* outputs */
1391 	/* AOW0 (8h)*/
1392 	update_power_state(codec, 0x8, parm);
1393 
1394 	if (spec->codec_type == VT1802) {
1395 		/* PW4 (28h), MW4 (18h), MUX4(38h) */
1396 		parm = AC_PWRST_D3;
1397 		set_pin_power_state(codec, 0x28, &parm);
1398 		update_power_state(codec, 0x18, parm);
1399 		update_power_state(codec, 0x38, parm);
1400 	} else {
1401 		/* PW4 (26h), MW4 (1ch), MUX4(37h) */
1402 		parm = AC_PWRST_D3;
1403 		set_pin_power_state(codec, 0x26, &parm);
1404 		update_power_state(codec, 0x1c, parm);
1405 		update_power_state(codec, 0x37, parm);
1406 	}
1407 
1408 	if (spec->codec_type == VT1802) {
1409 		/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1410 		parm = AC_PWRST_D3;
1411 		set_pin_power_state(codec, 0x25, &parm);
1412 		update_power_state(codec, 0x15, parm);
1413 		update_power_state(codec, 0x35, parm);
1414 	} else {
1415 		/* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1416 		parm = AC_PWRST_D3;
1417 		set_pin_power_state(codec, 0x25, &parm);
1418 		update_power_state(codec, 0x19, parm);
1419 		update_power_state(codec, 0x35, parm);
1420 	}
1421 
1422 	if (spec->gen.indep_hp_enabled)
1423 		update_power_state(codec, 0x9, AC_PWRST_D0);
1424 
1425 	/* Class-D */
1426 	/* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1427 	present = snd_hda_jack_detect(codec, 0x25);
1428 
1429 	parm = AC_PWRST_D3;
1430 	set_pin_power_state(codec, 0x24, &parm);
1431 	parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1432 	if (spec->codec_type == VT1802)
1433 		update_power_state(codec, 0x14, parm);
1434 	else
1435 		update_power_state(codec, 0x18, parm);
1436 	update_power_state(codec, 0x34, parm);
1437 
1438 	/* Mono Out */
1439 	present = snd_hda_jack_detect(codec, 0x26);
1440 
1441 	parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1442 	if (spec->codec_type == VT1802) {
1443 		/* PW15 (33h), MW8(1ch), MUX8(3ch) */
1444 		update_power_state(codec, 0x33, parm);
1445 		update_power_state(codec, 0x1c, parm);
1446 		update_power_state(codec, 0x3c, parm);
1447 	} else {
1448 		/* PW15 (31h), MW8(17h), MUX8(3bh) */
1449 		update_power_state(codec, 0x31, parm);
1450 		update_power_state(codec, 0x17, parm);
1451 		update_power_state(codec, 0x3b, parm);
1452 	}
1453 	/* MW9 (21h) */
1454 	if (imux_is_smixer || !is_aa_path_mute(codec))
1455 		update_power_state(codec, 0x21, AC_PWRST_D0);
1456 	else
1457 		update_power_state(codec, 0x21, AC_PWRST_D3);
1458 }
1459 
1460 /*
1461  * pin fix-up
1462  */
1463 enum {
1464 	VIA_FIXUP_INTMIC_BOOST,
1465 	VIA_FIXUP_ASUS_G75,
1466 };
1467 
1468 static void via_fixup_intmic_boost(struct hda_codec *codec,
1469 				  const struct hda_fixup *fix, int action)
1470 {
1471 	if (action == HDA_FIXUP_ACT_PRE_PROBE)
1472 		override_mic_boost(codec, 0x30, 0, 2, 40);
1473 }
1474 
1475 static const struct hda_fixup via_fixups[] = {
1476 	[VIA_FIXUP_INTMIC_BOOST] = {
1477 		.type = HDA_FIXUP_FUNC,
1478 		.v.func = via_fixup_intmic_boost,
1479 	},
1480 	[VIA_FIXUP_ASUS_G75] = {
1481 		.type = HDA_FIXUP_PINS,
1482 		.v.pins = (const struct hda_pintbl[]) {
1483 			/* set 0x24 and 0x33 as speakers */
1484 			{ 0x24, 0x991301f0 },
1485 			{ 0x33, 0x991301f1 }, /* subwoofer */
1486 			{ }
1487 		}
1488 	},
1489 };
1490 
1491 static const struct snd_pci_quirk vt2002p_fixups[] = {
1492 	SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
1493 	SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1494 	{}
1495 };
1496 
1497 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1498  * Replace this with mixer NID 0x1c
1499  */
1500 static void fix_vt1802_connections(struct hda_codec *codec)
1501 {
1502 	static hda_nid_t conn_24[] = { 0x14, 0x1c };
1503 	static hda_nid_t conn_33[] = { 0x1c };
1504 
1505 	snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1506 	snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1507 }
1508 
1509 /* patch for vt2002P */
1510 static int patch_vt2002P(struct hda_codec *codec)
1511 {
1512 	struct via_spec *spec;
1513 	int err;
1514 
1515 	/* create a codec specific record */
1516 	spec = via_new_spec(codec);
1517 	if (spec == NULL)
1518 		return -ENOMEM;
1519 
1520 	spec->gen.mixer_nid = 0x21;
1521 	override_mic_boost(codec, 0x2b, 0, 3, 40);
1522 	override_mic_boost(codec, 0x29, 0, 3, 40);
1523 	if (spec->codec_type == VT1802)
1524 		fix_vt1802_connections(codec);
1525 	add_secret_dac_path(codec);
1526 
1527 	snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1528 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1529 
1530 	/* automatic parse from the BIOS config */
1531 	err = via_parse_auto_config(codec);
1532 	if (err < 0) {
1533 		via_free(codec);
1534 		return err;
1535 	}
1536 
1537 	if (spec->codec_type == VT1802)
1538 		spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
1539 	else
1540 		spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1541 
1542 	codec->patch_ops = via_patch_ops;
1543 
1544 	spec->set_widgets_power_state =  set_widgets_power_state_vt2002P;
1545 	return 0;
1546 }
1547 
1548 /* for vt1812 */
1549 
1550 static const struct hda_verb vt1812_init_verbs[] = {
1551 	/* Enable Boost Volume backdoor */
1552 	{0x1, 0xfb9, 0x24},
1553 	/* Enable AOW0 to MW9 */
1554 	{0x1, 0xfb8, 0xa8},
1555 	{ }
1556 };
1557 
1558 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1559 {
1560 	struct via_spec *spec = codec->spec;
1561 	unsigned int parm;
1562 	unsigned int present;
1563 	/* inputs */
1564 	/* PW 5/6/7 (29h/2ah/2bh) */
1565 	parm = AC_PWRST_D3;
1566 	set_pin_power_state(codec, 0x29, &parm);
1567 	set_pin_power_state(codec, 0x2a, &parm);
1568 	set_pin_power_state(codec, 0x2b, &parm);
1569 	parm = AC_PWRST_D0;
1570 	/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1571 	update_power_state(codec, 0x1e, parm);
1572 	update_power_state(codec, 0x1f, parm);
1573 	update_power_state(codec, 0x10, parm);
1574 	update_power_state(codec, 0x11, parm);
1575 
1576 	/* outputs */
1577 	/* AOW0 (8h)*/
1578 	update_power_state(codec, 0x8, AC_PWRST_D0);
1579 
1580 	/* PW4 (28h), MW4 (18h), MUX4(38h) */
1581 	parm = AC_PWRST_D3;
1582 	set_pin_power_state(codec, 0x28, &parm);
1583 	update_power_state(codec, 0x18, parm);
1584 	update_power_state(codec, 0x38, parm);
1585 
1586 	/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1587 	parm = AC_PWRST_D3;
1588 	set_pin_power_state(codec, 0x25, &parm);
1589 	update_power_state(codec, 0x15, parm);
1590 	update_power_state(codec, 0x35, parm);
1591 	if (spec->gen.indep_hp_enabled)
1592 		update_power_state(codec, 0x9, AC_PWRST_D0);
1593 
1594 	/* Internal Speaker */
1595 	/* PW0 (24h), MW0(14h), MUX0(34h) */
1596 	present = snd_hda_jack_detect(codec, 0x25);
1597 
1598 	parm = AC_PWRST_D3;
1599 	set_pin_power_state(codec, 0x24, &parm);
1600 	if (present) {
1601 		update_power_state(codec, 0x14, AC_PWRST_D3);
1602 		update_power_state(codec, 0x34, AC_PWRST_D3);
1603 	} else {
1604 		update_power_state(codec, 0x14, AC_PWRST_D0);
1605 		update_power_state(codec, 0x34, AC_PWRST_D0);
1606 	}
1607 
1608 
1609 	/* Mono Out */
1610 	/* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1611 	present = snd_hda_jack_detect(codec, 0x28);
1612 
1613 	parm = AC_PWRST_D3;
1614 	set_pin_power_state(codec, 0x31, &parm);
1615 	if (present) {
1616 		update_power_state(codec, 0x1c, AC_PWRST_D3);
1617 		update_power_state(codec, 0x3c, AC_PWRST_D3);
1618 		update_power_state(codec, 0x3e, AC_PWRST_D3);
1619 	} else {
1620 		update_power_state(codec, 0x1c, AC_PWRST_D0);
1621 		update_power_state(codec, 0x3c, AC_PWRST_D0);
1622 		update_power_state(codec, 0x3e, AC_PWRST_D0);
1623 	}
1624 
1625 	/* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1626 	parm = AC_PWRST_D3;
1627 	set_pin_power_state(codec, 0x33, &parm);
1628 	update_power_state(codec, 0x1d, parm);
1629 	update_power_state(codec, 0x3d, parm);
1630 
1631 }
1632 
1633 /* patch for vt1812 */
1634 static int patch_vt1812(struct hda_codec *codec)
1635 {
1636 	struct via_spec *spec;
1637 	int err;
1638 
1639 	/* create a codec specific record */
1640 	spec = via_new_spec(codec);
1641 	if (spec == NULL)
1642 		return -ENOMEM;
1643 
1644 	spec->gen.mixer_nid = 0x21;
1645 	override_mic_boost(codec, 0x2b, 0, 3, 40);
1646 	override_mic_boost(codec, 0x29, 0, 3, 40);
1647 	add_secret_dac_path(codec);
1648 
1649 	/* automatic parse from the BIOS config */
1650 	err = via_parse_auto_config(codec);
1651 	if (err < 0) {
1652 		via_free(codec);
1653 		return err;
1654 	}
1655 
1656 	spec->init_verbs[spec->num_iverbs++]  = vt1812_init_verbs;
1657 
1658 	codec->patch_ops = via_patch_ops;
1659 
1660 	spec->set_widgets_power_state =  set_widgets_power_state_vt1812;
1661 	return 0;
1662 }
1663 
1664 /* patch for vt3476 */
1665 
1666 static const struct hda_verb vt3476_init_verbs[] = {
1667 	/* Enable DMic 8/16/32K */
1668 	{0x1, 0xF7B, 0x30},
1669 	/* Enable Boost Volume backdoor */
1670 	{0x1, 0xFB9, 0x20},
1671 	/* Enable AOW-MW9 path */
1672 	{0x1, 0xFB8, 0x10},
1673 	{ }
1674 };
1675 
1676 static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1677 {
1678 	struct via_spec *spec = codec->spec;
1679 	int imux_is_smixer;
1680 	unsigned int parm, parm2;
1681 	/* MUX10 (1eh) = stereo mixer */
1682 	imux_is_smixer =
1683 	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1684 	/* inputs */
1685 	/* PW 5/6/7 (29h/2ah/2bh) */
1686 	parm = AC_PWRST_D3;
1687 	set_pin_power_state(codec, 0x29, &parm);
1688 	set_pin_power_state(codec, 0x2a, &parm);
1689 	set_pin_power_state(codec, 0x2b, &parm);
1690 	if (imux_is_smixer)
1691 		parm = AC_PWRST_D0;
1692 	/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1693 	update_power_state(codec, 0x1e, parm);
1694 	update_power_state(codec, 0x1f, parm);
1695 	update_power_state(codec, 0x10, parm);
1696 	update_power_state(codec, 0x11, parm);
1697 
1698 	/* outputs */
1699 	/* PW3 (27h), MW3(37h), AOW3 (bh) */
1700 	if (spec->codec_type == VT1705CF) {
1701 		parm = AC_PWRST_D3;
1702 		update_power_state(codec, 0x27, parm);
1703 		update_power_state(codec, 0x37, parm);
1704 	}	else {
1705 		parm = AC_PWRST_D3;
1706 		set_pin_power_state(codec, 0x27, &parm);
1707 		update_power_state(codec, 0x37, parm);
1708 	}
1709 
1710 	/* PW2 (26h), MW2(36h), AOW2 (ah) */
1711 	parm = AC_PWRST_D3;
1712 	set_pin_power_state(codec, 0x26, &parm);
1713 	update_power_state(codec, 0x36, parm);
1714 	if (smart51_enabled(codec)) {
1715 		/* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1716 		set_pin_power_state(codec, 0x2b, &parm);
1717 		update_power_state(codec, 0x3b, parm);
1718 		update_power_state(codec, 0x1b, parm);
1719 	}
1720 	update_conv_power_state(codec, 0xa, parm, 2);
1721 
1722 	/* PW1 (25h), MW1(35h), AOW1 (9h) */
1723 	parm = AC_PWRST_D3;
1724 	set_pin_power_state(codec, 0x25, &parm);
1725 	update_power_state(codec, 0x35, parm);
1726 	if (smart51_enabled(codec)) {
1727 		/* PW6(2ah), MW6(3ah), MUX6(1ah) */
1728 		set_pin_power_state(codec, 0x2a, &parm);
1729 		update_power_state(codec, 0x3a, parm);
1730 		update_power_state(codec, 0x1a, parm);
1731 	}
1732 	update_conv_power_state(codec, 0x9, parm, 1);
1733 
1734 	/* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1735 	parm = AC_PWRST_D3;
1736 	set_pin_power_state(codec, 0x28, &parm);
1737 	update_power_state(codec, 0x38, parm);
1738 	update_power_state(codec, 0x18, parm);
1739 	if (spec->gen.indep_hp_enabled)
1740 		update_conv_power_state(codec, 0xb, parm, 3);
1741 	parm2 = parm; /* for pin 0x0b */
1742 
1743 	/* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1744 	parm = AC_PWRST_D3;
1745 	set_pin_power_state(codec, 0x24, &parm);
1746 	update_power_state(codec, 0x34, parm);
1747 	if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1748 		parm = parm2;
1749 	update_conv_power_state(codec, 0x8, parm, 0);
1750 	/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1751 	update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1752 }
1753 
1754 static int patch_vt3476(struct hda_codec *codec)
1755 {
1756 	struct via_spec *spec;
1757 	int err;
1758 
1759 	/* create a codec specific record */
1760 	spec = via_new_spec(codec);
1761 	if (spec == NULL)
1762 		return -ENOMEM;
1763 
1764 	spec->gen.mixer_nid = 0x3f;
1765 	add_secret_dac_path(codec);
1766 
1767 	/* automatic parse from the BIOS config */
1768 	err = via_parse_auto_config(codec);
1769 	if (err < 0) {
1770 		via_free(codec);
1771 		return err;
1772 	}
1773 
1774 	spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1775 
1776 	codec->patch_ops = via_patch_ops;
1777 
1778 	spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1779 
1780 	return 0;
1781 }
1782 
1783 /*
1784  * patch entries
1785  */
1786 static const struct hda_codec_preset snd_hda_preset_via[] = {
1787 	{ .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1788 	{ .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1789 	{ .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1790 	{ .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1791 	{ .id = 0x1106e710, .name = "VT1709 10-Ch",
1792 	  .patch = patch_vt1709},
1793 	{ .id = 0x1106e711, .name = "VT1709 10-Ch",
1794 	  .patch = patch_vt1709},
1795 	{ .id = 0x1106e712, .name = "VT1709 10-Ch",
1796 	  .patch = patch_vt1709},
1797 	{ .id = 0x1106e713, .name = "VT1709 10-Ch",
1798 	  .patch = patch_vt1709},
1799 	{ .id = 0x1106e714, .name = "VT1709 6-Ch",
1800 	  .patch = patch_vt1709},
1801 	{ .id = 0x1106e715, .name = "VT1709 6-Ch",
1802 	  .patch = patch_vt1709},
1803 	{ .id = 0x1106e716, .name = "VT1709 6-Ch",
1804 	  .patch = patch_vt1709},
1805 	{ .id = 0x1106e717, .name = "VT1709 6-Ch",
1806 	  .patch = patch_vt1709},
1807 	{ .id = 0x1106e720, .name = "VT1708B 8-Ch",
1808 	  .patch = patch_vt1708B},
1809 	{ .id = 0x1106e721, .name = "VT1708B 8-Ch",
1810 	  .patch = patch_vt1708B},
1811 	{ .id = 0x1106e722, .name = "VT1708B 8-Ch",
1812 	  .patch = patch_vt1708B},
1813 	{ .id = 0x1106e723, .name = "VT1708B 8-Ch",
1814 	  .patch = patch_vt1708B},
1815 	{ .id = 0x1106e724, .name = "VT1708B 4-Ch",
1816 	  .patch = patch_vt1708B},
1817 	{ .id = 0x1106e725, .name = "VT1708B 4-Ch",
1818 	  .patch = patch_vt1708B},
1819 	{ .id = 0x1106e726, .name = "VT1708B 4-Ch",
1820 	  .patch = patch_vt1708B},
1821 	{ .id = 0x1106e727, .name = "VT1708B 4-Ch",
1822 	  .patch = patch_vt1708B},
1823 	{ .id = 0x11060397, .name = "VT1708S",
1824 	  .patch = patch_vt1708S},
1825 	{ .id = 0x11061397, .name = "VT1708S",
1826 	  .patch = patch_vt1708S},
1827 	{ .id = 0x11062397, .name = "VT1708S",
1828 	  .patch = patch_vt1708S},
1829 	{ .id = 0x11063397, .name = "VT1708S",
1830 	  .patch = patch_vt1708S},
1831 	{ .id = 0x11064397, .name = "VT1705",
1832 	  .patch = patch_vt1708S},
1833 	{ .id = 0x11065397, .name = "VT1708S",
1834 	  .patch = patch_vt1708S},
1835 	{ .id = 0x11066397, .name = "VT1708S",
1836 	  .patch = patch_vt1708S},
1837 	{ .id = 0x11067397, .name = "VT1708S",
1838 	  .patch = patch_vt1708S},
1839 	{ .id = 0x11060398, .name = "VT1702",
1840 	  .patch = patch_vt1702},
1841 	{ .id = 0x11061398, .name = "VT1702",
1842 	  .patch = patch_vt1702},
1843 	{ .id = 0x11062398, .name = "VT1702",
1844 	  .patch = patch_vt1702},
1845 	{ .id = 0x11063398, .name = "VT1702",
1846 	  .patch = patch_vt1702},
1847 	{ .id = 0x11064398, .name = "VT1702",
1848 	  .patch = patch_vt1702},
1849 	{ .id = 0x11065398, .name = "VT1702",
1850 	  .patch = patch_vt1702},
1851 	{ .id = 0x11066398, .name = "VT1702",
1852 	  .patch = patch_vt1702},
1853 	{ .id = 0x11067398, .name = "VT1702",
1854 	  .patch = patch_vt1702},
1855 	{ .id = 0x11060428, .name = "VT1718S",
1856 	  .patch = patch_vt1718S},
1857 	{ .id = 0x11064428, .name = "VT1718S",
1858 	  .patch = patch_vt1718S},
1859 	{ .id = 0x11060441, .name = "VT2020",
1860 	  .patch = patch_vt1718S},
1861 	{ .id = 0x11064441, .name = "VT1828S",
1862 	  .patch = patch_vt1718S},
1863 	{ .id = 0x11060433, .name = "VT1716S",
1864 	  .patch = patch_vt1716S},
1865 	{ .id = 0x1106a721, .name = "VT1716S",
1866 	  .patch = patch_vt1716S},
1867 	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1868 	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
1869 	{ .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
1870 	{ .id = 0x11060440, .name = "VT1818S",
1871 	  .patch = patch_vt1708S},
1872 	{ .id = 0x11060446, .name = "VT1802",
1873 		.patch = patch_vt2002P},
1874 	{ .id = 0x11068446, .name = "VT1802",
1875 		.patch = patch_vt2002P},
1876 	{ .id = 0x11064760, .name = "VT1705CF",
1877 		.patch = patch_vt3476},
1878 	{ .id = 0x11064761, .name = "VT1708SCE",
1879 		.patch = patch_vt3476},
1880 	{ .id = 0x11064762, .name = "VT1808",
1881 		.patch = patch_vt3476},
1882 	{} /* terminator */
1883 };
1884 
1885 MODULE_ALIAS("snd-hda-codec-id:1106*");
1886 
1887 static struct hda_codec_preset_list via_list = {
1888 	.preset = snd_hda_preset_via,
1889 	.owner = THIS_MODULE,
1890 };
1891 
1892 MODULE_LICENSE("GPL");
1893 MODULE_DESCRIPTION("VIA HD-audio codec");
1894 
1895 static int __init patch_via_init(void)
1896 {
1897 	return snd_hda_add_codec_preset(&via_list);
1898 }
1899 
1900 static void __exit patch_via_exit(void)
1901 {
1902 	snd_hda_delete_codec_preset(&via_list);
1903 }
1904 
1905 module_init(patch_via_init)
1906 module_exit(patch_via_exit)
1907