xref: /openbmc/linux/sound/pci/hda/patch_via.c (revision 36dd5c4afff825fca1b6ccde678f51d6933a6850)
1c577b8a1SJoseph Chan /*
2c577b8a1SJoseph Chan  * Universal Interface for Intel High Definition Audio Codec
3c577b8a1SJoseph Chan  *
48e86597fSLydia Wang  * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5c577b8a1SJoseph Chan  *
68e86597fSLydia Wang  *  (C) 2006-2009 VIA Technology, Inc.
78e86597fSLydia Wang  *  (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8c577b8a1SJoseph Chan  *
9c577b8a1SJoseph Chan  *  This driver is free software; you can redistribute it and/or modify
10c577b8a1SJoseph Chan  *  it under the terms of the GNU General Public License as published by
11c577b8a1SJoseph Chan  *  the Free Software Foundation; either version 2 of the License, or
12c577b8a1SJoseph Chan  *  (at your option) any later version.
13c577b8a1SJoseph Chan  *
14c577b8a1SJoseph Chan  *  This driver is distributed in the hope that it will be useful,
15c577b8a1SJoseph Chan  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16c577b8a1SJoseph Chan  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17c577b8a1SJoseph Chan  *  GNU General Public License for more details.
18c577b8a1SJoseph Chan  *
19c577b8a1SJoseph Chan  *  You should have received a copy of the GNU General Public License
20c577b8a1SJoseph Chan  *  along with this program; if not, write to the Free Software
21c577b8a1SJoseph Chan  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22c577b8a1SJoseph Chan  */
23c577b8a1SJoseph Chan 
24c577b8a1SJoseph Chan /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
25c577b8a1SJoseph Chan /*									     */
26c577b8a1SJoseph Chan /* 2006-03-03  Lydia Wang  Create the basic patch to support VT1708 codec    */
27c577b8a1SJoseph Chan /* 2006-03-14  Lydia Wang  Modify hard code for some pin widget nid	     */
28c577b8a1SJoseph Chan /* 2006-08-02  Lydia Wang  Add support to VT1709 codec			     */
29c577b8a1SJoseph Chan /* 2006-09-08  Lydia Wang  Fix internal loopback recording source select bug */
30f7278fd0SJosepch Chan /* 2007-09-12  Lydia Wang  Add EAPD enable during driver initialization	     */
31f7278fd0SJosepch Chan /* 2007-09-17  Lydia Wang  Add VT1708B codec support			    */
3276d9b0ddSHarald Welte /* 2007-11-14  Lydia Wang  Add VT1708A codec HP and CD pin connect config    */
33fb4cb772SHarald Welte /* 2008-02-03  Lydia Wang  Fix Rear channels and Back channels inverse issue */
34d949cac1SHarald Welte /* 2008-03-06  Lydia Wang  Add VT1702 codec and VT1708S codec support	     */
3569e52a80SHarald Welte /* 2008-04-09  Lydia Wang  Add mute front speaker when HP plugin	     */
360aa62aefSHarald Welte /* 2008-04-09  Lydia Wang  Add Independent HP feature			     */
3798aa34c0SHarald Welte /* 2008-05-28  Lydia Wang  Add second S/PDIF Out support for VT1702	     */
38d7426329SHarald Welte /* 2008-09-15  Logan Li	   Add VT1708S Mic Boost workaround/backdoor	     */
398e86597fSLydia Wang /* 2009-02-16  Logan Li	   Add support for VT1718S			     */
408e86597fSLydia Wang /* 2009-03-13  Logan Li	   Add support for VT1716S			     */
418e86597fSLydia Wang /* 2009-04-14  Lydai Wang  Add support for VT1828S and VT2020		     */
428e86597fSLydia Wang /* 2009-07-08  Lydia Wang  Add support for VT2002P			     */
438e86597fSLydia Wang /* 2009-07-21  Lydia Wang  Add support for VT1812			     */
44*36dd5c4aSLydia Wang /* 2009-09-19  Lydia Wang  Add support for VT1818S			     */
45c577b8a1SJoseph Chan /*									     */
46c577b8a1SJoseph Chan /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47c577b8a1SJoseph Chan 
48c577b8a1SJoseph Chan 
49c577b8a1SJoseph Chan #include <linux/init.h>
50c577b8a1SJoseph Chan #include <linux/delay.h>
51c577b8a1SJoseph Chan #include <linux/slab.h>
52c577b8a1SJoseph Chan #include <sound/core.h>
530aa62aefSHarald Welte #include <sound/asoundef.h>
54c577b8a1SJoseph Chan #include "hda_codec.h"
55c577b8a1SJoseph Chan #include "hda_local.h"
56c577b8a1SJoseph Chan 
57c577b8a1SJoseph Chan /* amp values */
58c577b8a1SJoseph Chan #define AMP_VAL_IDX_SHIFT	19
59c577b8a1SJoseph Chan #define AMP_VAL_IDX_MASK	(0x0f<<19)
60c577b8a1SJoseph Chan 
61c577b8a1SJoseph Chan /* Pin Widget NID */
62c577b8a1SJoseph Chan #define VT1708_HP_NID		0x13
63c577b8a1SJoseph Chan #define VT1708_DIGOUT_NID	0x14
64c577b8a1SJoseph Chan #define VT1708_DIGIN_NID	0x16
65f7278fd0SJosepch Chan #define VT1708_DIGIN_PIN	0x26
6676d9b0ddSHarald Welte #define VT1708_HP_PIN_NID	0x20
6776d9b0ddSHarald Welte #define VT1708_CD_PIN_NID	0x24
68c577b8a1SJoseph Chan 
69c577b8a1SJoseph Chan #define VT1709_HP_DAC_NID	0x28
70c577b8a1SJoseph Chan #define VT1709_DIGOUT_NID	0x13
71c577b8a1SJoseph Chan #define VT1709_DIGIN_NID	0x17
72f7278fd0SJosepch Chan #define VT1709_DIGIN_PIN	0x25
73f7278fd0SJosepch Chan 
74f7278fd0SJosepch Chan #define VT1708B_HP_NID		0x25
75f7278fd0SJosepch Chan #define VT1708B_DIGOUT_NID	0x12
76f7278fd0SJosepch Chan #define VT1708B_DIGIN_NID	0x15
77f7278fd0SJosepch Chan #define VT1708B_DIGIN_PIN	0x21
78c577b8a1SJoseph Chan 
79d949cac1SHarald Welte #define VT1708S_HP_NID		0x25
80d949cac1SHarald Welte #define VT1708S_DIGOUT_NID	0x12
81d949cac1SHarald Welte 
82d949cac1SHarald Welte #define VT1702_HP_NID		0x17
83d949cac1SHarald Welte #define VT1702_DIGOUT_NID	0x11
84d949cac1SHarald Welte 
85d7426329SHarald Welte enum VIA_HDA_CODEC {
86d7426329SHarald Welte 	UNKNOWN = -1,
87d7426329SHarald Welte 	VT1708,
88d7426329SHarald Welte 	VT1709_10CH,
89d7426329SHarald Welte 	VT1709_6CH,
90d7426329SHarald Welte 	VT1708B_8CH,
91d7426329SHarald Welte 	VT1708B_4CH,
92d7426329SHarald Welte 	VT1708S,
93518bf3baSLydia Wang 	VT1708BCE,
94d7426329SHarald Welte 	VT1702,
95eb7188caSLydia Wang 	VT1718S,
96f3db423dSLydia Wang 	VT1716S,
9725eaba2fSLydia Wang 	VT2002P,
98ab6734e7SLydia Wang 	VT1812,
99d7426329SHarald Welte 	CODEC_TYPES,
100d7426329SHarald Welte };
101d7426329SHarald Welte 
1021f2e99feSLydia Wang struct via_spec {
1031f2e99feSLydia Wang 	/* codec parameterization */
104f3db423dSLydia Wang 	struct snd_kcontrol_new *mixers[6];
1051f2e99feSLydia Wang 	unsigned int num_mixers;
1061f2e99feSLydia Wang 
1071f2e99feSLydia Wang 	struct hda_verb *init_verbs[5];
1081f2e99feSLydia Wang 	unsigned int num_iverbs;
1091f2e99feSLydia Wang 
1101f2e99feSLydia Wang 	char *stream_name_analog;
1111f2e99feSLydia Wang 	struct hda_pcm_stream *stream_analog_playback;
1121f2e99feSLydia Wang 	struct hda_pcm_stream *stream_analog_capture;
1131f2e99feSLydia Wang 
1141f2e99feSLydia Wang 	char *stream_name_digital;
1151f2e99feSLydia Wang 	struct hda_pcm_stream *stream_digital_playback;
1161f2e99feSLydia Wang 	struct hda_pcm_stream *stream_digital_capture;
1171f2e99feSLydia Wang 
1181f2e99feSLydia Wang 	/* playback */
1191f2e99feSLydia Wang 	struct hda_multi_out multiout;
1201f2e99feSLydia Wang 	hda_nid_t slave_dig_outs[2];
1211f2e99feSLydia Wang 
1221f2e99feSLydia Wang 	/* capture */
1231f2e99feSLydia Wang 	unsigned int num_adc_nids;
1241f2e99feSLydia Wang 	hda_nid_t *adc_nids;
1251f2e99feSLydia Wang 	hda_nid_t mux_nids[3];
1261f2e99feSLydia Wang 	hda_nid_t dig_in_nid;
1271f2e99feSLydia Wang 	hda_nid_t dig_in_pin;
1281f2e99feSLydia Wang 
1291f2e99feSLydia Wang 	/* capture source */
1301f2e99feSLydia Wang 	const struct hda_input_mux *input_mux;
1311f2e99feSLydia Wang 	unsigned int cur_mux[3];
1321f2e99feSLydia Wang 
1331f2e99feSLydia Wang 	/* PCM information */
1341f2e99feSLydia Wang 	struct hda_pcm pcm_rec[3];
1351f2e99feSLydia Wang 
1361f2e99feSLydia Wang 	/* dynamic controls, init_verbs and input_mux */
1371f2e99feSLydia Wang 	struct auto_pin_cfg autocfg;
1381f2e99feSLydia Wang 	struct snd_array kctls;
1391f2e99feSLydia Wang 	struct hda_input_mux private_imux[2];
1401f2e99feSLydia Wang 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
1411f2e99feSLydia Wang 
1421f2e99feSLydia Wang 	/* HP mode source */
1431f2e99feSLydia Wang 	const struct hda_input_mux *hp_mux;
1441f2e99feSLydia Wang 	unsigned int hp_independent_mode;
1451f2e99feSLydia Wang 	unsigned int hp_independent_mode_index;
1461f2e99feSLydia Wang 	unsigned int smart51_enabled;
147f3db423dSLydia Wang 	unsigned int dmic_enabled;
1481f2e99feSLydia Wang 	enum VIA_HDA_CODEC codec_type;
1491f2e99feSLydia Wang 
1501f2e99feSLydia Wang 	/* work to check hp jack state */
1511f2e99feSLydia Wang 	struct hda_codec *codec;
1521f2e99feSLydia Wang 	struct delayed_work vt1708_hp_work;
1531f2e99feSLydia Wang 	int vt1708_jack_detectect;
1541f2e99feSLydia Wang 	int vt1708_hp_present;
1551f2e99feSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
1561f2e99feSLydia Wang 	struct hda_loopback_check loopback;
1571f2e99feSLydia Wang #endif
1581f2e99feSLydia Wang };
1591f2e99feSLydia Wang 
160744ff5f4SLydia Wang static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
161d7426329SHarald Welte {
162744ff5f4SLydia Wang 	u32 vendor_id = codec->vendor_id;
163d7426329SHarald Welte 	u16 ven_id = vendor_id >> 16;
164d7426329SHarald Welte 	u16 dev_id = vendor_id & 0xffff;
165d7426329SHarald Welte 	enum VIA_HDA_CODEC codec_type;
166d7426329SHarald Welte 
167d7426329SHarald Welte 	/* get codec type */
168d7426329SHarald Welte 	if (ven_id != 0x1106)
169d7426329SHarald Welte 		codec_type = UNKNOWN;
170d7426329SHarald Welte 	else if (dev_id >= 0x1708 && dev_id <= 0x170b)
171d7426329SHarald Welte 		codec_type = VT1708;
172d7426329SHarald Welte 	else if (dev_id >= 0xe710 && dev_id <= 0xe713)
173d7426329SHarald Welte 		codec_type = VT1709_10CH;
174d7426329SHarald Welte 	else if (dev_id >= 0xe714 && dev_id <= 0xe717)
175d7426329SHarald Welte 		codec_type = VT1709_6CH;
176518bf3baSLydia Wang 	else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
177d7426329SHarald Welte 		codec_type = VT1708B_8CH;
178518bf3baSLydia Wang 		if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
179518bf3baSLydia Wang 			codec_type = VT1708BCE;
180518bf3baSLydia Wang 	} else if (dev_id >= 0xe724 && dev_id <= 0xe727)
181d7426329SHarald Welte 		codec_type = VT1708B_4CH;
182d7426329SHarald Welte 	else if ((dev_id & 0xfff) == 0x397
183d7426329SHarald Welte 		 && (dev_id >> 12) < 8)
184d7426329SHarald Welte 		codec_type = VT1708S;
185d7426329SHarald Welte 	else if ((dev_id & 0xfff) == 0x398
186d7426329SHarald Welte 		 && (dev_id >> 12) < 8)
187d7426329SHarald Welte 		codec_type = VT1702;
188eb7188caSLydia Wang 	else if ((dev_id & 0xfff) == 0x428
189eb7188caSLydia Wang 		 && (dev_id >> 12) < 8)
190eb7188caSLydia Wang 		codec_type = VT1718S;
191f3db423dSLydia Wang 	else if (dev_id == 0x0433 || dev_id == 0xa721)
192f3db423dSLydia Wang 		codec_type = VT1716S;
193bb3c6bfcSLydia Wang 	else if (dev_id == 0x0441 || dev_id == 0x4441)
194bb3c6bfcSLydia Wang 		codec_type = VT1718S;
19525eaba2fSLydia Wang 	else if (dev_id == 0x0438 || dev_id == 0x4438)
19625eaba2fSLydia Wang 		codec_type = VT2002P;
197ab6734e7SLydia Wang 	else if (dev_id == 0x0448)
198ab6734e7SLydia Wang 		codec_type = VT1812;
199*36dd5c4aSLydia Wang 	else if (dev_id == 0x0440)
200*36dd5c4aSLydia Wang 		codec_type = VT1708S;
201d7426329SHarald Welte 	else
202d7426329SHarald Welte 		codec_type = UNKNOWN;
203d7426329SHarald Welte 	return codec_type;
204d7426329SHarald Welte };
205d7426329SHarald Welte 
20669e52a80SHarald Welte #define VIA_HP_EVENT		0x01
20769e52a80SHarald Welte #define VIA_GPIO_EVENT		0x02
208a34df19aSLydia Wang #define VIA_JACK_EVENT		0x04
209f3db423dSLydia Wang #define VIA_MONO_EVENT		0x08
21025eaba2fSLydia Wang #define VIA_SPEAKER_EVENT	0x10
21125eaba2fSLydia Wang #define VIA_BIND_HP_EVENT	0x20
21269e52a80SHarald Welte 
213c577b8a1SJoseph Chan enum {
214c577b8a1SJoseph Chan 	VIA_CTL_WIDGET_VOL,
215c577b8a1SJoseph Chan 	VIA_CTL_WIDGET_MUTE,
216f5271101SLydia Wang 	VIA_CTL_WIDGET_ANALOG_MUTE,
21725eaba2fSLydia Wang 	VIA_CTL_WIDGET_BIND_PIN_MUTE,
218c577b8a1SJoseph Chan };
219c577b8a1SJoseph Chan 
220c577b8a1SJoseph Chan enum {
221eb14a46cSHarald Welte 	AUTO_SEQ_FRONT = 0,
222c577b8a1SJoseph Chan 	AUTO_SEQ_SURROUND,
223c577b8a1SJoseph Chan 	AUTO_SEQ_CENLFE,
224c577b8a1SJoseph Chan 	AUTO_SEQ_SIDE
225c577b8a1SJoseph Chan };
226c577b8a1SJoseph Chan 
227f5271101SLydia Wang static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
228f5271101SLydia Wang static void set_jack_power_state(struct hda_codec *codec);
2291f2e99feSLydia Wang static int is_aa_path_mute(struct hda_codec *codec);
2301f2e99feSLydia Wang 
2311f2e99feSLydia Wang static void vt1708_start_hp_work(struct via_spec *spec)
2321f2e99feSLydia Wang {
2331f2e99feSLydia Wang 	if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
2341f2e99feSLydia Wang 		return;
2351f2e99feSLydia Wang 	snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
2361f2e99feSLydia Wang 			    !spec->vt1708_jack_detectect);
2371f2e99feSLydia Wang 	if (!delayed_work_pending(&spec->vt1708_hp_work))
2381f2e99feSLydia Wang 		schedule_delayed_work(&spec->vt1708_hp_work,
2391f2e99feSLydia Wang 				      msecs_to_jiffies(100));
2401f2e99feSLydia Wang }
2411f2e99feSLydia Wang 
2421f2e99feSLydia Wang static void vt1708_stop_hp_work(struct via_spec *spec)
2431f2e99feSLydia Wang {
2441f2e99feSLydia Wang 	if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
2451f2e99feSLydia Wang 		return;
2461f2e99feSLydia Wang 	if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
2471f2e99feSLydia Wang 	    && !is_aa_path_mute(spec->codec))
2481f2e99feSLydia Wang 		return;
2491f2e99feSLydia Wang 	snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
2501f2e99feSLydia Wang 			    !spec->vt1708_jack_detectect);
2511f2e99feSLydia Wang 	cancel_delayed_work(&spec->vt1708_hp_work);
2521f2e99feSLydia Wang 	flush_scheduled_work();
2531f2e99feSLydia Wang }
254f5271101SLydia Wang 
25525eaba2fSLydia Wang 
256f5271101SLydia Wang static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
257f5271101SLydia Wang 				   struct snd_ctl_elem_value *ucontrol)
258f5271101SLydia Wang {
259f5271101SLydia Wang 	int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
260f5271101SLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261f5271101SLydia Wang 
262f5271101SLydia Wang 	set_jack_power_state(codec);
263f5271101SLydia Wang 	analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
2641f2e99feSLydia Wang 	if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
2651f2e99feSLydia Wang 		if (is_aa_path_mute(codec))
2661f2e99feSLydia Wang 			vt1708_start_hp_work(codec->spec);
2671f2e99feSLydia Wang 		else
2681f2e99feSLydia Wang 			vt1708_stop_hp_work(codec->spec);
2691f2e99feSLydia Wang 	}
270f5271101SLydia Wang 	return change;
271f5271101SLydia Wang }
272f5271101SLydia Wang 
273f5271101SLydia Wang /* modify .put = snd_hda_mixer_amp_switch_put */
274f5271101SLydia Wang #define ANALOG_INPUT_MUTE						\
275f5271101SLydia Wang 	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
276f5271101SLydia Wang 			.name = NULL,					\
277f5271101SLydia Wang 			.index = 0,					\
278f5271101SLydia Wang 			.info = snd_hda_mixer_amp_switch_info,		\
279f5271101SLydia Wang 			.get = snd_hda_mixer_amp_switch_get,		\
280f5271101SLydia Wang 			.put = analog_input_switch_put,			\
281f5271101SLydia Wang 			.private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
282f5271101SLydia Wang 
28325eaba2fSLydia Wang static void via_hp_bind_automute(struct hda_codec *codec);
28425eaba2fSLydia Wang 
28525eaba2fSLydia Wang static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
28625eaba2fSLydia Wang 			       struct snd_ctl_elem_value *ucontrol)
28725eaba2fSLydia Wang {
28825eaba2fSLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
28925eaba2fSLydia Wang 	struct via_spec *spec = codec->spec;
29025eaba2fSLydia Wang 	int i;
29125eaba2fSLydia Wang 	int change = 0;
29225eaba2fSLydia Wang 
29325eaba2fSLydia Wang 	long *valp = ucontrol->value.integer.value;
29425eaba2fSLydia Wang 	int lmute, rmute;
29525eaba2fSLydia Wang 	if (strstr(kcontrol->id.name, "Switch") == NULL) {
29625eaba2fSLydia Wang 		snd_printd("Invalid control!\n");
29725eaba2fSLydia Wang 		return change;
29825eaba2fSLydia Wang 	}
29925eaba2fSLydia Wang 	change = snd_hda_mixer_amp_switch_put(kcontrol,
30025eaba2fSLydia Wang 					      ucontrol);
30125eaba2fSLydia Wang 	/* Get mute value */
30225eaba2fSLydia Wang 	lmute = *valp ? 0 : HDA_AMP_MUTE;
30325eaba2fSLydia Wang 	valp++;
30425eaba2fSLydia Wang 	rmute = *valp ? 0 : HDA_AMP_MUTE;
30525eaba2fSLydia Wang 
30625eaba2fSLydia Wang 	/* Set hp pins */
30725eaba2fSLydia Wang 	if (!spec->hp_independent_mode) {
30825eaba2fSLydia Wang 		for (i = 0; i < spec->autocfg.hp_outs; i++) {
30925eaba2fSLydia Wang 			snd_hda_codec_amp_update(
31025eaba2fSLydia Wang 				codec, spec->autocfg.hp_pins[i],
31125eaba2fSLydia Wang 				0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
31225eaba2fSLydia Wang 				lmute);
31325eaba2fSLydia Wang 			snd_hda_codec_amp_update(
31425eaba2fSLydia Wang 				codec, spec->autocfg.hp_pins[i],
31525eaba2fSLydia Wang 				1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
31625eaba2fSLydia Wang 				rmute);
31725eaba2fSLydia Wang 		}
31825eaba2fSLydia Wang 	}
31925eaba2fSLydia Wang 
32025eaba2fSLydia Wang 	if (!lmute && !rmute) {
32125eaba2fSLydia Wang 		/* Line Outs */
32225eaba2fSLydia Wang 		for (i = 0; i < spec->autocfg.line_outs; i++)
32325eaba2fSLydia Wang 			snd_hda_codec_amp_stereo(
32425eaba2fSLydia Wang 				codec, spec->autocfg.line_out_pins[i],
32525eaba2fSLydia Wang 				HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
32625eaba2fSLydia Wang 		/* Speakers */
32725eaba2fSLydia Wang 		for (i = 0; i < spec->autocfg.speaker_outs; i++)
32825eaba2fSLydia Wang 			snd_hda_codec_amp_stereo(
32925eaba2fSLydia Wang 				codec, spec->autocfg.speaker_pins[i],
33025eaba2fSLydia Wang 				HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
33125eaba2fSLydia Wang 		/* unmute */
33225eaba2fSLydia Wang 		via_hp_bind_automute(codec);
33325eaba2fSLydia Wang 
33425eaba2fSLydia Wang 	} else {
33525eaba2fSLydia Wang 		if (lmute) {
33625eaba2fSLydia Wang 			/* Mute all left channels */
33725eaba2fSLydia Wang 			for (i = 1; i < spec->autocfg.line_outs; i++)
33825eaba2fSLydia Wang 				snd_hda_codec_amp_update(
33925eaba2fSLydia Wang 					codec,
34025eaba2fSLydia Wang 					spec->autocfg.line_out_pins[i],
34125eaba2fSLydia Wang 					0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
34225eaba2fSLydia Wang 					lmute);
34325eaba2fSLydia Wang 			for (i = 0; i < spec->autocfg.speaker_outs; i++)
34425eaba2fSLydia Wang 				snd_hda_codec_amp_update(
34525eaba2fSLydia Wang 					codec,
34625eaba2fSLydia Wang 					spec->autocfg.speaker_pins[i],
34725eaba2fSLydia Wang 					0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
34825eaba2fSLydia Wang 					lmute);
34925eaba2fSLydia Wang 		}
35025eaba2fSLydia Wang 		if (rmute) {
35125eaba2fSLydia Wang 			/* mute all right channels */
35225eaba2fSLydia Wang 			for (i = 1; i < spec->autocfg.line_outs; i++)
35325eaba2fSLydia Wang 				snd_hda_codec_amp_update(
35425eaba2fSLydia Wang 					codec,
35525eaba2fSLydia Wang 					spec->autocfg.line_out_pins[i],
35625eaba2fSLydia Wang 					1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
35725eaba2fSLydia Wang 					rmute);
35825eaba2fSLydia Wang 			for (i = 0; i < spec->autocfg.speaker_outs; i++)
35925eaba2fSLydia Wang 				snd_hda_codec_amp_update(
36025eaba2fSLydia Wang 					codec,
36125eaba2fSLydia Wang 					spec->autocfg.speaker_pins[i],
36225eaba2fSLydia Wang 					1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
36325eaba2fSLydia Wang 					rmute);
36425eaba2fSLydia Wang 		}
36525eaba2fSLydia Wang 	}
36625eaba2fSLydia Wang 	return change;
36725eaba2fSLydia Wang }
36825eaba2fSLydia Wang 
36925eaba2fSLydia Wang #define BIND_PIN_MUTE							\
37025eaba2fSLydia Wang 	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
37125eaba2fSLydia Wang 			.name = NULL,					\
37225eaba2fSLydia Wang 			.index = 0,					\
37325eaba2fSLydia Wang 			.info = snd_hda_mixer_amp_switch_info,		\
37425eaba2fSLydia Wang 			.get = snd_hda_mixer_amp_switch_get,		\
37525eaba2fSLydia Wang 			.put = bind_pin_switch_put,			\
37625eaba2fSLydia Wang 			.private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
37725eaba2fSLydia Wang 
37871eb7dccSLydia Wang static struct snd_kcontrol_new via_control_templates[] = {
379c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
380c577b8a1SJoseph Chan 	HDA_CODEC_MUTE(NULL, 0, 0, 0),
381f5271101SLydia Wang 	ANALOG_INPUT_MUTE,
38225eaba2fSLydia Wang 	BIND_PIN_MUTE,
383c577b8a1SJoseph Chan };
384c577b8a1SJoseph Chan 
385c577b8a1SJoseph Chan static hda_nid_t vt1708_adc_nids[2] = {
386c577b8a1SJoseph Chan 	/* ADC1-2 */
387c577b8a1SJoseph Chan 	0x15, 0x27
388c577b8a1SJoseph Chan };
389c577b8a1SJoseph Chan 
390c577b8a1SJoseph Chan static hda_nid_t vt1709_adc_nids[3] = {
391c577b8a1SJoseph Chan 	/* ADC1-2 */
392c577b8a1SJoseph Chan 	0x14, 0x15, 0x16
393c577b8a1SJoseph Chan };
394c577b8a1SJoseph Chan 
395f7278fd0SJosepch Chan static hda_nid_t vt1708B_adc_nids[2] = {
396f7278fd0SJosepch Chan 	/* ADC1-2 */
397f7278fd0SJosepch Chan 	0x13, 0x14
398f7278fd0SJosepch Chan };
399f7278fd0SJosepch Chan 
400d949cac1SHarald Welte static hda_nid_t vt1708S_adc_nids[2] = {
401d949cac1SHarald Welte 	/* ADC1-2 */
402d949cac1SHarald Welte 	0x13, 0x14
403d949cac1SHarald Welte };
404d949cac1SHarald Welte 
405d949cac1SHarald Welte static hda_nid_t vt1702_adc_nids[3] = {
406d949cac1SHarald Welte 	/* ADC1-2 */
407d949cac1SHarald Welte 	0x12, 0x20, 0x1F
408d949cac1SHarald Welte };
409d949cac1SHarald Welte 
410eb7188caSLydia Wang static hda_nid_t vt1718S_adc_nids[2] = {
411eb7188caSLydia Wang 	/* ADC1-2 */
412eb7188caSLydia Wang 	0x10, 0x11
413eb7188caSLydia Wang };
414eb7188caSLydia Wang 
415f3db423dSLydia Wang static hda_nid_t vt1716S_adc_nids[2] = {
416f3db423dSLydia Wang 	/* ADC1-2 */
417f3db423dSLydia Wang 	0x13, 0x14
418f3db423dSLydia Wang };
419f3db423dSLydia Wang 
42025eaba2fSLydia Wang static hda_nid_t vt2002P_adc_nids[2] = {
42125eaba2fSLydia Wang 	/* ADC1-2 */
42225eaba2fSLydia Wang 	0x10, 0x11
42325eaba2fSLydia Wang };
42425eaba2fSLydia Wang 
425ab6734e7SLydia Wang static hda_nid_t vt1812_adc_nids[2] = {
426ab6734e7SLydia Wang 	/* ADC1-2 */
427ab6734e7SLydia Wang 	0x10, 0x11
428ab6734e7SLydia Wang };
429ab6734e7SLydia Wang 
430ab6734e7SLydia Wang 
431c577b8a1SJoseph Chan /* add dynamic controls */
432c577b8a1SJoseph Chan static int via_add_control(struct via_spec *spec, int type, const char *name,
433c577b8a1SJoseph Chan 			   unsigned long val)
434c577b8a1SJoseph Chan {
435c577b8a1SJoseph Chan 	struct snd_kcontrol_new *knew;
436c577b8a1SJoseph Chan 
437603c4019STakashi Iwai 	snd_array_init(&spec->kctls, sizeof(*knew), 32);
438603c4019STakashi Iwai 	knew = snd_array_new(&spec->kctls);
439c577b8a1SJoseph Chan 	if (!knew)
440c577b8a1SJoseph Chan 		return -ENOMEM;
44171eb7dccSLydia Wang 	*knew = via_control_templates[type];
442c577b8a1SJoseph Chan 	knew->name = kstrdup(name, GFP_KERNEL);
443c577b8a1SJoseph Chan 	if (!knew->name)
444c577b8a1SJoseph Chan 		return -ENOMEM;
445c577b8a1SJoseph Chan 	knew->private_value = val;
446c577b8a1SJoseph Chan 	return 0;
447c577b8a1SJoseph Chan }
448c577b8a1SJoseph Chan 
449603c4019STakashi Iwai static void via_free_kctls(struct hda_codec *codec)
450603c4019STakashi Iwai {
451603c4019STakashi Iwai 	struct via_spec *spec = codec->spec;
452603c4019STakashi Iwai 
453603c4019STakashi Iwai 	if (spec->kctls.list) {
454603c4019STakashi Iwai 		struct snd_kcontrol_new *kctl = spec->kctls.list;
455603c4019STakashi Iwai 		int i;
456603c4019STakashi Iwai 		for (i = 0; i < spec->kctls.used; i++)
457603c4019STakashi Iwai 			kfree(kctl[i].name);
458603c4019STakashi Iwai 	}
459603c4019STakashi Iwai 	snd_array_free(&spec->kctls);
460603c4019STakashi Iwai }
461603c4019STakashi Iwai 
462c577b8a1SJoseph Chan /* create input playback/capture controls for the given pin */
4639510e8ddSLydia Wang static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
4649510e8ddSLydia Wang 				int idx, int mix_nid)
465c577b8a1SJoseph Chan {
466c577b8a1SJoseph Chan 	char name[32];
467c577b8a1SJoseph Chan 	int err;
468c577b8a1SJoseph Chan 
469c577b8a1SJoseph Chan 	sprintf(name, "%s Playback Volume", ctlname);
470c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
471c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
472c577b8a1SJoseph Chan 	if (err < 0)
473c577b8a1SJoseph Chan 		return err;
474c577b8a1SJoseph Chan 	sprintf(name, "%s Playback Switch", ctlname);
475f5271101SLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
476c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
477c577b8a1SJoseph Chan 	if (err < 0)
478c577b8a1SJoseph Chan 		return err;
479c577b8a1SJoseph Chan 	return 0;
480c577b8a1SJoseph Chan }
481c577b8a1SJoseph Chan 
482c577b8a1SJoseph Chan static void via_auto_set_output_and_unmute(struct hda_codec *codec,
483c577b8a1SJoseph Chan 					   hda_nid_t nid, int pin_type,
484c577b8a1SJoseph Chan 					   int dac_idx)
485c577b8a1SJoseph Chan {
486c577b8a1SJoseph Chan 	/* set as output */
487c577b8a1SJoseph Chan 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
488c577b8a1SJoseph Chan 			    pin_type);
489c577b8a1SJoseph Chan 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
490c577b8a1SJoseph Chan 			    AMP_OUT_UNMUTE);
491d3a11e60STakashi Iwai 	if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
492d3a11e60STakashi Iwai 		snd_hda_codec_write(codec, nid, 0,
493d3a11e60STakashi Iwai 				    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
494c577b8a1SJoseph Chan }
495c577b8a1SJoseph Chan 
496c577b8a1SJoseph Chan 
497c577b8a1SJoseph Chan static void via_auto_init_multi_out(struct hda_codec *codec)
498c577b8a1SJoseph Chan {
499c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
500c577b8a1SJoseph Chan 	int i;
501c577b8a1SJoseph Chan 
502c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
503c577b8a1SJoseph Chan 		hda_nid_t nid = spec->autocfg.line_out_pins[i];
504c577b8a1SJoseph Chan 		if (nid)
505c577b8a1SJoseph Chan 			via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
506c577b8a1SJoseph Chan 	}
507c577b8a1SJoseph Chan }
508c577b8a1SJoseph Chan 
509c577b8a1SJoseph Chan static void via_auto_init_hp_out(struct hda_codec *codec)
510c577b8a1SJoseph Chan {
511c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
512c577b8a1SJoseph Chan 	hda_nid_t pin;
51325eaba2fSLydia Wang 	int i;
514c577b8a1SJoseph Chan 
51525eaba2fSLydia Wang 	for (i = 0; i < spec->autocfg.hp_outs; i++) {
51625eaba2fSLydia Wang 		pin = spec->autocfg.hp_pins[i];
517c577b8a1SJoseph Chan 		if (pin) /* connect to front */
518c577b8a1SJoseph Chan 			via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
519c577b8a1SJoseph Chan 	}
52025eaba2fSLydia Wang }
521c577b8a1SJoseph Chan 
522c577b8a1SJoseph Chan static void via_auto_init_analog_input(struct hda_codec *codec)
523c577b8a1SJoseph Chan {
524c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
525c577b8a1SJoseph Chan 	int i;
526c577b8a1SJoseph Chan 
527c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
528c577b8a1SJoseph Chan 		hda_nid_t nid = spec->autocfg.input_pins[i];
529c577b8a1SJoseph Chan 
530c577b8a1SJoseph Chan 		snd_hda_codec_write(codec, nid, 0,
531c577b8a1SJoseph Chan 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
532c577b8a1SJoseph Chan 				    (i <= AUTO_PIN_FRONT_MIC ?
533c577b8a1SJoseph Chan 				     PIN_VREF50 : PIN_IN));
534c577b8a1SJoseph Chan 
535c577b8a1SJoseph Chan 	}
536c577b8a1SJoseph Chan }
537f5271101SLydia Wang 
5381564b287SLydia Wang static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
5391564b287SLydia Wang 
540f5271101SLydia Wang static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
541f5271101SLydia Wang 				unsigned int *affected_parm)
542f5271101SLydia Wang {
543f5271101SLydia Wang 	unsigned parm;
544f5271101SLydia Wang 	unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
545f5271101SLydia Wang 	unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
546f5271101SLydia Wang 		>> AC_DEFCFG_MISC_SHIFT
547f5271101SLydia Wang 		& AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
548f5271101SLydia Wang 	unsigned present = snd_hda_codec_read(codec, nid, 0,
549f5271101SLydia Wang 					      AC_VERB_GET_PIN_SENSE, 0) >> 31;
5501564b287SLydia Wang 	struct via_spec *spec = codec->spec;
5511564b287SLydia Wang 	if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
5521564b287SLydia Wang 	    || ((no_presence || present)
5531564b287SLydia Wang 		&& get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
554f5271101SLydia Wang 		*affected_parm = AC_PWRST_D0; /* if it's connected */
555f5271101SLydia Wang 		parm = AC_PWRST_D0;
556f5271101SLydia Wang 	} else
557f5271101SLydia Wang 		parm = AC_PWRST_D3;
558f5271101SLydia Wang 
559f5271101SLydia Wang 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
560f5271101SLydia Wang }
561f5271101SLydia Wang 
562f5271101SLydia Wang static void set_jack_power_state(struct hda_codec *codec)
563f5271101SLydia Wang {
564f5271101SLydia Wang 	struct via_spec *spec = codec->spec;
565f5271101SLydia Wang 	int imux_is_smixer;
566f5271101SLydia Wang 	unsigned int parm;
567f5271101SLydia Wang 
568f5271101SLydia Wang 	if (spec->codec_type == VT1702) {
569f5271101SLydia Wang 		imux_is_smixer = snd_hda_codec_read(
570f5271101SLydia Wang 			codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
571f5271101SLydia Wang 		/* inputs */
572f5271101SLydia Wang 		/* PW 1/2/5 (14h/15h/18h) */
573f5271101SLydia Wang 		parm = AC_PWRST_D3;
574f5271101SLydia Wang 		set_pin_power_state(codec, 0x14, &parm);
575f5271101SLydia Wang 		set_pin_power_state(codec, 0x15, &parm);
576f5271101SLydia Wang 		set_pin_power_state(codec, 0x18, &parm);
577f5271101SLydia Wang 		if (imux_is_smixer)
578f5271101SLydia Wang 			parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
579f5271101SLydia Wang 		/* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
580f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
581f5271101SLydia Wang 				    parm);
582f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
583f5271101SLydia Wang 				    parm);
584f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
585f5271101SLydia Wang 				    parm);
586f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
587f5271101SLydia Wang 				    parm);
588f5271101SLydia Wang 
589f5271101SLydia Wang 		/* outputs */
590f5271101SLydia Wang 		/* PW 3/4 (16h/17h) */
591f5271101SLydia Wang 		parm = AC_PWRST_D3;
592f5271101SLydia Wang 		set_pin_power_state(codec, 0x16, &parm);
593f5271101SLydia Wang 		set_pin_power_state(codec, 0x17, &parm);
594f5271101SLydia Wang 		/* MW0 (1ah), AOW 0/1 (10h/1dh) */
595f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
596f5271101SLydia Wang 				    imux_is_smixer ? AC_PWRST_D0 : parm);
597f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
598f5271101SLydia Wang 				    parm);
599f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
600f5271101SLydia Wang 				    parm);
601f5271101SLydia Wang 	} else if (spec->codec_type == VT1708B_8CH
602f5271101SLydia Wang 		   || spec->codec_type == VT1708B_4CH
603f5271101SLydia Wang 		   || spec->codec_type == VT1708S) {
604f5271101SLydia Wang 		/* SW0 (17h) = stereo mixer */
605f5271101SLydia Wang 		int is_8ch = spec->codec_type != VT1708B_4CH;
606f5271101SLydia Wang 		imux_is_smixer = snd_hda_codec_read(
607f5271101SLydia Wang 			codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
608f5271101SLydia Wang 			== ((spec->codec_type == VT1708S)  ? 5 : 0);
609f5271101SLydia Wang 		/* inputs */
610f5271101SLydia Wang 		/* PW 1/2/5 (1ah/1bh/1eh) */
611f5271101SLydia Wang 		parm = AC_PWRST_D3;
612f5271101SLydia Wang 		set_pin_power_state(codec, 0x1a, &parm);
613f5271101SLydia Wang 		set_pin_power_state(codec, 0x1b, &parm);
614f5271101SLydia Wang 		set_pin_power_state(codec, 0x1e, &parm);
615f5271101SLydia Wang 		if (imux_is_smixer)
616f5271101SLydia Wang 			parm = AC_PWRST_D0;
617f5271101SLydia Wang 		/* SW0 (17h), AIW 0/1 (13h/14h) */
618f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
619f5271101SLydia Wang 				    parm);
620f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
621f5271101SLydia Wang 				    parm);
622f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
623f5271101SLydia Wang 				    parm);
624f5271101SLydia Wang 
625f5271101SLydia Wang 		/* outputs */
626f5271101SLydia Wang 		/* PW0 (19h), SW1 (18h), AOW1 (11h) */
627f5271101SLydia Wang 		parm = AC_PWRST_D3;
628f5271101SLydia Wang 		set_pin_power_state(codec, 0x19, &parm);
629f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
630f5271101SLydia Wang 				    parm);
631f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
632f5271101SLydia Wang 				    parm);
633f5271101SLydia Wang 
634f5271101SLydia Wang 		/* PW6 (22h), SW2 (26h), AOW2 (24h) */
635f5271101SLydia Wang 		if (is_8ch) {
636f5271101SLydia Wang 			parm = AC_PWRST_D3;
637f5271101SLydia Wang 			set_pin_power_state(codec, 0x22, &parm);
638f5271101SLydia Wang 			snd_hda_codec_write(codec, 0x26, 0,
639f5271101SLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
640f5271101SLydia Wang 			snd_hda_codec_write(codec, 0x24, 0,
641f5271101SLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
642f5271101SLydia Wang 		}
643f5271101SLydia Wang 
644f5271101SLydia Wang 		/* PW 3/4/7 (1ch/1dh/23h) */
645f5271101SLydia Wang 		parm = AC_PWRST_D3;
646f5271101SLydia Wang 		/* force to D0 for internal Speaker */
647f5271101SLydia Wang 		set_pin_power_state(codec, 0x1c, &parm);
648f5271101SLydia Wang 		set_pin_power_state(codec, 0x1d, &parm);
649f5271101SLydia Wang 		if (is_8ch)
650f5271101SLydia Wang 			set_pin_power_state(codec, 0x23, &parm);
651f5271101SLydia Wang 		/* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
652f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
653f5271101SLydia Wang 				    imux_is_smixer ? AC_PWRST_D0 : parm);
654f5271101SLydia Wang 		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
655f5271101SLydia Wang 				    parm);
656f5271101SLydia Wang 		if (is_8ch) {
657f5271101SLydia Wang 			snd_hda_codec_write(codec, 0x25, 0,
658f5271101SLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
659f5271101SLydia Wang 			snd_hda_codec_write(codec, 0x27, 0,
660f5271101SLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
661f5271101SLydia Wang 		}
662eb7188caSLydia Wang 	}  else if (spec->codec_type == VT1718S) {
663eb7188caSLydia Wang 		/* MUX6 (1eh) = stereo mixer */
664eb7188caSLydia Wang 		imux_is_smixer = snd_hda_codec_read(
665eb7188caSLydia Wang 			codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
666eb7188caSLydia Wang 		/* inputs */
667eb7188caSLydia Wang 		/* PW 5/6/7 (29h/2ah/2bh) */
668eb7188caSLydia Wang 		parm = AC_PWRST_D3;
669eb7188caSLydia Wang 		set_pin_power_state(codec, 0x29, &parm);
670eb7188caSLydia Wang 		set_pin_power_state(codec, 0x2a, &parm);
671eb7188caSLydia Wang 		set_pin_power_state(codec, 0x2b, &parm);
672eb7188caSLydia Wang 		if (imux_is_smixer)
673eb7188caSLydia Wang 			parm = AC_PWRST_D0;
674eb7188caSLydia Wang 		/* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
675eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
676eb7188caSLydia Wang 				    parm);
677eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
678eb7188caSLydia Wang 				    parm);
679eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
680eb7188caSLydia Wang 				    parm);
681eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
682eb7188caSLydia Wang 				    parm);
683eb7188caSLydia Wang 
684eb7188caSLydia Wang 		/* outputs */
685eb7188caSLydia Wang 		/* PW3 (27h), MW2 (1ah), AOW3 (bh) */
686eb7188caSLydia Wang 		parm = AC_PWRST_D3;
687eb7188caSLydia Wang 		set_pin_power_state(codec, 0x27, &parm);
688eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
689eb7188caSLydia Wang 				    parm);
690eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
691eb7188caSLydia Wang 				    parm);
692eb7188caSLydia Wang 
693eb7188caSLydia Wang 		/* PW2 (26h), AOW2 (ah) */
694eb7188caSLydia Wang 		parm = AC_PWRST_D3;
695eb7188caSLydia Wang 		set_pin_power_state(codec, 0x26, &parm);
696eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
697eb7188caSLydia Wang 				    parm);
698eb7188caSLydia Wang 
699eb7188caSLydia Wang 		/* PW0/1 (24h/25h) */
700eb7188caSLydia Wang 		parm = AC_PWRST_D3;
701eb7188caSLydia Wang 		set_pin_power_state(codec, 0x24, &parm);
702eb7188caSLydia Wang 		set_pin_power_state(codec, 0x25, &parm);
703eb7188caSLydia Wang 		if (!spec->hp_independent_mode) /* check for redirected HP */
704eb7188caSLydia Wang 			set_pin_power_state(codec, 0x28, &parm);
705eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
706eb7188caSLydia Wang 				    parm);
707eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
708eb7188caSLydia Wang 				    parm);
709eb7188caSLydia Wang 		/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
710eb7188caSLydia Wang 		snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
711eb7188caSLydia Wang 				    imux_is_smixer ? AC_PWRST_D0 : parm);
712eb7188caSLydia Wang 		if (spec->hp_independent_mode) {
713eb7188caSLydia Wang 			/* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
714eb7188caSLydia Wang 			parm = AC_PWRST_D3;
715eb7188caSLydia Wang 			set_pin_power_state(codec, 0x28, &parm);
716eb7188caSLydia Wang 			snd_hda_codec_write(codec, 0x1b, 0,
717eb7188caSLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
718eb7188caSLydia Wang 			snd_hda_codec_write(codec, 0x34, 0,
719eb7188caSLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
720eb7188caSLydia Wang 			snd_hda_codec_write(codec, 0xc, 0,
721eb7188caSLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
722eb7188caSLydia Wang 		}
723f3db423dSLydia Wang 	} else if (spec->codec_type == VT1716S) {
724f3db423dSLydia Wang 		unsigned int mono_out, present;
725f3db423dSLydia Wang 		/* SW0 (17h) = stereo mixer */
726f3db423dSLydia Wang 		imux_is_smixer = snd_hda_codec_read(
727f3db423dSLydia Wang 			codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) ==  5;
728f3db423dSLydia Wang 		/* inputs */
729f3db423dSLydia Wang 		/* PW 1/2/5 (1ah/1bh/1eh) */
730f3db423dSLydia Wang 		parm = AC_PWRST_D3;
731f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1a, &parm);
732f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1b, &parm);
733f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1e, &parm);
734f3db423dSLydia Wang 		if (imux_is_smixer)
735f3db423dSLydia Wang 			parm = AC_PWRST_D0;
736f3db423dSLydia Wang 		/* SW0 (17h), AIW0(13h) */
737f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
738f3db423dSLydia Wang 				    parm);
739f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
740f3db423dSLydia Wang 				    parm);
741f3db423dSLydia Wang 
742f3db423dSLydia Wang 		parm = AC_PWRST_D3;
743f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1e, &parm);
744f3db423dSLydia Wang 		/* PW11 (22h) */
745f3db423dSLydia Wang 		if (spec->dmic_enabled)
746f3db423dSLydia Wang 			set_pin_power_state(codec, 0x22, &parm);
747f3db423dSLydia Wang 		else
748f3db423dSLydia Wang 			snd_hda_codec_write(
749f3db423dSLydia Wang 				codec, 0x22, 0,
750f3db423dSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
751f3db423dSLydia Wang 
752f3db423dSLydia Wang 		/* SW2(26h), AIW1(14h) */
753f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
754f3db423dSLydia Wang 				    parm);
755f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
756f3db423dSLydia Wang 				    parm);
757f3db423dSLydia Wang 
758f3db423dSLydia Wang 		/* outputs */
759f3db423dSLydia Wang 		/* PW0 (19h), SW1 (18h), AOW1 (11h) */
760f3db423dSLydia Wang 		parm = AC_PWRST_D3;
761f3db423dSLydia Wang 		set_pin_power_state(codec, 0x19, &parm);
762f3db423dSLydia Wang 		/* Smart 5.1 PW2(1bh) */
763f3db423dSLydia Wang 		if (spec->smart51_enabled)
764f3db423dSLydia Wang 			set_pin_power_state(codec, 0x1b, &parm);
765f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
766f3db423dSLydia Wang 				    parm);
767f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
768f3db423dSLydia Wang 				    parm);
769f3db423dSLydia Wang 
770f3db423dSLydia Wang 		/* PW7 (23h), SW3 (27h), AOW3 (25h) */
771f3db423dSLydia Wang 		parm = AC_PWRST_D3;
772f3db423dSLydia Wang 		set_pin_power_state(codec, 0x23, &parm);
773f3db423dSLydia Wang 		/* Smart 5.1 PW1(1ah) */
774f3db423dSLydia Wang 		if (spec->smart51_enabled)
775f3db423dSLydia Wang 			set_pin_power_state(codec, 0x1a, &parm);
776f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
777f3db423dSLydia Wang 				    parm);
778f3db423dSLydia Wang 
779f3db423dSLydia Wang 		/* Smart 5.1 PW5(1eh) */
780f3db423dSLydia Wang 		if (spec->smart51_enabled)
781f3db423dSLydia Wang 			set_pin_power_state(codec, 0x1e, &parm);
782f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
783f3db423dSLydia Wang 				    parm);
784f3db423dSLydia Wang 
785f3db423dSLydia Wang 		/* Mono out */
786f3db423dSLydia Wang 		/* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
787f3db423dSLydia Wang 		present = snd_hda_codec_read(
788f3db423dSLydia Wang 			codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
789f3db423dSLydia Wang 		if (present)
790f3db423dSLydia Wang 			mono_out = 0;
791f3db423dSLydia Wang 		else {
792f3db423dSLydia Wang 			present = snd_hda_codec_read(
793f3db423dSLydia Wang 				codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
794f3db423dSLydia Wang 				& 0x80000000;
795f3db423dSLydia Wang 			if (!spec->hp_independent_mode && present)
796f3db423dSLydia Wang 				mono_out = 0;
797f3db423dSLydia Wang 			else
798f3db423dSLydia Wang 				mono_out = 1;
799f3db423dSLydia Wang 		}
800f3db423dSLydia Wang 		parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
801f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
802f3db423dSLydia Wang 				    parm);
803f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
804f3db423dSLydia Wang 				    parm);
805f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
806f3db423dSLydia Wang 				    parm);
807f3db423dSLydia Wang 
808f3db423dSLydia Wang 		/* PW 3/4 (1ch/1dh) */
809f3db423dSLydia Wang 		parm = AC_PWRST_D3;
810f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1c, &parm);
811f3db423dSLydia Wang 		set_pin_power_state(codec, 0x1d, &parm);
812f3db423dSLydia Wang 		/* HP Independent Mode, power on AOW3 */
813f3db423dSLydia Wang 		if (spec->hp_independent_mode)
814f3db423dSLydia Wang 			snd_hda_codec_write(codec, 0x25, 0,
815f3db423dSLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
816f3db423dSLydia Wang 
817f3db423dSLydia Wang 		/* force to D0 for internal Speaker */
818f3db423dSLydia Wang 		/* MW0 (16h), AOW0 (10h) */
819f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
820f3db423dSLydia Wang 				    imux_is_smixer ? AC_PWRST_D0 : parm);
821f3db423dSLydia Wang 		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
822f3db423dSLydia Wang 				    mono_out ? AC_PWRST_D0 : parm);
82325eaba2fSLydia Wang 	} else if (spec->codec_type == VT2002P) {
82425eaba2fSLydia Wang 		unsigned int present;
82525eaba2fSLydia Wang 		/* MUX9 (1eh) = stereo mixer */
82625eaba2fSLydia Wang 		imux_is_smixer = snd_hda_codec_read(
82725eaba2fSLydia Wang 			codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
82825eaba2fSLydia Wang 		/* inputs */
82925eaba2fSLydia Wang 		/* PW 5/6/7 (29h/2ah/2bh) */
83025eaba2fSLydia Wang 		parm = AC_PWRST_D3;
83125eaba2fSLydia Wang 		set_pin_power_state(codec, 0x29, &parm);
83225eaba2fSLydia Wang 		set_pin_power_state(codec, 0x2a, &parm);
83325eaba2fSLydia Wang 		set_pin_power_state(codec, 0x2b, &parm);
83425eaba2fSLydia Wang 		if (imux_is_smixer)
83525eaba2fSLydia Wang 			parm = AC_PWRST_D0;
83625eaba2fSLydia Wang 		/* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
83725eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x1e, 0,
83825eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
83925eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x1f, 0,
84025eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
84125eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x10, 0,
84225eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
84325eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x11, 0,
84425eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
84525eaba2fSLydia Wang 
84625eaba2fSLydia Wang 		/* outputs */
84725eaba2fSLydia Wang 		/* AOW0 (8h)*/
84825eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x8, 0,
84925eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
85025eaba2fSLydia Wang 
85125eaba2fSLydia Wang 		/* PW4 (26h), MW4 (1ch), MUX4(37h) */
85225eaba2fSLydia Wang 		parm = AC_PWRST_D3;
85325eaba2fSLydia Wang 		set_pin_power_state(codec, 0x26, &parm);
85425eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x1c, 0,
85525eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
85625eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x37,
85725eaba2fSLydia Wang 				    0, AC_VERB_SET_POWER_STATE, parm);
85825eaba2fSLydia Wang 
85925eaba2fSLydia Wang 		/* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
86025eaba2fSLydia Wang 		parm = AC_PWRST_D3;
86125eaba2fSLydia Wang 		set_pin_power_state(codec, 0x25, &parm);
86225eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x19, 0,
86325eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
86425eaba2fSLydia Wang 		snd_hda_codec_write(codec, 0x35, 0,
86525eaba2fSLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
86625eaba2fSLydia Wang 		if (spec->hp_independent_mode)	{
86725eaba2fSLydia Wang 			snd_hda_codec_write(codec, 0x9, 0,
86825eaba2fSLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
86925eaba2fSLydia Wang 		}
87025eaba2fSLydia Wang 
87125eaba2fSLydia Wang 		/* Class-D */
87225eaba2fSLydia Wang 		/* PW0 (24h), MW0(18h), MUX0(34h) */
87325eaba2fSLydia Wang 		present = snd_hda_codec_read(
87425eaba2fSLydia Wang 			codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
87525eaba2fSLydia Wang 		parm = AC_PWRST_D3;
87625eaba2fSLydia Wang 		set_pin_power_state(codec, 0x24, &parm);
87725eaba2fSLydia Wang 		if (present) {
87825eaba2fSLydia Wang 			snd_hda_codec_write(
87925eaba2fSLydia Wang 				codec, 0x18, 0,
88025eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
88125eaba2fSLydia Wang 			snd_hda_codec_write(
88225eaba2fSLydia Wang 				codec, 0x34, 0,
88325eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
88425eaba2fSLydia Wang 		} else {
88525eaba2fSLydia Wang 			snd_hda_codec_write(
88625eaba2fSLydia Wang 				codec, 0x18, 0,
88725eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
88825eaba2fSLydia Wang 			snd_hda_codec_write(
88925eaba2fSLydia Wang 				codec, 0x34, 0,
89025eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
89125eaba2fSLydia Wang 		}
89225eaba2fSLydia Wang 
89325eaba2fSLydia Wang 		/* Mono Out */
89425eaba2fSLydia Wang 		/* PW15 (31h), MW8(17h), MUX8(3bh) */
89525eaba2fSLydia Wang 		present = snd_hda_codec_read(
89625eaba2fSLydia Wang 			codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
89725eaba2fSLydia Wang 		parm = AC_PWRST_D3;
89825eaba2fSLydia Wang 		set_pin_power_state(codec, 0x31, &parm);
89925eaba2fSLydia Wang 		if (present) {
90025eaba2fSLydia Wang 			snd_hda_codec_write(
90125eaba2fSLydia Wang 				codec, 0x17, 0,
90225eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
90325eaba2fSLydia Wang 			snd_hda_codec_write(
90425eaba2fSLydia Wang 				codec, 0x3b, 0,
90525eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
90625eaba2fSLydia Wang 		} else {
90725eaba2fSLydia Wang 			snd_hda_codec_write(
90825eaba2fSLydia Wang 				codec, 0x17, 0,
90925eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
91025eaba2fSLydia Wang 			snd_hda_codec_write(
91125eaba2fSLydia Wang 				codec, 0x3b, 0,
91225eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
91325eaba2fSLydia Wang 		}
91425eaba2fSLydia Wang 
91525eaba2fSLydia Wang 		/* MW9 (21h) */
91625eaba2fSLydia Wang 		if (imux_is_smixer || !is_aa_path_mute(codec))
91725eaba2fSLydia Wang 			snd_hda_codec_write(
91825eaba2fSLydia Wang 				codec, 0x21, 0,
91925eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
92025eaba2fSLydia Wang 		else
92125eaba2fSLydia Wang 			snd_hda_codec_write(
92225eaba2fSLydia Wang 				codec, 0x21, 0,
92325eaba2fSLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
924ab6734e7SLydia Wang 	} else if (spec->codec_type == VT1812) {
925ab6734e7SLydia Wang 		unsigned int present;
926ab6734e7SLydia Wang 		/* MUX10 (1eh) = stereo mixer */
927ab6734e7SLydia Wang 		imux_is_smixer = snd_hda_codec_read(
928ab6734e7SLydia Wang 			codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
929ab6734e7SLydia Wang 		/* inputs */
930ab6734e7SLydia Wang 		/* PW 5/6/7 (29h/2ah/2bh) */
931ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
932ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x29, &parm);
933ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x2a, &parm);
934ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x2b, &parm);
935ab6734e7SLydia Wang 		if (imux_is_smixer)
936ab6734e7SLydia Wang 			parm = AC_PWRST_D0;
937ab6734e7SLydia Wang 		/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
938ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x1e, 0,
939ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
940ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x1f, 0,
941ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
942ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x10, 0,
943ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
944ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x11, 0,
945ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
946ab6734e7SLydia Wang 
947ab6734e7SLydia Wang 		/* outputs */
948ab6734e7SLydia Wang 		/* AOW0 (8h)*/
949ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x8, 0,
950ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
951ab6734e7SLydia Wang 
952ab6734e7SLydia Wang 		/* PW4 (28h), MW4 (18h), MUX4(38h) */
953ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
954ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x28, &parm);
955ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x18, 0,
956ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
957ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x38, 0,
958ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
959ab6734e7SLydia Wang 
960ab6734e7SLydia Wang 		/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
961ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
962ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x25, &parm);
963ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x15, 0,
964ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
965ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x35, 0,
966ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
967ab6734e7SLydia Wang 		if (spec->hp_independent_mode)	{
968ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x9, 0,
969ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE, parm);
970ab6734e7SLydia Wang 		}
971ab6734e7SLydia Wang 
972ab6734e7SLydia Wang 		/* Internal Speaker */
973ab6734e7SLydia Wang 		/* PW0 (24h), MW0(14h), MUX0(34h) */
974ab6734e7SLydia Wang 		present = snd_hda_codec_read(
975ab6734e7SLydia Wang 			codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
976ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
977ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x24, &parm);
978ab6734e7SLydia Wang 		if (present) {
979ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x14, 0,
980ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
981ab6734e7SLydia Wang 					    AC_PWRST_D3);
982ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x34, 0,
983ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
984ab6734e7SLydia Wang 					    AC_PWRST_D3);
985ab6734e7SLydia Wang 		} else {
986ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x14, 0,
987ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
988ab6734e7SLydia Wang 					    AC_PWRST_D0);
989ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x34, 0,
990ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
991ab6734e7SLydia Wang 					    AC_PWRST_D0);
992ab6734e7SLydia Wang 		}
993ab6734e7SLydia Wang 		/* Mono Out */
994ab6734e7SLydia Wang 		/* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
995ab6734e7SLydia Wang 		present = snd_hda_codec_read(
996ab6734e7SLydia Wang 			codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
997ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
998ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x31, &parm);
999ab6734e7SLydia Wang 		if (present) {
1000ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x1c, 0,
1001ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1002ab6734e7SLydia Wang 					    AC_PWRST_D3);
1003ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x3c, 0,
1004ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1005ab6734e7SLydia Wang 					    AC_PWRST_D3);
1006ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x3e, 0,
1007ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1008ab6734e7SLydia Wang 					    AC_PWRST_D3);
1009ab6734e7SLydia Wang 		} else {
1010ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x1c, 0,
1011ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1012ab6734e7SLydia Wang 					    AC_PWRST_D0);
1013ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x3c, 0,
1014ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1015ab6734e7SLydia Wang 					    AC_PWRST_D0);
1016ab6734e7SLydia Wang 			snd_hda_codec_write(codec, 0x3e, 0,
1017ab6734e7SLydia Wang 					    AC_VERB_SET_POWER_STATE,
1018ab6734e7SLydia Wang 					    AC_PWRST_D0);
1019ab6734e7SLydia Wang 		}
1020ab6734e7SLydia Wang 
1021ab6734e7SLydia Wang 		/* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1022ab6734e7SLydia Wang 		parm = AC_PWRST_D3;
1023ab6734e7SLydia Wang 		set_pin_power_state(codec, 0x33, &parm);
1024ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x1d, 0,
1025ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
1026ab6734e7SLydia Wang 		snd_hda_codec_write(codec, 0x3d, 0,
1027ab6734e7SLydia Wang 				    AC_VERB_SET_POWER_STATE, parm);
1028ab6734e7SLydia Wang 
1029ab6734e7SLydia Wang 		/* MW9 (21h) */
1030ab6734e7SLydia Wang 		if (imux_is_smixer || !is_aa_path_mute(codec))
1031ab6734e7SLydia Wang 			snd_hda_codec_write(
1032ab6734e7SLydia Wang 				codec, 0x21, 0,
1033ab6734e7SLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1034ab6734e7SLydia Wang 		else
1035ab6734e7SLydia Wang 			snd_hda_codec_write(
1036ab6734e7SLydia Wang 				codec, 0x21, 0,
1037ab6734e7SLydia Wang 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1038f5271101SLydia Wang 	}
1039f5271101SLydia Wang }
1040f5271101SLydia Wang 
1041c577b8a1SJoseph Chan /*
1042c577b8a1SJoseph Chan  * input MUX handling
1043c577b8a1SJoseph Chan  */
1044c577b8a1SJoseph Chan static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1045c577b8a1SJoseph Chan 			     struct snd_ctl_elem_info *uinfo)
1046c577b8a1SJoseph Chan {
1047c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1048c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1049c577b8a1SJoseph Chan 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
1050c577b8a1SJoseph Chan }
1051c577b8a1SJoseph Chan 
1052c577b8a1SJoseph Chan static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1053c577b8a1SJoseph Chan 			    struct snd_ctl_elem_value *ucontrol)
1054c577b8a1SJoseph Chan {
1055c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1056c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1057c577b8a1SJoseph Chan 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1058c577b8a1SJoseph Chan 
1059c577b8a1SJoseph Chan 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1060c577b8a1SJoseph Chan 	return 0;
1061c577b8a1SJoseph Chan }
1062c577b8a1SJoseph Chan 
1063c577b8a1SJoseph Chan static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1064c577b8a1SJoseph Chan 			    struct snd_ctl_elem_value *ucontrol)
1065c577b8a1SJoseph Chan {
1066c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1067c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1068c577b8a1SJoseph Chan 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1069c577b8a1SJoseph Chan 
1070337b9d02STakashi Iwai 	if (!spec->mux_nids[adc_idx])
1071337b9d02STakashi Iwai 		return -EINVAL;
1072a80e6e3cSLydia Wang 	/* switch to D0 beofre change index */
1073a80e6e3cSLydia Wang 	if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1074a80e6e3cSLydia Wang 			       AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1075a80e6e3cSLydia Wang 		snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1076a80e6e3cSLydia Wang 				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1077a80e6e3cSLydia Wang 	/* update jack power state */
1078a80e6e3cSLydia Wang 	set_jack_power_state(codec);
1079a80e6e3cSLydia Wang 
1080c577b8a1SJoseph Chan 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1081337b9d02STakashi Iwai 				     spec->mux_nids[adc_idx],
1082c577b8a1SJoseph Chan 				     &spec->cur_mux[adc_idx]);
1083c577b8a1SJoseph Chan }
1084c577b8a1SJoseph Chan 
10850aa62aefSHarald Welte static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
10860aa62aefSHarald Welte 				   struct snd_ctl_elem_info *uinfo)
10870aa62aefSHarald Welte {
10880aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10890aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
10900aa62aefSHarald Welte 	return snd_hda_input_mux_info(spec->hp_mux, uinfo);
10910aa62aefSHarald Welte }
10920aa62aefSHarald Welte 
10930aa62aefSHarald Welte static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
10940aa62aefSHarald Welte 				  struct snd_ctl_elem_value *ucontrol)
10950aa62aefSHarald Welte {
10960aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10970aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
1098eb7188caSLydia Wang 	hda_nid_t nid;
1099eb7188caSLydia Wang 	unsigned int pinsel;
1100eb7188caSLydia Wang 
1101eb7188caSLydia Wang 	switch (spec->codec_type) {
1102eb7188caSLydia Wang 	case VT1718S:
1103eb7188caSLydia Wang 		nid = 0x34;
1104eb7188caSLydia Wang 		break;
110525eaba2fSLydia Wang 	case VT2002P:
110625eaba2fSLydia Wang 		nid = 0x35;
110725eaba2fSLydia Wang 		break;
1108ab6734e7SLydia Wang 	case VT1812:
1109ab6734e7SLydia Wang 		nid = 0x3d;
1110ab6734e7SLydia Wang 		break;
1111eb7188caSLydia Wang 	default:
1112eb7188caSLydia Wang 		nid = spec->autocfg.hp_pins[0];
1113eb7188caSLydia Wang 		break;
1114eb7188caSLydia Wang 	}
1115eb7188caSLydia Wang 	/* use !! to translate conn sel 2 for VT1718S */
1116eb7188caSLydia Wang 	pinsel = !!snd_hda_codec_read(codec, nid, 0,
11170aa62aefSHarald Welte 				      AC_VERB_GET_CONNECT_SEL,
11180aa62aefSHarald Welte 				      0x00);
11190aa62aefSHarald Welte 	ucontrol->value.enumerated.item[0] = pinsel;
11200aa62aefSHarald Welte 
11210aa62aefSHarald Welte 	return 0;
11220aa62aefSHarald Welte }
11230aa62aefSHarald Welte 
11240713efebSLydia Wang static void activate_ctl(struct hda_codec *codec, const char *name, int active)
11250713efebSLydia Wang {
11260713efebSLydia Wang 	struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
11270713efebSLydia Wang 	if (ctl) {
11280713efebSLydia Wang 		ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
11290713efebSLydia Wang 		ctl->vd[0].access |= active
11300713efebSLydia Wang 			? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
11310713efebSLydia Wang 		snd_ctl_notify(codec->bus->card,
11320713efebSLydia Wang 			       SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
11330713efebSLydia Wang 	}
11340713efebSLydia Wang }
11350713efebSLydia Wang 
1136cdc1784dSLydia Wang static int update_side_mute_status(struct hda_codec *codec)
1137cdc1784dSLydia Wang {
1138cdc1784dSLydia Wang 	/* mute side channel */
1139cdc1784dSLydia Wang 	struct via_spec *spec = codec->spec;
1140cdc1784dSLydia Wang 	unsigned int parm = spec->hp_independent_mode
1141cdc1784dSLydia Wang 		? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1142cdc1784dSLydia Wang 	hda_nid_t sw3;
1143cdc1784dSLydia Wang 
1144cdc1784dSLydia Wang 	switch (spec->codec_type) {
1145cdc1784dSLydia Wang 	case VT1708:
1146cdc1784dSLydia Wang 		sw3 = 0x1b;
1147cdc1784dSLydia Wang 		break;
1148cdc1784dSLydia Wang 	case VT1709_10CH:
1149cdc1784dSLydia Wang 		sw3 = 0x29;
1150cdc1784dSLydia Wang 		break;
1151cdc1784dSLydia Wang 	case VT1708B_8CH:
1152cdc1784dSLydia Wang 	case VT1708S:
1153cdc1784dSLydia Wang 		sw3 = 0x27;
1154cdc1784dSLydia Wang 		break;
1155cdc1784dSLydia Wang 	default:
1156cdc1784dSLydia Wang 		sw3 = 0;
1157cdc1784dSLydia Wang 		break;
1158cdc1784dSLydia Wang 	}
1159cdc1784dSLydia Wang 
1160cdc1784dSLydia Wang 	if (sw3)
1161cdc1784dSLydia Wang 		snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1162cdc1784dSLydia Wang 				    parm);
1163cdc1784dSLydia Wang 	return 0;
1164cdc1784dSLydia Wang }
1165cdc1784dSLydia Wang 
11660aa62aefSHarald Welte static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
11670aa62aefSHarald Welte 				  struct snd_ctl_elem_value *ucontrol)
11680aa62aefSHarald Welte {
11690aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11700aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
11710aa62aefSHarald Welte 	hda_nid_t nid = spec->autocfg.hp_pins[0];
11720aa62aefSHarald Welte 	unsigned int pinsel = ucontrol->value.enumerated.item[0];
1173cdc1784dSLydia Wang 	/* Get Independent Mode index of headphone pin widget */
1174cdc1784dSLydia Wang 	spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1175cdc1784dSLydia Wang 		? 1 : 0;
11760aa62aefSHarald Welte 
1177eb7188caSLydia Wang 	switch (spec->codec_type) {
1178eb7188caSLydia Wang 	case VT1718S:
1179eb7188caSLydia Wang 		nid = 0x34;
1180eb7188caSLydia Wang 		pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
1181eb7188caSLydia Wang 		spec->multiout.num_dacs = 4;
1182eb7188caSLydia Wang 		break;
118325eaba2fSLydia Wang 	case VT2002P:
118425eaba2fSLydia Wang 		nid = 0x35;
118525eaba2fSLydia Wang 		break;
1186ab6734e7SLydia Wang 	case VT1812:
1187ab6734e7SLydia Wang 		nid = 0x3d;
1188ab6734e7SLydia Wang 		break;
1189eb7188caSLydia Wang 	default:
1190eb7188caSLydia Wang 		nid = spec->autocfg.hp_pins[0];
1191eb7188caSLydia Wang 		break;
1192eb7188caSLydia Wang 	}
1193cdc1784dSLydia Wang 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
11940aa62aefSHarald Welte 
1195cdc1784dSLydia Wang 	if (spec->multiout.hp_nid && spec->multiout.hp_nid
1196cdc1784dSLydia Wang 	    != spec->multiout.dac_nids[HDA_FRONT])
1197cdc1784dSLydia Wang 		snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
11980aa62aefSHarald Welte 					   0, 0, 0);
11990aa62aefSHarald Welte 
1200cdc1784dSLydia Wang 	update_side_mute_status(codec);
12010713efebSLydia Wang 	/* update HP volume/swtich active state */
12020713efebSLydia Wang 	if (spec->codec_type == VT1708S
1203eb7188caSLydia Wang 	    || spec->codec_type == VT1702
1204f3db423dSLydia Wang 	    || spec->codec_type == VT1718S
120525eaba2fSLydia Wang 	    || spec->codec_type == VT1716S
1206ab6734e7SLydia Wang 	    || spec->codec_type == VT2002P
1207ab6734e7SLydia Wang 	    || spec->codec_type == VT1812) {
12080713efebSLydia Wang 		activate_ctl(codec, "Headphone Playback Volume",
12090713efebSLydia Wang 			     spec->hp_independent_mode);
12100713efebSLydia Wang 		activate_ctl(codec, "Headphone Playback Switch",
12110713efebSLydia Wang 			     spec->hp_independent_mode);
12120713efebSLydia Wang 	}
12130aa62aefSHarald Welte 	return 0;
12140aa62aefSHarald Welte }
12150aa62aefSHarald Welte 
12160aa62aefSHarald Welte static struct snd_kcontrol_new via_hp_mixer[] = {
12170aa62aefSHarald Welte 	{
12180aa62aefSHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12190aa62aefSHarald Welte 		.name = "Independent HP",
12200aa62aefSHarald Welte 		.count = 1,
12210aa62aefSHarald Welte 		.info = via_independent_hp_info,
12220aa62aefSHarald Welte 		.get = via_independent_hp_get,
12230aa62aefSHarald Welte 		.put = via_independent_hp_put,
12240aa62aefSHarald Welte 	},
12250aa62aefSHarald Welte 	{ } /* end */
12260aa62aefSHarald Welte };
12270aa62aefSHarald Welte 
12281564b287SLydia Wang static void notify_aa_path_ctls(struct hda_codec *codec)
12291564b287SLydia Wang {
12301564b287SLydia Wang 	int i;
12311564b287SLydia Wang 	struct snd_ctl_elem_id id;
12321564b287SLydia Wang 	const char *labels[] = {"Mic", "Front Mic", "Line"};
12331564b287SLydia Wang 
12341564b287SLydia Wang 	memset(&id, 0, sizeof(id));
12351564b287SLydia Wang 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
12361564b287SLydia Wang 	for (i = 0; i < ARRAY_SIZE(labels); i++) {
12371564b287SLydia Wang 		sprintf(id.name, "%s Playback Volume", labels[i]);
12381564b287SLydia Wang 		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
12391564b287SLydia Wang 			       &id);
12401564b287SLydia Wang 	}
12411564b287SLydia Wang }
12421564b287SLydia Wang 
12431564b287SLydia Wang static void mute_aa_path(struct hda_codec *codec, int mute)
12441564b287SLydia Wang {
12451564b287SLydia Wang 	struct via_spec *spec = codec->spec;
12461564b287SLydia Wang 	hda_nid_t  nid_mixer;
12471564b287SLydia Wang 	int start_idx;
12481564b287SLydia Wang 	int end_idx;
12491564b287SLydia Wang 	int i;
12501564b287SLydia Wang 	/* get nid of MW0 and start & end index */
12511564b287SLydia Wang 	switch (spec->codec_type) {
12521564b287SLydia Wang 	case VT1708:
12531564b287SLydia Wang 		nid_mixer = 0x17;
12541564b287SLydia Wang 		start_idx = 2;
12551564b287SLydia Wang 		end_idx = 4;
12561564b287SLydia Wang 		break;
12571564b287SLydia Wang 	case VT1709_10CH:
12581564b287SLydia Wang 	case VT1709_6CH:
12591564b287SLydia Wang 		nid_mixer = 0x18;
12601564b287SLydia Wang 		start_idx = 2;
12611564b287SLydia Wang 		end_idx = 4;
12621564b287SLydia Wang 		break;
12631564b287SLydia Wang 	case VT1708B_8CH:
12641564b287SLydia Wang 	case VT1708B_4CH:
12651564b287SLydia Wang 	case VT1708S:
1266f3db423dSLydia Wang 	case VT1716S:
12671564b287SLydia Wang 		nid_mixer = 0x16;
12681564b287SLydia Wang 		start_idx = 2;
12691564b287SLydia Wang 		end_idx = 4;
12701564b287SLydia Wang 		break;
12711564b287SLydia Wang 	default:
12721564b287SLydia Wang 		return;
12731564b287SLydia Wang 	}
12741564b287SLydia Wang 	/* check AA path's mute status */
12751564b287SLydia Wang 	for (i = start_idx; i <= end_idx; i++) {
12761564b287SLydia Wang 		int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
12771564b287SLydia Wang 		snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
12781564b287SLydia Wang 					 HDA_AMP_MUTE, val);
12791564b287SLydia Wang 	}
12801564b287SLydia Wang }
12811564b287SLydia Wang static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
12821564b287SLydia Wang {
12831564b287SLydia Wang 	int res = 0;
12841564b287SLydia Wang 	int index;
12851564b287SLydia Wang 	for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
12861564b287SLydia Wang 		if (pin == spec->autocfg.input_pins[index]) {
12871564b287SLydia Wang 			res = 1;
12881564b287SLydia Wang 			break;
12891564b287SLydia Wang 		}
12901564b287SLydia Wang 	}
12911564b287SLydia Wang 	return res;
12921564b287SLydia Wang }
12931564b287SLydia Wang 
12941564b287SLydia Wang static int via_smart51_info(struct snd_kcontrol *kcontrol,
12951564b287SLydia Wang 			    struct snd_ctl_elem_info *uinfo)
12961564b287SLydia Wang {
12971564b287SLydia Wang 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12981564b287SLydia Wang 	uinfo->count = 1;
12991564b287SLydia Wang 	uinfo->value.integer.min = 0;
13001564b287SLydia Wang 	uinfo->value.integer.max = 1;
13011564b287SLydia Wang 	return 0;
13021564b287SLydia Wang }
13031564b287SLydia Wang 
13041564b287SLydia Wang static int via_smart51_get(struct snd_kcontrol *kcontrol,
13051564b287SLydia Wang 			   struct snd_ctl_elem_value *ucontrol)
13061564b287SLydia Wang {
13071564b287SLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
13081564b287SLydia Wang 	struct via_spec *spec = codec->spec;
13091564b287SLydia Wang 	int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
13101564b287SLydia Wang 	int on = 1;
13111564b287SLydia Wang 	int i;
13121564b287SLydia Wang 
13131564b287SLydia Wang 	for (i = 0; i < ARRAY_SIZE(index); i++) {
13141564b287SLydia Wang 		hda_nid_t nid = spec->autocfg.input_pins[index[i]];
13151564b287SLydia Wang 		if (nid) {
13161564b287SLydia Wang 			int ctl =
13171564b287SLydia Wang 			    snd_hda_codec_read(codec, nid, 0,
13181564b287SLydia Wang 					       AC_VERB_GET_PIN_WIDGET_CONTROL,
13191564b287SLydia Wang 					       0);
13201564b287SLydia Wang 			if (i == AUTO_PIN_FRONT_MIC
1321eb7188caSLydia Wang 			    && spec->hp_independent_mode
1322eb7188caSLydia Wang 			    && spec->codec_type != VT1718S)
13231564b287SLydia Wang 				continue; /* ignore FMic for independent HP */
13241564b287SLydia Wang 			if (ctl & AC_PINCTL_IN_EN
13251564b287SLydia Wang 			    && !(ctl & AC_PINCTL_OUT_EN))
13261564b287SLydia Wang 				on = 0;
13271564b287SLydia Wang 		}
13281564b287SLydia Wang 	}
13291564b287SLydia Wang 	*ucontrol->value.integer.value = on;
13301564b287SLydia Wang 	return 0;
13311564b287SLydia Wang }
13321564b287SLydia Wang 
13331564b287SLydia Wang static int via_smart51_put(struct snd_kcontrol *kcontrol,
13341564b287SLydia Wang 			   struct snd_ctl_elem_value *ucontrol)
13351564b287SLydia Wang {
13361564b287SLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
13371564b287SLydia Wang 	struct via_spec *spec = codec->spec;
13381564b287SLydia Wang 	int out_in = *ucontrol->value.integer.value
13391564b287SLydia Wang 		? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
13401564b287SLydia Wang 	int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
13411564b287SLydia Wang 	int i;
13421564b287SLydia Wang 
13431564b287SLydia Wang 	for (i = 0; i < ARRAY_SIZE(index); i++) {
13441564b287SLydia Wang 		hda_nid_t nid = spec->autocfg.input_pins[index[i]];
13451564b287SLydia Wang 		if (i == AUTO_PIN_FRONT_MIC
1346eb7188caSLydia Wang 		    && spec->hp_independent_mode
1347eb7188caSLydia Wang 		    && spec->codec_type != VT1718S)
13481564b287SLydia Wang 			continue; /* don't retask FMic for independent HP */
13491564b287SLydia Wang 		if (nid) {
13501564b287SLydia Wang 			unsigned int parm = snd_hda_codec_read(
13511564b287SLydia Wang 				codec, nid, 0,
13521564b287SLydia Wang 				AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
13531564b287SLydia Wang 			parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
13541564b287SLydia Wang 			parm |= out_in;
13551564b287SLydia Wang 			snd_hda_codec_write(codec, nid, 0,
13561564b287SLydia Wang 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
13571564b287SLydia Wang 					    parm);
13581564b287SLydia Wang 			if (out_in == AC_PINCTL_OUT_EN) {
13591564b287SLydia Wang 				mute_aa_path(codec, 1);
13601564b287SLydia Wang 				notify_aa_path_ctls(codec);
13611564b287SLydia Wang 			}
1362eb7188caSLydia Wang 			if (spec->codec_type == VT1718S)
1363eb7188caSLydia Wang 				snd_hda_codec_amp_stereo(
1364eb7188caSLydia Wang 					codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1365eb7188caSLydia Wang 					HDA_AMP_UNMUTE);
13661564b287SLydia Wang 		}
13671564b287SLydia Wang 		if (i == AUTO_PIN_FRONT_MIC) {
1368f3db423dSLydia Wang 			if (spec->codec_type == VT1708S
1369f3db423dSLydia Wang 			    || spec->codec_type == VT1716S) {
13701564b287SLydia Wang 				/* input = index 1 (AOW3) */
13711564b287SLydia Wang 				snd_hda_codec_write(
13721564b287SLydia Wang 					codec, nid, 0,
13731564b287SLydia Wang 					AC_VERB_SET_CONNECT_SEL, 1);
13741564b287SLydia Wang 				snd_hda_codec_amp_stereo(
13751564b287SLydia Wang 					codec, nid, HDA_OUTPUT,
13761564b287SLydia Wang 					0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
13771564b287SLydia Wang 			}
13781564b287SLydia Wang 		}
13791564b287SLydia Wang 	}
13801564b287SLydia Wang 	spec->smart51_enabled = *ucontrol->value.integer.value;
13811564b287SLydia Wang 	set_jack_power_state(codec);
13821564b287SLydia Wang 	return 1;
13831564b287SLydia Wang }
13841564b287SLydia Wang 
13851564b287SLydia Wang static struct snd_kcontrol_new via_smart51_mixer[] = {
13861564b287SLydia Wang 	{
13871564b287SLydia Wang 	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13881564b287SLydia Wang 	 .name = "Smart 5.1",
13891564b287SLydia Wang 	 .count = 1,
13901564b287SLydia Wang 	 .info = via_smart51_info,
13911564b287SLydia Wang 	 .get = via_smart51_get,
13921564b287SLydia Wang 	 .put = via_smart51_put,
13931564b287SLydia Wang 	 },
13941564b287SLydia Wang 	{}			/* end */
13951564b287SLydia Wang };
13961564b287SLydia Wang 
1397c577b8a1SJoseph Chan /* capture mixer elements */
1398c577b8a1SJoseph Chan static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1399c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1400c577b8a1SJoseph Chan 	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1401c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1402c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1403c577b8a1SJoseph Chan 	{
1404c577b8a1SJoseph Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1405c577b8a1SJoseph Chan 		/* The multiple "Capture Source" controls confuse alsamixer
1406c577b8a1SJoseph Chan 		 * So call somewhat different..
1407c577b8a1SJoseph Chan 		 */
1408c577b8a1SJoseph Chan 		/* .name = "Capture Source", */
1409c577b8a1SJoseph Chan 		.name = "Input Source",
1410c577b8a1SJoseph Chan 		.count = 1,
1411c577b8a1SJoseph Chan 		.info = via_mux_enum_info,
1412c577b8a1SJoseph Chan 		.get = via_mux_enum_get,
1413c577b8a1SJoseph Chan 		.put = via_mux_enum_put,
1414c577b8a1SJoseph Chan 	},
1415c577b8a1SJoseph Chan 	{ } /* end */
1416c577b8a1SJoseph Chan };
1417f5271101SLydia Wang 
1418f5271101SLydia Wang /* check AA path's mute statue */
1419f5271101SLydia Wang static int is_aa_path_mute(struct hda_codec *codec)
1420f5271101SLydia Wang {
1421f5271101SLydia Wang 	int mute = 1;
1422f5271101SLydia Wang 	hda_nid_t  nid_mixer;
1423f5271101SLydia Wang 	int start_idx;
1424f5271101SLydia Wang 	int end_idx;
1425f5271101SLydia Wang 	int i;
1426f5271101SLydia Wang 	struct via_spec *spec = codec->spec;
1427f5271101SLydia Wang 	/* get nid of MW0 and start & end index */
1428f5271101SLydia Wang 	switch (spec->codec_type) {
1429f5271101SLydia Wang 	case VT1708B_8CH:
1430f5271101SLydia Wang 	case VT1708B_4CH:
1431f5271101SLydia Wang 	case VT1708S:
1432f3db423dSLydia Wang 	case VT1716S:
1433f5271101SLydia Wang 		nid_mixer = 0x16;
1434f5271101SLydia Wang 		start_idx = 2;
1435f5271101SLydia Wang 		end_idx = 4;
1436f5271101SLydia Wang 		break;
1437f5271101SLydia Wang 	case VT1702:
1438f5271101SLydia Wang 		nid_mixer = 0x1a;
1439f5271101SLydia Wang 		start_idx = 1;
1440f5271101SLydia Wang 		end_idx = 3;
1441f5271101SLydia Wang 		break;
1442eb7188caSLydia Wang 	case VT1718S:
1443eb7188caSLydia Wang 		nid_mixer = 0x21;
1444eb7188caSLydia Wang 		start_idx = 1;
1445eb7188caSLydia Wang 		end_idx = 3;
1446eb7188caSLydia Wang 		break;
144725eaba2fSLydia Wang 	case VT2002P:
1448ab6734e7SLydia Wang 	case VT1812:
144925eaba2fSLydia Wang 		nid_mixer = 0x21;
145025eaba2fSLydia Wang 		start_idx = 0;
145125eaba2fSLydia Wang 		end_idx = 2;
145225eaba2fSLydia Wang 		break;
1453f5271101SLydia Wang 	default:
1454f5271101SLydia Wang 		return 0;
1455f5271101SLydia Wang 	}
1456f5271101SLydia Wang 	/* check AA path's mute status */
1457f5271101SLydia Wang 	for (i = start_idx; i <= end_idx; i++) {
1458f5271101SLydia Wang 		unsigned int con_list = snd_hda_codec_read(
1459f5271101SLydia Wang 			codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1460f5271101SLydia Wang 		int shift = 8 * (i % 4);
1461f5271101SLydia Wang 		hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1462f5271101SLydia Wang 		unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1463f5271101SLydia Wang 		if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1464f5271101SLydia Wang 			/* check mute status while the pin is connected */
1465f5271101SLydia Wang 			int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1466f5271101SLydia Wang 							    HDA_INPUT, i) >> 7;
1467f5271101SLydia Wang 			int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1468f5271101SLydia Wang 							    HDA_INPUT, i) >> 7;
1469f5271101SLydia Wang 			if (!mute_l || !mute_r) {
1470f5271101SLydia Wang 				mute = 0;
1471f5271101SLydia Wang 				break;
1472f5271101SLydia Wang 			}
1473f5271101SLydia Wang 		}
1474f5271101SLydia Wang 	}
1475f5271101SLydia Wang 	return mute;
1476f5271101SLydia Wang }
1477f5271101SLydia Wang 
1478f5271101SLydia Wang /* enter/exit analog low-current mode */
1479f5271101SLydia Wang static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1480f5271101SLydia Wang {
1481f5271101SLydia Wang 	struct via_spec *spec = codec->spec;
1482f5271101SLydia Wang 	static int saved_stream_idle = 1; /* saved stream idle status */
1483f5271101SLydia Wang 	int enable = is_aa_path_mute(codec);
1484f5271101SLydia Wang 	unsigned int verb = 0;
1485f5271101SLydia Wang 	unsigned int parm = 0;
1486f5271101SLydia Wang 
1487f5271101SLydia Wang 	if (stream_idle == -1)	/* stream status did not change */
1488f5271101SLydia Wang 		enable = enable && saved_stream_idle;
1489f5271101SLydia Wang 	else {
1490f5271101SLydia Wang 		enable = enable && stream_idle;
1491f5271101SLydia Wang 		saved_stream_idle = stream_idle;
1492f5271101SLydia Wang 	}
1493f5271101SLydia Wang 
1494f5271101SLydia Wang 	/* decide low current mode's verb & parameter */
1495f5271101SLydia Wang 	switch (spec->codec_type) {
1496f5271101SLydia Wang 	case VT1708B_8CH:
1497f5271101SLydia Wang 	case VT1708B_4CH:
1498f5271101SLydia Wang 		verb = 0xf70;
1499f5271101SLydia Wang 		parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1500f5271101SLydia Wang 		break;
1501f5271101SLydia Wang 	case VT1708S:
1502eb7188caSLydia Wang 	case VT1718S:
1503f3db423dSLydia Wang 	case VT1716S:
1504f5271101SLydia Wang 		verb = 0xf73;
1505f5271101SLydia Wang 		parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1506f5271101SLydia Wang 		break;
1507f5271101SLydia Wang 	case VT1702:
1508f5271101SLydia Wang 		verb = 0xf73;
1509f5271101SLydia Wang 		parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1510f5271101SLydia Wang 		break;
151125eaba2fSLydia Wang 	case VT2002P:
1512ab6734e7SLydia Wang 	case VT1812:
151325eaba2fSLydia Wang 		verb = 0xf93;
151425eaba2fSLydia Wang 		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
151525eaba2fSLydia Wang 		break;
1516f5271101SLydia Wang 	default:
1517f5271101SLydia Wang 		return;		/* other codecs are not supported */
1518f5271101SLydia Wang 	}
1519f5271101SLydia Wang 	/* send verb */
1520f5271101SLydia Wang 	snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1521f5271101SLydia Wang }
1522f5271101SLydia Wang 
1523c577b8a1SJoseph Chan /*
1524c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
1525c577b8a1SJoseph Chan  */
1526c577b8a1SJoseph Chan static struct hda_verb vt1708_volume_init_verbs[] = {
1527c577b8a1SJoseph Chan 	/*
1528c577b8a1SJoseph Chan 	 * Unmute ADC0-1 and set the default input to mic-in
1529c577b8a1SJoseph Chan 	 */
1530c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1531c577b8a1SJoseph Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1532c577b8a1SJoseph Chan 
1533c577b8a1SJoseph Chan 
1534f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1535c577b8a1SJoseph Chan 	 * mixer widget
1536c577b8a1SJoseph Chan 	 */
1537c577b8a1SJoseph Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1538f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1539f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1540f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1541f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1542f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1543c577b8a1SJoseph Chan 
1544c577b8a1SJoseph Chan 	/*
1545c577b8a1SJoseph Chan 	 * Set up output mixers (0x19 - 0x1b)
1546c577b8a1SJoseph Chan 	 */
1547c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
1548c577b8a1SJoseph Chan 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1549c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1550c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1551c577b8a1SJoseph Chan 
1552bfdc675aSLydia Wang 	/* Setup default input MW0 to PW4 */
1553bfdc675aSLydia Wang 	{0x20, AC_VERB_SET_CONNECT_SEL, 0},
1554c577b8a1SJoseph Chan 	/* PW9 Output enable */
1555c577b8a1SJoseph Chan 	{0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1556f7278fd0SJosepch Chan 	{ }
1557c577b8a1SJoseph Chan };
1558c577b8a1SJoseph Chan 
1559c577b8a1SJoseph Chan static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1560c577b8a1SJoseph Chan 				 struct hda_codec *codec,
1561c577b8a1SJoseph Chan 				 struct snd_pcm_substream *substream)
1562c577b8a1SJoseph Chan {
1563c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
156417314379SLydia Wang 	int idle = substream->pstr->substream_opened == 1
156517314379SLydia Wang 		&& substream->ref_count == 0;
156617314379SLydia Wang 	analog_low_current_mode(codec, idle);
15679a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
15689a08160bSTakashi Iwai 					     hinfo);
1569c577b8a1SJoseph Chan }
1570c577b8a1SJoseph Chan 
15710aa62aefSHarald Welte static void playback_multi_pcm_prep_0(struct hda_codec *codec,
15720aa62aefSHarald Welte 				      unsigned int stream_tag,
15730aa62aefSHarald Welte 				      unsigned int format,
15740aa62aefSHarald Welte 				      struct snd_pcm_substream *substream)
15750aa62aefSHarald Welte {
15760aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
15770aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
15780aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
15790aa62aefSHarald Welte 	int chs = substream->runtime->channels;
15800aa62aefSHarald Welte 	int i;
15810aa62aefSHarald Welte 
15820aa62aefSHarald Welte 	mutex_lock(&codec->spdif_mutex);
15830aa62aefSHarald Welte 	if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
15840aa62aefSHarald Welte 		if (chs == 2 &&
15850aa62aefSHarald Welte 		    snd_hda_is_supported_format(codec, mout->dig_out_nid,
15860aa62aefSHarald Welte 						format) &&
15870aa62aefSHarald Welte 		    !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
15880aa62aefSHarald Welte 			mout->dig_out_used = HDA_DIG_ANALOG_DUP;
15890aa62aefSHarald Welte 			/* turn off SPDIF once; otherwise the IEC958 bits won't
15900aa62aefSHarald Welte 			 * be updated */
15910aa62aefSHarald Welte 			if (codec->spdif_ctls & AC_DIG1_ENABLE)
15920aa62aefSHarald Welte 				snd_hda_codec_write(codec, mout->dig_out_nid, 0,
15930aa62aefSHarald Welte 						    AC_VERB_SET_DIGI_CONVERT_1,
15940aa62aefSHarald Welte 						    codec->spdif_ctls &
15950aa62aefSHarald Welte 							~AC_DIG1_ENABLE & 0xff);
15960aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
15970aa62aefSHarald Welte 						   stream_tag, 0, format);
15980aa62aefSHarald Welte 			/* turn on again (if needed) */
15990aa62aefSHarald Welte 			if (codec->spdif_ctls & AC_DIG1_ENABLE)
16000aa62aefSHarald Welte 				snd_hda_codec_write(codec, mout->dig_out_nid, 0,
16010aa62aefSHarald Welte 						    AC_VERB_SET_DIGI_CONVERT_1,
16020aa62aefSHarald Welte 						    codec->spdif_ctls & 0xff);
16030aa62aefSHarald Welte 		} else {
16040aa62aefSHarald Welte 			mout->dig_out_used = 0;
16050aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
16060aa62aefSHarald Welte 						   0, 0, 0);
16070aa62aefSHarald Welte 		}
16080aa62aefSHarald Welte 	}
16090aa62aefSHarald Welte 	mutex_unlock(&codec->spdif_mutex);
16100aa62aefSHarald Welte 
16110aa62aefSHarald Welte 	/* front */
16120aa62aefSHarald Welte 	snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
16130aa62aefSHarald Welte 				   0, format);
16140aa62aefSHarald Welte 
1615eb7188caSLydia Wang 	if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1616eb7188caSLydia Wang 	    && !spec->hp_independent_mode)
16170aa62aefSHarald Welte 		/* headphone out will just decode front left/right (stereo) */
16180aa62aefSHarald Welte 		snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
16190aa62aefSHarald Welte 					   0, format);
16200aa62aefSHarald Welte 
16210aa62aefSHarald Welte 	/* extra outputs copied from front */
16220aa62aefSHarald Welte 	for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
16230aa62aefSHarald Welte 		if (mout->extra_out_nid[i])
16240aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec,
16250aa62aefSHarald Welte 						   mout->extra_out_nid[i],
16260aa62aefSHarald Welte 						   stream_tag, 0, format);
16270aa62aefSHarald Welte 
16280aa62aefSHarald Welte 	/* surrounds */
16290aa62aefSHarald Welte 	for (i = 1; i < mout->num_dacs; i++) {
16300aa62aefSHarald Welte 		if (chs >= (i + 1) * 2) /* independent out */
16310aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
16320aa62aefSHarald Welte 						   i * 2, format);
16330aa62aefSHarald Welte 		else /* copy front */
16340aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
16350aa62aefSHarald Welte 						   0, format);
16360aa62aefSHarald Welte 	}
16370aa62aefSHarald Welte }
16380aa62aefSHarald Welte 
16390aa62aefSHarald Welte static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
16400aa62aefSHarald Welte 					  struct hda_codec *codec,
16410aa62aefSHarald Welte 					  unsigned int stream_tag,
16420aa62aefSHarald Welte 					  unsigned int format,
16430aa62aefSHarald Welte 					  struct snd_pcm_substream *substream)
16440aa62aefSHarald Welte {
16450aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
16460aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
16470aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
16480aa62aefSHarald Welte 
16490aa62aefSHarald Welte 	if (substream->number == 0)
16500aa62aefSHarald Welte 		playback_multi_pcm_prep_0(codec, stream_tag, format,
16510aa62aefSHarald Welte 					  substream);
16520aa62aefSHarald Welte 	else {
16530aa62aefSHarald Welte 		if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
16540aa62aefSHarald Welte 		    spec->hp_independent_mode)
16550aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
16560aa62aefSHarald Welte 						   stream_tag, 0, format);
16570aa62aefSHarald Welte 	}
16581f2e99feSLydia Wang 	vt1708_start_hp_work(spec);
16590aa62aefSHarald Welte 	return 0;
16600aa62aefSHarald Welte }
16610aa62aefSHarald Welte 
16620aa62aefSHarald Welte static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
16630aa62aefSHarald Welte 				    struct hda_codec *codec,
16640aa62aefSHarald Welte 				    struct snd_pcm_substream *substream)
16650aa62aefSHarald Welte {
16660aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
16670aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
16680aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
16690aa62aefSHarald Welte 	int i;
16700aa62aefSHarald Welte 
16710aa62aefSHarald Welte 	if (substream->number == 0) {
16720aa62aefSHarald Welte 		for (i = 0; i < mout->num_dacs; i++)
16730aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
16740aa62aefSHarald Welte 
16750aa62aefSHarald Welte 		if (mout->hp_nid && !spec->hp_independent_mode)
16760aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
16770aa62aefSHarald Welte 						   0, 0, 0);
16780aa62aefSHarald Welte 
16790aa62aefSHarald Welte 		for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
16800aa62aefSHarald Welte 			if (mout->extra_out_nid[i])
16810aa62aefSHarald Welte 				snd_hda_codec_setup_stream(codec,
16820aa62aefSHarald Welte 							mout->extra_out_nid[i],
16830aa62aefSHarald Welte 							0, 0, 0);
16840aa62aefSHarald Welte 		mutex_lock(&codec->spdif_mutex);
16850aa62aefSHarald Welte 		if (mout->dig_out_nid &&
16860aa62aefSHarald Welte 		    mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
16870aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
16880aa62aefSHarald Welte 						   0, 0, 0);
16890aa62aefSHarald Welte 			mout->dig_out_used = 0;
16900aa62aefSHarald Welte 		}
16910aa62aefSHarald Welte 		mutex_unlock(&codec->spdif_mutex);
16920aa62aefSHarald Welte 	} else {
16930aa62aefSHarald Welte 		if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
16940aa62aefSHarald Welte 		    spec->hp_independent_mode)
16950aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
16960aa62aefSHarald Welte 						   0, 0, 0);
16970aa62aefSHarald Welte 	}
16981f2e99feSLydia Wang 	vt1708_stop_hp_work(spec);
16990aa62aefSHarald Welte 	return 0;
17000aa62aefSHarald Welte }
17010aa62aefSHarald Welte 
1702c577b8a1SJoseph Chan /*
1703c577b8a1SJoseph Chan  * Digital out
1704c577b8a1SJoseph Chan  */
1705c577b8a1SJoseph Chan static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1706c577b8a1SJoseph Chan 				     struct hda_codec *codec,
1707c577b8a1SJoseph Chan 				     struct snd_pcm_substream *substream)
1708c577b8a1SJoseph Chan {
1709c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1710c577b8a1SJoseph Chan 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1711c577b8a1SJoseph Chan }
1712c577b8a1SJoseph Chan 
1713c577b8a1SJoseph Chan static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1714c577b8a1SJoseph Chan 				      struct hda_codec *codec,
1715c577b8a1SJoseph Chan 				      struct snd_pcm_substream *substream)
1716c577b8a1SJoseph Chan {
1717c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1718c577b8a1SJoseph Chan 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1719c577b8a1SJoseph Chan }
1720c577b8a1SJoseph Chan 
17215691ec7fSHarald Welte static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
172298aa34c0SHarald Welte 					struct hda_codec *codec,
172398aa34c0SHarald Welte 					unsigned int stream_tag,
172498aa34c0SHarald Welte 					unsigned int format,
172598aa34c0SHarald Welte 					struct snd_pcm_substream *substream)
172698aa34c0SHarald Welte {
172798aa34c0SHarald Welte 	struct via_spec *spec = codec->spec;
17289da29271STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
17299da29271STakashi Iwai 					     stream_tag, format, substream);
17309da29271STakashi Iwai }
17315691ec7fSHarald Welte 
17329da29271STakashi Iwai static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
17339da29271STakashi Iwai 					struct hda_codec *codec,
17349da29271STakashi Iwai 					struct snd_pcm_substream *substream)
17359da29271STakashi Iwai {
17369da29271STakashi Iwai 	struct via_spec *spec = codec->spec;
17379da29271STakashi Iwai 	snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
173898aa34c0SHarald Welte 	return 0;
173998aa34c0SHarald Welte }
174098aa34c0SHarald Welte 
1741c577b8a1SJoseph Chan /*
1742c577b8a1SJoseph Chan  * Analog capture
1743c577b8a1SJoseph Chan  */
1744c577b8a1SJoseph Chan static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1745c577b8a1SJoseph Chan 				   struct hda_codec *codec,
1746c577b8a1SJoseph Chan 				   unsigned int stream_tag,
1747c577b8a1SJoseph Chan 				   unsigned int format,
1748c577b8a1SJoseph Chan 				   struct snd_pcm_substream *substream)
1749c577b8a1SJoseph Chan {
1750c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1751c577b8a1SJoseph Chan 
1752c577b8a1SJoseph Chan 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1753c577b8a1SJoseph Chan 				   stream_tag, 0, format);
1754c577b8a1SJoseph Chan 	return 0;
1755c577b8a1SJoseph Chan }
1756c577b8a1SJoseph Chan 
1757c577b8a1SJoseph Chan static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1758c577b8a1SJoseph Chan 				   struct hda_codec *codec,
1759c577b8a1SJoseph Chan 				   struct snd_pcm_substream *substream)
1760c577b8a1SJoseph Chan {
1761c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1762888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1763c577b8a1SJoseph Chan 	return 0;
1764c577b8a1SJoseph Chan }
1765c577b8a1SJoseph Chan 
1766c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_analog_playback = {
17670aa62aefSHarald Welte 	.substreams = 2,
1768c577b8a1SJoseph Chan 	.channels_min = 2,
1769c577b8a1SJoseph Chan 	.channels_max = 8,
1770c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
1771c577b8a1SJoseph Chan 	.ops = {
1772c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
17730aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
17740aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
1775c577b8a1SJoseph Chan 	},
1776c577b8a1SJoseph Chan };
1777c577b8a1SJoseph Chan 
1778bc9b5623STakashi Iwai static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1779c873cc25SLydia Wang 	.substreams = 2,
1780bc9b5623STakashi Iwai 	.channels_min = 2,
1781bc9b5623STakashi Iwai 	.channels_max = 8,
1782bc9b5623STakashi Iwai 	.nid = 0x10, /* NID to query formats and rates */
1783bc9b5623STakashi Iwai 	/* We got noisy outputs on the right channel on VT1708 when
1784bc9b5623STakashi Iwai 	 * 24bit samples are used.  Until any workaround is found,
1785bc9b5623STakashi Iwai 	 * disable the 24bit format, so far.
1786bc9b5623STakashi Iwai 	 */
1787bc9b5623STakashi Iwai 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
1788bc9b5623STakashi Iwai 	.ops = {
1789bc9b5623STakashi Iwai 		.open = via_playback_pcm_open,
1790c873cc25SLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
1791c873cc25SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup
1792bc9b5623STakashi Iwai 	},
1793bc9b5623STakashi Iwai };
1794bc9b5623STakashi Iwai 
1795c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1796c577b8a1SJoseph Chan 	.substreams = 2,
1797c577b8a1SJoseph Chan 	.channels_min = 2,
1798c577b8a1SJoseph Chan 	.channels_max = 2,
1799c577b8a1SJoseph Chan 	.nid = 0x15, /* NID to query formats and rates */
1800c577b8a1SJoseph Chan 	.ops = {
1801c577b8a1SJoseph Chan 		.prepare = via_capture_pcm_prepare,
1802c577b8a1SJoseph Chan 		.cleanup = via_capture_pcm_cleanup
1803c577b8a1SJoseph Chan 	},
1804c577b8a1SJoseph Chan };
1805c577b8a1SJoseph Chan 
1806c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1807c577b8a1SJoseph Chan 	.substreams = 1,
1808c577b8a1SJoseph Chan 	.channels_min = 2,
1809c577b8a1SJoseph Chan 	.channels_max = 2,
1810c577b8a1SJoseph Chan 	/* NID is set in via_build_pcms */
1811c577b8a1SJoseph Chan 	.ops = {
1812c577b8a1SJoseph Chan 		.open = via_dig_playback_pcm_open,
18136b97eb45STakashi Iwai 		.close = via_dig_playback_pcm_close,
18149da29271STakashi Iwai 		.prepare = via_dig_playback_pcm_prepare,
18159da29271STakashi Iwai 		.cleanup = via_dig_playback_pcm_cleanup
1816c577b8a1SJoseph Chan 	},
1817c577b8a1SJoseph Chan };
1818c577b8a1SJoseph Chan 
1819c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1820c577b8a1SJoseph Chan 	.substreams = 1,
1821c577b8a1SJoseph Chan 	.channels_min = 2,
1822c577b8a1SJoseph Chan 	.channels_max = 2,
1823c577b8a1SJoseph Chan };
1824c577b8a1SJoseph Chan 
1825c577b8a1SJoseph Chan static int via_build_controls(struct hda_codec *codec)
1826c577b8a1SJoseph Chan {
1827c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1828c577b8a1SJoseph Chan 	int err;
1829c577b8a1SJoseph Chan 	int i;
1830c577b8a1SJoseph Chan 
1831c577b8a1SJoseph Chan 	for (i = 0; i < spec->num_mixers; i++) {
1832c577b8a1SJoseph Chan 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1833c577b8a1SJoseph Chan 		if (err < 0)
1834c577b8a1SJoseph Chan 			return err;
1835c577b8a1SJoseph Chan 	}
1836c577b8a1SJoseph Chan 
1837c577b8a1SJoseph Chan 	if (spec->multiout.dig_out_nid) {
1838c577b8a1SJoseph Chan 		err = snd_hda_create_spdif_out_ctls(codec,
1839c577b8a1SJoseph Chan 						    spec->multiout.dig_out_nid);
1840c577b8a1SJoseph Chan 		if (err < 0)
1841c577b8a1SJoseph Chan 			return err;
18429a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
18439a08160bSTakashi Iwai 						    &spec->multiout);
18449a08160bSTakashi Iwai 		if (err < 0)
18459a08160bSTakashi Iwai 			return err;
18469a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
1847c577b8a1SJoseph Chan 	}
1848c577b8a1SJoseph Chan 	if (spec->dig_in_nid) {
1849c577b8a1SJoseph Chan 		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1850c577b8a1SJoseph Chan 		if (err < 0)
1851c577b8a1SJoseph Chan 			return err;
1852c577b8a1SJoseph Chan 	}
185317314379SLydia Wang 
185417314379SLydia Wang 	/* init power states */
185517314379SLydia Wang 	set_jack_power_state(codec);
185617314379SLydia Wang 	analog_low_current_mode(codec, 1);
185717314379SLydia Wang 
1858603c4019STakashi Iwai 	via_free_kctls(codec); /* no longer needed */
1859c577b8a1SJoseph Chan 	return 0;
1860c577b8a1SJoseph Chan }
1861c577b8a1SJoseph Chan 
1862c577b8a1SJoseph Chan static int via_build_pcms(struct hda_codec *codec)
1863c577b8a1SJoseph Chan {
1864c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1865c577b8a1SJoseph Chan 	struct hda_pcm *info = spec->pcm_rec;
1866c577b8a1SJoseph Chan 
1867c577b8a1SJoseph Chan 	codec->num_pcms = 1;
1868c577b8a1SJoseph Chan 	codec->pcm_info = info;
1869c577b8a1SJoseph Chan 
1870c577b8a1SJoseph Chan 	info->name = spec->stream_name_analog;
1871377ff31aSLydia Wang 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1872377ff31aSLydia Wang 		*(spec->stream_analog_playback);
1873377ff31aSLydia Wang 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1874377ff31aSLydia Wang 		spec->multiout.dac_nids[0];
1875c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1876c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1877c577b8a1SJoseph Chan 
1878c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1879c577b8a1SJoseph Chan 		spec->multiout.max_channels;
1880c577b8a1SJoseph Chan 
1881c577b8a1SJoseph Chan 	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1882c577b8a1SJoseph Chan 		codec->num_pcms++;
1883c577b8a1SJoseph Chan 		info++;
1884c577b8a1SJoseph Chan 		info->name = spec->stream_name_digital;
18857ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
1886c577b8a1SJoseph Chan 		if (spec->multiout.dig_out_nid) {
1887c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1888c577b8a1SJoseph Chan 				*(spec->stream_digital_playback);
1889c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1890c577b8a1SJoseph Chan 				spec->multiout.dig_out_nid;
1891c577b8a1SJoseph Chan 		}
1892c577b8a1SJoseph Chan 		if (spec->dig_in_nid) {
1893c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1894c577b8a1SJoseph Chan 				*(spec->stream_digital_capture);
1895c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1896c577b8a1SJoseph Chan 				spec->dig_in_nid;
1897c577b8a1SJoseph Chan 		}
1898c577b8a1SJoseph Chan 	}
1899c577b8a1SJoseph Chan 
1900c577b8a1SJoseph Chan 	return 0;
1901c577b8a1SJoseph Chan }
1902c577b8a1SJoseph Chan 
1903c577b8a1SJoseph Chan static void via_free(struct hda_codec *codec)
1904c577b8a1SJoseph Chan {
1905c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1906c577b8a1SJoseph Chan 
1907c577b8a1SJoseph Chan 	if (!spec)
1908c577b8a1SJoseph Chan 		return;
1909c577b8a1SJoseph Chan 
1910603c4019STakashi Iwai 	via_free_kctls(codec);
19111f2e99feSLydia Wang 	vt1708_stop_hp_work(spec);
1912c577b8a1SJoseph Chan 	kfree(codec->spec);
1913c577b8a1SJoseph Chan }
1914c577b8a1SJoseph Chan 
191569e52a80SHarald Welte /* mute internal speaker if HP is plugged */
191669e52a80SHarald Welte static void via_hp_automute(struct hda_codec *codec)
191769e52a80SHarald Welte {
1918dcf34c8cSLydia Wang 	unsigned int present = 0;
191969e52a80SHarald Welte 	struct via_spec *spec = codec->spec;
192069e52a80SHarald Welte 
192169e52a80SHarald Welte 	present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
192269e52a80SHarald Welte 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1923dcf34c8cSLydia Wang 
1924dcf34c8cSLydia Wang 	if (!spec->hp_independent_mode) {
1925dcf34c8cSLydia Wang 		struct snd_ctl_elem_id id;
1926dcf34c8cSLydia Wang 		/* auto mute */
1927dcf34c8cSLydia Wang 		snd_hda_codec_amp_stereo(
1928dcf34c8cSLydia Wang 			codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1929dcf34c8cSLydia Wang 			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1930dcf34c8cSLydia Wang 		/* notify change */
1931dcf34c8cSLydia Wang 		memset(&id, 0, sizeof(id));
1932dcf34c8cSLydia Wang 		id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1933dcf34c8cSLydia Wang 		strcpy(id.name, "Front Playback Switch");
1934dcf34c8cSLydia Wang 		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1935dcf34c8cSLydia Wang 			       &id);
1936dcf34c8cSLydia Wang 	}
193769e52a80SHarald Welte }
193869e52a80SHarald Welte 
1939f3db423dSLydia Wang /* mute mono out if HP or Line out is plugged */
1940f3db423dSLydia Wang static void via_mono_automute(struct hda_codec *codec)
1941f3db423dSLydia Wang {
1942f3db423dSLydia Wang 	unsigned int hp_present, lineout_present;
1943f3db423dSLydia Wang 	struct via_spec *spec = codec->spec;
1944f3db423dSLydia Wang 
1945f3db423dSLydia Wang 	if (spec->codec_type != VT1716S)
1946f3db423dSLydia Wang 		return;
1947f3db423dSLydia Wang 
1948f3db423dSLydia Wang 	lineout_present = snd_hda_codec_read(
1949f3db423dSLydia Wang 		codec, spec->autocfg.line_out_pins[0], 0,
1950f3db423dSLydia Wang 		AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1951f3db423dSLydia Wang 
1952f3db423dSLydia Wang 	/* Mute Mono Out if Line Out is plugged */
1953f3db423dSLydia Wang 	if (lineout_present) {
1954f3db423dSLydia Wang 		snd_hda_codec_amp_stereo(
1955f3db423dSLydia Wang 			codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1956f3db423dSLydia Wang 		return;
1957f3db423dSLydia Wang 	}
1958f3db423dSLydia Wang 
1959f3db423dSLydia Wang 	hp_present = snd_hda_codec_read(
1960f3db423dSLydia Wang 		codec, spec->autocfg.hp_pins[0], 0,
1961f3db423dSLydia Wang 		AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1962f3db423dSLydia Wang 
1963f3db423dSLydia Wang 	if (!spec->hp_independent_mode)
1964f3db423dSLydia Wang 		snd_hda_codec_amp_stereo(
1965f3db423dSLydia Wang 			codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1966f3db423dSLydia Wang 			hp_present ? HDA_AMP_MUTE : 0);
1967f3db423dSLydia Wang }
1968f3db423dSLydia Wang 
196969e52a80SHarald Welte static void via_gpio_control(struct hda_codec *codec)
197069e52a80SHarald Welte {
197169e52a80SHarald Welte 	unsigned int gpio_data;
197269e52a80SHarald Welte 	unsigned int vol_counter;
197369e52a80SHarald Welte 	unsigned int vol;
197469e52a80SHarald Welte 	unsigned int master_vol;
197569e52a80SHarald Welte 
197669e52a80SHarald Welte 	struct via_spec *spec = codec->spec;
197769e52a80SHarald Welte 
197869e52a80SHarald Welte 	gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
197969e52a80SHarald Welte 				       AC_VERB_GET_GPIO_DATA, 0) & 0x03;
198069e52a80SHarald Welte 
198169e52a80SHarald Welte 	vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
198269e52a80SHarald Welte 					  0xF84, 0) & 0x3F0000) >> 16;
198369e52a80SHarald Welte 
198469e52a80SHarald Welte 	vol = vol_counter & 0x1F;
198569e52a80SHarald Welte 	master_vol = snd_hda_codec_read(codec, 0x1A, 0,
198669e52a80SHarald Welte 					AC_VERB_GET_AMP_GAIN_MUTE,
198769e52a80SHarald Welte 					AC_AMP_GET_INPUT);
198869e52a80SHarald Welte 
198969e52a80SHarald Welte 	if (gpio_data == 0x02) {
199069e52a80SHarald Welte 		/* unmute line out */
199169e52a80SHarald Welte 		snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
199269e52a80SHarald Welte 					 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
199369e52a80SHarald Welte 
199469e52a80SHarald Welte 		if (vol_counter & 0x20) {
199569e52a80SHarald Welte 			/* decrease volume */
199669e52a80SHarald Welte 			if (vol > master_vol)
199769e52a80SHarald Welte 				vol = master_vol;
199869e52a80SHarald Welte 			snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
199969e52a80SHarald Welte 						 0, HDA_AMP_VOLMASK,
200069e52a80SHarald Welte 						 master_vol-vol);
200169e52a80SHarald Welte 		} else {
200269e52a80SHarald Welte 			/* increase volume */
200369e52a80SHarald Welte 			snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
200469e52a80SHarald Welte 					 HDA_AMP_VOLMASK,
200569e52a80SHarald Welte 					 ((master_vol+vol) > 0x2A) ? 0x2A :
200669e52a80SHarald Welte 					  (master_vol+vol));
200769e52a80SHarald Welte 		}
200869e52a80SHarald Welte 	} else if (!(gpio_data & 0x02)) {
200969e52a80SHarald Welte 		/* mute line out */
201069e52a80SHarald Welte 		snd_hda_codec_amp_stereo(codec,
201169e52a80SHarald Welte 					 spec->autocfg.line_out_pins[0],
201269e52a80SHarald Welte 					 HDA_OUTPUT, 0, HDA_AMP_MUTE,
201369e52a80SHarald Welte 					 HDA_AMP_MUTE);
201469e52a80SHarald Welte 	}
201569e52a80SHarald Welte }
201669e52a80SHarald Welte 
201725eaba2fSLydia Wang /* mute Internal-Speaker if HP is plugged */
201825eaba2fSLydia Wang static void via_speaker_automute(struct hda_codec *codec)
201925eaba2fSLydia Wang {
202025eaba2fSLydia Wang 	unsigned int hp_present;
202125eaba2fSLydia Wang 	struct via_spec *spec = codec->spec;
202225eaba2fSLydia Wang 
2023ab6734e7SLydia Wang 	if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
202425eaba2fSLydia Wang 		return;
202525eaba2fSLydia Wang 
202625eaba2fSLydia Wang 	hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
202725eaba2fSLydia Wang 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
202825eaba2fSLydia Wang 
202925eaba2fSLydia Wang 	if (!spec->hp_independent_mode) {
203025eaba2fSLydia Wang 		struct snd_ctl_elem_id id;
203125eaba2fSLydia Wang 		snd_hda_codec_amp_stereo(
203225eaba2fSLydia Wang 			codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
203325eaba2fSLydia Wang 			HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
203425eaba2fSLydia Wang 		/* notify change */
203525eaba2fSLydia Wang 		memset(&id, 0, sizeof(id));
203625eaba2fSLydia Wang 		id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
203725eaba2fSLydia Wang 		strcpy(id.name, "Speaker Playback Switch");
203825eaba2fSLydia Wang 		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
203925eaba2fSLydia Wang 			       &id);
204025eaba2fSLydia Wang 	}
204125eaba2fSLydia Wang }
204225eaba2fSLydia Wang 
204325eaba2fSLydia Wang /* mute line-out and internal speaker if HP is plugged */
204425eaba2fSLydia Wang static void via_hp_bind_automute(struct hda_codec *codec)
204525eaba2fSLydia Wang {
204625eaba2fSLydia Wang 	unsigned int hp_present, present = 0;
204725eaba2fSLydia Wang 	struct via_spec *spec = codec->spec;
204825eaba2fSLydia Wang 	int i;
204925eaba2fSLydia Wang 
205025eaba2fSLydia Wang 	if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
205125eaba2fSLydia Wang 		return;
205225eaba2fSLydia Wang 
205325eaba2fSLydia Wang 	hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
205425eaba2fSLydia Wang 					AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
205525eaba2fSLydia Wang 
205625eaba2fSLydia Wang 	present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
205725eaba2fSLydia Wang 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
205825eaba2fSLydia Wang 
205925eaba2fSLydia Wang 	if (!spec->hp_independent_mode) {
206025eaba2fSLydia Wang 		/* Mute Line-Outs */
206125eaba2fSLydia Wang 		for (i = 0; i < spec->autocfg.line_outs; i++)
206225eaba2fSLydia Wang 			snd_hda_codec_amp_stereo(
206325eaba2fSLydia Wang 				codec, spec->autocfg.line_out_pins[i],
206425eaba2fSLydia Wang 				HDA_OUTPUT, 0,
206525eaba2fSLydia Wang 				HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
206625eaba2fSLydia Wang 		if (hp_present)
206725eaba2fSLydia Wang 			present = hp_present;
206825eaba2fSLydia Wang 	}
206925eaba2fSLydia Wang 	/* Speakers */
207025eaba2fSLydia Wang 	for (i = 0; i < spec->autocfg.speaker_outs; i++)
207125eaba2fSLydia Wang 		snd_hda_codec_amp_stereo(
207225eaba2fSLydia Wang 			codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
207325eaba2fSLydia Wang 			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
207425eaba2fSLydia Wang }
207525eaba2fSLydia Wang 
207625eaba2fSLydia Wang 
207769e52a80SHarald Welte /* unsolicited event for jack sensing */
207869e52a80SHarald Welte static void via_unsol_event(struct hda_codec *codec,
207969e52a80SHarald Welte 				  unsigned int res)
208069e52a80SHarald Welte {
208169e52a80SHarald Welte 	res >>= 26;
2082a34df19aSLydia Wang 	if (res & VIA_HP_EVENT)
208369e52a80SHarald Welte 		via_hp_automute(codec);
2084a34df19aSLydia Wang 	if (res & VIA_GPIO_EVENT)
208569e52a80SHarald Welte 		via_gpio_control(codec);
2086a34df19aSLydia Wang 	if (res & VIA_JACK_EVENT)
2087a34df19aSLydia Wang 		set_jack_power_state(codec);
2088f3db423dSLydia Wang 	if (res & VIA_MONO_EVENT)
2089f3db423dSLydia Wang 		via_mono_automute(codec);
209025eaba2fSLydia Wang 	if (res & VIA_SPEAKER_EVENT)
209125eaba2fSLydia Wang 		via_speaker_automute(codec);
209225eaba2fSLydia Wang 	if (res & VIA_BIND_HP_EVENT)
209325eaba2fSLydia Wang 		via_hp_bind_automute(codec);
209469e52a80SHarald Welte }
209569e52a80SHarald Welte 
2096c577b8a1SJoseph Chan static int via_init(struct hda_codec *codec)
2097c577b8a1SJoseph Chan {
2098c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
209969e52a80SHarald Welte 	int i;
210069e52a80SHarald Welte 	for (i = 0; i < spec->num_iverbs; i++)
210169e52a80SHarald Welte 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
210269e52a80SHarald Welte 
2103518bf3baSLydia Wang 	spec->codec_type = get_codec_type(codec);
2104518bf3baSLydia Wang 	if (spec->codec_type == VT1708BCE)
2105518bf3baSLydia Wang 		spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2106518bf3baSLydia Wang 					       same */
2107f7278fd0SJosepch Chan 	/* Lydia Add for EAPD enable */
2108f7278fd0SJosepch Chan 	if (!spec->dig_in_nid) { /* No Digital In connection */
210955d1d6c1STakashi Iwai 		if (spec->dig_in_pin) {
211055d1d6c1STakashi Iwai 			snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2111f7278fd0SJosepch Chan 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
211212b74c80STakashi Iwai 					    PIN_OUT);
211355d1d6c1STakashi Iwai 			snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2114f7278fd0SJosepch Chan 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2115f7278fd0SJosepch Chan 		}
211612b74c80STakashi Iwai 	} else /* enable SPDIF-input pin */
211712b74c80STakashi Iwai 		snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
211812b74c80STakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2119f7278fd0SJosepch Chan 
21209da29271STakashi Iwai 	/* assign slave outs */
21219da29271STakashi Iwai 	if (spec->slave_dig_outs[0])
21229da29271STakashi Iwai 		codec->slave_dig_outs = spec->slave_dig_outs;
21235691ec7fSHarald Welte 
2124c577b8a1SJoseph Chan 	return 0;
2125c577b8a1SJoseph Chan }
2126c577b8a1SJoseph Chan 
21271f2e99feSLydia Wang #ifdef SND_HDA_NEEDS_RESUME
21281f2e99feSLydia Wang static int via_suspend(struct hda_codec *codec, pm_message_t state)
21291f2e99feSLydia Wang {
21301f2e99feSLydia Wang 	struct via_spec *spec = codec->spec;
21311f2e99feSLydia Wang 	vt1708_stop_hp_work(spec);
21321f2e99feSLydia Wang 	return 0;
21331f2e99feSLydia Wang }
21341f2e99feSLydia Wang #endif
21351f2e99feSLydia Wang 
2136cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
2137cb53c626STakashi Iwai static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2138cb53c626STakashi Iwai {
2139cb53c626STakashi Iwai 	struct via_spec *spec = codec->spec;
2140cb53c626STakashi Iwai 	return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2141cb53c626STakashi Iwai }
2142cb53c626STakashi Iwai #endif
2143cb53c626STakashi Iwai 
2144c577b8a1SJoseph Chan /*
2145c577b8a1SJoseph Chan  */
2146c577b8a1SJoseph Chan static struct hda_codec_ops via_patch_ops = {
2147c577b8a1SJoseph Chan 	.build_controls = via_build_controls,
2148c577b8a1SJoseph Chan 	.build_pcms = via_build_pcms,
2149c577b8a1SJoseph Chan 	.init = via_init,
2150c577b8a1SJoseph Chan 	.free = via_free,
21511f2e99feSLydia Wang #ifdef SND_HDA_NEEDS_RESUME
21521f2e99feSLydia Wang 	.suspend = via_suspend,
21531f2e99feSLydia Wang #endif
2154cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
2155cb53c626STakashi Iwai 	.check_power_status = via_check_power_status,
2156cb53c626STakashi Iwai #endif
2157c577b8a1SJoseph Chan };
2158c577b8a1SJoseph Chan 
2159c577b8a1SJoseph Chan /* fill in the dac_nids table from the parsed pin configuration */
2160c577b8a1SJoseph Chan static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2161c577b8a1SJoseph Chan 				     const struct auto_pin_cfg *cfg)
2162c577b8a1SJoseph Chan {
2163c577b8a1SJoseph Chan 	int i;
2164c577b8a1SJoseph Chan 	hda_nid_t nid;
2165c577b8a1SJoseph Chan 
2166c577b8a1SJoseph Chan 	spec->multiout.num_dacs = cfg->line_outs;
2167c577b8a1SJoseph Chan 
2168c577b8a1SJoseph Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
2169c577b8a1SJoseph Chan 
2170c577b8a1SJoseph Chan 	for (i = 0; i < 4; i++) {
2171c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
2172c577b8a1SJoseph Chan 		if (nid) {
2173c577b8a1SJoseph Chan 			/* config dac list */
2174c577b8a1SJoseph Chan 			switch (i) {
2175c577b8a1SJoseph Chan 			case AUTO_SEQ_FRONT:
2176c577b8a1SJoseph Chan 				spec->multiout.dac_nids[i] = 0x10;
2177c577b8a1SJoseph Chan 				break;
2178c577b8a1SJoseph Chan 			case AUTO_SEQ_CENLFE:
2179c577b8a1SJoseph Chan 				spec->multiout.dac_nids[i] = 0x12;
2180c577b8a1SJoseph Chan 				break;
2181c577b8a1SJoseph Chan 			case AUTO_SEQ_SURROUND:
2182fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
2183c577b8a1SJoseph Chan 				break;
2184c577b8a1SJoseph Chan 			case AUTO_SEQ_SIDE:
2185fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x13;
2186c577b8a1SJoseph Chan 				break;
2187c577b8a1SJoseph Chan 			}
2188c577b8a1SJoseph Chan 		}
2189c577b8a1SJoseph Chan 	}
2190c577b8a1SJoseph Chan 
2191c577b8a1SJoseph Chan 	return 0;
2192c577b8a1SJoseph Chan }
2193c577b8a1SJoseph Chan 
2194c577b8a1SJoseph Chan /* add playback controls from the parsed DAC table */
2195c577b8a1SJoseph Chan static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2196c577b8a1SJoseph Chan 					     const struct auto_pin_cfg *cfg)
2197c577b8a1SJoseph Chan {
2198c577b8a1SJoseph Chan 	char name[32];
2199c577b8a1SJoseph Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
22009645c203SLydia Wang 	hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2201c577b8a1SJoseph Chan 	int i, err;
2202c577b8a1SJoseph Chan 
2203c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2204c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
2205c577b8a1SJoseph Chan 
2206c577b8a1SJoseph Chan 		if (!nid)
2207c577b8a1SJoseph Chan 			continue;
2208c577b8a1SJoseph Chan 
22099645c203SLydia Wang 		nid_vol = nid_vols[i];
2210c577b8a1SJoseph Chan 
2211c577b8a1SJoseph Chan 		if (i == AUTO_SEQ_CENLFE) {
2212c577b8a1SJoseph Chan 			/* Center/LFE */
2213c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2214c577b8a1SJoseph Chan 					"Center Playback Volume",
2215f7278fd0SJosepch Chan 					HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2216f7278fd0SJosepch Chan 							    HDA_OUTPUT));
2217c577b8a1SJoseph Chan 			if (err < 0)
2218c577b8a1SJoseph Chan 				return err;
2219c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2220c577b8a1SJoseph Chan 					      "LFE Playback Volume",
2221f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2222f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2223c577b8a1SJoseph Chan 			if (err < 0)
2224c577b8a1SJoseph Chan 				return err;
2225c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2226c577b8a1SJoseph Chan 					      "Center Playback Switch",
2227f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2228f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2229c577b8a1SJoseph Chan 			if (err < 0)
2230c577b8a1SJoseph Chan 				return err;
2231c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2232c577b8a1SJoseph Chan 					      "LFE Playback Switch",
2233f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2234f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2235c577b8a1SJoseph Chan 			if (err < 0)
2236c577b8a1SJoseph Chan 				return err;
2237c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_FRONT) {
2238c577b8a1SJoseph Chan 			/* add control to mixer index 0 */
2239c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2240c577b8a1SJoseph Chan 					      "Master Front Playback Volume",
22419645c203SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2242f7278fd0SJosepch Chan 								  HDA_INPUT));
2243c577b8a1SJoseph Chan 			if (err < 0)
2244c577b8a1SJoseph Chan 				return err;
2245c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2246c577b8a1SJoseph Chan 					      "Master Front Playback Switch",
22479645c203SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2248f7278fd0SJosepch Chan 								  HDA_INPUT));
2249c577b8a1SJoseph Chan 			if (err < 0)
2250c577b8a1SJoseph Chan 				return err;
2251c577b8a1SJoseph Chan 
2252c577b8a1SJoseph Chan 			/* add control to PW3 */
2253c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2254c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2255f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2256f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2257c577b8a1SJoseph Chan 			if (err < 0)
2258c577b8a1SJoseph Chan 				return err;
2259c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2260c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2261f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2262f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2263c577b8a1SJoseph Chan 			if (err < 0)
2264c577b8a1SJoseph Chan 				return err;
2265c577b8a1SJoseph Chan 		} else {
2266c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2267c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2268f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2269f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2270c577b8a1SJoseph Chan 			if (err < 0)
2271c577b8a1SJoseph Chan 				return err;
2272c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2273c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2274f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2275f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2276c577b8a1SJoseph Chan 			if (err < 0)
2277c577b8a1SJoseph Chan 				return err;
2278c577b8a1SJoseph Chan 		}
2279c577b8a1SJoseph Chan 	}
2280c577b8a1SJoseph Chan 
2281c577b8a1SJoseph Chan 	return 0;
2282c577b8a1SJoseph Chan }
2283c577b8a1SJoseph Chan 
22840aa62aefSHarald Welte static void create_hp_imux(struct via_spec *spec)
22850aa62aefSHarald Welte {
22860aa62aefSHarald Welte 	int i;
22870aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[1];
22880aa62aefSHarald Welte 	static const char *texts[] = { "OFF", "ON", NULL};
22890aa62aefSHarald Welte 
22900aa62aefSHarald Welte 	/* for hp mode select */
22910aa62aefSHarald Welte 	i = 0;
22920aa62aefSHarald Welte 	while (texts[i] != NULL) {
22930aa62aefSHarald Welte 		imux->items[imux->num_items].label =  texts[i];
22940aa62aefSHarald Welte 		imux->items[imux->num_items].index = i;
22950aa62aefSHarald Welte 		imux->num_items++;
22960aa62aefSHarald Welte 		i++;
22970aa62aefSHarald Welte 	}
22980aa62aefSHarald Welte 
22990aa62aefSHarald Welte 	spec->hp_mux = &spec->private_imux[1];
23000aa62aefSHarald Welte }
23010aa62aefSHarald Welte 
2302c577b8a1SJoseph Chan static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2303c577b8a1SJoseph Chan {
2304c577b8a1SJoseph Chan 	int err;
2305c577b8a1SJoseph Chan 
2306c577b8a1SJoseph Chan 	if (!pin)
2307c577b8a1SJoseph Chan 		return 0;
2308c577b8a1SJoseph Chan 
2309c577b8a1SJoseph Chan 	spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2310cdc1784dSLydia Wang 	spec->hp_independent_mode_index = 1;
2311c577b8a1SJoseph Chan 
2312c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2313c577b8a1SJoseph Chan 			      "Headphone Playback Volume",
2314c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2315c577b8a1SJoseph Chan 	if (err < 0)
2316c577b8a1SJoseph Chan 		return err;
2317c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2318c577b8a1SJoseph Chan 			      "Headphone Playback Switch",
2319c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2320c577b8a1SJoseph Chan 	if (err < 0)
2321c577b8a1SJoseph Chan 		return err;
2322c577b8a1SJoseph Chan 
23230aa62aefSHarald Welte 	create_hp_imux(spec);
23240aa62aefSHarald Welte 
2325c577b8a1SJoseph Chan 	return 0;
2326c577b8a1SJoseph Chan }
2327c577b8a1SJoseph Chan 
2328c577b8a1SJoseph Chan /* create playback/capture controls for input pins */
2329c577b8a1SJoseph Chan static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2330c577b8a1SJoseph Chan 						const struct auto_pin_cfg *cfg)
2331c577b8a1SJoseph Chan {
2332c577b8a1SJoseph Chan 	static char *labels[] = {
2333c577b8a1SJoseph Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2334c577b8a1SJoseph Chan 	};
23350aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
2336c577b8a1SJoseph Chan 	int i, err, idx = 0;
2337c577b8a1SJoseph Chan 
2338c577b8a1SJoseph Chan 	/* for internal loopback recording select */
2339c577b8a1SJoseph Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
2340c577b8a1SJoseph Chan 	imux->items[imux->num_items].index = idx;
2341c577b8a1SJoseph Chan 	imux->num_items++;
2342c577b8a1SJoseph Chan 
2343c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
2344c577b8a1SJoseph Chan 		if (!cfg->input_pins[i])
2345c577b8a1SJoseph Chan 			continue;
2346c577b8a1SJoseph Chan 
2347c577b8a1SJoseph Chan 		switch (cfg->input_pins[i]) {
2348c577b8a1SJoseph Chan 		case 0x1d: /* Mic */
2349c577b8a1SJoseph Chan 			idx = 2;
2350c577b8a1SJoseph Chan 			break;
2351c577b8a1SJoseph Chan 
2352c577b8a1SJoseph Chan 		case 0x1e: /* Line In */
2353c577b8a1SJoseph Chan 			idx = 3;
2354c577b8a1SJoseph Chan 			break;
2355c577b8a1SJoseph Chan 
2356c577b8a1SJoseph Chan 		case 0x21: /* Front Mic */
2357c577b8a1SJoseph Chan 			idx = 4;
2358c577b8a1SJoseph Chan 			break;
2359c577b8a1SJoseph Chan 
2360c577b8a1SJoseph Chan 		case 0x24: /* CD */
2361c577b8a1SJoseph Chan 			idx = 1;
2362c577b8a1SJoseph Chan 			break;
2363c577b8a1SJoseph Chan 		}
23649510e8ddSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x17);
2365c577b8a1SJoseph Chan 		if (err < 0)
2366c577b8a1SJoseph Chan 			return err;
2367c577b8a1SJoseph Chan 		imux->items[imux->num_items].label = labels[i];
2368c577b8a1SJoseph Chan 		imux->items[imux->num_items].index = idx;
2369c577b8a1SJoseph Chan 		imux->num_items++;
2370c577b8a1SJoseph Chan 	}
2371c577b8a1SJoseph Chan 	return 0;
2372c577b8a1SJoseph Chan }
2373c577b8a1SJoseph Chan 
2374cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
2375cb53c626STakashi Iwai static struct hda_amp_list vt1708_loopbacks[] = {
2376cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 1 },
2377cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 2 },
2378cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 3 },
2379cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 4 },
2380cb53c626STakashi Iwai 	{ } /* end */
2381cb53c626STakashi Iwai };
2382cb53c626STakashi Iwai #endif
2383cb53c626STakashi Iwai 
238476d9b0ddSHarald Welte static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
238576d9b0ddSHarald Welte {
238676d9b0ddSHarald Welte 	unsigned int def_conf;
238776d9b0ddSHarald Welte 	unsigned char seqassoc;
238876d9b0ddSHarald Welte 
23892f334f92STakashi Iwai 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
239076d9b0ddSHarald Welte 	seqassoc = (unsigned char) get_defcfg_association(def_conf);
239176d9b0ddSHarald Welte 	seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
239282ef9e45SLydia Wang 	if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
239382ef9e45SLydia Wang 	    && (seqassoc == 0xf0 || seqassoc == 0xff)) {
239476d9b0ddSHarald Welte 		def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
23952f334f92STakashi Iwai 		snd_hda_codec_set_pincfg(codec, nid, def_conf);
239676d9b0ddSHarald Welte 	}
239776d9b0ddSHarald Welte 
239876d9b0ddSHarald Welte 	return;
239976d9b0ddSHarald Welte }
240076d9b0ddSHarald Welte 
24011f2e99feSLydia Wang static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
24021f2e99feSLydia Wang 				     struct snd_ctl_elem_value *ucontrol)
24031f2e99feSLydia Wang {
24041f2e99feSLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
24051f2e99feSLydia Wang 	struct via_spec *spec = codec->spec;
24061f2e99feSLydia Wang 
24071f2e99feSLydia Wang 	if (spec->codec_type != VT1708)
24081f2e99feSLydia Wang 		return 0;
24091f2e99feSLydia Wang 	spec->vt1708_jack_detectect =
24101f2e99feSLydia Wang 		!((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
24111f2e99feSLydia Wang 	ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
24121f2e99feSLydia Wang 	return 0;
24131f2e99feSLydia Wang }
24141f2e99feSLydia Wang 
24151f2e99feSLydia Wang static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
24161f2e99feSLydia Wang 				     struct snd_ctl_elem_value *ucontrol)
24171f2e99feSLydia Wang {
24181f2e99feSLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
24191f2e99feSLydia Wang 	struct via_spec *spec = codec->spec;
24201f2e99feSLydia Wang 	int change;
24211f2e99feSLydia Wang 
24221f2e99feSLydia Wang 	if (spec->codec_type != VT1708)
24231f2e99feSLydia Wang 		return 0;
24241f2e99feSLydia Wang 	spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
24251f2e99feSLydia Wang 	change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
24261f2e99feSLydia Wang 		== !spec->vt1708_jack_detectect;
24271f2e99feSLydia Wang 	if (spec->vt1708_jack_detectect) {
24281f2e99feSLydia Wang 		mute_aa_path(codec, 1);
24291f2e99feSLydia Wang 		notify_aa_path_ctls(codec);
24301f2e99feSLydia Wang 	}
24311f2e99feSLydia Wang 	return change;
24321f2e99feSLydia Wang }
24331f2e99feSLydia Wang 
24341f2e99feSLydia Wang static struct snd_kcontrol_new vt1708_jack_detectect[] = {
24351f2e99feSLydia Wang 	{
24361f2e99feSLydia Wang 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
24371f2e99feSLydia Wang 		.name = "Jack Detect",
24381f2e99feSLydia Wang 		.count = 1,
24391f2e99feSLydia Wang 		.info = snd_ctl_boolean_mono_info,
24401f2e99feSLydia Wang 		.get = vt1708_jack_detectect_get,
24411f2e99feSLydia Wang 		.put = vt1708_jack_detectect_put,
24421f2e99feSLydia Wang 	},
24431f2e99feSLydia Wang 	{} /* end */
24441f2e99feSLydia Wang };
24451f2e99feSLydia Wang 
2446c577b8a1SJoseph Chan static int vt1708_parse_auto_config(struct hda_codec *codec)
2447c577b8a1SJoseph Chan {
2448c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
2449c577b8a1SJoseph Chan 	int err;
2450c577b8a1SJoseph Chan 
245176d9b0ddSHarald Welte 	/* Add HP and CD pin config connect bit re-config action */
245276d9b0ddSHarald Welte 	vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
245376d9b0ddSHarald Welte 	vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
245476d9b0ddSHarald Welte 
2455c577b8a1SJoseph Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2456c577b8a1SJoseph Chan 	if (err < 0)
2457c577b8a1SJoseph Chan 		return err;
2458c577b8a1SJoseph Chan 	err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2459c577b8a1SJoseph Chan 	if (err < 0)
2460c577b8a1SJoseph Chan 		return err;
2461c577b8a1SJoseph Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2462c577b8a1SJoseph Chan 		return 0; /* can't find valid BIOS pin config */
2463c577b8a1SJoseph Chan 
2464c577b8a1SJoseph Chan 	err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2465c577b8a1SJoseph Chan 	if (err < 0)
2466c577b8a1SJoseph Chan 		return err;
2467c577b8a1SJoseph Chan 	err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2468c577b8a1SJoseph Chan 	if (err < 0)
2469c577b8a1SJoseph Chan 		return err;
2470c577b8a1SJoseph Chan 	err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2471c577b8a1SJoseph Chan 	if (err < 0)
2472c577b8a1SJoseph Chan 		return err;
24731f2e99feSLydia Wang 	/* add jack detect on/off control */
24741f2e99feSLydia Wang 	err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
24751f2e99feSLydia Wang 	if (err < 0)
24761f2e99feSLydia Wang 		return err;
2477c577b8a1SJoseph Chan 
2478c577b8a1SJoseph Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2479c577b8a1SJoseph Chan 
24800852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
2481c577b8a1SJoseph Chan 		spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
248255d1d6c1STakashi Iwai 	spec->dig_in_pin = VT1708_DIGIN_PIN;
2483c577b8a1SJoseph Chan 	if (spec->autocfg.dig_in_pin)
2484c577b8a1SJoseph Chan 		spec->dig_in_nid = VT1708_DIGIN_NID;
2485c577b8a1SJoseph Chan 
2486603c4019STakashi Iwai 	if (spec->kctls.list)
2487603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
2488c577b8a1SJoseph Chan 
248969e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2490c577b8a1SJoseph Chan 
24910aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
24920aa62aefSHarald Welte 
2493f8fdd495SHarald Welte 	if (spec->hp_mux)
24940aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
2495c577b8a1SJoseph Chan 
24961564b287SLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2497c577b8a1SJoseph Chan 	return 1;
2498c577b8a1SJoseph Chan }
2499c577b8a1SJoseph Chan 
2500c577b8a1SJoseph Chan /* init callback for auto-configuration model -- overriding the default init */
2501c577b8a1SJoseph Chan static int via_auto_init(struct hda_codec *codec)
2502c577b8a1SJoseph Chan {
250325eaba2fSLydia Wang 	struct via_spec *spec = codec->spec;
250425eaba2fSLydia Wang 
2505c577b8a1SJoseph Chan 	via_init(codec);
2506c577b8a1SJoseph Chan 	via_auto_init_multi_out(codec);
2507c577b8a1SJoseph Chan 	via_auto_init_hp_out(codec);
2508c577b8a1SJoseph Chan 	via_auto_init_analog_input(codec);
2509ab6734e7SLydia Wang 	if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
251025eaba2fSLydia Wang 		via_hp_bind_automute(codec);
251125eaba2fSLydia Wang 	} else {
251225eaba2fSLydia Wang 		via_hp_automute(codec);
251325eaba2fSLydia Wang 		via_speaker_automute(codec);
251425eaba2fSLydia Wang 	}
251525eaba2fSLydia Wang 
2516c577b8a1SJoseph Chan 	return 0;
2517c577b8a1SJoseph Chan }
2518c577b8a1SJoseph Chan 
25191f2e99feSLydia Wang static void vt1708_update_hp_jack_state(struct work_struct *work)
25201f2e99feSLydia Wang {
25211f2e99feSLydia Wang 	struct via_spec *spec = container_of(work, struct via_spec,
25221f2e99feSLydia Wang 					     vt1708_hp_work.work);
25231f2e99feSLydia Wang 	if (spec->codec_type != VT1708)
25241f2e99feSLydia Wang 		return;
25251f2e99feSLydia Wang 	/* if jack state toggled */
25261f2e99feSLydia Wang 	if (spec->vt1708_hp_present
25271f2e99feSLydia Wang 	    != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
25281f2e99feSLydia Wang 				   AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
25291f2e99feSLydia Wang 		spec->vt1708_hp_present ^= 1;
25301f2e99feSLydia Wang 		via_hp_automute(spec->codec);
25311f2e99feSLydia Wang 	}
25321f2e99feSLydia Wang 	vt1708_start_hp_work(spec);
25331f2e99feSLydia Wang }
25341f2e99feSLydia Wang 
2535337b9d02STakashi Iwai static int get_mux_nids(struct hda_codec *codec)
2536337b9d02STakashi Iwai {
2537337b9d02STakashi Iwai 	struct via_spec *spec = codec->spec;
2538337b9d02STakashi Iwai 	hda_nid_t nid, conn[8];
2539337b9d02STakashi Iwai 	unsigned int type;
2540337b9d02STakashi Iwai 	int i, n;
2541337b9d02STakashi Iwai 
2542337b9d02STakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
2543337b9d02STakashi Iwai 		nid = spec->adc_nids[i];
2544337b9d02STakashi Iwai 		while (nid) {
2545a22d543aSTakashi Iwai 			type = get_wcaps_type(get_wcaps(codec, nid));
25461c55d521STakashi Iwai 			if (type == AC_WID_PIN)
25471c55d521STakashi Iwai 				break;
2548337b9d02STakashi Iwai 			n = snd_hda_get_connections(codec, nid, conn,
2549337b9d02STakashi Iwai 						    ARRAY_SIZE(conn));
2550337b9d02STakashi Iwai 			if (n <= 0)
2551337b9d02STakashi Iwai 				break;
2552337b9d02STakashi Iwai 			if (n > 1) {
2553337b9d02STakashi Iwai 				spec->mux_nids[i] = nid;
2554337b9d02STakashi Iwai 				break;
2555337b9d02STakashi Iwai 			}
2556337b9d02STakashi Iwai 			nid = conn[0];
2557337b9d02STakashi Iwai 		}
2558337b9d02STakashi Iwai 	}
25591c55d521STakashi Iwai 	return 0;
2560337b9d02STakashi Iwai }
2561337b9d02STakashi Iwai 
2562c577b8a1SJoseph Chan static int patch_vt1708(struct hda_codec *codec)
2563c577b8a1SJoseph Chan {
2564c577b8a1SJoseph Chan 	struct via_spec *spec;
2565c577b8a1SJoseph Chan 	int err;
2566c577b8a1SJoseph Chan 
2567c577b8a1SJoseph Chan 	/* create a codec specific record */
2568eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2569c577b8a1SJoseph Chan 	if (spec == NULL)
2570c577b8a1SJoseph Chan 		return -ENOMEM;
2571c577b8a1SJoseph Chan 
2572c577b8a1SJoseph Chan 	codec->spec = spec;
2573c577b8a1SJoseph Chan 
2574c577b8a1SJoseph Chan 	/* automatic parse from the BIOS config */
2575c577b8a1SJoseph Chan 	err = vt1708_parse_auto_config(codec);
2576c577b8a1SJoseph Chan 	if (err < 0) {
2577c577b8a1SJoseph Chan 		via_free(codec);
2578c577b8a1SJoseph Chan 		return err;
2579c577b8a1SJoseph Chan 	} else if (!err) {
2580c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
2581c577b8a1SJoseph Chan 		       "from BIOS.  Using genenic mode...\n");
2582c577b8a1SJoseph Chan 	}
2583c577b8a1SJoseph Chan 
2584c577b8a1SJoseph Chan 
2585c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1708 Analog";
2586c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2587bc9b5623STakashi Iwai 	/* disable 32bit format on VT1708 */
2588bc9b5623STakashi Iwai 	if (codec->vendor_id == 0x11061708)
2589bc9b5623STakashi Iwai 		spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2590c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2591c577b8a1SJoseph Chan 
2592c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1708 Digital";
2593c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2594c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2595c577b8a1SJoseph Chan 
2596c577b8a1SJoseph Chan 
2597c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
2598c577b8a1SJoseph Chan 		spec->adc_nids = vt1708_adc_nids;
2599c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
26000f67a611STakashi Iwai 		get_mux_nids(codec);
2601c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2602c577b8a1SJoseph Chan 		spec->num_mixers++;
2603c577b8a1SJoseph Chan 	}
2604c577b8a1SJoseph Chan 
2605c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
2606c577b8a1SJoseph Chan 
2607c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
2608cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
2609cb53c626STakashi Iwai 	spec->loopback.amplist = vt1708_loopbacks;
2610cb53c626STakashi Iwai #endif
26111f2e99feSLydia Wang 	spec->codec = codec;
26121f2e99feSLydia Wang 	INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2613c577b8a1SJoseph Chan 	return 0;
2614c577b8a1SJoseph Chan }
2615c577b8a1SJoseph Chan 
2616c577b8a1SJoseph Chan /* capture mixer elements */
2617c577b8a1SJoseph Chan static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2618c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2619c577b8a1SJoseph Chan 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2620c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2621c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2622c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2623c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2624c577b8a1SJoseph Chan 	{
2625c577b8a1SJoseph Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2626c577b8a1SJoseph Chan 		/* The multiple "Capture Source" controls confuse alsamixer
2627c577b8a1SJoseph Chan 		 * So call somewhat different..
2628c577b8a1SJoseph Chan 		 */
2629c577b8a1SJoseph Chan 		/* .name = "Capture Source", */
2630c577b8a1SJoseph Chan 		.name = "Input Source",
2631c577b8a1SJoseph Chan 		.count = 1,
2632c577b8a1SJoseph Chan 		.info = via_mux_enum_info,
2633c577b8a1SJoseph Chan 		.get = via_mux_enum_get,
2634c577b8a1SJoseph Chan 		.put = via_mux_enum_put,
2635c577b8a1SJoseph Chan 	},
2636c577b8a1SJoseph Chan 	{ } /* end */
2637c577b8a1SJoseph Chan };
2638c577b8a1SJoseph Chan 
263969e52a80SHarald Welte static struct hda_verb vt1709_uniwill_init_verbs[] = {
2640a34df19aSLydia Wang 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2641a34df19aSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
264269e52a80SHarald Welte 	{ }
264369e52a80SHarald Welte };
264469e52a80SHarald Welte 
2645c577b8a1SJoseph Chan /*
2646c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
2647c577b8a1SJoseph Chan  */
2648c577b8a1SJoseph Chan static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2649c577b8a1SJoseph Chan 	/*
2650c577b8a1SJoseph Chan 	 * Unmute ADC0-2 and set the default input to mic-in
2651c577b8a1SJoseph Chan 	 */
2652c577b8a1SJoseph Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2653c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2654c577b8a1SJoseph Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2655c577b8a1SJoseph Chan 
2656c577b8a1SJoseph Chan 
2657f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2658c577b8a1SJoseph Chan 	 * mixer widget
2659c577b8a1SJoseph Chan 	 */
2660c577b8a1SJoseph Chan 	/* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2661f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2662f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2663f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2664f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2665f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2666c577b8a1SJoseph Chan 
2667c577b8a1SJoseph Chan 	/*
2668c577b8a1SJoseph Chan 	 * Set up output selector (0x1a, 0x1b, 0x29)
2669c577b8a1SJoseph Chan 	 */
2670c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
2671c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2672c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2673c577b8a1SJoseph Chan 	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2674c577b8a1SJoseph Chan 
2675c577b8a1SJoseph Chan 	/*
2676c577b8a1SJoseph Chan 	 *  Unmute PW3 and PW4
2677c577b8a1SJoseph Chan 	 */
2678c577b8a1SJoseph Chan 	{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2679c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2680c577b8a1SJoseph Chan 
2681bfdc675aSLydia Wang 	/* Set input of PW4 as MW0 */
2682bfdc675aSLydia Wang 	{0x20, AC_VERB_SET_CONNECT_SEL, 0},
2683c577b8a1SJoseph Chan 	/* PW9 Output enable */
2684c577b8a1SJoseph Chan 	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2685c577b8a1SJoseph Chan 	{ }
2686c577b8a1SJoseph Chan };
2687c577b8a1SJoseph Chan 
2688c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2689c577b8a1SJoseph Chan 	.substreams = 1,
2690c577b8a1SJoseph Chan 	.channels_min = 2,
2691c577b8a1SJoseph Chan 	.channels_max = 10,
2692c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
2693c577b8a1SJoseph Chan 	.ops = {
2694c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
2695c873cc25SLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
2696c873cc25SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
2697c577b8a1SJoseph Chan 	},
2698c577b8a1SJoseph Chan };
2699c577b8a1SJoseph Chan 
2700c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2701c577b8a1SJoseph Chan 	.substreams = 1,
2702c577b8a1SJoseph Chan 	.channels_min = 2,
2703c577b8a1SJoseph Chan 	.channels_max = 6,
2704c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
2705c577b8a1SJoseph Chan 	.ops = {
2706c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
2707c873cc25SLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
2708c873cc25SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
2709c577b8a1SJoseph Chan 	},
2710c577b8a1SJoseph Chan };
2711c577b8a1SJoseph Chan 
2712c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2713c577b8a1SJoseph Chan 	.substreams = 2,
2714c577b8a1SJoseph Chan 	.channels_min = 2,
2715c577b8a1SJoseph Chan 	.channels_max = 2,
2716c577b8a1SJoseph Chan 	.nid = 0x14, /* NID to query formats and rates */
2717c577b8a1SJoseph Chan 	.ops = {
2718c577b8a1SJoseph Chan 		.prepare = via_capture_pcm_prepare,
2719c577b8a1SJoseph Chan 		.cleanup = via_capture_pcm_cleanup
2720c577b8a1SJoseph Chan 	},
2721c577b8a1SJoseph Chan };
2722c577b8a1SJoseph Chan 
2723c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2724c577b8a1SJoseph Chan 	.substreams = 1,
2725c577b8a1SJoseph Chan 	.channels_min = 2,
2726c577b8a1SJoseph Chan 	.channels_max = 2,
2727c577b8a1SJoseph Chan 	/* NID is set in via_build_pcms */
2728c577b8a1SJoseph Chan 	.ops = {
2729c577b8a1SJoseph Chan 		.open = via_dig_playback_pcm_open,
2730c577b8a1SJoseph Chan 		.close = via_dig_playback_pcm_close
2731c577b8a1SJoseph Chan 	},
2732c577b8a1SJoseph Chan };
2733c577b8a1SJoseph Chan 
2734c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2735c577b8a1SJoseph Chan 	.substreams = 1,
2736c577b8a1SJoseph Chan 	.channels_min = 2,
2737c577b8a1SJoseph Chan 	.channels_max = 2,
2738c577b8a1SJoseph Chan };
2739c577b8a1SJoseph Chan 
2740c577b8a1SJoseph Chan static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2741c577b8a1SJoseph Chan 				     const struct auto_pin_cfg *cfg)
2742c577b8a1SJoseph Chan {
2743c577b8a1SJoseph Chan 	int i;
2744c577b8a1SJoseph Chan 	hda_nid_t nid;
2745c577b8a1SJoseph Chan 
2746c577b8a1SJoseph Chan 	if (cfg->line_outs == 4)  /* 10 channels */
2747c577b8a1SJoseph Chan 		spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2748c577b8a1SJoseph Chan 	else if (cfg->line_outs == 3) /* 6 channels */
2749c577b8a1SJoseph Chan 		spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2750c577b8a1SJoseph Chan 
2751c577b8a1SJoseph Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
2752c577b8a1SJoseph Chan 
2753c577b8a1SJoseph Chan 	if (cfg->line_outs == 4) { /* 10 channels */
2754c577b8a1SJoseph Chan 		for (i = 0; i < cfg->line_outs; i++) {
2755c577b8a1SJoseph Chan 			nid = cfg->line_out_pins[i];
2756c577b8a1SJoseph Chan 			if (nid) {
2757c577b8a1SJoseph Chan 				/* config dac list */
2758c577b8a1SJoseph Chan 				switch (i) {
2759c577b8a1SJoseph Chan 				case AUTO_SEQ_FRONT:
2760c577b8a1SJoseph Chan 					/* AOW0 */
2761c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x10;
2762c577b8a1SJoseph Chan 					break;
2763c577b8a1SJoseph Chan 				case AUTO_SEQ_CENLFE:
2764c577b8a1SJoseph Chan 					/* AOW2 */
2765c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x12;
2766c577b8a1SJoseph Chan 					break;
2767c577b8a1SJoseph Chan 				case AUTO_SEQ_SURROUND:
2768c577b8a1SJoseph Chan 					/* AOW3 */
2769fb4cb772SHarald Welte 					spec->multiout.dac_nids[i] = 0x11;
2770c577b8a1SJoseph Chan 					break;
2771c577b8a1SJoseph Chan 				case AUTO_SEQ_SIDE:
2772c577b8a1SJoseph Chan 					/* AOW1 */
2773fb4cb772SHarald Welte 					spec->multiout.dac_nids[i] = 0x27;
2774c577b8a1SJoseph Chan 					break;
2775c577b8a1SJoseph Chan 				default:
2776c577b8a1SJoseph Chan 					break;
2777c577b8a1SJoseph Chan 				}
2778c577b8a1SJoseph Chan 			}
2779c577b8a1SJoseph Chan 		}
2780c577b8a1SJoseph Chan 		spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2781c577b8a1SJoseph Chan 
2782c577b8a1SJoseph Chan 	} else if (cfg->line_outs == 3) { /* 6 channels */
2783c577b8a1SJoseph Chan 		for (i = 0; i < cfg->line_outs; i++) {
2784c577b8a1SJoseph Chan 			nid = cfg->line_out_pins[i];
2785c577b8a1SJoseph Chan 			if (nid) {
2786c577b8a1SJoseph Chan 				/* config dac list */
2787c577b8a1SJoseph Chan 				switch (i) {
2788c577b8a1SJoseph Chan 				case AUTO_SEQ_FRONT:
2789c577b8a1SJoseph Chan 					/* AOW0 */
2790c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x10;
2791c577b8a1SJoseph Chan 					break;
2792c577b8a1SJoseph Chan 				case AUTO_SEQ_CENLFE:
2793c577b8a1SJoseph Chan 					/* AOW2 */
2794c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x12;
2795c577b8a1SJoseph Chan 					break;
2796c577b8a1SJoseph Chan 				case AUTO_SEQ_SURROUND:
2797c577b8a1SJoseph Chan 					/* AOW1 */
2798c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x11;
2799c577b8a1SJoseph Chan 					break;
2800c577b8a1SJoseph Chan 				default:
2801c577b8a1SJoseph Chan 					break;
2802c577b8a1SJoseph Chan 				}
2803c577b8a1SJoseph Chan 			}
2804c577b8a1SJoseph Chan 		}
2805c577b8a1SJoseph Chan 	}
2806c577b8a1SJoseph Chan 
2807c577b8a1SJoseph Chan 	return 0;
2808c577b8a1SJoseph Chan }
2809c577b8a1SJoseph Chan 
2810c577b8a1SJoseph Chan /* add playback controls from the parsed DAC table */
2811c577b8a1SJoseph Chan static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2812c577b8a1SJoseph Chan 					     const struct auto_pin_cfg *cfg)
2813c577b8a1SJoseph Chan {
2814c577b8a1SJoseph Chan 	char name[32];
2815c577b8a1SJoseph Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
28164483a2f5SLydia Wang 	hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2817c577b8a1SJoseph Chan 	int i, err;
2818c577b8a1SJoseph Chan 
2819c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2820c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
2821c577b8a1SJoseph Chan 
2822c577b8a1SJoseph Chan 		if (!nid)
2823c577b8a1SJoseph Chan 			continue;
2824c577b8a1SJoseph Chan 
28254483a2f5SLydia Wang 		nid_vol = nid_vols[i];
28264483a2f5SLydia Wang 
2827c577b8a1SJoseph Chan 		if (i == AUTO_SEQ_CENLFE) {
2828c577b8a1SJoseph Chan 			/* Center/LFE */
2829c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2830c577b8a1SJoseph Chan 					      "Center Playback Volume",
28314483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2832f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2833c577b8a1SJoseph Chan 			if (err < 0)
2834c577b8a1SJoseph Chan 				return err;
2835c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2836c577b8a1SJoseph Chan 					      "LFE Playback Volume",
28374483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2838f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2839c577b8a1SJoseph Chan 			if (err < 0)
2840c577b8a1SJoseph Chan 				return err;
2841c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2842c577b8a1SJoseph Chan 					      "Center Playback Switch",
28434483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2844f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2845c577b8a1SJoseph Chan 			if (err < 0)
2846c577b8a1SJoseph Chan 				return err;
2847c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2848c577b8a1SJoseph Chan 					      "LFE Playback Switch",
28494483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2850f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2851c577b8a1SJoseph Chan 			if (err < 0)
2852c577b8a1SJoseph Chan 				return err;
2853c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_FRONT) {
28544483a2f5SLydia Wang 			/* ADD control to mixer index 0 */
2855c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2856c577b8a1SJoseph Chan 					      "Master Front Playback Volume",
28574483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2858f7278fd0SJosepch Chan 								  HDA_INPUT));
2859c577b8a1SJoseph Chan 			if (err < 0)
2860c577b8a1SJoseph Chan 				return err;
2861c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2862c577b8a1SJoseph Chan 					      "Master Front Playback Switch",
28634483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2864f7278fd0SJosepch Chan 								  HDA_INPUT));
2865c577b8a1SJoseph Chan 			if (err < 0)
2866c577b8a1SJoseph Chan 				return err;
2867c577b8a1SJoseph Chan 
2868c577b8a1SJoseph Chan 			/* add control to PW3 */
2869c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2870c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2871f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2872f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2873c577b8a1SJoseph Chan 			if (err < 0)
2874c577b8a1SJoseph Chan 				return err;
2875c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2876c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2877f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2878f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2879c577b8a1SJoseph Chan 			if (err < 0)
2880c577b8a1SJoseph Chan 				return err;
2881c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_SURROUND) {
2882c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2883c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
28844483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2885f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2886c577b8a1SJoseph Chan 			if (err < 0)
2887c577b8a1SJoseph Chan 				return err;
2888c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2889c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
28904483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2891f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2892c577b8a1SJoseph Chan 			if (err < 0)
2893c577b8a1SJoseph Chan 				return err;
2894c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_SIDE) {
2895c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2896c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
28974483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2898f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2899c577b8a1SJoseph Chan 			if (err < 0)
2900c577b8a1SJoseph Chan 				return err;
2901c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2902c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
29034483a2f5SLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2904f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2905c577b8a1SJoseph Chan 			if (err < 0)
2906c577b8a1SJoseph Chan 				return err;
2907c577b8a1SJoseph Chan 		}
2908c577b8a1SJoseph Chan 	}
2909c577b8a1SJoseph Chan 
2910c577b8a1SJoseph Chan 	return 0;
2911c577b8a1SJoseph Chan }
2912c577b8a1SJoseph Chan 
2913c577b8a1SJoseph Chan static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2914c577b8a1SJoseph Chan {
2915c577b8a1SJoseph Chan 	int err;
2916c577b8a1SJoseph Chan 
2917c577b8a1SJoseph Chan 	if (!pin)
2918c577b8a1SJoseph Chan 		return 0;
2919c577b8a1SJoseph Chan 
2920c577b8a1SJoseph Chan 	if (spec->multiout.num_dacs == 5) /* 10 channels */
2921c577b8a1SJoseph Chan 		spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2922c577b8a1SJoseph Chan 	else if (spec->multiout.num_dacs == 3) /* 6 channels */
2923c577b8a1SJoseph Chan 		spec->multiout.hp_nid = 0;
2924cdc1784dSLydia Wang 	spec->hp_independent_mode_index = 1;
2925c577b8a1SJoseph Chan 
2926c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2927c577b8a1SJoseph Chan 			      "Headphone Playback Volume",
2928c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2929c577b8a1SJoseph Chan 	if (err < 0)
2930c577b8a1SJoseph Chan 		return err;
2931c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2932c577b8a1SJoseph Chan 			      "Headphone Playback Switch",
2933c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2934c577b8a1SJoseph Chan 	if (err < 0)
2935c577b8a1SJoseph Chan 		return err;
2936c577b8a1SJoseph Chan 
2937c577b8a1SJoseph Chan 	return 0;
2938c577b8a1SJoseph Chan }
2939c577b8a1SJoseph Chan 
2940c577b8a1SJoseph Chan /* create playback/capture controls for input pins */
2941c577b8a1SJoseph Chan static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2942c577b8a1SJoseph Chan 						const struct auto_pin_cfg *cfg)
2943c577b8a1SJoseph Chan {
2944c577b8a1SJoseph Chan 	static char *labels[] = {
2945c577b8a1SJoseph Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2946c577b8a1SJoseph Chan 	};
29470aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
2948c577b8a1SJoseph Chan 	int i, err, idx = 0;
2949c577b8a1SJoseph Chan 
2950c577b8a1SJoseph Chan 	/* for internal loopback recording select */
2951c577b8a1SJoseph Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
2952c577b8a1SJoseph Chan 	imux->items[imux->num_items].index = idx;
2953c577b8a1SJoseph Chan 	imux->num_items++;
2954c577b8a1SJoseph Chan 
2955c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
2956c577b8a1SJoseph Chan 		if (!cfg->input_pins[i])
2957c577b8a1SJoseph Chan 			continue;
2958c577b8a1SJoseph Chan 
2959c577b8a1SJoseph Chan 		switch (cfg->input_pins[i]) {
2960c577b8a1SJoseph Chan 		case 0x1d: /* Mic */
2961c577b8a1SJoseph Chan 			idx = 2;
2962c577b8a1SJoseph Chan 			break;
2963c577b8a1SJoseph Chan 
2964c577b8a1SJoseph Chan 		case 0x1e: /* Line In */
2965c577b8a1SJoseph Chan 			idx = 3;
2966c577b8a1SJoseph Chan 			break;
2967c577b8a1SJoseph Chan 
2968c577b8a1SJoseph Chan 		case 0x21: /* Front Mic */
2969c577b8a1SJoseph Chan 			idx = 4;
2970c577b8a1SJoseph Chan 			break;
2971c577b8a1SJoseph Chan 
2972c577b8a1SJoseph Chan 		case 0x23: /* CD */
2973c577b8a1SJoseph Chan 			idx = 1;
2974c577b8a1SJoseph Chan 			break;
2975c577b8a1SJoseph Chan 		}
29769510e8ddSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x18);
2977c577b8a1SJoseph Chan 		if (err < 0)
2978c577b8a1SJoseph Chan 			return err;
2979c577b8a1SJoseph Chan 		imux->items[imux->num_items].label = labels[i];
2980c577b8a1SJoseph Chan 		imux->items[imux->num_items].index = idx;
2981c577b8a1SJoseph Chan 		imux->num_items++;
2982c577b8a1SJoseph Chan 	}
2983c577b8a1SJoseph Chan 	return 0;
2984c577b8a1SJoseph Chan }
2985c577b8a1SJoseph Chan 
2986c577b8a1SJoseph Chan static int vt1709_parse_auto_config(struct hda_codec *codec)
2987c577b8a1SJoseph Chan {
2988c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
2989c577b8a1SJoseph Chan 	int err;
2990c577b8a1SJoseph Chan 
2991c577b8a1SJoseph Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2992c577b8a1SJoseph Chan 	if (err < 0)
2993c577b8a1SJoseph Chan 		return err;
2994c577b8a1SJoseph Chan 	err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2995c577b8a1SJoseph Chan 	if (err < 0)
2996c577b8a1SJoseph Chan 		return err;
2997c577b8a1SJoseph Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2998c577b8a1SJoseph Chan 		return 0; /* can't find valid BIOS pin config */
2999c577b8a1SJoseph Chan 
3000c577b8a1SJoseph Chan 	err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3001c577b8a1SJoseph Chan 	if (err < 0)
3002c577b8a1SJoseph Chan 		return err;
3003c577b8a1SJoseph Chan 	err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3004c577b8a1SJoseph Chan 	if (err < 0)
3005c577b8a1SJoseph Chan 		return err;
3006c577b8a1SJoseph Chan 	err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3007c577b8a1SJoseph Chan 	if (err < 0)
3008c577b8a1SJoseph Chan 		return err;
3009c577b8a1SJoseph Chan 
3010c577b8a1SJoseph Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3011c577b8a1SJoseph Chan 
30120852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
3013c577b8a1SJoseph Chan 		spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
301455d1d6c1STakashi Iwai 	spec->dig_in_pin = VT1709_DIGIN_PIN;
3015c577b8a1SJoseph Chan 	if (spec->autocfg.dig_in_pin)
3016c577b8a1SJoseph Chan 		spec->dig_in_nid = VT1709_DIGIN_NID;
3017c577b8a1SJoseph Chan 
3018603c4019STakashi Iwai 	if (spec->kctls.list)
3019603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
3020c577b8a1SJoseph Chan 
30210aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
3022c577b8a1SJoseph Chan 
3023f8fdd495SHarald Welte 	if (spec->hp_mux)
3024f8fdd495SHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
3025f8fdd495SHarald Welte 
30261564b287SLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3027c577b8a1SJoseph Chan 	return 1;
3028c577b8a1SJoseph Chan }
3029c577b8a1SJoseph Chan 
3030cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3031cb53c626STakashi Iwai static struct hda_amp_list vt1709_loopbacks[] = {
3032cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 1 },
3033cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 2 },
3034cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 3 },
3035cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 4 },
3036cb53c626STakashi Iwai 	{ } /* end */
3037cb53c626STakashi Iwai };
3038cb53c626STakashi Iwai #endif
3039cb53c626STakashi Iwai 
3040c577b8a1SJoseph Chan static int patch_vt1709_10ch(struct hda_codec *codec)
3041c577b8a1SJoseph Chan {
3042c577b8a1SJoseph Chan 	struct via_spec *spec;
3043c577b8a1SJoseph Chan 	int err;
3044c577b8a1SJoseph Chan 
3045c577b8a1SJoseph Chan 	/* create a codec specific record */
3046eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3047c577b8a1SJoseph Chan 	if (spec == NULL)
3048c577b8a1SJoseph Chan 		return -ENOMEM;
3049c577b8a1SJoseph Chan 
3050c577b8a1SJoseph Chan 	codec->spec = spec;
3051c577b8a1SJoseph Chan 
3052c577b8a1SJoseph Chan 	err = vt1709_parse_auto_config(codec);
3053c577b8a1SJoseph Chan 	if (err < 0) {
3054c577b8a1SJoseph Chan 		via_free(codec);
3055c577b8a1SJoseph Chan 		return err;
3056c577b8a1SJoseph Chan 	} else if (!err) {
3057c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration.  "
3058c577b8a1SJoseph Chan 		       "Using genenic mode...\n");
3059c577b8a1SJoseph Chan 	}
3060c577b8a1SJoseph Chan 
306169e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
306269e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3063c577b8a1SJoseph Chan 
3064c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1709 Analog";
3065c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3066c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3067c577b8a1SJoseph Chan 
3068c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1709 Digital";
3069c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3070c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3071c577b8a1SJoseph Chan 
3072c577b8a1SJoseph Chan 
3073c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
3074c577b8a1SJoseph Chan 		spec->adc_nids = vt1709_adc_nids;
3075c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3076337b9d02STakashi Iwai 		get_mux_nids(codec);
3077c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3078c577b8a1SJoseph Chan 		spec->num_mixers++;
3079c577b8a1SJoseph Chan 	}
3080c577b8a1SJoseph Chan 
3081c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
3082c577b8a1SJoseph Chan 
3083c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
308469e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
3085cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3086cb53c626STakashi Iwai 	spec->loopback.amplist = vt1709_loopbacks;
3087cb53c626STakashi Iwai #endif
3088c577b8a1SJoseph Chan 
3089c577b8a1SJoseph Chan 	return 0;
3090c577b8a1SJoseph Chan }
3091c577b8a1SJoseph Chan /*
3092c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
3093c577b8a1SJoseph Chan  */
3094c577b8a1SJoseph Chan static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3095c577b8a1SJoseph Chan 	/*
3096c577b8a1SJoseph Chan 	 * Unmute ADC0-2 and set the default input to mic-in
3097c577b8a1SJoseph Chan 	 */
3098c577b8a1SJoseph Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3099c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3100c577b8a1SJoseph Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3101c577b8a1SJoseph Chan 
3102c577b8a1SJoseph Chan 
3103c577b8a1SJoseph Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3104c577b8a1SJoseph Chan 	 * mixer widget
3105c577b8a1SJoseph Chan 	 */
3106c577b8a1SJoseph Chan 	/* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3107c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3108c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3109c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3110c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3111c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3112c577b8a1SJoseph Chan 
3113c577b8a1SJoseph Chan 	/*
3114c577b8a1SJoseph Chan 	 * Set up output selector (0x1a, 0x1b, 0x29)
3115c577b8a1SJoseph Chan 	 */
3116c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
3117c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3118c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3119c577b8a1SJoseph Chan 	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3120c577b8a1SJoseph Chan 
3121c577b8a1SJoseph Chan 	/*
3122c577b8a1SJoseph Chan 	 *  Unmute PW3 and PW4
3123c577b8a1SJoseph Chan 	 */
3124c577b8a1SJoseph Chan 	{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3125c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3126c577b8a1SJoseph Chan 
3127c577b8a1SJoseph Chan 	/* Set input of PW4 as MW0 */
3128c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_CONNECT_SEL, 0},
3129c577b8a1SJoseph Chan 	/* PW9 Output enable */
3130c577b8a1SJoseph Chan 	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3131c577b8a1SJoseph Chan 	{ }
3132c577b8a1SJoseph Chan };
3133c577b8a1SJoseph Chan 
3134c577b8a1SJoseph Chan static int patch_vt1709_6ch(struct hda_codec *codec)
3135c577b8a1SJoseph Chan {
3136c577b8a1SJoseph Chan 	struct via_spec *spec;
3137c577b8a1SJoseph Chan 	int err;
3138c577b8a1SJoseph Chan 
3139c577b8a1SJoseph Chan 	/* create a codec specific record */
3140eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3141c577b8a1SJoseph Chan 	if (spec == NULL)
3142c577b8a1SJoseph Chan 		return -ENOMEM;
3143c577b8a1SJoseph Chan 
3144c577b8a1SJoseph Chan 	codec->spec = spec;
3145c577b8a1SJoseph Chan 
3146c577b8a1SJoseph Chan 	err = vt1709_parse_auto_config(codec);
3147c577b8a1SJoseph Chan 	if (err < 0) {
3148c577b8a1SJoseph Chan 		via_free(codec);
3149c577b8a1SJoseph Chan 		return err;
3150c577b8a1SJoseph Chan 	} else if (!err) {
3151c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration.  "
3152c577b8a1SJoseph Chan 		       "Using genenic mode...\n");
3153c577b8a1SJoseph Chan 	}
3154c577b8a1SJoseph Chan 
315569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
315669e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3157c577b8a1SJoseph Chan 
3158c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1709 Analog";
3159c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3160c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3161c577b8a1SJoseph Chan 
3162c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1709 Digital";
3163c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3164c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3165c577b8a1SJoseph Chan 
3166c577b8a1SJoseph Chan 
3167c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
3168c577b8a1SJoseph Chan 		spec->adc_nids = vt1709_adc_nids;
3169c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3170337b9d02STakashi Iwai 		get_mux_nids(codec);
3171c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3172c577b8a1SJoseph Chan 		spec->num_mixers++;
3173c577b8a1SJoseph Chan 	}
3174c577b8a1SJoseph Chan 
3175c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
3176c577b8a1SJoseph Chan 
3177c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
317869e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
3179cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3180cb53c626STakashi Iwai 	spec->loopback.amplist = vt1709_loopbacks;
3181cb53c626STakashi Iwai #endif
3182f7278fd0SJosepch Chan 	return 0;
3183f7278fd0SJosepch Chan }
3184f7278fd0SJosepch Chan 
3185f7278fd0SJosepch Chan /* capture mixer elements */
3186f7278fd0SJosepch Chan static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3187f7278fd0SJosepch Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3188f7278fd0SJosepch Chan 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3189f7278fd0SJosepch Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3190f7278fd0SJosepch Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3191f7278fd0SJosepch Chan 	{
3192f7278fd0SJosepch Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3193f7278fd0SJosepch Chan 		/* The multiple "Capture Source" controls confuse alsamixer
3194f7278fd0SJosepch Chan 		 * So call somewhat different..
3195f7278fd0SJosepch Chan 		 */
3196f7278fd0SJosepch Chan 		/* .name = "Capture Source", */
3197f7278fd0SJosepch Chan 		.name = "Input Source",
3198f7278fd0SJosepch Chan 		.count = 1,
3199f7278fd0SJosepch Chan 		.info = via_mux_enum_info,
3200f7278fd0SJosepch Chan 		.get = via_mux_enum_get,
3201f7278fd0SJosepch Chan 		.put = via_mux_enum_put,
3202f7278fd0SJosepch Chan 	},
3203f7278fd0SJosepch Chan 	{ } /* end */
3204f7278fd0SJosepch Chan };
3205f7278fd0SJosepch Chan /*
3206f7278fd0SJosepch Chan  * generic initialization of ADC, input mixers and output mixers
3207f7278fd0SJosepch Chan  */
3208f7278fd0SJosepch Chan static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3209f7278fd0SJosepch Chan 	/*
3210f7278fd0SJosepch Chan 	 * Unmute ADC0-1 and set the default input to mic-in
3211f7278fd0SJosepch Chan 	 */
3212f7278fd0SJosepch Chan 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3213f7278fd0SJosepch Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3214f7278fd0SJosepch Chan 
3215f7278fd0SJosepch Chan 
3216f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3217f7278fd0SJosepch Chan 	 * mixer widget
3218f7278fd0SJosepch Chan 	 */
3219f7278fd0SJosepch Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3220f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3221f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3222f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3223f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3224f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3225f7278fd0SJosepch Chan 
3226f7278fd0SJosepch Chan 	/*
3227f7278fd0SJosepch Chan 	 * Set up output mixers
3228f7278fd0SJosepch Chan 	 */
3229f7278fd0SJosepch Chan 	/* set vol=0 to output mixers */
3230f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3231f7278fd0SJosepch Chan 	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3232f7278fd0SJosepch Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3233f7278fd0SJosepch Chan 
3234f7278fd0SJosepch Chan 	/* Setup default input to PW4 */
3235bfdc675aSLydia Wang 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3236f7278fd0SJosepch Chan 	/* PW9 Output enable */
3237f7278fd0SJosepch Chan 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3238f7278fd0SJosepch Chan 	/* PW10 Input enable */
3239f7278fd0SJosepch Chan 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3240f7278fd0SJosepch Chan 	{ }
3241f7278fd0SJosepch Chan };
3242f7278fd0SJosepch Chan 
3243f7278fd0SJosepch Chan static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3244f7278fd0SJosepch Chan 	/*
3245f7278fd0SJosepch Chan 	 * Unmute ADC0-1 and set the default input to mic-in
3246f7278fd0SJosepch Chan 	 */
3247f7278fd0SJosepch Chan 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3248f7278fd0SJosepch Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3249f7278fd0SJosepch Chan 
3250f7278fd0SJosepch Chan 
3251f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3252f7278fd0SJosepch Chan 	 * mixer widget
3253f7278fd0SJosepch Chan 	 */
3254f7278fd0SJosepch Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3255f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3256f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3257f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3258f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3259f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3260f7278fd0SJosepch Chan 
3261f7278fd0SJosepch Chan 	/*
3262f7278fd0SJosepch Chan 	 * Set up output mixers
3263f7278fd0SJosepch Chan 	 */
3264f7278fd0SJosepch Chan 	/* set vol=0 to output mixers */
3265f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3266f7278fd0SJosepch Chan 	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3267f7278fd0SJosepch Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3268f7278fd0SJosepch Chan 
3269f7278fd0SJosepch Chan 	/* Setup default input of PW4 to MW0 */
3270f7278fd0SJosepch Chan 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3271f7278fd0SJosepch Chan 	/* PW9 Output enable */
3272f7278fd0SJosepch Chan 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3273f7278fd0SJosepch Chan 	/* PW10 Input enable */
3274f7278fd0SJosepch Chan 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3275f7278fd0SJosepch Chan 	{ }
3276f7278fd0SJosepch Chan };
3277f7278fd0SJosepch Chan 
327869e52a80SHarald Welte static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3279a34df19aSLydia Wang 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3280a34df19aSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3281a34df19aSLydia Wang 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3282a34df19aSLydia Wang 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3283a34df19aSLydia Wang 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3284a34df19aSLydia Wang 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3285a34df19aSLydia Wang 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3286a34df19aSLydia Wang 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3287a34df19aSLydia Wang 	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
328869e52a80SHarald Welte 	{ }
328969e52a80SHarald Welte };
329069e52a80SHarald Welte 
329117314379SLydia Wang static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
329217314379SLydia Wang 			      struct hda_codec *codec,
329317314379SLydia Wang 			      struct snd_pcm_substream *substream)
329417314379SLydia Wang {
329517314379SLydia Wang 	int idle = substream->pstr->substream_opened == 1
329617314379SLydia Wang 		&& substream->ref_count == 0;
329717314379SLydia Wang 
329817314379SLydia Wang 	analog_low_current_mode(codec, idle);
329917314379SLydia Wang 	return 0;
330017314379SLydia Wang }
330117314379SLydia Wang 
3302f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
33030aa62aefSHarald Welte 	.substreams = 2,
3304f7278fd0SJosepch Chan 	.channels_min = 2,
3305f7278fd0SJosepch Chan 	.channels_max = 8,
3306f7278fd0SJosepch Chan 	.nid = 0x10, /* NID to query formats and rates */
3307f7278fd0SJosepch Chan 	.ops = {
3308f7278fd0SJosepch Chan 		.open = via_playback_pcm_open,
33090aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
331017314379SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
331117314379SLydia Wang 		.close = via_pcm_open_close
3312f7278fd0SJosepch Chan 	},
3313f7278fd0SJosepch Chan };
3314f7278fd0SJosepch Chan 
3315f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
33160aa62aefSHarald Welte 	.substreams = 2,
3317f7278fd0SJosepch Chan 	.channels_min = 2,
3318f7278fd0SJosepch Chan 	.channels_max = 4,
3319f7278fd0SJosepch Chan 	.nid = 0x10, /* NID to query formats and rates */
3320f7278fd0SJosepch Chan 	.ops = {
3321f7278fd0SJosepch Chan 		.open = via_playback_pcm_open,
33220aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
33230aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
3324f7278fd0SJosepch Chan 	},
3325f7278fd0SJosepch Chan };
3326f7278fd0SJosepch Chan 
3327f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3328f7278fd0SJosepch Chan 	.substreams = 2,
3329f7278fd0SJosepch Chan 	.channels_min = 2,
3330f7278fd0SJosepch Chan 	.channels_max = 2,
3331f7278fd0SJosepch Chan 	.nid = 0x13, /* NID to query formats and rates */
3332f7278fd0SJosepch Chan 	.ops = {
333317314379SLydia Wang 		.open = via_pcm_open_close,
3334f7278fd0SJosepch Chan 		.prepare = via_capture_pcm_prepare,
333517314379SLydia Wang 		.cleanup = via_capture_pcm_cleanup,
333617314379SLydia Wang 		.close = via_pcm_open_close
3337f7278fd0SJosepch Chan 	},
3338f7278fd0SJosepch Chan };
3339f7278fd0SJosepch Chan 
3340f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3341f7278fd0SJosepch Chan 	.substreams = 1,
3342f7278fd0SJosepch Chan 	.channels_min = 2,
3343f7278fd0SJosepch Chan 	.channels_max = 2,
3344f7278fd0SJosepch Chan 	/* NID is set in via_build_pcms */
3345f7278fd0SJosepch Chan 	.ops = {
3346f7278fd0SJosepch Chan 		.open = via_dig_playback_pcm_open,
3347f7278fd0SJosepch Chan 		.close = via_dig_playback_pcm_close,
33489da29271STakashi Iwai 		.prepare = via_dig_playback_pcm_prepare,
33499da29271STakashi Iwai 		.cleanup = via_dig_playback_pcm_cleanup
3350f7278fd0SJosepch Chan 	},
3351f7278fd0SJosepch Chan };
3352f7278fd0SJosepch Chan 
3353f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3354f7278fd0SJosepch Chan 	.substreams = 1,
3355f7278fd0SJosepch Chan 	.channels_min = 2,
3356f7278fd0SJosepch Chan 	.channels_max = 2,
3357f7278fd0SJosepch Chan };
3358f7278fd0SJosepch Chan 
3359f7278fd0SJosepch Chan /* fill in the dac_nids table from the parsed pin configuration */
3360f7278fd0SJosepch Chan static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3361f7278fd0SJosepch Chan 				     const struct auto_pin_cfg *cfg)
3362f7278fd0SJosepch Chan {
3363f7278fd0SJosepch Chan 	int i;
3364f7278fd0SJosepch Chan 	hda_nid_t nid;
3365f7278fd0SJosepch Chan 
3366f7278fd0SJosepch Chan 	spec->multiout.num_dacs = cfg->line_outs;
3367f7278fd0SJosepch Chan 
3368f7278fd0SJosepch Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
3369f7278fd0SJosepch Chan 
3370f7278fd0SJosepch Chan 	for (i = 0; i < 4; i++) {
3371f7278fd0SJosepch Chan 		nid = cfg->line_out_pins[i];
3372f7278fd0SJosepch Chan 		if (nid) {
3373f7278fd0SJosepch Chan 			/* config dac list */
3374f7278fd0SJosepch Chan 			switch (i) {
3375f7278fd0SJosepch Chan 			case AUTO_SEQ_FRONT:
3376f7278fd0SJosepch Chan 				spec->multiout.dac_nids[i] = 0x10;
3377f7278fd0SJosepch Chan 				break;
3378f7278fd0SJosepch Chan 			case AUTO_SEQ_CENLFE:
3379f7278fd0SJosepch Chan 				spec->multiout.dac_nids[i] = 0x24;
3380f7278fd0SJosepch Chan 				break;
3381f7278fd0SJosepch Chan 			case AUTO_SEQ_SURROUND:
3382fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
3383f7278fd0SJosepch Chan 				break;
3384f7278fd0SJosepch Chan 			case AUTO_SEQ_SIDE:
3385fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x25;
3386f7278fd0SJosepch Chan 				break;
3387f7278fd0SJosepch Chan 			}
3388f7278fd0SJosepch Chan 		}
3389f7278fd0SJosepch Chan 	}
3390f7278fd0SJosepch Chan 
3391f7278fd0SJosepch Chan 	return 0;
3392f7278fd0SJosepch Chan }
3393f7278fd0SJosepch Chan 
3394f7278fd0SJosepch Chan /* add playback controls from the parsed DAC table */
3395f7278fd0SJosepch Chan static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3396f7278fd0SJosepch Chan 					     const struct auto_pin_cfg *cfg)
3397f7278fd0SJosepch Chan {
3398f7278fd0SJosepch Chan 	char name[32];
3399f7278fd0SJosepch Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3400fb4cb772SHarald Welte 	hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3401f7278fd0SJosepch Chan 	hda_nid_t nid, nid_vol = 0;
3402f7278fd0SJosepch Chan 	int i, err;
3403f7278fd0SJosepch Chan 
3404f7278fd0SJosepch Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3405f7278fd0SJosepch Chan 		nid = cfg->line_out_pins[i];
3406f7278fd0SJosepch Chan 
3407f7278fd0SJosepch Chan 		if (!nid)
3408f7278fd0SJosepch Chan 			continue;
3409f7278fd0SJosepch Chan 
3410f7278fd0SJosepch Chan 		nid_vol = nid_vols[i];
3411f7278fd0SJosepch Chan 
3412f7278fd0SJosepch Chan 		if (i == AUTO_SEQ_CENLFE) {
3413f7278fd0SJosepch Chan 			/* Center/LFE */
3414f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3415f7278fd0SJosepch Chan 					      "Center Playback Volume",
3416f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3417f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3418f7278fd0SJosepch Chan 			if (err < 0)
3419f7278fd0SJosepch Chan 				return err;
3420f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3421f7278fd0SJosepch Chan 					      "LFE Playback Volume",
3422f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3423f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3424f7278fd0SJosepch Chan 			if (err < 0)
3425f7278fd0SJosepch Chan 				return err;
3426f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3427f7278fd0SJosepch Chan 					      "Center Playback Switch",
3428f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3429f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3430f7278fd0SJosepch Chan 			if (err < 0)
3431f7278fd0SJosepch Chan 				return err;
3432f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3433f7278fd0SJosepch Chan 					      "LFE Playback Switch",
3434f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3435f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3436f7278fd0SJosepch Chan 			if (err < 0)
3437f7278fd0SJosepch Chan 				return err;
3438f7278fd0SJosepch Chan 		} else if (i == AUTO_SEQ_FRONT) {
3439f7278fd0SJosepch Chan 			/* add control to mixer index 0 */
3440f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3441f7278fd0SJosepch Chan 					      "Master Front Playback Volume",
3442f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3443f7278fd0SJosepch Chan 								  HDA_INPUT));
3444f7278fd0SJosepch Chan 			if (err < 0)
3445f7278fd0SJosepch Chan 				return err;
3446f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3447f7278fd0SJosepch Chan 					      "Master Front Playback Switch",
3448f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3449f7278fd0SJosepch Chan 								  HDA_INPUT));
3450f7278fd0SJosepch Chan 			if (err < 0)
3451f7278fd0SJosepch Chan 				return err;
3452f7278fd0SJosepch Chan 
3453f7278fd0SJosepch Chan 			/* add control to PW3 */
3454f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Volume", chname[i]);
3455f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3456f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3457f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3458f7278fd0SJosepch Chan 			if (err < 0)
3459f7278fd0SJosepch Chan 				return err;
3460f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Switch", chname[i]);
3461f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3462f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3463f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3464f7278fd0SJosepch Chan 			if (err < 0)
3465f7278fd0SJosepch Chan 				return err;
3466f7278fd0SJosepch Chan 		} else {
3467f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Volume", chname[i]);
3468f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3469f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3470f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3471f7278fd0SJosepch Chan 			if (err < 0)
3472f7278fd0SJosepch Chan 				return err;
3473f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Switch", chname[i]);
3474f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3475f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3476f7278fd0SJosepch Chan 								  HDA_OUTPUT));
3477f7278fd0SJosepch Chan 			if (err < 0)
3478f7278fd0SJosepch Chan 				return err;
3479f7278fd0SJosepch Chan 		}
3480f7278fd0SJosepch Chan 	}
3481f7278fd0SJosepch Chan 
3482f7278fd0SJosepch Chan 	return 0;
3483f7278fd0SJosepch Chan }
3484f7278fd0SJosepch Chan 
3485f7278fd0SJosepch Chan static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3486f7278fd0SJosepch Chan {
3487f7278fd0SJosepch Chan 	int err;
3488f7278fd0SJosepch Chan 
3489f7278fd0SJosepch Chan 	if (!pin)
3490f7278fd0SJosepch Chan 		return 0;
3491f7278fd0SJosepch Chan 
3492f7278fd0SJosepch Chan 	spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3493cdc1784dSLydia Wang 	spec->hp_independent_mode_index = 1;
3494f7278fd0SJosepch Chan 
3495f7278fd0SJosepch Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3496f7278fd0SJosepch Chan 			      "Headphone Playback Volume",
3497f7278fd0SJosepch Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3498f7278fd0SJosepch Chan 	if (err < 0)
3499f7278fd0SJosepch Chan 		return err;
3500f7278fd0SJosepch Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3501f7278fd0SJosepch Chan 			      "Headphone Playback Switch",
3502f7278fd0SJosepch Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3503f7278fd0SJosepch Chan 	if (err < 0)
3504f7278fd0SJosepch Chan 		return err;
3505f7278fd0SJosepch Chan 
35060aa62aefSHarald Welte 	create_hp_imux(spec);
35070aa62aefSHarald Welte 
3508f7278fd0SJosepch Chan 	return 0;
3509f7278fd0SJosepch Chan }
3510f7278fd0SJosepch Chan 
3511f7278fd0SJosepch Chan /* create playback/capture controls for input pins */
3512f7278fd0SJosepch Chan static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3513f7278fd0SJosepch Chan 						const struct auto_pin_cfg *cfg)
3514f7278fd0SJosepch Chan {
3515f7278fd0SJosepch Chan 	static char *labels[] = {
3516f7278fd0SJosepch Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3517f7278fd0SJosepch Chan 	};
35180aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
3519f7278fd0SJosepch Chan 	int i, err, idx = 0;
3520f7278fd0SJosepch Chan 
3521f7278fd0SJosepch Chan 	/* for internal loopback recording select */
3522f7278fd0SJosepch Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
3523f7278fd0SJosepch Chan 	imux->items[imux->num_items].index = idx;
3524f7278fd0SJosepch Chan 	imux->num_items++;
3525f7278fd0SJosepch Chan 
3526f7278fd0SJosepch Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
3527f7278fd0SJosepch Chan 		if (!cfg->input_pins[i])
3528f7278fd0SJosepch Chan 			continue;
3529f7278fd0SJosepch Chan 
3530f7278fd0SJosepch Chan 		switch (cfg->input_pins[i]) {
3531f7278fd0SJosepch Chan 		case 0x1a: /* Mic */
3532f7278fd0SJosepch Chan 			idx = 2;
3533f7278fd0SJosepch Chan 			break;
3534f7278fd0SJosepch Chan 
3535f7278fd0SJosepch Chan 		case 0x1b: /* Line In */
3536f7278fd0SJosepch Chan 			idx = 3;
3537f7278fd0SJosepch Chan 			break;
3538f7278fd0SJosepch Chan 
3539f7278fd0SJosepch Chan 		case 0x1e: /* Front Mic */
3540f7278fd0SJosepch Chan 			idx = 4;
3541f7278fd0SJosepch Chan 			break;
3542f7278fd0SJosepch Chan 
3543f7278fd0SJosepch Chan 		case 0x1f: /* CD */
3544f7278fd0SJosepch Chan 			idx = 1;
3545f7278fd0SJosepch Chan 			break;
3546f7278fd0SJosepch Chan 		}
35479510e8ddSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x16);
3548f7278fd0SJosepch Chan 		if (err < 0)
3549f7278fd0SJosepch Chan 			return err;
3550f7278fd0SJosepch Chan 		imux->items[imux->num_items].label = labels[i];
3551f7278fd0SJosepch Chan 		imux->items[imux->num_items].index = idx;
3552f7278fd0SJosepch Chan 		imux->num_items++;
3553f7278fd0SJosepch Chan 	}
3554f7278fd0SJosepch Chan 	return 0;
3555f7278fd0SJosepch Chan }
3556f7278fd0SJosepch Chan 
3557f7278fd0SJosepch Chan static int vt1708B_parse_auto_config(struct hda_codec *codec)
3558f7278fd0SJosepch Chan {
3559f7278fd0SJosepch Chan 	struct via_spec *spec = codec->spec;
3560f7278fd0SJosepch Chan 	int err;
3561f7278fd0SJosepch Chan 
3562f7278fd0SJosepch Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3563f7278fd0SJosepch Chan 	if (err < 0)
3564f7278fd0SJosepch Chan 		return err;
3565f7278fd0SJosepch Chan 	err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3566f7278fd0SJosepch Chan 	if (err < 0)
3567f7278fd0SJosepch Chan 		return err;
3568f7278fd0SJosepch Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3569f7278fd0SJosepch Chan 		return 0; /* can't find valid BIOS pin config */
3570f7278fd0SJosepch Chan 
3571f7278fd0SJosepch Chan 	err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3572f7278fd0SJosepch Chan 	if (err < 0)
3573f7278fd0SJosepch Chan 		return err;
3574f7278fd0SJosepch Chan 	err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3575f7278fd0SJosepch Chan 	if (err < 0)
3576f7278fd0SJosepch Chan 		return err;
3577f7278fd0SJosepch Chan 	err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3578f7278fd0SJosepch Chan 	if (err < 0)
3579f7278fd0SJosepch Chan 		return err;
3580f7278fd0SJosepch Chan 
3581f7278fd0SJosepch Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3582f7278fd0SJosepch Chan 
35830852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
3584f7278fd0SJosepch Chan 		spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
358555d1d6c1STakashi Iwai 	spec->dig_in_pin = VT1708B_DIGIN_PIN;
3586f7278fd0SJosepch Chan 	if (spec->autocfg.dig_in_pin)
3587f7278fd0SJosepch Chan 		spec->dig_in_nid = VT1708B_DIGIN_NID;
3588f7278fd0SJosepch Chan 
3589603c4019STakashi Iwai 	if (spec->kctls.list)
3590603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
3591f7278fd0SJosepch Chan 
35920aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
35930aa62aefSHarald Welte 
3594f8fdd495SHarald Welte 	if (spec->hp_mux)
35950aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
3596f7278fd0SJosepch Chan 
35971564b287SLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3598f7278fd0SJosepch Chan 	return 1;
3599f7278fd0SJosepch Chan }
3600f7278fd0SJosepch Chan 
3601f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
3602f7278fd0SJosepch Chan static struct hda_amp_list vt1708B_loopbacks[] = {
3603f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 1 },
3604f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 2 },
3605f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 3 },
3606f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 4 },
3607f7278fd0SJosepch Chan 	{ } /* end */
3608f7278fd0SJosepch Chan };
3609f7278fd0SJosepch Chan #endif
3610518bf3baSLydia Wang static int patch_vt1708S(struct hda_codec *codec);
3611f7278fd0SJosepch Chan static int patch_vt1708B_8ch(struct hda_codec *codec)
3612f7278fd0SJosepch Chan {
3613f7278fd0SJosepch Chan 	struct via_spec *spec;
3614f7278fd0SJosepch Chan 	int err;
3615f7278fd0SJosepch Chan 
3616518bf3baSLydia Wang 	if (get_codec_type(codec) == VT1708BCE)
3617518bf3baSLydia Wang 		return patch_vt1708S(codec);
3618f7278fd0SJosepch Chan 	/* create a codec specific record */
3619eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3620f7278fd0SJosepch Chan 	if (spec == NULL)
3621f7278fd0SJosepch Chan 		return -ENOMEM;
3622f7278fd0SJosepch Chan 
3623f7278fd0SJosepch Chan 	codec->spec = spec;
3624f7278fd0SJosepch Chan 
3625f7278fd0SJosepch Chan 	/* automatic parse from the BIOS config */
3626f7278fd0SJosepch Chan 	err = vt1708B_parse_auto_config(codec);
3627f7278fd0SJosepch Chan 	if (err < 0) {
3628f7278fd0SJosepch Chan 		via_free(codec);
3629f7278fd0SJosepch Chan 		return err;
3630f7278fd0SJosepch Chan 	} else if (!err) {
3631f7278fd0SJosepch Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
3632f7278fd0SJosepch Chan 		       "from BIOS.  Using genenic mode...\n");
3633f7278fd0SJosepch Chan 	}
3634f7278fd0SJosepch Chan 
363569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
363669e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3637f7278fd0SJosepch Chan 
3638f7278fd0SJosepch Chan 	spec->stream_name_analog = "VT1708B Analog";
3639f7278fd0SJosepch Chan 	spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3640f7278fd0SJosepch Chan 	spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3641f7278fd0SJosepch Chan 
3642f7278fd0SJosepch Chan 	spec->stream_name_digital = "VT1708B Digital";
3643f7278fd0SJosepch Chan 	spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3644f7278fd0SJosepch Chan 	spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3645f7278fd0SJosepch Chan 
3646f7278fd0SJosepch Chan 	if (!spec->adc_nids && spec->input_mux) {
3647f7278fd0SJosepch Chan 		spec->adc_nids = vt1708B_adc_nids;
3648f7278fd0SJosepch Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3649337b9d02STakashi Iwai 		get_mux_nids(codec);
3650f7278fd0SJosepch Chan 		spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3651f7278fd0SJosepch Chan 		spec->num_mixers++;
3652f7278fd0SJosepch Chan 	}
3653f7278fd0SJosepch Chan 
3654f7278fd0SJosepch Chan 	codec->patch_ops = via_patch_ops;
3655f7278fd0SJosepch Chan 
3656f7278fd0SJosepch Chan 	codec->patch_ops.init = via_auto_init;
365769e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
3658f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
3659f7278fd0SJosepch Chan 	spec->loopback.amplist = vt1708B_loopbacks;
3660f7278fd0SJosepch Chan #endif
3661f7278fd0SJosepch Chan 
3662f7278fd0SJosepch Chan 	return 0;
3663f7278fd0SJosepch Chan }
3664f7278fd0SJosepch Chan 
3665f7278fd0SJosepch Chan static int patch_vt1708B_4ch(struct hda_codec *codec)
3666f7278fd0SJosepch Chan {
3667f7278fd0SJosepch Chan 	struct via_spec *spec;
3668f7278fd0SJosepch Chan 	int err;
3669f7278fd0SJosepch Chan 
3670f7278fd0SJosepch Chan 	/* create a codec specific record */
3671eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3672f7278fd0SJosepch Chan 	if (spec == NULL)
3673f7278fd0SJosepch Chan 		return -ENOMEM;
3674f7278fd0SJosepch Chan 
3675f7278fd0SJosepch Chan 	codec->spec = spec;
3676f7278fd0SJosepch Chan 
3677f7278fd0SJosepch Chan 	/* automatic parse from the BIOS config */
3678f7278fd0SJosepch Chan 	err = vt1708B_parse_auto_config(codec);
3679f7278fd0SJosepch Chan 	if (err < 0) {
3680f7278fd0SJosepch Chan 		via_free(codec);
3681f7278fd0SJosepch Chan 		return err;
3682f7278fd0SJosepch Chan 	} else if (!err) {
3683f7278fd0SJosepch Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
3684f7278fd0SJosepch Chan 		       "from BIOS.  Using genenic mode...\n");
3685f7278fd0SJosepch Chan 	}
3686f7278fd0SJosepch Chan 
368769e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
368869e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3689f7278fd0SJosepch Chan 
3690f7278fd0SJosepch Chan 	spec->stream_name_analog = "VT1708B Analog";
3691f7278fd0SJosepch Chan 	spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3692f7278fd0SJosepch Chan 	spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3693f7278fd0SJosepch Chan 
3694f7278fd0SJosepch Chan 	spec->stream_name_digital = "VT1708B Digital";
3695f7278fd0SJosepch Chan 	spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3696f7278fd0SJosepch Chan 	spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3697f7278fd0SJosepch Chan 
3698f7278fd0SJosepch Chan 	if (!spec->adc_nids && spec->input_mux) {
3699f7278fd0SJosepch Chan 		spec->adc_nids = vt1708B_adc_nids;
3700f7278fd0SJosepch Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3701337b9d02STakashi Iwai 		get_mux_nids(codec);
3702f7278fd0SJosepch Chan 		spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3703f7278fd0SJosepch Chan 		spec->num_mixers++;
3704f7278fd0SJosepch Chan 	}
3705f7278fd0SJosepch Chan 
3706f7278fd0SJosepch Chan 	codec->patch_ops = via_patch_ops;
3707f7278fd0SJosepch Chan 
3708f7278fd0SJosepch Chan 	codec->patch_ops.init = via_auto_init;
370969e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
3710f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
3711f7278fd0SJosepch Chan 	spec->loopback.amplist = vt1708B_loopbacks;
3712f7278fd0SJosepch Chan #endif
3713c577b8a1SJoseph Chan 
3714c577b8a1SJoseph Chan 	return 0;
3715c577b8a1SJoseph Chan }
3716c577b8a1SJoseph Chan 
3717d949cac1SHarald Welte /* Patch for VT1708S */
3718d949cac1SHarald Welte 
3719d949cac1SHarald Welte /* capture mixer elements */
3720d949cac1SHarald Welte static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3721d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3722d949cac1SHarald Welte 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3723d949cac1SHarald Welte 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3724d949cac1SHarald Welte 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
37256369bcfcSLydia Wang 	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
37266369bcfcSLydia Wang 	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
37276369bcfcSLydia Wang 			 HDA_INPUT),
3728d949cac1SHarald Welte 	{
3729d949cac1SHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3730d949cac1SHarald Welte 		/* The multiple "Capture Source" controls confuse alsamixer
3731d949cac1SHarald Welte 		 * So call somewhat different..
3732d949cac1SHarald Welte 		 */
3733d949cac1SHarald Welte 		/* .name = "Capture Source", */
3734d949cac1SHarald Welte 		.name = "Input Source",
3735d949cac1SHarald Welte 		.count = 1,
3736d949cac1SHarald Welte 		.info = via_mux_enum_info,
3737d949cac1SHarald Welte 		.get = via_mux_enum_get,
3738d949cac1SHarald Welte 		.put = via_mux_enum_put,
3739d949cac1SHarald Welte 	},
3740d949cac1SHarald Welte 	{ } /* end */
3741d949cac1SHarald Welte };
3742d949cac1SHarald Welte 
3743d949cac1SHarald Welte static struct hda_verb vt1708S_volume_init_verbs[] = {
3744d949cac1SHarald Welte 	/* Unmute ADC0-1 and set the default input to mic-in */
3745d949cac1SHarald Welte 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3746d949cac1SHarald Welte 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3747d949cac1SHarald Welte 
3748d949cac1SHarald Welte 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3749d949cac1SHarald Welte 	 * analog-loopback mixer widget */
3750d949cac1SHarald Welte 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3751d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3752d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3753d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3754d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3755d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3756d949cac1SHarald Welte 
3757d949cac1SHarald Welte 	/* Setup default input of PW4 to MW0 */
3758d949cac1SHarald Welte 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
37595691ec7fSHarald Welte 	/* PW9, PW10  Output enable */
3760d949cac1SHarald Welte 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
37615691ec7fSHarald Welte 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3762d7426329SHarald Welte 	/* Enable Mic Boost Volume backdoor */
3763d7426329SHarald Welte 	{0x1, 0xf98, 0x1},
3764bc7e7e5cSLydia Wang 	/* don't bybass mixer */
3765bc7e7e5cSLydia Wang 	{0x1, 0xf88, 0xc0},
3766d949cac1SHarald Welte 	{ }
3767d949cac1SHarald Welte };
3768d949cac1SHarald Welte 
376969e52a80SHarald Welte static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3770a34df19aSLydia Wang 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3771a34df19aSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3772a34df19aSLydia Wang 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3773a34df19aSLydia Wang 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3774a34df19aSLydia Wang 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3775a34df19aSLydia Wang 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3776a34df19aSLydia Wang 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3777a34df19aSLydia Wang 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3778a34df19aSLydia Wang 	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
377969e52a80SHarald Welte 	{ }
378069e52a80SHarald Welte };
378169e52a80SHarald Welte 
3782d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3783d949cac1SHarald Welte 	.substreams = 2,
3784d949cac1SHarald Welte 	.channels_min = 2,
3785d949cac1SHarald Welte 	.channels_max = 8,
3786d949cac1SHarald Welte 	.nid = 0x10, /* NID to query formats and rates */
3787d949cac1SHarald Welte 	.ops = {
3788d949cac1SHarald Welte 		.open = via_playback_pcm_open,
3789c873cc25SLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
3790c873cc25SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
379117314379SLydia Wang 		.close = via_pcm_open_close
3792d949cac1SHarald Welte 	},
3793d949cac1SHarald Welte };
3794d949cac1SHarald Welte 
3795d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3796d949cac1SHarald Welte 	.substreams = 2,
3797d949cac1SHarald Welte 	.channels_min = 2,
3798d949cac1SHarald Welte 	.channels_max = 2,
3799d949cac1SHarald Welte 	.nid = 0x13, /* NID to query formats and rates */
3800d949cac1SHarald Welte 	.ops = {
380117314379SLydia Wang 		.open = via_pcm_open_close,
3802d949cac1SHarald Welte 		.prepare = via_capture_pcm_prepare,
380317314379SLydia Wang 		.cleanup = via_capture_pcm_cleanup,
380417314379SLydia Wang 		.close = via_pcm_open_close
3805d949cac1SHarald Welte 	},
3806d949cac1SHarald Welte };
3807d949cac1SHarald Welte 
3808d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
38099da29271STakashi Iwai 	.substreams = 1,
3810d949cac1SHarald Welte 	.channels_min = 2,
3811d949cac1SHarald Welte 	.channels_max = 2,
3812d949cac1SHarald Welte 	/* NID is set in via_build_pcms */
3813d949cac1SHarald Welte 	.ops = {
3814d949cac1SHarald Welte 		.open = via_dig_playback_pcm_open,
3815d949cac1SHarald Welte 		.close = via_dig_playback_pcm_close,
38169da29271STakashi Iwai 		.prepare = via_dig_playback_pcm_prepare,
38179da29271STakashi Iwai 		.cleanup = via_dig_playback_pcm_cleanup
3818d949cac1SHarald Welte 	},
3819d949cac1SHarald Welte };
3820d949cac1SHarald Welte 
3821d949cac1SHarald Welte /* fill in the dac_nids table from the parsed pin configuration */
3822d949cac1SHarald Welte static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3823d949cac1SHarald Welte 				     const struct auto_pin_cfg *cfg)
3824d949cac1SHarald Welte {
3825d949cac1SHarald Welte 	int i;
3826d949cac1SHarald Welte 	hda_nid_t nid;
3827d949cac1SHarald Welte 
3828d949cac1SHarald Welte 	spec->multiout.num_dacs = cfg->line_outs;
3829d949cac1SHarald Welte 
3830d949cac1SHarald Welte 	spec->multiout.dac_nids = spec->private_dac_nids;
3831d949cac1SHarald Welte 
3832d949cac1SHarald Welte 	for (i = 0; i < 4; i++) {
3833d949cac1SHarald Welte 		nid = cfg->line_out_pins[i];
3834d949cac1SHarald Welte 		if (nid) {
3835d949cac1SHarald Welte 			/* config dac list */
3836d949cac1SHarald Welte 			switch (i) {
3837d949cac1SHarald Welte 			case AUTO_SEQ_FRONT:
3838d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x10;
3839d949cac1SHarald Welte 				break;
3840d949cac1SHarald Welte 			case AUTO_SEQ_CENLFE:
3841d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x24;
3842d949cac1SHarald Welte 				break;
3843d949cac1SHarald Welte 			case AUTO_SEQ_SURROUND:
3844d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
3845d949cac1SHarald Welte 				break;
3846d949cac1SHarald Welte 			case AUTO_SEQ_SIDE:
3847d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x25;
3848d949cac1SHarald Welte 				break;
3849d949cac1SHarald Welte 			}
3850d949cac1SHarald Welte 		}
3851d949cac1SHarald Welte 	}
3852d949cac1SHarald Welte 
3853d949cac1SHarald Welte 	return 0;
3854d949cac1SHarald Welte }
3855d949cac1SHarald Welte 
3856d949cac1SHarald Welte /* add playback controls from the parsed DAC table */
3857d949cac1SHarald Welte static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3858d949cac1SHarald Welte 					     const struct auto_pin_cfg *cfg)
3859d949cac1SHarald Welte {
3860d949cac1SHarald Welte 	char name[32];
3861d949cac1SHarald Welte 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3862d949cac1SHarald Welte 	hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3863d949cac1SHarald Welte 	hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3864d949cac1SHarald Welte 	hda_nid_t nid, nid_vol, nid_mute;
3865d949cac1SHarald Welte 	int i, err;
3866d949cac1SHarald Welte 
3867d949cac1SHarald Welte 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3868d949cac1SHarald Welte 		nid = cfg->line_out_pins[i];
3869d949cac1SHarald Welte 
3870d949cac1SHarald Welte 		if (!nid)
3871d949cac1SHarald Welte 			continue;
3872d949cac1SHarald Welte 
3873d949cac1SHarald Welte 		nid_vol = nid_vols[i];
3874d949cac1SHarald Welte 		nid_mute = nid_mutes[i];
3875d949cac1SHarald Welte 
3876d949cac1SHarald Welte 		if (i == AUTO_SEQ_CENLFE) {
3877d949cac1SHarald Welte 			/* Center/LFE */
3878d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3879d949cac1SHarald Welte 					      "Center Playback Volume",
3880d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3881d949cac1SHarald Welte 								  HDA_OUTPUT));
3882d949cac1SHarald Welte 			if (err < 0)
3883d949cac1SHarald Welte 				return err;
3884d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3885d949cac1SHarald Welte 					      "LFE Playback Volume",
3886d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3887d949cac1SHarald Welte 								  HDA_OUTPUT));
3888d949cac1SHarald Welte 			if (err < 0)
3889d949cac1SHarald Welte 				return err;
3890d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3891d949cac1SHarald Welte 					      "Center Playback Switch",
3892d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
3893d949cac1SHarald Welte 								  1, 0,
3894d949cac1SHarald Welte 								  HDA_OUTPUT));
3895d949cac1SHarald Welte 			if (err < 0)
3896d949cac1SHarald Welte 				return err;
3897d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3898d949cac1SHarald Welte 					      "LFE Playback Switch",
3899d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
3900d949cac1SHarald Welte 								  2, 0,
3901d949cac1SHarald Welte 								  HDA_OUTPUT));
3902d949cac1SHarald Welte 			if (err < 0)
3903d949cac1SHarald Welte 				return err;
3904d949cac1SHarald Welte 		} else if (i == AUTO_SEQ_FRONT) {
3905d949cac1SHarald Welte 			/* add control to mixer index 0 */
3906d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3907d949cac1SHarald Welte 					      "Master Front Playback Volume",
3908d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3909d949cac1SHarald Welte 								  HDA_INPUT));
3910d949cac1SHarald Welte 			if (err < 0)
3911d949cac1SHarald Welte 				return err;
3912d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3913d949cac1SHarald Welte 					      "Master Front Playback Switch",
3914d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3915d949cac1SHarald Welte 								  HDA_INPUT));
3916d949cac1SHarald Welte 			if (err < 0)
3917d949cac1SHarald Welte 				return err;
3918d949cac1SHarald Welte 
3919d949cac1SHarald Welte 			/* Front */
3920d949cac1SHarald Welte 			sprintf(name, "%s Playback Volume", chname[i]);
3921d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3922d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3923d949cac1SHarald Welte 								  HDA_OUTPUT));
3924d949cac1SHarald Welte 			if (err < 0)
3925d949cac1SHarald Welte 				return err;
3926d949cac1SHarald Welte 			sprintf(name, "%s Playback Switch", chname[i]);
3927d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3928d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
3929d949cac1SHarald Welte 								  3, 0,
3930d949cac1SHarald Welte 								  HDA_OUTPUT));
3931d949cac1SHarald Welte 			if (err < 0)
3932d949cac1SHarald Welte 				return err;
3933d949cac1SHarald Welte 		} else {
3934d949cac1SHarald Welte 			sprintf(name, "%s Playback Volume", chname[i]);
3935d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3936d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3937d949cac1SHarald Welte 								  HDA_OUTPUT));
3938d949cac1SHarald Welte 			if (err < 0)
3939d949cac1SHarald Welte 				return err;
3940d949cac1SHarald Welte 			sprintf(name, "%s Playback Switch", chname[i]);
3941d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3942d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
3943d949cac1SHarald Welte 								  3, 0,
3944d949cac1SHarald Welte 								  HDA_OUTPUT));
3945d949cac1SHarald Welte 			if (err < 0)
3946d949cac1SHarald Welte 				return err;
3947d949cac1SHarald Welte 		}
3948d949cac1SHarald Welte 	}
3949d949cac1SHarald Welte 
3950d949cac1SHarald Welte 	return 0;
3951d949cac1SHarald Welte }
3952d949cac1SHarald Welte 
3953d949cac1SHarald Welte static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3954d949cac1SHarald Welte {
3955d949cac1SHarald Welte 	int err;
3956d949cac1SHarald Welte 
3957d949cac1SHarald Welte 	if (!pin)
3958d949cac1SHarald Welte 		return 0;
3959d949cac1SHarald Welte 
3960d949cac1SHarald Welte 	spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3961cdc1784dSLydia Wang 	spec->hp_independent_mode_index = 1;
3962d949cac1SHarald Welte 
3963d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3964d949cac1SHarald Welte 			      "Headphone Playback Volume",
3965d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3966d949cac1SHarald Welte 	if (err < 0)
3967d949cac1SHarald Welte 		return err;
3968d949cac1SHarald Welte 
3969d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3970d949cac1SHarald Welte 			      "Headphone Playback Switch",
3971d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3972d949cac1SHarald Welte 	if (err < 0)
3973d949cac1SHarald Welte 		return err;
3974d949cac1SHarald Welte 
39750aa62aefSHarald Welte 	create_hp_imux(spec);
39760aa62aefSHarald Welte 
3977d949cac1SHarald Welte 	return 0;
3978d949cac1SHarald Welte }
3979d949cac1SHarald Welte 
3980d949cac1SHarald Welte /* create playback/capture controls for input pins */
3981d949cac1SHarald Welte static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3982d949cac1SHarald Welte 						const struct auto_pin_cfg *cfg)
3983d949cac1SHarald Welte {
3984d949cac1SHarald Welte 	static char *labels[] = {
3985d949cac1SHarald Welte 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3986d949cac1SHarald Welte 	};
39870aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
3988d949cac1SHarald Welte 	int i, err, idx = 0;
3989d949cac1SHarald Welte 
3990d949cac1SHarald Welte 	/* for internal loopback recording select */
3991d949cac1SHarald Welte 	imux->items[imux->num_items].label = "Stereo Mixer";
3992d949cac1SHarald Welte 	imux->items[imux->num_items].index = 5;
3993d949cac1SHarald Welte 	imux->num_items++;
3994d949cac1SHarald Welte 
3995d949cac1SHarald Welte 	for (i = 0; i < AUTO_PIN_LAST; i++) {
3996d949cac1SHarald Welte 		if (!cfg->input_pins[i])
3997d949cac1SHarald Welte 			continue;
3998d949cac1SHarald Welte 
3999d949cac1SHarald Welte 		switch (cfg->input_pins[i]) {
4000d949cac1SHarald Welte 		case 0x1a: /* Mic */
4001d949cac1SHarald Welte 			idx = 2;
4002d949cac1SHarald Welte 			break;
4003d949cac1SHarald Welte 
4004d949cac1SHarald Welte 		case 0x1b: /* Line In */
4005d949cac1SHarald Welte 			idx = 3;
4006d949cac1SHarald Welte 			break;
4007d949cac1SHarald Welte 
4008d949cac1SHarald Welte 		case 0x1e: /* Front Mic */
4009d949cac1SHarald Welte 			idx = 4;
4010d949cac1SHarald Welte 			break;
4011d949cac1SHarald Welte 
4012d949cac1SHarald Welte 		case 0x1f: /* CD */
4013d949cac1SHarald Welte 			idx = 1;
4014d949cac1SHarald Welte 			break;
4015d949cac1SHarald Welte 		}
40169510e8ddSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x16);
4017d949cac1SHarald Welte 		if (err < 0)
4018d949cac1SHarald Welte 			return err;
4019d949cac1SHarald Welte 		imux->items[imux->num_items].label = labels[i];
4020d949cac1SHarald Welte 		imux->items[imux->num_items].index = idx-1;
4021d949cac1SHarald Welte 		imux->num_items++;
4022d949cac1SHarald Welte 	}
4023d949cac1SHarald Welte 	return 0;
4024d949cac1SHarald Welte }
4025d949cac1SHarald Welte 
40269da29271STakashi Iwai /* fill out digital output widgets; one for master and one for slave outputs */
40279da29271STakashi Iwai static void fill_dig_outs(struct hda_codec *codec)
40289da29271STakashi Iwai {
40299da29271STakashi Iwai 	struct via_spec *spec = codec->spec;
40309da29271STakashi Iwai 	int i;
40319da29271STakashi Iwai 
40329da29271STakashi Iwai 	for (i = 0; i < spec->autocfg.dig_outs; i++) {
40339da29271STakashi Iwai 		hda_nid_t nid;
40349da29271STakashi Iwai 		int conn;
40359da29271STakashi Iwai 
40369da29271STakashi Iwai 		nid = spec->autocfg.dig_out_pins[i];
40379da29271STakashi Iwai 		if (!nid)
40389da29271STakashi Iwai 			continue;
40399da29271STakashi Iwai 		conn = snd_hda_get_connections(codec, nid, &nid, 1);
40409da29271STakashi Iwai 		if (conn < 1)
40419da29271STakashi Iwai 			continue;
40429da29271STakashi Iwai 		if (!spec->multiout.dig_out_nid)
40439da29271STakashi Iwai 			spec->multiout.dig_out_nid = nid;
40449da29271STakashi Iwai 		else {
40459da29271STakashi Iwai 			spec->slave_dig_outs[0] = nid;
40469da29271STakashi Iwai 			break; /* at most two dig outs */
40479da29271STakashi Iwai 		}
40489da29271STakashi Iwai 	}
40499da29271STakashi Iwai }
40509da29271STakashi Iwai 
4051d949cac1SHarald Welte static int vt1708S_parse_auto_config(struct hda_codec *codec)
4052d949cac1SHarald Welte {
4053d949cac1SHarald Welte 	struct via_spec *spec = codec->spec;
4054d949cac1SHarald Welte 	int err;
4055d949cac1SHarald Welte 
40569da29271STakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4057d949cac1SHarald Welte 	if (err < 0)
4058d949cac1SHarald Welte 		return err;
4059d949cac1SHarald Welte 	err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4060d949cac1SHarald Welte 	if (err < 0)
4061d949cac1SHarald Welte 		return err;
4062d949cac1SHarald Welte 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4063d949cac1SHarald Welte 		return 0; /* can't find valid BIOS pin config */
4064d949cac1SHarald Welte 
4065d949cac1SHarald Welte 	err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4066d949cac1SHarald Welte 	if (err < 0)
4067d949cac1SHarald Welte 		return err;
4068d949cac1SHarald Welte 	err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4069d949cac1SHarald Welte 	if (err < 0)
4070d949cac1SHarald Welte 		return err;
4071d949cac1SHarald Welte 	err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4072d949cac1SHarald Welte 	if (err < 0)
4073d949cac1SHarald Welte 		return err;
4074d949cac1SHarald Welte 
4075d949cac1SHarald Welte 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4076d949cac1SHarald Welte 
40779da29271STakashi Iwai 	fill_dig_outs(codec);
407898aa34c0SHarald Welte 
4079603c4019STakashi Iwai 	if (spec->kctls.list)
4080603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
4081d949cac1SHarald Welte 
40820aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
40830aa62aefSHarald Welte 
4084f8fdd495SHarald Welte 	if (spec->hp_mux)
40850aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
4086d949cac1SHarald Welte 
40871564b287SLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4088d949cac1SHarald Welte 	return 1;
4089d949cac1SHarald Welte }
4090d949cac1SHarald Welte 
4091d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
4092d949cac1SHarald Welte static struct hda_amp_list vt1708S_loopbacks[] = {
4093d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 1 },
4094d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 2 },
4095d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 3 },
4096d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 4 },
4097d949cac1SHarald Welte 	{ } /* end */
4098d949cac1SHarald Welte };
4099d949cac1SHarald Welte #endif
4100d949cac1SHarald Welte 
41016369bcfcSLydia Wang static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
41026369bcfcSLydia Wang 			       int offset, int num_steps, int step_size)
41036369bcfcSLydia Wang {
41046369bcfcSLydia Wang 	snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
41056369bcfcSLydia Wang 				  (offset << AC_AMPCAP_OFFSET_SHIFT) |
41066369bcfcSLydia Wang 				  (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
41076369bcfcSLydia Wang 				  (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
41086369bcfcSLydia Wang 				  (0 << AC_AMPCAP_MUTE_SHIFT));
41096369bcfcSLydia Wang }
41106369bcfcSLydia Wang 
4111d949cac1SHarald Welte static int patch_vt1708S(struct hda_codec *codec)
4112d949cac1SHarald Welte {
4113d949cac1SHarald Welte 	struct via_spec *spec;
4114d949cac1SHarald Welte 	int err;
4115d949cac1SHarald Welte 
4116d949cac1SHarald Welte 	/* create a codec specific record */
4117d949cac1SHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4118d949cac1SHarald Welte 	if (spec == NULL)
4119d949cac1SHarald Welte 		return -ENOMEM;
4120d949cac1SHarald Welte 
4121d949cac1SHarald Welte 	codec->spec = spec;
4122d949cac1SHarald Welte 
4123d949cac1SHarald Welte 	/* automatic parse from the BIOS config */
4124d949cac1SHarald Welte 	err = vt1708S_parse_auto_config(codec);
4125d949cac1SHarald Welte 	if (err < 0) {
4126d949cac1SHarald Welte 		via_free(codec);
4127d949cac1SHarald Welte 		return err;
4128d949cac1SHarald Welte 	} else if (!err) {
4129d949cac1SHarald Welte 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
4130d949cac1SHarald Welte 		       "from BIOS.  Using genenic mode...\n");
4131d949cac1SHarald Welte 	}
4132d949cac1SHarald Welte 
413369e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
413469e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4135d949cac1SHarald Welte 
4136*36dd5c4aSLydia Wang 	if (codec->vendor_id == 0x11060440)
4137*36dd5c4aSLydia Wang 		spec->stream_name_analog = "VT1818S Analog";
4138*36dd5c4aSLydia Wang 	else
4139d949cac1SHarald Welte 		spec->stream_name_analog = "VT1708S Analog";
4140d949cac1SHarald Welte 	spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4141d949cac1SHarald Welte 	spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4142d949cac1SHarald Welte 
4143*36dd5c4aSLydia Wang 	if (codec->vendor_id == 0x11060440)
4144*36dd5c4aSLydia Wang 		spec->stream_name_digital = "VT1818S Digital";
4145*36dd5c4aSLydia Wang 	else
4146d949cac1SHarald Welte 		spec->stream_name_digital = "VT1708S Digital";
4147d949cac1SHarald Welte 	spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4148d949cac1SHarald Welte 
4149d949cac1SHarald Welte 	if (!spec->adc_nids && spec->input_mux) {
4150d949cac1SHarald Welte 		spec->adc_nids = vt1708S_adc_nids;
4151d949cac1SHarald Welte 		spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4152337b9d02STakashi Iwai 		get_mux_nids(codec);
41536369bcfcSLydia Wang 		override_mic_boost(codec, 0x1a, 0, 3, 40);
41546369bcfcSLydia Wang 		override_mic_boost(codec, 0x1e, 0, 3, 40);
4155d949cac1SHarald Welte 		spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4156d949cac1SHarald Welte 		spec->num_mixers++;
4157d949cac1SHarald Welte 	}
4158d949cac1SHarald Welte 
4159d949cac1SHarald Welte 	codec->patch_ops = via_patch_ops;
4160d949cac1SHarald Welte 
4161d949cac1SHarald Welte 	codec->patch_ops.init = via_auto_init;
416269e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
4163d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
4164d949cac1SHarald Welte 	spec->loopback.amplist = vt1708S_loopbacks;
4165d949cac1SHarald Welte #endif
4166d949cac1SHarald Welte 
4167518bf3baSLydia Wang 	/* correct names for VT1708BCE */
4168518bf3baSLydia Wang 	if (get_codec_type(codec) == VT1708BCE)	{
4169518bf3baSLydia Wang 		kfree(codec->chip_name);
4170518bf3baSLydia Wang 		codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4171518bf3baSLydia Wang 		snprintf(codec->bus->card->mixername,
4172518bf3baSLydia Wang 			 sizeof(codec->bus->card->mixername),
4173518bf3baSLydia Wang 			 "%s %s", codec->vendor_name, codec->chip_name);
4174518bf3baSLydia Wang 		spec->stream_name_analog = "VT1708BCE Analog";
4175518bf3baSLydia Wang 		spec->stream_name_digital = "VT1708BCE Digital";
4176518bf3baSLydia Wang 	}
4177d949cac1SHarald Welte 	return 0;
4178d949cac1SHarald Welte }
4179d949cac1SHarald Welte 
4180d949cac1SHarald Welte /* Patch for VT1702 */
4181d949cac1SHarald Welte 
4182d949cac1SHarald Welte /* capture mixer elements */
4183d949cac1SHarald Welte static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4184d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4185d949cac1SHarald Welte 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4186d949cac1SHarald Welte 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4187d949cac1SHarald Welte 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4188d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4189d949cac1SHarald Welte 	HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4190d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4191d949cac1SHarald Welte 			 HDA_INPUT),
4192d949cac1SHarald Welte 	{
4193d949cac1SHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4194d949cac1SHarald Welte 		/* The multiple "Capture Source" controls confuse alsamixer
4195d949cac1SHarald Welte 		 * So call somewhat different..
4196d949cac1SHarald Welte 		 */
4197d949cac1SHarald Welte 		/* .name = "Capture Source", */
4198d949cac1SHarald Welte 		.name = "Input Source",
4199d949cac1SHarald Welte 		.count = 1,
4200d949cac1SHarald Welte 		.info = via_mux_enum_info,
4201d949cac1SHarald Welte 		.get = via_mux_enum_get,
4202d949cac1SHarald Welte 		.put = via_mux_enum_put,
4203d949cac1SHarald Welte 	},
4204d949cac1SHarald Welte 	{ } /* end */
4205d949cac1SHarald Welte };
4206d949cac1SHarald Welte 
4207d949cac1SHarald Welte static struct hda_verb vt1702_volume_init_verbs[] = {
4208d949cac1SHarald Welte 	/*
4209d949cac1SHarald Welte 	 * Unmute ADC0-1 and set the default input to mic-in
4210d949cac1SHarald Welte 	 */
4211d949cac1SHarald Welte 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4212d949cac1SHarald Welte 	{0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4213d949cac1SHarald Welte 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4214d949cac1SHarald Welte 
4215d949cac1SHarald Welte 
4216d949cac1SHarald Welte 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4217d949cac1SHarald Welte 	 * mixer widget
4218d949cac1SHarald Welte 	 */
4219d949cac1SHarald Welte 	/* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4220d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4221d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4222d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4223d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4224d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4225d949cac1SHarald Welte 
4226d949cac1SHarald Welte 	/* Setup default input of PW4 to MW0 */
4227d949cac1SHarald Welte 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4228d949cac1SHarald Welte 	/* PW6 PW7 Output enable */
4229d949cac1SHarald Welte 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4230d949cac1SHarald Welte 	{0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4231bc7e7e5cSLydia Wang 	/* mixer enable */
4232bc7e7e5cSLydia Wang 	{0x1, 0xF88, 0x3},
4233bc7e7e5cSLydia Wang 	/* GPIO 0~2 */
4234bc7e7e5cSLydia Wang 	{0x1, 0xF82, 0x3F},
4235d949cac1SHarald Welte 	{ }
4236d949cac1SHarald Welte };
4237d949cac1SHarald Welte 
423869e52a80SHarald Welte static struct hda_verb vt1702_uniwill_init_verbs[] = {
4239a34df19aSLydia Wang 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4240a34df19aSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4241a34df19aSLydia Wang 	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4242a34df19aSLydia Wang 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4243a34df19aSLydia Wang 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4244a34df19aSLydia Wang 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
424569e52a80SHarald Welte 	{ }
424669e52a80SHarald Welte };
424769e52a80SHarald Welte 
4248d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_analog_playback = {
42490aa62aefSHarald Welte 	.substreams = 2,
4250d949cac1SHarald Welte 	.channels_min = 2,
4251d949cac1SHarald Welte 	.channels_max = 2,
4252d949cac1SHarald Welte 	.nid = 0x10, /* NID to query formats and rates */
4253d949cac1SHarald Welte 	.ops = {
4254d949cac1SHarald Welte 		.open = via_playback_pcm_open,
42550aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
425617314379SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
425717314379SLydia Wang 		.close = via_pcm_open_close
4258d949cac1SHarald Welte 	},
4259d949cac1SHarald Welte };
4260d949cac1SHarald Welte 
4261d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4262d949cac1SHarald Welte 	.substreams = 3,
4263d949cac1SHarald Welte 	.channels_min = 2,
4264d949cac1SHarald Welte 	.channels_max = 2,
4265d949cac1SHarald Welte 	.nid = 0x12, /* NID to query formats and rates */
4266d949cac1SHarald Welte 	.ops = {
426717314379SLydia Wang 		.open = via_pcm_open_close,
4268d949cac1SHarald Welte 		.prepare = via_capture_pcm_prepare,
426917314379SLydia Wang 		.cleanup = via_capture_pcm_cleanup,
427017314379SLydia Wang 		.close = via_pcm_open_close
4271d949cac1SHarald Welte 	},
4272d949cac1SHarald Welte };
4273d949cac1SHarald Welte 
4274d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_digital_playback = {
42755691ec7fSHarald Welte 	.substreams = 2,
4276d949cac1SHarald Welte 	.channels_min = 2,
4277d949cac1SHarald Welte 	.channels_max = 2,
4278d949cac1SHarald Welte 	/* NID is set in via_build_pcms */
4279d949cac1SHarald Welte 	.ops = {
4280d949cac1SHarald Welte 		.open = via_dig_playback_pcm_open,
4281d949cac1SHarald Welte 		.close = via_dig_playback_pcm_close,
42829da29271STakashi Iwai 		.prepare = via_dig_playback_pcm_prepare,
42839da29271STakashi Iwai 		.cleanup = via_dig_playback_pcm_cleanup
4284d949cac1SHarald Welte 	},
4285d949cac1SHarald Welte };
4286d949cac1SHarald Welte 
4287d949cac1SHarald Welte /* fill in the dac_nids table from the parsed pin configuration */
4288d949cac1SHarald Welte static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4289d949cac1SHarald Welte 				     const struct auto_pin_cfg *cfg)
4290d949cac1SHarald Welte {
4291d949cac1SHarald Welte 	spec->multiout.num_dacs = 1;
4292d949cac1SHarald Welte 	spec->multiout.dac_nids = spec->private_dac_nids;
4293d949cac1SHarald Welte 
4294d949cac1SHarald Welte 	if (cfg->line_out_pins[0]) {
4295d949cac1SHarald Welte 		/* config dac list */
4296d949cac1SHarald Welte 		spec->multiout.dac_nids[0] = 0x10;
4297d949cac1SHarald Welte 	}
4298d949cac1SHarald Welte 
4299d949cac1SHarald Welte 	return 0;
4300d949cac1SHarald Welte }
4301d949cac1SHarald Welte 
4302d949cac1SHarald Welte /* add playback controls from the parsed DAC table */
4303d949cac1SHarald Welte static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4304d949cac1SHarald Welte 					     const struct auto_pin_cfg *cfg)
4305d949cac1SHarald Welte {
4306d949cac1SHarald Welte 	int err;
4307d949cac1SHarald Welte 
4308d949cac1SHarald Welte 	if (!cfg->line_out_pins[0])
4309d949cac1SHarald Welte 		return -1;
4310d949cac1SHarald Welte 
4311d949cac1SHarald Welte 	/* add control to mixer index 0 */
4312d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4313d949cac1SHarald Welte 			      "Master Front Playback Volume",
4314d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4315d949cac1SHarald Welte 	if (err < 0)
4316d949cac1SHarald Welte 		return err;
4317d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4318d949cac1SHarald Welte 			      "Master Front Playback Switch",
4319d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4320d949cac1SHarald Welte 	if (err < 0)
4321d949cac1SHarald Welte 		return err;
4322d949cac1SHarald Welte 
4323d949cac1SHarald Welte 	/* Front */
4324d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4325d949cac1SHarald Welte 			      "Front Playback Volume",
4326d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4327d949cac1SHarald Welte 	if (err < 0)
4328d949cac1SHarald Welte 		return err;
4329d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4330d949cac1SHarald Welte 			      "Front Playback Switch",
4331d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4332d949cac1SHarald Welte 	if (err < 0)
4333d949cac1SHarald Welte 		return err;
4334d949cac1SHarald Welte 
4335d949cac1SHarald Welte 	return 0;
4336d949cac1SHarald Welte }
4337d949cac1SHarald Welte 
4338d949cac1SHarald Welte static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4339d949cac1SHarald Welte {
43400713efebSLydia Wang 	int err, i;
43410713efebSLydia Wang 	struct hda_input_mux *imux;
43420713efebSLydia Wang 	static const char *texts[] = { "ON", "OFF", NULL};
4343d949cac1SHarald Welte 	if (!pin)
4344d949cac1SHarald Welte 		return 0;
4345d949cac1SHarald Welte 	spec->multiout.hp_nid = 0x1D;
4346cdc1784dSLydia Wang 	spec->hp_independent_mode_index = 0;
4347d949cac1SHarald Welte 
4348d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4349d949cac1SHarald Welte 			      "Headphone Playback Volume",
4350d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4351d949cac1SHarald Welte 	if (err < 0)
4352d949cac1SHarald Welte 		return err;
4353d949cac1SHarald Welte 
4354d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4355d949cac1SHarald Welte 			      "Headphone Playback Switch",
4356d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4357d949cac1SHarald Welte 	if (err < 0)
4358d949cac1SHarald Welte 		return err;
4359d949cac1SHarald Welte 
43600713efebSLydia Wang 	imux = &spec->private_imux[1];
43610aa62aefSHarald Welte 
43620713efebSLydia Wang 	/* for hp mode select */
43630713efebSLydia Wang 	i = 0;
43640713efebSLydia Wang 	while (texts[i] != NULL)	{
43650713efebSLydia Wang 		imux->items[imux->num_items].label =  texts[i];
43660713efebSLydia Wang 		imux->items[imux->num_items].index = i;
43670713efebSLydia Wang 		imux->num_items++;
43680713efebSLydia Wang 		i++;
43690713efebSLydia Wang 	}
43700713efebSLydia Wang 
43710713efebSLydia Wang 	spec->hp_mux = &spec->private_imux[1];
4372d949cac1SHarald Welte 	return 0;
4373d949cac1SHarald Welte }
4374d949cac1SHarald Welte 
4375d949cac1SHarald Welte /* create playback/capture controls for input pins */
4376d949cac1SHarald Welte static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4377d949cac1SHarald Welte 						const struct auto_pin_cfg *cfg)
4378d949cac1SHarald Welte {
4379d949cac1SHarald Welte 	static char *labels[] = {
4380d949cac1SHarald Welte 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4381d949cac1SHarald Welte 	};
43820aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
4383d949cac1SHarald Welte 	int i, err, idx = 0;
4384d949cac1SHarald Welte 
4385d949cac1SHarald Welte 	/* for internal loopback recording select */
4386d949cac1SHarald Welte 	imux->items[imux->num_items].label = "Stereo Mixer";
4387d949cac1SHarald Welte 	imux->items[imux->num_items].index = 3;
4388d949cac1SHarald Welte 	imux->num_items++;
4389d949cac1SHarald Welte 
4390d949cac1SHarald Welte 	for (i = 0; i < AUTO_PIN_LAST; i++) {
4391d949cac1SHarald Welte 		if (!cfg->input_pins[i])
4392d949cac1SHarald Welte 			continue;
4393d949cac1SHarald Welte 
4394d949cac1SHarald Welte 		switch (cfg->input_pins[i]) {
4395d949cac1SHarald Welte 		case 0x14: /* Mic */
4396d949cac1SHarald Welte 			idx = 1;
4397d949cac1SHarald Welte 			break;
4398d949cac1SHarald Welte 
4399d949cac1SHarald Welte 		case 0x15: /* Line In */
4400d949cac1SHarald Welte 			idx = 2;
4401d949cac1SHarald Welte 			break;
4402d949cac1SHarald Welte 
4403d949cac1SHarald Welte 		case 0x18: /* Front Mic */
4404d949cac1SHarald Welte 			idx = 3;
4405d949cac1SHarald Welte 			break;
4406d949cac1SHarald Welte 		}
44079510e8ddSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4408d949cac1SHarald Welte 		if (err < 0)
4409d949cac1SHarald Welte 			return err;
4410d949cac1SHarald Welte 		imux->items[imux->num_items].label = labels[i];
4411d949cac1SHarald Welte 		imux->items[imux->num_items].index = idx-1;
4412d949cac1SHarald Welte 		imux->num_items++;
4413d949cac1SHarald Welte 	}
4414d949cac1SHarald Welte 	return 0;
4415d949cac1SHarald Welte }
4416d949cac1SHarald Welte 
4417d949cac1SHarald Welte static int vt1702_parse_auto_config(struct hda_codec *codec)
4418d949cac1SHarald Welte {
4419d949cac1SHarald Welte 	struct via_spec *spec = codec->spec;
4420d949cac1SHarald Welte 	int err;
4421d949cac1SHarald Welte 
44229da29271STakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4423d949cac1SHarald Welte 	if (err < 0)
4424d949cac1SHarald Welte 		return err;
4425d949cac1SHarald Welte 	err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4426d949cac1SHarald Welte 	if (err < 0)
4427d949cac1SHarald Welte 		return err;
4428d949cac1SHarald Welte 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4429d949cac1SHarald Welte 		return 0; /* can't find valid BIOS pin config */
4430d949cac1SHarald Welte 
4431d949cac1SHarald Welte 	err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4432d949cac1SHarald Welte 	if (err < 0)
4433d949cac1SHarald Welte 		return err;
4434d949cac1SHarald Welte 	err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4435d949cac1SHarald Welte 	if (err < 0)
4436d949cac1SHarald Welte 		return err;
4437c2c02ea3SLydia Wang 	/* limit AA path volume to 0 dB */
4438c2c02ea3SLydia Wang 	snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4439c2c02ea3SLydia Wang 				  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4440c2c02ea3SLydia Wang 				  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4441c2c02ea3SLydia Wang 				  (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4442c2c02ea3SLydia Wang 				  (1 << AC_AMPCAP_MUTE_SHIFT));
4443d949cac1SHarald Welte 	err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4444d949cac1SHarald Welte 	if (err < 0)
4445d949cac1SHarald Welte 		return err;
4446d949cac1SHarald Welte 
4447d949cac1SHarald Welte 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4448d949cac1SHarald Welte 
44499da29271STakashi Iwai 	fill_dig_outs(codec);
445098aa34c0SHarald Welte 
4451603c4019STakashi Iwai 	if (spec->kctls.list)
4452603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
4453d949cac1SHarald Welte 
44540aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
44550aa62aefSHarald Welte 
4456f8fdd495SHarald Welte 	if (spec->hp_mux)
44570aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
4458d949cac1SHarald Welte 
4459d949cac1SHarald Welte 	return 1;
4460d949cac1SHarald Welte }
4461d949cac1SHarald Welte 
4462d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
4463d949cac1SHarald Welte static struct hda_amp_list vt1702_loopbacks[] = {
4464d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 1 },
4465d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 2 },
4466d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 3 },
4467d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 4 },
4468d949cac1SHarald Welte 	{ } /* end */
4469d949cac1SHarald Welte };
4470d949cac1SHarald Welte #endif
4471d949cac1SHarald Welte 
4472d949cac1SHarald Welte static int patch_vt1702(struct hda_codec *codec)
4473d949cac1SHarald Welte {
4474d949cac1SHarald Welte 	struct via_spec *spec;
4475d949cac1SHarald Welte 	int err;
4476d949cac1SHarald Welte 
4477d949cac1SHarald Welte 	/* create a codec specific record */
4478d949cac1SHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4479d949cac1SHarald Welte 	if (spec == NULL)
4480d949cac1SHarald Welte 		return -ENOMEM;
4481d949cac1SHarald Welte 
4482d949cac1SHarald Welte 	codec->spec = spec;
4483d949cac1SHarald Welte 
4484d949cac1SHarald Welte 	/* automatic parse from the BIOS config */
4485d949cac1SHarald Welte 	err = vt1702_parse_auto_config(codec);
4486d949cac1SHarald Welte 	if (err < 0) {
4487d949cac1SHarald Welte 		via_free(codec);
4488d949cac1SHarald Welte 		return err;
4489d949cac1SHarald Welte 	} else if (!err) {
4490d949cac1SHarald Welte 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
4491d949cac1SHarald Welte 		       "from BIOS.  Using genenic mode...\n");
4492d949cac1SHarald Welte 	}
4493d949cac1SHarald Welte 
449469e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
449569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4496d949cac1SHarald Welte 
4497d949cac1SHarald Welte 	spec->stream_name_analog = "VT1702 Analog";
4498d949cac1SHarald Welte 	spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4499d949cac1SHarald Welte 	spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4500d949cac1SHarald Welte 
4501d949cac1SHarald Welte 	spec->stream_name_digital = "VT1702 Digital";
4502d949cac1SHarald Welte 	spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4503d949cac1SHarald Welte 
4504d949cac1SHarald Welte 	if (!spec->adc_nids && spec->input_mux) {
4505d949cac1SHarald Welte 		spec->adc_nids = vt1702_adc_nids;
4506d949cac1SHarald Welte 		spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4507337b9d02STakashi Iwai 		get_mux_nids(codec);
4508d949cac1SHarald Welte 		spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4509d949cac1SHarald Welte 		spec->num_mixers++;
4510d949cac1SHarald Welte 	}
4511d949cac1SHarald Welte 
4512d949cac1SHarald Welte 	codec->patch_ops = via_patch_ops;
4513d949cac1SHarald Welte 
4514d949cac1SHarald Welte 	codec->patch_ops.init = via_auto_init;
451569e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
4516d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
4517d949cac1SHarald Welte 	spec->loopback.amplist = vt1702_loopbacks;
4518d949cac1SHarald Welte #endif
4519d949cac1SHarald Welte 
4520d949cac1SHarald Welte 	return 0;
4521d949cac1SHarald Welte }
4522d949cac1SHarald Welte 
4523eb7188caSLydia Wang /* Patch for VT1718S */
4524eb7188caSLydia Wang 
4525eb7188caSLydia Wang /* capture mixer elements */
4526eb7188caSLydia Wang static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4527eb7188caSLydia Wang 	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4528eb7188caSLydia Wang 	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4529eb7188caSLydia Wang 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4530eb7188caSLydia Wang 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4531eb7188caSLydia Wang 	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4532eb7188caSLydia Wang 	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4533eb7188caSLydia Wang 			 HDA_INPUT),
4534eb7188caSLydia Wang 	{
4535eb7188caSLydia Wang 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4536eb7188caSLydia Wang 		/* The multiple "Capture Source" controls confuse alsamixer
4537eb7188caSLydia Wang 		 * So call somewhat different..
4538eb7188caSLydia Wang 		 */
4539eb7188caSLydia Wang 		.name = "Input Source",
4540eb7188caSLydia Wang 		.count = 2,
4541eb7188caSLydia Wang 		.info = via_mux_enum_info,
4542eb7188caSLydia Wang 		.get = via_mux_enum_get,
4543eb7188caSLydia Wang 		.put = via_mux_enum_put,
4544eb7188caSLydia Wang 	},
4545eb7188caSLydia Wang 	{ } /* end */
4546eb7188caSLydia Wang };
4547eb7188caSLydia Wang 
4548eb7188caSLydia Wang static struct hda_verb vt1718S_volume_init_verbs[] = {
4549eb7188caSLydia Wang 	/*
4550eb7188caSLydia Wang 	 * Unmute ADC0-1 and set the default input to mic-in
4551eb7188caSLydia Wang 	 */
4552eb7188caSLydia Wang 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4553eb7188caSLydia Wang 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4554eb7188caSLydia Wang 
4555eb7188caSLydia Wang 
4556eb7188caSLydia Wang 	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4557eb7188caSLydia Wang 	 * mixer widget
4558eb7188caSLydia Wang 	 */
4559eb7188caSLydia Wang 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4560eb7188caSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4561eb7188caSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4562eb7188caSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4563eb7188caSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4564eb7188caSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4565eb7188caSLydia Wang 
4566eb7188caSLydia Wang 	/* Setup default input of Front HP to MW9 */
4567eb7188caSLydia Wang 	{0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4568eb7188caSLydia Wang 	/* PW9 PW10 Output enable */
4569eb7188caSLydia Wang 	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4570eb7188caSLydia Wang 	{0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4571eb7188caSLydia Wang 	/* PW11 Input enable */
4572eb7188caSLydia Wang 	{0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4573eb7188caSLydia Wang 	/* Enable Boost Volume backdoor */
4574eb7188caSLydia Wang 	{0x1, 0xf88, 0x8},
4575eb7188caSLydia Wang 	/* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4576eb7188caSLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4577eb7188caSLydia Wang 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4578eb7188caSLydia Wang 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4579eb7188caSLydia Wang 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4580eb7188caSLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4581eb7188caSLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4582eb7188caSLydia Wang 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4583eb7188caSLydia Wang 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4584eb7188caSLydia Wang 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4585eb7188caSLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4586eb7188caSLydia Wang 	/* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4587eb7188caSLydia Wang 	{0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4588eb7188caSLydia Wang 	{0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4589eb7188caSLydia Wang 	/* Unmute MW4's index 0 */
4590eb7188caSLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4591eb7188caSLydia Wang 	{ }
4592eb7188caSLydia Wang };
4593eb7188caSLydia Wang 
4594eb7188caSLydia Wang 
4595eb7188caSLydia Wang static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4596eb7188caSLydia Wang 	{0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4597eb7188caSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4598eb7188caSLydia Wang 	{0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4599eb7188caSLydia Wang 	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4600eb7188caSLydia Wang 	{0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4601eb7188caSLydia Wang 	{0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4602eb7188caSLydia Wang 	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4603eb7188caSLydia Wang 	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4604eb7188caSLydia Wang 	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4605eb7188caSLydia Wang 	{ }
4606eb7188caSLydia Wang };
4607eb7188caSLydia Wang 
4608eb7188caSLydia Wang static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4609eb7188caSLydia Wang 	.substreams = 2,
4610eb7188caSLydia Wang 	.channels_min = 2,
4611eb7188caSLydia Wang 	.channels_max = 10,
4612eb7188caSLydia Wang 	.nid = 0x8, /* NID to query formats and rates */
4613eb7188caSLydia Wang 	.ops = {
4614eb7188caSLydia Wang 		.open = via_playback_pcm_open,
4615eb7188caSLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
4616eb7188caSLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
4617eb7188caSLydia Wang 		.close = via_pcm_open_close,
4618eb7188caSLydia Wang 	},
4619eb7188caSLydia Wang };
4620eb7188caSLydia Wang 
4621eb7188caSLydia Wang static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4622eb7188caSLydia Wang 	.substreams = 2,
4623eb7188caSLydia Wang 	.channels_min = 2,
4624eb7188caSLydia Wang 	.channels_max = 2,
4625eb7188caSLydia Wang 	.nid = 0x10, /* NID to query formats and rates */
4626eb7188caSLydia Wang 	.ops = {
4627eb7188caSLydia Wang 		.open = via_pcm_open_close,
4628eb7188caSLydia Wang 		.prepare = via_capture_pcm_prepare,
4629eb7188caSLydia Wang 		.cleanup = via_capture_pcm_cleanup,
4630eb7188caSLydia Wang 		.close = via_pcm_open_close,
4631eb7188caSLydia Wang 	},
4632eb7188caSLydia Wang };
4633eb7188caSLydia Wang 
4634eb7188caSLydia Wang static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4635eb7188caSLydia Wang 	.substreams = 2,
4636eb7188caSLydia Wang 	.channels_min = 2,
4637eb7188caSLydia Wang 	.channels_max = 2,
4638eb7188caSLydia Wang 	/* NID is set in via_build_pcms */
4639eb7188caSLydia Wang 	.ops = {
4640eb7188caSLydia Wang 		.open = via_dig_playback_pcm_open,
4641eb7188caSLydia Wang 		.close = via_dig_playback_pcm_close,
4642eb7188caSLydia Wang 		.prepare = via_dig_playback_pcm_prepare,
4643eb7188caSLydia Wang 		.cleanup = via_dig_playback_pcm_cleanup
4644eb7188caSLydia Wang 	},
4645eb7188caSLydia Wang };
4646eb7188caSLydia Wang 
4647eb7188caSLydia Wang static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4648eb7188caSLydia Wang 	.substreams = 1,
4649eb7188caSLydia Wang 	.channels_min = 2,
4650eb7188caSLydia Wang 	.channels_max = 2,
4651eb7188caSLydia Wang };
4652eb7188caSLydia Wang 
4653eb7188caSLydia Wang /* fill in the dac_nids table from the parsed pin configuration */
4654eb7188caSLydia Wang static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4655eb7188caSLydia Wang 				     const struct auto_pin_cfg *cfg)
4656eb7188caSLydia Wang {
4657eb7188caSLydia Wang 	int i;
4658eb7188caSLydia Wang 	hda_nid_t nid;
4659eb7188caSLydia Wang 
4660eb7188caSLydia Wang 	spec->multiout.num_dacs = cfg->line_outs;
4661eb7188caSLydia Wang 
4662eb7188caSLydia Wang 	spec->multiout.dac_nids = spec->private_dac_nids;
4663eb7188caSLydia Wang 
4664eb7188caSLydia Wang 	for (i = 0; i < 4; i++) {
4665eb7188caSLydia Wang 		nid = cfg->line_out_pins[i];
4666eb7188caSLydia Wang 		if (nid) {
4667eb7188caSLydia Wang 			/* config dac list */
4668eb7188caSLydia Wang 			switch (i) {
4669eb7188caSLydia Wang 			case AUTO_SEQ_FRONT:
4670eb7188caSLydia Wang 				spec->multiout.dac_nids[i] = 0x8;
4671eb7188caSLydia Wang 				break;
4672eb7188caSLydia Wang 			case AUTO_SEQ_CENLFE:
4673eb7188caSLydia Wang 				spec->multiout.dac_nids[i] = 0xa;
4674eb7188caSLydia Wang 				break;
4675eb7188caSLydia Wang 			case AUTO_SEQ_SURROUND:
4676eb7188caSLydia Wang 				spec->multiout.dac_nids[i] = 0x9;
4677eb7188caSLydia Wang 				break;
4678eb7188caSLydia Wang 			case AUTO_SEQ_SIDE:
4679eb7188caSLydia Wang 				spec->multiout.dac_nids[i] = 0xb;
4680eb7188caSLydia Wang 				break;
4681eb7188caSLydia Wang 			}
4682eb7188caSLydia Wang 		}
4683eb7188caSLydia Wang 	}
4684eb7188caSLydia Wang 
4685eb7188caSLydia Wang 	return 0;
4686eb7188caSLydia Wang }
4687eb7188caSLydia Wang 
4688eb7188caSLydia Wang /* add playback controls from the parsed DAC table */
4689eb7188caSLydia Wang static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4690eb7188caSLydia Wang 					     const struct auto_pin_cfg *cfg)
4691eb7188caSLydia Wang {
4692eb7188caSLydia Wang 	char name[32];
4693eb7188caSLydia Wang 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4694eb7188caSLydia Wang 	hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4695eb7188caSLydia Wang 	hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4696eb7188caSLydia Wang 	hda_nid_t nid, nid_vol, nid_mute = 0;
4697eb7188caSLydia Wang 	int i, err;
4698eb7188caSLydia Wang 
4699eb7188caSLydia Wang 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4700eb7188caSLydia Wang 		nid = cfg->line_out_pins[i];
4701eb7188caSLydia Wang 
4702eb7188caSLydia Wang 		if (!nid)
4703eb7188caSLydia Wang 			continue;
4704eb7188caSLydia Wang 		nid_vol = nid_vols[i];
4705eb7188caSLydia Wang 		nid_mute = nid_mutes[i];
4706eb7188caSLydia Wang 
4707eb7188caSLydia Wang 		if (i == AUTO_SEQ_CENLFE) {
4708eb7188caSLydia Wang 			/* Center/LFE */
4709eb7188caSLydia Wang 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4710eb7188caSLydia Wang 					      "Center Playback Volume",
4711eb7188caSLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4712eb7188caSLydia Wang 								  HDA_OUTPUT));
4713eb7188caSLydia Wang 			if (err < 0)
4714eb7188caSLydia Wang 				return err;
4715eb7188caSLydia Wang 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4716eb7188caSLydia Wang 					      "LFE Playback Volume",
4717eb7188caSLydia Wang 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4718eb7188caSLydia Wang 								  HDA_OUTPUT));
4719eb7188caSLydia Wang 			if (err < 0)
4720eb7188caSLydia Wang 				return err;
4721eb7188caSLydia Wang 			err = via_add_control(
4722eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE,
4723eb7188caSLydia Wang 				"Center Playback Switch",
4724eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4725eb7188caSLydia Wang 						    HDA_OUTPUT));
4726eb7188caSLydia Wang 			if (err < 0)
4727eb7188caSLydia Wang 				return err;
4728eb7188caSLydia Wang 			err = via_add_control(
4729eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE,
4730eb7188caSLydia Wang 				"LFE Playback Switch",
4731eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4732eb7188caSLydia Wang 						    HDA_OUTPUT));
4733eb7188caSLydia Wang 			if (err < 0)
4734eb7188caSLydia Wang 				return err;
4735eb7188caSLydia Wang 		} else if (i == AUTO_SEQ_FRONT) {
4736eb7188caSLydia Wang 			/* Front */
4737eb7188caSLydia Wang 			sprintf(name, "%s Playback Volume", chname[i]);
4738eb7188caSLydia Wang 			err = via_add_control(
4739eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_VOL, name,
4740eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4741eb7188caSLydia Wang 			if (err < 0)
4742eb7188caSLydia Wang 				return err;
4743eb7188caSLydia Wang 			sprintf(name, "%s Playback Switch", chname[i]);
4744eb7188caSLydia Wang 			err = via_add_control(
4745eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE, name,
4746eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4747eb7188caSLydia Wang 						    HDA_OUTPUT));
4748eb7188caSLydia Wang 			if (err < 0)
4749eb7188caSLydia Wang 				return err;
4750eb7188caSLydia Wang 		} else {
4751eb7188caSLydia Wang 			sprintf(name, "%s Playback Volume", chname[i]);
4752eb7188caSLydia Wang 			err = via_add_control(
4753eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_VOL, name,
4754eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4755eb7188caSLydia Wang 			if (err < 0)
4756eb7188caSLydia Wang 				return err;
4757eb7188caSLydia Wang 			sprintf(name, "%s Playback Switch", chname[i]);
4758eb7188caSLydia Wang 			err = via_add_control(
4759eb7188caSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE, name,
4760eb7188caSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4761eb7188caSLydia Wang 						    HDA_OUTPUT));
4762eb7188caSLydia Wang 			if (err < 0)
4763eb7188caSLydia Wang 				return err;
4764eb7188caSLydia Wang 		}
4765eb7188caSLydia Wang 	}
4766eb7188caSLydia Wang 	return 0;
4767eb7188caSLydia Wang }
4768eb7188caSLydia Wang 
4769eb7188caSLydia Wang static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4770eb7188caSLydia Wang {
4771eb7188caSLydia Wang 	int err;
4772eb7188caSLydia Wang 
4773eb7188caSLydia Wang 	if (!pin)
4774eb7188caSLydia Wang 		return 0;
4775eb7188caSLydia Wang 
4776eb7188caSLydia Wang 	spec->multiout.hp_nid = 0xc; /* AOW4 */
4777eb7188caSLydia Wang 	spec->hp_independent_mode_index = 1;
4778eb7188caSLydia Wang 
4779eb7188caSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4780eb7188caSLydia Wang 			      "Headphone Playback Volume",
4781eb7188caSLydia Wang 			      HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4782eb7188caSLydia Wang 	if (err < 0)
4783eb7188caSLydia Wang 		return err;
4784eb7188caSLydia Wang 
4785eb7188caSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4786eb7188caSLydia Wang 			      "Headphone Playback Switch",
4787eb7188caSLydia Wang 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4788eb7188caSLydia Wang 	if (err < 0)
4789eb7188caSLydia Wang 		return err;
4790eb7188caSLydia Wang 
4791eb7188caSLydia Wang 	create_hp_imux(spec);
4792eb7188caSLydia Wang 	return 0;
4793eb7188caSLydia Wang }
4794eb7188caSLydia Wang 
4795eb7188caSLydia Wang /* create playback/capture controls for input pins */
4796eb7188caSLydia Wang static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4797eb7188caSLydia Wang 						const struct auto_pin_cfg *cfg)
4798eb7188caSLydia Wang {
4799eb7188caSLydia Wang 	static char *labels[] = {
4800eb7188caSLydia Wang 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4801eb7188caSLydia Wang 	};
4802eb7188caSLydia Wang 	struct hda_input_mux *imux = &spec->private_imux[0];
4803eb7188caSLydia Wang 	int i, err, idx = 0;
4804eb7188caSLydia Wang 
4805eb7188caSLydia Wang 	/* for internal loopback recording select */
4806eb7188caSLydia Wang 	imux->items[imux->num_items].label = "Stereo Mixer";
4807eb7188caSLydia Wang 	imux->items[imux->num_items].index = 5;
4808eb7188caSLydia Wang 	imux->num_items++;
4809eb7188caSLydia Wang 
4810eb7188caSLydia Wang 	for (i = 0; i < AUTO_PIN_LAST; i++) {
4811eb7188caSLydia Wang 		if (!cfg->input_pins[i])
4812eb7188caSLydia Wang 			continue;
4813eb7188caSLydia Wang 
4814eb7188caSLydia Wang 		switch (cfg->input_pins[i]) {
4815eb7188caSLydia Wang 		case 0x2b: /* Mic */
4816eb7188caSLydia Wang 			idx = 1;
4817eb7188caSLydia Wang 			break;
4818eb7188caSLydia Wang 
4819eb7188caSLydia Wang 		case 0x2a: /* Line In */
4820eb7188caSLydia Wang 			idx = 2;
4821eb7188caSLydia Wang 			break;
4822eb7188caSLydia Wang 
4823eb7188caSLydia Wang 		case 0x29: /* Front Mic */
4824eb7188caSLydia Wang 			idx = 3;
4825eb7188caSLydia Wang 			break;
4826eb7188caSLydia Wang 
4827eb7188caSLydia Wang 		case 0x2c: /* CD */
4828eb7188caSLydia Wang 			idx = 0;
4829eb7188caSLydia Wang 			break;
4830eb7188caSLydia Wang 		}
4831eb7188caSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x21);
4832eb7188caSLydia Wang 		if (err < 0)
4833eb7188caSLydia Wang 			return err;
4834eb7188caSLydia Wang 		imux->items[imux->num_items].label = labels[i];
4835eb7188caSLydia Wang 		imux->items[imux->num_items].index = idx;
4836eb7188caSLydia Wang 		imux->num_items++;
4837eb7188caSLydia Wang 	}
4838eb7188caSLydia Wang 	return 0;
4839eb7188caSLydia Wang }
4840eb7188caSLydia Wang 
4841eb7188caSLydia Wang static int vt1718S_parse_auto_config(struct hda_codec *codec)
4842eb7188caSLydia Wang {
4843eb7188caSLydia Wang 	struct via_spec *spec = codec->spec;
4844eb7188caSLydia Wang 	int err;
4845eb7188caSLydia Wang 
4846eb7188caSLydia Wang 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4847eb7188caSLydia Wang 
4848eb7188caSLydia Wang 	if (err < 0)
4849eb7188caSLydia Wang 		return err;
4850eb7188caSLydia Wang 	err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4851eb7188caSLydia Wang 	if (err < 0)
4852eb7188caSLydia Wang 		return err;
4853eb7188caSLydia Wang 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4854eb7188caSLydia Wang 		return 0; /* can't find valid BIOS pin config */
4855eb7188caSLydia Wang 
4856eb7188caSLydia Wang 	err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4857eb7188caSLydia Wang 	if (err < 0)
4858eb7188caSLydia Wang 		return err;
4859eb7188caSLydia Wang 	err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4860eb7188caSLydia Wang 	if (err < 0)
4861eb7188caSLydia Wang 		return err;
4862eb7188caSLydia Wang 	err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4863eb7188caSLydia Wang 	if (err < 0)
4864eb7188caSLydia Wang 		return err;
4865eb7188caSLydia Wang 
4866eb7188caSLydia Wang 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4867eb7188caSLydia Wang 
4868eb7188caSLydia Wang 	fill_dig_outs(codec);
4869eb7188caSLydia Wang 
4870eb7188caSLydia Wang 	if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4871eb7188caSLydia Wang 		spec->dig_in_nid = 0x13;
4872eb7188caSLydia Wang 
4873eb7188caSLydia Wang 	if (spec->kctls.list)
4874eb7188caSLydia Wang 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
4875eb7188caSLydia Wang 
4876eb7188caSLydia Wang 	spec->input_mux = &spec->private_imux[0];
4877eb7188caSLydia Wang 
4878eb7188caSLydia Wang 	if (spec->hp_mux)
4879eb7188caSLydia Wang 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
4880eb7188caSLydia Wang 
4881eb7188caSLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4882eb7188caSLydia Wang 
4883eb7188caSLydia Wang 	return 1;
4884eb7188caSLydia Wang }
4885eb7188caSLydia Wang 
4886eb7188caSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
4887eb7188caSLydia Wang static struct hda_amp_list vt1718S_loopbacks[] = {
4888eb7188caSLydia Wang 	{ 0x21, HDA_INPUT, 1 },
4889eb7188caSLydia Wang 	{ 0x21, HDA_INPUT, 2 },
4890eb7188caSLydia Wang 	{ 0x21, HDA_INPUT, 3 },
4891eb7188caSLydia Wang 	{ 0x21, HDA_INPUT, 4 },
4892eb7188caSLydia Wang 	{ } /* end */
4893eb7188caSLydia Wang };
4894eb7188caSLydia Wang #endif
4895eb7188caSLydia Wang 
4896eb7188caSLydia Wang static int patch_vt1718S(struct hda_codec *codec)
4897eb7188caSLydia Wang {
4898eb7188caSLydia Wang 	struct via_spec *spec;
4899eb7188caSLydia Wang 	int err;
4900eb7188caSLydia Wang 
4901eb7188caSLydia Wang 	/* create a codec specific record */
4902eb7188caSLydia Wang 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4903eb7188caSLydia Wang 	if (spec == NULL)
4904eb7188caSLydia Wang 		return -ENOMEM;
4905eb7188caSLydia Wang 
4906eb7188caSLydia Wang 	codec->spec = spec;
4907eb7188caSLydia Wang 
4908eb7188caSLydia Wang 	/* automatic parse from the BIOS config */
4909eb7188caSLydia Wang 	err = vt1718S_parse_auto_config(codec);
4910eb7188caSLydia Wang 	if (err < 0) {
4911eb7188caSLydia Wang 		via_free(codec);
4912eb7188caSLydia Wang 		return err;
4913eb7188caSLydia Wang 	} else if (!err) {
4914eb7188caSLydia Wang 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
4915eb7188caSLydia Wang 		       "from BIOS.  Using genenic mode...\n");
4916eb7188caSLydia Wang 	}
4917eb7188caSLydia Wang 
4918eb7188caSLydia Wang 	spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4919eb7188caSLydia Wang 	spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4920eb7188caSLydia Wang 
4921bb3c6bfcSLydia Wang 	if (codec->vendor_id == 0x11060441)
4922bb3c6bfcSLydia Wang 		spec->stream_name_analog = "VT2020 Analog";
4923bb3c6bfcSLydia Wang 	else if (codec->vendor_id == 0x11064441)
4924bb3c6bfcSLydia Wang 		spec->stream_name_analog = "VT1828S Analog";
4925bb3c6bfcSLydia Wang 	else
4926eb7188caSLydia Wang 		spec->stream_name_analog = "VT1718S Analog";
4927eb7188caSLydia Wang 	spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4928eb7188caSLydia Wang 	spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4929eb7188caSLydia Wang 
4930bb3c6bfcSLydia Wang 	if (codec->vendor_id == 0x11060441)
4931bb3c6bfcSLydia Wang 		spec->stream_name_digital = "VT2020 Digital";
4932bb3c6bfcSLydia Wang 	else if (codec->vendor_id == 0x11064441)
4933bb3c6bfcSLydia Wang 		spec->stream_name_digital = "VT1828S Digital";
4934bb3c6bfcSLydia Wang 	else
4935eb7188caSLydia Wang 		spec->stream_name_digital = "VT1718S Digital";
4936eb7188caSLydia Wang 	spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4937bb3c6bfcSLydia Wang 	if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4938eb7188caSLydia Wang 		spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4939eb7188caSLydia Wang 
4940eb7188caSLydia Wang 	if (!spec->adc_nids && spec->input_mux) {
4941eb7188caSLydia Wang 		spec->adc_nids = vt1718S_adc_nids;
4942eb7188caSLydia Wang 		spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4943eb7188caSLydia Wang 		get_mux_nids(codec);
4944bb3c6bfcSLydia Wang 		override_mic_boost(codec, 0x2b, 0, 3, 40);
4945bb3c6bfcSLydia Wang 		override_mic_boost(codec, 0x29, 0, 3, 40);
4946eb7188caSLydia Wang 		spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4947eb7188caSLydia Wang 		spec->num_mixers++;
4948eb7188caSLydia Wang 	}
4949eb7188caSLydia Wang 
4950eb7188caSLydia Wang 	codec->patch_ops = via_patch_ops;
4951eb7188caSLydia Wang 
4952eb7188caSLydia Wang 	codec->patch_ops.init = via_auto_init;
49530f48327eSStephen Rothwell 	codec->patch_ops.unsol_event = via_unsol_event;
4954eb7188caSLydia Wang 
4955eb7188caSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
4956eb7188caSLydia Wang 	spec->loopback.amplist = vt1718S_loopbacks;
4957eb7188caSLydia Wang #endif
4958eb7188caSLydia Wang 
4959eb7188caSLydia Wang 	return 0;
4960eb7188caSLydia Wang }
4961f3db423dSLydia Wang 
4962f3db423dSLydia Wang /* Patch for VT1716S */
4963f3db423dSLydia Wang 
4964f3db423dSLydia Wang static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4965f3db423dSLydia Wang 			    struct snd_ctl_elem_info *uinfo)
4966f3db423dSLydia Wang {
4967f3db423dSLydia Wang 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4968f3db423dSLydia Wang 	uinfo->count = 1;
4969f3db423dSLydia Wang 	uinfo->value.integer.min = 0;
4970f3db423dSLydia Wang 	uinfo->value.integer.max = 1;
4971f3db423dSLydia Wang 	return 0;
4972f3db423dSLydia Wang }
4973f3db423dSLydia Wang 
4974f3db423dSLydia Wang static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4975f3db423dSLydia Wang 			   struct snd_ctl_elem_value *ucontrol)
4976f3db423dSLydia Wang {
4977f3db423dSLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4978f3db423dSLydia Wang 	int index = 0;
4979f3db423dSLydia Wang 
4980f3db423dSLydia Wang 	index = snd_hda_codec_read(codec, 0x26, 0,
4981f3db423dSLydia Wang 					       AC_VERB_GET_CONNECT_SEL, 0);
4982f3db423dSLydia Wang 	if (index != -1)
4983f3db423dSLydia Wang 		*ucontrol->value.integer.value = index;
4984f3db423dSLydia Wang 
4985f3db423dSLydia Wang 	return 0;
4986f3db423dSLydia Wang }
4987f3db423dSLydia Wang 
4988f3db423dSLydia Wang static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4989f3db423dSLydia Wang 			   struct snd_ctl_elem_value *ucontrol)
4990f3db423dSLydia Wang {
4991f3db423dSLydia Wang 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4992f3db423dSLydia Wang 	struct via_spec *spec = codec->spec;
4993f3db423dSLydia Wang 	int index = *ucontrol->value.integer.value;
4994f3db423dSLydia Wang 
4995f3db423dSLydia Wang 	snd_hda_codec_write(codec, 0x26, 0,
4996f3db423dSLydia Wang 					       AC_VERB_SET_CONNECT_SEL, index);
4997f3db423dSLydia Wang 	spec->dmic_enabled = index;
4998f3db423dSLydia Wang 	set_jack_power_state(codec);
4999f3db423dSLydia Wang 
5000f3db423dSLydia Wang 	return 1;
5001f3db423dSLydia Wang }
5002f3db423dSLydia Wang 
5003f3db423dSLydia Wang /* capture mixer elements */
5004f3db423dSLydia Wang static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
5005f3db423dSLydia Wang 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
5006f3db423dSLydia Wang 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
5007f3db423dSLydia Wang 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5008f3db423dSLydia Wang 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5009f3db423dSLydia Wang 	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5010f3db423dSLydia Wang 	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5011f3db423dSLydia Wang 			 HDA_INPUT),
5012f3db423dSLydia Wang 	{
5013f3db423dSLydia Wang 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5014f3db423dSLydia Wang 		.name = "Input Source",
5015f3db423dSLydia Wang 		.count = 1,
5016f3db423dSLydia Wang 		.info = via_mux_enum_info,
5017f3db423dSLydia Wang 		.get = via_mux_enum_get,
5018f3db423dSLydia Wang 		.put = via_mux_enum_put,
5019f3db423dSLydia Wang 	},
5020f3db423dSLydia Wang 	{ } /* end */
5021f3db423dSLydia Wang };
5022f3db423dSLydia Wang 
5023f3db423dSLydia Wang static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5024f3db423dSLydia Wang 	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5025f3db423dSLydia Wang 	{
5026f3db423dSLydia Wang 	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5027f3db423dSLydia Wang 	 .name = "Digital Mic Capture Switch",
5028f3db423dSLydia Wang 	 .count = 1,
5029f3db423dSLydia Wang 	 .info = vt1716s_dmic_info,
5030f3db423dSLydia Wang 	 .get = vt1716s_dmic_get,
5031f3db423dSLydia Wang 	 .put = vt1716s_dmic_put,
5032f3db423dSLydia Wang 	 },
5033f3db423dSLydia Wang 	{}			/* end */
5034f3db423dSLydia Wang };
5035f3db423dSLydia Wang 
5036f3db423dSLydia Wang 
5037f3db423dSLydia Wang /* mono-out mixer elements */
5038f3db423dSLydia Wang static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5039f3db423dSLydia Wang 	HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5040f3db423dSLydia Wang 	{ } /* end */
5041f3db423dSLydia Wang };
5042f3db423dSLydia Wang 
5043f3db423dSLydia Wang static struct hda_verb vt1716S_volume_init_verbs[] = {
5044f3db423dSLydia Wang 	/*
5045f3db423dSLydia Wang 	 * Unmute ADC0-1 and set the default input to mic-in
5046f3db423dSLydia Wang 	 */
5047f3db423dSLydia Wang 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5048f3db423dSLydia Wang 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5049f3db423dSLydia Wang 
5050f3db423dSLydia Wang 
5051f3db423dSLydia Wang 	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5052f3db423dSLydia Wang 	 * mixer widget
5053f3db423dSLydia Wang 	 */
5054f3db423dSLydia Wang 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5055f3db423dSLydia Wang 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5056f3db423dSLydia Wang 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5057f3db423dSLydia Wang 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5058f3db423dSLydia Wang 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5059f3db423dSLydia Wang 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5060f3db423dSLydia Wang 
5061f3db423dSLydia Wang 	/* MUX Indices: Stereo Mixer = 5 */
5062f3db423dSLydia Wang 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5063f3db423dSLydia Wang 
5064f3db423dSLydia Wang 	/* Setup default input of PW4 to MW0 */
5065f3db423dSLydia Wang 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5066f3db423dSLydia Wang 
5067f3db423dSLydia Wang 	/* Setup default input of SW1 as MW0 */
5068f3db423dSLydia Wang 	{0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5069f3db423dSLydia Wang 
5070f3db423dSLydia Wang 	/* Setup default input of SW4 as AOW0 */
5071f3db423dSLydia Wang 	{0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5072f3db423dSLydia Wang 
5073f3db423dSLydia Wang 	/* PW9 PW10 Output enable */
5074f3db423dSLydia Wang 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5075f3db423dSLydia Wang 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5076f3db423dSLydia Wang 
5077f3db423dSLydia Wang 	/* Unmute SW1, PW12 */
5078f3db423dSLydia Wang 	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5079f3db423dSLydia Wang 	{0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5080f3db423dSLydia Wang 	/* PW12 Output enable */
5081f3db423dSLydia Wang 	{0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5082f3db423dSLydia Wang 	/* Enable Boost Volume backdoor */
5083f3db423dSLydia Wang 	{0x1, 0xf8a, 0x80},
5084f3db423dSLydia Wang 	/* don't bybass mixer */
5085f3db423dSLydia Wang 	{0x1, 0xf88, 0xc0},
5086f3db423dSLydia Wang 	/* Enable mono output */
5087f3db423dSLydia Wang 	{0x1, 0xf90, 0x08},
5088f3db423dSLydia Wang 	{ }
5089f3db423dSLydia Wang };
5090f3db423dSLydia Wang 
5091f3db423dSLydia Wang 
5092f3db423dSLydia Wang static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5093f3db423dSLydia Wang 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5094f3db423dSLydia Wang 	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5095f3db423dSLydia Wang 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5096f3db423dSLydia Wang 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5097f3db423dSLydia Wang 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5098f3db423dSLydia Wang 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5099f3db423dSLydia Wang 	 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5100f3db423dSLydia Wang 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5101f3db423dSLydia Wang 	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5102f3db423dSLydia Wang 	{ }
5103f3db423dSLydia Wang };
5104f3db423dSLydia Wang 
5105f3db423dSLydia Wang static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5106f3db423dSLydia Wang 	.substreams = 2,
5107f3db423dSLydia Wang 	.channels_min = 2,
5108f3db423dSLydia Wang 	.channels_max = 6,
5109f3db423dSLydia Wang 	.nid = 0x10, /* NID to query formats and rates */
5110f3db423dSLydia Wang 	.ops = {
5111f3db423dSLydia Wang 		.open = via_playback_pcm_open,
5112f3db423dSLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
5113f3db423dSLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
5114f3db423dSLydia Wang 		.close = via_pcm_open_close,
5115f3db423dSLydia Wang 	},
5116f3db423dSLydia Wang };
5117f3db423dSLydia Wang 
5118f3db423dSLydia Wang static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5119f3db423dSLydia Wang 	.substreams = 2,
5120f3db423dSLydia Wang 	.channels_min = 2,
5121f3db423dSLydia Wang 	.channels_max = 2,
5122f3db423dSLydia Wang 	.nid = 0x13, /* NID to query formats and rates */
5123f3db423dSLydia Wang 	.ops = {
5124f3db423dSLydia Wang 		.open = via_pcm_open_close,
5125f3db423dSLydia Wang 		.prepare = via_capture_pcm_prepare,
5126f3db423dSLydia Wang 		.cleanup = via_capture_pcm_cleanup,
5127f3db423dSLydia Wang 		.close = via_pcm_open_close,
5128f3db423dSLydia Wang 	},
5129f3db423dSLydia Wang };
5130f3db423dSLydia Wang 
5131f3db423dSLydia Wang static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5132f3db423dSLydia Wang 	.substreams = 2,
5133f3db423dSLydia Wang 	.channels_min = 2,
5134f3db423dSLydia Wang 	.channels_max = 2,
5135f3db423dSLydia Wang 	/* NID is set in via_build_pcms */
5136f3db423dSLydia Wang 	.ops = {
5137f3db423dSLydia Wang 		.open = via_dig_playback_pcm_open,
5138f3db423dSLydia Wang 		.close = via_dig_playback_pcm_close,
5139f3db423dSLydia Wang 		.prepare = via_dig_playback_pcm_prepare,
5140f3db423dSLydia Wang 		.cleanup = via_dig_playback_pcm_cleanup
5141f3db423dSLydia Wang 	},
5142f3db423dSLydia Wang };
5143f3db423dSLydia Wang 
5144f3db423dSLydia Wang /* fill in the dac_nids table from the parsed pin configuration */
5145f3db423dSLydia Wang static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5146f3db423dSLydia Wang 				      const struct auto_pin_cfg *cfg)
5147f3db423dSLydia Wang {	int i;
5148f3db423dSLydia Wang 	hda_nid_t nid;
5149f3db423dSLydia Wang 
5150f3db423dSLydia Wang 	spec->multiout.num_dacs = cfg->line_outs;
5151f3db423dSLydia Wang 
5152f3db423dSLydia Wang 	spec->multiout.dac_nids = spec->private_dac_nids;
5153f3db423dSLydia Wang 
5154f3db423dSLydia Wang 	for (i = 0; i < 3; i++) {
5155f3db423dSLydia Wang 		nid = cfg->line_out_pins[i];
5156f3db423dSLydia Wang 		if (nid) {
5157f3db423dSLydia Wang 			/* config dac list */
5158f3db423dSLydia Wang 			switch (i) {
5159f3db423dSLydia Wang 			case AUTO_SEQ_FRONT:
5160f3db423dSLydia Wang 				spec->multiout.dac_nids[i] = 0x10;
5161f3db423dSLydia Wang 				break;
5162f3db423dSLydia Wang 			case AUTO_SEQ_CENLFE:
5163f3db423dSLydia Wang 				spec->multiout.dac_nids[i] = 0x25;
5164f3db423dSLydia Wang 				break;
5165f3db423dSLydia Wang 			case AUTO_SEQ_SURROUND:
5166f3db423dSLydia Wang 				spec->multiout.dac_nids[i] = 0x11;
5167f3db423dSLydia Wang 				break;
5168f3db423dSLydia Wang 			}
5169f3db423dSLydia Wang 		}
5170f3db423dSLydia Wang 	}
5171f3db423dSLydia Wang 
5172f3db423dSLydia Wang 	return 0;
5173f3db423dSLydia Wang }
5174f3db423dSLydia Wang 
5175f3db423dSLydia Wang /* add playback controls from the parsed DAC table */
5176f3db423dSLydia Wang static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5177f3db423dSLydia Wang 					      const struct auto_pin_cfg *cfg)
5178f3db423dSLydia Wang {
5179f3db423dSLydia Wang 	char name[32];
5180f3db423dSLydia Wang 	static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5181f3db423dSLydia Wang 	hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5182f3db423dSLydia Wang 	hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5183f3db423dSLydia Wang 	hda_nid_t nid, nid_vol, nid_mute;
5184f3db423dSLydia Wang 	int i, err;
5185f3db423dSLydia Wang 
5186f3db423dSLydia Wang 	for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5187f3db423dSLydia Wang 		nid = cfg->line_out_pins[i];
5188f3db423dSLydia Wang 
5189f3db423dSLydia Wang 		if (!nid)
5190f3db423dSLydia Wang 			continue;
5191f3db423dSLydia Wang 
5192f3db423dSLydia Wang 		nid_vol = nid_vols[i];
5193f3db423dSLydia Wang 		nid_mute = nid_mutes[i];
5194f3db423dSLydia Wang 
5195f3db423dSLydia Wang 		if (i == AUTO_SEQ_CENLFE) {
5196f3db423dSLydia Wang 			err = via_add_control(
5197f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_VOL,
5198f3db423dSLydia Wang 				"Center Playback Volume",
5199f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5200f3db423dSLydia Wang 			if (err < 0)
5201f3db423dSLydia Wang 				return err;
5202f3db423dSLydia Wang 			err = via_add_control(
5203f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_VOL,
5204f3db423dSLydia Wang 				"LFE Playback Volume",
5205f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5206f3db423dSLydia Wang 			if (err < 0)
5207f3db423dSLydia Wang 				return err;
5208f3db423dSLydia Wang 			err = via_add_control(
5209f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE,
5210f3db423dSLydia Wang 				"Center Playback Switch",
5211f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5212f3db423dSLydia Wang 						    HDA_OUTPUT));
5213f3db423dSLydia Wang 			if (err < 0)
5214f3db423dSLydia Wang 				return err;
5215f3db423dSLydia Wang 			err = via_add_control(
5216f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE,
5217f3db423dSLydia Wang 				"LFE Playback Switch",
5218f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5219f3db423dSLydia Wang 						    HDA_OUTPUT));
5220f3db423dSLydia Wang 			if (err < 0)
5221f3db423dSLydia Wang 				return err;
5222f3db423dSLydia Wang 		} else if (i == AUTO_SEQ_FRONT) {
5223f3db423dSLydia Wang 
5224f3db423dSLydia Wang 			err = via_add_control(
5225f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_VOL,
5226f3db423dSLydia Wang 				"Master Front Playback Volume",
5227f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5228f3db423dSLydia Wang 			if (err < 0)
5229f3db423dSLydia Wang 				return err;
5230f3db423dSLydia Wang 			err = via_add_control(
5231f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE,
5232f3db423dSLydia Wang 				"Master Front Playback Switch",
5233f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5234f3db423dSLydia Wang 			if (err < 0)
5235f3db423dSLydia Wang 				return err;
5236f3db423dSLydia Wang 
5237f3db423dSLydia Wang 			sprintf(name, "%s Playback Volume", chname[i]);
5238f3db423dSLydia Wang 			err = via_add_control(
5239f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_VOL, name,
5240f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5241f3db423dSLydia Wang 			if (err < 0)
5242f3db423dSLydia Wang 				return err;
5243f3db423dSLydia Wang 			sprintf(name, "%s Playback Switch", chname[i]);
5244f3db423dSLydia Wang 			err = via_add_control(
5245f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE, name,
5246f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5247f3db423dSLydia Wang 						    HDA_OUTPUT));
5248f3db423dSLydia Wang 			if (err < 0)
5249f3db423dSLydia Wang 				return err;
5250f3db423dSLydia Wang 		} else {
5251f3db423dSLydia Wang 			sprintf(name, "%s Playback Volume", chname[i]);
5252f3db423dSLydia Wang 			err = via_add_control(
5253f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_VOL, name,
5254f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5255f3db423dSLydia Wang 			if (err < 0)
5256f3db423dSLydia Wang 				return err;
5257f3db423dSLydia Wang 			sprintf(name, "%s Playback Switch", chname[i]);
5258f3db423dSLydia Wang 			err = via_add_control(
5259f3db423dSLydia Wang 				spec, VIA_CTL_WIDGET_MUTE, name,
5260f3db423dSLydia Wang 				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5261f3db423dSLydia Wang 						    HDA_OUTPUT));
5262f3db423dSLydia Wang 			if (err < 0)
5263f3db423dSLydia Wang 				return err;
5264f3db423dSLydia Wang 		}
5265f3db423dSLydia Wang 	}
5266f3db423dSLydia Wang 	return 0;
5267f3db423dSLydia Wang }
5268f3db423dSLydia Wang 
5269f3db423dSLydia Wang static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5270f3db423dSLydia Wang {
5271f3db423dSLydia Wang 	int err;
5272f3db423dSLydia Wang 
5273f3db423dSLydia Wang 	if (!pin)
5274f3db423dSLydia Wang 		return 0;
5275f3db423dSLydia Wang 
5276f3db423dSLydia Wang 	spec->multiout.hp_nid = 0x25; /* AOW3 */
5277f3db423dSLydia Wang 	spec->hp_independent_mode_index = 1;
5278f3db423dSLydia Wang 
5279f3db423dSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5280f3db423dSLydia Wang 			      "Headphone Playback Volume",
5281f3db423dSLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5282f3db423dSLydia Wang 	if (err < 0)
5283f3db423dSLydia Wang 		return err;
5284f3db423dSLydia Wang 
5285f3db423dSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5286f3db423dSLydia Wang 			      "Headphone Playback Switch",
5287f3db423dSLydia Wang 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5288f3db423dSLydia Wang 	if (err < 0)
5289f3db423dSLydia Wang 		return err;
5290f3db423dSLydia Wang 
5291f3db423dSLydia Wang 	create_hp_imux(spec);
5292f3db423dSLydia Wang 	return 0;
5293f3db423dSLydia Wang }
5294f3db423dSLydia Wang 
5295f3db423dSLydia Wang /* create playback/capture controls for input pins */
5296f3db423dSLydia Wang static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5297f3db423dSLydia Wang 						const struct auto_pin_cfg *cfg)
5298f3db423dSLydia Wang {
5299f3db423dSLydia Wang 	static char *labels[] = {
5300f3db423dSLydia Wang 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5301f3db423dSLydia Wang 	};
5302f3db423dSLydia Wang 	struct hda_input_mux *imux = &spec->private_imux[0];
5303f3db423dSLydia Wang 	int i, err, idx = 0;
5304f3db423dSLydia Wang 
5305f3db423dSLydia Wang 	/* for internal loopback recording select */
5306f3db423dSLydia Wang 	imux->items[imux->num_items].label = "Stereo Mixer";
5307f3db423dSLydia Wang 	imux->items[imux->num_items].index = 5;
5308f3db423dSLydia Wang 	imux->num_items++;
5309f3db423dSLydia Wang 
5310f3db423dSLydia Wang 	for (i = 0; i < AUTO_PIN_LAST; i++) {
5311f3db423dSLydia Wang 		if (!cfg->input_pins[i])
5312f3db423dSLydia Wang 			continue;
5313f3db423dSLydia Wang 
5314f3db423dSLydia Wang 		switch (cfg->input_pins[i]) {
5315f3db423dSLydia Wang 		case 0x1a: /* Mic */
5316f3db423dSLydia Wang 			idx = 2;
5317f3db423dSLydia Wang 			break;
5318f3db423dSLydia Wang 
5319f3db423dSLydia Wang 		case 0x1b: /* Line In */
5320f3db423dSLydia Wang 			idx = 3;
5321f3db423dSLydia Wang 			break;
5322f3db423dSLydia Wang 
5323f3db423dSLydia Wang 		case 0x1e: /* Front Mic */
5324f3db423dSLydia Wang 			idx = 4;
5325f3db423dSLydia Wang 			break;
5326f3db423dSLydia Wang 
5327f3db423dSLydia Wang 		case 0x1f: /* CD */
5328f3db423dSLydia Wang 			idx = 1;
5329f3db423dSLydia Wang 			break;
5330f3db423dSLydia Wang 		}
5331f3db423dSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x16);
5332f3db423dSLydia Wang 		if (err < 0)
5333f3db423dSLydia Wang 			return err;
5334f3db423dSLydia Wang 		imux->items[imux->num_items].label = labels[i];
5335f3db423dSLydia Wang 		imux->items[imux->num_items].index = idx-1;
5336f3db423dSLydia Wang 		imux->num_items++;
5337f3db423dSLydia Wang 	}
5338f3db423dSLydia Wang 	return 0;
5339f3db423dSLydia Wang }
5340f3db423dSLydia Wang 
5341f3db423dSLydia Wang static int vt1716S_parse_auto_config(struct hda_codec *codec)
5342f3db423dSLydia Wang {
5343f3db423dSLydia Wang 	struct via_spec *spec = codec->spec;
5344f3db423dSLydia Wang 	int err;
5345f3db423dSLydia Wang 
5346f3db423dSLydia Wang 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5347f3db423dSLydia Wang 	if (err < 0)
5348f3db423dSLydia Wang 		return err;
5349f3db423dSLydia Wang 	err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5350f3db423dSLydia Wang 	if (err < 0)
5351f3db423dSLydia Wang 		return err;
5352f3db423dSLydia Wang 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5353f3db423dSLydia Wang 		return 0; /* can't find valid BIOS pin config */
5354f3db423dSLydia Wang 
5355f3db423dSLydia Wang 	err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5356f3db423dSLydia Wang 	if (err < 0)
5357f3db423dSLydia Wang 		return err;
5358f3db423dSLydia Wang 	err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5359f3db423dSLydia Wang 	if (err < 0)
5360f3db423dSLydia Wang 		return err;
5361f3db423dSLydia Wang 	err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5362f3db423dSLydia Wang 	if (err < 0)
5363f3db423dSLydia Wang 		return err;
5364f3db423dSLydia Wang 
5365f3db423dSLydia Wang 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5366f3db423dSLydia Wang 
5367f3db423dSLydia Wang 	fill_dig_outs(codec);
5368f3db423dSLydia Wang 
5369f3db423dSLydia Wang 	if (spec->kctls.list)
5370f3db423dSLydia Wang 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
5371f3db423dSLydia Wang 
5372f3db423dSLydia Wang 	spec->input_mux = &spec->private_imux[0];
5373f3db423dSLydia Wang 
5374f3db423dSLydia Wang 	if (spec->hp_mux)
5375f3db423dSLydia Wang 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
5376f3db423dSLydia Wang 
5377f3db423dSLydia Wang 	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5378f3db423dSLydia Wang 
5379f3db423dSLydia Wang 	return 1;
5380f3db423dSLydia Wang }
5381f3db423dSLydia Wang 
5382f3db423dSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
5383f3db423dSLydia Wang static struct hda_amp_list vt1716S_loopbacks[] = {
5384f3db423dSLydia Wang 	{ 0x16, HDA_INPUT, 1 },
5385f3db423dSLydia Wang 	{ 0x16, HDA_INPUT, 2 },
5386f3db423dSLydia Wang 	{ 0x16, HDA_INPUT, 3 },
5387f3db423dSLydia Wang 	{ 0x16, HDA_INPUT, 4 },
5388f3db423dSLydia Wang 	{ } /* end */
5389f3db423dSLydia Wang };
5390f3db423dSLydia Wang #endif
5391f3db423dSLydia Wang 
5392f3db423dSLydia Wang static int patch_vt1716S(struct hda_codec *codec)
5393f3db423dSLydia Wang {
5394f3db423dSLydia Wang 	struct via_spec *spec;
5395f3db423dSLydia Wang 	int err;
5396f3db423dSLydia Wang 
5397f3db423dSLydia Wang 	/* create a codec specific record */
5398f3db423dSLydia Wang 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5399f3db423dSLydia Wang 	if (spec == NULL)
5400f3db423dSLydia Wang 		return -ENOMEM;
5401f3db423dSLydia Wang 
5402f3db423dSLydia Wang 	codec->spec = spec;
5403f3db423dSLydia Wang 
5404f3db423dSLydia Wang 	/* automatic parse from the BIOS config */
5405f3db423dSLydia Wang 	err = vt1716S_parse_auto_config(codec);
5406f3db423dSLydia Wang 	if (err < 0) {
5407f3db423dSLydia Wang 		via_free(codec);
5408f3db423dSLydia Wang 		return err;
5409f3db423dSLydia Wang 	} else if (!err) {
5410f3db423dSLydia Wang 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
5411f3db423dSLydia Wang 		       "from BIOS.  Using genenic mode...\n");
5412f3db423dSLydia Wang 	}
5413f3db423dSLydia Wang 
5414f3db423dSLydia Wang 	spec->init_verbs[spec->num_iverbs++]  = vt1716S_volume_init_verbs;
5415f3db423dSLydia Wang 	spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5416f3db423dSLydia Wang 
5417f3db423dSLydia Wang 	spec->stream_name_analog = "VT1716S Analog";
5418f3db423dSLydia Wang 	spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5419f3db423dSLydia Wang 	spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5420f3db423dSLydia Wang 
5421f3db423dSLydia Wang 	spec->stream_name_digital = "VT1716S Digital";
5422f3db423dSLydia Wang 	spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5423f3db423dSLydia Wang 
5424f3db423dSLydia Wang 	if (!spec->adc_nids && spec->input_mux) {
5425f3db423dSLydia Wang 		spec->adc_nids = vt1716S_adc_nids;
5426f3db423dSLydia Wang 		spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5427f3db423dSLydia Wang 		get_mux_nids(codec);
5428f3db423dSLydia Wang 		override_mic_boost(codec, 0x1a, 0, 3, 40);
5429f3db423dSLydia Wang 		override_mic_boost(codec, 0x1e, 0, 3, 40);
5430f3db423dSLydia Wang 		spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5431f3db423dSLydia Wang 		spec->num_mixers++;
5432f3db423dSLydia Wang 	}
5433f3db423dSLydia Wang 
5434f3db423dSLydia Wang 	spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5435f3db423dSLydia Wang 	spec->num_mixers++;
5436f3db423dSLydia Wang 
5437f3db423dSLydia Wang 	spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5438f3db423dSLydia Wang 
5439f3db423dSLydia Wang 	codec->patch_ops = via_patch_ops;
5440f3db423dSLydia Wang 
5441f3db423dSLydia Wang 	codec->patch_ops.init = via_auto_init;
54420f48327eSStephen Rothwell 	codec->patch_ops.unsol_event = via_unsol_event;
5443f3db423dSLydia Wang 
5444f3db423dSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
5445f3db423dSLydia Wang 	spec->loopback.amplist = vt1716S_loopbacks;
5446f3db423dSLydia Wang #endif
5447f3db423dSLydia Wang 
5448f3db423dSLydia Wang 	return 0;
5449f3db423dSLydia Wang }
545025eaba2fSLydia Wang 
545125eaba2fSLydia Wang /* for vt2002P */
545225eaba2fSLydia Wang 
545325eaba2fSLydia Wang /* capture mixer elements */
545425eaba2fSLydia Wang static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
545525eaba2fSLydia Wang 	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
545625eaba2fSLydia Wang 	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
545725eaba2fSLydia Wang 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
545825eaba2fSLydia Wang 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
545925eaba2fSLydia Wang 	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
546025eaba2fSLydia Wang 	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
546125eaba2fSLydia Wang 			 HDA_INPUT),
546225eaba2fSLydia Wang 	{
546325eaba2fSLydia Wang 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
546425eaba2fSLydia Wang 		/* The multiple "Capture Source" controls confuse alsamixer
546525eaba2fSLydia Wang 		 * So call somewhat different..
546625eaba2fSLydia Wang 		 */
546725eaba2fSLydia Wang 		/* .name = "Capture Source", */
546825eaba2fSLydia Wang 		.name = "Input Source",
546925eaba2fSLydia Wang 		.count = 2,
547025eaba2fSLydia Wang 		.info = via_mux_enum_info,
547125eaba2fSLydia Wang 		.get = via_mux_enum_get,
547225eaba2fSLydia Wang 		.put = via_mux_enum_put,
547325eaba2fSLydia Wang 	},
547425eaba2fSLydia Wang 	{ } /* end */
547525eaba2fSLydia Wang };
547625eaba2fSLydia Wang 
547725eaba2fSLydia Wang static struct hda_verb vt2002P_volume_init_verbs[] = {
547825eaba2fSLydia Wang 	/*
547925eaba2fSLydia Wang 	 * Unmute ADC0-1 and set the default input to mic-in
548025eaba2fSLydia Wang 	 */
548125eaba2fSLydia Wang 	{0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
548225eaba2fSLydia Wang 	{0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
548325eaba2fSLydia Wang 
548425eaba2fSLydia Wang 
548525eaba2fSLydia Wang 	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
548625eaba2fSLydia Wang 	 * mixer widget
548725eaba2fSLydia Wang 	 */
548825eaba2fSLydia Wang 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
548925eaba2fSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
549025eaba2fSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
549125eaba2fSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
549225eaba2fSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
549325eaba2fSLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
549425eaba2fSLydia Wang 
549525eaba2fSLydia Wang 	/* MUX Indices: Mic = 0 */
549625eaba2fSLydia Wang 	{0x1e, AC_VERB_SET_CONNECT_SEL, 0},
549725eaba2fSLydia Wang 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0},
549825eaba2fSLydia Wang 
549925eaba2fSLydia Wang 	/* PW9 Output enable */
550025eaba2fSLydia Wang 	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
550125eaba2fSLydia Wang 
550225eaba2fSLydia Wang 	/* Enable Boost Volume backdoor */
550325eaba2fSLydia Wang 	{0x1, 0xfb9, 0x24},
550425eaba2fSLydia Wang 
550525eaba2fSLydia Wang 	/* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
550625eaba2fSLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
550725eaba2fSLydia Wang 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
550825eaba2fSLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
550925eaba2fSLydia Wang 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
551025eaba2fSLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
551125eaba2fSLydia Wang 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
551225eaba2fSLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
551325eaba2fSLydia Wang 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
551425eaba2fSLydia Wang 
551525eaba2fSLydia Wang 	/* set MUX0/1/4/8 = 0 (AOW0) */
551625eaba2fSLydia Wang 	{0x34, AC_VERB_SET_CONNECT_SEL, 0},
551725eaba2fSLydia Wang 	{0x35, AC_VERB_SET_CONNECT_SEL, 0},
551825eaba2fSLydia Wang 	{0x37, AC_VERB_SET_CONNECT_SEL, 0},
551925eaba2fSLydia Wang 	{0x3b, AC_VERB_SET_CONNECT_SEL, 0},
552025eaba2fSLydia Wang 
552125eaba2fSLydia Wang 	/* set PW0 index=0 (MW0) */
552225eaba2fSLydia Wang 	{0x24, AC_VERB_SET_CONNECT_SEL, 0},
552325eaba2fSLydia Wang 
552425eaba2fSLydia Wang 	/* Enable AOW0 to MW9 */
552525eaba2fSLydia Wang 	{0x1, 0xfb8, 0x88},
552625eaba2fSLydia Wang 	{ }
552725eaba2fSLydia Wang };
552825eaba2fSLydia Wang 
552925eaba2fSLydia Wang 
553025eaba2fSLydia Wang static struct hda_verb vt2002P_uniwill_init_verbs[] = {
553125eaba2fSLydia Wang 	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
553225eaba2fSLydia Wang 	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
553325eaba2fSLydia Wang 	{0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
553425eaba2fSLydia Wang 	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
553525eaba2fSLydia Wang 	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
553625eaba2fSLydia Wang 	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
553725eaba2fSLydia Wang 	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
553825eaba2fSLydia Wang 	{ }
553925eaba2fSLydia Wang };
554025eaba2fSLydia Wang 
554125eaba2fSLydia Wang static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
554225eaba2fSLydia Wang 	.substreams = 2,
554325eaba2fSLydia Wang 	.channels_min = 2,
554425eaba2fSLydia Wang 	.channels_max = 2,
554525eaba2fSLydia Wang 	.nid = 0x8, /* NID to query formats and rates */
554625eaba2fSLydia Wang 	.ops = {
554725eaba2fSLydia Wang 		.open = via_playback_pcm_open,
554825eaba2fSLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
554925eaba2fSLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
555025eaba2fSLydia Wang 		.close = via_pcm_open_close,
555125eaba2fSLydia Wang 	},
555225eaba2fSLydia Wang };
555325eaba2fSLydia Wang 
555425eaba2fSLydia Wang static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
555525eaba2fSLydia Wang 	.substreams = 2,
555625eaba2fSLydia Wang 	.channels_min = 2,
555725eaba2fSLydia Wang 	.channels_max = 2,
555825eaba2fSLydia Wang 	.nid = 0x10, /* NID to query formats and rates */
555925eaba2fSLydia Wang 	.ops = {
556025eaba2fSLydia Wang 		.open = via_pcm_open_close,
556125eaba2fSLydia Wang 		.prepare = via_capture_pcm_prepare,
556225eaba2fSLydia Wang 		.cleanup = via_capture_pcm_cleanup,
556325eaba2fSLydia Wang 		.close = via_pcm_open_close,
556425eaba2fSLydia Wang 	},
556525eaba2fSLydia Wang };
556625eaba2fSLydia Wang 
556725eaba2fSLydia Wang static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
556825eaba2fSLydia Wang 	.substreams = 1,
556925eaba2fSLydia Wang 	.channels_min = 2,
557025eaba2fSLydia Wang 	.channels_max = 2,
557125eaba2fSLydia Wang 	/* NID is set in via_build_pcms */
557225eaba2fSLydia Wang 	.ops = {
557325eaba2fSLydia Wang 		.open = via_dig_playback_pcm_open,
557425eaba2fSLydia Wang 		.close = via_dig_playback_pcm_close,
557525eaba2fSLydia Wang 		.prepare = via_dig_playback_pcm_prepare,
557625eaba2fSLydia Wang 		.cleanup = via_dig_playback_pcm_cleanup
557725eaba2fSLydia Wang 	},
557825eaba2fSLydia Wang };
557925eaba2fSLydia Wang 
558025eaba2fSLydia Wang /* fill in the dac_nids table from the parsed pin configuration */
558125eaba2fSLydia Wang static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
558225eaba2fSLydia Wang 				      const struct auto_pin_cfg *cfg)
558325eaba2fSLydia Wang {
558425eaba2fSLydia Wang 	spec->multiout.num_dacs = 1;
558525eaba2fSLydia Wang 	spec->multiout.dac_nids = spec->private_dac_nids;
558625eaba2fSLydia Wang 	if (cfg->line_out_pins[0])
558725eaba2fSLydia Wang 		spec->multiout.dac_nids[0] = 0x8;
558825eaba2fSLydia Wang 	return 0;
558925eaba2fSLydia Wang }
559025eaba2fSLydia Wang 
559125eaba2fSLydia Wang /* add playback controls from the parsed DAC table */
559225eaba2fSLydia Wang static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
559325eaba2fSLydia Wang 					     const struct auto_pin_cfg *cfg)
559425eaba2fSLydia Wang {
559525eaba2fSLydia Wang 	int err;
559625eaba2fSLydia Wang 
559725eaba2fSLydia Wang 	if (!cfg->line_out_pins[0])
559825eaba2fSLydia Wang 		return -1;
559925eaba2fSLydia Wang 
560025eaba2fSLydia Wang 
560125eaba2fSLydia Wang 	/* Line-Out: PortE */
560225eaba2fSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
560325eaba2fSLydia Wang 			      "Master Front Playback Volume",
560425eaba2fSLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
560525eaba2fSLydia Wang 	if (err < 0)
560625eaba2fSLydia Wang 		return err;
560725eaba2fSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
560825eaba2fSLydia Wang 			      "Master Front Playback Switch",
560925eaba2fSLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
561025eaba2fSLydia Wang 	if (err < 0)
561125eaba2fSLydia Wang 		return err;
561225eaba2fSLydia Wang 
561325eaba2fSLydia Wang 	return 0;
561425eaba2fSLydia Wang }
561525eaba2fSLydia Wang 
561625eaba2fSLydia Wang static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
561725eaba2fSLydia Wang {
561825eaba2fSLydia Wang 	int err;
561925eaba2fSLydia Wang 
562025eaba2fSLydia Wang 	if (!pin)
562125eaba2fSLydia Wang 		return 0;
562225eaba2fSLydia Wang 
562325eaba2fSLydia Wang 	spec->multiout.hp_nid = 0x9;
562425eaba2fSLydia Wang 	spec->hp_independent_mode_index = 1;
562525eaba2fSLydia Wang 
562625eaba2fSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
562725eaba2fSLydia Wang 			      "Headphone Playback Volume",
562825eaba2fSLydia Wang 			      HDA_COMPOSE_AMP_VAL(
562925eaba2fSLydia Wang 				      spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
563025eaba2fSLydia Wang 	if (err < 0)
563125eaba2fSLydia Wang 		return err;
563225eaba2fSLydia Wang 
563325eaba2fSLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
563425eaba2fSLydia Wang 			      "Headphone Playback Switch",
563525eaba2fSLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
563625eaba2fSLydia Wang 	if (err < 0)
563725eaba2fSLydia Wang 		return err;
563825eaba2fSLydia Wang 
563925eaba2fSLydia Wang 	create_hp_imux(spec);
564025eaba2fSLydia Wang 	return 0;
564125eaba2fSLydia Wang }
564225eaba2fSLydia Wang 
564325eaba2fSLydia Wang /* create playback/capture controls for input pins */
564425eaba2fSLydia Wang static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
564525eaba2fSLydia Wang 						const struct auto_pin_cfg *cfg)
564625eaba2fSLydia Wang {
564725eaba2fSLydia Wang 	static char *labels[] = {
564825eaba2fSLydia Wang 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
564925eaba2fSLydia Wang 	};
565025eaba2fSLydia Wang 	struct hda_input_mux *imux = &spec->private_imux[0];
565125eaba2fSLydia Wang 	int i, err, idx = 0;
565225eaba2fSLydia Wang 
565325eaba2fSLydia Wang 	for (i = 0; i < AUTO_PIN_LAST; i++) {
565425eaba2fSLydia Wang 		if (!cfg->input_pins[i])
565525eaba2fSLydia Wang 			continue;
565625eaba2fSLydia Wang 
565725eaba2fSLydia Wang 		switch (cfg->input_pins[i]) {
565825eaba2fSLydia Wang 		case 0x2b: /* Mic */
565925eaba2fSLydia Wang 			idx = 0;
566025eaba2fSLydia Wang 			break;
566125eaba2fSLydia Wang 
566225eaba2fSLydia Wang 		case 0x2a: /* Line In */
566325eaba2fSLydia Wang 			idx = 1;
566425eaba2fSLydia Wang 			break;
566525eaba2fSLydia Wang 
566625eaba2fSLydia Wang 		case 0x29: /* Front Mic */
566725eaba2fSLydia Wang 			idx = 2;
566825eaba2fSLydia Wang 			break;
566925eaba2fSLydia Wang 		}
567025eaba2fSLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x21);
567125eaba2fSLydia Wang 		if (err < 0)
567225eaba2fSLydia Wang 			return err;
567325eaba2fSLydia Wang 		imux->items[imux->num_items].label = labels[i];
567425eaba2fSLydia Wang 		imux->items[imux->num_items].index = idx;
567525eaba2fSLydia Wang 		imux->num_items++;
567625eaba2fSLydia Wang 	}
567725eaba2fSLydia Wang 
567825eaba2fSLydia Wang 	/* build volume/mute control of loopback */
567925eaba2fSLydia Wang 	err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
568025eaba2fSLydia Wang 	if (err < 0)
568125eaba2fSLydia Wang 		return err;
568225eaba2fSLydia Wang 
568325eaba2fSLydia Wang 	/* for internal loopback recording select */
568425eaba2fSLydia Wang 	imux->items[imux->num_items].label = "Stereo Mixer";
568525eaba2fSLydia Wang 	imux->items[imux->num_items].index = 3;
568625eaba2fSLydia Wang 	imux->num_items++;
568725eaba2fSLydia Wang 
568825eaba2fSLydia Wang 	/* for digital mic select */
568925eaba2fSLydia Wang 	imux->items[imux->num_items].label = "Digital Mic";
569025eaba2fSLydia Wang 	imux->items[imux->num_items].index = 4;
569125eaba2fSLydia Wang 	imux->num_items++;
569225eaba2fSLydia Wang 
569325eaba2fSLydia Wang 	return 0;
569425eaba2fSLydia Wang }
569525eaba2fSLydia Wang 
569625eaba2fSLydia Wang static int vt2002P_parse_auto_config(struct hda_codec *codec)
569725eaba2fSLydia Wang {
569825eaba2fSLydia Wang 	struct via_spec *spec = codec->spec;
569925eaba2fSLydia Wang 	int err;
570025eaba2fSLydia Wang 
570125eaba2fSLydia Wang 
570225eaba2fSLydia Wang 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
570325eaba2fSLydia Wang 	if (err < 0)
570425eaba2fSLydia Wang 		return err;
570525eaba2fSLydia Wang 
570625eaba2fSLydia Wang 	err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
570725eaba2fSLydia Wang 	if (err < 0)
570825eaba2fSLydia Wang 		return err;
570925eaba2fSLydia Wang 
571025eaba2fSLydia Wang 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
571125eaba2fSLydia Wang 		return 0; /* can't find valid BIOS pin config */
571225eaba2fSLydia Wang 
571325eaba2fSLydia Wang 	err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
571425eaba2fSLydia Wang 	if (err < 0)
571525eaba2fSLydia Wang 		return err;
571625eaba2fSLydia Wang 	err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
571725eaba2fSLydia Wang 	if (err < 0)
571825eaba2fSLydia Wang 		return err;
571925eaba2fSLydia Wang 	err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
572025eaba2fSLydia Wang 	if (err < 0)
572125eaba2fSLydia Wang 		return err;
572225eaba2fSLydia Wang 
572325eaba2fSLydia Wang 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
572425eaba2fSLydia Wang 
572525eaba2fSLydia Wang 	fill_dig_outs(codec);
572625eaba2fSLydia Wang 
572725eaba2fSLydia Wang 	if (spec->kctls.list)
572825eaba2fSLydia Wang 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
572925eaba2fSLydia Wang 
573025eaba2fSLydia Wang 	spec->input_mux = &spec->private_imux[0];
573125eaba2fSLydia Wang 
573225eaba2fSLydia Wang 	if (spec->hp_mux)
573325eaba2fSLydia Wang 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
573425eaba2fSLydia Wang 
573525eaba2fSLydia Wang 	return 1;
573625eaba2fSLydia Wang }
573725eaba2fSLydia Wang 
573825eaba2fSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
573925eaba2fSLydia Wang static struct hda_amp_list vt2002P_loopbacks[] = {
574025eaba2fSLydia Wang 	{ 0x21, HDA_INPUT, 0 },
574125eaba2fSLydia Wang 	{ 0x21, HDA_INPUT, 1 },
574225eaba2fSLydia Wang 	{ 0x21, HDA_INPUT, 2 },
574325eaba2fSLydia Wang 	{ } /* end */
574425eaba2fSLydia Wang };
574525eaba2fSLydia Wang #endif
574625eaba2fSLydia Wang 
574725eaba2fSLydia Wang 
574825eaba2fSLydia Wang /* patch for vt2002P */
574925eaba2fSLydia Wang static int patch_vt2002P(struct hda_codec *codec)
575025eaba2fSLydia Wang {
575125eaba2fSLydia Wang 	struct via_spec *spec;
575225eaba2fSLydia Wang 	int err;
575325eaba2fSLydia Wang 
575425eaba2fSLydia Wang 	/* create a codec specific record */
575525eaba2fSLydia Wang 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
575625eaba2fSLydia Wang 	if (spec == NULL)
575725eaba2fSLydia Wang 		return -ENOMEM;
575825eaba2fSLydia Wang 
575925eaba2fSLydia Wang 	codec->spec = spec;
576025eaba2fSLydia Wang 
576125eaba2fSLydia Wang 	/* automatic parse from the BIOS config */
576225eaba2fSLydia Wang 	err = vt2002P_parse_auto_config(codec);
576325eaba2fSLydia Wang 	if (err < 0) {
576425eaba2fSLydia Wang 		via_free(codec);
576525eaba2fSLydia Wang 		return err;
576625eaba2fSLydia Wang 	} else if (!err) {
576725eaba2fSLydia Wang 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
576825eaba2fSLydia Wang 		       "from BIOS.  Using genenic mode...\n");
576925eaba2fSLydia Wang 	}
577025eaba2fSLydia Wang 
577125eaba2fSLydia Wang 	spec->init_verbs[spec->num_iverbs++]  = vt2002P_volume_init_verbs;
577225eaba2fSLydia Wang 	spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
577325eaba2fSLydia Wang 
577425eaba2fSLydia Wang 	spec->stream_name_analog = "VT2002P Analog";
577525eaba2fSLydia Wang 	spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
577625eaba2fSLydia Wang 	spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
577725eaba2fSLydia Wang 
577825eaba2fSLydia Wang 	spec->stream_name_digital = "VT2002P Digital";
577925eaba2fSLydia Wang 	spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
578025eaba2fSLydia Wang 
578125eaba2fSLydia Wang 	if (!spec->adc_nids && spec->input_mux) {
578225eaba2fSLydia Wang 		spec->adc_nids = vt2002P_adc_nids;
578325eaba2fSLydia Wang 		spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
578425eaba2fSLydia Wang 		get_mux_nids(codec);
578525eaba2fSLydia Wang 		override_mic_boost(codec, 0x2b, 0, 3, 40);
578625eaba2fSLydia Wang 		override_mic_boost(codec, 0x29, 0, 3, 40);
578725eaba2fSLydia Wang 		spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
578825eaba2fSLydia Wang 		spec->num_mixers++;
578925eaba2fSLydia Wang 	}
579025eaba2fSLydia Wang 
579125eaba2fSLydia Wang 	codec->patch_ops = via_patch_ops;
579225eaba2fSLydia Wang 
579325eaba2fSLydia Wang 	codec->patch_ops.init = via_auto_init;
57940f48327eSStephen Rothwell 	codec->patch_ops.unsol_event = via_unsol_event;
579525eaba2fSLydia Wang 
579625eaba2fSLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
579725eaba2fSLydia Wang 	spec->loopback.amplist = vt2002P_loopbacks;
579825eaba2fSLydia Wang #endif
579925eaba2fSLydia Wang 
580025eaba2fSLydia Wang 	return 0;
580125eaba2fSLydia Wang }
5802ab6734e7SLydia Wang 
5803ab6734e7SLydia Wang /* for vt1812 */
5804ab6734e7SLydia Wang 
5805ab6734e7SLydia Wang /* capture mixer elements */
5806ab6734e7SLydia Wang static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5807ab6734e7SLydia Wang 	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5808ab6734e7SLydia Wang 	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5809ab6734e7SLydia Wang 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5810ab6734e7SLydia Wang 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5811ab6734e7SLydia Wang 	HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5812ab6734e7SLydia Wang 	HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5813ab6734e7SLydia Wang 		       HDA_INPUT),
5814ab6734e7SLydia Wang 	{
5815ab6734e7SLydia Wang 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5816ab6734e7SLydia Wang 		/* The multiple "Capture Source" controls confuse alsamixer
5817ab6734e7SLydia Wang 		 * So call somewhat different..
5818ab6734e7SLydia Wang 		 */
5819ab6734e7SLydia Wang 		.name = "Input Source",
5820ab6734e7SLydia Wang 		.count = 2,
5821ab6734e7SLydia Wang 		.info = via_mux_enum_info,
5822ab6734e7SLydia Wang 		.get = via_mux_enum_get,
5823ab6734e7SLydia Wang 		.put = via_mux_enum_put,
5824ab6734e7SLydia Wang 	},
5825ab6734e7SLydia Wang 	{ } /* end */
5826ab6734e7SLydia Wang };
5827ab6734e7SLydia Wang 
5828ab6734e7SLydia Wang static struct hda_verb vt1812_volume_init_verbs[] = {
5829ab6734e7SLydia Wang 	/*
5830ab6734e7SLydia Wang 	 * Unmute ADC0-1 and set the default input to mic-in
5831ab6734e7SLydia Wang 	 */
5832ab6734e7SLydia Wang 	{0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5833ab6734e7SLydia Wang 	{0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5834ab6734e7SLydia Wang 
5835ab6734e7SLydia Wang 
5836ab6734e7SLydia Wang 	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5837ab6734e7SLydia Wang 	 * mixer widget
5838ab6734e7SLydia Wang 	 */
5839ab6734e7SLydia Wang 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5840ab6734e7SLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5841ab6734e7SLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5842ab6734e7SLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5843ab6734e7SLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5844ab6734e7SLydia Wang 	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5845ab6734e7SLydia Wang 
5846ab6734e7SLydia Wang 	/* MUX Indices: Mic = 0 */
5847ab6734e7SLydia Wang 	{0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5848ab6734e7SLydia Wang 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5849ab6734e7SLydia Wang 
5850ab6734e7SLydia Wang 	/* PW9 Output enable */
5851ab6734e7SLydia Wang 	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5852ab6734e7SLydia Wang 
5853ab6734e7SLydia Wang 	/* Enable Boost Volume backdoor */
5854ab6734e7SLydia Wang 	{0x1, 0xfb9, 0x24},
5855ab6734e7SLydia Wang 
5856ab6734e7SLydia Wang 	/* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5857ab6734e7SLydia Wang 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5858ab6734e7SLydia Wang 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5859ab6734e7SLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5860ab6734e7SLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5861ab6734e7SLydia Wang 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5862ab6734e7SLydia Wang 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5863ab6734e7SLydia Wang 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5864ab6734e7SLydia Wang 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5865ab6734e7SLydia Wang 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5866ab6734e7SLydia Wang 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5867ab6734e7SLydia Wang 
5868ab6734e7SLydia Wang 	/* set MUX0/1/4/13/15 = 0 (AOW0) */
5869ab6734e7SLydia Wang 	{0x34, AC_VERB_SET_CONNECT_SEL, 0},
5870ab6734e7SLydia Wang 	{0x35, AC_VERB_SET_CONNECT_SEL, 0},
5871ab6734e7SLydia Wang 	{0x38, AC_VERB_SET_CONNECT_SEL, 0},
5872ab6734e7SLydia Wang 	{0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5873ab6734e7SLydia Wang 	{0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5874ab6734e7SLydia Wang 
5875ab6734e7SLydia Wang 	/* Enable AOW0 to MW9 */
5876ab6734e7SLydia Wang 	{0x1, 0xfb8, 0xa8},
5877ab6734e7SLydia Wang 	{ }
5878ab6734e7SLydia Wang };
5879ab6734e7SLydia Wang 
5880ab6734e7SLydia Wang 
5881ab6734e7SLydia Wang static struct hda_verb vt1812_uniwill_init_verbs[] = {
5882ab6734e7SLydia Wang 	{0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5883ab6734e7SLydia Wang 	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5884ab6734e7SLydia Wang 	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5885ab6734e7SLydia Wang 	{0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5886ab6734e7SLydia Wang 	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5887ab6734e7SLydia Wang 	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5888ab6734e7SLydia Wang 	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5889ab6734e7SLydia Wang 	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5890ab6734e7SLydia Wang 	{ }
5891ab6734e7SLydia Wang };
5892ab6734e7SLydia Wang 
5893ab6734e7SLydia Wang static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5894ab6734e7SLydia Wang 	.substreams = 2,
5895ab6734e7SLydia Wang 	.channels_min = 2,
5896ab6734e7SLydia Wang 	.channels_max = 2,
5897ab6734e7SLydia Wang 	.nid = 0x8, /* NID to query formats and rates */
5898ab6734e7SLydia Wang 	.ops = {
5899ab6734e7SLydia Wang 		.open = via_playback_pcm_open,
5900ab6734e7SLydia Wang 		.prepare = via_playback_multi_pcm_prepare,
5901ab6734e7SLydia Wang 		.cleanup = via_playback_multi_pcm_cleanup,
5902ab6734e7SLydia Wang 		.close = via_pcm_open_close,
5903ab6734e7SLydia Wang 	},
5904ab6734e7SLydia Wang };
5905ab6734e7SLydia Wang 
5906ab6734e7SLydia Wang static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5907ab6734e7SLydia Wang 	.substreams = 2,
5908ab6734e7SLydia Wang 	.channels_min = 2,
5909ab6734e7SLydia Wang 	.channels_max = 2,
5910ab6734e7SLydia Wang 	.nid = 0x10, /* NID to query formats and rates */
5911ab6734e7SLydia Wang 	.ops = {
5912ab6734e7SLydia Wang 		.open = via_pcm_open_close,
5913ab6734e7SLydia Wang 		.prepare = via_capture_pcm_prepare,
5914ab6734e7SLydia Wang 		.cleanup = via_capture_pcm_cleanup,
5915ab6734e7SLydia Wang 		.close = via_pcm_open_close,
5916ab6734e7SLydia Wang 	},
5917ab6734e7SLydia Wang };
5918ab6734e7SLydia Wang 
5919ab6734e7SLydia Wang static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5920ab6734e7SLydia Wang 	.substreams = 1,
5921ab6734e7SLydia Wang 	.channels_min = 2,
5922ab6734e7SLydia Wang 	.channels_max = 2,
5923ab6734e7SLydia Wang 	/* NID is set in via_build_pcms */
5924ab6734e7SLydia Wang 	.ops = {
5925ab6734e7SLydia Wang 		.open = via_dig_playback_pcm_open,
5926ab6734e7SLydia Wang 		.close = via_dig_playback_pcm_close,
5927ab6734e7SLydia Wang 		.prepare = via_dig_playback_pcm_prepare,
5928ab6734e7SLydia Wang 		.cleanup = via_dig_playback_pcm_cleanup
5929ab6734e7SLydia Wang 	},
5930ab6734e7SLydia Wang };
5931ab6734e7SLydia Wang /* fill in the dac_nids table from the parsed pin configuration */
5932ab6734e7SLydia Wang static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5933ab6734e7SLydia Wang 				     const struct auto_pin_cfg *cfg)
5934ab6734e7SLydia Wang {
5935ab6734e7SLydia Wang 	spec->multiout.num_dacs = 1;
5936ab6734e7SLydia Wang 	spec->multiout.dac_nids = spec->private_dac_nids;
5937ab6734e7SLydia Wang 	if (cfg->line_out_pins[0])
5938ab6734e7SLydia Wang 		spec->multiout.dac_nids[0] = 0x8;
5939ab6734e7SLydia Wang 	return 0;
5940ab6734e7SLydia Wang }
5941ab6734e7SLydia Wang 
5942ab6734e7SLydia Wang 
5943ab6734e7SLydia Wang /* add playback controls from the parsed DAC table */
5944ab6734e7SLydia Wang static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5945ab6734e7SLydia Wang 					     const struct auto_pin_cfg *cfg)
5946ab6734e7SLydia Wang {
5947ab6734e7SLydia Wang 	int err;
5948ab6734e7SLydia Wang 
5949ab6734e7SLydia Wang 	if (!cfg->line_out_pins[0])
5950ab6734e7SLydia Wang 		return -1;
5951ab6734e7SLydia Wang 
5952ab6734e7SLydia Wang 	/* Line-Out: PortE */
5953ab6734e7SLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5954ab6734e7SLydia Wang 			      "Master Front Playback Volume",
5955ab6734e7SLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5956ab6734e7SLydia Wang 	if (err < 0)
5957ab6734e7SLydia Wang 		return err;
5958ab6734e7SLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5959ab6734e7SLydia Wang 			      "Master Front Playback Switch",
5960ab6734e7SLydia Wang 			      HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5961ab6734e7SLydia Wang 	if (err < 0)
5962ab6734e7SLydia Wang 		return err;
5963ab6734e7SLydia Wang 
5964ab6734e7SLydia Wang 	return 0;
5965ab6734e7SLydia Wang }
5966ab6734e7SLydia Wang 
5967ab6734e7SLydia Wang static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5968ab6734e7SLydia Wang {
5969ab6734e7SLydia Wang 	int err;
5970ab6734e7SLydia Wang 
5971ab6734e7SLydia Wang 	if (!pin)
5972ab6734e7SLydia Wang 		return 0;
5973ab6734e7SLydia Wang 
5974ab6734e7SLydia Wang 	spec->multiout.hp_nid = 0x9;
5975ab6734e7SLydia Wang 	spec->hp_independent_mode_index = 1;
5976ab6734e7SLydia Wang 
5977ab6734e7SLydia Wang 
5978ab6734e7SLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5979ab6734e7SLydia Wang 			      "Headphone Playback Volume",
5980ab6734e7SLydia Wang 			      HDA_COMPOSE_AMP_VAL(
5981ab6734e7SLydia Wang 				      spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5982ab6734e7SLydia Wang 	if (err < 0)
5983ab6734e7SLydia Wang 		return err;
5984ab6734e7SLydia Wang 
5985ab6734e7SLydia Wang 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5986ab6734e7SLydia Wang 			      "Headphone Playback Switch",
5987ab6734e7SLydia Wang 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5988ab6734e7SLydia Wang 	if (err < 0)
5989ab6734e7SLydia Wang 		return err;
5990ab6734e7SLydia Wang 
5991ab6734e7SLydia Wang 	create_hp_imux(spec);
5992ab6734e7SLydia Wang 	return 0;
5993ab6734e7SLydia Wang }
5994ab6734e7SLydia Wang 
5995ab6734e7SLydia Wang /* create playback/capture controls for input pins */
5996ab6734e7SLydia Wang static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5997ab6734e7SLydia Wang 						const struct auto_pin_cfg *cfg)
5998ab6734e7SLydia Wang {
5999ab6734e7SLydia Wang 	static char *labels[] = {
6000ab6734e7SLydia Wang 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6001ab6734e7SLydia Wang 	};
6002ab6734e7SLydia Wang 	struct hda_input_mux *imux = &spec->private_imux[0];
6003ab6734e7SLydia Wang 	int i, err, idx = 0;
6004ab6734e7SLydia Wang 
6005ab6734e7SLydia Wang 	for (i = 0; i < AUTO_PIN_LAST; i++) {
6006ab6734e7SLydia Wang 		if (!cfg->input_pins[i])
6007ab6734e7SLydia Wang 			continue;
6008ab6734e7SLydia Wang 
6009ab6734e7SLydia Wang 		switch (cfg->input_pins[i]) {
6010ab6734e7SLydia Wang 		case 0x2b: /* Mic */
6011ab6734e7SLydia Wang 			idx = 0;
6012ab6734e7SLydia Wang 			break;
6013ab6734e7SLydia Wang 
6014ab6734e7SLydia Wang 		case 0x2a: /* Line In */
6015ab6734e7SLydia Wang 			idx = 1;
6016ab6734e7SLydia Wang 			break;
6017ab6734e7SLydia Wang 
6018ab6734e7SLydia Wang 		case 0x29: /* Front Mic */
6019ab6734e7SLydia Wang 			idx = 2;
6020ab6734e7SLydia Wang 			break;
6021ab6734e7SLydia Wang 		}
6022ab6734e7SLydia Wang 		err = via_new_analog_input(spec, labels[i], idx, 0x21);
6023ab6734e7SLydia Wang 		if (err < 0)
6024ab6734e7SLydia Wang 			return err;
6025ab6734e7SLydia Wang 		imux->items[imux->num_items].label = labels[i];
6026ab6734e7SLydia Wang 		imux->items[imux->num_items].index = idx;
6027ab6734e7SLydia Wang 		imux->num_items++;
6028ab6734e7SLydia Wang 	}
6029ab6734e7SLydia Wang 	/* build volume/mute control of loopback */
6030ab6734e7SLydia Wang 	err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6031ab6734e7SLydia Wang 	if (err < 0)
6032ab6734e7SLydia Wang 		return err;
6033ab6734e7SLydia Wang 
6034ab6734e7SLydia Wang 	/* for internal loopback recording select */
6035ab6734e7SLydia Wang 	imux->items[imux->num_items].label = "Stereo Mixer";
6036ab6734e7SLydia Wang 	imux->items[imux->num_items].index = 5;
6037ab6734e7SLydia Wang 	imux->num_items++;
6038ab6734e7SLydia Wang 
6039ab6734e7SLydia Wang 	/* for digital mic select */
6040ab6734e7SLydia Wang 	imux->items[imux->num_items].label = "Digital Mic";
6041ab6734e7SLydia Wang 	imux->items[imux->num_items].index = 6;
6042ab6734e7SLydia Wang 	imux->num_items++;
6043ab6734e7SLydia Wang 
6044ab6734e7SLydia Wang 	return 0;
6045ab6734e7SLydia Wang }
6046ab6734e7SLydia Wang 
6047ab6734e7SLydia Wang static int vt1812_parse_auto_config(struct hda_codec *codec)
6048ab6734e7SLydia Wang {
6049ab6734e7SLydia Wang 	struct via_spec *spec = codec->spec;
6050ab6734e7SLydia Wang 	int err;
6051ab6734e7SLydia Wang 
6052ab6734e7SLydia Wang 
6053ab6734e7SLydia Wang 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6054ab6734e7SLydia Wang 	if (err < 0)
6055ab6734e7SLydia Wang 		return err;
6056ab6734e7SLydia Wang 	fill_dig_outs(codec);
6057ab6734e7SLydia Wang 	err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6058ab6734e7SLydia Wang 	if (err < 0)
6059ab6734e7SLydia Wang 		return err;
6060ab6734e7SLydia Wang 
6061ab6734e7SLydia Wang 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6062ab6734e7SLydia Wang 		return 0; /* can't find valid BIOS pin config */
6063ab6734e7SLydia Wang 
6064ab6734e7SLydia Wang 	err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6065ab6734e7SLydia Wang 	if (err < 0)
6066ab6734e7SLydia Wang 		return err;
6067ab6734e7SLydia Wang 	err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6068ab6734e7SLydia Wang 	if (err < 0)
6069ab6734e7SLydia Wang 		return err;
6070ab6734e7SLydia Wang 	err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6071ab6734e7SLydia Wang 	if (err < 0)
6072ab6734e7SLydia Wang 		return err;
6073ab6734e7SLydia Wang 
6074ab6734e7SLydia Wang 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6075ab6734e7SLydia Wang 
6076ab6734e7SLydia Wang 	fill_dig_outs(codec);
6077ab6734e7SLydia Wang 
6078ab6734e7SLydia Wang 	if (spec->kctls.list)
6079ab6734e7SLydia Wang 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
6080ab6734e7SLydia Wang 
6081ab6734e7SLydia Wang 	spec->input_mux = &spec->private_imux[0];
6082ab6734e7SLydia Wang 
6083ab6734e7SLydia Wang 	if (spec->hp_mux)
6084ab6734e7SLydia Wang 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
6085ab6734e7SLydia Wang 
6086ab6734e7SLydia Wang 	return 1;
6087ab6734e7SLydia Wang }
6088ab6734e7SLydia Wang 
6089ab6734e7SLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
6090ab6734e7SLydia Wang static struct hda_amp_list vt1812_loopbacks[] = {
6091ab6734e7SLydia Wang 	{ 0x21, HDA_INPUT, 0 },
6092ab6734e7SLydia Wang 	{ 0x21, HDA_INPUT, 1 },
6093ab6734e7SLydia Wang 	{ 0x21, HDA_INPUT, 2 },
6094ab6734e7SLydia Wang 	{ } /* end */
6095ab6734e7SLydia Wang };
6096ab6734e7SLydia Wang #endif
6097ab6734e7SLydia Wang 
6098ab6734e7SLydia Wang 
6099ab6734e7SLydia Wang /* patch for vt1812 */
6100ab6734e7SLydia Wang static int patch_vt1812(struct hda_codec *codec)
6101ab6734e7SLydia Wang {
6102ab6734e7SLydia Wang 	struct via_spec *spec;
6103ab6734e7SLydia Wang 	int err;
6104ab6734e7SLydia Wang 
6105ab6734e7SLydia Wang 	/* create a codec specific record */
6106ab6734e7SLydia Wang 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6107ab6734e7SLydia Wang 	if (spec == NULL)
6108ab6734e7SLydia Wang 		return -ENOMEM;
6109ab6734e7SLydia Wang 
6110ab6734e7SLydia Wang 	codec->spec = spec;
6111ab6734e7SLydia Wang 
6112ab6734e7SLydia Wang 	/* automatic parse from the BIOS config */
6113ab6734e7SLydia Wang 	err = vt1812_parse_auto_config(codec);
6114ab6734e7SLydia Wang 	if (err < 0) {
6115ab6734e7SLydia Wang 		via_free(codec);
6116ab6734e7SLydia Wang 		return err;
6117ab6734e7SLydia Wang 	} else if (!err) {
6118ab6734e7SLydia Wang 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
6119ab6734e7SLydia Wang 		       "from BIOS.  Using genenic mode...\n");
6120ab6734e7SLydia Wang 	}
6121ab6734e7SLydia Wang 
6122ab6734e7SLydia Wang 
6123ab6734e7SLydia Wang 	spec->init_verbs[spec->num_iverbs++]  = vt1812_volume_init_verbs;
6124ab6734e7SLydia Wang 	spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6125ab6734e7SLydia Wang 
6126ab6734e7SLydia Wang 	spec->stream_name_analog = "VT1812 Analog";
6127ab6734e7SLydia Wang 	spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6128ab6734e7SLydia Wang 	spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6129ab6734e7SLydia Wang 
6130ab6734e7SLydia Wang 	spec->stream_name_digital = "VT1812 Digital";
6131ab6734e7SLydia Wang 	spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6132ab6734e7SLydia Wang 
6133ab6734e7SLydia Wang 
6134ab6734e7SLydia Wang 	if (!spec->adc_nids && spec->input_mux) {
6135ab6734e7SLydia Wang 		spec->adc_nids = vt1812_adc_nids;
6136ab6734e7SLydia Wang 		spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6137ab6734e7SLydia Wang 		get_mux_nids(codec);
6138ab6734e7SLydia Wang 		override_mic_boost(codec, 0x2b, 0, 3, 40);
6139ab6734e7SLydia Wang 		override_mic_boost(codec, 0x29, 0, 3, 40);
6140ab6734e7SLydia Wang 		spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6141ab6734e7SLydia Wang 		spec->num_mixers++;
6142ab6734e7SLydia Wang 	}
6143ab6734e7SLydia Wang 
6144ab6734e7SLydia Wang 	codec->patch_ops = via_patch_ops;
6145ab6734e7SLydia Wang 
6146ab6734e7SLydia Wang 	codec->patch_ops.init = via_auto_init;
61470f48327eSStephen Rothwell 	codec->patch_ops.unsol_event = via_unsol_event;
6148ab6734e7SLydia Wang 
6149ab6734e7SLydia Wang #ifdef CONFIG_SND_HDA_POWER_SAVE
6150ab6734e7SLydia Wang 	spec->loopback.amplist = vt1812_loopbacks;
6151ab6734e7SLydia Wang #endif
6152ab6734e7SLydia Wang 
6153ab6734e7SLydia Wang 	return 0;
6154ab6734e7SLydia Wang }
6155ab6734e7SLydia Wang 
6156c577b8a1SJoseph Chan /*
6157c577b8a1SJoseph Chan  * patch entries
6158c577b8a1SJoseph Chan  */
61591289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_via[] = {
61603218c178STakashi Iwai 	{ .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
61613218c178STakashi Iwai 	{ .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
61623218c178STakashi Iwai 	{ .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
61633218c178STakashi Iwai 	{ .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
61643218c178STakashi Iwai 	{ .id = 0x1106e710, .name = "VT1709 10-Ch",
6165f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
61663218c178STakashi Iwai 	{ .id = 0x1106e711, .name = "VT1709 10-Ch",
6167f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
61683218c178STakashi Iwai 	{ .id = 0x1106e712, .name = "VT1709 10-Ch",
6169f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
61703218c178STakashi Iwai 	{ .id = 0x1106e713, .name = "VT1709 10-Ch",
6171f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
61723218c178STakashi Iwai 	{ .id = 0x1106e714, .name = "VT1709 6-Ch",
6173f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
61743218c178STakashi Iwai 	{ .id = 0x1106e715, .name = "VT1709 6-Ch",
6175f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
61763218c178STakashi Iwai 	{ .id = 0x1106e716, .name = "VT1709 6-Ch",
6177f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
61783218c178STakashi Iwai 	{ .id = 0x1106e717, .name = "VT1709 6-Ch",
6179f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
61803218c178STakashi Iwai 	{ .id = 0x1106e720, .name = "VT1708B 8-Ch",
6181f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
61823218c178STakashi Iwai 	{ .id = 0x1106e721, .name = "VT1708B 8-Ch",
6183f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
61843218c178STakashi Iwai 	{ .id = 0x1106e722, .name = "VT1708B 8-Ch",
6185f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
61863218c178STakashi Iwai 	{ .id = 0x1106e723, .name = "VT1708B 8-Ch",
6187f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
61883218c178STakashi Iwai 	{ .id = 0x1106e724, .name = "VT1708B 4-Ch",
6189f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
61903218c178STakashi Iwai 	{ .id = 0x1106e725, .name = "VT1708B 4-Ch",
6191f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
61923218c178STakashi Iwai 	{ .id = 0x1106e726, .name = "VT1708B 4-Ch",
6193f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
61943218c178STakashi Iwai 	{ .id = 0x1106e727, .name = "VT1708B 4-Ch",
6195f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
61963218c178STakashi Iwai 	{ .id = 0x11060397, .name = "VT1708S",
6197d949cac1SHarald Welte 	  .patch = patch_vt1708S},
61983218c178STakashi Iwai 	{ .id = 0x11061397, .name = "VT1708S",
6199d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62003218c178STakashi Iwai 	{ .id = 0x11062397, .name = "VT1708S",
6201d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62023218c178STakashi Iwai 	{ .id = 0x11063397, .name = "VT1708S",
6203d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62043218c178STakashi Iwai 	{ .id = 0x11064397, .name = "VT1708S",
6205d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62063218c178STakashi Iwai 	{ .id = 0x11065397, .name = "VT1708S",
6207d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62083218c178STakashi Iwai 	{ .id = 0x11066397, .name = "VT1708S",
6209d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62103218c178STakashi Iwai 	{ .id = 0x11067397, .name = "VT1708S",
6211d949cac1SHarald Welte 	  .patch = patch_vt1708S},
62123218c178STakashi Iwai 	{ .id = 0x11060398, .name = "VT1702",
6213d949cac1SHarald Welte 	  .patch = patch_vt1702},
62143218c178STakashi Iwai 	{ .id = 0x11061398, .name = "VT1702",
6215d949cac1SHarald Welte 	  .patch = patch_vt1702},
62163218c178STakashi Iwai 	{ .id = 0x11062398, .name = "VT1702",
6217d949cac1SHarald Welte 	  .patch = patch_vt1702},
62183218c178STakashi Iwai 	{ .id = 0x11063398, .name = "VT1702",
6219d949cac1SHarald Welte 	  .patch = patch_vt1702},
62203218c178STakashi Iwai 	{ .id = 0x11064398, .name = "VT1702",
6221d949cac1SHarald Welte 	  .patch = patch_vt1702},
62223218c178STakashi Iwai 	{ .id = 0x11065398, .name = "VT1702",
6223d949cac1SHarald Welte 	  .patch = patch_vt1702},
62243218c178STakashi Iwai 	{ .id = 0x11066398, .name = "VT1702",
6225d949cac1SHarald Welte 	  .patch = patch_vt1702},
62263218c178STakashi Iwai 	{ .id = 0x11067398, .name = "VT1702",
6227d949cac1SHarald Welte 	  .patch = patch_vt1702},
6228eb7188caSLydia Wang 	{ .id = 0x11060428, .name = "VT1718S",
6229eb7188caSLydia Wang 	  .patch = patch_vt1718S},
6230eb7188caSLydia Wang 	{ .id = 0x11064428, .name = "VT1718S",
6231eb7188caSLydia Wang 	  .patch = patch_vt1718S},
6232bb3c6bfcSLydia Wang 	{ .id = 0x11060441, .name = "VT2020",
6233bb3c6bfcSLydia Wang 	  .patch = patch_vt1718S},
6234bb3c6bfcSLydia Wang 	{ .id = 0x11064441, .name = "VT1828S",
6235bb3c6bfcSLydia Wang 	  .patch = patch_vt1718S},
6236f3db423dSLydia Wang 	{ .id = 0x11060433, .name = "VT1716S",
6237f3db423dSLydia Wang 	  .patch = patch_vt1716S},
6238f3db423dSLydia Wang 	{ .id = 0x1106a721, .name = "VT1716S",
6239f3db423dSLydia Wang 	  .patch = patch_vt1716S},
624025eaba2fSLydia Wang 	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
624125eaba2fSLydia Wang 	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6242ab6734e7SLydia Wang 	{ .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6243*36dd5c4aSLydia Wang 	{ .id = 0x11060440, .name = "VT1818S",
6244*36dd5c4aSLydia Wang 	  .patch = patch_vt1708S},
6245c577b8a1SJoseph Chan 	{} /* terminator */
6246c577b8a1SJoseph Chan };
62471289e9e8STakashi Iwai 
62481289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:1106*");
62491289e9e8STakashi Iwai 
62501289e9e8STakashi Iwai static struct hda_codec_preset_list via_list = {
62511289e9e8STakashi Iwai 	.preset = snd_hda_preset_via,
62521289e9e8STakashi Iwai 	.owner = THIS_MODULE,
62531289e9e8STakashi Iwai };
62541289e9e8STakashi Iwai 
62551289e9e8STakashi Iwai MODULE_LICENSE("GPL");
62561289e9e8STakashi Iwai MODULE_DESCRIPTION("VIA HD-audio codec");
62571289e9e8STakashi Iwai 
62581289e9e8STakashi Iwai static int __init patch_via_init(void)
62591289e9e8STakashi Iwai {
62601289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&via_list);
62611289e9e8STakashi Iwai }
62621289e9e8STakashi Iwai 
62631289e9e8STakashi Iwai static void __exit patch_via_exit(void)
62641289e9e8STakashi Iwai {
62651289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&via_list);
62661289e9e8STakashi Iwai }
62671289e9e8STakashi Iwai 
62681289e9e8STakashi Iwai module_init(patch_via_init)
62691289e9e8STakashi Iwai module_exit(patch_via_exit)
6270