xref: /openbmc/linux/sound/pci/hda/patch_via.c (revision 97da55fc)
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 static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
122 
123 static struct via_spec *via_new_spec(struct hda_codec *codec)
124 {
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;
132 	snd_hda_gen_spec_init(&spec->gen);
133 	spec->codec_type = get_codec_type(codec);
134 	/* VT1708BCE & VT1708S are almost same */
135 	if (spec->codec_type == VT1708BCE)
136 		spec->codec_type = VT1708S;
137 	spec->no_pin_power_ctl = 1;
138 	spec->gen.indep_hp = 1;
139 	spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140 	return spec;
141 }
142 
143 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
144 {
145 	u32 vendor_id = codec->vendor_id;
146 	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;
159 	else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
160 		codec_type = VT1708B_8CH;
161 		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)
164 		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;
171 	else if ((dev_id & 0xfff) == 0x428
172 		 && (dev_id >> 12) < 8)
173 		codec_type = VT1718S;
174 	else if (dev_id == 0x0433 || dev_id == 0xa721)
175 		codec_type = VT1716S;
176 	else if (dev_id == 0x0441 || dev_id == 0x4441)
177 		codec_type = VT1718S;
178 	else if (dev_id == 0x0438 || dev_id == 0x4438)
179 		codec_type = VT2002P;
180 	else if (dev_id == 0x0448)
181 		codec_type = VT1812;
182 	else if (dev_id == 0x0440)
183 		codec_type = VT1708S;
184 	else if ((dev_id & 0xfff) == 0x446)
185 		codec_type = VT1802;
186 	else if (dev_id == 0x4760)
187 		codec_type = VT1705CF;
188 	else if (dev_id == 0x4761 || dev_id == 0x4762)
189 		codec_type = VT1808;
190 	else
191 		codec_type = UNKNOWN;
192 	return codec_type;
193 };
194 
195 static void analog_low_current_mode(struct hda_codec *codec);
196 static bool is_aa_path_mute(struct hda_codec *codec);
197 
198 #define hp_detect_with_aa(codec) \
199 	(snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
200 	 !is_aa_path_mute(codec))
201 
202 static void vt1708_stop_hp_work(struct hda_codec *codec)
203 {
204 	struct via_spec *spec = codec->spec;
205 	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
206 		return;
207 	if (spec->hp_work_active) {
208 		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;
212 	}
213 }
214 
215 static void vt1708_update_hp_work(struct hda_codec *codec)
216 {
217 	struct via_spec *spec = codec->spec;
218 	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
219 		return;
220 	if (spec->vt1708_jack_detect) {
221 		if (!spec->hp_work_active) {
222 			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;
227 		}
228 	} else if (!hp_detect_with_aa(codec))
229 		vt1708_stop_hp_work(codec);
230 }
231 
232 static 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 }
238 
239 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
240 			       unsigned int parm)
241 {
242 	if (snd_hda_check_power_state(codec, nid, parm))
243 		return;
244 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
245 }
246 
247 static 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;
252 
253 	if (snd_hda_check_power_state(codec, nid, parm))
254 		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 
269 static 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 
275 static 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 
286 static 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 */
294 	struct via_spec *spec = codec->spec;
295 	unsigned present = 0;
296 
297 	no_presence |= spec->no_pin_power_ctl;
298 	if (!no_presence)
299 		present = snd_hda_jack_detect(codec, nid);
300 	if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
301 	    || ((no_presence || present)
302 		&& get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
303 		*affected_parm = AC_PWRST_D0; /* if it's connected */
304 		parm = AC_PWRST_D0;
305 	} else
306 		parm = AC_PWRST_D3;
307 
308 	update_power_state(codec, nid, parm);
309 }
310 
311 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
312 				  struct snd_ctl_elem_info *uinfo)
313 {
314 	return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
315 }
316 
317 static 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 
326 static 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);
337 	analog_low_current_mode(codec);
338 	return 1;
339 }
340 
341 static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
342 	{
343 	.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,
348 	},
349 	{} /* terminator */
350 };
351 
352 
353 /* check AA path's mute status */
354 static bool is_aa_path_mute(struct hda_codec *codec)
355 {
356 	struct via_spec *spec = codec->spec;
357 	const struct hda_amp_list *p;
358 	int ch, v;
359 
360 	p = spec->gen.loopback.amplist;
361 	if (!p)
362 		return true;
363 	for (; p->nid; p++) {
364 		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;
369 		}
370 	}
371 	return true;
372 }
373 
374 /* enter/exit analog low-current mode */
375 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
376 {
377 	struct via_spec *spec = codec->spec;
378 	bool enable;
379 	unsigned int verb, parm;
380 
381 	if (spec->no_pin_power_ctl)
382 		enable = false;
383 	else
384 		enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
385 	if (enable == spec->alc_mode && !force)
386 		return;
387 	spec->alc_mode = enable;
388 
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:
397 	case VT1718S:
398 	case VT1716S:
399 		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;
406 	case VT2002P:
407 	case VT1812:
408 	case VT1802:
409 		verb = 0xf93;
410 		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
411 		break;
412 	case VT1705CF:
413 	case VT1808:
414 		verb = 0xf82;
415 		parm = enable ? 0x00 : 0xe0;  /* 0x00: 4/40x, 0xe0: 1x */
416 		break;
417 	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 
424 static void analog_low_current_mode(struct hda_codec *codec)
425 {
426 	return __analog_low_current_mode(codec, false);
427 }
428 
429 static int via_build_controls(struct hda_codec *codec)
430 {
431 	struct via_spec *spec = codec->spec;
432 	int err, i;
433 
434 	err = snd_hda_gen_build_controls(codec);
435 	if (err < 0)
436 		return err;
437 
438 	if (spec->set_widgets_power_state)
439 		spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
440 
441 	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 
447 	return 0;
448 }
449 
450 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
451 				  struct hda_codec *codec,
452 				  struct snd_pcm_substream *substream,
453 				  int action)
454 {
455 	analog_low_current_mode(codec);
456 	vt1708_update_hp_work(codec);
457 }
458 
459 static void via_free(struct hda_codec *codec)
460 {
461 	struct via_spec *spec = codec->spec;
462 
463 	if (!spec)
464 		return;
465 
466 	vt1708_stop_hp_work(codec);
467 	snd_hda_gen_spec_free(&spec->gen);
468 	kfree(spec);
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 	if (spec->codec_type == VT1802) {
478 		/* Fix pop noise on headphones */
479 		int i;
480 		for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
481 			snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
482 	}
483 
484 	return 0;
485 }
486 #endif
487 
488 #ifdef CONFIG_PM
489 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
490 {
491 	struct via_spec *spec = codec->spec;
492 	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);
496 }
497 #endif
498 
499 /*
500  */
501 
502 static int via_init(struct hda_codec *codec);
503 
504 static const struct hda_codec_ops via_patch_ops = {
505 	.build_controls = via_build_controls,
506 	.build_pcms = snd_hda_gen_build_pcms,
507 	.init = via_init,
508 	.free = via_free,
509 	.unsol_event = snd_hda_jack_unsol_event,
510 #ifdef CONFIG_PM
511 	.suspend = via_suspend,
512 	.check_power_status = via_check_power_status,
513 #endif
514 };
515 
516 
517 static const struct hda_verb vt1708_init_verbs[] = {
518 	/* power down jack detect function */
519 	{0x1, 0xf81, 0x1},
520 	{ }
521 };
522 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
523 {
524 	unsigned int def_conf;
525 	unsigned char seqassoc;
526 
527 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
528 	seqassoc = (unsigned char) get_defcfg_association(def_conf);
529 	seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
530 	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);
534 	}
535 
536 	return;
537 }
538 
539 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
540 				     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;
547 	ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
548 	return 0;
549 }
550 
551 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
552 				     struct snd_ctl_elem_value *ucontrol)
553 {
554 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555 	struct via_spec *spec = codec->spec;
556 	int val;
557 
558 	if (spec->codec_type != VT1708)
559 		return 0;
560 	val = !!ucontrol->value.integer.value[0];
561 	if (spec->vt1708_jack_detect == val)
562 		return 0;
563 	spec->vt1708_jack_detect = val;
564 	vt1708_update_hp_work(codec);
565 	return 1;
566 }
567 
568 static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
569 	{
570 	.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,
576 	},
577 	{} /* terminator */
578 };
579 
580 static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
581 {
582 	set_widgets_power_state(codec);
583 	snd_hda_gen_hp_automute(codec, tbl);
584 }
585 
586 static 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);
590 }
591 
592 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
593 {
594 	set_widgets_power_state(codec);
595 }
596 
597 #define VIA_JACK_EVENT	(HDA_GEN_LAST_EVENT + 1)
598 
599 static void via_set_jack_unsol_events(struct hda_codec *codec)
600 {
601 	struct via_spec *spec = codec->spec;
602 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
603 	hda_nid_t pin;
604 	int i;
605 
606 	spec->gen.hp_automute_hook = via_hp_automute;
607 	if (cfg->speaker_pins[0])
608 		spec->gen.line_automute_hook = via_line_automute;
609 
610 	for (i = 0; i < cfg->line_outs; i++) {
611 		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,
615 							    VIA_JACK_EVENT,
616 							    via_jack_powerstate_event);
617 	}
618 
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 
629 static int via_parse_auto_config(struct hda_codec *codec)
630 {
631 	struct via_spec *spec = codec->spec;
632 	int err;
633 
634 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
635 	if (err < 0)
636 		return err;
637 
638 	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
639 	if (err < 0)
640 		return err;
641 
642 	via_set_jack_unsol_events(codec);
643 	return 0;
644 }
645 
646 static int via_init(struct hda_codec *codec)
647 {
648 	struct via_spec *spec = codec->spec;
649 	int i;
650 
651 	for (i = 0; i < spec->num_iverbs; i++)
652 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
653 
654 	/* init power states */
655 	set_widgets_power_state(codec);
656 	__analog_low_current_mode(codec, true);
657 
658 	snd_hda_gen_init(codec);
659 
660 	vt1708_update_hp_work(codec);
661 
662 	return 0;
663 }
664 
665 static int vt1708_build_controls(struct hda_codec *codec)
666 {
667 	/* In order not to create "Phantom Jack" controls,
668 	   temporary enable jackpoll */
669 	int err;
670 	int old_interval = codec->jackpoll_interval;
671 	codec->jackpoll_interval = msecs_to_jiffies(100);
672 	err = via_build_controls(codec);
673 	codec->jackpoll_interval = old_interval;
674 	return err;
675 }
676 
677 static int vt1708_build_pcms(struct hda_codec *codec)
678 {
679 	struct via_spec *spec = codec->spec;
680 	int i, err;
681 
682 	err = snd_hda_gen_build_pcms(codec);
683 	if (err < 0 || codec->vendor_id != 0x11061708)
684 		return err;
685 
686 	/* We got noisy outputs on the right channel on VT1708 when
687 	 * 24bit samples are used.  Until any workaround is found,
688 	 * disable the 24bit format, so far.
689 	 */
690 	for (i = 0; i < codec->num_pcms; i++) {
691 		struct hda_pcm *info = &spec->gen.pcm_rec[i];
692 		if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
693 		    info->pcm_type != HDA_PCM_TYPE_AUDIO)
694 			continue;
695 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
696 			SNDRV_PCM_FMTBIT_S16_LE;
697 	}
698 
699 	return 0;
700 }
701 
702 static int patch_vt1708(struct hda_codec *codec)
703 {
704 	struct via_spec *spec;
705 	int err;
706 
707 	/* create a codec specific record */
708 	spec = via_new_spec(codec);
709 	if (spec == NULL)
710 		return -ENOMEM;
711 
712 	spec->gen.mixer_nid = 0x17;
713 
714 	/* set jackpoll_interval while parsing the codec */
715 	codec->jackpoll_interval = msecs_to_jiffies(100);
716 	spec->vt1708_jack_detect = 1;
717 
718 	/* don't support the input jack switching due to lack of unsol event */
719 	/* (it may work with polling, though, but it needs testing) */
720 	spec->gen.suppress_auto_mic = 1;
721 
722 	/* Add HP and CD pin config connect bit re-config action */
723 	vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
724 	vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
725 
726 	/* automatic parse from the BIOS config */
727 	err = via_parse_auto_config(codec);
728 	if (err < 0) {
729 		via_free(codec);
730 		return err;
731 	}
732 
733 	/* add jack detect on/off control */
734 	spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
735 
736 	spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
737 
738 	codec->patch_ops = via_patch_ops;
739 	codec->patch_ops.build_controls = vt1708_build_controls;
740 	codec->patch_ops.build_pcms = vt1708_build_pcms;
741 
742 	/* clear jackpoll_interval again; it's set dynamically */
743 	codec->jackpoll_interval = 0;
744 
745 	return 0;
746 }
747 
748 static int patch_vt1709(struct hda_codec *codec)
749 {
750 	struct via_spec *spec;
751 	int err;
752 
753 	/* create a codec specific record */
754 	spec = via_new_spec(codec);
755 	if (spec == NULL)
756 		return -ENOMEM;
757 
758 	spec->gen.mixer_nid = 0x18;
759 
760 	err = via_parse_auto_config(codec);
761 	if (err < 0) {
762 		via_free(codec);
763 		return err;
764 	}
765 
766 	codec->patch_ops = via_patch_ops;
767 
768 	return 0;
769 }
770 
771 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
772 {
773 	struct via_spec *spec = codec->spec;
774 	int imux_is_smixer;
775 	unsigned int parm;
776 	int is_8ch = 0;
777 	if ((spec->codec_type != VT1708B_4CH) &&
778 	    (codec->vendor_id != 0x11064397))
779 		is_8ch = 1;
780 
781 	/* SW0 (17h) = stereo mixer */
782 	imux_is_smixer =
783 	(snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
784 	 == ((spec->codec_type == VT1708S) ? 5 : 0));
785 	/* inputs */
786 	/* PW 1/2/5 (1ah/1bh/1eh) */
787 	parm = AC_PWRST_D3;
788 	set_pin_power_state(codec, 0x1a, &parm);
789 	set_pin_power_state(codec, 0x1b, &parm);
790 	set_pin_power_state(codec, 0x1e, &parm);
791 	if (imux_is_smixer)
792 		parm = AC_PWRST_D0;
793 	/* SW0 (17h), AIW 0/1 (13h/14h) */
794 	update_power_state(codec, 0x17, parm);
795 	update_power_state(codec, 0x13, parm);
796 	update_power_state(codec, 0x14, parm);
797 
798 	/* outputs */
799 	/* PW0 (19h), SW1 (18h), AOW1 (11h) */
800 	parm = AC_PWRST_D3;
801 	set_pin_power_state(codec, 0x19, &parm);
802 	if (smart51_enabled(codec))
803 		set_pin_power_state(codec, 0x1b, &parm);
804 	update_power_state(codec, 0x18, parm);
805 	update_power_state(codec, 0x11, parm);
806 
807 	/* PW6 (22h), SW2 (26h), AOW2 (24h) */
808 	if (is_8ch) {
809 		parm = AC_PWRST_D3;
810 		set_pin_power_state(codec, 0x22, &parm);
811 		if (smart51_enabled(codec))
812 			set_pin_power_state(codec, 0x1a, &parm);
813 		update_power_state(codec, 0x26, parm);
814 		update_power_state(codec, 0x24, parm);
815 	} else if (codec->vendor_id == 0x11064397) {
816 		/* PW7(23h), SW2(27h), AOW2(25h) */
817 		parm = AC_PWRST_D3;
818 		set_pin_power_state(codec, 0x23, &parm);
819 		if (smart51_enabled(codec))
820 			set_pin_power_state(codec, 0x1a, &parm);
821 		update_power_state(codec, 0x27, parm);
822 		update_power_state(codec, 0x25, parm);
823 	}
824 
825 	/* PW 3/4/7 (1ch/1dh/23h) */
826 	parm = AC_PWRST_D3;
827 	/* force to D0 for internal Speaker */
828 	set_pin_power_state(codec, 0x1c, &parm);
829 	set_pin_power_state(codec, 0x1d, &parm);
830 	if (is_8ch)
831 		set_pin_power_state(codec, 0x23, &parm);
832 
833 	/* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
834 	update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
835 	update_power_state(codec, 0x10, parm);
836 	if (is_8ch) {
837 		update_power_state(codec, 0x25, parm);
838 		update_power_state(codec, 0x27, parm);
839 	} else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
840 		update_power_state(codec, 0x25, parm);
841 }
842 
843 static int patch_vt1708S(struct hda_codec *codec);
844 static int patch_vt1708B(struct hda_codec *codec)
845 {
846 	struct via_spec *spec;
847 	int err;
848 
849 	if (get_codec_type(codec) == VT1708BCE)
850 		return patch_vt1708S(codec);
851 
852 	/* create a codec specific record */
853 	spec = via_new_spec(codec);
854 	if (spec == NULL)
855 		return -ENOMEM;
856 
857 	spec->gen.mixer_nid = 0x16;
858 
859 	/* automatic parse from the BIOS config */
860 	err = via_parse_auto_config(codec);
861 	if (err < 0) {
862 		via_free(codec);
863 		return err;
864 	}
865 
866 	codec->patch_ops = via_patch_ops;
867 
868 	spec->set_widgets_power_state =  set_widgets_power_state_vt1708B;
869 
870 	return 0;
871 }
872 
873 /* Patch for VT1708S */
874 static const struct hda_verb vt1708S_init_verbs[] = {
875 	/* Enable Mic Boost Volume backdoor */
876 	{0x1, 0xf98, 0x1},
877 	/* don't bybass mixer */
878 	{0x1, 0xf88, 0xc0},
879 	{ }
880 };
881 
882 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
883 			       int offset, int num_steps, int step_size)
884 {
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