xref: /openbmc/linux/sound/pci/hda/patch_via.c (revision 2f334f92cfb44d17b9f24a43f8998cca03f9a3dd)
1c577b8a1SJoseph Chan /*
2c577b8a1SJoseph Chan  * Universal Interface for Intel High Definition Audio Codec
3c577b8a1SJoseph Chan  *
4d949cac1SHarald Welte  * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
5c577b8a1SJoseph Chan  *
676d9b0ddSHarald Welte  * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7c577b8a1SJoseph Chan  *			   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	     */
39c577b8a1SJoseph Chan /*                                                                           */
40c577b8a1SJoseph Chan /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41c577b8a1SJoseph Chan 
42c577b8a1SJoseph Chan 
43c577b8a1SJoseph Chan #include <linux/init.h>
44c577b8a1SJoseph Chan #include <linux/delay.h>
45c577b8a1SJoseph Chan #include <linux/slab.h>
46c577b8a1SJoseph Chan #include <sound/core.h>
470aa62aefSHarald Welte #include <sound/asoundef.h>
48c577b8a1SJoseph Chan #include "hda_codec.h"
49c577b8a1SJoseph Chan #include "hda_local.h"
50c577b8a1SJoseph Chan 
51c577b8a1SJoseph Chan /* amp values */
52c577b8a1SJoseph Chan #define AMP_VAL_IDX_SHIFT	19
53c577b8a1SJoseph Chan #define AMP_VAL_IDX_MASK	(0x0f<<19)
54c577b8a1SJoseph Chan 
55c577b8a1SJoseph Chan /* Pin Widget NID */
56c577b8a1SJoseph Chan #define VT1708_HP_NID		0x13
57c577b8a1SJoseph Chan #define VT1708_DIGOUT_NID	0x14
58c577b8a1SJoseph Chan #define VT1708_DIGIN_NID	0x16
59f7278fd0SJosepch Chan #define VT1708_DIGIN_PIN	0x26
6076d9b0ddSHarald Welte #define VT1708_HP_PIN_NID	0x20
6176d9b0ddSHarald Welte #define VT1708_CD_PIN_NID	0x24
62c577b8a1SJoseph Chan 
63c577b8a1SJoseph Chan #define VT1709_HP_DAC_NID	0x28
64c577b8a1SJoseph Chan #define VT1709_DIGOUT_NID	0x13
65c577b8a1SJoseph Chan #define VT1709_DIGIN_NID	0x17
66f7278fd0SJosepch Chan #define VT1709_DIGIN_PIN	0x25
67f7278fd0SJosepch Chan 
68f7278fd0SJosepch Chan #define VT1708B_HP_NID		0x25
69f7278fd0SJosepch Chan #define VT1708B_DIGOUT_NID	0x12
70f7278fd0SJosepch Chan #define VT1708B_DIGIN_NID	0x15
71f7278fd0SJosepch Chan #define VT1708B_DIGIN_PIN	0x21
72c577b8a1SJoseph Chan 
73d949cac1SHarald Welte #define VT1708S_HP_NID		0x25
74d949cac1SHarald Welte #define VT1708S_DIGOUT_NID	0x12
75d949cac1SHarald Welte 
76d949cac1SHarald Welte #define VT1702_HP_NID		0x17
77d949cac1SHarald Welte #define VT1702_DIGOUT_NID	0x11
78d949cac1SHarald Welte 
79c577b8a1SJoseph Chan #define IS_VT1708_VENDORID(x)		((x) >= 0x11061708 && (x) <= 0x1106170b)
80c577b8a1SJoseph Chan #define IS_VT1709_10CH_VENDORID(x)	((x) >= 0x1106e710 && (x) <= 0x1106e713)
81c577b8a1SJoseph Chan #define IS_VT1709_6CH_VENDORID(x)	((x) >= 0x1106e714 && (x) <= 0x1106e717)
82f7278fd0SJosepch Chan #define IS_VT1708B_8CH_VENDORID(x)	((x) >= 0x1106e720 && (x) <= 0x1106e723)
83f7278fd0SJosepch Chan #define IS_VT1708B_4CH_VENDORID(x)	((x) >= 0x1106e724 && (x) <= 0x1106e727)
84d949cac1SHarald Welte #define IS_VT1708S_VENDORID(x)		((x) >= 0x11060397 && (x) <= 0x11067397)
85d949cac1SHarald Welte #define IS_VT1702_VENDORID(x)		((x) >= 0x11060398 && (x) <= 0x11067398)
86c577b8a1SJoseph Chan 
87d7426329SHarald Welte enum VIA_HDA_CODEC {
88d7426329SHarald Welte 	UNKNOWN = -1,
89d7426329SHarald Welte 	VT1708,
90d7426329SHarald Welte 	VT1709_10CH,
91d7426329SHarald Welte 	VT1709_6CH,
92d7426329SHarald Welte 	VT1708B_8CH,
93d7426329SHarald Welte 	VT1708B_4CH,
94d7426329SHarald Welte 	VT1708S,
95d7426329SHarald Welte 	VT1702,
96d7426329SHarald Welte 	CODEC_TYPES,
97d7426329SHarald Welte };
98d7426329SHarald Welte 
99d7426329SHarald Welte static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
100d7426329SHarald Welte {
101d7426329SHarald Welte 	u16 ven_id = vendor_id >> 16;
102d7426329SHarald Welte 	u16 dev_id = vendor_id & 0xffff;
103d7426329SHarald Welte 	enum VIA_HDA_CODEC codec_type;
104d7426329SHarald Welte 
105d7426329SHarald Welte 	/* get codec type */
106d7426329SHarald Welte 	if (ven_id != 0x1106)
107d7426329SHarald Welte 		codec_type = UNKNOWN;
108d7426329SHarald Welte 	else if (dev_id >= 0x1708 && dev_id <= 0x170b)
109d7426329SHarald Welte 		codec_type = VT1708;
110d7426329SHarald Welte 	else if (dev_id >= 0xe710 && dev_id <= 0xe713)
111d7426329SHarald Welte 		codec_type = VT1709_10CH;
112d7426329SHarald Welte 	else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113d7426329SHarald Welte 		codec_type = VT1709_6CH;
114d7426329SHarald Welte 	else if (dev_id >= 0xe720 && dev_id <= 0xe723)
115d7426329SHarald Welte 		codec_type = VT1708B_8CH;
116d7426329SHarald Welte 	else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117d7426329SHarald Welte 		codec_type = VT1708B_4CH;
118d7426329SHarald Welte 	else if ((dev_id & 0xfff) == 0x397
119d7426329SHarald Welte 		 && (dev_id >> 12) < 8)
120d7426329SHarald Welte 		codec_type = VT1708S;
121d7426329SHarald Welte 	else if ((dev_id & 0xfff) == 0x398
122d7426329SHarald Welte 		 && (dev_id >> 12) < 8)
123d7426329SHarald Welte 		codec_type = VT1702;
124d7426329SHarald Welte 	else
125d7426329SHarald Welte 		codec_type = UNKNOWN;
126d7426329SHarald Welte 	return codec_type;
127d7426329SHarald Welte };
128d7426329SHarald Welte 
12969e52a80SHarald Welte #define VIA_HP_EVENT		0x01
13069e52a80SHarald Welte #define VIA_GPIO_EVENT		0x02
13169e52a80SHarald Welte 
132c577b8a1SJoseph Chan enum {
133c577b8a1SJoseph Chan 	VIA_CTL_WIDGET_VOL,
134c577b8a1SJoseph Chan 	VIA_CTL_WIDGET_MUTE,
135c577b8a1SJoseph Chan };
136c577b8a1SJoseph Chan 
137c577b8a1SJoseph Chan enum {
138eb14a46cSHarald Welte 	AUTO_SEQ_FRONT = 0,
139c577b8a1SJoseph Chan 	AUTO_SEQ_SURROUND,
140c577b8a1SJoseph Chan 	AUTO_SEQ_CENLFE,
141c577b8a1SJoseph Chan 	AUTO_SEQ_SIDE
142c577b8a1SJoseph Chan };
143c577b8a1SJoseph Chan 
144d7426329SHarald Welte /* Some VT1708S based boards gets the micboost setting wrong, so we have
145d7426329SHarald Welte  * to apply some brute-force and re-write the TLV's by software. */
146d7426329SHarald Welte static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
147d7426329SHarald Welte 			 unsigned int size, unsigned int __user *_tlv)
148d7426329SHarald Welte {
149d7426329SHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
150d7426329SHarald Welte 	hda_nid_t nid = get_amp_nid(kcontrol);
151d7426329SHarald Welte 
152d7426329SHarald Welte 	if (get_codec_type(codec->vendor_id) == VT1708S
153d7426329SHarald Welte 	    && (nid == 0x1a || nid == 0x1e)) {
154d7426329SHarald Welte 		if (size < 4 * sizeof(unsigned int))
155d7426329SHarald Welte 			return -ENOMEM;
156d7426329SHarald Welte 		if (put_user(1, _tlv))	/* SNDRV_CTL_TLVT_DB_SCALE */
157d7426329SHarald Welte 			return -EFAULT;
158d7426329SHarald Welte 		if (put_user(2 * sizeof(unsigned int), _tlv + 1))
159d7426329SHarald Welte 			return -EFAULT;
160d7426329SHarald Welte 		if (put_user(0, _tlv + 2)) /* offset = 0 */
161d7426329SHarald Welte 			return -EFAULT;
162d7426329SHarald Welte 		if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
163d7426329SHarald Welte 			return -EFAULT;
164d7426329SHarald Welte 	}
165d7426329SHarald Welte 	return 0;
166d7426329SHarald Welte }
167d7426329SHarald Welte 
168d7426329SHarald Welte static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
169d7426329SHarald Welte 				 struct snd_ctl_elem_info *uinfo)
170d7426329SHarald Welte {
171d7426329SHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172d7426329SHarald Welte 	hda_nid_t nid = get_amp_nid(kcontrol);
173d7426329SHarald Welte 
174d7426329SHarald Welte 	if (get_codec_type(codec->vendor_id) == VT1708S
175d7426329SHarald Welte 	    && (nid == 0x1a || nid == 0x1e)) {
176d7426329SHarald Welte 		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
177d7426329SHarald Welte 		uinfo->count = 2;
178d7426329SHarald Welte 		uinfo->value.integer.min = 0;
179d7426329SHarald Welte 		uinfo->value.integer.max = 3;
180d7426329SHarald Welte 	}
181d7426329SHarald Welte 	return 0;
182d7426329SHarald Welte }
183d7426329SHarald Welte 
184c577b8a1SJoseph Chan static struct snd_kcontrol_new vt1708_control_templates[] = {
185c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
186c577b8a1SJoseph Chan 	HDA_CODEC_MUTE(NULL, 0, 0, 0),
187c577b8a1SJoseph Chan };
188c577b8a1SJoseph Chan 
189c577b8a1SJoseph Chan 
190c577b8a1SJoseph Chan struct via_spec {
191c577b8a1SJoseph Chan 	/* codec parameterization */
192c577b8a1SJoseph Chan 	struct snd_kcontrol_new *mixers[3];
193c577b8a1SJoseph Chan 	unsigned int num_mixers;
194c577b8a1SJoseph Chan 
19569e52a80SHarald Welte 	struct hda_verb *init_verbs[5];
19669e52a80SHarald Welte 	unsigned int num_iverbs;
197c577b8a1SJoseph Chan 
198c577b8a1SJoseph Chan 	char *stream_name_analog;
199c577b8a1SJoseph Chan 	struct hda_pcm_stream *stream_analog_playback;
200c577b8a1SJoseph Chan 	struct hda_pcm_stream *stream_analog_capture;
201c577b8a1SJoseph Chan 
202c577b8a1SJoseph Chan 	char *stream_name_digital;
203c577b8a1SJoseph Chan 	struct hda_pcm_stream *stream_digital_playback;
204c577b8a1SJoseph Chan 	struct hda_pcm_stream *stream_digital_capture;
205c577b8a1SJoseph Chan 
206c577b8a1SJoseph Chan 	/* playback */
207c577b8a1SJoseph Chan 	struct hda_multi_out multiout;
20898aa34c0SHarald Welte 	hda_nid_t extra_dig_out_nid;
209c577b8a1SJoseph Chan 
210c577b8a1SJoseph Chan 	/* capture */
211c577b8a1SJoseph Chan 	unsigned int num_adc_nids;
212c577b8a1SJoseph Chan 	hda_nid_t *adc_nids;
213c577b8a1SJoseph Chan 	hda_nid_t dig_in_nid;
214c577b8a1SJoseph Chan 
215c577b8a1SJoseph Chan 	/* capture source */
216c577b8a1SJoseph Chan 	const struct hda_input_mux *input_mux;
217c577b8a1SJoseph Chan 	unsigned int cur_mux[3];
218c577b8a1SJoseph Chan 
219c577b8a1SJoseph Chan 	/* PCM information */
22098aa34c0SHarald Welte 	struct hda_pcm pcm_rec[3];
221c577b8a1SJoseph Chan 
222c577b8a1SJoseph Chan 	/* dynamic controls, init_verbs and input_mux */
223c577b8a1SJoseph Chan 	struct auto_pin_cfg autocfg;
224603c4019STakashi Iwai 	struct snd_array kctls;
2250aa62aefSHarald Welte 	struct hda_input_mux private_imux[2];
22641923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
227cb53c626STakashi Iwai 
2280aa62aefSHarald Welte 	/* HP mode source */
2290aa62aefSHarald Welte 	const struct hda_input_mux *hp_mux;
2300aa62aefSHarald Welte 	unsigned int hp_independent_mode;
2310aa62aefSHarald Welte 
232cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
233cb53c626STakashi Iwai 	struct hda_loopback_check loopback;
234cb53c626STakashi Iwai #endif
235c577b8a1SJoseph Chan };
236c577b8a1SJoseph Chan 
237c577b8a1SJoseph Chan static hda_nid_t vt1708_adc_nids[2] = {
238c577b8a1SJoseph Chan 	/* ADC1-2 */
239c577b8a1SJoseph Chan 	0x15, 0x27
240c577b8a1SJoseph Chan };
241c577b8a1SJoseph Chan 
242c577b8a1SJoseph Chan static hda_nid_t vt1709_adc_nids[3] = {
243c577b8a1SJoseph Chan 	/* ADC1-2 */
244c577b8a1SJoseph Chan 	0x14, 0x15, 0x16
245c577b8a1SJoseph Chan };
246c577b8a1SJoseph Chan 
247f7278fd0SJosepch Chan static hda_nid_t vt1708B_adc_nids[2] = {
248f7278fd0SJosepch Chan 	/* ADC1-2 */
249f7278fd0SJosepch Chan 	0x13, 0x14
250f7278fd0SJosepch Chan };
251f7278fd0SJosepch Chan 
252d949cac1SHarald Welte static hda_nid_t vt1708S_adc_nids[2] = {
253d949cac1SHarald Welte 	/* ADC1-2 */
254d949cac1SHarald Welte 	0x13, 0x14
255d949cac1SHarald Welte };
256d949cac1SHarald Welte 
257d949cac1SHarald Welte static hda_nid_t vt1702_adc_nids[3] = {
258d949cac1SHarald Welte 	/* ADC1-2 */
259d949cac1SHarald Welte 	0x12, 0x20, 0x1F
260d949cac1SHarald Welte };
261d949cac1SHarald Welte 
262c577b8a1SJoseph Chan /* add dynamic controls */
263c577b8a1SJoseph Chan static int via_add_control(struct via_spec *spec, int type, const char *name,
264c577b8a1SJoseph Chan 			   unsigned long val)
265c577b8a1SJoseph Chan {
266c577b8a1SJoseph Chan 	struct snd_kcontrol_new *knew;
267c577b8a1SJoseph Chan 
268603c4019STakashi Iwai 	snd_array_init(&spec->kctls, sizeof(*knew), 32);
269603c4019STakashi Iwai 	knew = snd_array_new(&spec->kctls);
270c577b8a1SJoseph Chan 	if (!knew)
271c577b8a1SJoseph Chan 		return -ENOMEM;
272c577b8a1SJoseph Chan 	*knew = vt1708_control_templates[type];
273c577b8a1SJoseph Chan 	knew->name = kstrdup(name, GFP_KERNEL);
274c577b8a1SJoseph Chan 	if (!knew->name)
275c577b8a1SJoseph Chan 		return -ENOMEM;
276c577b8a1SJoseph Chan 	knew->private_value = val;
277c577b8a1SJoseph Chan 	return 0;
278c577b8a1SJoseph Chan }
279c577b8a1SJoseph Chan 
280603c4019STakashi Iwai static void via_free_kctls(struct hda_codec *codec)
281603c4019STakashi Iwai {
282603c4019STakashi Iwai 	struct via_spec *spec = codec->spec;
283603c4019STakashi Iwai 
284603c4019STakashi Iwai 	if (spec->kctls.list) {
285603c4019STakashi Iwai 		struct snd_kcontrol_new *kctl = spec->kctls.list;
286603c4019STakashi Iwai 		int i;
287603c4019STakashi Iwai 		for (i = 0; i < spec->kctls.used; i++)
288603c4019STakashi Iwai 			kfree(kctl[i].name);
289603c4019STakashi Iwai 	}
290603c4019STakashi Iwai 	snd_array_free(&spec->kctls);
291603c4019STakashi Iwai }
292603c4019STakashi Iwai 
293c577b8a1SJoseph Chan /* create input playback/capture controls for the given pin */
294c577b8a1SJoseph Chan static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
295c577b8a1SJoseph Chan 				const char *ctlname, int idx, int mix_nid)
296c577b8a1SJoseph Chan {
297c577b8a1SJoseph Chan 	char name[32];
298c577b8a1SJoseph Chan 	int err;
299c577b8a1SJoseph Chan 
300c577b8a1SJoseph Chan 	sprintf(name, "%s Playback Volume", ctlname);
301c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
302c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
303c577b8a1SJoseph Chan 	if (err < 0)
304c577b8a1SJoseph Chan 		return err;
305c577b8a1SJoseph Chan 	sprintf(name, "%s Playback Switch", ctlname);
306c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
307c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
308c577b8a1SJoseph Chan 	if (err < 0)
309c577b8a1SJoseph Chan 		return err;
310c577b8a1SJoseph Chan 	return 0;
311c577b8a1SJoseph Chan }
312c577b8a1SJoseph Chan 
313c577b8a1SJoseph Chan static void via_auto_set_output_and_unmute(struct hda_codec *codec,
314c577b8a1SJoseph Chan 					   hda_nid_t nid, int pin_type,
315c577b8a1SJoseph Chan 					   int dac_idx)
316c577b8a1SJoseph Chan {
317c577b8a1SJoseph Chan 	/* set as output */
318c577b8a1SJoseph Chan 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
319c577b8a1SJoseph Chan 			    pin_type);
320c577b8a1SJoseph Chan 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
321c577b8a1SJoseph Chan 			    AMP_OUT_UNMUTE);
322c577b8a1SJoseph Chan }
323c577b8a1SJoseph Chan 
324c577b8a1SJoseph Chan 
325c577b8a1SJoseph Chan static void via_auto_init_multi_out(struct hda_codec *codec)
326c577b8a1SJoseph Chan {
327c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
328c577b8a1SJoseph Chan 	int i;
329c577b8a1SJoseph Chan 
330c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
331c577b8a1SJoseph Chan 		hda_nid_t nid = spec->autocfg.line_out_pins[i];
332c577b8a1SJoseph Chan 		if (nid)
333c577b8a1SJoseph Chan 			via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
334c577b8a1SJoseph Chan 	}
335c577b8a1SJoseph Chan }
336c577b8a1SJoseph Chan 
337c577b8a1SJoseph Chan static void via_auto_init_hp_out(struct hda_codec *codec)
338c577b8a1SJoseph Chan {
339c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
340c577b8a1SJoseph Chan 	hda_nid_t pin;
341c577b8a1SJoseph Chan 
342c577b8a1SJoseph Chan 	pin = spec->autocfg.hp_pins[0];
343c577b8a1SJoseph Chan 	if (pin) /* connect to front */
344c577b8a1SJoseph Chan 		via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
345c577b8a1SJoseph Chan }
346c577b8a1SJoseph Chan 
347c577b8a1SJoseph Chan static void via_auto_init_analog_input(struct hda_codec *codec)
348c577b8a1SJoseph Chan {
349c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
350c577b8a1SJoseph Chan 	int i;
351c577b8a1SJoseph Chan 
352c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
353c577b8a1SJoseph Chan 		hda_nid_t nid = spec->autocfg.input_pins[i];
354c577b8a1SJoseph Chan 
355c577b8a1SJoseph Chan 		snd_hda_codec_write(codec, nid, 0,
356c577b8a1SJoseph Chan 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
357c577b8a1SJoseph Chan 				    (i <= AUTO_PIN_FRONT_MIC ?
358c577b8a1SJoseph Chan 				     PIN_VREF50 : PIN_IN));
359c577b8a1SJoseph Chan 
360c577b8a1SJoseph Chan 	}
361c577b8a1SJoseph Chan }
362c577b8a1SJoseph Chan /*
363c577b8a1SJoseph Chan  * input MUX handling
364c577b8a1SJoseph Chan  */
365c577b8a1SJoseph Chan static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
366c577b8a1SJoseph Chan 			     struct snd_ctl_elem_info *uinfo)
367c577b8a1SJoseph Chan {
368c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
370c577b8a1SJoseph Chan 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
371c577b8a1SJoseph Chan }
372c577b8a1SJoseph Chan 
373c577b8a1SJoseph Chan static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
374c577b8a1SJoseph Chan 			    struct snd_ctl_elem_value *ucontrol)
375c577b8a1SJoseph Chan {
376c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
378c577b8a1SJoseph Chan 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379c577b8a1SJoseph Chan 
380c577b8a1SJoseph Chan 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
381c577b8a1SJoseph Chan 	return 0;
382c577b8a1SJoseph Chan }
383c577b8a1SJoseph Chan 
384c577b8a1SJoseph Chan static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
385c577b8a1SJoseph Chan 			    struct snd_ctl_elem_value *ucontrol)
386c577b8a1SJoseph Chan {
387c577b8a1SJoseph Chan 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
389c577b8a1SJoseph Chan 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390c577b8a1SJoseph Chan 	unsigned int vendor_id = codec->vendor_id;
391c577b8a1SJoseph Chan 
392c577b8a1SJoseph Chan 	/* AIW0  lydia 060801 add for correct sw0 input select */
393c577b8a1SJoseph Chan 	if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
394c577b8a1SJoseph Chan 		return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
395c577b8a1SJoseph Chan 					     0x18, &spec->cur_mux[adc_idx]);
396c577b8a1SJoseph Chan 	else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
397eb14a46cSHarald Welte 		  IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
398c577b8a1SJoseph Chan 		return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399c577b8a1SJoseph Chan 					     0x19, &spec->cur_mux[adc_idx]);
400f7278fd0SJosepch Chan 	else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
401eb14a46cSHarald Welte 		  IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
402f7278fd0SJosepch Chan 		return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
403f7278fd0SJosepch Chan 					     0x17, &spec->cur_mux[adc_idx]);
404d949cac1SHarald Welte 	else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
405d949cac1SHarald Welte 		return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
406d949cac1SHarald Welte 					     0x13, &spec->cur_mux[adc_idx]);
407c577b8a1SJoseph Chan 	else
408c577b8a1SJoseph Chan 		return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
409c577b8a1SJoseph Chan 					     spec->adc_nids[adc_idx],
410c577b8a1SJoseph Chan 					     &spec->cur_mux[adc_idx]);
411c577b8a1SJoseph Chan }
412c577b8a1SJoseph Chan 
4130aa62aefSHarald Welte static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
4140aa62aefSHarald Welte 				   struct snd_ctl_elem_info *uinfo)
4150aa62aefSHarald Welte {
4160aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4170aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
4180aa62aefSHarald Welte 	return snd_hda_input_mux_info(spec->hp_mux, uinfo);
4190aa62aefSHarald Welte }
4200aa62aefSHarald Welte 
4210aa62aefSHarald Welte static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
4220aa62aefSHarald Welte 				  struct snd_ctl_elem_value *ucontrol)
4230aa62aefSHarald Welte {
4240aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4250aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
4260aa62aefSHarald Welte 	hda_nid_t nid = spec->autocfg.hp_pins[0];
4270aa62aefSHarald Welte 	unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
4280aa62aefSHarald Welte 						 AC_VERB_GET_CONNECT_SEL,
4290aa62aefSHarald Welte 						 0x00);
4300aa62aefSHarald Welte 
4310aa62aefSHarald Welte 	ucontrol->value.enumerated.item[0] = pinsel;
4320aa62aefSHarald Welte 
4330aa62aefSHarald Welte 	return 0;
4340aa62aefSHarald Welte }
4350aa62aefSHarald Welte 
4360aa62aefSHarald Welte static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
4370aa62aefSHarald Welte 				  struct snd_ctl_elem_value *ucontrol)
4380aa62aefSHarald Welte {
4390aa62aefSHarald Welte 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4400aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
4410aa62aefSHarald Welte 	hda_nid_t nid = spec->autocfg.hp_pins[0];
4420aa62aefSHarald Welte 	unsigned int pinsel = ucontrol->value.enumerated.item[0];
4430aa62aefSHarald Welte 	unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
4440aa62aefSHarald Welte 					 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
4450aa62aefSHarald Welte 
4460aa62aefSHarald Welte 	if (con_nid == spec->multiout.hp_nid) {
4470aa62aefSHarald Welte 		if (pinsel == 0) {
4480aa62aefSHarald Welte 			if (!spec->hp_independent_mode) {
4490aa62aefSHarald Welte 				if (spec->multiout.num_dacs > 1)
4500aa62aefSHarald Welte 					spec->multiout.num_dacs -= 1;
4510aa62aefSHarald Welte 				spec->hp_independent_mode = 1;
4520aa62aefSHarald Welte 			}
4530aa62aefSHarald Welte 		} else if (pinsel == 1) {
4540aa62aefSHarald Welte 		       if (spec->hp_independent_mode) {
4550aa62aefSHarald Welte 				if (spec->multiout.num_dacs > 1)
4560aa62aefSHarald Welte 					spec->multiout.num_dacs += 1;
4570aa62aefSHarald Welte 				spec->hp_independent_mode = 0;
4580aa62aefSHarald Welte 		       }
4590aa62aefSHarald Welte 		}
4600aa62aefSHarald Welte 	} else {
4610aa62aefSHarald Welte 		if (pinsel == 0) {
4620aa62aefSHarald Welte 			if (spec->hp_independent_mode) {
4630aa62aefSHarald Welte 				if (spec->multiout.num_dacs > 1)
4640aa62aefSHarald Welte 					spec->multiout.num_dacs += 1;
4650aa62aefSHarald Welte 				spec->hp_independent_mode = 0;
4660aa62aefSHarald Welte 			}
4670aa62aefSHarald Welte 		} else if (pinsel == 1) {
4680aa62aefSHarald Welte 		       if (!spec->hp_independent_mode) {
4690aa62aefSHarald Welte 				if (spec->multiout.num_dacs > 1)
4700aa62aefSHarald Welte 					spec->multiout.num_dacs -= 1;
4710aa62aefSHarald Welte 				spec->hp_independent_mode = 1;
4720aa62aefSHarald Welte 		       }
4730aa62aefSHarald Welte 		}
4740aa62aefSHarald Welte 	}
4750aa62aefSHarald Welte 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
4760aa62aefSHarald Welte 			    pinsel);
4770aa62aefSHarald Welte 
4780aa62aefSHarald Welte 	if (spec->multiout.hp_nid &&
4790aa62aefSHarald Welte 	    spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
4800aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec,
4810aa62aefSHarald Welte 						   spec->multiout.hp_nid,
4820aa62aefSHarald Welte 						   0, 0, 0);
4830aa62aefSHarald Welte 
4840aa62aefSHarald Welte 	return 0;
4850aa62aefSHarald Welte }
4860aa62aefSHarald Welte 
4870aa62aefSHarald Welte static struct snd_kcontrol_new via_hp_mixer[] = {
4880aa62aefSHarald Welte 	{
4890aa62aefSHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4900aa62aefSHarald Welte 		.name = "Independent HP",
4910aa62aefSHarald Welte 		.count = 1,
4920aa62aefSHarald Welte 		.info = via_independent_hp_info,
4930aa62aefSHarald Welte 		.get = via_independent_hp_get,
4940aa62aefSHarald Welte 		.put = via_independent_hp_put,
4950aa62aefSHarald Welte 	},
4960aa62aefSHarald Welte 	{ } /* end */
4970aa62aefSHarald Welte };
4980aa62aefSHarald Welte 
499c577b8a1SJoseph Chan /* capture mixer elements */
500c577b8a1SJoseph Chan static struct snd_kcontrol_new vt1708_capture_mixer[] = {
501c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
502c577b8a1SJoseph Chan 	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
503c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
504c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
505c577b8a1SJoseph Chan 	{
506c577b8a1SJoseph Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
507c577b8a1SJoseph Chan 		/* The multiple "Capture Source" controls confuse alsamixer
508c577b8a1SJoseph Chan 		 * So call somewhat different..
509c577b8a1SJoseph Chan 		 */
510c577b8a1SJoseph Chan 		/* .name = "Capture Source", */
511c577b8a1SJoseph Chan 		.name = "Input Source",
512c577b8a1SJoseph Chan 		.count = 1,
513c577b8a1SJoseph Chan 		.info = via_mux_enum_info,
514c577b8a1SJoseph Chan 		.get = via_mux_enum_get,
515c577b8a1SJoseph Chan 		.put = via_mux_enum_put,
516c577b8a1SJoseph Chan 	},
517c577b8a1SJoseph Chan 	{ } /* end */
518c577b8a1SJoseph Chan };
519c577b8a1SJoseph Chan /*
520c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
521c577b8a1SJoseph Chan  */
522c577b8a1SJoseph Chan static struct hda_verb vt1708_volume_init_verbs[] = {
523c577b8a1SJoseph Chan 	/*
524c577b8a1SJoseph Chan 	 * Unmute ADC0-1 and set the default input to mic-in
525c577b8a1SJoseph Chan 	 */
526c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
527c577b8a1SJoseph Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
528c577b8a1SJoseph Chan 
529c577b8a1SJoseph Chan 
530f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
531c577b8a1SJoseph Chan 	 * mixer widget
532c577b8a1SJoseph Chan 	 */
533c577b8a1SJoseph Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
534f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
535f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
536f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
537f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
538f7278fd0SJosepch Chan 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
539c577b8a1SJoseph Chan 
540c577b8a1SJoseph Chan 	/*
541c577b8a1SJoseph Chan 	 * Set up output mixers (0x19 - 0x1b)
542c577b8a1SJoseph Chan 	 */
543c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
544c577b8a1SJoseph Chan 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
545c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
546c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
547c577b8a1SJoseph Chan 
548c577b8a1SJoseph Chan 	/* Setup default input to PW4 */
549c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
550c577b8a1SJoseph Chan 	/* PW9 Output enable */
551c577b8a1SJoseph Chan 	{0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
552f7278fd0SJosepch Chan 	{ }
553c577b8a1SJoseph Chan };
554c577b8a1SJoseph Chan 
555c577b8a1SJoseph Chan static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
556c577b8a1SJoseph Chan 				 struct hda_codec *codec,
557c577b8a1SJoseph Chan 				 struct snd_pcm_substream *substream)
558c577b8a1SJoseph Chan {
559c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
5609a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
5619a08160bSTakashi Iwai 					     hinfo);
562c577b8a1SJoseph Chan }
563c577b8a1SJoseph Chan 
564c577b8a1SJoseph Chan static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
565c577b8a1SJoseph Chan 				    struct hda_codec *codec,
566c577b8a1SJoseph Chan 				    unsigned int stream_tag,
567c577b8a1SJoseph Chan 				    unsigned int format,
568c577b8a1SJoseph Chan 				    struct snd_pcm_substream *substream)
569c577b8a1SJoseph Chan {
570c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
571c577b8a1SJoseph Chan 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
572c577b8a1SJoseph Chan 						stream_tag, format, substream);
573c577b8a1SJoseph Chan }
574c577b8a1SJoseph Chan 
575c577b8a1SJoseph Chan static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
576c577b8a1SJoseph Chan 				    struct hda_codec *codec,
577c577b8a1SJoseph Chan 				    struct snd_pcm_substream *substream)
578c577b8a1SJoseph Chan {
579c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
580c577b8a1SJoseph Chan 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
581c577b8a1SJoseph Chan }
582c577b8a1SJoseph Chan 
5830aa62aefSHarald Welte 
5840aa62aefSHarald Welte static void playback_multi_pcm_prep_0(struct hda_codec *codec,
5850aa62aefSHarald Welte 				      unsigned int stream_tag,
5860aa62aefSHarald Welte 				      unsigned int format,
5870aa62aefSHarald Welte 				      struct snd_pcm_substream *substream)
5880aa62aefSHarald Welte {
5890aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
5900aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
5910aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
5920aa62aefSHarald Welte 	int chs = substream->runtime->channels;
5930aa62aefSHarald Welte 	int i;
5940aa62aefSHarald Welte 
5950aa62aefSHarald Welte 	mutex_lock(&codec->spdif_mutex);
5960aa62aefSHarald Welte 	if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
5970aa62aefSHarald Welte 		if (chs == 2 &&
5980aa62aefSHarald Welte 		    snd_hda_is_supported_format(codec, mout->dig_out_nid,
5990aa62aefSHarald Welte 						format) &&
6000aa62aefSHarald Welte 		    !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
6010aa62aefSHarald Welte 			mout->dig_out_used = HDA_DIG_ANALOG_DUP;
6020aa62aefSHarald Welte 			/* turn off SPDIF once; otherwise the IEC958 bits won't
6030aa62aefSHarald Welte 			 * be updated */
6040aa62aefSHarald Welte 			if (codec->spdif_ctls & AC_DIG1_ENABLE)
6050aa62aefSHarald Welte 				snd_hda_codec_write(codec, mout->dig_out_nid, 0,
6060aa62aefSHarald Welte 						    AC_VERB_SET_DIGI_CONVERT_1,
6070aa62aefSHarald Welte 						    codec->spdif_ctls &
6080aa62aefSHarald Welte 							~AC_DIG1_ENABLE & 0xff);
6090aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
6100aa62aefSHarald Welte 						   stream_tag, 0, format);
6110aa62aefSHarald Welte 			/* turn on again (if needed) */
6120aa62aefSHarald Welte 			if (codec->spdif_ctls & AC_DIG1_ENABLE)
6130aa62aefSHarald Welte 				snd_hda_codec_write(codec, mout->dig_out_nid, 0,
6140aa62aefSHarald Welte 						    AC_VERB_SET_DIGI_CONVERT_1,
6150aa62aefSHarald Welte 						    codec->spdif_ctls & 0xff);
6160aa62aefSHarald Welte 		} else {
6170aa62aefSHarald Welte 			mout->dig_out_used = 0;
6180aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
6190aa62aefSHarald Welte 						   0, 0, 0);
6200aa62aefSHarald Welte 		}
6210aa62aefSHarald Welte 	}
6220aa62aefSHarald Welte 	mutex_unlock(&codec->spdif_mutex);
6230aa62aefSHarald Welte 
6240aa62aefSHarald Welte 	/* front */
6250aa62aefSHarald Welte 	snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
6260aa62aefSHarald Welte 				   0, format);
6270aa62aefSHarald Welte 
6280aa62aefSHarald Welte 	if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
6290aa62aefSHarald Welte 	    !spec->hp_independent_mode)
6300aa62aefSHarald Welte 		/* headphone out will just decode front left/right (stereo) */
6310aa62aefSHarald Welte 		snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
6320aa62aefSHarald Welte 					   0, format);
6330aa62aefSHarald Welte 
6340aa62aefSHarald Welte 	/* extra outputs copied from front */
6350aa62aefSHarald Welte 	for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
6360aa62aefSHarald Welte 		if (mout->extra_out_nid[i])
6370aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec,
6380aa62aefSHarald Welte 						   mout->extra_out_nid[i],
6390aa62aefSHarald Welte 						   stream_tag, 0, format);
6400aa62aefSHarald Welte 
6410aa62aefSHarald Welte 	/* surrounds */
6420aa62aefSHarald Welte 	for (i = 1; i < mout->num_dacs; i++) {
6430aa62aefSHarald Welte 		if (chs >= (i + 1) * 2) /* independent out */
6440aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
6450aa62aefSHarald Welte 						   i * 2, format);
6460aa62aefSHarald Welte 		else /* copy front */
6470aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
6480aa62aefSHarald Welte 						   0, format);
6490aa62aefSHarald Welte 	}
6500aa62aefSHarald Welte }
6510aa62aefSHarald Welte 
6520aa62aefSHarald Welte static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
6530aa62aefSHarald Welte 					  struct hda_codec *codec,
6540aa62aefSHarald Welte 					  unsigned int stream_tag,
6550aa62aefSHarald Welte 					  unsigned int format,
6560aa62aefSHarald Welte 					  struct snd_pcm_substream *substream)
6570aa62aefSHarald Welte {
6580aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
6590aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
6600aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
6610aa62aefSHarald Welte 
6620aa62aefSHarald Welte 	if (substream->number == 0)
6630aa62aefSHarald Welte 		playback_multi_pcm_prep_0(codec, stream_tag, format,
6640aa62aefSHarald Welte 					  substream);
6650aa62aefSHarald Welte 	else {
6660aa62aefSHarald Welte 		if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
6670aa62aefSHarald Welte 		    spec->hp_independent_mode)
6680aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
6690aa62aefSHarald Welte 						   stream_tag, 0, format);
6700aa62aefSHarald Welte 	}
6710aa62aefSHarald Welte 
6720aa62aefSHarald Welte 	return 0;
6730aa62aefSHarald Welte }
6740aa62aefSHarald Welte 
6750aa62aefSHarald Welte static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
6760aa62aefSHarald Welte 				    struct hda_codec *codec,
6770aa62aefSHarald Welte 				    struct snd_pcm_substream *substream)
6780aa62aefSHarald Welte {
6790aa62aefSHarald Welte 	struct via_spec *spec = codec->spec;
6800aa62aefSHarald Welte 	struct hda_multi_out *mout = &spec->multiout;
6810aa62aefSHarald Welte 	hda_nid_t *nids = mout->dac_nids;
6820aa62aefSHarald Welte 	int i;
6830aa62aefSHarald Welte 
6840aa62aefSHarald Welte 	if (substream->number == 0) {
6850aa62aefSHarald Welte 		for (i = 0; i < mout->num_dacs; i++)
6860aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
6870aa62aefSHarald Welte 
6880aa62aefSHarald Welte 		if (mout->hp_nid && !spec->hp_independent_mode)
6890aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
6900aa62aefSHarald Welte 						   0, 0, 0);
6910aa62aefSHarald Welte 
6920aa62aefSHarald Welte 		for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
6930aa62aefSHarald Welte 			if (mout->extra_out_nid[i])
6940aa62aefSHarald Welte 				snd_hda_codec_setup_stream(codec,
6950aa62aefSHarald Welte 							mout->extra_out_nid[i],
6960aa62aefSHarald Welte 							0, 0, 0);
6970aa62aefSHarald Welte 		mutex_lock(&codec->spdif_mutex);
6980aa62aefSHarald Welte 		if (mout->dig_out_nid &&
6990aa62aefSHarald Welte 		    mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
7000aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
7010aa62aefSHarald Welte 						   0, 0, 0);
7020aa62aefSHarald Welte 			mout->dig_out_used = 0;
7030aa62aefSHarald Welte 		}
7040aa62aefSHarald Welte 		mutex_unlock(&codec->spdif_mutex);
7050aa62aefSHarald Welte 	} else {
7060aa62aefSHarald Welte 		if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
7070aa62aefSHarald Welte 		    spec->hp_independent_mode)
7080aa62aefSHarald Welte 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
7090aa62aefSHarald Welte 						   0, 0, 0);
7100aa62aefSHarald Welte 	}
7110aa62aefSHarald Welte 
7120aa62aefSHarald Welte 	return 0;
7130aa62aefSHarald Welte }
7140aa62aefSHarald Welte 
715c577b8a1SJoseph Chan /*
716c577b8a1SJoseph Chan  * Digital out
717c577b8a1SJoseph Chan  */
718c577b8a1SJoseph Chan static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
719c577b8a1SJoseph Chan 				     struct hda_codec *codec,
720c577b8a1SJoseph Chan 				     struct snd_pcm_substream *substream)
721c577b8a1SJoseph Chan {
722c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
723c577b8a1SJoseph Chan 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
724c577b8a1SJoseph Chan }
725c577b8a1SJoseph Chan 
726c577b8a1SJoseph Chan static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
727c577b8a1SJoseph Chan 				      struct hda_codec *codec,
728c577b8a1SJoseph Chan 				      struct snd_pcm_substream *substream)
729c577b8a1SJoseph Chan {
730c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
731c577b8a1SJoseph Chan 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
732c577b8a1SJoseph Chan }
733c577b8a1SJoseph Chan 
73498aa34c0SHarald Welte /* setup SPDIF output stream */
73598aa34c0SHarald Welte static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
73698aa34c0SHarald Welte 				 unsigned int stream_tag, unsigned int format)
73798aa34c0SHarald Welte {
73898aa34c0SHarald Welte 	/* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
73998aa34c0SHarald Welte 	if (codec->spdif_ctls & AC_DIG1_ENABLE)
74098aa34c0SHarald Welte 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
74198aa34c0SHarald Welte 				    codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
74298aa34c0SHarald Welte 	snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
74398aa34c0SHarald Welte 	/* turn on again (if needed) */
74498aa34c0SHarald Welte 	if (codec->spdif_ctls & AC_DIG1_ENABLE)
74598aa34c0SHarald Welte 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
74698aa34c0SHarald Welte 				    codec->spdif_ctls & 0xff);
74798aa34c0SHarald Welte }
74898aa34c0SHarald Welte 
7495691ec7fSHarald Welte static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
75098aa34c0SHarald Welte 					struct hda_codec *codec,
75198aa34c0SHarald Welte 					unsigned int stream_tag,
75298aa34c0SHarald Welte 					unsigned int format,
75398aa34c0SHarald Welte 					struct snd_pcm_substream *substream)
75498aa34c0SHarald Welte {
75598aa34c0SHarald Welte 	struct via_spec *spec = codec->spec;
7565691ec7fSHarald Welte 	hda_nid_t nid;
7575691ec7fSHarald Welte 
7585691ec7fSHarald Welte 	/* 1st or 2nd S/PDIF */
7595691ec7fSHarald Welte 	if (substream->number == 0)
7605691ec7fSHarald Welte 		nid = spec->multiout.dig_out_nid;
7615691ec7fSHarald Welte 	else if (substream->number == 1)
7625691ec7fSHarald Welte 		nid = spec->extra_dig_out_nid;
7635691ec7fSHarald Welte 	else
7645691ec7fSHarald Welte 		return -1;
76598aa34c0SHarald Welte 
76698aa34c0SHarald Welte 	mutex_lock(&codec->spdif_mutex);
7675691ec7fSHarald Welte 	setup_dig_playback_stream(codec, nid, stream_tag, format);
76898aa34c0SHarald Welte 	mutex_unlock(&codec->spdif_mutex);
76998aa34c0SHarald Welte 	return 0;
77098aa34c0SHarald Welte }
77198aa34c0SHarald Welte 
772c577b8a1SJoseph Chan /*
773c577b8a1SJoseph Chan  * Analog capture
774c577b8a1SJoseph Chan  */
775c577b8a1SJoseph Chan static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
776c577b8a1SJoseph Chan 				   struct hda_codec *codec,
777c577b8a1SJoseph Chan 				   unsigned int stream_tag,
778c577b8a1SJoseph Chan 				   unsigned int format,
779c577b8a1SJoseph Chan 				   struct snd_pcm_substream *substream)
780c577b8a1SJoseph Chan {
781c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
782c577b8a1SJoseph Chan 
783c577b8a1SJoseph Chan 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
784c577b8a1SJoseph Chan 				   stream_tag, 0, format);
785c577b8a1SJoseph Chan 	return 0;
786c577b8a1SJoseph Chan }
787c577b8a1SJoseph Chan 
788c577b8a1SJoseph Chan static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
789c577b8a1SJoseph Chan 				   struct hda_codec *codec,
790c577b8a1SJoseph Chan 				   struct snd_pcm_substream *substream)
791c577b8a1SJoseph Chan {
792c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
793888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
794c577b8a1SJoseph Chan 	return 0;
795c577b8a1SJoseph Chan }
796c577b8a1SJoseph Chan 
797c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_analog_playback = {
7980aa62aefSHarald Welte 	.substreams = 2,
799c577b8a1SJoseph Chan 	.channels_min = 2,
800c577b8a1SJoseph Chan 	.channels_max = 8,
801c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
802c577b8a1SJoseph Chan 	.ops = {
803c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
8040aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
8050aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
806c577b8a1SJoseph Chan 	},
807c577b8a1SJoseph Chan };
808c577b8a1SJoseph Chan 
809bc9b5623STakashi Iwai static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
810bc9b5623STakashi Iwai 	.substreams = 1,
811bc9b5623STakashi Iwai 	.channels_min = 2,
812bc9b5623STakashi Iwai 	.channels_max = 8,
813bc9b5623STakashi Iwai 	.nid = 0x10, /* NID to query formats and rates */
814bc9b5623STakashi Iwai 	/* We got noisy outputs on the right channel on VT1708 when
815bc9b5623STakashi Iwai 	 * 24bit samples are used.  Until any workaround is found,
816bc9b5623STakashi Iwai 	 * disable the 24bit format, so far.
817bc9b5623STakashi Iwai 	 */
818bc9b5623STakashi Iwai 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
819bc9b5623STakashi Iwai 	.ops = {
820bc9b5623STakashi Iwai 		.open = via_playback_pcm_open,
821bc9b5623STakashi Iwai 		.prepare = via_playback_pcm_prepare,
822bc9b5623STakashi Iwai 		.cleanup = via_playback_pcm_cleanup
823bc9b5623STakashi Iwai 	},
824bc9b5623STakashi Iwai };
825bc9b5623STakashi Iwai 
826c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_analog_capture = {
827c577b8a1SJoseph Chan 	.substreams = 2,
828c577b8a1SJoseph Chan 	.channels_min = 2,
829c577b8a1SJoseph Chan 	.channels_max = 2,
830c577b8a1SJoseph Chan 	.nid = 0x15, /* NID to query formats and rates */
831c577b8a1SJoseph Chan 	.ops = {
832c577b8a1SJoseph Chan 		.prepare = via_capture_pcm_prepare,
833c577b8a1SJoseph Chan 		.cleanup = via_capture_pcm_cleanup
834c577b8a1SJoseph Chan 	},
835c577b8a1SJoseph Chan };
836c577b8a1SJoseph Chan 
837c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_digital_playback = {
838c577b8a1SJoseph Chan 	.substreams = 1,
839c577b8a1SJoseph Chan 	.channels_min = 2,
840c577b8a1SJoseph Chan 	.channels_max = 2,
841c577b8a1SJoseph Chan 	/* NID is set in via_build_pcms */
842c577b8a1SJoseph Chan 	.ops = {
843c577b8a1SJoseph Chan 		.open = via_dig_playback_pcm_open,
8446b97eb45STakashi Iwai 		.close = via_dig_playback_pcm_close,
8456b97eb45STakashi Iwai 		.prepare = via_dig_playback_pcm_prepare
846c577b8a1SJoseph Chan 	},
847c577b8a1SJoseph Chan };
848c577b8a1SJoseph Chan 
849c577b8a1SJoseph Chan static struct hda_pcm_stream vt1708_pcm_digital_capture = {
850c577b8a1SJoseph Chan 	.substreams = 1,
851c577b8a1SJoseph Chan 	.channels_min = 2,
852c577b8a1SJoseph Chan 	.channels_max = 2,
853c577b8a1SJoseph Chan };
854c577b8a1SJoseph Chan 
855c577b8a1SJoseph Chan static int via_build_controls(struct hda_codec *codec)
856c577b8a1SJoseph Chan {
857c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
858c577b8a1SJoseph Chan 	int err;
859c577b8a1SJoseph Chan 	int i;
860c577b8a1SJoseph Chan 
861c577b8a1SJoseph Chan 	for (i = 0; i < spec->num_mixers; i++) {
862c577b8a1SJoseph Chan 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
863c577b8a1SJoseph Chan 		if (err < 0)
864c577b8a1SJoseph Chan 			return err;
865c577b8a1SJoseph Chan 	}
866c577b8a1SJoseph Chan 
867c577b8a1SJoseph Chan 	if (spec->multiout.dig_out_nid) {
868c577b8a1SJoseph Chan 		err = snd_hda_create_spdif_out_ctls(codec,
869c577b8a1SJoseph Chan 						    spec->multiout.dig_out_nid);
870c577b8a1SJoseph Chan 		if (err < 0)
871c577b8a1SJoseph Chan 			return err;
8729a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
8739a08160bSTakashi Iwai 						    &spec->multiout);
8749a08160bSTakashi Iwai 		if (err < 0)
8759a08160bSTakashi Iwai 			return err;
8769a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
87798aa34c0SHarald Welte 
87898aa34c0SHarald Welte 		if (spec->extra_dig_out_nid) {
87998aa34c0SHarald Welte 			err = snd_hda_create_spdif_out_ctls(codec,
88098aa34c0SHarald Welte 						    spec->extra_dig_out_nid);
88198aa34c0SHarald Welte 			if (err < 0)
88298aa34c0SHarald Welte 				return err;
88398aa34c0SHarald Welte 		}
884c577b8a1SJoseph Chan 	}
885c577b8a1SJoseph Chan 	if (spec->dig_in_nid) {
886c577b8a1SJoseph Chan 		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
887c577b8a1SJoseph Chan 		if (err < 0)
888c577b8a1SJoseph Chan 			return err;
889c577b8a1SJoseph Chan 	}
890603c4019STakashi Iwai 	via_free_kctls(codec); /* no longer needed */
891c577b8a1SJoseph Chan 	return 0;
892c577b8a1SJoseph Chan }
893c577b8a1SJoseph Chan 
894c577b8a1SJoseph Chan static int via_build_pcms(struct hda_codec *codec)
895c577b8a1SJoseph Chan {
896c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
897c577b8a1SJoseph Chan 	struct hda_pcm *info = spec->pcm_rec;
898c577b8a1SJoseph Chan 
899c577b8a1SJoseph Chan 	codec->num_pcms = 1;
900c577b8a1SJoseph Chan 	codec->pcm_info = info;
901c577b8a1SJoseph Chan 
902c577b8a1SJoseph Chan 	info->name = spec->stream_name_analog;
903c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
904c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
905c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
906c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
907c577b8a1SJoseph Chan 
908c577b8a1SJoseph Chan 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
909c577b8a1SJoseph Chan 		spec->multiout.max_channels;
910c577b8a1SJoseph Chan 
911c577b8a1SJoseph Chan 	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
912c577b8a1SJoseph Chan 		codec->num_pcms++;
913c577b8a1SJoseph Chan 		info++;
914c577b8a1SJoseph Chan 		info->name = spec->stream_name_digital;
9157ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
916c577b8a1SJoseph Chan 		if (spec->multiout.dig_out_nid) {
917c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
918c577b8a1SJoseph Chan 				*(spec->stream_digital_playback);
919c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
920c577b8a1SJoseph Chan 				spec->multiout.dig_out_nid;
921c577b8a1SJoseph Chan 		}
922c577b8a1SJoseph Chan 		if (spec->dig_in_nid) {
923c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
924c577b8a1SJoseph Chan 				*(spec->stream_digital_capture);
925c577b8a1SJoseph Chan 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
926c577b8a1SJoseph Chan 				spec->dig_in_nid;
927c577b8a1SJoseph Chan 		}
928c577b8a1SJoseph Chan 	}
929c577b8a1SJoseph Chan 
930c577b8a1SJoseph Chan 	return 0;
931c577b8a1SJoseph Chan }
932c577b8a1SJoseph Chan 
933c577b8a1SJoseph Chan static void via_free(struct hda_codec *codec)
934c577b8a1SJoseph Chan {
935c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
936c577b8a1SJoseph Chan 
937c577b8a1SJoseph Chan 	if (!spec)
938c577b8a1SJoseph Chan 		return;
939c577b8a1SJoseph Chan 
940603c4019STakashi Iwai 	via_free_kctls(codec);
941c577b8a1SJoseph Chan 	kfree(codec->spec);
942c577b8a1SJoseph Chan }
943c577b8a1SJoseph Chan 
94469e52a80SHarald Welte /* mute internal speaker if HP is plugged */
94569e52a80SHarald Welte static void via_hp_automute(struct hda_codec *codec)
94669e52a80SHarald Welte {
94769e52a80SHarald Welte 	unsigned int present;
94869e52a80SHarald Welte 	struct via_spec *spec = codec->spec;
94969e52a80SHarald Welte 
95069e52a80SHarald Welte 	present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
95169e52a80SHarald Welte 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
95269e52a80SHarald Welte 	snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
95369e52a80SHarald Welte 				 HDA_OUTPUT, 0, HDA_AMP_MUTE,
95469e52a80SHarald Welte 				 present ? HDA_AMP_MUTE : 0);
95569e52a80SHarald Welte }
95669e52a80SHarald Welte 
95769e52a80SHarald Welte static void via_gpio_control(struct hda_codec *codec)
95869e52a80SHarald Welte {
95969e52a80SHarald Welte 	unsigned int gpio_data;
96069e52a80SHarald Welte 	unsigned int vol_counter;
96169e52a80SHarald Welte 	unsigned int vol;
96269e52a80SHarald Welte 	unsigned int master_vol;
96369e52a80SHarald Welte 
96469e52a80SHarald Welte 	struct via_spec *spec = codec->spec;
96569e52a80SHarald Welte 
96669e52a80SHarald Welte 	gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
96769e52a80SHarald Welte 				       AC_VERB_GET_GPIO_DATA, 0) & 0x03;
96869e52a80SHarald Welte 
96969e52a80SHarald Welte 	vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
97069e52a80SHarald Welte 					  0xF84, 0) & 0x3F0000) >> 16;
97169e52a80SHarald Welte 
97269e52a80SHarald Welte 	vol = vol_counter & 0x1F;
97369e52a80SHarald Welte 	master_vol = snd_hda_codec_read(codec, 0x1A, 0,
97469e52a80SHarald Welte 					AC_VERB_GET_AMP_GAIN_MUTE,
97569e52a80SHarald Welte 					AC_AMP_GET_INPUT);
97669e52a80SHarald Welte 
97769e52a80SHarald Welte 	if (gpio_data == 0x02) {
97869e52a80SHarald Welte 		/* unmute line out */
97969e52a80SHarald Welte 		snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
98069e52a80SHarald Welte 					 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
98169e52a80SHarald Welte 
98269e52a80SHarald Welte 		if (vol_counter & 0x20) {
98369e52a80SHarald Welte 			/* decrease volume */
98469e52a80SHarald Welte 			if (vol > master_vol)
98569e52a80SHarald Welte 				vol = master_vol;
98669e52a80SHarald Welte 			snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
98769e52a80SHarald Welte 						 0, HDA_AMP_VOLMASK,
98869e52a80SHarald Welte 						 master_vol-vol);
98969e52a80SHarald Welte 		} else {
99069e52a80SHarald Welte 			/* increase volume */
99169e52a80SHarald Welte 			snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
99269e52a80SHarald Welte 					 HDA_AMP_VOLMASK,
99369e52a80SHarald Welte 					 ((master_vol+vol) > 0x2A) ? 0x2A :
99469e52a80SHarald Welte 					  (master_vol+vol));
99569e52a80SHarald Welte 		}
99669e52a80SHarald Welte 	} else if (!(gpio_data & 0x02)) {
99769e52a80SHarald Welte 		/* mute line out */
99869e52a80SHarald Welte 		snd_hda_codec_amp_stereo(codec,
99969e52a80SHarald Welte 					 spec->autocfg.line_out_pins[0],
100069e52a80SHarald Welte 					 HDA_OUTPUT, 0, HDA_AMP_MUTE,
100169e52a80SHarald Welte 					 HDA_AMP_MUTE);
100269e52a80SHarald Welte 	}
100369e52a80SHarald Welte }
100469e52a80SHarald Welte 
100569e52a80SHarald Welte /* unsolicited event for jack sensing */
100669e52a80SHarald Welte static void via_unsol_event(struct hda_codec *codec,
100769e52a80SHarald Welte 				  unsigned int res)
100869e52a80SHarald Welte {
100969e52a80SHarald Welte 	res >>= 26;
101069e52a80SHarald Welte 	if (res == VIA_HP_EVENT)
101169e52a80SHarald Welte 		via_hp_automute(codec);
101269e52a80SHarald Welte 	else if (res == VIA_GPIO_EVENT)
101369e52a80SHarald Welte 		via_gpio_control(codec);
101469e52a80SHarald Welte }
101569e52a80SHarald Welte 
10165691ec7fSHarald Welte static hda_nid_t slave_dig_outs[] = {
10175691ec7fSHarald Welte 	0,
10185691ec7fSHarald Welte };
10195691ec7fSHarald Welte 
1020c577b8a1SJoseph Chan static int via_init(struct hda_codec *codec)
1021c577b8a1SJoseph Chan {
1022c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
102369e52a80SHarald Welte 	int i;
102469e52a80SHarald Welte 	for (i = 0; i < spec->num_iverbs; i++)
102569e52a80SHarald Welte 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
102669e52a80SHarald Welte 
1027f7278fd0SJosepch Chan 	/* Lydia Add for EAPD enable */
1028f7278fd0SJosepch Chan 	if (!spec->dig_in_nid) { /* No Digital In connection */
1029f7278fd0SJosepch Chan 		if (IS_VT1708_VENDORID(codec->vendor_id)) {
1030f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1031f7278fd0SJosepch Chan 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
103212b74c80STakashi Iwai 					    PIN_OUT);
1033f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1034f7278fd0SJosepch Chan 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1035f7278fd0SJosepch Chan 		} else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
1036f7278fd0SJosepch Chan 			   IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
1037f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1038f7278fd0SJosepch Chan 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
103912b74c80STakashi Iwai 					    PIN_OUT);
1040f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1041f7278fd0SJosepch Chan 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1042f7278fd0SJosepch Chan 		} else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
1043f7278fd0SJosepch Chan 			   IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
1044f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1045f7278fd0SJosepch Chan 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
104612b74c80STakashi Iwai 					    PIN_OUT);
1047f7278fd0SJosepch Chan 			snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1048f7278fd0SJosepch Chan 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1049f7278fd0SJosepch Chan 		}
105012b74c80STakashi Iwai 	} else /* enable SPDIF-input pin */
105112b74c80STakashi Iwai 		snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
105212b74c80STakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1053f7278fd0SJosepch Chan 
10545691ec7fSHarald Welte 	/* no slave outs */
10555691ec7fSHarald Welte 	codec->slave_dig_outs = slave_dig_outs;
10565691ec7fSHarald Welte 
1057c577b8a1SJoseph Chan  	return 0;
1058c577b8a1SJoseph Chan }
1059c577b8a1SJoseph Chan 
1060cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1061cb53c626STakashi Iwai static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1062cb53c626STakashi Iwai {
1063cb53c626STakashi Iwai 	struct via_spec *spec = codec->spec;
1064cb53c626STakashi Iwai 	return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1065cb53c626STakashi Iwai }
1066cb53c626STakashi Iwai #endif
1067cb53c626STakashi Iwai 
1068c577b8a1SJoseph Chan /*
1069c577b8a1SJoseph Chan  */
1070c577b8a1SJoseph Chan static struct hda_codec_ops via_patch_ops = {
1071c577b8a1SJoseph Chan 	.build_controls = via_build_controls,
1072c577b8a1SJoseph Chan 	.build_pcms = via_build_pcms,
1073c577b8a1SJoseph Chan 	.init = via_init,
1074c577b8a1SJoseph Chan 	.free = via_free,
1075cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1076cb53c626STakashi Iwai 	.check_power_status = via_check_power_status,
1077cb53c626STakashi Iwai #endif
1078c577b8a1SJoseph Chan };
1079c577b8a1SJoseph Chan 
1080c577b8a1SJoseph Chan /* fill in the dac_nids table from the parsed pin configuration */
1081c577b8a1SJoseph Chan static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1082c577b8a1SJoseph Chan 				     const struct auto_pin_cfg *cfg)
1083c577b8a1SJoseph Chan {
1084c577b8a1SJoseph Chan 	int i;
1085c577b8a1SJoseph Chan 	hda_nid_t nid;
1086c577b8a1SJoseph Chan 
1087c577b8a1SJoseph Chan 	spec->multiout.num_dacs = cfg->line_outs;
1088c577b8a1SJoseph Chan 
1089c577b8a1SJoseph Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
1090c577b8a1SJoseph Chan 
1091c577b8a1SJoseph Chan 	for(i = 0; i < 4; i++) {
1092c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
1093c577b8a1SJoseph Chan 		if (nid) {
1094c577b8a1SJoseph Chan 			/* config dac list */
1095c577b8a1SJoseph Chan 			switch (i) {
1096c577b8a1SJoseph Chan 			case AUTO_SEQ_FRONT:
1097c577b8a1SJoseph Chan 				spec->multiout.dac_nids[i] = 0x10;
1098c577b8a1SJoseph Chan 				break;
1099c577b8a1SJoseph Chan 			case AUTO_SEQ_CENLFE:
1100c577b8a1SJoseph Chan 				spec->multiout.dac_nids[i] = 0x12;
1101c577b8a1SJoseph Chan 				break;
1102c577b8a1SJoseph Chan 			case AUTO_SEQ_SURROUND:
1103fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
1104c577b8a1SJoseph Chan 				break;
1105c577b8a1SJoseph Chan 			case AUTO_SEQ_SIDE:
1106fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x13;
1107c577b8a1SJoseph Chan 				break;
1108c577b8a1SJoseph Chan 			}
1109c577b8a1SJoseph Chan 		}
1110c577b8a1SJoseph Chan 	}
1111c577b8a1SJoseph Chan 
1112c577b8a1SJoseph Chan 	return 0;
1113c577b8a1SJoseph Chan }
1114c577b8a1SJoseph Chan 
1115c577b8a1SJoseph Chan /* add playback controls from the parsed DAC table */
1116c577b8a1SJoseph Chan static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1117c577b8a1SJoseph Chan 					     const struct auto_pin_cfg *cfg)
1118c577b8a1SJoseph Chan {
1119c577b8a1SJoseph Chan 	char name[32];
1120c577b8a1SJoseph Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1121c577b8a1SJoseph Chan 	hda_nid_t nid, nid_vol = 0;
1122c577b8a1SJoseph Chan 	int i, err;
1123c577b8a1SJoseph Chan 
1124c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1125c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
1126c577b8a1SJoseph Chan 
1127c577b8a1SJoseph Chan 		if (!nid)
1128c577b8a1SJoseph Chan 			continue;
1129c577b8a1SJoseph Chan 
1130c577b8a1SJoseph Chan 		if (i != AUTO_SEQ_FRONT)
1131fb4cb772SHarald Welte 			nid_vol = 0x18 + i;
1132c577b8a1SJoseph Chan 
1133c577b8a1SJoseph Chan 		if (i == AUTO_SEQ_CENLFE) {
1134c577b8a1SJoseph Chan 			/* Center/LFE */
1135c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1136c577b8a1SJoseph Chan 					"Center Playback Volume",
1137f7278fd0SJosepch Chan 					HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1138f7278fd0SJosepch Chan 							    HDA_OUTPUT));
1139c577b8a1SJoseph Chan 			if (err < 0)
1140c577b8a1SJoseph Chan 				return err;
1141c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1142c577b8a1SJoseph Chan 					      "LFE Playback Volume",
1143f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1144f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1145c577b8a1SJoseph Chan 			if (err < 0)
1146c577b8a1SJoseph Chan 				return err;
1147c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1148c577b8a1SJoseph Chan 					      "Center Playback Switch",
1149f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1150f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1151c577b8a1SJoseph Chan 			if (err < 0)
1152c577b8a1SJoseph Chan 				return err;
1153c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1154c577b8a1SJoseph Chan 					      "LFE Playback Switch",
1155f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1156f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1157c577b8a1SJoseph Chan 			if (err < 0)
1158c577b8a1SJoseph Chan 				return err;
1159c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_FRONT){
1160c577b8a1SJoseph Chan 			/* add control to mixer index 0 */
1161c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1162c577b8a1SJoseph Chan 					      "Master Front Playback Volume",
1163f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1164f7278fd0SJosepch Chan 								  HDA_INPUT));
1165c577b8a1SJoseph Chan 			if (err < 0)
1166c577b8a1SJoseph Chan 				return err;
1167c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1168c577b8a1SJoseph Chan 					      "Master Front Playback Switch",
1169f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1170f7278fd0SJosepch Chan 								  HDA_INPUT));
1171c577b8a1SJoseph Chan 			if (err < 0)
1172c577b8a1SJoseph Chan 				return err;
1173c577b8a1SJoseph Chan 
1174c577b8a1SJoseph Chan 			/* add control to PW3 */
1175c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
1176c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1177f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1178f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1179c577b8a1SJoseph Chan 			if (err < 0)
1180c577b8a1SJoseph Chan 				return err;
1181c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
1182c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1183f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1184f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1185c577b8a1SJoseph Chan 			if (err < 0)
1186c577b8a1SJoseph Chan 				return err;
1187c577b8a1SJoseph Chan 		} else {
1188c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
1189c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1190f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1191f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1192c577b8a1SJoseph Chan 			if (err < 0)
1193c577b8a1SJoseph Chan 				return err;
1194c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
1195c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1196f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1197f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1198c577b8a1SJoseph Chan 			if (err < 0)
1199c577b8a1SJoseph Chan 				return err;
1200c577b8a1SJoseph Chan 		}
1201c577b8a1SJoseph Chan 	}
1202c577b8a1SJoseph Chan 
1203c577b8a1SJoseph Chan 	return 0;
1204c577b8a1SJoseph Chan }
1205c577b8a1SJoseph Chan 
12060aa62aefSHarald Welte static void create_hp_imux(struct via_spec *spec)
12070aa62aefSHarald Welte {
12080aa62aefSHarald Welte 	int i;
12090aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[1];
12100aa62aefSHarald Welte 	static const char *texts[] = { "OFF", "ON", NULL};
12110aa62aefSHarald Welte 
12120aa62aefSHarald Welte 	/* for hp mode select */
12130aa62aefSHarald Welte 	i = 0;
12140aa62aefSHarald Welte 	while (texts[i] != NULL) {
12150aa62aefSHarald Welte 		imux->items[imux->num_items].label =  texts[i];
12160aa62aefSHarald Welte 		imux->items[imux->num_items].index = i;
12170aa62aefSHarald Welte 		imux->num_items++;
12180aa62aefSHarald Welte 		i++;
12190aa62aefSHarald Welte 	}
12200aa62aefSHarald Welte 
12210aa62aefSHarald Welte 	spec->hp_mux = &spec->private_imux[1];
12220aa62aefSHarald Welte }
12230aa62aefSHarald Welte 
1224c577b8a1SJoseph Chan static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1225c577b8a1SJoseph Chan {
1226c577b8a1SJoseph Chan 	int err;
1227c577b8a1SJoseph Chan 
1228c577b8a1SJoseph Chan 	if (!pin)
1229c577b8a1SJoseph Chan 		return 0;
1230c577b8a1SJoseph Chan 
1231c577b8a1SJoseph Chan 	spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1232c577b8a1SJoseph Chan 
1233c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1234c577b8a1SJoseph Chan 			      "Headphone Playback Volume",
1235c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1236c577b8a1SJoseph Chan 	if (err < 0)
1237c577b8a1SJoseph Chan 		return err;
1238c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1239c577b8a1SJoseph Chan 			      "Headphone Playback Switch",
1240c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1241c577b8a1SJoseph Chan 	if (err < 0)
1242c577b8a1SJoseph Chan 		return err;
1243c577b8a1SJoseph Chan 
12440aa62aefSHarald Welte 	create_hp_imux(spec);
12450aa62aefSHarald Welte 
1246c577b8a1SJoseph Chan 	return 0;
1247c577b8a1SJoseph Chan }
1248c577b8a1SJoseph Chan 
1249c577b8a1SJoseph Chan /* create playback/capture controls for input pins */
1250c577b8a1SJoseph Chan static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1251c577b8a1SJoseph Chan 						const struct auto_pin_cfg *cfg)
1252c577b8a1SJoseph Chan {
1253c577b8a1SJoseph Chan 	static char *labels[] = {
1254c577b8a1SJoseph Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1255c577b8a1SJoseph Chan 	};
12560aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
1257c577b8a1SJoseph Chan 	int i, err, idx = 0;
1258c577b8a1SJoseph Chan 
1259c577b8a1SJoseph Chan 	/* for internal loopback recording select */
1260c577b8a1SJoseph Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
1261c577b8a1SJoseph Chan 	imux->items[imux->num_items].index = idx;
1262c577b8a1SJoseph Chan 	imux->num_items++;
1263c577b8a1SJoseph Chan 
1264c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
1265c577b8a1SJoseph Chan 		if (!cfg->input_pins[i])
1266c577b8a1SJoseph Chan 			continue;
1267c577b8a1SJoseph Chan 
1268c577b8a1SJoseph Chan 		switch (cfg->input_pins[i]) {
1269c577b8a1SJoseph Chan 		case 0x1d: /* Mic */
1270c577b8a1SJoseph Chan 			idx = 2;
1271c577b8a1SJoseph Chan 			break;
1272c577b8a1SJoseph Chan 
1273c577b8a1SJoseph Chan 		case 0x1e: /* Line In */
1274c577b8a1SJoseph Chan 			idx = 3;
1275c577b8a1SJoseph Chan 			break;
1276c577b8a1SJoseph Chan 
1277c577b8a1SJoseph Chan 		case 0x21: /* Front Mic */
1278c577b8a1SJoseph Chan 			idx = 4;
1279c577b8a1SJoseph Chan 			break;
1280c577b8a1SJoseph Chan 
1281c577b8a1SJoseph Chan 		case 0x24: /* CD */
1282c577b8a1SJoseph Chan 			idx = 1;
1283c577b8a1SJoseph Chan 			break;
1284c577b8a1SJoseph Chan 		}
1285c577b8a1SJoseph Chan 		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1286c577b8a1SJoseph Chan 					   idx, 0x17);
1287c577b8a1SJoseph Chan 		if (err < 0)
1288c577b8a1SJoseph Chan 			return err;
1289c577b8a1SJoseph Chan 		imux->items[imux->num_items].label = labels[i];
1290c577b8a1SJoseph Chan 		imux->items[imux->num_items].index = idx;
1291c577b8a1SJoseph Chan 		imux->num_items++;
1292c577b8a1SJoseph Chan 	}
1293c577b8a1SJoseph Chan 	return 0;
1294c577b8a1SJoseph Chan }
1295c577b8a1SJoseph Chan 
1296cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1297cb53c626STakashi Iwai static struct hda_amp_list vt1708_loopbacks[] = {
1298cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 1 },
1299cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 2 },
1300cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 3 },
1301cb53c626STakashi Iwai 	{ 0x17, HDA_INPUT, 4 },
1302cb53c626STakashi Iwai 	{ } /* end */
1303cb53c626STakashi Iwai };
1304cb53c626STakashi Iwai #endif
1305cb53c626STakashi Iwai 
130676d9b0ddSHarald Welte static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
130776d9b0ddSHarald Welte {
130876d9b0ddSHarald Welte 	unsigned int def_conf;
130976d9b0ddSHarald Welte 	unsigned char seqassoc;
131076d9b0ddSHarald Welte 
1311*2f334f92STakashi Iwai 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
131276d9b0ddSHarald Welte 	seqassoc = (unsigned char) get_defcfg_association(def_conf);
131376d9b0ddSHarald Welte 	seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
131476d9b0ddSHarald Welte 	if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
131576d9b0ddSHarald Welte 		if (seqassoc == 0xff) {
131676d9b0ddSHarald Welte 			def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1317*2f334f92STakashi Iwai 			snd_hda_codec_set_pincfg(codec, nid, def_conf);
131876d9b0ddSHarald Welte 		}
131976d9b0ddSHarald Welte 	}
132076d9b0ddSHarald Welte 
132176d9b0ddSHarald Welte 	return;
132276d9b0ddSHarald Welte }
132376d9b0ddSHarald Welte 
1324c577b8a1SJoseph Chan static int vt1708_parse_auto_config(struct hda_codec *codec)
1325c577b8a1SJoseph Chan {
1326c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1327c577b8a1SJoseph Chan 	int err;
1328c577b8a1SJoseph Chan 
132976d9b0ddSHarald Welte 	/* Add HP and CD pin config connect bit re-config action */
133076d9b0ddSHarald Welte 	vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
133176d9b0ddSHarald Welte 	vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
133276d9b0ddSHarald Welte 
1333c577b8a1SJoseph Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1334c577b8a1SJoseph Chan 	if (err < 0)
1335c577b8a1SJoseph Chan 		return err;
1336c577b8a1SJoseph Chan 	err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1337c577b8a1SJoseph Chan 	if (err < 0)
1338c577b8a1SJoseph Chan 		return err;
1339c577b8a1SJoseph Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1340c577b8a1SJoseph Chan 		return 0; /* can't find valid BIOS pin config */
1341c577b8a1SJoseph Chan 
1342c577b8a1SJoseph Chan 	err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1343c577b8a1SJoseph Chan 	if (err < 0)
1344c577b8a1SJoseph Chan 		return err;
1345c577b8a1SJoseph Chan 	err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1346c577b8a1SJoseph Chan 	if (err < 0)
1347c577b8a1SJoseph Chan 		return err;
1348c577b8a1SJoseph Chan 	err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1349c577b8a1SJoseph Chan 	if (err < 0)
1350c577b8a1SJoseph Chan 		return err;
1351c577b8a1SJoseph Chan 
1352c577b8a1SJoseph Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1353c577b8a1SJoseph Chan 
13540852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
1355c577b8a1SJoseph Chan 		spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1356c577b8a1SJoseph Chan 	if (spec->autocfg.dig_in_pin)
1357c577b8a1SJoseph Chan 		spec->dig_in_nid = VT1708_DIGIN_NID;
1358c577b8a1SJoseph Chan 
1359603c4019STakashi Iwai 	if (spec->kctls.list)
1360603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
1361c577b8a1SJoseph Chan 
136269e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1363c577b8a1SJoseph Chan 
13640aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
13650aa62aefSHarald Welte 
1366f8fdd495SHarald Welte 	if (spec->hp_mux)
13670aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
1368c577b8a1SJoseph Chan 
1369c577b8a1SJoseph Chan 	return 1;
1370c577b8a1SJoseph Chan }
1371c577b8a1SJoseph Chan 
1372c577b8a1SJoseph Chan /* init callback for auto-configuration model -- overriding the default init */
1373c577b8a1SJoseph Chan static int via_auto_init(struct hda_codec *codec)
1374c577b8a1SJoseph Chan {
1375c577b8a1SJoseph Chan 	via_init(codec);
1376c577b8a1SJoseph Chan 	via_auto_init_multi_out(codec);
1377c577b8a1SJoseph Chan 	via_auto_init_hp_out(codec);
1378c577b8a1SJoseph Chan 	via_auto_init_analog_input(codec);
1379c577b8a1SJoseph Chan 	return 0;
1380c577b8a1SJoseph Chan }
1381c577b8a1SJoseph Chan 
1382c577b8a1SJoseph Chan static int patch_vt1708(struct hda_codec *codec)
1383c577b8a1SJoseph Chan {
1384c577b8a1SJoseph Chan 	struct via_spec *spec;
1385c577b8a1SJoseph Chan 	int err;
1386c577b8a1SJoseph Chan 
1387c577b8a1SJoseph Chan 	/* create a codec specific record */
1388eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1389c577b8a1SJoseph Chan 	if (spec == NULL)
1390c577b8a1SJoseph Chan 		return -ENOMEM;
1391c577b8a1SJoseph Chan 
1392c577b8a1SJoseph Chan 	codec->spec = spec;
1393c577b8a1SJoseph Chan 
1394c577b8a1SJoseph Chan 	/* automatic parse from the BIOS config */
1395c577b8a1SJoseph Chan 	err = vt1708_parse_auto_config(codec);
1396c577b8a1SJoseph Chan 	if (err < 0) {
1397c577b8a1SJoseph Chan 		via_free(codec);
1398c577b8a1SJoseph Chan 		return err;
1399c577b8a1SJoseph Chan 	} else if (!err) {
1400c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
1401c577b8a1SJoseph Chan 		       "from BIOS.  Using genenic mode...\n");
1402c577b8a1SJoseph Chan 	}
1403c577b8a1SJoseph Chan 
1404c577b8a1SJoseph Chan 
1405c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1708 Analog";
1406c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1407bc9b5623STakashi Iwai 	/* disable 32bit format on VT1708 */
1408bc9b5623STakashi Iwai 	if (codec->vendor_id == 0x11061708)
1409bc9b5623STakashi Iwai 		spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1410c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1411c577b8a1SJoseph Chan 
1412c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1708 Digital";
1413c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1414c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1415c577b8a1SJoseph Chan 
1416c577b8a1SJoseph Chan 
1417c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
1418c577b8a1SJoseph Chan 		spec->adc_nids = vt1708_adc_nids;
1419c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1420c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1421c577b8a1SJoseph Chan 		spec->num_mixers++;
1422c577b8a1SJoseph Chan 	}
1423c577b8a1SJoseph Chan 
1424c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
1425c577b8a1SJoseph Chan 
1426c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
1427cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1428cb53c626STakashi Iwai 	spec->loopback.amplist = vt1708_loopbacks;
1429cb53c626STakashi Iwai #endif
1430c577b8a1SJoseph Chan 
1431c577b8a1SJoseph Chan 	return 0;
1432c577b8a1SJoseph Chan }
1433c577b8a1SJoseph Chan 
1434c577b8a1SJoseph Chan /* capture mixer elements */
1435c577b8a1SJoseph Chan static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1436c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1437c577b8a1SJoseph Chan 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1438c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1439c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1440c577b8a1SJoseph Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1441c577b8a1SJoseph Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1442c577b8a1SJoseph Chan 	{
1443c577b8a1SJoseph Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1444c577b8a1SJoseph Chan 		/* The multiple "Capture Source" controls confuse alsamixer
1445c577b8a1SJoseph Chan 		 * So call somewhat different..
1446c577b8a1SJoseph Chan 		 */
1447c577b8a1SJoseph Chan 		/* .name = "Capture Source", */
1448c577b8a1SJoseph Chan 		.name = "Input Source",
1449c577b8a1SJoseph Chan 		.count = 1,
1450c577b8a1SJoseph Chan 		.info = via_mux_enum_info,
1451c577b8a1SJoseph Chan 		.get = via_mux_enum_get,
1452c577b8a1SJoseph Chan 		.put = via_mux_enum_put,
1453c577b8a1SJoseph Chan 	},
1454c577b8a1SJoseph Chan 	{ } /* end */
1455c577b8a1SJoseph Chan };
1456c577b8a1SJoseph Chan 
145769e52a80SHarald Welte static struct hda_verb vt1709_uniwill_init_verbs[] = {
145869e52a80SHarald Welte 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
145969e52a80SHarald Welte 	{ }
146069e52a80SHarald Welte };
146169e52a80SHarald Welte 
1462c577b8a1SJoseph Chan /*
1463c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
1464c577b8a1SJoseph Chan  */
1465c577b8a1SJoseph Chan static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1466c577b8a1SJoseph Chan 	/*
1467c577b8a1SJoseph Chan 	 * Unmute ADC0-2 and set the default input to mic-in
1468c577b8a1SJoseph Chan 	 */
1469c577b8a1SJoseph Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1470c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1471c577b8a1SJoseph Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1472c577b8a1SJoseph Chan 
1473c577b8a1SJoseph Chan 
1474f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1475c577b8a1SJoseph Chan 	 * mixer widget
1476c577b8a1SJoseph Chan 	 */
1477c577b8a1SJoseph Chan 	/* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1478f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1479f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1480f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1481f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1482f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1483c577b8a1SJoseph Chan 
1484c577b8a1SJoseph Chan 	/*
1485c577b8a1SJoseph Chan 	 * Set up output selector (0x1a, 0x1b, 0x29)
1486c577b8a1SJoseph Chan 	 */
1487c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
1488c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1489c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1490c577b8a1SJoseph Chan 	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1491c577b8a1SJoseph Chan 
1492c577b8a1SJoseph Chan 	/*
1493c577b8a1SJoseph Chan 	 *  Unmute PW3 and PW4
1494c577b8a1SJoseph Chan 	 */
1495c577b8a1SJoseph Chan 	{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1496c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1497c577b8a1SJoseph Chan 
1498c577b8a1SJoseph Chan 	/* Set input of PW4 as AOW4 */
1499c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1500c577b8a1SJoseph Chan 	/* PW9 Output enable */
1501c577b8a1SJoseph Chan 	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1502c577b8a1SJoseph Chan 	{ }
1503c577b8a1SJoseph Chan };
1504c577b8a1SJoseph Chan 
1505c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1506c577b8a1SJoseph Chan 	.substreams = 1,
1507c577b8a1SJoseph Chan 	.channels_min = 2,
1508c577b8a1SJoseph Chan 	.channels_max = 10,
1509c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
1510c577b8a1SJoseph Chan 	.ops = {
1511c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
1512c577b8a1SJoseph Chan 		.prepare = via_playback_pcm_prepare,
1513c577b8a1SJoseph Chan 		.cleanup = via_playback_pcm_cleanup
1514c577b8a1SJoseph Chan 	},
1515c577b8a1SJoseph Chan };
1516c577b8a1SJoseph Chan 
1517c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1518c577b8a1SJoseph Chan 	.substreams = 1,
1519c577b8a1SJoseph Chan 	.channels_min = 2,
1520c577b8a1SJoseph Chan 	.channels_max = 6,
1521c577b8a1SJoseph Chan 	.nid = 0x10, /* NID to query formats and rates */
1522c577b8a1SJoseph Chan 	.ops = {
1523c577b8a1SJoseph Chan 		.open = via_playback_pcm_open,
1524c577b8a1SJoseph Chan 		.prepare = via_playback_pcm_prepare,
1525c577b8a1SJoseph Chan 		.cleanup = via_playback_pcm_cleanup
1526c577b8a1SJoseph Chan 	},
1527c577b8a1SJoseph Chan };
1528c577b8a1SJoseph Chan 
1529c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1530c577b8a1SJoseph Chan 	.substreams = 2,
1531c577b8a1SJoseph Chan 	.channels_min = 2,
1532c577b8a1SJoseph Chan 	.channels_max = 2,
1533c577b8a1SJoseph Chan 	.nid = 0x14, /* NID to query formats and rates */
1534c577b8a1SJoseph Chan 	.ops = {
1535c577b8a1SJoseph Chan 		.prepare = via_capture_pcm_prepare,
1536c577b8a1SJoseph Chan 		.cleanup = via_capture_pcm_cleanup
1537c577b8a1SJoseph Chan 	},
1538c577b8a1SJoseph Chan };
1539c577b8a1SJoseph Chan 
1540c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1541c577b8a1SJoseph Chan 	.substreams = 1,
1542c577b8a1SJoseph Chan 	.channels_min = 2,
1543c577b8a1SJoseph Chan 	.channels_max = 2,
1544c577b8a1SJoseph Chan 	/* NID is set in via_build_pcms */
1545c577b8a1SJoseph Chan 	.ops = {
1546c577b8a1SJoseph Chan 		.open = via_dig_playback_pcm_open,
1547c577b8a1SJoseph Chan 		.close = via_dig_playback_pcm_close
1548c577b8a1SJoseph Chan 	},
1549c577b8a1SJoseph Chan };
1550c577b8a1SJoseph Chan 
1551c577b8a1SJoseph Chan static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1552c577b8a1SJoseph Chan 	.substreams = 1,
1553c577b8a1SJoseph Chan 	.channels_min = 2,
1554c577b8a1SJoseph Chan 	.channels_max = 2,
1555c577b8a1SJoseph Chan };
1556c577b8a1SJoseph Chan 
1557c577b8a1SJoseph Chan static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1558c577b8a1SJoseph Chan 				     const struct auto_pin_cfg *cfg)
1559c577b8a1SJoseph Chan {
1560c577b8a1SJoseph Chan 	int i;
1561c577b8a1SJoseph Chan 	hda_nid_t nid;
1562c577b8a1SJoseph Chan 
1563c577b8a1SJoseph Chan 	if (cfg->line_outs == 4)  /* 10 channels */
1564c577b8a1SJoseph Chan 		spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1565c577b8a1SJoseph Chan 	else if (cfg->line_outs == 3) /* 6 channels */
1566c577b8a1SJoseph Chan 		spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1567c577b8a1SJoseph Chan 
1568c577b8a1SJoseph Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
1569c577b8a1SJoseph Chan 
1570c577b8a1SJoseph Chan 	if (cfg->line_outs == 4) { /* 10 channels */
1571c577b8a1SJoseph Chan 		for (i = 0; i < cfg->line_outs; i++) {
1572c577b8a1SJoseph Chan 			nid = cfg->line_out_pins[i];
1573c577b8a1SJoseph Chan 			if (nid) {
1574c577b8a1SJoseph Chan 				/* config dac list */
1575c577b8a1SJoseph Chan 				switch (i) {
1576c577b8a1SJoseph Chan 				case AUTO_SEQ_FRONT:
1577c577b8a1SJoseph Chan 					/* AOW0 */
1578c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x10;
1579c577b8a1SJoseph Chan 					break;
1580c577b8a1SJoseph Chan 				case AUTO_SEQ_CENLFE:
1581c577b8a1SJoseph Chan 					/* AOW2 */
1582c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x12;
1583c577b8a1SJoseph Chan 					break;
1584c577b8a1SJoseph Chan 				case AUTO_SEQ_SURROUND:
1585c577b8a1SJoseph Chan 					/* AOW3 */
1586fb4cb772SHarald Welte 					spec->multiout.dac_nids[i] = 0x11;
1587c577b8a1SJoseph Chan 					break;
1588c577b8a1SJoseph Chan 				case AUTO_SEQ_SIDE:
1589c577b8a1SJoseph Chan 					/* AOW1 */
1590fb4cb772SHarald Welte 					spec->multiout.dac_nids[i] = 0x27;
1591c577b8a1SJoseph Chan 					break;
1592c577b8a1SJoseph Chan 				default:
1593c577b8a1SJoseph Chan 					break;
1594c577b8a1SJoseph Chan 				}
1595c577b8a1SJoseph Chan 			}
1596c577b8a1SJoseph Chan 		}
1597c577b8a1SJoseph Chan 		spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1598c577b8a1SJoseph Chan 
1599c577b8a1SJoseph Chan 	} else if (cfg->line_outs == 3) { /* 6 channels */
1600c577b8a1SJoseph Chan 		for(i = 0; i < cfg->line_outs; i++) {
1601c577b8a1SJoseph Chan 			nid = cfg->line_out_pins[i];
1602c577b8a1SJoseph Chan 			if (nid) {
1603c577b8a1SJoseph Chan 				/* config dac list */
1604c577b8a1SJoseph Chan 				switch(i) {
1605c577b8a1SJoseph Chan 				case AUTO_SEQ_FRONT:
1606c577b8a1SJoseph Chan 					/* AOW0 */
1607c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x10;
1608c577b8a1SJoseph Chan 					break;
1609c577b8a1SJoseph Chan 				case AUTO_SEQ_CENLFE:
1610c577b8a1SJoseph Chan 					/* AOW2 */
1611c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x12;
1612c577b8a1SJoseph Chan 					break;
1613c577b8a1SJoseph Chan 				case AUTO_SEQ_SURROUND:
1614c577b8a1SJoseph Chan 					/* AOW1 */
1615c577b8a1SJoseph Chan 					spec->multiout.dac_nids[i] = 0x11;
1616c577b8a1SJoseph Chan 					break;
1617c577b8a1SJoseph Chan 				default:
1618c577b8a1SJoseph Chan 					break;
1619c577b8a1SJoseph Chan 				}
1620c577b8a1SJoseph Chan 			}
1621c577b8a1SJoseph Chan 		}
1622c577b8a1SJoseph Chan 	}
1623c577b8a1SJoseph Chan 
1624c577b8a1SJoseph Chan 	return 0;
1625c577b8a1SJoseph Chan }
1626c577b8a1SJoseph Chan 
1627c577b8a1SJoseph Chan /* add playback controls from the parsed DAC table */
1628c577b8a1SJoseph Chan static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1629c577b8a1SJoseph Chan 					     const struct auto_pin_cfg *cfg)
1630c577b8a1SJoseph Chan {
1631c577b8a1SJoseph Chan 	char name[32];
1632c577b8a1SJoseph Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1633c577b8a1SJoseph Chan 	hda_nid_t nid = 0;
1634c577b8a1SJoseph Chan 	int i, err;
1635c577b8a1SJoseph Chan 
1636c577b8a1SJoseph Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1637c577b8a1SJoseph Chan 		nid = cfg->line_out_pins[i];
1638c577b8a1SJoseph Chan 
1639c577b8a1SJoseph Chan 		if (!nid)
1640c577b8a1SJoseph Chan 			continue;
1641c577b8a1SJoseph Chan 
1642c577b8a1SJoseph Chan 		if (i == AUTO_SEQ_CENLFE) {
1643c577b8a1SJoseph Chan 			/* Center/LFE */
1644c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1645c577b8a1SJoseph Chan 					      "Center Playback Volume",
1646f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1647f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1648c577b8a1SJoseph Chan 			if (err < 0)
1649c577b8a1SJoseph Chan 				return err;
1650c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1651c577b8a1SJoseph Chan 					      "LFE Playback Volume",
1652f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1653f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1654c577b8a1SJoseph Chan 			if (err < 0)
1655c577b8a1SJoseph Chan 				return err;
1656c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1657c577b8a1SJoseph Chan 					      "Center Playback Switch",
1658f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1659f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1660c577b8a1SJoseph Chan 			if (err < 0)
1661c577b8a1SJoseph Chan 				return err;
1662c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1663c577b8a1SJoseph Chan 					      "LFE Playback Switch",
1664f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1665f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1666c577b8a1SJoseph Chan 			if (err < 0)
1667c577b8a1SJoseph Chan 				return err;
1668c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_FRONT){
1669c577b8a1SJoseph Chan 			/* add control to mixer index 0 */
1670c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1671c577b8a1SJoseph Chan 					      "Master Front Playback Volume",
1672f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1673f7278fd0SJosepch Chan 								  HDA_INPUT));
1674c577b8a1SJoseph Chan 			if (err < 0)
1675c577b8a1SJoseph Chan 				return err;
1676c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1677c577b8a1SJoseph Chan 					      "Master Front Playback Switch",
1678f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1679f7278fd0SJosepch Chan 								  HDA_INPUT));
1680c577b8a1SJoseph Chan 			if (err < 0)
1681c577b8a1SJoseph Chan 				return err;
1682c577b8a1SJoseph Chan 
1683c577b8a1SJoseph Chan 			/* add control to PW3 */
1684c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
1685c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1686f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1687f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1688c577b8a1SJoseph Chan 			if (err < 0)
1689c577b8a1SJoseph Chan 				return err;
1690c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
1691c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1692f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1693f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1694c577b8a1SJoseph Chan 			if (err < 0)
1695c577b8a1SJoseph Chan 				return err;
1696c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_SURROUND) {
1697c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
1698c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1699fb4cb772SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1700f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1701c577b8a1SJoseph Chan 			if (err < 0)
1702c577b8a1SJoseph Chan 				return err;
1703c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
1704c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1705fb4cb772SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1706f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1707c577b8a1SJoseph Chan 			if (err < 0)
1708c577b8a1SJoseph Chan 				return err;
1709c577b8a1SJoseph Chan 		} else if (i == AUTO_SEQ_SIDE) {
1710c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Volume", chname[i]);
1711c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1712fb4cb772SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1713f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1714c577b8a1SJoseph Chan 			if (err < 0)
1715c577b8a1SJoseph Chan 				return err;
1716c577b8a1SJoseph Chan 			sprintf(name, "%s Playback Switch", chname[i]);
1717c577b8a1SJoseph Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1718fb4cb772SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1719f7278fd0SJosepch Chan 								  HDA_OUTPUT));
1720c577b8a1SJoseph Chan 			if (err < 0)
1721c577b8a1SJoseph Chan 				return err;
1722c577b8a1SJoseph Chan 		}
1723c577b8a1SJoseph Chan 	}
1724c577b8a1SJoseph Chan 
1725c577b8a1SJoseph Chan 	return 0;
1726c577b8a1SJoseph Chan }
1727c577b8a1SJoseph Chan 
1728c577b8a1SJoseph Chan static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1729c577b8a1SJoseph Chan {
1730c577b8a1SJoseph Chan 	int err;
1731c577b8a1SJoseph Chan 
1732c577b8a1SJoseph Chan 	if (!pin)
1733c577b8a1SJoseph Chan 		return 0;
1734c577b8a1SJoseph Chan 
1735c577b8a1SJoseph Chan 	if (spec->multiout.num_dacs == 5) /* 10 channels */
1736c577b8a1SJoseph Chan 		spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1737c577b8a1SJoseph Chan 	else if (spec->multiout.num_dacs == 3) /* 6 channels */
1738c577b8a1SJoseph Chan 		spec->multiout.hp_nid = 0;
1739c577b8a1SJoseph Chan 
1740c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1741c577b8a1SJoseph Chan 			      "Headphone Playback Volume",
1742c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1743c577b8a1SJoseph Chan 	if (err < 0)
1744c577b8a1SJoseph Chan 		return err;
1745c577b8a1SJoseph Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1746c577b8a1SJoseph Chan 			      "Headphone Playback Switch",
1747c577b8a1SJoseph Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1748c577b8a1SJoseph Chan 	if (err < 0)
1749c577b8a1SJoseph Chan 		return err;
1750c577b8a1SJoseph Chan 
1751c577b8a1SJoseph Chan 	return 0;
1752c577b8a1SJoseph Chan }
1753c577b8a1SJoseph Chan 
1754c577b8a1SJoseph Chan /* create playback/capture controls for input pins */
1755c577b8a1SJoseph Chan static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1756c577b8a1SJoseph Chan 						const struct auto_pin_cfg *cfg)
1757c577b8a1SJoseph Chan {
1758c577b8a1SJoseph Chan 	static char *labels[] = {
1759c577b8a1SJoseph Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1760c577b8a1SJoseph Chan 	};
17610aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
1762c577b8a1SJoseph Chan 	int i, err, idx = 0;
1763c577b8a1SJoseph Chan 
1764c577b8a1SJoseph Chan 	/* for internal loopback recording select */
1765c577b8a1SJoseph Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
1766c577b8a1SJoseph Chan 	imux->items[imux->num_items].index = idx;
1767c577b8a1SJoseph Chan 	imux->num_items++;
1768c577b8a1SJoseph Chan 
1769c577b8a1SJoseph Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
1770c577b8a1SJoseph Chan 		if (!cfg->input_pins[i])
1771c577b8a1SJoseph Chan 			continue;
1772c577b8a1SJoseph Chan 
1773c577b8a1SJoseph Chan 		switch (cfg->input_pins[i]) {
1774c577b8a1SJoseph Chan 		case 0x1d: /* Mic */
1775c577b8a1SJoseph Chan 			idx = 2;
1776c577b8a1SJoseph Chan 			break;
1777c577b8a1SJoseph Chan 
1778c577b8a1SJoseph Chan 		case 0x1e: /* Line In */
1779c577b8a1SJoseph Chan 			idx = 3;
1780c577b8a1SJoseph Chan 			break;
1781c577b8a1SJoseph Chan 
1782c577b8a1SJoseph Chan 		case 0x21: /* Front Mic */
1783c577b8a1SJoseph Chan 			idx = 4;
1784c577b8a1SJoseph Chan 			break;
1785c577b8a1SJoseph Chan 
1786c577b8a1SJoseph Chan 		case 0x23: /* CD */
1787c577b8a1SJoseph Chan 			idx = 1;
1788c577b8a1SJoseph Chan 			break;
1789c577b8a1SJoseph Chan 		}
1790c577b8a1SJoseph Chan 		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1791c577b8a1SJoseph Chan 					   idx, 0x18);
1792c577b8a1SJoseph Chan 		if (err < 0)
1793c577b8a1SJoseph Chan 			return err;
1794c577b8a1SJoseph Chan 		imux->items[imux->num_items].label = labels[i];
1795c577b8a1SJoseph Chan 		imux->items[imux->num_items].index = idx;
1796c577b8a1SJoseph Chan 		imux->num_items++;
1797c577b8a1SJoseph Chan 	}
1798c577b8a1SJoseph Chan 	return 0;
1799c577b8a1SJoseph Chan }
1800c577b8a1SJoseph Chan 
1801c577b8a1SJoseph Chan static int vt1709_parse_auto_config(struct hda_codec *codec)
1802c577b8a1SJoseph Chan {
1803c577b8a1SJoseph Chan 	struct via_spec *spec = codec->spec;
1804c577b8a1SJoseph Chan 	int err;
1805c577b8a1SJoseph Chan 
1806c577b8a1SJoseph Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1807c577b8a1SJoseph Chan 	if (err < 0)
1808c577b8a1SJoseph Chan 		return err;
1809c577b8a1SJoseph Chan 	err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1810c577b8a1SJoseph Chan 	if (err < 0)
1811c577b8a1SJoseph Chan 		return err;
1812c577b8a1SJoseph Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1813c577b8a1SJoseph Chan 		return 0; /* can't find valid BIOS pin config */
1814c577b8a1SJoseph Chan 
1815c577b8a1SJoseph Chan 	err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1816c577b8a1SJoseph Chan 	if (err < 0)
1817c577b8a1SJoseph Chan 		return err;
1818c577b8a1SJoseph Chan 	err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1819c577b8a1SJoseph Chan 	if (err < 0)
1820c577b8a1SJoseph Chan 		return err;
1821c577b8a1SJoseph Chan 	err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1822c577b8a1SJoseph Chan 	if (err < 0)
1823c577b8a1SJoseph Chan 		return err;
1824c577b8a1SJoseph Chan 
1825c577b8a1SJoseph Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1826c577b8a1SJoseph Chan 
18270852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
1828c577b8a1SJoseph Chan 		spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1829c577b8a1SJoseph Chan 	if (spec->autocfg.dig_in_pin)
1830c577b8a1SJoseph Chan 		spec->dig_in_nid = VT1709_DIGIN_NID;
1831c577b8a1SJoseph Chan 
1832603c4019STakashi Iwai 	if (spec->kctls.list)
1833603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
1834c577b8a1SJoseph Chan 
18350aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
1836c577b8a1SJoseph Chan 
1837f8fdd495SHarald Welte 	if (spec->hp_mux)
1838f8fdd495SHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
1839f8fdd495SHarald Welte 
1840c577b8a1SJoseph Chan 	return 1;
1841c577b8a1SJoseph Chan }
1842c577b8a1SJoseph Chan 
1843cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1844cb53c626STakashi Iwai static struct hda_amp_list vt1709_loopbacks[] = {
1845cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 1 },
1846cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 2 },
1847cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 3 },
1848cb53c626STakashi Iwai 	{ 0x18, HDA_INPUT, 4 },
1849cb53c626STakashi Iwai 	{ } /* end */
1850cb53c626STakashi Iwai };
1851cb53c626STakashi Iwai #endif
1852cb53c626STakashi Iwai 
1853c577b8a1SJoseph Chan static int patch_vt1709_10ch(struct hda_codec *codec)
1854c577b8a1SJoseph Chan {
1855c577b8a1SJoseph Chan 	struct via_spec *spec;
1856c577b8a1SJoseph Chan 	int err;
1857c577b8a1SJoseph Chan 
1858c577b8a1SJoseph Chan 	/* create a codec specific record */
1859eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1860c577b8a1SJoseph Chan 	if (spec == NULL)
1861c577b8a1SJoseph Chan 		return -ENOMEM;
1862c577b8a1SJoseph Chan 
1863c577b8a1SJoseph Chan 	codec->spec = spec;
1864c577b8a1SJoseph Chan 
1865c577b8a1SJoseph Chan 	err = vt1709_parse_auto_config(codec);
1866c577b8a1SJoseph Chan 	if (err < 0) {
1867c577b8a1SJoseph Chan 		via_free(codec);
1868c577b8a1SJoseph Chan 		return err;
1869c577b8a1SJoseph Chan 	} else if (!err) {
1870c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration.  "
1871c577b8a1SJoseph Chan 		       "Using genenic mode...\n");
1872c577b8a1SJoseph Chan 	}
1873c577b8a1SJoseph Chan 
187469e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
187569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1876c577b8a1SJoseph Chan 
1877c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1709 Analog";
1878c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1879c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1880c577b8a1SJoseph Chan 
1881c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1709 Digital";
1882c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1883c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1884c577b8a1SJoseph Chan 
1885c577b8a1SJoseph Chan 
1886c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
1887c577b8a1SJoseph Chan 		spec->adc_nids = vt1709_adc_nids;
1888c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1889c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1890c577b8a1SJoseph Chan 		spec->num_mixers++;
1891c577b8a1SJoseph Chan 	}
1892c577b8a1SJoseph Chan 
1893c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
1894c577b8a1SJoseph Chan 
1895c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
189669e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
1897cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1898cb53c626STakashi Iwai 	spec->loopback.amplist = vt1709_loopbacks;
1899cb53c626STakashi Iwai #endif
1900c577b8a1SJoseph Chan 
1901c577b8a1SJoseph Chan 	return 0;
1902c577b8a1SJoseph Chan }
1903c577b8a1SJoseph Chan /*
1904c577b8a1SJoseph Chan  * generic initialization of ADC, input mixers and output mixers
1905c577b8a1SJoseph Chan  */
1906c577b8a1SJoseph Chan static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1907c577b8a1SJoseph Chan 	/*
1908c577b8a1SJoseph Chan 	 * Unmute ADC0-2 and set the default input to mic-in
1909c577b8a1SJoseph Chan 	 */
1910c577b8a1SJoseph Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1911c577b8a1SJoseph Chan 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1912c577b8a1SJoseph Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1913c577b8a1SJoseph Chan 
1914c577b8a1SJoseph Chan 
1915c577b8a1SJoseph Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1916c577b8a1SJoseph Chan 	 * mixer widget
1917c577b8a1SJoseph Chan 	 */
1918c577b8a1SJoseph Chan 	/* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1919c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1920c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1921c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1922c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1923c577b8a1SJoseph Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1924c577b8a1SJoseph Chan 
1925c577b8a1SJoseph Chan 	/*
1926c577b8a1SJoseph Chan 	 * Set up output selector (0x1a, 0x1b, 0x29)
1927c577b8a1SJoseph Chan 	 */
1928c577b8a1SJoseph Chan 	/* set vol=0 to output mixers */
1929c577b8a1SJoseph Chan 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1930c577b8a1SJoseph Chan 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1931c577b8a1SJoseph Chan 	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1932c577b8a1SJoseph Chan 
1933c577b8a1SJoseph Chan 	/*
1934c577b8a1SJoseph Chan 	 *  Unmute PW3 and PW4
1935c577b8a1SJoseph Chan 	 */
1936c577b8a1SJoseph Chan 	{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1937c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1938c577b8a1SJoseph Chan 
1939c577b8a1SJoseph Chan 	/* Set input of PW4 as MW0 */
1940c577b8a1SJoseph Chan 	{0x20, AC_VERB_SET_CONNECT_SEL, 0},
1941c577b8a1SJoseph Chan 	/* PW9 Output enable */
1942c577b8a1SJoseph Chan 	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1943c577b8a1SJoseph Chan 	{ }
1944c577b8a1SJoseph Chan };
1945c577b8a1SJoseph Chan 
1946c577b8a1SJoseph Chan static int patch_vt1709_6ch(struct hda_codec *codec)
1947c577b8a1SJoseph Chan {
1948c577b8a1SJoseph Chan 	struct via_spec *spec;
1949c577b8a1SJoseph Chan 	int err;
1950c577b8a1SJoseph Chan 
1951c577b8a1SJoseph Chan 	/* create a codec specific record */
1952eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1953c577b8a1SJoseph Chan 	if (spec == NULL)
1954c577b8a1SJoseph Chan 		return -ENOMEM;
1955c577b8a1SJoseph Chan 
1956c577b8a1SJoseph Chan 	codec->spec = spec;
1957c577b8a1SJoseph Chan 
1958c577b8a1SJoseph Chan 	err = vt1709_parse_auto_config(codec);
1959c577b8a1SJoseph Chan 	if (err < 0) {
1960c577b8a1SJoseph Chan 		via_free(codec);
1961c577b8a1SJoseph Chan 		return err;
1962c577b8a1SJoseph Chan 	} else if (!err) {
1963c577b8a1SJoseph Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration.  "
1964c577b8a1SJoseph Chan 		       "Using genenic mode...\n");
1965c577b8a1SJoseph Chan 	}
1966c577b8a1SJoseph Chan 
196769e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
196869e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1969c577b8a1SJoseph Chan 
1970c577b8a1SJoseph Chan 	spec->stream_name_analog = "VT1709 Analog";
1971c577b8a1SJoseph Chan 	spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1972c577b8a1SJoseph Chan 	spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1973c577b8a1SJoseph Chan 
1974c577b8a1SJoseph Chan 	spec->stream_name_digital = "VT1709 Digital";
1975c577b8a1SJoseph Chan 	spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1976c577b8a1SJoseph Chan 	spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1977c577b8a1SJoseph Chan 
1978c577b8a1SJoseph Chan 
1979c577b8a1SJoseph Chan 	if (!spec->adc_nids && spec->input_mux) {
1980c577b8a1SJoseph Chan 		spec->adc_nids = vt1709_adc_nids;
1981c577b8a1SJoseph Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1982c577b8a1SJoseph Chan 		spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1983c577b8a1SJoseph Chan 		spec->num_mixers++;
1984c577b8a1SJoseph Chan 	}
1985c577b8a1SJoseph Chan 
1986c577b8a1SJoseph Chan 	codec->patch_ops = via_patch_ops;
1987c577b8a1SJoseph Chan 
1988c577b8a1SJoseph Chan 	codec->patch_ops.init = via_auto_init;
198969e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
1990cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
1991cb53c626STakashi Iwai 	spec->loopback.amplist = vt1709_loopbacks;
1992cb53c626STakashi Iwai #endif
1993f7278fd0SJosepch Chan 	return 0;
1994f7278fd0SJosepch Chan }
1995f7278fd0SJosepch Chan 
1996f7278fd0SJosepch Chan /* capture mixer elements */
1997f7278fd0SJosepch Chan static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1998f7278fd0SJosepch Chan 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1999f7278fd0SJosepch Chan 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2000f7278fd0SJosepch Chan 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2001f7278fd0SJosepch Chan 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2002f7278fd0SJosepch Chan 	{
2003f7278fd0SJosepch Chan 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2004f7278fd0SJosepch Chan 		/* The multiple "Capture Source" controls confuse alsamixer
2005f7278fd0SJosepch Chan 		 * So call somewhat different..
2006f7278fd0SJosepch Chan 		 */
2007f7278fd0SJosepch Chan 		/* .name = "Capture Source", */
2008f7278fd0SJosepch Chan 		.name = "Input Source",
2009f7278fd0SJosepch Chan 		.count = 1,
2010f7278fd0SJosepch Chan 		.info = via_mux_enum_info,
2011f7278fd0SJosepch Chan 		.get = via_mux_enum_get,
2012f7278fd0SJosepch Chan 		.put = via_mux_enum_put,
2013f7278fd0SJosepch Chan 	},
2014f7278fd0SJosepch Chan 	{ } /* end */
2015f7278fd0SJosepch Chan };
2016f7278fd0SJosepch Chan /*
2017f7278fd0SJosepch Chan  * generic initialization of ADC, input mixers and output mixers
2018f7278fd0SJosepch Chan  */
2019f7278fd0SJosepch Chan static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2020f7278fd0SJosepch Chan 	/*
2021f7278fd0SJosepch Chan 	 * Unmute ADC0-1 and set the default input to mic-in
2022f7278fd0SJosepch Chan 	 */
2023f7278fd0SJosepch Chan 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2024f7278fd0SJosepch Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2025f7278fd0SJosepch Chan 
2026f7278fd0SJosepch Chan 
2027f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2028f7278fd0SJosepch Chan 	 * mixer widget
2029f7278fd0SJosepch Chan 	 */
2030f7278fd0SJosepch Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2031f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2032f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2033f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2034f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2035f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2036f7278fd0SJosepch Chan 
2037f7278fd0SJosepch Chan 	/*
2038f7278fd0SJosepch Chan 	 * Set up output mixers
2039f7278fd0SJosepch Chan 	 */
2040f7278fd0SJosepch Chan 	/* set vol=0 to output mixers */
2041f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2042f7278fd0SJosepch Chan 	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2043f7278fd0SJosepch Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2044f7278fd0SJosepch Chan 
2045f7278fd0SJosepch Chan 	/* Setup default input to PW4 */
2046f7278fd0SJosepch Chan 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2047f7278fd0SJosepch Chan 	/* PW9 Output enable */
2048f7278fd0SJosepch Chan 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2049f7278fd0SJosepch Chan 	/* PW10 Input enable */
2050f7278fd0SJosepch Chan 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2051f7278fd0SJosepch Chan 	{ }
2052f7278fd0SJosepch Chan };
2053f7278fd0SJosepch Chan 
2054f7278fd0SJosepch Chan static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2055f7278fd0SJosepch Chan 	/*
2056f7278fd0SJosepch Chan 	 * Unmute ADC0-1 and set the default input to mic-in
2057f7278fd0SJosepch Chan 	 */
2058f7278fd0SJosepch Chan 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2059f7278fd0SJosepch Chan 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2060f7278fd0SJosepch Chan 
2061f7278fd0SJosepch Chan 
2062f7278fd0SJosepch Chan 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2063f7278fd0SJosepch Chan 	 * mixer widget
2064f7278fd0SJosepch Chan 	 */
2065f7278fd0SJosepch Chan 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2066f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2067f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2068f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2069f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2070f7278fd0SJosepch Chan 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2071f7278fd0SJosepch Chan 
2072f7278fd0SJosepch Chan 	/*
2073f7278fd0SJosepch Chan 	 * Set up output mixers
2074f7278fd0SJosepch Chan 	 */
2075f7278fd0SJosepch Chan 	/* set vol=0 to output mixers */
2076f7278fd0SJosepch Chan 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2077f7278fd0SJosepch Chan 	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2078f7278fd0SJosepch Chan 	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2079f7278fd0SJosepch Chan 
2080f7278fd0SJosepch Chan 	/* Setup default input of PW4 to MW0 */
2081f7278fd0SJosepch Chan 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2082f7278fd0SJosepch Chan 	/* PW9 Output enable */
2083f7278fd0SJosepch Chan 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2084f7278fd0SJosepch Chan 	/* PW10 Input enable */
2085f7278fd0SJosepch Chan 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2086f7278fd0SJosepch Chan 	{ }
2087f7278fd0SJosepch Chan };
2088f7278fd0SJosepch Chan 
208969e52a80SHarald Welte static struct hda_verb vt1708B_uniwill_init_verbs[] = {
209069e52a80SHarald Welte 	{0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
209169e52a80SHarald Welte 	{ }
209269e52a80SHarald Welte };
209369e52a80SHarald Welte 
2094f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
20950aa62aefSHarald Welte 	.substreams = 2,
2096f7278fd0SJosepch Chan 	.channels_min = 2,
2097f7278fd0SJosepch Chan 	.channels_max = 8,
2098f7278fd0SJosepch Chan 	.nid = 0x10, /* NID to query formats and rates */
2099f7278fd0SJosepch Chan 	.ops = {
2100f7278fd0SJosepch Chan 		.open = via_playback_pcm_open,
21010aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
21020aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
2103f7278fd0SJosepch Chan 	},
2104f7278fd0SJosepch Chan };
2105f7278fd0SJosepch Chan 
2106f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
21070aa62aefSHarald Welte 	.substreams = 2,
2108f7278fd0SJosepch Chan 	.channels_min = 2,
2109f7278fd0SJosepch Chan 	.channels_max = 4,
2110f7278fd0SJosepch Chan 	.nid = 0x10, /* NID to query formats and rates */
2111f7278fd0SJosepch Chan 	.ops = {
2112f7278fd0SJosepch Chan 		.open = via_playback_pcm_open,
21130aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
21140aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
2115f7278fd0SJosepch Chan 	},
2116f7278fd0SJosepch Chan };
2117f7278fd0SJosepch Chan 
2118f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2119f7278fd0SJosepch Chan 	.substreams = 2,
2120f7278fd0SJosepch Chan 	.channels_min = 2,
2121f7278fd0SJosepch Chan 	.channels_max = 2,
2122f7278fd0SJosepch Chan 	.nid = 0x13, /* NID to query formats and rates */
2123f7278fd0SJosepch Chan 	.ops = {
2124f7278fd0SJosepch Chan 		.prepare = via_capture_pcm_prepare,
2125f7278fd0SJosepch Chan 		.cleanup = via_capture_pcm_cleanup
2126f7278fd0SJosepch Chan 	},
2127f7278fd0SJosepch Chan };
2128f7278fd0SJosepch Chan 
2129f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2130f7278fd0SJosepch Chan 	.substreams = 1,
2131f7278fd0SJosepch Chan 	.channels_min = 2,
2132f7278fd0SJosepch Chan 	.channels_max = 2,
2133f7278fd0SJosepch Chan 	/* NID is set in via_build_pcms */
2134f7278fd0SJosepch Chan 	.ops = {
2135f7278fd0SJosepch Chan 		.open = via_dig_playback_pcm_open,
2136f7278fd0SJosepch Chan 		.close = via_dig_playback_pcm_close,
2137f7278fd0SJosepch Chan 		.prepare = via_dig_playback_pcm_prepare
2138f7278fd0SJosepch Chan 	},
2139f7278fd0SJosepch Chan };
2140f7278fd0SJosepch Chan 
2141f7278fd0SJosepch Chan static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2142f7278fd0SJosepch Chan 	.substreams = 1,
2143f7278fd0SJosepch Chan 	.channels_min = 2,
2144f7278fd0SJosepch Chan 	.channels_max = 2,
2145f7278fd0SJosepch Chan };
2146f7278fd0SJosepch Chan 
2147f7278fd0SJosepch Chan /* fill in the dac_nids table from the parsed pin configuration */
2148f7278fd0SJosepch Chan static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2149f7278fd0SJosepch Chan 				     const struct auto_pin_cfg *cfg)
2150f7278fd0SJosepch Chan {
2151f7278fd0SJosepch Chan 	int i;
2152f7278fd0SJosepch Chan 	hda_nid_t nid;
2153f7278fd0SJosepch Chan 
2154f7278fd0SJosepch Chan 	spec->multiout.num_dacs = cfg->line_outs;
2155f7278fd0SJosepch Chan 
2156f7278fd0SJosepch Chan 	spec->multiout.dac_nids = spec->private_dac_nids;
2157f7278fd0SJosepch Chan 
2158f7278fd0SJosepch Chan 	for (i = 0; i < 4; i++) {
2159f7278fd0SJosepch Chan 		nid = cfg->line_out_pins[i];
2160f7278fd0SJosepch Chan 		if (nid) {
2161f7278fd0SJosepch Chan 			/* config dac list */
2162f7278fd0SJosepch Chan 			switch (i) {
2163f7278fd0SJosepch Chan 			case AUTO_SEQ_FRONT:
2164f7278fd0SJosepch Chan 				spec->multiout.dac_nids[i] = 0x10;
2165f7278fd0SJosepch Chan 				break;
2166f7278fd0SJosepch Chan 			case AUTO_SEQ_CENLFE:
2167f7278fd0SJosepch Chan 				spec->multiout.dac_nids[i] = 0x24;
2168f7278fd0SJosepch Chan 				break;
2169f7278fd0SJosepch Chan 			case AUTO_SEQ_SURROUND:
2170fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
2171f7278fd0SJosepch Chan 				break;
2172f7278fd0SJosepch Chan 			case AUTO_SEQ_SIDE:
2173fb4cb772SHarald Welte 				spec->multiout.dac_nids[i] = 0x25;
2174f7278fd0SJosepch Chan 				break;
2175f7278fd0SJosepch Chan 			}
2176f7278fd0SJosepch Chan 		}
2177f7278fd0SJosepch Chan 	}
2178f7278fd0SJosepch Chan 
2179f7278fd0SJosepch Chan 	return 0;
2180f7278fd0SJosepch Chan }
2181f7278fd0SJosepch Chan 
2182f7278fd0SJosepch Chan /* add playback controls from the parsed DAC table */
2183f7278fd0SJosepch Chan static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2184f7278fd0SJosepch Chan 					     const struct auto_pin_cfg *cfg)
2185f7278fd0SJosepch Chan {
2186f7278fd0SJosepch Chan 	char name[32];
2187f7278fd0SJosepch Chan 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2188fb4cb772SHarald Welte 	hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2189f7278fd0SJosepch Chan 	hda_nid_t nid, nid_vol = 0;
2190f7278fd0SJosepch Chan 	int i, err;
2191f7278fd0SJosepch Chan 
2192f7278fd0SJosepch Chan 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2193f7278fd0SJosepch Chan 		nid = cfg->line_out_pins[i];
2194f7278fd0SJosepch Chan 
2195f7278fd0SJosepch Chan 		if (!nid)
2196f7278fd0SJosepch Chan 			continue;
2197f7278fd0SJosepch Chan 
2198f7278fd0SJosepch Chan 		nid_vol = nid_vols[i];
2199f7278fd0SJosepch Chan 
2200f7278fd0SJosepch Chan 		if (i == AUTO_SEQ_CENLFE) {
2201f7278fd0SJosepch Chan 			/* Center/LFE */
2202f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2203f7278fd0SJosepch Chan 					      "Center Playback Volume",
2204f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2205f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2206f7278fd0SJosepch Chan 			if (err < 0)
2207f7278fd0SJosepch Chan 				return err;
2208f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2209f7278fd0SJosepch Chan 					      "LFE Playback Volume",
2210f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2211f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2212f7278fd0SJosepch Chan 			if (err < 0)
2213f7278fd0SJosepch Chan 				return err;
2214f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2215f7278fd0SJosepch Chan 					      "Center Playback Switch",
2216f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2217f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2218f7278fd0SJosepch Chan 			if (err < 0)
2219f7278fd0SJosepch Chan 				return err;
2220f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2221f7278fd0SJosepch Chan 					      "LFE Playback Switch",
2222f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2223f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2224f7278fd0SJosepch Chan 			if (err < 0)
2225f7278fd0SJosepch Chan 				return err;
2226f7278fd0SJosepch Chan 		} else if (i == AUTO_SEQ_FRONT) {
2227f7278fd0SJosepch Chan 			/* add control to mixer index 0 */
2228f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2229f7278fd0SJosepch Chan 					      "Master Front Playback Volume",
2230f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2231f7278fd0SJosepch Chan 								  HDA_INPUT));
2232f7278fd0SJosepch Chan 			if (err < 0)
2233f7278fd0SJosepch Chan 				return err;
2234f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2235f7278fd0SJosepch Chan 					      "Master Front Playback Switch",
2236f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2237f7278fd0SJosepch Chan 								  HDA_INPUT));
2238f7278fd0SJosepch Chan 			if (err < 0)
2239f7278fd0SJosepch Chan 				return err;
2240f7278fd0SJosepch Chan 
2241f7278fd0SJosepch Chan 			/* add control to PW3 */
2242f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2243f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2244f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2245f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2246f7278fd0SJosepch Chan 			if (err < 0)
2247f7278fd0SJosepch Chan 				return err;
2248f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2249f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2250f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2251f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2252f7278fd0SJosepch Chan 			if (err < 0)
2253f7278fd0SJosepch Chan 				return err;
2254f7278fd0SJosepch Chan 		} else {
2255f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Volume", chname[i]);
2256f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2257f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2258f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2259f7278fd0SJosepch Chan 			if (err < 0)
2260f7278fd0SJosepch Chan 				return err;
2261f7278fd0SJosepch Chan 			sprintf(name, "%s Playback Switch", chname[i]);
2262f7278fd0SJosepch Chan 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2263f7278fd0SJosepch Chan 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2264f7278fd0SJosepch Chan 								  HDA_OUTPUT));
2265f7278fd0SJosepch Chan 			if (err < 0)
2266f7278fd0SJosepch Chan 				return err;
2267f7278fd0SJosepch Chan 		}
2268f7278fd0SJosepch Chan 	}
2269f7278fd0SJosepch Chan 
2270f7278fd0SJosepch Chan 	return 0;
2271f7278fd0SJosepch Chan }
2272f7278fd0SJosepch Chan 
2273f7278fd0SJosepch Chan static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2274f7278fd0SJosepch Chan {
2275f7278fd0SJosepch Chan 	int err;
2276f7278fd0SJosepch Chan 
2277f7278fd0SJosepch Chan 	if (!pin)
2278f7278fd0SJosepch Chan 		return 0;
2279f7278fd0SJosepch Chan 
2280f7278fd0SJosepch Chan 	spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2281f7278fd0SJosepch Chan 
2282f7278fd0SJosepch Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2283f7278fd0SJosepch Chan 			      "Headphone Playback Volume",
2284f7278fd0SJosepch Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2285f7278fd0SJosepch Chan 	if (err < 0)
2286f7278fd0SJosepch Chan 		return err;
2287f7278fd0SJosepch Chan 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2288f7278fd0SJosepch Chan 			      "Headphone Playback Switch",
2289f7278fd0SJosepch Chan 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2290f7278fd0SJosepch Chan 	if (err < 0)
2291f7278fd0SJosepch Chan 		return err;
2292f7278fd0SJosepch Chan 
22930aa62aefSHarald Welte 	create_hp_imux(spec);
22940aa62aefSHarald Welte 
2295f7278fd0SJosepch Chan 	return 0;
2296f7278fd0SJosepch Chan }
2297f7278fd0SJosepch Chan 
2298f7278fd0SJosepch Chan /* create playback/capture controls for input pins */
2299f7278fd0SJosepch Chan static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2300f7278fd0SJosepch Chan 						const struct auto_pin_cfg *cfg)
2301f7278fd0SJosepch Chan {
2302f7278fd0SJosepch Chan 	static char *labels[] = {
2303f7278fd0SJosepch Chan 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2304f7278fd0SJosepch Chan 	};
23050aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
2306f7278fd0SJosepch Chan 	int i, err, idx = 0;
2307f7278fd0SJosepch Chan 
2308f7278fd0SJosepch Chan 	/* for internal loopback recording select */
2309f7278fd0SJosepch Chan 	imux->items[imux->num_items].label = "Stereo Mixer";
2310f7278fd0SJosepch Chan 	imux->items[imux->num_items].index = idx;
2311f7278fd0SJosepch Chan 	imux->num_items++;
2312f7278fd0SJosepch Chan 
2313f7278fd0SJosepch Chan 	for (i = 0; i < AUTO_PIN_LAST; i++) {
2314f7278fd0SJosepch Chan 		if (!cfg->input_pins[i])
2315f7278fd0SJosepch Chan 			continue;
2316f7278fd0SJosepch Chan 
2317f7278fd0SJosepch Chan 		switch (cfg->input_pins[i]) {
2318f7278fd0SJosepch Chan 		case 0x1a: /* Mic */
2319f7278fd0SJosepch Chan 			idx = 2;
2320f7278fd0SJosepch Chan 			break;
2321f7278fd0SJosepch Chan 
2322f7278fd0SJosepch Chan 		case 0x1b: /* Line In */
2323f7278fd0SJosepch Chan 			idx = 3;
2324f7278fd0SJosepch Chan 			break;
2325f7278fd0SJosepch Chan 
2326f7278fd0SJosepch Chan 		case 0x1e: /* Front Mic */
2327f7278fd0SJosepch Chan 			idx = 4;
2328f7278fd0SJosepch Chan 			break;
2329f7278fd0SJosepch Chan 
2330f7278fd0SJosepch Chan 		case 0x1f: /* CD */
2331f7278fd0SJosepch Chan 			idx = 1;
2332f7278fd0SJosepch Chan 			break;
2333f7278fd0SJosepch Chan 		}
2334f7278fd0SJosepch Chan 		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2335f7278fd0SJosepch Chan 					   idx, 0x16);
2336f7278fd0SJosepch Chan 		if (err < 0)
2337f7278fd0SJosepch Chan 			return err;
2338f7278fd0SJosepch Chan 		imux->items[imux->num_items].label = labels[i];
2339f7278fd0SJosepch Chan 		imux->items[imux->num_items].index = idx;
2340f7278fd0SJosepch Chan 		imux->num_items++;
2341f7278fd0SJosepch Chan 	}
2342f7278fd0SJosepch Chan 	return 0;
2343f7278fd0SJosepch Chan }
2344f7278fd0SJosepch Chan 
2345f7278fd0SJosepch Chan static int vt1708B_parse_auto_config(struct hda_codec *codec)
2346f7278fd0SJosepch Chan {
2347f7278fd0SJosepch Chan 	struct via_spec *spec = codec->spec;
2348f7278fd0SJosepch Chan 	int err;
2349f7278fd0SJosepch Chan 
2350f7278fd0SJosepch Chan 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2351f7278fd0SJosepch Chan 	if (err < 0)
2352f7278fd0SJosepch Chan 		return err;
2353f7278fd0SJosepch Chan 	err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2354f7278fd0SJosepch Chan 	if (err < 0)
2355f7278fd0SJosepch Chan 		return err;
2356f7278fd0SJosepch Chan 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2357f7278fd0SJosepch Chan 		return 0; /* can't find valid BIOS pin config */
2358f7278fd0SJosepch Chan 
2359f7278fd0SJosepch Chan 	err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2360f7278fd0SJosepch Chan 	if (err < 0)
2361f7278fd0SJosepch Chan 		return err;
2362f7278fd0SJosepch Chan 	err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2363f7278fd0SJosepch Chan 	if (err < 0)
2364f7278fd0SJosepch Chan 		return err;
2365f7278fd0SJosepch Chan 	err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2366f7278fd0SJosepch Chan 	if (err < 0)
2367f7278fd0SJosepch Chan 		return err;
2368f7278fd0SJosepch Chan 
2369f7278fd0SJosepch Chan 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2370f7278fd0SJosepch Chan 
23710852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
2372f7278fd0SJosepch Chan 		spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2373f7278fd0SJosepch Chan 	if (spec->autocfg.dig_in_pin)
2374f7278fd0SJosepch Chan 		spec->dig_in_nid = VT1708B_DIGIN_NID;
2375f7278fd0SJosepch Chan 
2376603c4019STakashi Iwai 	if (spec->kctls.list)
2377603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
2378f7278fd0SJosepch Chan 
23790aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
23800aa62aefSHarald Welte 
2381f8fdd495SHarald Welte 	if (spec->hp_mux)
23820aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
2383f7278fd0SJosepch Chan 
2384f7278fd0SJosepch Chan 	return 1;
2385f7278fd0SJosepch Chan }
2386f7278fd0SJosepch Chan 
2387f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
2388f7278fd0SJosepch Chan static struct hda_amp_list vt1708B_loopbacks[] = {
2389f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 1 },
2390f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 2 },
2391f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 3 },
2392f7278fd0SJosepch Chan 	{ 0x16, HDA_INPUT, 4 },
2393f7278fd0SJosepch Chan 	{ } /* end */
2394f7278fd0SJosepch Chan };
2395f7278fd0SJosepch Chan #endif
2396f7278fd0SJosepch Chan 
2397f7278fd0SJosepch Chan static int patch_vt1708B_8ch(struct hda_codec *codec)
2398f7278fd0SJosepch Chan {
2399f7278fd0SJosepch Chan 	struct via_spec *spec;
2400f7278fd0SJosepch Chan 	int err;
2401f7278fd0SJosepch Chan 
2402f7278fd0SJosepch Chan 	/* create a codec specific record */
2403eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2404f7278fd0SJosepch Chan 	if (spec == NULL)
2405f7278fd0SJosepch Chan 		return -ENOMEM;
2406f7278fd0SJosepch Chan 
2407f7278fd0SJosepch Chan 	codec->spec = spec;
2408f7278fd0SJosepch Chan 
2409f7278fd0SJosepch Chan 	/* automatic parse from the BIOS config */
2410f7278fd0SJosepch Chan 	err = vt1708B_parse_auto_config(codec);
2411f7278fd0SJosepch Chan 	if (err < 0) {
2412f7278fd0SJosepch Chan 		via_free(codec);
2413f7278fd0SJosepch Chan 		return err;
2414f7278fd0SJosepch Chan 	} else if (!err) {
2415f7278fd0SJosepch Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
2416f7278fd0SJosepch Chan 		       "from BIOS.  Using genenic mode...\n");
2417f7278fd0SJosepch Chan 	}
2418f7278fd0SJosepch Chan 
241969e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
242069e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2421f7278fd0SJosepch Chan 
2422f7278fd0SJosepch Chan 	spec->stream_name_analog = "VT1708B Analog";
2423f7278fd0SJosepch Chan 	spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2424f7278fd0SJosepch Chan 	spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2425f7278fd0SJosepch Chan 
2426f7278fd0SJosepch Chan 	spec->stream_name_digital = "VT1708B Digital";
2427f7278fd0SJosepch Chan 	spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2428f7278fd0SJosepch Chan 	spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2429f7278fd0SJosepch Chan 
2430f7278fd0SJosepch Chan 	if (!spec->adc_nids && spec->input_mux) {
2431f7278fd0SJosepch Chan 		spec->adc_nids = vt1708B_adc_nids;
2432f7278fd0SJosepch Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2433f7278fd0SJosepch Chan 		spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2434f7278fd0SJosepch Chan 		spec->num_mixers++;
2435f7278fd0SJosepch Chan 	}
2436f7278fd0SJosepch Chan 
2437f7278fd0SJosepch Chan 	codec->patch_ops = via_patch_ops;
2438f7278fd0SJosepch Chan 
2439f7278fd0SJosepch Chan 	codec->patch_ops.init = via_auto_init;
244069e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
2441f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
2442f7278fd0SJosepch Chan 	spec->loopback.amplist = vt1708B_loopbacks;
2443f7278fd0SJosepch Chan #endif
2444f7278fd0SJosepch Chan 
2445f7278fd0SJosepch Chan 	return 0;
2446f7278fd0SJosepch Chan }
2447f7278fd0SJosepch Chan 
2448f7278fd0SJosepch Chan static int patch_vt1708B_4ch(struct hda_codec *codec)
2449f7278fd0SJosepch Chan {
2450f7278fd0SJosepch Chan 	struct via_spec *spec;
2451f7278fd0SJosepch Chan 	int err;
2452f7278fd0SJosepch Chan 
2453f7278fd0SJosepch Chan 	/* create a codec specific record */
2454eb14a46cSHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2455f7278fd0SJosepch Chan 	if (spec == NULL)
2456f7278fd0SJosepch Chan 		return -ENOMEM;
2457f7278fd0SJosepch Chan 
2458f7278fd0SJosepch Chan 	codec->spec = spec;
2459f7278fd0SJosepch Chan 
2460f7278fd0SJosepch Chan 	/* automatic parse from the BIOS config */
2461f7278fd0SJosepch Chan 	err = vt1708B_parse_auto_config(codec);
2462f7278fd0SJosepch Chan 	if (err < 0) {
2463f7278fd0SJosepch Chan 		via_free(codec);
2464f7278fd0SJosepch Chan 		return err;
2465f7278fd0SJosepch Chan 	} else if (!err) {
2466f7278fd0SJosepch Chan 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
2467f7278fd0SJosepch Chan 		       "from BIOS.  Using genenic mode...\n");
2468f7278fd0SJosepch Chan 	}
2469f7278fd0SJosepch Chan 
247069e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
247169e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2472f7278fd0SJosepch Chan 
2473f7278fd0SJosepch Chan 	spec->stream_name_analog = "VT1708B Analog";
2474f7278fd0SJosepch Chan 	spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2475f7278fd0SJosepch Chan 	spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2476f7278fd0SJosepch Chan 
2477f7278fd0SJosepch Chan 	spec->stream_name_digital = "VT1708B Digital";
2478f7278fd0SJosepch Chan 	spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2479f7278fd0SJosepch Chan 	spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2480f7278fd0SJosepch Chan 
2481f7278fd0SJosepch Chan 	if (!spec->adc_nids && spec->input_mux) {
2482f7278fd0SJosepch Chan 		spec->adc_nids = vt1708B_adc_nids;
2483f7278fd0SJosepch Chan 		spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2484f7278fd0SJosepch Chan 		spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2485f7278fd0SJosepch Chan 		spec->num_mixers++;
2486f7278fd0SJosepch Chan 	}
2487f7278fd0SJosepch Chan 
2488f7278fd0SJosepch Chan 	codec->patch_ops = via_patch_ops;
2489f7278fd0SJosepch Chan 
2490f7278fd0SJosepch Chan 	codec->patch_ops.init = via_auto_init;
249169e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
2492f7278fd0SJosepch Chan #ifdef CONFIG_SND_HDA_POWER_SAVE
2493f7278fd0SJosepch Chan 	spec->loopback.amplist = vt1708B_loopbacks;
2494f7278fd0SJosepch Chan #endif
2495c577b8a1SJoseph Chan 
2496c577b8a1SJoseph Chan 	return 0;
2497c577b8a1SJoseph Chan }
2498c577b8a1SJoseph Chan 
2499d949cac1SHarald Welte /* Patch for VT1708S */
2500d949cac1SHarald Welte 
2501d7426329SHarald Welte /* VT1708S software backdoor based override for buggy hardware micboost
2502d7426329SHarald Welte  * setting */
2503d7426329SHarald Welte #define MIC_BOOST_VOLUME(xname, nid) {				\
2504d7426329SHarald Welte 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
2505d7426329SHarald Welte 	.name = xname,					\
2506d7426329SHarald Welte 	.index = 0,					\
2507d7426329SHarald Welte 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |	\
2508d7426329SHarald Welte 	SNDRV_CTL_ELEM_ACCESS_TLV_READ |		\
2509d7426329SHarald Welte 	SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,		\
2510d7426329SHarald Welte 	.info = mic_boost_volume_info,			\
2511d7426329SHarald Welte 	.get = snd_hda_mixer_amp_volume_get,		\
2512d7426329SHarald Welte 	.put = snd_hda_mixer_amp_volume_put,		\
2513d7426329SHarald Welte 	.tlv = { .c = mic_boost_tlv },			\
2514d7426329SHarald Welte 	.private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2515d7426329SHarald Welte 
2516d949cac1SHarald Welte /* capture mixer elements */
2517d949cac1SHarald Welte static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2518d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2519d949cac1SHarald Welte 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2520d949cac1SHarald Welte 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2521d949cac1SHarald Welte 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2522d7426329SHarald Welte 	MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2523d7426329SHarald Welte 	MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2524d949cac1SHarald Welte 	{
2525d949cac1SHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2526d949cac1SHarald Welte 		/* The multiple "Capture Source" controls confuse alsamixer
2527d949cac1SHarald Welte 		 * So call somewhat different..
2528d949cac1SHarald Welte 		 */
2529d949cac1SHarald Welte 		/* .name = "Capture Source", */
2530d949cac1SHarald Welte 		.name = "Input Source",
2531d949cac1SHarald Welte 		.count = 1,
2532d949cac1SHarald Welte 		.info = via_mux_enum_info,
2533d949cac1SHarald Welte 		.get = via_mux_enum_get,
2534d949cac1SHarald Welte 		.put = via_mux_enum_put,
2535d949cac1SHarald Welte 	},
2536d949cac1SHarald Welte 	{ } /* end */
2537d949cac1SHarald Welte };
2538d949cac1SHarald Welte 
2539d949cac1SHarald Welte static struct hda_verb vt1708S_volume_init_verbs[] = {
2540d949cac1SHarald Welte 	/* Unmute ADC0-1 and set the default input to mic-in */
2541d949cac1SHarald Welte 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2542d949cac1SHarald Welte 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2543d949cac1SHarald Welte 
2544d949cac1SHarald Welte 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2545d949cac1SHarald Welte 	 * analog-loopback mixer widget */
2546d949cac1SHarald Welte 	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2547d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2548d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2549d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2550d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2551d949cac1SHarald Welte 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2552d949cac1SHarald Welte 
2553d949cac1SHarald Welte 	/* Setup default input of PW4 to MW0 */
2554d949cac1SHarald Welte 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
25555691ec7fSHarald Welte 	/* PW9, PW10  Output enable */
2556d949cac1SHarald Welte 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
25575691ec7fSHarald Welte 	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2558d7426329SHarald Welte 	/* Enable Mic Boost Volume backdoor */
2559d7426329SHarald Welte 	{0x1, 0xf98, 0x1},
2560d949cac1SHarald Welte 	{ }
2561d949cac1SHarald Welte };
2562d949cac1SHarald Welte 
256369e52a80SHarald Welte static struct hda_verb vt1708S_uniwill_init_verbs[] = {
256469e52a80SHarald Welte 	{0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
256569e52a80SHarald Welte 	{ }
256669e52a80SHarald Welte };
256769e52a80SHarald Welte 
2568d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2569d949cac1SHarald Welte 	.substreams = 2,
2570d949cac1SHarald Welte 	.channels_min = 2,
2571d949cac1SHarald Welte 	.channels_max = 8,
2572d949cac1SHarald Welte 	.nid = 0x10, /* NID to query formats and rates */
2573d949cac1SHarald Welte 	.ops = {
2574d949cac1SHarald Welte 		.open = via_playback_pcm_open,
2575d949cac1SHarald Welte 		.prepare = via_playback_pcm_prepare,
2576d949cac1SHarald Welte 		.cleanup = via_playback_pcm_cleanup
2577d949cac1SHarald Welte 	},
2578d949cac1SHarald Welte };
2579d949cac1SHarald Welte 
2580d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2581d949cac1SHarald Welte 	.substreams = 2,
2582d949cac1SHarald Welte 	.channels_min = 2,
2583d949cac1SHarald Welte 	.channels_max = 2,
2584d949cac1SHarald Welte 	.nid = 0x13, /* NID to query formats and rates */
2585d949cac1SHarald Welte 	.ops = {
2586d949cac1SHarald Welte 		.prepare = via_capture_pcm_prepare,
2587d949cac1SHarald Welte 		.cleanup = via_capture_pcm_cleanup
2588d949cac1SHarald Welte 	},
2589d949cac1SHarald Welte };
2590d949cac1SHarald Welte 
2591d949cac1SHarald Welte static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
25925691ec7fSHarald Welte 	.substreams = 2,
2593d949cac1SHarald Welte 	.channels_min = 2,
2594d949cac1SHarald Welte 	.channels_max = 2,
2595d949cac1SHarald Welte 	/* NID is set in via_build_pcms */
2596d949cac1SHarald Welte 	.ops = {
2597d949cac1SHarald Welte 		.open = via_dig_playback_pcm_open,
2598d949cac1SHarald Welte 		.close = via_dig_playback_pcm_close,
2599d949cac1SHarald Welte 		.prepare = via_dig_playback_pcm_prepare
2600d949cac1SHarald Welte 	},
2601d949cac1SHarald Welte };
2602d949cac1SHarald Welte 
2603d949cac1SHarald Welte /* fill in the dac_nids table from the parsed pin configuration */
2604d949cac1SHarald Welte static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2605d949cac1SHarald Welte 				     const struct auto_pin_cfg *cfg)
2606d949cac1SHarald Welte {
2607d949cac1SHarald Welte 	int i;
2608d949cac1SHarald Welte 	hda_nid_t nid;
2609d949cac1SHarald Welte 
2610d949cac1SHarald Welte 	spec->multiout.num_dacs = cfg->line_outs;
2611d949cac1SHarald Welte 
2612d949cac1SHarald Welte 	spec->multiout.dac_nids = spec->private_dac_nids;
2613d949cac1SHarald Welte 
2614d949cac1SHarald Welte 	for (i = 0; i < 4; i++) {
2615d949cac1SHarald Welte 		nid = cfg->line_out_pins[i];
2616d949cac1SHarald Welte 		if (nid) {
2617d949cac1SHarald Welte 			/* config dac list */
2618d949cac1SHarald Welte 			switch (i) {
2619d949cac1SHarald Welte 			case AUTO_SEQ_FRONT:
2620d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x10;
2621d949cac1SHarald Welte 				break;
2622d949cac1SHarald Welte 			case AUTO_SEQ_CENLFE:
2623d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x24;
2624d949cac1SHarald Welte 				break;
2625d949cac1SHarald Welte 			case AUTO_SEQ_SURROUND:
2626d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x11;
2627d949cac1SHarald Welte 				break;
2628d949cac1SHarald Welte 			case AUTO_SEQ_SIDE:
2629d949cac1SHarald Welte 				spec->multiout.dac_nids[i] = 0x25;
2630d949cac1SHarald Welte 				break;
2631d949cac1SHarald Welte 			}
2632d949cac1SHarald Welte 		}
2633d949cac1SHarald Welte 	}
2634d949cac1SHarald Welte 
2635d949cac1SHarald Welte 	return 0;
2636d949cac1SHarald Welte }
2637d949cac1SHarald Welte 
2638d949cac1SHarald Welte /* add playback controls from the parsed DAC table */
2639d949cac1SHarald Welte static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2640d949cac1SHarald Welte 					     const struct auto_pin_cfg *cfg)
2641d949cac1SHarald Welte {
2642d949cac1SHarald Welte 	char name[32];
2643d949cac1SHarald Welte 	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2644d949cac1SHarald Welte 	hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2645d949cac1SHarald Welte 	hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2646d949cac1SHarald Welte 	hda_nid_t nid, nid_vol, nid_mute;
2647d949cac1SHarald Welte 	int i, err;
2648d949cac1SHarald Welte 
2649d949cac1SHarald Welte 	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2650d949cac1SHarald Welte 		nid = cfg->line_out_pins[i];
2651d949cac1SHarald Welte 
2652d949cac1SHarald Welte 		if (!nid)
2653d949cac1SHarald Welte 			continue;
2654d949cac1SHarald Welte 
2655d949cac1SHarald Welte 		nid_vol = nid_vols[i];
2656d949cac1SHarald Welte 		nid_mute = nid_mutes[i];
2657d949cac1SHarald Welte 
2658d949cac1SHarald Welte 		if (i == AUTO_SEQ_CENLFE) {
2659d949cac1SHarald Welte 			/* Center/LFE */
2660d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2661d949cac1SHarald Welte 					      "Center Playback Volume",
2662d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2663d949cac1SHarald Welte 								  HDA_OUTPUT));
2664d949cac1SHarald Welte 			if (err < 0)
2665d949cac1SHarald Welte 				return err;
2666d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2667d949cac1SHarald Welte 					      "LFE Playback Volume",
2668d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2669d949cac1SHarald Welte 								  HDA_OUTPUT));
2670d949cac1SHarald Welte 			if (err < 0)
2671d949cac1SHarald Welte 				return err;
2672d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2673d949cac1SHarald Welte 					      "Center Playback Switch",
2674d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
2675d949cac1SHarald Welte 								  1, 0,
2676d949cac1SHarald Welte 								  HDA_OUTPUT));
2677d949cac1SHarald Welte 			if (err < 0)
2678d949cac1SHarald Welte 				return err;
2679d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2680d949cac1SHarald Welte 					      "LFE Playback Switch",
2681d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
2682d949cac1SHarald Welte 								  2, 0,
2683d949cac1SHarald Welte 								  HDA_OUTPUT));
2684d949cac1SHarald Welte 			if (err < 0)
2685d949cac1SHarald Welte 				return err;
2686d949cac1SHarald Welte 		} else if (i == AUTO_SEQ_FRONT) {
2687d949cac1SHarald Welte 			/* add control to mixer index 0 */
2688d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2689d949cac1SHarald Welte 					      "Master Front Playback Volume",
2690d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2691d949cac1SHarald Welte 								  HDA_INPUT));
2692d949cac1SHarald Welte 			if (err < 0)
2693d949cac1SHarald Welte 				return err;
2694d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2695d949cac1SHarald Welte 					      "Master Front Playback Switch",
2696d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2697d949cac1SHarald Welte 								  HDA_INPUT));
2698d949cac1SHarald Welte 			if (err < 0)
2699d949cac1SHarald Welte 				return err;
2700d949cac1SHarald Welte 
2701d949cac1SHarald Welte 			/* Front */
2702d949cac1SHarald Welte 			sprintf(name, "%s Playback Volume", chname[i]);
2703d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2704d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2705d949cac1SHarald Welte 								  HDA_OUTPUT));
2706d949cac1SHarald Welte 			if (err < 0)
2707d949cac1SHarald Welte 				return err;
2708d949cac1SHarald Welte 			sprintf(name, "%s Playback Switch", chname[i]);
2709d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2710d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
2711d949cac1SHarald Welte 								  3, 0,
2712d949cac1SHarald Welte 								  HDA_OUTPUT));
2713d949cac1SHarald Welte 			if (err < 0)
2714d949cac1SHarald Welte 				return err;
2715d949cac1SHarald Welte 		} else {
2716d949cac1SHarald Welte 			sprintf(name, "%s Playback Volume", chname[i]);
2717d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2718d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2719d949cac1SHarald Welte 								  HDA_OUTPUT));
2720d949cac1SHarald Welte 			if (err < 0)
2721d949cac1SHarald Welte 				return err;
2722d949cac1SHarald Welte 			sprintf(name, "%s Playback Switch", chname[i]);
2723d949cac1SHarald Welte 			err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2724d949cac1SHarald Welte 					      HDA_COMPOSE_AMP_VAL(nid_mute,
2725d949cac1SHarald Welte 								  3, 0,
2726d949cac1SHarald Welte 								  HDA_OUTPUT));
2727d949cac1SHarald Welte 			if (err < 0)
2728d949cac1SHarald Welte 				return err;
2729d949cac1SHarald Welte 		}
2730d949cac1SHarald Welte 	}
2731d949cac1SHarald Welte 
2732d949cac1SHarald Welte 	return 0;
2733d949cac1SHarald Welte }
2734d949cac1SHarald Welte 
2735d949cac1SHarald Welte static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2736d949cac1SHarald Welte {
2737d949cac1SHarald Welte 	int err;
2738d949cac1SHarald Welte 
2739d949cac1SHarald Welte 	if (!pin)
2740d949cac1SHarald Welte 		return 0;
2741d949cac1SHarald Welte 
2742d949cac1SHarald Welte 	spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2743d949cac1SHarald Welte 
2744d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2745d949cac1SHarald Welte 			      "Headphone Playback Volume",
2746d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2747d949cac1SHarald Welte 	if (err < 0)
2748d949cac1SHarald Welte 		return err;
2749d949cac1SHarald Welte 
2750d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2751d949cac1SHarald Welte 			      "Headphone Playback Switch",
2752d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2753d949cac1SHarald Welte 	if (err < 0)
2754d949cac1SHarald Welte 		return err;
2755d949cac1SHarald Welte 
27560aa62aefSHarald Welte 	create_hp_imux(spec);
27570aa62aefSHarald Welte 
2758d949cac1SHarald Welte 	return 0;
2759d949cac1SHarald Welte }
2760d949cac1SHarald Welte 
2761d949cac1SHarald Welte /* create playback/capture controls for input pins */
2762d949cac1SHarald Welte static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2763d949cac1SHarald Welte 						const struct auto_pin_cfg *cfg)
2764d949cac1SHarald Welte {
2765d949cac1SHarald Welte 	static char *labels[] = {
2766d949cac1SHarald Welte 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2767d949cac1SHarald Welte 	};
27680aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
2769d949cac1SHarald Welte 	int i, err, idx = 0;
2770d949cac1SHarald Welte 
2771d949cac1SHarald Welte 	/* for internal loopback recording select */
2772d949cac1SHarald Welte 	imux->items[imux->num_items].label = "Stereo Mixer";
2773d949cac1SHarald Welte 	imux->items[imux->num_items].index = 5;
2774d949cac1SHarald Welte 	imux->num_items++;
2775d949cac1SHarald Welte 
2776d949cac1SHarald Welte 	for (i = 0; i < AUTO_PIN_LAST; i++) {
2777d949cac1SHarald Welte 		if (!cfg->input_pins[i])
2778d949cac1SHarald Welte 			continue;
2779d949cac1SHarald Welte 
2780d949cac1SHarald Welte 		switch (cfg->input_pins[i]) {
2781d949cac1SHarald Welte 		case 0x1a: /* Mic */
2782d949cac1SHarald Welte 			idx = 2;
2783d949cac1SHarald Welte 			break;
2784d949cac1SHarald Welte 
2785d949cac1SHarald Welte 		case 0x1b: /* Line In */
2786d949cac1SHarald Welte 			idx = 3;
2787d949cac1SHarald Welte 			break;
2788d949cac1SHarald Welte 
2789d949cac1SHarald Welte 		case 0x1e: /* Front Mic */
2790d949cac1SHarald Welte 			idx = 4;
2791d949cac1SHarald Welte 			break;
2792d949cac1SHarald Welte 
2793d949cac1SHarald Welte 		case 0x1f: /* CD */
2794d949cac1SHarald Welte 			idx = 1;
2795d949cac1SHarald Welte 			break;
2796d949cac1SHarald Welte 		}
2797d949cac1SHarald Welte 		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2798d949cac1SHarald Welte 					   idx, 0x16);
2799d949cac1SHarald Welte 		if (err < 0)
2800d949cac1SHarald Welte 			return err;
2801d949cac1SHarald Welte 		imux->items[imux->num_items].label = labels[i];
2802d949cac1SHarald Welte 		imux->items[imux->num_items].index = idx-1;
2803d949cac1SHarald Welte 		imux->num_items++;
2804d949cac1SHarald Welte 	}
2805d949cac1SHarald Welte 	return 0;
2806d949cac1SHarald Welte }
2807d949cac1SHarald Welte 
2808d949cac1SHarald Welte static int vt1708S_parse_auto_config(struct hda_codec *codec)
2809d949cac1SHarald Welte {
2810d949cac1SHarald Welte 	struct via_spec *spec = codec->spec;
2811d949cac1SHarald Welte 	int err;
2812d949cac1SHarald Welte 	static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2813d949cac1SHarald Welte 
2814d949cac1SHarald Welte 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2815d949cac1SHarald Welte 					   vt1708s_ignore);
2816d949cac1SHarald Welte 	if (err < 0)
2817d949cac1SHarald Welte 		return err;
2818d949cac1SHarald Welte 	err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2819d949cac1SHarald Welte 	if (err < 0)
2820d949cac1SHarald Welte 		return err;
2821d949cac1SHarald Welte 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2822d949cac1SHarald Welte 		return 0; /* can't find valid BIOS pin config */
2823d949cac1SHarald Welte 
2824d949cac1SHarald Welte 	err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2825d949cac1SHarald Welte 	if (err < 0)
2826d949cac1SHarald Welte 		return err;
2827d949cac1SHarald Welte 	err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2828d949cac1SHarald Welte 	if (err < 0)
2829d949cac1SHarald Welte 		return err;
2830d949cac1SHarald Welte 	err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2831d949cac1SHarald Welte 	if (err < 0)
2832d949cac1SHarald Welte 		return err;
2833d949cac1SHarald Welte 
2834d949cac1SHarald Welte 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2835d949cac1SHarald Welte 
28360852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
2837d949cac1SHarald Welte 		spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2838d949cac1SHarald Welte 
283998aa34c0SHarald Welte 	spec->extra_dig_out_nid = 0x15;
284098aa34c0SHarald Welte 
2841603c4019STakashi Iwai 	if (spec->kctls.list)
2842603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
2843d949cac1SHarald Welte 
28440aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
28450aa62aefSHarald Welte 
2846f8fdd495SHarald Welte 	if (spec->hp_mux)
28470aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
2848d949cac1SHarald Welte 
2849d949cac1SHarald Welte 	return 1;
2850d949cac1SHarald Welte }
2851d949cac1SHarald Welte 
2852d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
2853d949cac1SHarald Welte static struct hda_amp_list vt1708S_loopbacks[] = {
2854d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 1 },
2855d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 2 },
2856d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 3 },
2857d949cac1SHarald Welte 	{ 0x16, HDA_INPUT, 4 },
2858d949cac1SHarald Welte 	{ } /* end */
2859d949cac1SHarald Welte };
2860d949cac1SHarald Welte #endif
2861d949cac1SHarald Welte 
2862d949cac1SHarald Welte static int patch_vt1708S(struct hda_codec *codec)
2863d949cac1SHarald Welte {
2864d949cac1SHarald Welte 	struct via_spec *spec;
2865d949cac1SHarald Welte 	int err;
2866d949cac1SHarald Welte 
2867d949cac1SHarald Welte 	/* create a codec specific record */
2868d949cac1SHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2869d949cac1SHarald Welte 	if (spec == NULL)
2870d949cac1SHarald Welte 		return -ENOMEM;
2871d949cac1SHarald Welte 
2872d949cac1SHarald Welte 	codec->spec = spec;
2873d949cac1SHarald Welte 
2874d949cac1SHarald Welte 	/* automatic parse from the BIOS config */
2875d949cac1SHarald Welte 	err = vt1708S_parse_auto_config(codec);
2876d949cac1SHarald Welte 	if (err < 0) {
2877d949cac1SHarald Welte 		via_free(codec);
2878d949cac1SHarald Welte 		return err;
2879d949cac1SHarald Welte 	} else if (!err) {
2880d949cac1SHarald Welte 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
2881d949cac1SHarald Welte 		       "from BIOS.  Using genenic mode...\n");
2882d949cac1SHarald Welte 	}
2883d949cac1SHarald Welte 
288469e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
288569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2886d949cac1SHarald Welte 
2887d949cac1SHarald Welte 	spec->stream_name_analog = "VT1708S Analog";
2888d949cac1SHarald Welte 	spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2889d949cac1SHarald Welte 	spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2890d949cac1SHarald Welte 
2891d949cac1SHarald Welte 	spec->stream_name_digital = "VT1708S Digital";
2892d949cac1SHarald Welte 	spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2893d949cac1SHarald Welte 
2894d949cac1SHarald Welte 	if (!spec->adc_nids && spec->input_mux) {
2895d949cac1SHarald Welte 		spec->adc_nids = vt1708S_adc_nids;
2896d949cac1SHarald Welte 		spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2897d949cac1SHarald Welte 		spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2898d949cac1SHarald Welte 		spec->num_mixers++;
2899d949cac1SHarald Welte 	}
2900d949cac1SHarald Welte 
2901d949cac1SHarald Welte 	codec->patch_ops = via_patch_ops;
2902d949cac1SHarald Welte 
2903d949cac1SHarald Welte 	codec->patch_ops.init = via_auto_init;
290469e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
2905d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
2906d949cac1SHarald Welte 	spec->loopback.amplist = vt1708S_loopbacks;
2907d949cac1SHarald Welte #endif
2908d949cac1SHarald Welte 
2909d949cac1SHarald Welte 	return 0;
2910d949cac1SHarald Welte }
2911d949cac1SHarald Welte 
2912d949cac1SHarald Welte /* Patch for VT1702 */
2913d949cac1SHarald Welte 
2914d949cac1SHarald Welte /* capture mixer elements */
2915d949cac1SHarald Welte static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2916d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2917d949cac1SHarald Welte 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2918d949cac1SHarald Welte 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2919d949cac1SHarald Welte 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2920d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2921d949cac1SHarald Welte 	HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2922d949cac1SHarald Welte 	HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2923d949cac1SHarald Welte 			 HDA_INPUT),
2924d949cac1SHarald Welte 	{
2925d949cac1SHarald Welte 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2926d949cac1SHarald Welte 		/* The multiple "Capture Source" controls confuse alsamixer
2927d949cac1SHarald Welte 		 * So call somewhat different..
2928d949cac1SHarald Welte 		 */
2929d949cac1SHarald Welte 		/* .name = "Capture Source", */
2930d949cac1SHarald Welte 		.name = "Input Source",
2931d949cac1SHarald Welte 		.count = 1,
2932d949cac1SHarald Welte 		.info = via_mux_enum_info,
2933d949cac1SHarald Welte 		.get = via_mux_enum_get,
2934d949cac1SHarald Welte 		.put = via_mux_enum_put,
2935d949cac1SHarald Welte 	},
2936d949cac1SHarald Welte 	{ } /* end */
2937d949cac1SHarald Welte };
2938d949cac1SHarald Welte 
2939d949cac1SHarald Welte static struct hda_verb vt1702_volume_init_verbs[] = {
2940d949cac1SHarald Welte 	/*
2941d949cac1SHarald Welte 	 * Unmute ADC0-1 and set the default input to mic-in
2942d949cac1SHarald Welte 	 */
2943d949cac1SHarald Welte 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2944d949cac1SHarald Welte 	{0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2945d949cac1SHarald Welte 	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2946d949cac1SHarald Welte 
2947d949cac1SHarald Welte 
2948d949cac1SHarald Welte 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2949d949cac1SHarald Welte 	 * mixer widget
2950d949cac1SHarald Welte 	 */
2951d949cac1SHarald Welte 	/* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2952d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2953d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2954d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2955d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2956d949cac1SHarald Welte 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2957d949cac1SHarald Welte 
2958d949cac1SHarald Welte 	/* Setup default input of PW4 to MW0 */
2959d949cac1SHarald Welte 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2960d949cac1SHarald Welte 	/* PW6 PW7 Output enable */
2961d949cac1SHarald Welte 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2962d949cac1SHarald Welte 	{0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2963d949cac1SHarald Welte 	{ }
2964d949cac1SHarald Welte };
2965d949cac1SHarald Welte 
296669e52a80SHarald Welte static struct hda_verb vt1702_uniwill_init_verbs[] = {
296769e52a80SHarald Welte 	{0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
296869e52a80SHarald Welte 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
296969e52a80SHarald Welte 	{ }
297069e52a80SHarald Welte };
297169e52a80SHarald Welte 
2972d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_analog_playback = {
29730aa62aefSHarald Welte 	.substreams = 2,
2974d949cac1SHarald Welte 	.channels_min = 2,
2975d949cac1SHarald Welte 	.channels_max = 2,
2976d949cac1SHarald Welte 	.nid = 0x10, /* NID to query formats and rates */
2977d949cac1SHarald Welte 	.ops = {
2978d949cac1SHarald Welte 		.open = via_playback_pcm_open,
29790aa62aefSHarald Welte 		.prepare = via_playback_multi_pcm_prepare,
29800aa62aefSHarald Welte 		.cleanup = via_playback_multi_pcm_cleanup
2981d949cac1SHarald Welte 	},
2982d949cac1SHarald Welte };
2983d949cac1SHarald Welte 
2984d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2985d949cac1SHarald Welte 	.substreams = 3,
2986d949cac1SHarald Welte 	.channels_min = 2,
2987d949cac1SHarald Welte 	.channels_max = 2,
2988d949cac1SHarald Welte 	.nid = 0x12, /* NID to query formats and rates */
2989d949cac1SHarald Welte 	.ops = {
2990d949cac1SHarald Welte 		.prepare = via_capture_pcm_prepare,
2991d949cac1SHarald Welte 		.cleanup = via_capture_pcm_cleanup
2992d949cac1SHarald Welte 	},
2993d949cac1SHarald Welte };
2994d949cac1SHarald Welte 
2995d949cac1SHarald Welte static struct hda_pcm_stream vt1702_pcm_digital_playback = {
29965691ec7fSHarald Welte 	.substreams = 2,
2997d949cac1SHarald Welte 	.channels_min = 2,
2998d949cac1SHarald Welte 	.channels_max = 2,
2999d949cac1SHarald Welte 	/* NID is set in via_build_pcms */
3000d949cac1SHarald Welte 	.ops = {
3001d949cac1SHarald Welte 		.open = via_dig_playback_pcm_open,
3002d949cac1SHarald Welte 		.close = via_dig_playback_pcm_close,
3003d949cac1SHarald Welte 		.prepare = via_dig_playback_pcm_prepare
3004d949cac1SHarald Welte 	},
3005d949cac1SHarald Welte };
3006d949cac1SHarald Welte 
3007d949cac1SHarald Welte /* fill in the dac_nids table from the parsed pin configuration */
3008d949cac1SHarald Welte static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3009d949cac1SHarald Welte 				     const struct auto_pin_cfg *cfg)
3010d949cac1SHarald Welte {
3011d949cac1SHarald Welte 	spec->multiout.num_dacs = 1;
3012d949cac1SHarald Welte 	spec->multiout.dac_nids = spec->private_dac_nids;
3013d949cac1SHarald Welte 
3014d949cac1SHarald Welte 	if (cfg->line_out_pins[0]) {
3015d949cac1SHarald Welte 		/* config dac list */
3016d949cac1SHarald Welte 		spec->multiout.dac_nids[0] = 0x10;
3017d949cac1SHarald Welte 	}
3018d949cac1SHarald Welte 
3019d949cac1SHarald Welte 	return 0;
3020d949cac1SHarald Welte }
3021d949cac1SHarald Welte 
3022d949cac1SHarald Welte /* add playback controls from the parsed DAC table */
3023d949cac1SHarald Welte static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3024d949cac1SHarald Welte 					     const struct auto_pin_cfg *cfg)
3025d949cac1SHarald Welte {
3026d949cac1SHarald Welte 	int err;
3027d949cac1SHarald Welte 
3028d949cac1SHarald Welte 	if (!cfg->line_out_pins[0])
3029d949cac1SHarald Welte 		return -1;
3030d949cac1SHarald Welte 
3031d949cac1SHarald Welte 	/* add control to mixer index 0 */
3032d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3033d949cac1SHarald Welte 			      "Master Front Playback Volume",
3034d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3035d949cac1SHarald Welte 	if (err < 0)
3036d949cac1SHarald Welte 		return err;
3037d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3038d949cac1SHarald Welte 			      "Master Front Playback Switch",
3039d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3040d949cac1SHarald Welte 	if (err < 0)
3041d949cac1SHarald Welte 		return err;
3042d949cac1SHarald Welte 
3043d949cac1SHarald Welte 	/* Front */
3044d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3045d949cac1SHarald Welte 			      "Front Playback Volume",
3046d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3047d949cac1SHarald Welte 	if (err < 0)
3048d949cac1SHarald Welte 		return err;
3049d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3050d949cac1SHarald Welte 			      "Front Playback Switch",
3051d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3052d949cac1SHarald Welte 	if (err < 0)
3053d949cac1SHarald Welte 		return err;
3054d949cac1SHarald Welte 
3055d949cac1SHarald Welte 	return 0;
3056d949cac1SHarald Welte }
3057d949cac1SHarald Welte 
3058d949cac1SHarald Welte static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3059d949cac1SHarald Welte {
3060d949cac1SHarald Welte 	int err;
3061d949cac1SHarald Welte 
3062d949cac1SHarald Welte 	if (!pin)
3063d949cac1SHarald Welte 		return 0;
3064d949cac1SHarald Welte 
3065d949cac1SHarald Welte 	spec->multiout.hp_nid = 0x1D;
3066d949cac1SHarald Welte 
3067d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3068d949cac1SHarald Welte 			      "Headphone Playback Volume",
3069d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3070d949cac1SHarald Welte 	if (err < 0)
3071d949cac1SHarald Welte 		return err;
3072d949cac1SHarald Welte 
3073d949cac1SHarald Welte 	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3074d949cac1SHarald Welte 			      "Headphone Playback Switch",
3075d949cac1SHarald Welte 			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3076d949cac1SHarald Welte 	if (err < 0)
3077d949cac1SHarald Welte 		return err;
3078d949cac1SHarald Welte 
30790aa62aefSHarald Welte 	create_hp_imux(spec);
30800aa62aefSHarald Welte 
3081d949cac1SHarald Welte 	return 0;
3082d949cac1SHarald Welte }
3083d949cac1SHarald Welte 
3084d949cac1SHarald Welte /* create playback/capture controls for input pins */
3085d949cac1SHarald Welte static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3086d949cac1SHarald Welte 						const struct auto_pin_cfg *cfg)
3087d949cac1SHarald Welte {
3088d949cac1SHarald Welte 	static char *labels[] = {
3089d949cac1SHarald Welte 		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3090d949cac1SHarald Welte 	};
30910aa62aefSHarald Welte 	struct hda_input_mux *imux = &spec->private_imux[0];
3092d949cac1SHarald Welte 	int i, err, idx = 0;
3093d949cac1SHarald Welte 
3094d949cac1SHarald Welte 	/* for internal loopback recording select */
3095d949cac1SHarald Welte 	imux->items[imux->num_items].label = "Stereo Mixer";
3096d949cac1SHarald Welte 	imux->items[imux->num_items].index = 3;
3097d949cac1SHarald Welte 	imux->num_items++;
3098d949cac1SHarald Welte 
3099d949cac1SHarald Welte 	for (i = 0; i < AUTO_PIN_LAST; i++) {
3100d949cac1SHarald Welte 		if (!cfg->input_pins[i])
3101d949cac1SHarald Welte 			continue;
3102d949cac1SHarald Welte 
3103d949cac1SHarald Welte 		switch (cfg->input_pins[i]) {
3104d949cac1SHarald Welte 		case 0x14: /* Mic */
3105d949cac1SHarald Welte 			idx = 1;
3106d949cac1SHarald Welte 			break;
3107d949cac1SHarald Welte 
3108d949cac1SHarald Welte 		case 0x15: /* Line In */
3109d949cac1SHarald Welte 			idx = 2;
3110d949cac1SHarald Welte 			break;
3111d949cac1SHarald Welte 
3112d949cac1SHarald Welte 		case 0x18: /* Front Mic */
3113d949cac1SHarald Welte 			idx = 3;
3114d949cac1SHarald Welte 			break;
3115d949cac1SHarald Welte 		}
3116d949cac1SHarald Welte 		err = via_new_analog_input(spec, cfg->input_pins[i],
3117d949cac1SHarald Welte 					   labels[i], idx, 0x1A);
3118d949cac1SHarald Welte 		if (err < 0)
3119d949cac1SHarald Welte 			return err;
3120d949cac1SHarald Welte 		imux->items[imux->num_items].label = labels[i];
3121d949cac1SHarald Welte 		imux->items[imux->num_items].index = idx-1;
3122d949cac1SHarald Welte 		imux->num_items++;
3123d949cac1SHarald Welte 	}
3124d949cac1SHarald Welte 	return 0;
3125d949cac1SHarald Welte }
3126d949cac1SHarald Welte 
3127d949cac1SHarald Welte static int vt1702_parse_auto_config(struct hda_codec *codec)
3128d949cac1SHarald Welte {
3129d949cac1SHarald Welte 	struct via_spec *spec = codec->spec;
3130d949cac1SHarald Welte 	int err;
3131d949cac1SHarald Welte 	static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3132d949cac1SHarald Welte 
3133d949cac1SHarald Welte 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3134d949cac1SHarald Welte 					   vt1702_ignore);
3135d949cac1SHarald Welte 	if (err < 0)
3136d949cac1SHarald Welte 		return err;
3137d949cac1SHarald Welte 	err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3138d949cac1SHarald Welte 	if (err < 0)
3139d949cac1SHarald Welte 		return err;
3140d949cac1SHarald Welte 	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3141d949cac1SHarald Welte 		return 0; /* can't find valid BIOS pin config */
3142d949cac1SHarald Welte 
3143d949cac1SHarald Welte 	err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3144d949cac1SHarald Welte 	if (err < 0)
3145d949cac1SHarald Welte 		return err;
3146d949cac1SHarald Welte 	err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3147d949cac1SHarald Welte 	if (err < 0)
3148d949cac1SHarald Welte 		return err;
3149d949cac1SHarald Welte 	err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3150d949cac1SHarald Welte 	if (err < 0)
3151d949cac1SHarald Welte 		return err;
3152d949cac1SHarald Welte 
3153d949cac1SHarald Welte 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3154d949cac1SHarald Welte 
31550852d7a6STakashi Iwai 	if (spec->autocfg.dig_outs)
3156d949cac1SHarald Welte 		spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3157d949cac1SHarald Welte 
315898aa34c0SHarald Welte 	spec->extra_dig_out_nid = 0x1B;
315998aa34c0SHarald Welte 
3160603c4019STakashi Iwai 	if (spec->kctls.list)
3161603c4019STakashi Iwai 		spec->mixers[spec->num_mixers++] = spec->kctls.list;
3162d949cac1SHarald Welte 
31630aa62aefSHarald Welte 	spec->input_mux = &spec->private_imux[0];
31640aa62aefSHarald Welte 
3165f8fdd495SHarald Welte 	if (spec->hp_mux)
31660aa62aefSHarald Welte 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
3167d949cac1SHarald Welte 
3168d949cac1SHarald Welte 	return 1;
3169d949cac1SHarald Welte }
3170d949cac1SHarald Welte 
3171d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
3172d949cac1SHarald Welte static struct hda_amp_list vt1702_loopbacks[] = {
3173d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 1 },
3174d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 2 },
3175d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 3 },
3176d949cac1SHarald Welte 	{ 0x1A, HDA_INPUT, 4 },
3177d949cac1SHarald Welte 	{ } /* end */
3178d949cac1SHarald Welte };
3179d949cac1SHarald Welte #endif
3180d949cac1SHarald Welte 
3181d949cac1SHarald Welte static int patch_vt1702(struct hda_codec *codec)
3182d949cac1SHarald Welte {
3183d949cac1SHarald Welte 	struct via_spec *spec;
3184d949cac1SHarald Welte 	int err;
3185d949cac1SHarald Welte 	unsigned int response;
3186d949cac1SHarald Welte 	unsigned char control;
3187d949cac1SHarald Welte 
3188d949cac1SHarald Welte 	/* create a codec specific record */
3189d949cac1SHarald Welte 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3190d949cac1SHarald Welte 	if (spec == NULL)
3191d949cac1SHarald Welte 		return -ENOMEM;
3192d949cac1SHarald Welte 
3193d949cac1SHarald Welte 	codec->spec = spec;
3194d949cac1SHarald Welte 
3195d949cac1SHarald Welte 	/* automatic parse from the BIOS config */
3196d949cac1SHarald Welte 	err = vt1702_parse_auto_config(codec);
3197d949cac1SHarald Welte 	if (err < 0) {
3198d949cac1SHarald Welte 		via_free(codec);
3199d949cac1SHarald Welte 		return err;
3200d949cac1SHarald Welte 	} else if (!err) {
3201d949cac1SHarald Welte 		printk(KERN_INFO "hda_codec: Cannot set up configuration "
3202d949cac1SHarald Welte 		       "from BIOS.  Using genenic mode...\n");
3203d949cac1SHarald Welte 	}
3204d949cac1SHarald Welte 
320569e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
320669e52a80SHarald Welte 	spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3207d949cac1SHarald Welte 
3208d949cac1SHarald Welte 	spec->stream_name_analog = "VT1702 Analog";
3209d949cac1SHarald Welte 	spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3210d949cac1SHarald Welte 	spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3211d949cac1SHarald Welte 
3212d949cac1SHarald Welte 	spec->stream_name_digital = "VT1702 Digital";
3213d949cac1SHarald Welte 	spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3214d949cac1SHarald Welte 
3215d949cac1SHarald Welte 	if (!spec->adc_nids && spec->input_mux) {
3216d949cac1SHarald Welte 		spec->adc_nids = vt1702_adc_nids;
3217d949cac1SHarald Welte 		spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3218d949cac1SHarald Welte 		spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3219d949cac1SHarald Welte 		spec->num_mixers++;
3220d949cac1SHarald Welte 	}
3221d949cac1SHarald Welte 
3222d949cac1SHarald Welte 	codec->patch_ops = via_patch_ops;
3223d949cac1SHarald Welte 
3224d949cac1SHarald Welte 	codec->patch_ops.init = via_auto_init;
322569e52a80SHarald Welte 	codec->patch_ops.unsol_event = via_unsol_event;
3226d949cac1SHarald Welte #ifdef CONFIG_SND_HDA_POWER_SAVE
3227d949cac1SHarald Welte 	spec->loopback.amplist = vt1702_loopbacks;
3228d949cac1SHarald Welte #endif
3229d949cac1SHarald Welte 
3230d949cac1SHarald Welte 	/* Open backdoor */
3231d949cac1SHarald Welte 	response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3232d949cac1SHarald Welte 	control = (unsigned char)(response & 0xff);
3233d949cac1SHarald Welte 	control |= 0x3;
3234d949cac1SHarald Welte 	snd_hda_codec_write(codec,  codec->afg, 0, 0xF88, control);
3235d949cac1SHarald Welte 
3236d949cac1SHarald Welte 	/* Enable GPIO 0&1 for volume&mute control */
3237d949cac1SHarald Welte 	/* Enable GPIO 2 for DMIC-DATA */
3238d949cac1SHarald Welte 	response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3239d949cac1SHarald Welte 	control = (unsigned char)((response >> 16) & 0x3f);
3240d949cac1SHarald Welte 	snd_hda_codec_write(codec,  codec->afg, 0, 0xF82, control);
3241d949cac1SHarald Welte 
3242d949cac1SHarald Welte 	return 0;
3243d949cac1SHarald Welte }
3244d949cac1SHarald Welte 
3245c577b8a1SJoseph Chan /*
3246c577b8a1SJoseph Chan  * patch entries
3247c577b8a1SJoseph Chan  */
32481289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_via[] = {
32493218c178STakashi Iwai 	{ .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
32503218c178STakashi Iwai 	{ .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
32513218c178STakashi Iwai 	{ .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
32523218c178STakashi Iwai 	{ .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
32533218c178STakashi Iwai 	{ .id = 0x1106e710, .name = "VT1709 10-Ch",
3254f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
32553218c178STakashi Iwai 	{ .id = 0x1106e711, .name = "VT1709 10-Ch",
3256f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
32573218c178STakashi Iwai 	{ .id = 0x1106e712, .name = "VT1709 10-Ch",
3258f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
32593218c178STakashi Iwai 	{ .id = 0x1106e713, .name = "VT1709 10-Ch",
3260f7278fd0SJosepch Chan 	  .patch = patch_vt1709_10ch},
32613218c178STakashi Iwai 	{ .id = 0x1106e714, .name = "VT1709 6-Ch",
3262f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
32633218c178STakashi Iwai 	{ .id = 0x1106e715, .name = "VT1709 6-Ch",
3264f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
32653218c178STakashi Iwai 	{ .id = 0x1106e716, .name = "VT1709 6-Ch",
3266f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
32673218c178STakashi Iwai 	{ .id = 0x1106e717, .name = "VT1709 6-Ch",
3268f7278fd0SJosepch Chan 	  .patch = patch_vt1709_6ch},
32693218c178STakashi Iwai 	{ .id = 0x1106e720, .name = "VT1708B 8-Ch",
3270f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
32713218c178STakashi Iwai 	{ .id = 0x1106e721, .name = "VT1708B 8-Ch",
3272f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
32733218c178STakashi Iwai 	{ .id = 0x1106e722, .name = "VT1708B 8-Ch",
3274f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
32753218c178STakashi Iwai 	{ .id = 0x1106e723, .name = "VT1708B 8-Ch",
3276f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_8ch},
32773218c178STakashi Iwai 	{ .id = 0x1106e724, .name = "VT1708B 4-Ch",
3278f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
32793218c178STakashi Iwai 	{ .id = 0x1106e725, .name = "VT1708B 4-Ch",
3280f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
32813218c178STakashi Iwai 	{ .id = 0x1106e726, .name = "VT1708B 4-Ch",
3282f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
32833218c178STakashi Iwai 	{ .id = 0x1106e727, .name = "VT1708B 4-Ch",
3284f7278fd0SJosepch Chan 	  .patch = patch_vt1708B_4ch},
32853218c178STakashi Iwai 	{ .id = 0x11060397, .name = "VT1708S",
3286d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32873218c178STakashi Iwai 	{ .id = 0x11061397, .name = "VT1708S",
3288d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32893218c178STakashi Iwai 	{ .id = 0x11062397, .name = "VT1708S",
3290d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32913218c178STakashi Iwai 	{ .id = 0x11063397, .name = "VT1708S",
3292d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32933218c178STakashi Iwai 	{ .id = 0x11064397, .name = "VT1708S",
3294d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32953218c178STakashi Iwai 	{ .id = 0x11065397, .name = "VT1708S",
3296d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32973218c178STakashi Iwai 	{ .id = 0x11066397, .name = "VT1708S",
3298d949cac1SHarald Welte 	  .patch = patch_vt1708S},
32993218c178STakashi Iwai 	{ .id = 0x11067397, .name = "VT1708S",
3300d949cac1SHarald Welte 	  .patch = patch_vt1708S},
33013218c178STakashi Iwai 	{ .id = 0x11060398, .name = "VT1702",
3302d949cac1SHarald Welte 	  .patch = patch_vt1702},
33033218c178STakashi Iwai 	{ .id = 0x11061398, .name = "VT1702",
3304d949cac1SHarald Welte 	  .patch = patch_vt1702},
33053218c178STakashi Iwai 	{ .id = 0x11062398, .name = "VT1702",
3306d949cac1SHarald Welte 	  .patch = patch_vt1702},
33073218c178STakashi Iwai 	{ .id = 0x11063398, .name = "VT1702",
3308d949cac1SHarald Welte 	  .patch = patch_vt1702},
33093218c178STakashi Iwai 	{ .id = 0x11064398, .name = "VT1702",
3310d949cac1SHarald Welte 	  .patch = patch_vt1702},
33113218c178STakashi Iwai 	{ .id = 0x11065398, .name = "VT1702",
3312d949cac1SHarald Welte 	  .patch = patch_vt1702},
33133218c178STakashi Iwai 	{ .id = 0x11066398, .name = "VT1702",
3314d949cac1SHarald Welte 	  .patch = patch_vt1702},
33153218c178STakashi Iwai 	{ .id = 0x11067398, .name = "VT1702",
3316d949cac1SHarald Welte 	  .patch = patch_vt1702},
3317c577b8a1SJoseph Chan 	{} /* terminator */
3318c577b8a1SJoseph Chan };
33191289e9e8STakashi Iwai 
33201289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:1106*");
33211289e9e8STakashi Iwai 
33221289e9e8STakashi Iwai static struct hda_codec_preset_list via_list = {
33231289e9e8STakashi Iwai 	.preset = snd_hda_preset_via,
33241289e9e8STakashi Iwai 	.owner = THIS_MODULE,
33251289e9e8STakashi Iwai };
33261289e9e8STakashi Iwai 
33271289e9e8STakashi Iwai MODULE_LICENSE("GPL");
33281289e9e8STakashi Iwai MODULE_DESCRIPTION("VIA HD-audio codec");
33291289e9e8STakashi Iwai 
33301289e9e8STakashi Iwai static int __init patch_via_init(void)
33311289e9e8STakashi Iwai {
33321289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&via_list);
33331289e9e8STakashi Iwai }
33341289e9e8STakashi Iwai 
33351289e9e8STakashi Iwai static void __exit patch_via_exit(void)
33361289e9e8STakashi Iwai {
33371289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&via_list);
33381289e9e8STakashi Iwai }
33391289e9e8STakashi Iwai 
33401289e9e8STakashi Iwai module_init(patch_via_init)
33411289e9e8STakashi Iwai module_exit(patch_via_exit)
3342