patch_realtek.c revision 0f40502e0b5300a37c4cfc7bf93f84c2702dbbe9
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for ALC 260/880/882 codecs
5 *
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 *                    PeiSen Hou <pshou@realtek.com.tw>
8 *                    Takashi Iwai <tiwai@suse.de>
9 *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10 *
11 *  This driver is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  This driver is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with this program; if not, write to the Free Software
23 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24 */
25
26#include <sound/driver.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
32#include "hda_codec.h"
33#include "hda_local.h"
34
35#define ALC880_FRONT_EVENT		0x01
36#define ALC880_DCVOL_EVENT		0x02
37#define ALC880_HP_EVENT			0x04
38#define ALC880_MIC_EVENT		0x08
39
40/* ALC880 board config type */
41enum {
42	ALC880_3ST,
43	ALC880_3ST_DIG,
44	ALC880_5ST,
45	ALC880_5ST_DIG,
46	ALC880_W810,
47	ALC880_Z71V,
48	ALC880_6ST,
49	ALC880_6ST_DIG,
50	ALC880_F1734,
51	ALC880_ASUS,
52	ALC880_ASUS_DIG,
53	ALC880_ASUS_W1V,
54	ALC880_ASUS_DIG2,
55	ALC880_FUJITSU,
56	ALC880_UNIWILL_DIG,
57	ALC880_UNIWILL,
58	ALC880_UNIWILL_P53,
59	ALC880_CLEVO,
60	ALC880_TCL_S700,
61	ALC880_LG,
62	ALC880_LG_LW,
63#ifdef CONFIG_SND_DEBUG
64	ALC880_TEST,
65#endif
66	ALC880_AUTO,
67	ALC880_MODEL_LAST /* last tag */
68};
69
70/* ALC260 models */
71enum {
72	ALC260_BASIC,
73	ALC260_HP,
74	ALC260_HP_3013,
75	ALC260_FUJITSU_S702X,
76	ALC260_ACER,
77	ALC260_WILL,
78	ALC260_REPLACER_672V,
79#ifdef CONFIG_SND_DEBUG
80	ALC260_TEST,
81#endif
82	ALC260_AUTO,
83	ALC260_MODEL_LAST /* last tag */
84};
85
86/* ALC262 models */
87enum {
88	ALC262_BASIC,
89	ALC262_HIPPO,
90	ALC262_HIPPO_1,
91	ALC262_FUJITSU,
92	ALC262_HP_BPC,
93	ALC262_HP_BPC_D7000_WL,
94	ALC262_HP_BPC_D7000_WF,
95	ALC262_BENQ_ED8,
96	ALC262_SONY_ASSAMD,
97	ALC262_BENQ_T31,
98	ALC262_AUTO,
99	ALC262_MODEL_LAST /* last tag */
100};
101
102/* ALC268 models */
103enum {
104	ALC268_3ST,
105	ALC268_AUTO,
106	ALC268_MODEL_LAST /* last tag */
107};
108
109/* ALC861 models */
110enum {
111	ALC861_3ST,
112	ALC660_3ST,
113	ALC861_3ST_DIG,
114	ALC861_6ST_DIG,
115	ALC861_UNIWILL_M31,
116	ALC861_TOSHIBA,
117	ALC861_ASUS,
118	ALC861_ASUS_LAPTOP,
119	ALC861_AUTO,
120	ALC861_MODEL_LAST,
121};
122
123/* ALC861-VD models */
124enum {
125	ALC660VD_3ST,
126	ALC660VD_3ST_DIG,
127	ALC861VD_3ST,
128	ALC861VD_3ST_DIG,
129	ALC861VD_6ST_DIG,
130	ALC861VD_LENOVO,
131	ALC861VD_DALLAS,
132	ALC861VD_AUTO,
133	ALC861VD_MODEL_LAST,
134};
135
136/* ALC662 models */
137enum {
138	ALC662_3ST_2ch_DIG,
139	ALC662_3ST_6ch_DIG,
140	ALC662_3ST_6ch,
141	ALC662_5ST_DIG,
142	ALC662_LENOVO_101E,
143	ALC662_AUTO,
144	ALC662_MODEL_LAST,
145};
146
147/* ALC882 models */
148enum {
149	ALC882_3ST_DIG,
150	ALC882_6ST_DIG,
151	ALC882_ARIMA,
152	ALC882_W2JC,
153	ALC882_TARGA,
154	ALC882_ASUS_A7J,
155	ALC885_MACPRO,
156	ALC882_AUTO,
157	ALC882_MODEL_LAST,
158};
159
160/* ALC883 models */
161enum {
162	ALC883_3ST_2ch_DIG,
163	ALC883_3ST_6ch_DIG,
164	ALC883_3ST_6ch,
165	ALC883_6ST_DIG,
166	ALC883_TARGA_DIG,
167	ALC883_TARGA_2ch_DIG,
168	ALC883_ACER,
169	ALC883_MEDION,
170	ALC883_MEDION_MD2,
171	ALC883_LAPTOP_EAPD,
172	ALC883_LENOVO_101E_2ch,
173	ALC883_LENOVO_NB0763,
174	ALC888_LENOVO_MS7195_DIG,
175	ALC888_HP_NETTLE,
176	ALC888_HP_LUCKNOW,
177	ALC883_AUTO,
178	ALC883_MODEL_LAST,
179};
180
181/* for GPIO Poll */
182#define GPIO_MASK	0x03
183
184struct alc_spec {
185	/* codec parameterization */
186	struct snd_kcontrol_new *mixers[5];	/* mixer arrays */
187	unsigned int num_mixers;
188
189	const struct hda_verb *init_verbs[5];	/* initialization verbs
190						 * don't forget NULL
191						 * termination!
192						 */
193	unsigned int num_init_verbs;
194
195	char *stream_name_analog;	/* analog PCM stream */
196	struct hda_pcm_stream *stream_analog_playback;
197	struct hda_pcm_stream *stream_analog_capture;
198
199	char *stream_name_digital;	/* digital PCM stream */
200	struct hda_pcm_stream *stream_digital_playback;
201	struct hda_pcm_stream *stream_digital_capture;
202
203	/* playback */
204	struct hda_multi_out multiout;	/* playback set-up
205					 * max_channels, dacs must be set
206					 * dig_out_nid and hp_nid are optional
207					 */
208
209	/* capture */
210	unsigned int num_adc_nids;
211	hda_nid_t *adc_nids;
212	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
213
214	/* capture source */
215	unsigned int num_mux_defs;
216	const struct hda_input_mux *input_mux;
217	unsigned int cur_mux[3];
218
219	/* channel model */
220	const struct hda_channel_mode *channel_mode;
221	int num_channel_mode;
222	int need_dac_fix;
223
224	/* PCM information */
225	struct hda_pcm pcm_rec[3];	/* used in alc_build_pcms() */
226
227	/* dynamic controls, init_verbs and input_mux */
228	struct auto_pin_cfg autocfg;
229	unsigned int num_kctl_alloc, num_kctl_used;
230	struct snd_kcontrol_new *kctl_alloc;
231	struct hda_input_mux private_imux;
232	hda_nid_t private_dac_nids[5];
233
234	/* hooks */
235	void (*init_hook)(struct hda_codec *codec);
236	void (*unsol_event)(struct hda_codec *codec, unsigned int res);
237
238	/* for pin sensing */
239	unsigned int sense_updated: 1;
240	unsigned int jack_present: 1;
241};
242
243/*
244 * configuration template - to be copied to the spec instance
245 */
246struct alc_config_preset {
247	struct snd_kcontrol_new *mixers[5]; /* should be identical size
248					     * with spec
249					     */
250	const struct hda_verb *init_verbs[5];
251	unsigned int num_dacs;
252	hda_nid_t *dac_nids;
253	hda_nid_t dig_out_nid;		/* optional */
254	hda_nid_t hp_nid;		/* optional */
255	unsigned int num_adc_nids;
256	hda_nid_t *adc_nids;
257	hda_nid_t dig_in_nid;
258	unsigned int num_channel_mode;
259	const struct hda_channel_mode *channel_mode;
260	int need_dac_fix;
261	unsigned int num_mux_defs;
262	const struct hda_input_mux *input_mux;
263	void (*unsol_event)(struct hda_codec *, unsigned int);
264	void (*init_hook)(struct hda_codec *);
265};
266
267
268/*
269 * input MUX handling
270 */
271static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
272			     struct snd_ctl_elem_info *uinfo)
273{
274	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
275	struct alc_spec *spec = codec->spec;
276	unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
277	if (mux_idx >= spec->num_mux_defs)
278		mux_idx = 0;
279	return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
280}
281
282static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
283			    struct snd_ctl_elem_value *ucontrol)
284{
285	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
286	struct alc_spec *spec = codec->spec;
287	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
288
289	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
290	return 0;
291}
292
293static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
294			    struct snd_ctl_elem_value *ucontrol)
295{
296	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297	struct alc_spec *spec = codec->spec;
298	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
299	unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
300	return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
301				     spec->adc_nids[adc_idx],
302				     &spec->cur_mux[adc_idx]);
303}
304
305
306/*
307 * channel mode setting
308 */
309static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
310			    struct snd_ctl_elem_info *uinfo)
311{
312	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
313	struct alc_spec *spec = codec->spec;
314	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
315				    spec->num_channel_mode);
316}
317
318static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
319			   struct snd_ctl_elem_value *ucontrol)
320{
321	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
322	struct alc_spec *spec = codec->spec;
323	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
324				   spec->num_channel_mode,
325				   spec->multiout.max_channels);
326}
327
328static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
329			   struct snd_ctl_elem_value *ucontrol)
330{
331	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332	struct alc_spec *spec = codec->spec;
333	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
334				      spec->num_channel_mode,
335				      &spec->multiout.max_channels);
336	if (err >= 0 && spec->need_dac_fix)
337		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
338	return err;
339}
340
341/*
342 * Control the mode of pin widget settings via the mixer.  "pc" is used
343 * instead of "%" to avoid consequences of accidently treating the % as
344 * being part of a format specifier.  Maximum allowed length of a value is
345 * 63 characters plus NULL terminator.
346 *
347 * Note: some retasking pin complexes seem to ignore requests for input
348 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
349 * are requested.  Therefore order this list so that this behaviour will not
350 * cause problems when mixer clients move through the enum sequentially.
351 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
352 * March 2006.
353 */
354static char *alc_pin_mode_names[] = {
355	"Mic 50pc bias", "Mic 80pc bias",
356	"Line in", "Line out", "Headphone out",
357};
358static unsigned char alc_pin_mode_values[] = {
359	PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
360};
361/* The control can present all 5 options, or it can limit the options based
362 * in the pin being assumed to be exclusively an input or an output pin.  In
363 * addition, "input" pins may or may not process the mic bias option
364 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
365 * accept requests for bias as of chip versions up to March 2006) and/or
366 * wiring in the computer.
367 */
368#define ALC_PIN_DIR_IN              0x00
369#define ALC_PIN_DIR_OUT             0x01
370#define ALC_PIN_DIR_INOUT           0x02
371#define ALC_PIN_DIR_IN_NOMICBIAS    0x03
372#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
373
374/* Info about the pin modes supported by the different pin direction modes.
375 * For each direction the minimum and maximum values are given.
376 */
377static signed char alc_pin_mode_dir_info[5][2] = {
378	{ 0, 2 },    /* ALC_PIN_DIR_IN */
379	{ 3, 4 },    /* ALC_PIN_DIR_OUT */
380	{ 0, 4 },    /* ALC_PIN_DIR_INOUT */
381	{ 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
382	{ 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
383};
384#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
385#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
386#define alc_pin_mode_n_items(_dir) \
387	(alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
388
389static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
390			     struct snd_ctl_elem_info *uinfo)
391{
392	unsigned int item_num = uinfo->value.enumerated.item;
393	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
394
395	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
396	uinfo->count = 1;
397	uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
398
399	if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
400		item_num = alc_pin_mode_min(dir);
401	strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
402	return 0;
403}
404
405static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
406			    struct snd_ctl_elem_value *ucontrol)
407{
408	unsigned int i;
409	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410	hda_nid_t nid = kcontrol->private_value & 0xffff;
411	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
412	long *valp = ucontrol->value.integer.value;
413	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
414						 AC_VERB_GET_PIN_WIDGET_CONTROL,
415						 0x00);
416
417	/* Find enumerated value for current pinctl setting */
418	i = alc_pin_mode_min(dir);
419	while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
420		i++;
421	*valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
422	return 0;
423}
424
425static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
426			    struct snd_ctl_elem_value *ucontrol)
427{
428	signed int change;
429	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
430	hda_nid_t nid = kcontrol->private_value & 0xffff;
431	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
432	long val = *ucontrol->value.integer.value;
433	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
434						 AC_VERB_GET_PIN_WIDGET_CONTROL,
435						 0x00);
436
437	if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
438		val = alc_pin_mode_min(dir);
439
440	change = pinctl != alc_pin_mode_values[val];
441	if (change) {
442		/* Set pin mode to that requested */
443		snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
444				    alc_pin_mode_values[val]);
445
446		/* Also enable the retasking pin's input/output as required
447		 * for the requested pin mode.  Enum values of 2 or less are
448		 * input modes.
449		 *
450		 * Dynamically switching the input/output buffers probably
451		 * reduces noise slightly (particularly on input) so we'll
452		 * do it.  However, having both input and output buffers
453		 * enabled simultaneously doesn't seem to be problematic if
454		 * this turns out to be necessary in the future.
455		 */
456		if (val <= 2) {
457			snd_hda_codec_write(codec, nid, 0,
458					    AC_VERB_SET_AMP_GAIN_MUTE,
459					    AMP_OUT_MUTE);
460			snd_hda_codec_write(codec, nid, 0,
461					    AC_VERB_SET_AMP_GAIN_MUTE,
462					    AMP_IN_UNMUTE(0));
463		} else {
464			snd_hda_codec_write(codec, nid, 0,
465					    AC_VERB_SET_AMP_GAIN_MUTE,
466					    AMP_IN_MUTE(0));
467			snd_hda_codec_write(codec, nid, 0,
468					    AC_VERB_SET_AMP_GAIN_MUTE,
469					    AMP_OUT_UNMUTE);
470		}
471	}
472	return change;
473}
474
475#define ALC_PIN_MODE(xname, nid, dir) \
476	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
477	  .info = alc_pin_mode_info, \
478	  .get = alc_pin_mode_get, \
479	  .put = alc_pin_mode_put, \
480	  .private_value = nid | (dir<<16) }
481
482/* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
483 * together using a mask with more than one bit set.  This control is
484 * currently used only by the ALC260 test model.  At this stage they are not
485 * needed for any "production" models.
486 */
487#ifdef CONFIG_SND_DEBUG
488static int alc_gpio_data_info(struct snd_kcontrol *kcontrol,
489			      struct snd_ctl_elem_info *uinfo)
490{
491	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
492	uinfo->count = 1;
493	uinfo->value.integer.min = 0;
494	uinfo->value.integer.max = 1;
495	return 0;
496}
497
498static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
499			     struct snd_ctl_elem_value *ucontrol)
500{
501	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
502	hda_nid_t nid = kcontrol->private_value & 0xffff;
503	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
504	long *valp = ucontrol->value.integer.value;
505	unsigned int val = snd_hda_codec_read(codec, nid, 0,
506					      AC_VERB_GET_GPIO_DATA, 0x00);
507
508	*valp = (val & mask) != 0;
509	return 0;
510}
511static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
512			     struct snd_ctl_elem_value *ucontrol)
513{
514	signed int change;
515	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
516	hda_nid_t nid = kcontrol->private_value & 0xffff;
517	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
518	long val = *ucontrol->value.integer.value;
519	unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
520						    AC_VERB_GET_GPIO_DATA,
521						    0x00);
522
523	/* Set/unset the masked GPIO bit(s) as needed */
524	change = (val == 0 ? 0 : mask) != (gpio_data & mask);
525	if (val == 0)
526		gpio_data &= ~mask;
527	else
528		gpio_data |= mask;
529	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
530
531	return change;
532}
533#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
534	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
535	  .info = alc_gpio_data_info, \
536	  .get = alc_gpio_data_get, \
537	  .put = alc_gpio_data_put, \
538	  .private_value = nid | (mask<<16) }
539#endif   /* CONFIG_SND_DEBUG */
540
541/* A switch control to allow the enabling of the digital IO pins on the
542 * ALC260.  This is incredibly simplistic; the intention of this control is
543 * to provide something in the test model allowing digital outputs to be
544 * identified if present.  If models are found which can utilise these
545 * outputs a more complete mixer control can be devised for those models if
546 * necessary.
547 */
548#ifdef CONFIG_SND_DEBUG
549static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
550			       struct snd_ctl_elem_info *uinfo)
551{
552	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
553	uinfo->count = 1;
554	uinfo->value.integer.min = 0;
555	uinfo->value.integer.max = 1;
556	return 0;
557}
558
559static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
560			      struct snd_ctl_elem_value *ucontrol)
561{
562	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563	hda_nid_t nid = kcontrol->private_value & 0xffff;
564	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
565	long *valp = ucontrol->value.integer.value;
566	unsigned int val = snd_hda_codec_read(codec, nid, 0,
567					      AC_VERB_GET_DIGI_CONVERT, 0x00);
568
569	*valp = (val & mask) != 0;
570	return 0;
571}
572static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
573			      struct snd_ctl_elem_value *ucontrol)
574{
575	signed int change;
576	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
577	hda_nid_t nid = kcontrol->private_value & 0xffff;
578	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
579	long val = *ucontrol->value.integer.value;
580	unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
581						    AC_VERB_GET_DIGI_CONVERT,
582						    0x00);
583
584	/* Set/unset the masked control bit(s) as needed */
585	change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
586	if (val==0)
587		ctrl_data &= ~mask;
588	else
589		ctrl_data |= mask;
590	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
591			    ctrl_data);
592
593	return change;
594}
595#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
596	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
597	  .info = alc_spdif_ctrl_info, \
598	  .get = alc_spdif_ctrl_get, \
599	  .put = alc_spdif_ctrl_put, \
600	  .private_value = nid | (mask<<16) }
601#endif   /* CONFIG_SND_DEBUG */
602
603/*
604 * set up from the preset table
605 */
606static void setup_preset(struct alc_spec *spec,
607			 const struct alc_config_preset *preset)
608{
609	int i;
610
611	for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
612		spec->mixers[spec->num_mixers++] = preset->mixers[i];
613	for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
614	     i++)
615		spec->init_verbs[spec->num_init_verbs++] =
616			preset->init_verbs[i];
617
618	spec->channel_mode = preset->channel_mode;
619	spec->num_channel_mode = preset->num_channel_mode;
620	spec->need_dac_fix = preset->need_dac_fix;
621
622	spec->multiout.max_channels = spec->channel_mode[0].channels;
623
624	spec->multiout.num_dacs = preset->num_dacs;
625	spec->multiout.dac_nids = preset->dac_nids;
626	spec->multiout.dig_out_nid = preset->dig_out_nid;
627	spec->multiout.hp_nid = preset->hp_nid;
628
629	spec->num_mux_defs = preset->num_mux_defs;
630	if (!spec->num_mux_defs)
631		spec->num_mux_defs = 1;
632	spec->input_mux = preset->input_mux;
633
634	spec->num_adc_nids = preset->num_adc_nids;
635	spec->adc_nids = preset->adc_nids;
636	spec->dig_in_nid = preset->dig_in_nid;
637
638	spec->unsol_event = preset->unsol_event;
639	spec->init_hook = preset->init_hook;
640}
641
642/* Enable GPIO mask and set output */
643static struct hda_verb alc_gpio1_init_verbs[] = {
644	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
645	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
646	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
647	{ }
648};
649
650static struct hda_verb alc_gpio2_init_verbs[] = {
651	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
652	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
653	{0x01, AC_VERB_SET_GPIO_DATA, 0x02},
654	{ }
655};
656
657static struct hda_verb alc_gpio3_init_verbs[] = {
658	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
659	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
660	{0x01, AC_VERB_SET_GPIO_DATA, 0x03},
661	{ }
662};
663
664/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
665 *	31 ~ 16 :	Manufacture ID
666 *	15 ~ 8	:	SKU ID
667 *	7  ~ 0	:	Assembly ID
668 *	port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
669 */
670static void alc_subsystem_id(struct hda_codec *codec,
671			     unsigned int porta, unsigned int porte,
672			     unsigned int portd)
673{
674	unsigned int ass, tmp;
675
676	ass = codec->subsystem_id;
677	if (!(ass & 1))
678		return;
679
680	/* Override */
681	tmp = (ass & 0x38) >> 3;	/* external Amp control */
682	switch (tmp) {
683	case 1:
684		snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
685		break;
686	case 3:
687		snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
688		break;
689	case 7:
690		snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
691		break;
692	case 5:
693		switch (codec->vendor_id) {
694		case 0x10ec0862:
695		case 0x10ec0660:
696		case 0x10ec0662:
697		case 0x10ec0267:
698		case 0x10ec0268:
699			snd_hda_codec_write(codec, 0x14, 0,
700					    AC_VERB_SET_EAPD_BTLENABLE, 2);
701			snd_hda_codec_write(codec, 0x15, 0,
702					    AC_VERB_SET_EAPD_BTLENABLE, 2);
703			return;
704		}
705	case 6:
706		if (ass & 4) {	/* bit 2 : 0 = Desktop, 1 = Laptop */
707			hda_nid_t port = 0;
708			tmp = (ass & 0x1800) >> 11;
709			switch (tmp) {
710			case 0: port = porta; break;
711			case 1: port = porte; break;
712			case 2: port = portd; break;
713			}
714			if (port)
715				snd_hda_codec_write(codec, port, 0,
716						    AC_VERB_SET_EAPD_BTLENABLE,
717						    2);
718		}
719		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
720		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF,
721				    (tmp == 5 ? 0x3040 : 0x3050));
722		break;
723	}
724}
725
726/*
727 * ALC880 3-stack model
728 *
729 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
730 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
731 *                 F-Mic = 0x1b, HP = 0x19
732 */
733
734static hda_nid_t alc880_dac_nids[4] = {
735	/* front, rear, clfe, rear_surr */
736	0x02, 0x05, 0x04, 0x03
737};
738
739static hda_nid_t alc880_adc_nids[3] = {
740	/* ADC0-2 */
741	0x07, 0x08, 0x09,
742};
743
744/* The datasheet says the node 0x07 is connected from inputs,
745 * but it shows zero connection in the real implementation on some devices.
746 * Note: this is a 915GAV bug, fixed on 915GLV
747 */
748static hda_nid_t alc880_adc_nids_alt[2] = {
749	/* ADC1-2 */
750	0x08, 0x09,
751};
752
753#define ALC880_DIGOUT_NID	0x06
754#define ALC880_DIGIN_NID	0x0a
755
756static struct hda_input_mux alc880_capture_source = {
757	.num_items = 4,
758	.items = {
759		{ "Mic", 0x0 },
760		{ "Front Mic", 0x3 },
761		{ "Line", 0x2 },
762		{ "CD", 0x4 },
763	},
764};
765
766/* channel source setting (2/6 channel selection for 3-stack) */
767/* 2ch mode */
768static struct hda_verb alc880_threestack_ch2_init[] = {
769	/* set line-in to input, mute it */
770	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
771	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
772	/* set mic-in to input vref 80%, mute it */
773	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
774	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
775	{ } /* end */
776};
777
778/* 6ch mode */
779static struct hda_verb alc880_threestack_ch6_init[] = {
780	/* set line-in to output, unmute it */
781	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
782	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
783	/* set mic-in to output, unmute it */
784	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
785	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
786	{ } /* end */
787};
788
789static struct hda_channel_mode alc880_threestack_modes[2] = {
790	{ 2, alc880_threestack_ch2_init },
791	{ 6, alc880_threestack_ch6_init },
792};
793
794static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
795	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
796	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
797	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
798	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
799	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
800	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
801	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
802	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
803	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
804	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
805	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
806	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
807	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
808	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
809	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
810	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
811	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
812	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
813	HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
814	{
815		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
816		.name = "Channel Mode",
817		.info = alc_ch_mode_info,
818		.get = alc_ch_mode_get,
819		.put = alc_ch_mode_put,
820	},
821	{ } /* end */
822};
823
824/* capture mixer elements */
825static struct snd_kcontrol_new alc880_capture_mixer[] = {
826	HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
827	HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
828	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
829	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
830	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
831	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
832	{
833		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
834		/* The multiple "Capture Source" controls confuse alsamixer
835		 * So call somewhat different..
836		 * FIXME: the controls appear in the "playback" view!
837		 */
838		/* .name = "Capture Source", */
839		.name = "Input Source",
840		.count = 3,
841		.info = alc_mux_enum_info,
842		.get = alc_mux_enum_get,
843		.put = alc_mux_enum_put,
844	},
845	{ } /* end */
846};
847
848/* capture mixer elements (in case NID 0x07 not available) */
849static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
850	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
851	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
852	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
853	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
854	{
855		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
856		/* The multiple "Capture Source" controls confuse alsamixer
857		 * So call somewhat different..
858		 * FIXME: the controls appear in the "playback" view!
859		 */
860		/* .name = "Capture Source", */
861		.name = "Input Source",
862		.count = 2,
863		.info = alc_mux_enum_info,
864		.get = alc_mux_enum_get,
865		.put = alc_mux_enum_put,
866	},
867	{ } /* end */
868};
869
870
871
872/*
873 * ALC880 5-stack model
874 *
875 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
876 *      Side = 0x02 (0xd)
877 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
878 *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
879 */
880
881/* additional mixers to alc880_three_stack_mixer */
882static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
883	HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
884	HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
885	{ } /* end */
886};
887
888/* channel source setting (6/8 channel selection for 5-stack) */
889/* 6ch mode */
890static struct hda_verb alc880_fivestack_ch6_init[] = {
891	/* set line-in to input, mute it */
892	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
893	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
894	{ } /* end */
895};
896
897/* 8ch mode */
898static struct hda_verb alc880_fivestack_ch8_init[] = {
899	/* set line-in to output, unmute it */
900	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
901	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
902	{ } /* end */
903};
904
905static struct hda_channel_mode alc880_fivestack_modes[2] = {
906	{ 6, alc880_fivestack_ch6_init },
907	{ 8, alc880_fivestack_ch8_init },
908};
909
910
911/*
912 * ALC880 6-stack model
913 *
914 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
915 *      Side = 0x05 (0x0f)
916 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
917 *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
918 */
919
920static hda_nid_t alc880_6st_dac_nids[4] = {
921	/* front, rear, clfe, rear_surr */
922	0x02, 0x03, 0x04, 0x05
923};
924
925static struct hda_input_mux alc880_6stack_capture_source = {
926	.num_items = 4,
927	.items = {
928		{ "Mic", 0x0 },
929		{ "Front Mic", 0x1 },
930		{ "Line", 0x2 },
931		{ "CD", 0x4 },
932	},
933};
934
935/* fixed 8-channels */
936static struct hda_channel_mode alc880_sixstack_modes[1] = {
937	{ 8, NULL },
938};
939
940static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
941	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
942	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
943	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
944	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
945	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
946	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
947	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
948	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
949	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
950	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
951	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
952	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
953	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
954	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
955	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
956	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
957	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
958	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
959	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
960	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
961	{
962		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
963		.name = "Channel Mode",
964		.info = alc_ch_mode_info,
965		.get = alc_ch_mode_get,
966		.put = alc_ch_mode_put,
967	},
968	{ } /* end */
969};
970
971
972/*
973 * ALC880 W810 model
974 *
975 * W810 has rear IO for:
976 * Front (DAC 02)
977 * Surround (DAC 03)
978 * Center/LFE (DAC 04)
979 * Digital out (06)
980 *
981 * The system also has a pair of internal speakers, and a headphone jack.
982 * These are both connected to Line2 on the codec, hence to DAC 02.
983 *
984 * There is a variable resistor to control the speaker or headphone
985 * volume. This is a hardware-only device without a software API.
986 *
987 * Plugging headphones in will disable the internal speakers. This is
988 * implemented in hardware, not via the driver using jack sense. In
989 * a similar fashion, plugging into the rear socket marked "front" will
990 * disable both the speakers and headphones.
991 *
992 * For input, there's a microphone jack, and an "audio in" jack.
993 * These may not do anything useful with this driver yet, because I
994 * haven't setup any initialization verbs for these yet...
995 */
996
997static hda_nid_t alc880_w810_dac_nids[3] = {
998	/* front, rear/surround, clfe */
999	0x02, 0x03, 0x04
1000};
1001
1002/* fixed 6 channels */
1003static struct hda_channel_mode alc880_w810_modes[1] = {
1004	{ 6, NULL }
1005};
1006
1007/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1008static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1009	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1010	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1011	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1012	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1013	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1014	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1015	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1016	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1017	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1018	{ } /* end */
1019};
1020
1021
1022/*
1023 * Z710V model
1024 *
1025 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1026 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1027 *                 Line = 0x1a
1028 */
1029
1030static hda_nid_t alc880_z71v_dac_nids[1] = {
1031	0x02
1032};
1033#define ALC880_Z71V_HP_DAC	0x03
1034
1035/* fixed 2 channels */
1036static struct hda_channel_mode alc880_2_jack_modes[1] = {
1037	{ 2, NULL }
1038};
1039
1040static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1041	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1042	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1043	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1044	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1045	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1046	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1047	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1048	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1049	{ } /* end */
1050};
1051
1052
1053/* FIXME! */
1054/*
1055 * ALC880 F1734 model
1056 *
1057 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1058 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1059 */
1060
1061static hda_nid_t alc880_f1734_dac_nids[1] = {
1062	0x03
1063};
1064#define ALC880_F1734_HP_DAC	0x02
1065
1066static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1067	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1068	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1069	HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1070	HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1071	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1072	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1073	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1074	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1075	{ } /* end */
1076};
1077
1078
1079/* FIXME! */
1080/*
1081 * ALC880 ASUS model
1082 *
1083 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1084 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1085 *  Mic = 0x18, Line = 0x1a
1086 */
1087
1088#define alc880_asus_dac_nids	alc880_w810_dac_nids	/* identical with w810 */
1089#define alc880_asus_modes	alc880_threestack_modes	/* 2/6 channel mode */
1090
1091static struct snd_kcontrol_new alc880_asus_mixer[] = {
1092	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1093	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1094	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1095	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1096	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1097	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1098	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1099	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1100	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1101	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1102	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1103	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1104	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1105	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1106	{
1107		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108		.name = "Channel Mode",
1109		.info = alc_ch_mode_info,
1110		.get = alc_ch_mode_get,
1111		.put = alc_ch_mode_put,
1112	},
1113	{ } /* end */
1114};
1115
1116/* FIXME! */
1117/*
1118 * ALC880 ASUS W1V model
1119 *
1120 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1121 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1122 *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1123 */
1124
1125/* additional mixers to alc880_asus_mixer */
1126static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1127	HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1128	HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1129	{ } /* end */
1130};
1131
1132/* additional mixers to alc880_asus_mixer */
1133static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1134	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1135	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1136	{ } /* end */
1137};
1138
1139/* TCL S700 */
1140static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1141	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1142	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1143	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1144	HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1145	HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1146	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1147	HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1148	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1149	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1150	{
1151		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1152		/* The multiple "Capture Source" controls confuse alsamixer
1153		 * So call somewhat different..
1154		 * FIXME: the controls appear in the "playback" view!
1155		 */
1156		/* .name = "Capture Source", */
1157		.name = "Input Source",
1158		.count = 1,
1159		.info = alc_mux_enum_info,
1160		.get = alc_mux_enum_get,
1161		.put = alc_mux_enum_put,
1162	},
1163	{ } /* end */
1164};
1165
1166/* Uniwill */
1167static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1168	HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1169	HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1170	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1171	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1172	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1173	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1174	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1175	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1176	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1177	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1178	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1179	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1180	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1181	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1182	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1183	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1184	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1185	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1186	{
1187		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1188		.name = "Channel Mode",
1189		.info = alc_ch_mode_info,
1190		.get = alc_ch_mode_get,
1191		.put = alc_ch_mode_put,
1192	},
1193	{ } /* end */
1194};
1195
1196static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1197	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1198	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1199	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1200	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1201	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1202	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1203	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1204	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1205	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1206	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1207	{ } /* end */
1208};
1209
1210static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1211	HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1212	HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1213	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1214	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1215	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1216	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1217	{ } /* end */
1218};
1219
1220/*
1221 * build control elements
1222 */
1223static int alc_build_controls(struct hda_codec *codec)
1224{
1225	struct alc_spec *spec = codec->spec;
1226	int err;
1227	int i;
1228
1229	for (i = 0; i < spec->num_mixers; i++) {
1230		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1231		if (err < 0)
1232			return err;
1233	}
1234
1235	if (spec->multiout.dig_out_nid) {
1236		err = snd_hda_create_spdif_out_ctls(codec,
1237						    spec->multiout.dig_out_nid);
1238		if (err < 0)
1239			return err;
1240	}
1241	if (spec->dig_in_nid) {
1242		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1243		if (err < 0)
1244			return err;
1245	}
1246	return 0;
1247}
1248
1249
1250/*
1251 * initialize the codec volumes, etc
1252 */
1253
1254/*
1255 * generic initialization of ADC, input mixers and output mixers
1256 */
1257static struct hda_verb alc880_volume_init_verbs[] = {
1258	/*
1259	 * Unmute ADC0-2 and set the default input to mic-in
1260	 */
1261	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1262	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1263	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1264	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1265	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1266	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1267
1268	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1269	 * mixer widget
1270	 * Note: PASD motherboards uses the Line In 2 as the input for front
1271	 * panel mic (mic 2)
1272	 */
1273	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1274	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1275	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1276	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1277	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1278	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1279
1280	/*
1281	 * Set up output mixers (0x0c - 0x0f)
1282	 */
1283	/* set vol=0 to output mixers */
1284	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1285	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1286	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1287	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1288	/* set up input amps for analog loopback */
1289	/* Amp Indices: DAC = 0, mixer = 1 */
1290	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1291	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1292	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1293	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1294	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1295	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1296	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1297	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1298
1299	{ }
1300};
1301
1302/*
1303 * 3-stack pin configuration:
1304 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1305 */
1306static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1307	/*
1308	 * preset connection lists of input pins
1309	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1310	 */
1311	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1312	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1313	{0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1314
1315	/*
1316	 * Set pin mode and muting
1317	 */
1318	/* set front pin widgets 0x14 for output */
1319	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1320	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1321	/* Mic1 (rear panel) pin widget for input and vref at 80% */
1322	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1323	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1324	/* Mic2 (as headphone out) for HP output */
1325	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1326	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1327	/* Line In pin widget for input */
1328	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1329	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1330	/* Line2 (as front mic) pin widget for input and vref at 80% */
1331	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1332	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1333	/* CD pin widget for input */
1334	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1335
1336	{ }
1337};
1338
1339/*
1340 * 5-stack pin configuration:
1341 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1342 * line-in/side = 0x1a, f-mic = 0x1b
1343 */
1344static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1345	/*
1346	 * preset connection lists of input pins
1347	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1348	 */
1349	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1350	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1351
1352	/*
1353	 * Set pin mode and muting
1354	 */
1355	/* set pin widgets 0x14-0x17 for output */
1356	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1357	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1358	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1359	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1360	/* unmute pins for output (no gain on this amp) */
1361	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1362	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1363	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1364	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1365
1366	/* Mic1 (rear panel) pin widget for input and vref at 80% */
1367	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1368	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1369	/* Mic2 (as headphone out) for HP output */
1370	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1371	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1372	/* Line In pin widget for input */
1373	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1374	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1375	/* Line2 (as front mic) pin widget for input and vref at 80% */
1376	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1377	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1378	/* CD pin widget for input */
1379	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1380
1381	{ }
1382};
1383
1384/*
1385 * W810 pin configuration:
1386 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1387 */
1388static struct hda_verb alc880_pin_w810_init_verbs[] = {
1389	/* hphone/speaker input selector: front DAC */
1390	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1391
1392	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1393	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1394	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1395	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1396	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1397	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1398
1399	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1400	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1401
1402	{ }
1403};
1404
1405/*
1406 * Z71V pin configuration:
1407 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1408 */
1409static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1410	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1411	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1412	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1413	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1414
1415	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1416	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1417	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1418	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1419
1420	{ }
1421};
1422
1423/*
1424 * 6-stack pin configuration:
1425 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1426 * f-mic = 0x19, line = 0x1a, HP = 0x1b
1427 */
1428static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1429	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1430
1431	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1432	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1433	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1434	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1435	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1436	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1437	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1438	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1439
1440	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1441	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1442	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1443	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1444	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1445	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1446	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1447	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1448	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1449
1450	{ }
1451};
1452
1453/*
1454 * Uniwill pin configuration:
1455 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1456 * line = 0x1a
1457 */
1458static struct hda_verb alc880_uniwill_init_verbs[] = {
1459	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1460
1461	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1462	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1463	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1464	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1465	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1466	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1467	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1469	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1470	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1471	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1472	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1473	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1474	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1475
1476	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1477	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1478	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1479	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1480	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1481	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1482	/* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1483	/* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1484	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1485
1486	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1487	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1488
1489	{ }
1490};
1491
1492/*
1493* Uniwill P53
1494* HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1495 */
1496static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1497	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1498
1499	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1500	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1501	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1502	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1503	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1504	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1505	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1506	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1507	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1508	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1509	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1510	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1511
1512	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1513	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1514	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1515	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1516	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1517	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1518
1519	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1520	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1521
1522	{ }
1523};
1524
1525static struct hda_verb alc880_beep_init_verbs[] = {
1526	{ 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1527	{ }
1528};
1529
1530/* toggle speaker-output according to the hp-jack state */
1531static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1532{
1533 	unsigned int present;
1534	unsigned char bits;
1535
1536 	present = snd_hda_codec_read(codec, 0x14, 0,
1537				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1538	bits = present ? 0x80 : 0;
1539	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
1540				 0x80, bits);
1541	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
1542				 0x80, bits);
1543	snd_hda_codec_amp_update(codec, 0x16, 0, HDA_OUTPUT, 0,
1544				 0x80, bits);
1545	snd_hda_codec_amp_update(codec, 0x16, 1, HDA_OUTPUT, 0,
1546				 0x80, bits);
1547}
1548
1549/* auto-toggle front mic */
1550static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1551{
1552 	unsigned int present;
1553	unsigned char bits;
1554
1555	present = snd_hda_codec_read(codec, 0x18, 0,
1556				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1557	bits = present ? 0x80 : 0;
1558	snd_hda_codec_amp_update(codec, 0x0b, 0, HDA_INPUT, 1,
1559				 0x80, bits);
1560	snd_hda_codec_amp_update(codec, 0x0b, 1, HDA_INPUT, 1,
1561				 0x80, bits);
1562}
1563
1564static void alc880_uniwill_automute(struct hda_codec *codec)
1565{
1566	alc880_uniwill_hp_automute(codec);
1567	alc880_uniwill_mic_automute(codec);
1568}
1569
1570static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1571				       unsigned int res)
1572{
1573	/* Looks like the unsol event is incompatible with the standard
1574	 * definition.  4bit tag is placed at 28 bit!
1575	 */
1576	switch (res >> 28) {
1577	case ALC880_HP_EVENT:
1578		alc880_uniwill_hp_automute(codec);
1579		break;
1580	case ALC880_MIC_EVENT:
1581		alc880_uniwill_mic_automute(codec);
1582		break;
1583	}
1584}
1585
1586static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1587{
1588 	unsigned int present;
1589	unsigned char bits;
1590
1591 	present = snd_hda_codec_read(codec, 0x14, 0,
1592				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1593	bits = present ? 0x80 : 0;
1594	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_INPUT, 0,
1595				 0x80, bits);
1596	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_INPUT, 0,
1597				 0x80, bits);
1598}
1599
1600static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1601{
1602	unsigned int present;
1603
1604	present = snd_hda_codec_read(codec, 0x21, 0,
1605				     AC_VERB_GET_VOLUME_KNOB_CONTROL, 0) & 0x7f;
1606
1607	snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
1608				 0x7f, present);
1609	snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
1610				 0x7f,  present);
1611
1612	snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
1613				 0x7f,  present);
1614	snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
1615				 0x7f, present);
1616
1617}
1618static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1619					   unsigned int res)
1620{
1621	/* Looks like the unsol event is incompatible with the standard
1622	 * definition.  4bit tag is placed at 28 bit!
1623	 */
1624	if ((res >> 28) == ALC880_HP_EVENT)
1625		alc880_uniwill_p53_hp_automute(codec);
1626	if ((res >> 28) == ALC880_DCVOL_EVENT)
1627		alc880_uniwill_p53_dcvol_automute(codec);
1628}
1629
1630/* FIXME! */
1631/*
1632 * F1734 pin configuration:
1633 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1634 */
1635static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1636	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1637	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1638	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1639	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1640
1641	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1642	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1643	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1644	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1645
1646	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1647	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1648	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1649	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1650	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1651	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1652	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1654	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1655
1656	{ }
1657};
1658
1659/* FIXME! */
1660/*
1661 * ASUS pin configuration:
1662 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1663 */
1664static struct hda_verb alc880_pin_asus_init_verbs[] = {
1665	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1666	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1667	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1668	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1669
1670	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1671	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1672	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1673	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1675	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1676	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1677	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1678
1679	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1680	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1681	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1682	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1683	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1684	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1685	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1686	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1687	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1688
1689	{ }
1690};
1691
1692/* Enable GPIO mask and set output */
1693#define alc880_gpio1_init_verbs	alc_gpio1_init_verbs
1694#define alc880_gpio2_init_verbs	alc_gpio2_init_verbs
1695
1696/* Clevo m520g init */
1697static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1698	/* headphone output */
1699	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1700	/* line-out */
1701	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1702	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1703	/* Line-in */
1704	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1705	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706	/* CD */
1707	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1708	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709	/* Mic1 (rear panel) */
1710	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1712	/* Mic2 (front panel) */
1713	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1714	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1715	/* headphone */
1716	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1717	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1718        /* change to EAPD mode */
1719	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1720	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1721
1722	{ }
1723};
1724
1725static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1726	/* change to EAPD mode */
1727	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1728	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1729
1730	/* Headphone output */
1731	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1732	/* Front output*/
1733	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1734	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1735
1736	/* Line In pin widget for input */
1737	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1738	/* CD pin widget for input */
1739	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1740	/* Mic1 (rear panel) pin widget for input and vref at 80% */
1741	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1742
1743	/* change to EAPD mode */
1744	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1745	{0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1746
1747	{ }
1748};
1749
1750/*
1751 * LG m1 express dual
1752 *
1753 * Pin assignment:
1754 *   Rear Line-In/Out (blue): 0x14
1755 *   Build-in Mic-In: 0x15
1756 *   Speaker-out: 0x17
1757 *   HP-Out (green): 0x1b
1758 *   Mic-In/Out (red): 0x19
1759 *   SPDIF-Out: 0x1e
1760 */
1761
1762/* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1763static hda_nid_t alc880_lg_dac_nids[3] = {
1764	0x05, 0x02, 0x03
1765};
1766
1767/* seems analog CD is not working */
1768static struct hda_input_mux alc880_lg_capture_source = {
1769	.num_items = 3,
1770	.items = {
1771		{ "Mic", 0x1 },
1772		{ "Line", 0x5 },
1773		{ "Internal Mic", 0x6 },
1774	},
1775};
1776
1777/* 2,4,6 channel modes */
1778static struct hda_verb alc880_lg_ch2_init[] = {
1779	/* set line-in and mic-in to input */
1780	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1781	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1782	{ }
1783};
1784
1785static struct hda_verb alc880_lg_ch4_init[] = {
1786	/* set line-in to out and mic-in to input */
1787	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1788	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1789	{ }
1790};
1791
1792static struct hda_verb alc880_lg_ch6_init[] = {
1793	/* set line-in and mic-in to output */
1794	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1795	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1796	{ }
1797};
1798
1799static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1800	{ 2, alc880_lg_ch2_init },
1801	{ 4, alc880_lg_ch4_init },
1802	{ 6, alc880_lg_ch6_init },
1803};
1804
1805static struct snd_kcontrol_new alc880_lg_mixer[] = {
1806	/* FIXME: it's not really "master" but front channels */
1807	HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1808	HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1809	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1810	HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1811	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1812	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1813	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1814	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1815	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1816	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1817	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1818	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1819	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1820	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1821	{
1822		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1823		.name = "Channel Mode",
1824		.info = alc_ch_mode_info,
1825		.get = alc_ch_mode_get,
1826		.put = alc_ch_mode_put,
1827	},
1828	{ } /* end */
1829};
1830
1831static struct hda_verb alc880_lg_init_verbs[] = {
1832	/* set capture source to mic-in */
1833	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1834	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1835	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1836	/* mute all amp mixer inputs */
1837	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1838	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
1839	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1840	/* line-in to input */
1841	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1842	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1843	/* built-in mic */
1844	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1845	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1846	/* speaker-out */
1847	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1848	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849	/* mic-in to input */
1850	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1851	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1852	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1853	/* HP-out */
1854	{0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1855	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1856	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1857	/* jack sense */
1858	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1859	{ }
1860};
1861
1862/* toggle speaker-output according to the hp-jack state */
1863static void alc880_lg_automute(struct hda_codec *codec)
1864{
1865	unsigned int present;
1866	unsigned char bits;
1867
1868	present = snd_hda_codec_read(codec, 0x1b, 0,
1869				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1870	bits = present ? 0x80 : 0;
1871	snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
1872				 0x80, bits);
1873	snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
1874				 0x80, bits);
1875}
1876
1877static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1878{
1879	/* Looks like the unsol event is incompatible with the standard
1880	 * definition.  4bit tag is placed at 28 bit!
1881	 */
1882	if ((res >> 28) == 0x01)
1883		alc880_lg_automute(codec);
1884}
1885
1886/*
1887 * LG LW20
1888 *
1889 * Pin assignment:
1890 *   Speaker-out: 0x14
1891 *   Mic-In: 0x18
1892 *   Built-in Mic-In: 0x19 (?)
1893 *   HP-Out: 0x1b
1894 *   SPDIF-Out: 0x1e
1895 */
1896
1897/* seems analog CD is not working */
1898static struct hda_input_mux alc880_lg_lw_capture_source = {
1899	.num_items = 2,
1900	.items = {
1901		{ "Mic", 0x0 },
1902		{ "Internal Mic", 0x1 },
1903	},
1904};
1905
1906#define alc880_lg_lw_modes alc880_threestack_modes
1907
1908static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1909	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1910	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1911	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1912	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1913	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1914	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1915	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1916	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1917	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1918	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1919	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1920	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1921	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1922	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1923	{
1924		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1925		.name = "Channel Mode",
1926		.info = alc_ch_mode_info,
1927		.get = alc_ch_mode_get,
1928		.put = alc_ch_mode_put,
1929	},
1930	{ } /* end */
1931};
1932
1933static struct hda_verb alc880_lg_lw_init_verbs[] = {
1934	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1935	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1936	{0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1937
1938	/* set capture source to mic-in */
1939	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1940	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1941	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1942	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1943	/* speaker-out */
1944	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1945	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1946	/* HP-out */
1947	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1948	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1949	/* mic-in to input */
1950	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1951	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1952	/* built-in mic */
1953	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1954	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1955	/* jack sense */
1956	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1957	{ }
1958};
1959
1960/* toggle speaker-output according to the hp-jack state */
1961static void alc880_lg_lw_automute(struct hda_codec *codec)
1962{
1963	unsigned int present;
1964	unsigned char bits;
1965
1966	present = snd_hda_codec_read(codec, 0x1b, 0,
1967				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1968	bits = present ? 0x80 : 0;
1969	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
1970				 0x80, bits);
1971	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
1972				 0x80, bits);
1973}
1974
1975static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1976{
1977	/* Looks like the unsol event is incompatible with the standard
1978	 * definition.  4bit tag is placed at 28 bit!
1979	 */
1980	if ((res >> 28) == 0x01)
1981		alc880_lg_lw_automute(codec);
1982}
1983
1984/*
1985 * Common callbacks
1986 */
1987
1988static int alc_init(struct hda_codec *codec)
1989{
1990	struct alc_spec *spec = codec->spec;
1991	unsigned int i;
1992
1993	for (i = 0; i < spec->num_init_verbs; i++)
1994		snd_hda_sequence_write(codec, spec->init_verbs[i]);
1995
1996	if (spec->init_hook)
1997		spec->init_hook(codec);
1998
1999	return 0;
2000}
2001
2002static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2003{
2004	struct alc_spec *spec = codec->spec;
2005
2006	if (spec->unsol_event)
2007		spec->unsol_event(codec, res);
2008}
2009
2010#ifdef CONFIG_PM
2011/*
2012 * resume
2013 */
2014static int alc_resume(struct hda_codec *codec)
2015{
2016	struct alc_spec *spec = codec->spec;
2017	int i;
2018
2019	alc_init(codec);
2020	for (i = 0; i < spec->num_mixers; i++)
2021		snd_hda_resume_ctls(codec, spec->mixers[i]);
2022	if (spec->multiout.dig_out_nid)
2023		snd_hda_resume_spdif_out(codec);
2024	if (spec->dig_in_nid)
2025		snd_hda_resume_spdif_in(codec);
2026
2027	return 0;
2028}
2029#endif
2030
2031/*
2032 * Analog playback callbacks
2033 */
2034static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2035				    struct hda_codec *codec,
2036				    struct snd_pcm_substream *substream)
2037{
2038	struct alc_spec *spec = codec->spec;
2039	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2040}
2041
2042static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2043				       struct hda_codec *codec,
2044				       unsigned int stream_tag,
2045				       unsigned int format,
2046				       struct snd_pcm_substream *substream)
2047{
2048	struct alc_spec *spec = codec->spec;
2049	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2050						stream_tag, format, substream);
2051}
2052
2053static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2054				       struct hda_codec *codec,
2055				       struct snd_pcm_substream *substream)
2056{
2057	struct alc_spec *spec = codec->spec;
2058	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2059}
2060
2061/*
2062 * Digital out
2063 */
2064static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2065					struct hda_codec *codec,
2066					struct snd_pcm_substream *substream)
2067{
2068	struct alc_spec *spec = codec->spec;
2069	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2070}
2071
2072static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2073					   struct hda_codec *codec,
2074					   unsigned int stream_tag,
2075					   unsigned int format,
2076					   struct snd_pcm_substream *substream)
2077{
2078	struct alc_spec *spec = codec->spec;
2079	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2080					     stream_tag, format, substream);
2081}
2082
2083static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2084					 struct hda_codec *codec,
2085					 struct snd_pcm_substream *substream)
2086{
2087	struct alc_spec *spec = codec->spec;
2088	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2089}
2090
2091/*
2092 * Analog capture
2093 */
2094static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2095				      struct hda_codec *codec,
2096				      unsigned int stream_tag,
2097				      unsigned int format,
2098				      struct snd_pcm_substream *substream)
2099{
2100	struct alc_spec *spec = codec->spec;
2101
2102	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2103				   stream_tag, 0, format);
2104	return 0;
2105}
2106
2107static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2108				      struct hda_codec *codec,
2109				      struct snd_pcm_substream *substream)
2110{
2111	struct alc_spec *spec = codec->spec;
2112
2113	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2114				   0, 0, 0);
2115	return 0;
2116}
2117
2118
2119/*
2120 */
2121static struct hda_pcm_stream alc880_pcm_analog_playback = {
2122	.substreams = 1,
2123	.channels_min = 2,
2124	.channels_max = 8,
2125	/* NID is set in alc_build_pcms */
2126	.ops = {
2127		.open = alc880_playback_pcm_open,
2128		.prepare = alc880_playback_pcm_prepare,
2129		.cleanup = alc880_playback_pcm_cleanup
2130	},
2131};
2132
2133static struct hda_pcm_stream alc880_pcm_analog_capture = {
2134	.substreams = 2,
2135	.channels_min = 2,
2136	.channels_max = 2,
2137	/* NID is set in alc_build_pcms */
2138	.ops = {
2139		.prepare = alc880_capture_pcm_prepare,
2140		.cleanup = alc880_capture_pcm_cleanup
2141	},
2142};
2143
2144static struct hda_pcm_stream alc880_pcm_digital_playback = {
2145	.substreams = 1,
2146	.channels_min = 2,
2147	.channels_max = 2,
2148	/* NID is set in alc_build_pcms */
2149	.ops = {
2150		.open = alc880_dig_playback_pcm_open,
2151		.close = alc880_dig_playback_pcm_close,
2152		.prepare = alc880_dig_playback_pcm_prepare
2153	},
2154};
2155
2156static struct hda_pcm_stream alc880_pcm_digital_capture = {
2157	.substreams = 1,
2158	.channels_min = 2,
2159	.channels_max = 2,
2160	/* NID is set in alc_build_pcms */
2161};
2162
2163/* Used by alc_build_pcms to flag that a PCM has no playback stream */
2164static struct hda_pcm_stream alc_pcm_null_playback = {
2165	.substreams = 0,
2166	.channels_min = 0,
2167	.channels_max = 0,
2168};
2169
2170static int alc_build_pcms(struct hda_codec *codec)
2171{
2172	struct alc_spec *spec = codec->spec;
2173	struct hda_pcm *info = spec->pcm_rec;
2174	int i;
2175
2176	codec->num_pcms = 1;
2177	codec->pcm_info = info;
2178
2179	info->name = spec->stream_name_analog;
2180	if (spec->stream_analog_playback) {
2181		snd_assert(spec->multiout.dac_nids, return -EINVAL);
2182		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2183		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2184	}
2185	if (spec->stream_analog_capture) {
2186		snd_assert(spec->adc_nids, return -EINVAL);
2187		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2188		info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2189	}
2190
2191	if (spec->channel_mode) {
2192		info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2193		for (i = 0; i < spec->num_channel_mode; i++) {
2194			if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2195				info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2196			}
2197		}
2198	}
2199
2200	/* SPDIF for stream index #1 */
2201	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2202		codec->num_pcms = 2;
2203		info = spec->pcm_rec + 1;
2204		info->name = spec->stream_name_digital;
2205		if (spec->multiout.dig_out_nid &&
2206		    spec->stream_digital_playback) {
2207			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2208			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2209		}
2210		if (spec->dig_in_nid &&
2211		    spec->stream_digital_capture) {
2212			info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2213			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2214		}
2215	}
2216
2217	/* If the use of more than one ADC is requested for the current
2218	 * model, configure a second analog capture-only PCM.
2219	 */
2220	/* Additional Analaog capture for index #2 */
2221	if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2222	    spec->adc_nids) {
2223		codec->num_pcms = 3;
2224		info = spec->pcm_rec + 2;
2225		info->name = spec->stream_name_analog;
2226		/* No playback stream for second PCM */
2227		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2228		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2229		if (spec->stream_analog_capture) {
2230			info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2231			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2232		}
2233	}
2234
2235	return 0;
2236}
2237
2238static void alc_free(struct hda_codec *codec)
2239{
2240	struct alc_spec *spec = codec->spec;
2241	unsigned int i;
2242
2243	if (!spec)
2244		return;
2245
2246	if (spec->kctl_alloc) {
2247		for (i = 0; i < spec->num_kctl_used; i++)
2248			kfree(spec->kctl_alloc[i].name);
2249		kfree(spec->kctl_alloc);
2250	}
2251	kfree(spec);
2252}
2253
2254/*
2255 */
2256static struct hda_codec_ops alc_patch_ops = {
2257	.build_controls = alc_build_controls,
2258	.build_pcms = alc_build_pcms,
2259	.init = alc_init,
2260	.free = alc_free,
2261	.unsol_event = alc_unsol_event,
2262#ifdef CONFIG_PM
2263	.resume = alc_resume,
2264#endif
2265};
2266
2267
2268/*
2269 * Test configuration for debugging
2270 *
2271 * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2272 * enum controls.
2273 */
2274#ifdef CONFIG_SND_DEBUG
2275static hda_nid_t alc880_test_dac_nids[4] = {
2276	0x02, 0x03, 0x04, 0x05
2277};
2278
2279static struct hda_input_mux alc880_test_capture_source = {
2280	.num_items = 7,
2281	.items = {
2282		{ "In-1", 0x0 },
2283		{ "In-2", 0x1 },
2284		{ "In-3", 0x2 },
2285		{ "In-4", 0x3 },
2286		{ "CD", 0x4 },
2287		{ "Front", 0x5 },
2288		{ "Surround", 0x6 },
2289	},
2290};
2291
2292static struct hda_channel_mode alc880_test_modes[4] = {
2293	{ 2, NULL },
2294	{ 4, NULL },
2295	{ 6, NULL },
2296	{ 8, NULL },
2297};
2298
2299static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2300				 struct snd_ctl_elem_info *uinfo)
2301{
2302	static char *texts[] = {
2303		"N/A", "Line Out", "HP Out",
2304		"In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2305	};
2306	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2307	uinfo->count = 1;
2308	uinfo->value.enumerated.items = 8;
2309	if (uinfo->value.enumerated.item >= 8)
2310		uinfo->value.enumerated.item = 7;
2311	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2312	return 0;
2313}
2314
2315static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2316				struct snd_ctl_elem_value *ucontrol)
2317{
2318	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2319	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2320	unsigned int pin_ctl, item = 0;
2321
2322	pin_ctl = snd_hda_codec_read(codec, nid, 0,
2323				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2324	if (pin_ctl & AC_PINCTL_OUT_EN) {
2325		if (pin_ctl & AC_PINCTL_HP_EN)
2326			item = 2;
2327		else
2328			item = 1;
2329	} else if (pin_ctl & AC_PINCTL_IN_EN) {
2330		switch (pin_ctl & AC_PINCTL_VREFEN) {
2331		case AC_PINCTL_VREF_HIZ: item = 3; break;
2332		case AC_PINCTL_VREF_50:  item = 4; break;
2333		case AC_PINCTL_VREF_GRD: item = 5; break;
2334		case AC_PINCTL_VREF_80:  item = 6; break;
2335		case AC_PINCTL_VREF_100: item = 7; break;
2336		}
2337	}
2338	ucontrol->value.enumerated.item[0] = item;
2339	return 0;
2340}
2341
2342static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2343				struct snd_ctl_elem_value *ucontrol)
2344{
2345	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2346	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2347	static unsigned int ctls[] = {
2348		0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2349		AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2350		AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2351		AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2352		AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2353		AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2354	};
2355	unsigned int old_ctl, new_ctl;
2356
2357	old_ctl = snd_hda_codec_read(codec, nid, 0,
2358				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2359	new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2360	if (old_ctl != new_ctl) {
2361		snd_hda_codec_write(codec, nid, 0,
2362				    AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
2363		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2364				    (ucontrol->value.enumerated.item[0] >= 3 ?
2365				     0xb080 : 0xb000));
2366		return 1;
2367	}
2368	return 0;
2369}
2370
2371static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2372				 struct snd_ctl_elem_info *uinfo)
2373{
2374	static char *texts[] = {
2375		"Front", "Surround", "CLFE", "Side"
2376	};
2377	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2378	uinfo->count = 1;
2379	uinfo->value.enumerated.items = 4;
2380	if (uinfo->value.enumerated.item >= 4)
2381		uinfo->value.enumerated.item = 3;
2382	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2383	return 0;
2384}
2385
2386static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2387				struct snd_ctl_elem_value *ucontrol)
2388{
2389	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2390	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2391	unsigned int sel;
2392
2393	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2394	ucontrol->value.enumerated.item[0] = sel & 3;
2395	return 0;
2396}
2397
2398static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2399				struct snd_ctl_elem_value *ucontrol)
2400{
2401	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2402	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2403	unsigned int sel;
2404
2405	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2406	if (ucontrol->value.enumerated.item[0] != sel) {
2407		sel = ucontrol->value.enumerated.item[0] & 3;
2408		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
2409		return 1;
2410	}
2411	return 0;
2412}
2413
2414#define PIN_CTL_TEST(xname,nid) {			\
2415		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
2416			.name = xname,		       \
2417			.info = alc_test_pin_ctl_info, \
2418			.get = alc_test_pin_ctl_get,   \
2419			.put = alc_test_pin_ctl_put,   \
2420			.private_value = nid	       \
2421			}
2422
2423#define PIN_SRC_TEST(xname,nid) {			\
2424		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
2425			.name = xname,		       \
2426			.info = alc_test_pin_src_info, \
2427			.get = alc_test_pin_src_get,   \
2428			.put = alc_test_pin_src_put,   \
2429			.private_value = nid	       \
2430			}
2431
2432static struct snd_kcontrol_new alc880_test_mixer[] = {
2433	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2434	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2435	HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2436	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2437	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2438	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2439	HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2440	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2441	PIN_CTL_TEST("Front Pin Mode", 0x14),
2442	PIN_CTL_TEST("Surround Pin Mode", 0x15),
2443	PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2444	PIN_CTL_TEST("Side Pin Mode", 0x17),
2445	PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2446	PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2447	PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2448	PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2449	PIN_SRC_TEST("In-1 Pin Source", 0x18),
2450	PIN_SRC_TEST("In-2 Pin Source", 0x19),
2451	PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2452	PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2453	HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2454	HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2455	HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2456	HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2457	HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2458	HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2459	HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2460	HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2461	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2462	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2463	{
2464		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2465		.name = "Channel Mode",
2466		.info = alc_ch_mode_info,
2467		.get = alc_ch_mode_get,
2468		.put = alc_ch_mode_put,
2469	},
2470	{ } /* end */
2471};
2472
2473static struct hda_verb alc880_test_init_verbs[] = {
2474	/* Unmute inputs of 0x0c - 0x0f */
2475	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2476	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2477	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2478	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2479	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2480	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2481	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2482	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2483	/* Vol output for 0x0c-0x0f */
2484	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2485	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2486	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2487	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2488	/* Set output pins 0x14-0x17 */
2489	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2490	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2491	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2492	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2493	/* Unmute output pins 0x14-0x17 */
2494	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2495	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2496	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2498	/* Set input pins 0x18-0x1c */
2499	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2500	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2501	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2502	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2503	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2504	/* Mute input pins 0x18-0x1b */
2505	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2506	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2507	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2508	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2509	/* ADC set up */
2510	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2511	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2512	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2513	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2514	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2515	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2516	/* Analog input/passthru */
2517	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2518	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2519	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2520	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2521	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2522	{ }
2523};
2524#endif
2525
2526/*
2527 */
2528
2529static const char *alc880_models[ALC880_MODEL_LAST] = {
2530	[ALC880_3ST]		= "3stack",
2531	[ALC880_TCL_S700]	= "tcl",
2532	[ALC880_3ST_DIG]	= "3stack-digout",
2533	[ALC880_CLEVO]		= "clevo",
2534	[ALC880_5ST]		= "5stack",
2535	[ALC880_5ST_DIG]	= "5stack-digout",
2536	[ALC880_W810]		= "w810",
2537	[ALC880_Z71V]		= "z71v",
2538	[ALC880_6ST]		= "6stack",
2539	[ALC880_6ST_DIG]	= "6stack-digout",
2540	[ALC880_ASUS]		= "asus",
2541	[ALC880_ASUS_W1V]	= "asus-w1v",
2542	[ALC880_ASUS_DIG]	= "asus-dig",
2543	[ALC880_ASUS_DIG2]	= "asus-dig2",
2544	[ALC880_UNIWILL_DIG]	= "uniwill",
2545	[ALC880_UNIWILL_P53]	= "uniwill-p53",
2546	[ALC880_FUJITSU]	= "fujitsu",
2547	[ALC880_F1734]		= "F1734",
2548	[ALC880_LG]		= "lg",
2549	[ALC880_LG_LW]		= "lg-lw",
2550#ifdef CONFIG_SND_DEBUG
2551	[ALC880_TEST]		= "test",
2552#endif
2553	[ALC880_AUTO]		= "auto",
2554};
2555
2556static struct snd_pci_quirk alc880_cfg_tbl[] = {
2557	/* Broken BIOS configuration */
2558	SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2559	SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2560
2561	SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2562	SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2563	SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2564	SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2565	SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2566	SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2567	SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2568	SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2569	SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2570
2571	SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2572	SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2573
2574	SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2575	SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2576	SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2577	SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2578	SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2579	SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2580	SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2581	/* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2582	SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2583	SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2584	SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2585	SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2586	SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2587	SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2588	SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2589
2590	SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2591	SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2592	SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2593	SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2594	SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2595	SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2596	SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2597	SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2598	SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2599	SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2600	SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2601	SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2602	SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2603	SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2604	SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2605	SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2606	SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2607	SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2608
2609	SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2610	SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2611	SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2612	SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2613
2614	SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2615	SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2616	SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2617	SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2618
2619	SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2620	SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2621	SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2622	SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2623
2624	SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2625	SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2626	SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2627	SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2628	SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2629	SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2630	SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2631	SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2632	SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2633	SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2634	SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2635
2636	{}
2637};
2638
2639/*
2640 * ALC880 codec presets
2641 */
2642static struct alc_config_preset alc880_presets[] = {
2643	[ALC880_3ST] = {
2644		.mixers = { alc880_three_stack_mixer },
2645		.init_verbs = { alc880_volume_init_verbs,
2646				alc880_pin_3stack_init_verbs },
2647		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2648		.dac_nids = alc880_dac_nids,
2649		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2650		.channel_mode = alc880_threestack_modes,
2651		.need_dac_fix = 1,
2652		.input_mux = &alc880_capture_source,
2653	},
2654	[ALC880_3ST_DIG] = {
2655		.mixers = { alc880_three_stack_mixer },
2656		.init_verbs = { alc880_volume_init_verbs,
2657				alc880_pin_3stack_init_verbs },
2658		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2659		.dac_nids = alc880_dac_nids,
2660		.dig_out_nid = ALC880_DIGOUT_NID,
2661		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2662		.channel_mode = alc880_threestack_modes,
2663		.need_dac_fix = 1,
2664		.input_mux = &alc880_capture_source,
2665	},
2666	[ALC880_TCL_S700] = {
2667		.mixers = { alc880_tcl_s700_mixer },
2668		.init_verbs = { alc880_volume_init_verbs,
2669				alc880_pin_tcl_S700_init_verbs,
2670				alc880_gpio2_init_verbs },
2671		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2672		.dac_nids = alc880_dac_nids,
2673		.hp_nid = 0x03,
2674		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2675		.channel_mode = alc880_2_jack_modes,
2676		.input_mux = &alc880_capture_source,
2677	},
2678	[ALC880_5ST] = {
2679		.mixers = { alc880_three_stack_mixer,
2680			    alc880_five_stack_mixer},
2681		.init_verbs = { alc880_volume_init_verbs,
2682				alc880_pin_5stack_init_verbs },
2683		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2684		.dac_nids = alc880_dac_nids,
2685		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2686		.channel_mode = alc880_fivestack_modes,
2687		.input_mux = &alc880_capture_source,
2688	},
2689	[ALC880_5ST_DIG] = {
2690		.mixers = { alc880_three_stack_mixer,
2691			    alc880_five_stack_mixer },
2692		.init_verbs = { alc880_volume_init_verbs,
2693				alc880_pin_5stack_init_verbs },
2694		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2695		.dac_nids = alc880_dac_nids,
2696		.dig_out_nid = ALC880_DIGOUT_NID,
2697		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2698		.channel_mode = alc880_fivestack_modes,
2699		.input_mux = &alc880_capture_source,
2700	},
2701	[ALC880_6ST] = {
2702		.mixers = { alc880_six_stack_mixer },
2703		.init_verbs = { alc880_volume_init_verbs,
2704				alc880_pin_6stack_init_verbs },
2705		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2706		.dac_nids = alc880_6st_dac_nids,
2707		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2708		.channel_mode = alc880_sixstack_modes,
2709		.input_mux = &alc880_6stack_capture_source,
2710	},
2711	[ALC880_6ST_DIG] = {
2712		.mixers = { alc880_six_stack_mixer },
2713		.init_verbs = { alc880_volume_init_verbs,
2714				alc880_pin_6stack_init_verbs },
2715		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2716		.dac_nids = alc880_6st_dac_nids,
2717		.dig_out_nid = ALC880_DIGOUT_NID,
2718		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2719		.channel_mode = alc880_sixstack_modes,
2720		.input_mux = &alc880_6stack_capture_source,
2721	},
2722	[ALC880_W810] = {
2723		.mixers = { alc880_w810_base_mixer },
2724		.init_verbs = { alc880_volume_init_verbs,
2725				alc880_pin_w810_init_verbs,
2726				alc880_gpio2_init_verbs },
2727		.num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2728		.dac_nids = alc880_w810_dac_nids,
2729		.dig_out_nid = ALC880_DIGOUT_NID,
2730		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2731		.channel_mode = alc880_w810_modes,
2732		.input_mux = &alc880_capture_source,
2733	},
2734	[ALC880_Z71V] = {
2735		.mixers = { alc880_z71v_mixer },
2736		.init_verbs = { alc880_volume_init_verbs,
2737				alc880_pin_z71v_init_verbs },
2738		.num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2739		.dac_nids = alc880_z71v_dac_nids,
2740		.dig_out_nid = ALC880_DIGOUT_NID,
2741		.hp_nid = 0x03,
2742		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2743		.channel_mode = alc880_2_jack_modes,
2744		.input_mux = &alc880_capture_source,
2745	},
2746	[ALC880_F1734] = {
2747		.mixers = { alc880_f1734_mixer },
2748		.init_verbs = { alc880_volume_init_verbs,
2749				alc880_pin_f1734_init_verbs },
2750		.num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2751		.dac_nids = alc880_f1734_dac_nids,
2752		.hp_nid = 0x02,
2753		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2754		.channel_mode = alc880_2_jack_modes,
2755		.input_mux = &alc880_capture_source,
2756	},
2757	[ALC880_ASUS] = {
2758		.mixers = { alc880_asus_mixer },
2759		.init_verbs = { alc880_volume_init_verbs,
2760				alc880_pin_asus_init_verbs,
2761				alc880_gpio1_init_verbs },
2762		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2763		.dac_nids = alc880_asus_dac_nids,
2764		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2765		.channel_mode = alc880_asus_modes,
2766		.need_dac_fix = 1,
2767		.input_mux = &alc880_capture_source,
2768	},
2769	[ALC880_ASUS_DIG] = {
2770		.mixers = { alc880_asus_mixer },
2771		.init_verbs = { alc880_volume_init_verbs,
2772				alc880_pin_asus_init_verbs,
2773				alc880_gpio1_init_verbs },
2774		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2775		.dac_nids = alc880_asus_dac_nids,
2776		.dig_out_nid = ALC880_DIGOUT_NID,
2777		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2778		.channel_mode = alc880_asus_modes,
2779		.need_dac_fix = 1,
2780		.input_mux = &alc880_capture_source,
2781	},
2782	[ALC880_ASUS_DIG2] = {
2783		.mixers = { alc880_asus_mixer },
2784		.init_verbs = { alc880_volume_init_verbs,
2785				alc880_pin_asus_init_verbs,
2786				alc880_gpio2_init_verbs }, /* use GPIO2 */
2787		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2788		.dac_nids = alc880_asus_dac_nids,
2789		.dig_out_nid = ALC880_DIGOUT_NID,
2790		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2791		.channel_mode = alc880_asus_modes,
2792		.need_dac_fix = 1,
2793		.input_mux = &alc880_capture_source,
2794	},
2795	[ALC880_ASUS_W1V] = {
2796		.mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2797		.init_verbs = { alc880_volume_init_verbs,
2798				alc880_pin_asus_init_verbs,
2799				alc880_gpio1_init_verbs },
2800		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2801		.dac_nids = alc880_asus_dac_nids,
2802		.dig_out_nid = ALC880_DIGOUT_NID,
2803		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2804		.channel_mode = alc880_asus_modes,
2805		.need_dac_fix = 1,
2806		.input_mux = &alc880_capture_source,
2807	},
2808	[ALC880_UNIWILL_DIG] = {
2809		.mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2810		.init_verbs = { alc880_volume_init_verbs,
2811				alc880_pin_asus_init_verbs },
2812		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2813		.dac_nids = alc880_asus_dac_nids,
2814		.dig_out_nid = ALC880_DIGOUT_NID,
2815		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2816		.channel_mode = alc880_asus_modes,
2817		.need_dac_fix = 1,
2818		.input_mux = &alc880_capture_source,
2819	},
2820	[ALC880_UNIWILL] = {
2821		.mixers = { alc880_uniwill_mixer },
2822		.init_verbs = { alc880_volume_init_verbs,
2823				alc880_uniwill_init_verbs },
2824		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2825		.dac_nids = alc880_asus_dac_nids,
2826		.dig_out_nid = ALC880_DIGOUT_NID,
2827		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2828		.channel_mode = alc880_threestack_modes,
2829		.need_dac_fix = 1,
2830		.input_mux = &alc880_capture_source,
2831		.unsol_event = alc880_uniwill_unsol_event,
2832		.init_hook = alc880_uniwill_automute,
2833	},
2834	[ALC880_UNIWILL_P53] = {
2835		.mixers = { alc880_uniwill_p53_mixer },
2836		.init_verbs = { alc880_volume_init_verbs,
2837				alc880_uniwill_p53_init_verbs },
2838		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2839		.dac_nids = alc880_asus_dac_nids,
2840		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2841		.channel_mode = alc880_threestack_modes,
2842		.input_mux = &alc880_capture_source,
2843		.unsol_event = alc880_uniwill_p53_unsol_event,
2844		.init_hook = alc880_uniwill_p53_hp_automute,
2845	},
2846	[ALC880_FUJITSU] = {
2847		.mixers = { alc880_fujitsu_mixer,
2848			    alc880_pcbeep_mixer, },
2849		.init_verbs = { alc880_volume_init_verbs,
2850				alc880_uniwill_p53_init_verbs,
2851	       			alc880_beep_init_verbs },
2852		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2853		.dac_nids = alc880_dac_nids,
2854		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2855		.channel_mode = alc880_2_jack_modes,
2856		.input_mux = &alc880_capture_source,
2857		.unsol_event = alc880_uniwill_p53_unsol_event,
2858		.init_hook = alc880_uniwill_p53_hp_automute,
2859	},
2860	[ALC880_CLEVO] = {
2861		.mixers = { alc880_three_stack_mixer },
2862		.init_verbs = { alc880_volume_init_verbs,
2863				alc880_pin_clevo_init_verbs },
2864		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2865		.dac_nids = alc880_dac_nids,
2866		.hp_nid = 0x03,
2867		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2868		.channel_mode = alc880_threestack_modes,
2869		.need_dac_fix = 1,
2870		.input_mux = &alc880_capture_source,
2871	},
2872	[ALC880_LG] = {
2873		.mixers = { alc880_lg_mixer },
2874		.init_verbs = { alc880_volume_init_verbs,
2875				alc880_lg_init_verbs },
2876		.num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2877		.dac_nids = alc880_lg_dac_nids,
2878		.dig_out_nid = ALC880_DIGOUT_NID,
2879		.num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2880		.channel_mode = alc880_lg_ch_modes,
2881		.need_dac_fix = 1,
2882		.input_mux = &alc880_lg_capture_source,
2883		.unsol_event = alc880_lg_unsol_event,
2884		.init_hook = alc880_lg_automute,
2885	},
2886	[ALC880_LG_LW] = {
2887		.mixers = { alc880_lg_lw_mixer },
2888		.init_verbs = { alc880_volume_init_verbs,
2889				alc880_lg_lw_init_verbs },
2890		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
2891		.dac_nids = alc880_dac_nids,
2892		.dig_out_nid = ALC880_DIGOUT_NID,
2893		.num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
2894		.channel_mode = alc880_lg_lw_modes,
2895		.input_mux = &alc880_lg_lw_capture_source,
2896		.unsol_event = alc880_lg_lw_unsol_event,
2897		.init_hook = alc880_lg_lw_automute,
2898	},
2899#ifdef CONFIG_SND_DEBUG
2900	[ALC880_TEST] = {
2901		.mixers = { alc880_test_mixer },
2902		.init_verbs = { alc880_test_init_verbs },
2903		.num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2904		.dac_nids = alc880_test_dac_nids,
2905		.dig_out_nid = ALC880_DIGOUT_NID,
2906		.num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2907		.channel_mode = alc880_test_modes,
2908		.input_mux = &alc880_test_capture_source,
2909	},
2910#endif
2911};
2912
2913/*
2914 * Automatic parse of I/O pins from the BIOS configuration
2915 */
2916
2917#define NUM_CONTROL_ALLOC	32
2918#define NUM_VERB_ALLOC		32
2919
2920enum {
2921	ALC_CTL_WIDGET_VOL,
2922	ALC_CTL_WIDGET_MUTE,
2923	ALC_CTL_BIND_MUTE,
2924};
2925static struct snd_kcontrol_new alc880_control_templates[] = {
2926	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2927	HDA_CODEC_MUTE(NULL, 0, 0, 0),
2928	HDA_BIND_MUTE(NULL, 0, 0, 0),
2929};
2930
2931/* add dynamic controls */
2932static int add_control(struct alc_spec *spec, int type, const char *name,
2933		       unsigned long val)
2934{
2935	struct snd_kcontrol_new *knew;
2936
2937	if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2938		int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2939
2940		/* array + terminator */
2941		knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
2942		if (!knew)
2943			return -ENOMEM;
2944		if (spec->kctl_alloc) {
2945			memcpy(knew, spec->kctl_alloc,
2946			       sizeof(*knew) * spec->num_kctl_alloc);
2947			kfree(spec->kctl_alloc);
2948		}
2949		spec->kctl_alloc = knew;
2950		spec->num_kctl_alloc = num;
2951	}
2952
2953	knew = &spec->kctl_alloc[spec->num_kctl_used];
2954	*knew = alc880_control_templates[type];
2955	knew->name = kstrdup(name, GFP_KERNEL);
2956	if (!knew->name)
2957		return -ENOMEM;
2958	knew->private_value = val;
2959	spec->num_kctl_used++;
2960	return 0;
2961}
2962
2963#define alc880_is_fixed_pin(nid)	((nid) >= 0x14 && (nid) <= 0x17)
2964#define alc880_fixed_pin_idx(nid)	((nid) - 0x14)
2965#define alc880_is_multi_pin(nid)	((nid) >= 0x18)
2966#define alc880_multi_pin_idx(nid)	((nid) - 0x18)
2967#define alc880_is_input_pin(nid)	((nid) >= 0x18)
2968#define alc880_input_pin_idx(nid)	((nid) - 0x18)
2969#define alc880_idx_to_dac(nid)		((nid) + 0x02)
2970#define alc880_dac_to_idx(nid)		((nid) - 0x02)
2971#define alc880_idx_to_mixer(nid)	((nid) + 0x0c)
2972#define alc880_idx_to_selector(nid)	((nid) + 0x10)
2973#define ALC880_PIN_CD_NID		0x1c
2974
2975/* fill in the dac_nids table from the parsed pin configuration */
2976static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
2977				     const struct auto_pin_cfg *cfg)
2978{
2979	hda_nid_t nid;
2980	int assigned[4];
2981	int i, j;
2982
2983	memset(assigned, 0, sizeof(assigned));
2984	spec->multiout.dac_nids = spec->private_dac_nids;
2985
2986	/* check the pins hardwired to audio widget */
2987	for (i = 0; i < cfg->line_outs; i++) {
2988		nid = cfg->line_out_pins[i];
2989		if (alc880_is_fixed_pin(nid)) {
2990			int idx = alc880_fixed_pin_idx(nid);
2991			spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
2992			assigned[idx] = 1;
2993		}
2994	}
2995	/* left pins can be connect to any audio widget */
2996	for (i = 0; i < cfg->line_outs; i++) {
2997		nid = cfg->line_out_pins[i];
2998		if (alc880_is_fixed_pin(nid))
2999			continue;
3000		/* search for an empty channel */
3001		for (j = 0; j < cfg->line_outs; j++) {
3002			if (!assigned[j]) {
3003				spec->multiout.dac_nids[i] =
3004					alc880_idx_to_dac(j);
3005				assigned[j] = 1;
3006				break;
3007			}
3008		}
3009	}
3010	spec->multiout.num_dacs = cfg->line_outs;
3011	return 0;
3012}
3013
3014/* add playback controls from the parsed DAC table */
3015static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3016					     const struct auto_pin_cfg *cfg)
3017{
3018	char name[32];
3019	static const char *chname[4] = {
3020		"Front", "Surround", NULL /*CLFE*/, "Side"
3021	};
3022	hda_nid_t nid;
3023	int i, err;
3024
3025	for (i = 0; i < cfg->line_outs; i++) {
3026		if (!spec->multiout.dac_nids[i])
3027			continue;
3028		nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3029		if (i == 2) {
3030			/* Center/LFE */
3031			err = add_control(spec, ALC_CTL_WIDGET_VOL,
3032					  "Center Playback Volume",
3033					  HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3034							      HDA_OUTPUT));
3035			if (err < 0)
3036				return err;
3037			err = add_control(spec, ALC_CTL_WIDGET_VOL,
3038					  "LFE Playback Volume",
3039					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3040							      HDA_OUTPUT));
3041			if (err < 0)
3042				return err;
3043			err = add_control(spec, ALC_CTL_BIND_MUTE,
3044					  "Center Playback Switch",
3045					  HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3046							      HDA_INPUT));
3047			if (err < 0)
3048				return err;
3049			err = add_control(spec, ALC_CTL_BIND_MUTE,
3050					  "LFE Playback Switch",
3051					  HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3052							      HDA_INPUT));
3053			if (err < 0)
3054				return err;
3055		} else {
3056			sprintf(name, "%s Playback Volume", chname[i]);
3057			err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3058					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3059							      HDA_OUTPUT));
3060			if (err < 0)
3061				return err;
3062			sprintf(name, "%s Playback Switch", chname[i]);
3063			err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3064					  HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3065							      HDA_INPUT));
3066			if (err < 0)
3067				return err;
3068		}
3069	}
3070	return 0;
3071}
3072
3073/* add playback controls for speaker and HP outputs */
3074static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3075					const char *pfx)
3076{
3077	hda_nid_t nid;
3078	int err;
3079	char name[32];
3080
3081	if (!pin)
3082		return 0;
3083
3084	if (alc880_is_fixed_pin(pin)) {
3085		nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3086		/* specify the DAC as the extra output */
3087		if (!spec->multiout.hp_nid)
3088			spec->multiout.hp_nid = nid;
3089		else
3090			spec->multiout.extra_out_nid[0] = nid;
3091		/* control HP volume/switch on the output mixer amp */
3092		nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3093		sprintf(name, "%s Playback Volume", pfx);
3094		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3095				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3096		if (err < 0)
3097			return err;
3098		sprintf(name, "%s Playback Switch", pfx);
3099		err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3100				  HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3101		if (err < 0)
3102			return err;
3103	} else if (alc880_is_multi_pin(pin)) {
3104		/* set manual connection */
3105		/* we have only a switch on HP-out PIN */
3106		sprintf(name, "%s Playback Switch", pfx);
3107		err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3108				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3109		if (err < 0)
3110			return err;
3111	}
3112	return 0;
3113}
3114
3115/* create input playback/capture controls for the given pin */
3116static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3117			    const char *ctlname,
3118			    int idx, hda_nid_t mix_nid)
3119{
3120	char name[32];
3121	int err;
3122
3123	sprintf(name, "%s Playback Volume", ctlname);
3124	err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3125			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3126	if (err < 0)
3127		return err;
3128	sprintf(name, "%s Playback Switch", ctlname);
3129	err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3130			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3131	if (err < 0)
3132		return err;
3133	return 0;
3134}
3135
3136/* create playback/capture controls for input pins */
3137static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3138						const struct auto_pin_cfg *cfg)
3139{
3140	struct hda_input_mux *imux = &spec->private_imux;
3141	int i, err, idx;
3142
3143	for (i = 0; i < AUTO_PIN_LAST; i++) {
3144		if (alc880_is_input_pin(cfg->input_pins[i])) {
3145			idx = alc880_input_pin_idx(cfg->input_pins[i]);
3146			err = new_analog_input(spec, cfg->input_pins[i],
3147					       auto_pin_cfg_labels[i],
3148					       idx, 0x0b);
3149			if (err < 0)
3150				return err;
3151			imux->items[imux->num_items].label =
3152				auto_pin_cfg_labels[i];
3153			imux->items[imux->num_items].index =
3154				alc880_input_pin_idx(cfg->input_pins[i]);
3155			imux->num_items++;
3156		}
3157	}
3158	return 0;
3159}
3160
3161static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3162					      hda_nid_t nid, int pin_type,
3163					      int dac_idx)
3164{
3165	/* set as output */
3166	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3167			    pin_type);
3168	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3169			    AMP_OUT_UNMUTE);
3170	/* need the manual connection? */
3171	if (alc880_is_multi_pin(nid)) {
3172		struct alc_spec *spec = codec->spec;
3173		int idx = alc880_multi_pin_idx(nid);
3174		snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3175				    AC_VERB_SET_CONNECT_SEL,
3176				    alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3177	}
3178}
3179
3180static int get_pin_type(int line_out_type)
3181{
3182	if (line_out_type == AUTO_PIN_HP_OUT)
3183		return PIN_HP;
3184	else
3185		return PIN_OUT;
3186}
3187
3188static void alc880_auto_init_multi_out(struct hda_codec *codec)
3189{
3190	struct alc_spec *spec = codec->spec;
3191	int i;
3192
3193	alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3194	for (i = 0; i < spec->autocfg.line_outs; i++) {
3195		hda_nid_t nid = spec->autocfg.line_out_pins[i];
3196		int pin_type = get_pin_type(spec->autocfg.line_out_type);
3197		alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3198	}
3199}
3200
3201static void alc880_auto_init_extra_out(struct hda_codec *codec)
3202{
3203	struct alc_spec *spec = codec->spec;
3204	hda_nid_t pin;
3205
3206	pin = spec->autocfg.speaker_pins[0];
3207	if (pin) /* connect to front */
3208		alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3209	pin = spec->autocfg.hp_pins[0];
3210	if (pin) /* connect to front */
3211		alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3212}
3213
3214static void alc880_auto_init_analog_input(struct hda_codec *codec)
3215{
3216	struct alc_spec *spec = codec->spec;
3217	int i;
3218
3219	for (i = 0; i < AUTO_PIN_LAST; i++) {
3220		hda_nid_t nid = spec->autocfg.input_pins[i];
3221		if (alc880_is_input_pin(nid)) {
3222			snd_hda_codec_write(codec, nid, 0,
3223					    AC_VERB_SET_PIN_WIDGET_CONTROL,
3224					    i <= AUTO_PIN_FRONT_MIC ?
3225					    PIN_VREF80 : PIN_IN);
3226			if (nid != ALC880_PIN_CD_NID)
3227				snd_hda_codec_write(codec, nid, 0,
3228						    AC_VERB_SET_AMP_GAIN_MUTE,
3229						    AMP_OUT_MUTE);
3230		}
3231	}
3232}
3233
3234/* parse the BIOS configuration and set up the alc_spec */
3235/* return 1 if successful, 0 if the proper config is not found,
3236 * or a negative error code
3237 */
3238static int alc880_parse_auto_config(struct hda_codec *codec)
3239{
3240	struct alc_spec *spec = codec->spec;
3241	int err;
3242	static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3243
3244	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3245					   alc880_ignore);
3246	if (err < 0)
3247		return err;
3248	if (!spec->autocfg.line_outs)
3249		return 0; /* can't find valid BIOS pin config */
3250
3251	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3252	if (err < 0)
3253		return err;
3254	err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3255	if (err < 0)
3256		return err;
3257	err = alc880_auto_create_extra_out(spec,
3258					   spec->autocfg.speaker_pins[0],
3259					   "Speaker");
3260	if (err < 0)
3261		return err;
3262	err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3263					   "Headphone");
3264	if (err < 0)
3265		return err;
3266	err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3267	if (err < 0)
3268		return err;
3269
3270	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3271
3272	if (spec->autocfg.dig_out_pin)
3273		spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3274	if (spec->autocfg.dig_in_pin)
3275		spec->dig_in_nid = ALC880_DIGIN_NID;
3276
3277	if (spec->kctl_alloc)
3278		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3279
3280	spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3281
3282	spec->num_mux_defs = 1;
3283	spec->input_mux = &spec->private_imux;
3284
3285	return 1;
3286}
3287
3288/* additional initialization for auto-configuration model */
3289static void alc880_auto_init(struct hda_codec *codec)
3290{
3291	alc880_auto_init_multi_out(codec);
3292	alc880_auto_init_extra_out(codec);
3293	alc880_auto_init_analog_input(codec);
3294}
3295
3296/*
3297 * OK, here we have finally the patch for ALC880
3298 */
3299
3300static int patch_alc880(struct hda_codec *codec)
3301{
3302	struct alc_spec *spec;
3303	int board_config;
3304	int err;
3305
3306	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3307	if (spec == NULL)
3308		return -ENOMEM;
3309
3310	codec->spec = spec;
3311
3312	board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3313						  alc880_models,
3314						  alc880_cfg_tbl);
3315	if (board_config < 0) {
3316		printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3317		       "trying auto-probe from BIOS...\n");
3318		board_config = ALC880_AUTO;
3319	}
3320
3321	if (board_config == ALC880_AUTO) {
3322		/* automatic parse from the BIOS config */
3323		err = alc880_parse_auto_config(codec);
3324		if (err < 0) {
3325			alc_free(codec);
3326			return err;
3327		} else if (!err) {
3328			printk(KERN_INFO
3329			       "hda_codec: Cannot set up configuration "
3330			       "from BIOS.  Using 3-stack mode...\n");
3331			board_config = ALC880_3ST;
3332		}
3333	}
3334
3335	if (board_config != ALC880_AUTO)
3336		setup_preset(spec, &alc880_presets[board_config]);
3337
3338	spec->stream_name_analog = "ALC880 Analog";
3339	spec->stream_analog_playback = &alc880_pcm_analog_playback;
3340	spec->stream_analog_capture = &alc880_pcm_analog_capture;
3341
3342	spec->stream_name_digital = "ALC880 Digital";
3343	spec->stream_digital_playback = &alc880_pcm_digital_playback;
3344	spec->stream_digital_capture = &alc880_pcm_digital_capture;
3345
3346	if (!spec->adc_nids && spec->input_mux) {
3347		/* check whether NID 0x07 is valid */
3348		unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3349		/* get type */
3350		wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3351		if (wcap != AC_WID_AUD_IN) {
3352			spec->adc_nids = alc880_adc_nids_alt;
3353			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3354			spec->mixers[spec->num_mixers] =
3355				alc880_capture_alt_mixer;
3356			spec->num_mixers++;
3357		} else {
3358			spec->adc_nids = alc880_adc_nids;
3359			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3360			spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3361			spec->num_mixers++;
3362		}
3363	}
3364
3365	codec->patch_ops = alc_patch_ops;
3366	if (board_config == ALC880_AUTO)
3367		spec->init_hook = alc880_auto_init;
3368
3369	return 0;
3370}
3371
3372
3373/*
3374 * ALC260 support
3375 */
3376
3377static hda_nid_t alc260_dac_nids[1] = {
3378	/* front */
3379	0x02,
3380};
3381
3382static hda_nid_t alc260_adc_nids[1] = {
3383	/* ADC0 */
3384	0x04,
3385};
3386
3387static hda_nid_t alc260_adc_nids_alt[1] = {
3388	/* ADC1 */
3389	0x05,
3390};
3391
3392static hda_nid_t alc260_hp_adc_nids[2] = {
3393	/* ADC1, 0 */
3394	0x05, 0x04
3395};
3396
3397/* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3398 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3399 */
3400static hda_nid_t alc260_dual_adc_nids[2] = {
3401	/* ADC0, ADC1 */
3402	0x04, 0x05
3403};
3404
3405#define ALC260_DIGOUT_NID	0x03
3406#define ALC260_DIGIN_NID	0x06
3407
3408static struct hda_input_mux alc260_capture_source = {
3409	.num_items = 4,
3410	.items = {
3411		{ "Mic", 0x0 },
3412		{ "Front Mic", 0x1 },
3413		{ "Line", 0x2 },
3414		{ "CD", 0x4 },
3415	},
3416};
3417
3418/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3419 * headphone jack and the internal CD lines since these are the only pins at
3420 * which audio can appear.  For flexibility, also allow the option of
3421 * recording the mixer output on the second ADC (ADC0 doesn't have a
3422 * connection to the mixer output).
3423 */
3424static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3425	{
3426		.num_items = 3,
3427		.items = {
3428			{ "Mic/Line", 0x0 },
3429			{ "CD", 0x4 },
3430			{ "Headphone", 0x2 },
3431		},
3432	},
3433	{
3434		.num_items = 4,
3435		.items = {
3436			{ "Mic/Line", 0x0 },
3437			{ "CD", 0x4 },
3438			{ "Headphone", 0x2 },
3439			{ "Mixer", 0x5 },
3440		},
3441	},
3442
3443};
3444
3445/* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3446 * the Fujitsu S702x, but jacks are marked differently.
3447 */
3448static struct hda_input_mux alc260_acer_capture_sources[2] = {
3449	{
3450		.num_items = 4,
3451		.items = {
3452			{ "Mic", 0x0 },
3453			{ "Line", 0x2 },
3454			{ "CD", 0x4 },
3455			{ "Headphone", 0x5 },
3456		},
3457	},
3458	{
3459		.num_items = 5,
3460		.items = {
3461			{ "Mic", 0x0 },
3462			{ "Line", 0x2 },
3463			{ "CD", 0x4 },
3464			{ "Headphone", 0x6 },
3465			{ "Mixer", 0x5 },
3466		},
3467	},
3468};
3469/*
3470 * This is just place-holder, so there's something for alc_build_pcms to look
3471 * at when it calculates the maximum number of channels. ALC260 has no mixer
3472 * element which allows changing the channel mode, so the verb list is
3473 * never used.
3474 */
3475static struct hda_channel_mode alc260_modes[1] = {
3476	{ 2, NULL },
3477};
3478
3479
3480/* Mixer combinations
3481 *
3482 * basic: base_output + input + pc_beep + capture
3483 * HP: base_output + input + capture_alt
3484 * HP_3013: hp_3013 + input + capture
3485 * fujitsu: fujitsu + capture
3486 * acer: acer + capture
3487 */
3488
3489static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3490	HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3491	HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3492	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3493	HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3494	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3495	HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3496	{ } /* end */
3497};
3498
3499static struct snd_kcontrol_new alc260_input_mixer[] = {
3500	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3501	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3502	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3503	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3504	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3505	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3506	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3507	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3508	{ } /* end */
3509};
3510
3511static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3512	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3513	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3514	{ } /* end */
3515};
3516
3517static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3518	HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3519	HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3520	HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3521	HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3522	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3523	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3524	HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3525	HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3526	{ } /* end */
3527};
3528
3529/* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
3530 * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3531 */
3532static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3533	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3534	HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3535	ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3536	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3537	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3538	HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3539	HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3540	ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3541	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3542	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3543	HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3544	HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3545	{ } /* end */
3546};
3547
3548/* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3549 * versions of the ALC260 don't act on requests to enable mic bias from NID
3550 * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3551 * datasheet doesn't mention this restriction.  At this stage it's not clear
3552 * whether this behaviour is intentional or is a hardware bug in chip
3553 * revisions available in early 2006.  Therefore for now allow the
3554 * "Headphone Jack Mode" control to span all choices, but if it turns out
3555 * that the lack of mic bias for this NID is intentional we could change the
3556 * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3557 *
3558 * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3559 * don't appear to make the mic bias available from the "line" jack, even
3560 * though the NID used for this jack (0x14) can supply it.  The theory is
3561 * that perhaps Acer have included blocking capacitors between the ALC260
3562 * and the output jack.  If this turns out to be the case for all such
3563 * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3564 * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3565 *
3566 * The C20x Tablet series have a mono internal speaker which is controlled
3567 * via the chip's Mono sum widget and pin complex, so include the necessary
3568 * controls for such models.  On models without a "mono speaker" the control
3569 * won't do anything.
3570 */
3571static struct snd_kcontrol_new alc260_acer_mixer[] = {
3572	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3573	HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3574	ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3575	HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3576			      HDA_OUTPUT),
3577	HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3578			   HDA_INPUT),
3579	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3580	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3581	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3582	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3583	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3584	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3585	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3586	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3587	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3588	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3589	{ } /* end */
3590};
3591
3592/* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3593 * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3594 */
3595static struct snd_kcontrol_new alc260_will_mixer[] = {
3596	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3597	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3598	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3599	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3600	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3601	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3602	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3603	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3604	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3605	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3606	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3607	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3608	{ } /* end */
3609};
3610
3611/* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3612 * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3613 */
3614static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3615	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3616	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3617	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3618	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3619	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3620	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3621	HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3622	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3623	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3624	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3625	{ } /* end */
3626};
3627
3628/* capture mixer elements */
3629static struct snd_kcontrol_new alc260_capture_mixer[] = {
3630	HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3631	HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3632	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3633	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3634	{
3635		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3636		/* The multiple "Capture Source" controls confuse alsamixer
3637		 * So call somewhat different..
3638		 * FIXME: the controls appear in the "playback" view!
3639		 */
3640		/* .name = "Capture Source", */
3641		.name = "Input Source",
3642		.count = 2,
3643		.info = alc_mux_enum_info,
3644		.get = alc_mux_enum_get,
3645		.put = alc_mux_enum_put,
3646	},
3647	{ } /* end */
3648};
3649
3650static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3651	HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3652	HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3653	{
3654		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3655		/* The multiple "Capture Source" controls confuse alsamixer
3656		 * So call somewhat different..
3657		 * FIXME: the controls appear in the "playback" view!
3658		 */
3659		/* .name = "Capture Source", */
3660		.name = "Input Source",
3661		.count = 1,
3662		.info = alc_mux_enum_info,
3663		.get = alc_mux_enum_get,
3664		.put = alc_mux_enum_put,
3665	},
3666	{ } /* end */
3667};
3668
3669/*
3670 * initialization verbs
3671 */
3672static struct hda_verb alc260_init_verbs[] = {
3673	/* Line In pin widget for input */
3674	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3675	/* CD pin widget for input */
3676	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3677	/* Mic1 (rear panel) pin widget for input and vref at 80% */
3678	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3679	/* Mic2 (front panel) pin widget for input and vref at 80% */
3680	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3681	/* LINE-2 is used for line-out in rear */
3682	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3683	/* select line-out */
3684	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3685	/* LINE-OUT pin */
3686	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3687	/* enable HP */
3688	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3689	/* enable Mono */
3690	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3691	/* mute capture amp left and right */
3692	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3693	/* set connection select to line in (default select for this ADC) */
3694	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3695	/* mute capture amp left and right */
3696	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3697	/* set connection select to line in (default select for this ADC) */
3698	{0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3699	/* set vol=0 Line-Out mixer amp left and right */
3700	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3701	/* unmute pin widget amp left and right (no gain on this amp) */
3702	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3703	/* set vol=0 HP mixer amp left and right */
3704	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3705	/* unmute pin widget amp left and right (no gain on this amp) */
3706	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3707	/* set vol=0 Mono mixer amp left and right */
3708	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3709	/* unmute pin widget amp left and right (no gain on this amp) */
3710	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3711	/* unmute LINE-2 out pin */
3712	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3713	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3714	 * Line In 2 = 0x03
3715	 */
3716	/* mute CD */
3717	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3718	/* mute Line In */
3719	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3720	/* mute Mic */
3721	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3722	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3723	/* mute Front out path */
3724	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3725	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3726	/* mute Headphone out path */
3727	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3728	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3729	/* mute Mono out path */
3730	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3731	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3732	{ }
3733};
3734
3735#if 0 /* should be identical with alc260_init_verbs? */
3736static struct hda_verb alc260_hp_init_verbs[] = {
3737	/* Headphone and output */
3738	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3739	/* mono output */
3740	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3741	/* Mic1 (rear panel) pin widget for input and vref at 80% */
3742	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3743	/* Mic2 (front panel) pin widget for input and vref at 80% */
3744	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3745	/* Line In pin widget for input */
3746	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3747	/* Line-2 pin widget for output */
3748	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3749	/* CD pin widget for input */
3750	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3751	/* unmute amp left and right */
3752	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3753	/* set connection select to line in (default select for this ADC) */
3754	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3755	/* unmute Line-Out mixer amp left and right (volume = 0) */
3756	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3757	/* mute pin widget amp left and right (no gain on this amp) */
3758	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3759	/* unmute HP mixer amp left and right (volume = 0) */
3760	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3761	/* mute pin widget amp left and right (no gain on this amp) */
3762	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3763	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3764	 * Line In 2 = 0x03
3765	 */
3766	/* unmute CD */
3767	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3768	/* unmute Line In */
3769	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3770	/* unmute Mic */
3771	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3772	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3773	/* Unmute Front out path */
3774	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3775	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3776	/* Unmute Headphone out path */
3777	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3778	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3779	/* Unmute Mono out path */
3780	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3781	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3782	{ }
3783};
3784#endif
3785
3786static struct hda_verb alc260_hp_3013_init_verbs[] = {
3787	/* Line out and output */
3788	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3789	/* mono output */
3790	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3791	/* Mic1 (rear panel) pin widget for input and vref at 80% */
3792	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3793	/* Mic2 (front panel) pin widget for input and vref at 80% */
3794	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3795	/* Line In pin widget for input */
3796	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3797	/* Headphone pin widget for output */
3798	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3799	/* CD pin widget for input */
3800	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3801	/* unmute amp left and right */
3802	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3803	/* set connection select to line in (default select for this ADC) */
3804	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3805	/* unmute Line-Out mixer amp left and right (volume = 0) */
3806	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3807	/* mute pin widget amp left and right (no gain on this amp) */
3808	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3809	/* unmute HP mixer amp left and right (volume = 0) */
3810	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3811	/* mute pin widget amp left and right (no gain on this amp) */
3812	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3813	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3814	 * Line In 2 = 0x03
3815	 */
3816	/* unmute CD */
3817	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3818	/* unmute Line In */
3819	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3820	/* unmute Mic */
3821	{0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3822	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3823	/* Unmute Front out path */
3824	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3825	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3826	/* Unmute Headphone out path */
3827	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3828	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3829	/* Unmute Mono out path */
3830	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3831	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3832	{ }
3833};
3834
3835/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3836 * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3837 * audio = 0x16, internal speaker = 0x10.
3838 */
3839static struct hda_verb alc260_fujitsu_init_verbs[] = {
3840	/* Disable all GPIOs */
3841	{0x01, AC_VERB_SET_GPIO_MASK, 0},
3842	/* Internal speaker is connected to headphone pin */
3843	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3844	/* Headphone/Line-out jack connects to Line1 pin; make it an output */
3845	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3846	/* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3847	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3848	/* Ensure all other unused pins are disabled and muted. */
3849	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3850	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3851	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3852	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3853	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3854	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3855	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3856	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3857
3858	/* Disable digital (SPDIF) pins */
3859	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3860	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3861
3862	/* Ensure Line1 pin widget takes its input from the OUT1 sum bus
3863	 * when acting as an output.
3864	 */
3865	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3866
3867	/* Start with output sum widgets muted and their output gains at min */
3868	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3869	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3870	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3871	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3872	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3873	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3874	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3875	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3876	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3877
3878	/* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3879	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3880	/* Unmute Line1 pin widget output buffer since it starts as an output.
3881	 * If the pin mode is changed by the user the pin mode control will
3882	 * take care of enabling the pin's input/output buffers as needed.
3883	 * Therefore there's no need to enable the input buffer at this
3884	 * stage.
3885	 */
3886	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3887	/* Unmute input buffer of pin widget used for Line-in (no equiv
3888	 * mixer ctrl)
3889	 */
3890	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3891
3892	/* Mute capture amp left and right */
3893	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3894	/* Set ADC connection select to match default mixer setting - line
3895	 * in (on mic1 pin)
3896	 */
3897	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3898
3899	/* Do the same for the second ADC: mute capture input amp and
3900	 * set ADC connection to line in (on mic1 pin)
3901	 */
3902	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3903	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3904
3905	/* Mute all inputs to mixer widget (even unconnected ones) */
3906	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3907	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3908	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3909	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3910	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3911	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3912	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3913	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3914
3915	{ }
3916};
3917
3918/* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3919 * similar laptops (adapted from Fujitsu init verbs).
3920 */
3921static struct hda_verb alc260_acer_init_verbs[] = {
3922	/* On TravelMate laptops, GPIO 0 enables the internal speaker and
3923	 * the headphone jack.  Turn this on and rely on the standard mute
3924	 * methods whenever the user wants to turn these outputs off.
3925	 */
3926	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3927	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3928	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3929	/* Internal speaker/Headphone jack is connected to Line-out pin */
3930	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3931	/* Internal microphone/Mic jack is connected to Mic1 pin */
3932	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3933	/* Line In jack is connected to Line1 pin */
3934	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3935	/* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3936	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3937	/* Ensure all other unused pins are disabled and muted. */
3938	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3939	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3940	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3941	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3942	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3943	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3944	/* Disable digital (SPDIF) pins */
3945	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3946	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3947
3948	/* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
3949	 * bus when acting as outputs.
3950	 */
3951	{0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3952	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3953
3954	/* Start with output sum widgets muted and their output gains at min */
3955	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3956	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3957	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3958	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3959	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3960	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3961	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3962	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3963	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3964
3965	/* Unmute Line-out pin widget amp left and right
3966	 * (no equiv mixer ctrl)
3967	 */
3968	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3969	/* Unmute mono pin widget amp output (no equiv mixer ctrl) */
3970	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3971	/* Unmute Mic1 and Line1 pin widget input buffers since they start as
3972	 * inputs. If the pin mode is changed by the user the pin mode control
3973	 * will take care of enabling the pin's input/output buffers as needed.
3974	 * Therefore there's no need to enable the input buffer at this
3975	 * stage.
3976	 */
3977	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3978	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3979
3980	/* Mute capture amp left and right */
3981	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3982	/* Set ADC connection select to match default mixer setting - mic
3983	 * (on mic1 pin)
3984	 */
3985	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3986
3987	/* Do similar with the second ADC: mute capture input amp and
3988	 * set ADC connection to mic to match ALSA's default state.
3989	 */
3990	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3991	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3992
3993	/* Mute all inputs to mixer widget (even unconnected ones) */
3994	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3995	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3996	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3997	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3998	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3999	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4000	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4001	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4002
4003	{ }
4004};
4005
4006static struct hda_verb alc260_will_verbs[] = {
4007	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4008	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4009	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4010	{0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4011	{0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4012	{0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4013	{}
4014};
4015
4016static struct hda_verb alc260_replacer_672v_verbs[] = {
4017	{0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4018	{0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4019	{0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4020
4021	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4022	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4023	{0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4024
4025	{0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4026	{}
4027};
4028
4029/* toggle speaker-output according to the hp-jack state */
4030static void alc260_replacer_672v_automute(struct hda_codec *codec)
4031{
4032        unsigned int present;
4033
4034	/* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4035        present = snd_hda_codec_read(codec, 0x0f, 0,
4036                                     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4037	if (present) {
4038		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 1);
4039		snd_hda_codec_write(codec, 0x0f, 0,
4040				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
4041	} else {
4042		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
4043		snd_hda_codec_write(codec, 0x0f, 0,
4044				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4045	}
4046}
4047
4048static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4049                                       unsigned int res)
4050{
4051        if ((res >> 26) == ALC880_HP_EVENT)
4052                alc260_replacer_672v_automute(codec);
4053}
4054
4055/* Test configuration for debugging, modelled after the ALC880 test
4056 * configuration.
4057 */
4058#ifdef CONFIG_SND_DEBUG
4059static hda_nid_t alc260_test_dac_nids[1] = {
4060	0x02,
4061};
4062static hda_nid_t alc260_test_adc_nids[2] = {
4063	0x04, 0x05,
4064};
4065/* For testing the ALC260, each input MUX needs its own definition since
4066 * the signal assignments are different.  This assumes that the first ADC
4067 * is NID 0x04.
4068 */
4069static struct hda_input_mux alc260_test_capture_sources[2] = {
4070	{
4071		.num_items = 7,
4072		.items = {
4073			{ "MIC1 pin", 0x0 },
4074			{ "MIC2 pin", 0x1 },
4075			{ "LINE1 pin", 0x2 },
4076			{ "LINE2 pin", 0x3 },
4077			{ "CD pin", 0x4 },
4078			{ "LINE-OUT pin", 0x5 },
4079			{ "HP-OUT pin", 0x6 },
4080		},
4081        },
4082	{
4083		.num_items = 8,
4084		.items = {
4085			{ "MIC1 pin", 0x0 },
4086			{ "MIC2 pin", 0x1 },
4087			{ "LINE1 pin", 0x2 },
4088			{ "LINE2 pin", 0x3 },
4089			{ "CD pin", 0x4 },
4090			{ "Mixer", 0x5 },
4091			{ "LINE-OUT pin", 0x6 },
4092			{ "HP-OUT pin", 0x7 },
4093		},
4094        },
4095};
4096static struct snd_kcontrol_new alc260_test_mixer[] = {
4097	/* Output driver widgets */
4098	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4099	HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4100	HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4101	HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4102	HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4103	HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4104
4105	/* Modes for retasking pin widgets
4106	 * Note: the ALC260 doesn't seem to act on requests to enable mic
4107         * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4108         * mention this restriction.  At this stage it's not clear whether
4109         * this behaviour is intentional or is a hardware bug in chip
4110         * revisions available at least up until early 2006.  Therefore for
4111         * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4112         * choices, but if it turns out that the lack of mic bias for these
4113         * NIDs is intentional we could change their modes from
4114         * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4115	 */
4116	ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4117	ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4118	ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4119	ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4120	ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4121	ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4122
4123	/* Loopback mixer controls */
4124	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4125	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4126	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4127	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4128	HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4129	HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4130	HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4131	HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4132	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4133	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4134	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4135	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4136	HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4137	HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4138	HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4139	HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4140
4141	/* Controls for GPIO pins, assuming they are configured as outputs */
4142	ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4143	ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4144	ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4145	ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4146
4147	/* Switches to allow the digital IO pins to be enabled.  The datasheet
4148	 * is ambigious as to which NID is which; testing on laptops which
4149	 * make this output available should provide clarification.
4150	 */
4151	ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4152	ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4153
4154	{ } /* end */
4155};
4156static struct hda_verb alc260_test_init_verbs[] = {
4157	/* Enable all GPIOs as outputs with an initial value of 0 */
4158	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4159	{0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4160	{0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4161
4162	/* Enable retasking pins as output, initially without power amp */
4163	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4164	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4165	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4166	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4167	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4168	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4169
4170	/* Disable digital (SPDIF) pins initially, but users can enable
4171	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
4172	 * payload also sets the generation to 0, output to be in "consumer"
4173	 * PCM format, copyright asserted, no pre-emphasis and no validity
4174	 * control.
4175	 */
4176	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4177	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4178
4179	/* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4180	 * OUT1 sum bus when acting as an output.
4181	 */
4182	{0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4183	{0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4184	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4185	{0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4186
4187	/* Start with output sum widgets muted and their output gains at min */
4188	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4189	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4190	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4191	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4192	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4193	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4194	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4195	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4196	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4197
4198	/* Unmute retasking pin widget output buffers since the default
4199	 * state appears to be output.  As the pin mode is changed by the
4200	 * user the pin mode control will take care of enabling the pin's
4201	 * input/output buffers as needed.
4202	 */
4203	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4204	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4205	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4206	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4207	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4208	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4209	/* Also unmute the mono-out pin widget */
4210	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4211
4212	/* Mute capture amp left and right */
4213	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4214	/* Set ADC connection select to match default mixer setting (mic1
4215	 * pin)
4216	 */
4217	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4218
4219	/* Do the same for the second ADC: mute capture input amp and
4220	 * set ADC connection to mic1 pin
4221	 */
4222	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4223	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4224
4225	/* Mute all inputs to mixer widget (even unconnected ones) */
4226	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4227	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4228	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4229	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4230	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4231	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4232	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4233	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4234
4235	{ }
4236};
4237#endif
4238
4239static struct hda_pcm_stream alc260_pcm_analog_playback = {
4240	.substreams = 1,
4241	.channels_min = 2,
4242	.channels_max = 2,
4243};
4244
4245static struct hda_pcm_stream alc260_pcm_analog_capture = {
4246	.substreams = 1,
4247	.channels_min = 2,
4248	.channels_max = 2,
4249};
4250
4251#define alc260_pcm_digital_playback	alc880_pcm_digital_playback
4252#define alc260_pcm_digital_capture	alc880_pcm_digital_capture
4253
4254/*
4255 * for BIOS auto-configuration
4256 */
4257
4258static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4259					const char *pfx)
4260{
4261	hda_nid_t nid_vol;
4262	unsigned long vol_val, sw_val;
4263	char name[32];
4264	int err;
4265
4266	if (nid >= 0x0f && nid < 0x11) {
4267		nid_vol = nid - 0x7;
4268		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4269		sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4270	} else if (nid == 0x11) {
4271		nid_vol = nid - 0x7;
4272		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4273		sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4274	} else if (nid >= 0x12 && nid <= 0x15) {
4275		nid_vol = 0x08;
4276		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4277		sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4278	} else
4279		return 0; /* N/A */
4280
4281	snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4282	err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4283	if (err < 0)
4284		return err;
4285	snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4286	err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4287	if (err < 0)
4288		return err;
4289	return 1;
4290}
4291
4292/* add playback controls from the parsed DAC table */
4293static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4294					     const struct auto_pin_cfg *cfg)
4295{
4296	hda_nid_t nid;
4297	int err;
4298
4299	spec->multiout.num_dacs = 1;
4300	spec->multiout.dac_nids = spec->private_dac_nids;
4301	spec->multiout.dac_nids[0] = 0x02;
4302
4303	nid = cfg->line_out_pins[0];
4304	if (nid) {
4305		err = alc260_add_playback_controls(spec, nid, "Front");
4306		if (err < 0)
4307			return err;
4308	}
4309
4310	nid = cfg->speaker_pins[0];
4311	if (nid) {
4312		err = alc260_add_playback_controls(spec, nid, "Speaker");
4313		if (err < 0)
4314			return err;
4315	}
4316
4317	nid = cfg->hp_pins[0];
4318	if (nid) {
4319		err = alc260_add_playback_controls(spec, nid, "Headphone");
4320		if (err < 0)
4321			return err;
4322	}
4323	return 0;
4324}
4325
4326/* create playback/capture controls for input pins */
4327static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4328						const struct auto_pin_cfg *cfg)
4329{
4330	struct hda_input_mux *imux = &spec->private_imux;
4331	int i, err, idx;
4332
4333	for (i = 0; i < AUTO_PIN_LAST; i++) {
4334		if (cfg->input_pins[i] >= 0x12) {
4335			idx = cfg->input_pins[i] - 0x12;
4336			err = new_analog_input(spec, cfg->input_pins[i],
4337					       auto_pin_cfg_labels[i], idx,
4338					       0x07);
4339			if (err < 0)
4340				return err;
4341			imux->items[imux->num_items].label =
4342				auto_pin_cfg_labels[i];
4343			imux->items[imux->num_items].index = idx;
4344			imux->num_items++;
4345		}
4346		if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4347			idx = cfg->input_pins[i] - 0x09;
4348			err = new_analog_input(spec, cfg->input_pins[i],
4349					       auto_pin_cfg_labels[i], idx,
4350					       0x07);
4351			if (err < 0)
4352				return err;
4353			imux->items[imux->num_items].label =
4354				auto_pin_cfg_labels[i];
4355			imux->items[imux->num_items].index = idx;
4356			imux->num_items++;
4357		}
4358	}
4359	return 0;
4360}
4361
4362static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4363					      hda_nid_t nid, int pin_type,
4364					      int sel_idx)
4365{
4366	/* set as output */
4367	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4368			    pin_type);
4369	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4370			    AMP_OUT_UNMUTE);
4371	/* need the manual connection? */
4372	if (nid >= 0x12) {
4373		int idx = nid - 0x12;
4374		snd_hda_codec_write(codec, idx + 0x0b, 0,
4375				    AC_VERB_SET_CONNECT_SEL, sel_idx);
4376	}
4377}
4378
4379static void alc260_auto_init_multi_out(struct hda_codec *codec)
4380{
4381	struct alc_spec *spec = codec->spec;
4382	hda_nid_t nid;
4383
4384	alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4385	nid = spec->autocfg.line_out_pins[0];
4386	if (nid) {
4387		int pin_type = get_pin_type(spec->autocfg.line_out_type);
4388		alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4389	}
4390
4391	nid = spec->autocfg.speaker_pins[0];
4392	if (nid)
4393		alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4394
4395	nid = spec->autocfg.hp_pins[0];
4396	if (nid)
4397		alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4398}
4399
4400#define ALC260_PIN_CD_NID		0x16
4401static void alc260_auto_init_analog_input(struct hda_codec *codec)
4402{
4403	struct alc_spec *spec = codec->spec;
4404	int i;
4405
4406	for (i = 0; i < AUTO_PIN_LAST; i++) {
4407		hda_nid_t nid = spec->autocfg.input_pins[i];
4408		if (nid >= 0x12) {
4409			snd_hda_codec_write(codec, nid, 0,
4410					    AC_VERB_SET_PIN_WIDGET_CONTROL,
4411					    i <= AUTO_PIN_FRONT_MIC ?
4412					    PIN_VREF80 : PIN_IN);
4413			if (nid != ALC260_PIN_CD_NID)
4414				snd_hda_codec_write(codec, nid, 0,
4415						    AC_VERB_SET_AMP_GAIN_MUTE,
4416						    AMP_OUT_MUTE);
4417		}
4418	}
4419}
4420
4421/*
4422 * generic initialization of ADC, input mixers and output mixers
4423 */
4424static struct hda_verb alc260_volume_init_verbs[] = {
4425	/*
4426	 * Unmute ADC0-1 and set the default input to mic-in
4427	 */
4428	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4429	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4430	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4431	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4432
4433	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4434	 * mixer widget
4435	 * Note: PASD motherboards uses the Line In 2 as the input for
4436	 * front panel mic (mic 2)
4437	 */
4438	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4439	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4440	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4441	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4442	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4443	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4444
4445	/*
4446	 * Set up output mixers (0x08 - 0x0a)
4447	 */
4448	/* set vol=0 to output mixers */
4449	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4450	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4451	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4452	/* set up input amps for analog loopback */
4453	/* Amp Indices: DAC = 0, mixer = 1 */
4454	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4455	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4456	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4457	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4458	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4459	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4460
4461	{ }
4462};
4463
4464static int alc260_parse_auto_config(struct hda_codec *codec)
4465{
4466	struct alc_spec *spec = codec->spec;
4467	unsigned int wcap;
4468	int err;
4469	static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4470
4471	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4472					   alc260_ignore);
4473	if (err < 0)
4474		return err;
4475	err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4476	if (err < 0)
4477		return err;
4478	if (!spec->kctl_alloc)
4479		return 0; /* can't find valid BIOS pin config */
4480	err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4481	if (err < 0)
4482		return err;
4483
4484	spec->multiout.max_channels = 2;
4485
4486	if (spec->autocfg.dig_out_pin)
4487		spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4488	if (spec->kctl_alloc)
4489		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4490
4491	spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4492
4493	spec->num_mux_defs = 1;
4494	spec->input_mux = &spec->private_imux;
4495
4496	/* check whether NID 0x04 is valid */
4497	wcap = get_wcaps(codec, 0x04);
4498	wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4499	if (wcap != AC_WID_AUD_IN) {
4500		spec->adc_nids = alc260_adc_nids_alt;
4501		spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4502		spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4503	} else {
4504		spec->adc_nids = alc260_adc_nids;
4505		spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4506		spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4507	}
4508	spec->num_mixers++;
4509
4510	return 1;
4511}
4512
4513/* additional initialization for auto-configuration model */
4514static void alc260_auto_init(struct hda_codec *codec)
4515{
4516	alc260_auto_init_multi_out(codec);
4517	alc260_auto_init_analog_input(codec);
4518}
4519
4520/*
4521 * ALC260 configurations
4522 */
4523static const char *alc260_models[ALC260_MODEL_LAST] = {
4524	[ALC260_BASIC]		= "basic",
4525	[ALC260_HP]		= "hp",
4526	[ALC260_HP_3013]	= "hp-3013",
4527	[ALC260_FUJITSU_S702X]	= "fujitsu",
4528	[ALC260_ACER]		= "acer",
4529	[ALC260_WILL]		= "will",
4530	[ALC260_REPLACER_672V]	= "replacer",
4531#ifdef CONFIG_SND_DEBUG
4532	[ALC260_TEST]		= "test",
4533#endif
4534	[ALC260_AUTO]		= "auto",
4535};
4536
4537static struct snd_pci_quirk alc260_cfg_tbl[] = {
4538	SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4539	SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4540	SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4541	SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4542	SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4543	SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4544	SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4545	SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4546	SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4547	SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4548	SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4549	SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4550	SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4551	SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4552	SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4553	SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4554	SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4555	SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4556	{}
4557};
4558
4559static struct alc_config_preset alc260_presets[] = {
4560	[ALC260_BASIC] = {
4561		.mixers = { alc260_base_output_mixer,
4562			    alc260_input_mixer,
4563			    alc260_pc_beep_mixer,
4564			    alc260_capture_mixer },
4565		.init_verbs = { alc260_init_verbs },
4566		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4567		.dac_nids = alc260_dac_nids,
4568		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4569		.adc_nids = alc260_adc_nids,
4570		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4571		.channel_mode = alc260_modes,
4572		.input_mux = &alc260_capture_source,
4573	},
4574	[ALC260_HP] = {
4575		.mixers = { alc260_base_output_mixer,
4576			    alc260_input_mixer,
4577			    alc260_capture_alt_mixer },
4578		.init_verbs = { alc260_init_verbs },
4579		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4580		.dac_nids = alc260_dac_nids,
4581		.num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4582		.adc_nids = alc260_hp_adc_nids,
4583		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4584		.channel_mode = alc260_modes,
4585		.input_mux = &alc260_capture_source,
4586	},
4587	[ALC260_HP_3013] = {
4588		.mixers = { alc260_hp_3013_mixer,
4589			    alc260_input_mixer,
4590			    alc260_capture_alt_mixer },
4591		.init_verbs = { alc260_hp_3013_init_verbs },
4592		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4593		.dac_nids = alc260_dac_nids,
4594		.num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4595		.adc_nids = alc260_hp_adc_nids,
4596		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4597		.channel_mode = alc260_modes,
4598		.input_mux = &alc260_capture_source,
4599	},
4600	[ALC260_FUJITSU_S702X] = {
4601		.mixers = { alc260_fujitsu_mixer,
4602			    alc260_capture_mixer },
4603		.init_verbs = { alc260_fujitsu_init_verbs },
4604		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4605		.dac_nids = alc260_dac_nids,
4606		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4607		.adc_nids = alc260_dual_adc_nids,
4608		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4609		.channel_mode = alc260_modes,
4610		.num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4611		.input_mux = alc260_fujitsu_capture_sources,
4612	},
4613	[ALC260_ACER] = {
4614		.mixers = { alc260_acer_mixer,
4615			    alc260_capture_mixer },
4616		.init_verbs = { alc260_acer_init_verbs },
4617		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4618		.dac_nids = alc260_dac_nids,
4619		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4620		.adc_nids = alc260_dual_adc_nids,
4621		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4622		.channel_mode = alc260_modes,
4623		.num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4624		.input_mux = alc260_acer_capture_sources,
4625	},
4626	[ALC260_WILL] = {
4627		.mixers = { alc260_will_mixer,
4628			    alc260_capture_mixer },
4629		.init_verbs = { alc260_init_verbs, alc260_will_verbs },
4630		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4631		.dac_nids = alc260_dac_nids,
4632		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4633		.adc_nids = alc260_adc_nids,
4634		.dig_out_nid = ALC260_DIGOUT_NID,
4635		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4636		.channel_mode = alc260_modes,
4637		.input_mux = &alc260_capture_source,
4638	},
4639	[ALC260_REPLACER_672V] = {
4640		.mixers = { alc260_replacer_672v_mixer,
4641			    alc260_capture_mixer },
4642		.init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4643		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
4644		.dac_nids = alc260_dac_nids,
4645		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4646		.adc_nids = alc260_adc_nids,
4647		.dig_out_nid = ALC260_DIGOUT_NID,
4648		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4649		.channel_mode = alc260_modes,
4650		.input_mux = &alc260_capture_source,
4651		.unsol_event = alc260_replacer_672v_unsol_event,
4652		.init_hook = alc260_replacer_672v_automute,
4653	},
4654#ifdef CONFIG_SND_DEBUG
4655	[ALC260_TEST] = {
4656		.mixers = { alc260_test_mixer,
4657			    alc260_capture_mixer },
4658		.init_verbs = { alc260_test_init_verbs },
4659		.num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4660		.dac_nids = alc260_test_dac_nids,
4661		.num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4662		.adc_nids = alc260_test_adc_nids,
4663		.num_channel_mode = ARRAY_SIZE(alc260_modes),
4664		.channel_mode = alc260_modes,
4665		.num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4666		.input_mux = alc260_test_capture_sources,
4667	},
4668#endif
4669};
4670
4671static int patch_alc260(struct hda_codec *codec)
4672{
4673	struct alc_spec *spec;
4674	int err, board_config;
4675
4676	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4677	if (spec == NULL)
4678		return -ENOMEM;
4679
4680	codec->spec = spec;
4681
4682	board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4683						  alc260_models,
4684						  alc260_cfg_tbl);
4685	if (board_config < 0) {
4686		snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4687			   "trying auto-probe from BIOS...\n");
4688		board_config = ALC260_AUTO;
4689	}
4690
4691	if (board_config == ALC260_AUTO) {
4692		/* automatic parse from the BIOS config */
4693		err = alc260_parse_auto_config(codec);
4694		if (err < 0) {
4695			alc_free(codec);
4696			return err;
4697		} else if (!err) {
4698			printk(KERN_INFO
4699			       "hda_codec: Cannot set up configuration "
4700			       "from BIOS.  Using base mode...\n");
4701			board_config = ALC260_BASIC;
4702		}
4703	}
4704
4705	if (board_config != ALC260_AUTO)
4706		setup_preset(spec, &alc260_presets[board_config]);
4707
4708	spec->stream_name_analog = "ALC260 Analog";
4709	spec->stream_analog_playback = &alc260_pcm_analog_playback;
4710	spec->stream_analog_capture = &alc260_pcm_analog_capture;
4711
4712	spec->stream_name_digital = "ALC260 Digital";
4713	spec->stream_digital_playback = &alc260_pcm_digital_playback;
4714	spec->stream_digital_capture = &alc260_pcm_digital_capture;
4715
4716	codec->patch_ops = alc_patch_ops;
4717	if (board_config == ALC260_AUTO)
4718		spec->init_hook = alc260_auto_init;
4719
4720	return 0;
4721}
4722
4723
4724/*
4725 * ALC882 support
4726 *
4727 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4728 * configuration.  Each pin widget can choose any input DACs and a mixer.
4729 * Each ADC is connected from a mixer of all inputs.  This makes possible
4730 * 6-channel independent captures.
4731 *
4732 * In addition, an independent DAC for the multi-playback (not used in this
4733 * driver yet).
4734 */
4735#define ALC882_DIGOUT_NID	0x06
4736#define ALC882_DIGIN_NID	0x0a
4737
4738static struct hda_channel_mode alc882_ch_modes[1] = {
4739	{ 8, NULL }
4740};
4741
4742static hda_nid_t alc882_dac_nids[4] = {
4743	/* front, rear, clfe, rear_surr */
4744	0x02, 0x03, 0x04, 0x05
4745};
4746
4747/* identical with ALC880 */
4748#define alc882_adc_nids		alc880_adc_nids
4749#define alc882_adc_nids_alt	alc880_adc_nids_alt
4750
4751/* input MUX */
4752/* FIXME: should be a matrix-type input source selection */
4753
4754static struct hda_input_mux alc882_capture_source = {
4755	.num_items = 4,
4756	.items = {
4757		{ "Mic", 0x0 },
4758		{ "Front Mic", 0x1 },
4759		{ "Line", 0x2 },
4760		{ "CD", 0x4 },
4761	},
4762};
4763#define alc882_mux_enum_info alc_mux_enum_info
4764#define alc882_mux_enum_get alc_mux_enum_get
4765
4766static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4767			       struct snd_ctl_elem_value *ucontrol)
4768{
4769	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4770	struct alc_spec *spec = codec->spec;
4771	const struct hda_input_mux *imux = spec->input_mux;
4772	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4773	static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4774	hda_nid_t nid = capture_mixers[adc_idx];
4775	unsigned int *cur_val = &spec->cur_mux[adc_idx];
4776	unsigned int i, idx;
4777
4778	idx = ucontrol->value.enumerated.item[0];
4779	if (idx >= imux->num_items)
4780		idx = imux->num_items - 1;
4781	if (*cur_val == idx && !codec->in_resume)
4782		return 0;
4783	for (i = 0; i < imux->num_items; i++) {
4784		unsigned int v = (i == idx) ? 0x7000 : 0x7080;
4785		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4786				    v | (imux->items[i].index << 8));
4787	}
4788	*cur_val = idx;
4789	return 1;
4790}
4791
4792/*
4793 * 2ch mode
4794 */
4795static struct hda_verb alc882_3ST_ch2_init[] = {
4796	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4797	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4798	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4799	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4800	{ } /* end */
4801};
4802
4803/*
4804 * 6ch mode
4805 */
4806static struct hda_verb alc882_3ST_ch6_init[] = {
4807	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4808	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4809	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4810	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4811	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4812	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4813	{ } /* end */
4814};
4815
4816static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
4817	{ 2, alc882_3ST_ch2_init },
4818	{ 6, alc882_3ST_ch6_init },
4819};
4820
4821/*
4822 * 6ch mode
4823 */
4824static struct hda_verb alc882_sixstack_ch6_init[] = {
4825	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4826	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4827	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4828	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4829	{ } /* end */
4830};
4831
4832/*
4833 * 8ch mode
4834 */
4835static struct hda_verb alc882_sixstack_ch8_init[] = {
4836	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4837	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4838	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4839	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4840	{ } /* end */
4841};
4842
4843static struct hda_channel_mode alc882_sixstack_modes[2] = {
4844	{ 6, alc882_sixstack_ch6_init },
4845	{ 8, alc882_sixstack_ch8_init },
4846};
4847
4848/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4849 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4850 */
4851static struct snd_kcontrol_new alc882_base_mixer[] = {
4852	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4853	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4854	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4855	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4856	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4857	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4858	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4859	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4860	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4861	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4862	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4863	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4864	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4865	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4866	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4867	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4868	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4869	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4870	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4871	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4872	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4873	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4874	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4875	{ } /* end */
4876};
4877
4878static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
4879	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4880	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4881	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4882	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4883	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4884	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4885	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4886	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4887	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4888	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4889	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4890	{ } /* end */
4891};
4892
4893static struct snd_kcontrol_new alc882_targa_mixer[] = {
4894	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4895	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4896	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4897	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4898	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4899	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4900	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4901	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4902	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4903	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4904	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4905	{ } /* end */
4906};
4907
4908/* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
4909 *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
4910 */
4911static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
4912	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4913	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
4914	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4915	HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4916	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4917	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4918	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4919	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4920	HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
4921	HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
4922	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4923	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4924	{ } /* end */
4925};
4926
4927static struct snd_kcontrol_new alc882_chmode_mixer[] = {
4928	{
4929		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4930		.name = "Channel Mode",
4931		.info = alc_ch_mode_info,
4932		.get = alc_ch_mode_get,
4933		.put = alc_ch_mode_put,
4934	},
4935	{ } /* end */
4936};
4937
4938static struct hda_verb alc882_init_verbs[] = {
4939	/* Front mixer: unmute input/output amp left and right (volume = 0) */
4940	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4941	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4942	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4943	/* Rear mixer */
4944	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4945	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4946	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4947	/* CLFE mixer */
4948	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4949	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4950	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4951	/* Side mixer */
4952	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4953	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4954	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4955
4956	/* Front Pin: output 0 (0x0c) */
4957	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4958	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4959	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
4960	/* Rear Pin: output 1 (0x0d) */
4961	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4962	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4963	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4964	/* CLFE Pin: output 2 (0x0e) */
4965	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4966	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4967	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
4968	/* Side Pin: output 3 (0x0f) */
4969	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4970	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4971	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
4972	/* Mic (rear) pin: input vref at 80% */
4973	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4974	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4975	/* Front Mic pin: input vref at 80% */
4976	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4977	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4978	/* Line In pin: input */
4979	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4980	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4981	/* Line-2 In: Headphone output (output 0 - 0x0c) */
4982	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4983	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4984	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
4985	/* CD pin widget for input */
4986	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4987
4988	/* FIXME: use matrix-type input source selection */
4989	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4990	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4991	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4992	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4993	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4994	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4995	/* Input mixer2 */
4996	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4997	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4998	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4999	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5000	/* Input mixer3 */
5001	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5002	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5003	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5004	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5005	/* ADC1: mute amp left and right */
5006	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5007	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5008	/* ADC2: mute amp left and right */
5009	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5010	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5011	/* ADC3: mute amp left and right */
5012	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5013	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5014
5015	{ }
5016};
5017
5018static struct hda_verb alc882_eapd_verbs[] = {
5019	/* change to EAPD mode */
5020	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5021	{0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5022	{ }
5023};
5024
5025/* Mac Pro test */
5026static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5027	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5028	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5029	HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5030	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5031	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5032	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5033	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5034	{ } /* end */
5035};
5036
5037static struct hda_verb alc882_macpro_init_verbs[] = {
5038	/* Front mixer: unmute input/output amp left and right (volume = 0) */
5039	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5040	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5042	/* Front Pin: output 0 (0x0c) */
5043	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5044	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5045	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5046	/* Front Mic pin: input vref at 80% */
5047	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5048	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5049	/* Speaker:  output */
5050	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5051	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5052	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5053	/* Headphone output (output 0 - 0x0c) */
5054	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5055	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5056	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5057
5058	/* FIXME: use matrix-type input source selection */
5059	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5060	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5061	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5062	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5063	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5064	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5065	/* Input mixer2 */
5066	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5067	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5068	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5069	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5070	/* Input mixer3 */
5071	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5072	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5073	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5074	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5075	/* ADC1: mute amp left and right */
5076	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5077	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5078	/* ADC2: mute amp left and right */
5079	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5080	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5081	/* ADC3: mute amp left and right */
5082	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5083	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5084
5085	{ }
5086};
5087
5088static struct hda_verb alc882_targa_verbs[] = {
5089	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5090	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5091
5092	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5093	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5094
5095	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5096	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5097	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5098
5099	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5100	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5101	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5102	{0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5103	{ } /* end */
5104};
5105
5106/* toggle speaker-output according to the hp-jack state */
5107static void alc882_targa_automute(struct hda_codec *codec)
5108{
5109 	unsigned int present;
5110
5111 	present = snd_hda_codec_read(codec, 0x14, 0,
5112				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5113	snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
5114				 0x80, present ? 0x80 : 0);
5115	snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
5116				 0x80, present ? 0x80 : 0);
5117	snd_hda_codec_write(codec, 1, 0, AC_VERB_SET_GPIO_DATA, present ? 1 : 3);
5118}
5119
5120static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5121{
5122	/* Looks like the unsol event is incompatible with the standard
5123	 * definition.  4bit tag is placed at 26 bit!
5124	 */
5125	if (((res >> 26) == ALC880_HP_EVENT)) {
5126		alc882_targa_automute(codec);
5127	}
5128}
5129
5130static struct hda_verb alc882_asus_a7j_verbs[] = {
5131	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5132	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5133
5134	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5135	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5136	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5137
5138	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5139	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5140	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5141
5142	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5143	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5144	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5145	{ } /* end */
5146};
5147
5148static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5149{
5150	unsigned int gpiostate, gpiomask, gpiodir;
5151
5152	gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5153				       AC_VERB_GET_GPIO_DATA, 0);
5154
5155	if (!muted)
5156		gpiostate |= (1 << pin);
5157	else
5158		gpiostate &= ~(1 << pin);
5159
5160	gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5161				      AC_VERB_GET_GPIO_MASK, 0);
5162	gpiomask |= (1 << pin);
5163
5164	gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5165				     AC_VERB_GET_GPIO_DIRECTION, 0);
5166	gpiodir |= (1 << pin);
5167
5168
5169	snd_hda_codec_write(codec, codec->afg, 0,
5170			    AC_VERB_SET_GPIO_MASK, gpiomask);
5171	snd_hda_codec_write(codec, codec->afg, 0,
5172			    AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5173
5174	msleep(1);
5175
5176	snd_hda_codec_write(codec, codec->afg, 0,
5177			    AC_VERB_SET_GPIO_DATA, gpiostate);
5178}
5179
5180/*
5181 * generic initialization of ADC, input mixers and output mixers
5182 */
5183static struct hda_verb alc882_auto_init_verbs[] = {
5184	/*
5185	 * Unmute ADC0-2 and set the default input to mic-in
5186	 */
5187	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5188	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5189	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5190	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5191	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5192	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5193
5194	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5195	 * mixer widget
5196	 * Note: PASD motherboards uses the Line In 2 as the input for
5197	 * front panel mic (mic 2)
5198	 */
5199	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5200	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5201	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5202	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5203	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5204	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5205
5206	/*
5207	 * Set up output mixers (0x0c - 0x0f)
5208	 */
5209	/* set vol=0 to output mixers */
5210	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5211	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5212	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5213	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5214	/* set up input amps for analog loopback */
5215	/* Amp Indices: DAC = 0, mixer = 1 */
5216	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5217	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5218	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5219	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5220	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5221	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5222	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5223	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5224	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5225	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5226
5227	/* FIXME: use matrix-type input source selection */
5228	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5229	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5230	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5231	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5232	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5233	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5234	/* Input mixer2 */
5235	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5236	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5237	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5238	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5239	/* Input mixer3 */
5240	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5241	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5242	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5243	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5244
5245	{ }
5246};
5247
5248/* capture mixer elements */
5249static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5250	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5251	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5252	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5253	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5254	{
5255		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5256		/* The multiple "Capture Source" controls confuse alsamixer
5257		 * So call somewhat different..
5258		 * FIXME: the controls appear in the "playback" view!
5259		 */
5260		/* .name = "Capture Source", */
5261		.name = "Input Source",
5262		.count = 2,
5263		.info = alc882_mux_enum_info,
5264		.get = alc882_mux_enum_get,
5265		.put = alc882_mux_enum_put,
5266	},
5267	{ } /* end */
5268};
5269
5270static struct snd_kcontrol_new alc882_capture_mixer[] = {
5271	HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5272	HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5273	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5274	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5275	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5276	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5277	{
5278		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5279		/* The multiple "Capture Source" controls confuse alsamixer
5280		 * So call somewhat different..
5281		 * FIXME: the controls appear in the "playback" view!
5282		 */
5283		/* .name = "Capture Source", */
5284		.name = "Input Source",
5285		.count = 3,
5286		.info = alc882_mux_enum_info,
5287		.get = alc882_mux_enum_get,
5288		.put = alc882_mux_enum_put,
5289	},
5290	{ } /* end */
5291};
5292
5293/* pcm configuration: identiacal with ALC880 */
5294#define alc882_pcm_analog_playback	alc880_pcm_analog_playback
5295#define alc882_pcm_analog_capture	alc880_pcm_analog_capture
5296#define alc882_pcm_digital_playback	alc880_pcm_digital_playback
5297#define alc882_pcm_digital_capture	alc880_pcm_digital_capture
5298
5299/*
5300 * configuration and preset
5301 */
5302static const char *alc882_models[ALC882_MODEL_LAST] = {
5303	[ALC882_3ST_DIG]	= "3stack-dig",
5304	[ALC882_6ST_DIG]	= "6stack-dig",
5305	[ALC882_ARIMA]		= "arima",
5306	[ALC882_W2JC]		= "w2jc",
5307	[ALC885_MACPRO]		= "macpro",
5308	[ALC882_AUTO]		= "auto",
5309};
5310
5311static struct snd_pci_quirk alc882_cfg_tbl[] = {
5312	SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5313	SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5314	SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5315	SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5316	SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5317	SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5318	SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5319	SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5320	{}
5321};
5322
5323static struct alc_config_preset alc882_presets[] = {
5324	[ALC882_3ST_DIG] = {
5325		.mixers = { alc882_base_mixer },
5326		.init_verbs = { alc882_init_verbs },
5327		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5328		.dac_nids = alc882_dac_nids,
5329		.dig_out_nid = ALC882_DIGOUT_NID,
5330		.dig_in_nid = ALC882_DIGIN_NID,
5331		.num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5332		.channel_mode = alc882_ch_modes,
5333		.need_dac_fix = 1,
5334		.input_mux = &alc882_capture_source,
5335	},
5336	[ALC882_6ST_DIG] = {
5337		.mixers = { alc882_base_mixer, alc882_chmode_mixer },
5338		.init_verbs = { alc882_init_verbs },
5339		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5340		.dac_nids = alc882_dac_nids,
5341		.dig_out_nid = ALC882_DIGOUT_NID,
5342		.dig_in_nid = ALC882_DIGIN_NID,
5343		.num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5344		.channel_mode = alc882_sixstack_modes,
5345		.input_mux = &alc882_capture_source,
5346	},
5347	[ALC882_ARIMA] = {
5348		.mixers = { alc882_base_mixer, alc882_chmode_mixer },
5349		.init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5350		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5351		.dac_nids = alc882_dac_nids,
5352		.num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5353		.channel_mode = alc882_sixstack_modes,
5354		.input_mux = &alc882_capture_source,
5355	},
5356	[ALC882_W2JC] = {
5357		.mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5358		.init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5359				alc880_gpio1_init_verbs },
5360		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5361		.dac_nids = alc882_dac_nids,
5362		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5363		.channel_mode = alc880_threestack_modes,
5364		.need_dac_fix = 1,
5365		.input_mux = &alc882_capture_source,
5366		.dig_out_nid = ALC882_DIGOUT_NID,
5367	},
5368	[ALC885_MACPRO] = {
5369		.mixers = { alc882_macpro_mixer },
5370		.init_verbs = { alc882_macpro_init_verbs },
5371		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5372		.dac_nids = alc882_dac_nids,
5373		.dig_out_nid = ALC882_DIGOUT_NID,
5374		.dig_in_nid = ALC882_DIGIN_NID,
5375		.num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5376		.channel_mode = alc882_ch_modes,
5377		.input_mux = &alc882_capture_source,
5378	},
5379	[ALC882_TARGA] = {
5380		.mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5381			    alc882_capture_mixer },
5382		.init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5383		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5384		.dac_nids = alc882_dac_nids,
5385		.dig_out_nid = ALC882_DIGOUT_NID,
5386		.num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5387		.adc_nids = alc882_adc_nids,
5388		.num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5389		.channel_mode = alc882_3ST_6ch_modes,
5390		.need_dac_fix = 1,
5391		.input_mux = &alc882_capture_source,
5392		.unsol_event = alc882_targa_unsol_event,
5393		.init_hook = alc882_targa_automute,
5394	},
5395	[ALC882_ASUS_A7J] = {
5396		.mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5397			    alc882_capture_mixer },
5398		.init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5399		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
5400		.dac_nids = alc882_dac_nids,
5401		.dig_out_nid = ALC882_DIGOUT_NID,
5402		.num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5403		.adc_nids = alc882_adc_nids,
5404		.num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5405		.channel_mode = alc882_3ST_6ch_modes,
5406		.need_dac_fix = 1,
5407		.input_mux = &alc882_capture_source,
5408	},
5409};
5410
5411
5412/*
5413 * BIOS auto configuration
5414 */
5415static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5416					      hda_nid_t nid, int pin_type,
5417					      int dac_idx)
5418{
5419	/* set as output */
5420	struct alc_spec *spec = codec->spec;
5421	int idx;
5422
5423	if (spec->multiout.dac_nids[dac_idx] == 0x25)
5424		idx = 4;
5425	else
5426		idx = spec->multiout.dac_nids[dac_idx] - 2;
5427
5428	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5429			    pin_type);
5430	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5431			    AMP_OUT_UNMUTE);
5432	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5433
5434}
5435
5436static void alc882_auto_init_multi_out(struct hda_codec *codec)
5437{
5438	struct alc_spec *spec = codec->spec;
5439	int i;
5440
5441	alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5442	for (i = 0; i <= HDA_SIDE; i++) {
5443		hda_nid_t nid = spec->autocfg.line_out_pins[i];
5444		int pin_type = get_pin_type(spec->autocfg.line_out_type);
5445		if (nid)
5446			alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5447							  i);
5448	}
5449}
5450
5451static void alc882_auto_init_hp_out(struct hda_codec *codec)
5452{
5453	struct alc_spec *spec = codec->spec;
5454	hda_nid_t pin;
5455
5456	pin = spec->autocfg.hp_pins[0];
5457	if (pin) /* connect to front */
5458		/* use dac 0 */
5459		alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5460}
5461
5462#define alc882_is_input_pin(nid)	alc880_is_input_pin(nid)
5463#define ALC882_PIN_CD_NID		ALC880_PIN_CD_NID
5464
5465static void alc882_auto_init_analog_input(struct hda_codec *codec)
5466{
5467	struct alc_spec *spec = codec->spec;
5468	int i;
5469
5470	for (i = 0; i < AUTO_PIN_LAST; i++) {
5471		hda_nid_t nid = spec->autocfg.input_pins[i];
5472		if (alc882_is_input_pin(nid)) {
5473			snd_hda_codec_write(codec, nid, 0,
5474					    AC_VERB_SET_PIN_WIDGET_CONTROL,
5475					    i <= AUTO_PIN_FRONT_MIC ?
5476					    PIN_VREF80 : PIN_IN);
5477			if (nid != ALC882_PIN_CD_NID)
5478				snd_hda_codec_write(codec, nid, 0,
5479						    AC_VERB_SET_AMP_GAIN_MUTE,
5480						    AMP_OUT_MUTE);
5481		}
5482	}
5483}
5484
5485/* almost identical with ALC880 parser... */
5486static int alc882_parse_auto_config(struct hda_codec *codec)
5487{
5488	struct alc_spec *spec = codec->spec;
5489	int err = alc880_parse_auto_config(codec);
5490
5491	if (err < 0)
5492		return err;
5493	else if (err > 0)
5494		/* hack - override the init verbs */
5495		spec->init_verbs[0] = alc882_auto_init_verbs;
5496	return err;
5497}
5498
5499/* additional initialization for auto-configuration model */
5500static void alc882_auto_init(struct hda_codec *codec)
5501{
5502	alc882_auto_init_multi_out(codec);
5503	alc882_auto_init_hp_out(codec);
5504	alc882_auto_init_analog_input(codec);
5505}
5506
5507static int patch_alc882(struct hda_codec *codec)
5508{
5509	struct alc_spec *spec;
5510	int err, board_config;
5511
5512	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5513	if (spec == NULL)
5514		return -ENOMEM;
5515
5516	codec->spec = spec;
5517
5518	board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
5519						  alc882_models,
5520						  alc882_cfg_tbl);
5521
5522	if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
5523		/* Pick up systems that don't supply PCI SSID */
5524		switch (codec->subsystem_id) {
5525		case 0x106b0c00: /* Mac Pro */
5526			board_config = ALC885_MACPRO;
5527			break;
5528		default:
5529			printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
5530		       			 "trying auto-probe from BIOS...\n");
5531			board_config = ALC882_AUTO;
5532		}
5533	}
5534
5535	if (board_config == ALC882_AUTO) {
5536		/* automatic parse from the BIOS config */
5537		err = alc882_parse_auto_config(codec);
5538		if (err < 0) {
5539			alc_free(codec);
5540			return err;
5541		} else if (!err) {
5542			printk(KERN_INFO
5543			       "hda_codec: Cannot set up configuration "
5544			       "from BIOS.  Using base mode...\n");
5545			board_config = ALC882_3ST_DIG;
5546		}
5547	}
5548
5549	if (board_config != ALC882_AUTO)
5550		setup_preset(spec, &alc882_presets[board_config]);
5551
5552	if (board_config == ALC885_MACPRO) {
5553		alc882_gpio_mute(codec, 0, 0);
5554		alc882_gpio_mute(codec, 1, 0);
5555	}
5556
5557	spec->stream_name_analog = "ALC882 Analog";
5558	spec->stream_analog_playback = &alc882_pcm_analog_playback;
5559	spec->stream_analog_capture = &alc882_pcm_analog_capture;
5560
5561	spec->stream_name_digital = "ALC882 Digital";
5562	spec->stream_digital_playback = &alc882_pcm_digital_playback;
5563	spec->stream_digital_capture = &alc882_pcm_digital_capture;
5564
5565	if (!spec->adc_nids && spec->input_mux) {
5566		/* check whether NID 0x07 is valid */
5567		unsigned int wcap = get_wcaps(codec, 0x07);
5568		/* get type */
5569		wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5570		if (wcap != AC_WID_AUD_IN) {
5571			spec->adc_nids = alc882_adc_nids_alt;
5572			spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
5573			spec->mixers[spec->num_mixers] =
5574				alc882_capture_alt_mixer;
5575			spec->num_mixers++;
5576		} else {
5577			spec->adc_nids = alc882_adc_nids;
5578			spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
5579			spec->mixers[spec->num_mixers] = alc882_capture_mixer;
5580			spec->num_mixers++;
5581		}
5582	}
5583
5584	codec->patch_ops = alc_patch_ops;
5585	if (board_config == ALC882_AUTO)
5586		spec->init_hook = alc882_auto_init;
5587
5588	return 0;
5589}
5590
5591/*
5592 * ALC883 support
5593 *
5594 * ALC883 is almost identical with ALC880 but has cleaner and more flexible
5595 * configuration.  Each pin widget can choose any input DACs and a mixer.
5596 * Each ADC is connected from a mixer of all inputs.  This makes possible
5597 * 6-channel independent captures.
5598 *
5599 * In addition, an independent DAC for the multi-playback (not used in this
5600 * driver yet).
5601 */
5602#define ALC883_DIGOUT_NID	0x06
5603#define ALC883_DIGIN_NID	0x0a
5604
5605static hda_nid_t alc883_dac_nids[4] = {
5606	/* front, rear, clfe, rear_surr */
5607	0x02, 0x04, 0x03, 0x05
5608};
5609
5610static hda_nid_t alc883_adc_nids[2] = {
5611	/* ADC1-2 */
5612	0x08, 0x09,
5613};
5614
5615/* input MUX */
5616/* FIXME: should be a matrix-type input source selection */
5617
5618static struct hda_input_mux alc883_capture_source = {
5619	.num_items = 4,
5620	.items = {
5621		{ "Mic", 0x0 },
5622		{ "Front Mic", 0x1 },
5623		{ "Line", 0x2 },
5624		{ "CD", 0x4 },
5625	},
5626};
5627
5628static struct hda_input_mux alc883_lenovo_101e_capture_source = {
5629	.num_items = 2,
5630	.items = {
5631		{ "Mic", 0x1 },
5632		{ "Line", 0x2 },
5633	},
5634};
5635
5636static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
5637	.num_items = 4,
5638	.items = {
5639		{ "Mic", 0x0 },
5640		{ "iMic", 0x1 },
5641		{ "Line", 0x2 },
5642		{ "CD", 0x4 },
5643	},
5644};
5645
5646#define alc883_mux_enum_info alc_mux_enum_info
5647#define alc883_mux_enum_get alc_mux_enum_get
5648
5649static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
5650			       struct snd_ctl_elem_value *ucontrol)
5651{
5652	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5653	struct alc_spec *spec = codec->spec;
5654	const struct hda_input_mux *imux = spec->input_mux;
5655	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5656	static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5657	hda_nid_t nid = capture_mixers[adc_idx];
5658	unsigned int *cur_val = &spec->cur_mux[adc_idx];
5659	unsigned int i, idx;
5660
5661	idx = ucontrol->value.enumerated.item[0];
5662	if (idx >= imux->num_items)
5663		idx = imux->num_items - 1;
5664	if (*cur_val == idx && !codec->in_resume)
5665		return 0;
5666	for (i = 0; i < imux->num_items; i++) {
5667		unsigned int v = (i == idx) ? 0x7000 : 0x7080;
5668		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5669				    v | (imux->items[i].index << 8));
5670	}
5671	*cur_val = idx;
5672	return 1;
5673}
5674
5675/*
5676 * 2ch mode
5677 */
5678static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
5679	{ 2, NULL }
5680};
5681
5682/*
5683 * 2ch mode
5684 */
5685static struct hda_verb alc883_3ST_ch2_init[] = {
5686	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5687	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5688	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5689	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5690	{ } /* end */
5691};
5692
5693/*
5694 * 6ch mode
5695 */
5696static struct hda_verb alc883_3ST_ch6_init[] = {
5697	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5698	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5699	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5700	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5701	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5702	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5703	{ } /* end */
5704};
5705
5706static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
5707	{ 2, alc883_3ST_ch2_init },
5708	{ 6, alc883_3ST_ch6_init },
5709};
5710
5711/*
5712 * 6ch mode
5713 */
5714static struct hda_verb alc883_sixstack_ch6_init[] = {
5715	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5716	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5717	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5718	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5719	{ } /* end */
5720};
5721
5722/*
5723 * 8ch mode
5724 */
5725static struct hda_verb alc883_sixstack_ch8_init[] = {
5726	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5727	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5728	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5729	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5730	{ } /* end */
5731};
5732
5733static struct hda_channel_mode alc883_sixstack_modes[2] = {
5734	{ 6, alc883_sixstack_ch6_init },
5735	{ 8, alc883_sixstack_ch8_init },
5736};
5737
5738static struct hda_verb alc883_medion_eapd_verbs[] = {
5739        /* eanable EAPD on medion laptop */
5740	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5741	{0x20, AC_VERB_SET_PROC_COEF, 0x3070},
5742	{ }
5743};
5744
5745/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5746 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5747 */
5748
5749static struct snd_kcontrol_new alc883_base_mixer[] = {
5750	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5751	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5752	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5753	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5754	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5755	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5756	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5757	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5758	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5759	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5760	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5761	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5762	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5763	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5764	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5765	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5766	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5767	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5768	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5769	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5770	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5771	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5772	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5773	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5774	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5775	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5776	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5777	{
5778		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5779		/* .name = "Capture Source", */
5780		.name = "Input Source",
5781		.count = 2,
5782		.info = alc883_mux_enum_info,
5783		.get = alc883_mux_enum_get,
5784		.put = alc883_mux_enum_put,
5785	},
5786	{ } /* end */
5787};
5788
5789static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
5790	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5791	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5792	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5793	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5794	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5795	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5796	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5797	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5798	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5799	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5800	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5801	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5802	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5803	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5804	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5805	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5806	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5807	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5808	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5809	{
5810		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5811		/* .name = "Capture Source", */
5812		.name = "Input Source",
5813		.count = 2,
5814		.info = alc883_mux_enum_info,
5815		.get = alc883_mux_enum_get,
5816		.put = alc883_mux_enum_put,
5817	},
5818	{ } /* end */
5819};
5820
5821static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
5822	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5823	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5824	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5825	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5826	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5827	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5828	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5829	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5830	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5831	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5832	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5833	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5834	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5835	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5836	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5837	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5838	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5839	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5840	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5841	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5842	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5843	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5844	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5845	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5846	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5847	{
5848		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5849		/* .name = "Capture Source", */
5850		.name = "Input Source",
5851		.count = 2,
5852		.info = alc883_mux_enum_info,
5853		.get = alc883_mux_enum_get,
5854		.put = alc883_mux_enum_put,
5855	},
5856	{ } /* end */
5857};
5858
5859static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
5860	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5861	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5862	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5863	HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5864	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5865	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5866	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
5867	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5868	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5869	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5870	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5871	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5872	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5873	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5874	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5875	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5876	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5877	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5878	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5879	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5880	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5881	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5882	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5883
5884	{
5885		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5886		/* .name = "Capture Source", */
5887		.name = "Input Source",
5888		.count = 1,
5889		.info = alc883_mux_enum_info,
5890		.get = alc883_mux_enum_get,
5891		.put = alc883_mux_enum_put,
5892	},
5893	{ } /* end */
5894};
5895
5896static struct snd_kcontrol_new alc883_tagra_mixer[] = {
5897	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5898	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5899	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5900	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5901	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5902	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5903	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5904	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5905	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5906	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5907	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5908	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5909	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5910	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5911	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5912	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5913	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5914	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5915	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5916	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5917	{
5918		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5919		/* .name = "Capture Source", */
5920		.name = "Input Source",
5921		.count = 2,
5922		.info = alc883_mux_enum_info,
5923		.get = alc883_mux_enum_get,
5924		.put = alc883_mux_enum_put,
5925	},
5926	{ } /* end */
5927};
5928
5929static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
5930	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5931	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5932	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5933	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5934	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5935	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5936	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5937	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5938	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5939	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5940	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5941	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5942	{
5943		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5944		/* .name = "Capture Source", */
5945		.name = "Input Source",
5946		.count = 2,
5947		.info = alc883_mux_enum_info,
5948		.get = alc883_mux_enum_get,
5949		.put = alc883_mux_enum_put,
5950	},
5951	{ } /* end */
5952};
5953
5954static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
5955	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5956	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5957	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5958	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
5959	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5960	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5961	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5962	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5963	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5964	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5965	{
5966		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5967		/* .name = "Capture Source", */
5968		.name = "Input Source",
5969		.count = 1,
5970		.info = alc883_mux_enum_info,
5971		.get = alc883_mux_enum_get,
5972		.put = alc883_mux_enum_put,
5973	},
5974	{ } /* end */
5975};
5976
5977static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
5978	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5979	HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
5980	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5981	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5982	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5983	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5984	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5985	HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5986	HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5987	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5988	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5989	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5990	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5991	{
5992		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5993		/* .name = "Capture Source", */
5994		.name = "Input Source",
5995		.count = 2,
5996		.info = alc883_mux_enum_info,
5997		.get = alc883_mux_enum_get,
5998		.put = alc883_mux_enum_put,
5999	},
6000	{ } /* end */
6001};
6002
6003static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6004	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6005	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6006	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6007	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6008	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6009	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6010	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6011	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6012	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6013	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6014	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6015	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6016	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6017	{
6018		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6019		/* .name = "Capture Source", */
6020		.name = "Input Source",
6021		.count = 2,
6022		.info = alc883_mux_enum_info,
6023		.get = alc883_mux_enum_get,
6024		.put = alc883_mux_enum_put,
6025	},
6026	{ } /* end */
6027};
6028
6029static struct snd_kcontrol_new alc888_hp_nettle_mixer[] = {
6030	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6031	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6032	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6033	HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6034	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6035	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6036	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6037	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6038	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6039	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6040	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6041	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6042	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6043	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6044	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6045	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6046	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6047	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6048	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6049	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6050	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6051	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6052	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6053	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6054	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6055	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6056	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6057	{
6058		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6059		/* .name = "Capture Source", */
6060		.name = "Input Source",
6061		.count = 2,
6062		.info = alc883_mux_enum_info,
6063		.get = alc883_mux_enum_get,
6064		.put = alc883_mux_enum_put,
6065	},
6066	{ } /* end */
6067};
6068
6069static struct snd_kcontrol_new alc888_hp_lucknow_mixer[] = {
6070	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6071	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6072	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6073	HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6074	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6075	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6076	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6077	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6078	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6079	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6080	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6081	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6082	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6083	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6084	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6085	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6086	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6087	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6088	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6089	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6090	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6091	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6092	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6093	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6094	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6095	{
6096		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6097		/* .name = "Capture Source", */
6098		.name = "Input Source",
6099		.count = 2,
6100		.info = alc883_mux_enum_info,
6101		.get = alc883_mux_enum_get,
6102		.put = alc883_mux_enum_put,
6103	},
6104	{ } /* end */
6105};
6106
6107static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6108	{
6109		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6110		.name = "Channel Mode",
6111		.info = alc_ch_mode_info,
6112		.get = alc_ch_mode_get,
6113		.put = alc_ch_mode_put,
6114	},
6115	{ } /* end */
6116};
6117
6118static struct hda_verb alc883_init_verbs[] = {
6119	/* ADC1: mute amp left and right */
6120	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6121	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6122	/* ADC2: mute amp left and right */
6123	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6124	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6125	/* Front mixer: unmute input/output amp left and right (volume = 0) */
6126	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6127	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6128	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6129	/* Rear mixer */
6130	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6131	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6132	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6133	/* CLFE mixer */
6134	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6135	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6136	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6137	/* Side mixer */
6138	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6139	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6140	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6141
6142	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6143	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6144	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6145	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6146	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6147
6148	/* Front Pin: output 0 (0x0c) */
6149	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6150	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6151	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6152	/* Rear Pin: output 1 (0x0d) */
6153	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6154	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6155	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6156	/* CLFE Pin: output 2 (0x0e) */
6157	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6158	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6159	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6160	/* Side Pin: output 3 (0x0f) */
6161	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6162	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6163	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6164	/* Mic (rear) pin: input vref at 80% */
6165	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6166	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6167	/* Front Mic pin: input vref at 80% */
6168	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6169	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6170	/* Line In pin: input */
6171	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6172	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6173	/* Line-2 In: Headphone output (output 0 - 0x0c) */
6174	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6175	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6176	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6177	/* CD pin widget for input */
6178	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6179
6180	/* FIXME: use matrix-type input source selection */
6181	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6182	/* Input mixer2 */
6183	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6184	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6185	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6186	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6187	/* Input mixer3 */
6188	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6189	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6190	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6191	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6192	{ }
6193};
6194
6195static struct hda_verb alc883_tagra_verbs[] = {
6196	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6197	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6198
6199	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6200	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6201
6202	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6203	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6204	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6205
6206	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6207	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6208	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6209	{0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6210
6211	{ } /* end */
6212};
6213
6214static struct hda_verb alc883_lenovo_101e_verbs[] = {
6215	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6216	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6217        {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6218	{ } /* end */
6219};
6220
6221static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6222        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6223	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6224        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6225        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6226	{ } /* end */
6227};
6228
6229static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6230	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6231	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6232	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6233	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6234	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6235	{ } /* end */
6236};
6237
6238static struct hda_verb alc888_hp_nettle_verbs[] = {
6239	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Front: output 0 (0x0c) */
6240	{0x15, AC_VERB_SET_CONNECT_SEL, 0x02},	/* Rear : output 2 (0x0e) */
6241	{0x16, AC_VERB_SET_CONNECT_SEL, 0x01},	/* CLFE : output 1 (0x0d) */
6242	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},	/* Side : output 3 (0x0f) */
6243	{ }
6244};
6245
6246static struct hda_verb alc888_hp_lucknow_verbs[] = {
6247	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Front: output 0 (0x0c) */
6248	{0x18, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Rear : output 1 (0x0d) */
6249	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},	/* CLFE : output 2 (0x0e) */
6250	{ }
6251};
6252
6253static struct hda_verb alc888_hp_lucknow_2ch_init[] = {
6254	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6255	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6256	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6257	{ 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6258	{ }
6259};
6260
6261static struct hda_verb alc888_hp_lucknow_6ch_init[] = {
6262	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6263	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6264	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6265	{ 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6266	{ }
6267};
6268
6269static struct hda_channel_mode alc888_hp_lucknow_modes[2] = {
6270	{ 2, alc888_hp_lucknow_2ch_init },
6271	{ 6, alc888_hp_lucknow_6ch_init },
6272};
6273
6274/* toggle front-jack and RCA according to the hp-jack state */
6275static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6276{
6277 	unsigned int present;
6278
6279 	present = snd_hda_codec_read(codec, 0x1b, 0,
6280				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6281	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6282				 0x80, present ? 0x80 : 0);
6283	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6284				 0x80, present ? 0x80 : 0);
6285	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6286				 0x80, present ? 0x80 : 0);
6287	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6288				 0x80, present ? 0x80 : 0);
6289
6290}
6291
6292/* toggle RCA according to the front-jack state */
6293static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6294{
6295 	unsigned int present;
6296
6297 	present = snd_hda_codec_read(codec, 0x14, 0,
6298				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6299	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6300				 0x80, present ? 0x80 : 0);
6301	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6302				 0x80, present ? 0x80 : 0);
6303
6304}
6305static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6306					     unsigned int res)
6307{
6308	if ((res >> 26) == ALC880_HP_EVENT)
6309		alc888_lenovo_ms7195_front_automute(codec);
6310	if ((res >> 26) == ALC880_FRONT_EVENT)
6311		alc888_lenovo_ms7195_rca_automute(codec);
6312}
6313
6314static struct hda_verb alc883_medion_md2_verbs[] = {
6315	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6316	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6317
6318	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6319
6320	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6321	{ } /* end */
6322};
6323
6324/* toggle speaker-output according to the hp-jack state */
6325static void alc883_medion_md2_automute(struct hda_codec *codec)
6326{
6327 	unsigned int present;
6328
6329 	present = snd_hda_codec_read(codec, 0x14, 0,
6330				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6331	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6332				 0x80, present ? 0x80 : 0);
6333	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6334				 0x80, present ? 0x80 : 0);
6335}
6336
6337static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
6338					  unsigned int res)
6339{
6340	if ((res >> 26) == ALC880_HP_EVENT)
6341		alc883_medion_md2_automute(codec);
6342}
6343
6344/* toggle speaker-output according to the hp-jack state */
6345static void alc883_tagra_automute(struct hda_codec *codec)
6346{
6347 	unsigned int present;
6348	unsigned char bits;
6349
6350 	present = snd_hda_codec_read(codec, 0x14, 0,
6351				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6352	bits = present ? 0x80 : 0;
6353	snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
6354				 0x80, bits);
6355	snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
6356				 0x80, bits);
6357	snd_hda_codec_write(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6358			    present ? 1 : 3);
6359}
6360
6361static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
6362{
6363	if ((res >> 26) == ALC880_HP_EVENT)
6364		alc883_tagra_automute(codec);
6365}
6366
6367static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
6368{
6369 	unsigned int present;
6370	unsigned char bits;
6371
6372 	present = snd_hda_codec_read(codec, 0x14, 0,
6373				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6374	bits = present ? 0x80 : 0;
6375	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6376				 0x80, bits);
6377	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6378				 0x80, bits);
6379}
6380
6381static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
6382{
6383 	unsigned int present;
6384	unsigned char bits;
6385
6386 	present = snd_hda_codec_read(codec, 0x1b, 0,
6387				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6388	bits = present ? 0x80 : 0;
6389	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6390				 0x80, bits);
6391	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6392				 0x80, bits);
6393	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6394				 0x80, bits);
6395	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6396				 0x80, bits);
6397}
6398
6399static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
6400					   unsigned int res)
6401{
6402	if ((res >> 26) == ALC880_HP_EVENT)
6403		alc883_lenovo_101e_all_automute(codec);
6404	if ((res >> 26) == ALC880_FRONT_EVENT)
6405		alc883_lenovo_101e_ispeaker_automute(codec);
6406}
6407
6408/*
6409 * generic initialization of ADC, input mixers and output mixers
6410 */
6411static struct hda_verb alc883_auto_init_verbs[] = {
6412	/*
6413	 * Unmute ADC0-2 and set the default input to mic-in
6414	 */
6415	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6416	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6417	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6418	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6419
6420	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6421	 * mixer widget
6422	 * Note: PASD motherboards uses the Line In 2 as the input for
6423	 * front panel mic (mic 2)
6424	 */
6425	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6426	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6427	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6428	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6429	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6430	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6431
6432	/*
6433	 * Set up output mixers (0x0c - 0x0f)
6434	 */
6435	/* set vol=0 to output mixers */
6436	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6437	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6438	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6439	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6440	/* set up input amps for analog loopback */
6441	/* Amp Indices: DAC = 0, mixer = 1 */
6442	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6443	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6444	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6445	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6446	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6447	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6448	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6449	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6450	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6451	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6452
6453	/* FIXME: use matrix-type input source selection */
6454	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6455	/* Input mixer1 */
6456	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6457	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6458	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6459	/* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6460	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6461	/* Input mixer2 */
6462	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6463	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6464	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6465	/* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6466	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6467
6468	{ }
6469};
6470
6471/* capture mixer elements */
6472static struct snd_kcontrol_new alc883_capture_mixer[] = {
6473	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6474	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6475	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6476	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6477	{
6478		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6479		/* The multiple "Capture Source" controls confuse alsamixer
6480		 * So call somewhat different..
6481		 * FIXME: the controls appear in the "playback" view!
6482		 */
6483		/* .name = "Capture Source", */
6484		.name = "Input Source",
6485		.count = 2,
6486		.info = alc882_mux_enum_info,
6487		.get = alc882_mux_enum_get,
6488		.put = alc882_mux_enum_put,
6489	},
6490	{ } /* end */
6491};
6492
6493/* pcm configuration: identiacal with ALC880 */
6494#define alc883_pcm_analog_playback	alc880_pcm_analog_playback
6495#define alc883_pcm_analog_capture	alc880_pcm_analog_capture
6496#define alc883_pcm_digital_playback	alc880_pcm_digital_playback
6497#define alc883_pcm_digital_capture	alc880_pcm_digital_capture
6498
6499/*
6500 * configuration and preset
6501 */
6502static const char *alc883_models[ALC883_MODEL_LAST] = {
6503	[ALC883_3ST_2ch_DIG]	= "3stack-dig",
6504	[ALC883_3ST_6ch_DIG]	= "3stack-6ch-dig",
6505	[ALC883_3ST_6ch]	= "3stack-6ch",
6506	[ALC883_6ST_DIG]	= "6stack-dig",
6507	[ALC883_TARGA_DIG]	= "targa-dig",
6508	[ALC883_TARGA_2ch_DIG]	= "targa-2ch-dig",
6509	[ALC883_ACER]		= "acer",
6510	[ALC883_MEDION]		= "medion",
6511	[ALC883_MEDION_MD2]	= "medion-md2",
6512	[ALC883_LAPTOP_EAPD]	= "laptop-eapd",
6513	[ALC883_LENOVO_101E_2ch] = "lenovo-101e",
6514	[ALC883_LENOVO_NB0763]	= "lenovo-nb0763",
6515	[ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
6516	[ALC888_HP_NETTLE]	= "hp-nettle",
6517	[ALC888_HP_LUCKNOW]	= "hp-lucknow",
6518	[ALC883_AUTO]		= "auto",
6519};
6520
6521static struct snd_pci_quirk alc883_cfg_tbl[] = {
6522	SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
6523	SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
6524	SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
6525	SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
6526	SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
6527	SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
6528	SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
6529	SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
6530	SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
6531	SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
6532	SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
6533	SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
6534	SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
6535	SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
6536	SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
6537	SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
6538	SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
6539	SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
6540	SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
6541	SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
6542	SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
6543	SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
6544	SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
6545	SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
6546	SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
6547	SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
6548	SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
6549	SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
6550	SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6551	SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6552	SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_HP_NETTLE),
6553	SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_HP_LUCKNOW),
6554	SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
6555	{}
6556};
6557
6558static struct alc_config_preset alc883_presets[] = {
6559	[ALC883_3ST_2ch_DIG] = {
6560		.mixers = { alc883_3ST_2ch_mixer },
6561		.init_verbs = { alc883_init_verbs },
6562		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6563		.dac_nids = alc883_dac_nids,
6564		.dig_out_nid = ALC883_DIGOUT_NID,
6565		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6566		.adc_nids = alc883_adc_nids,
6567		.dig_in_nid = ALC883_DIGIN_NID,
6568		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6569		.channel_mode = alc883_3ST_2ch_modes,
6570		.input_mux = &alc883_capture_source,
6571	},
6572	[ALC883_3ST_6ch_DIG] = {
6573		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6574		.init_verbs = { alc883_init_verbs },
6575		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6576		.dac_nids = alc883_dac_nids,
6577		.dig_out_nid = ALC883_DIGOUT_NID,
6578		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6579		.adc_nids = alc883_adc_nids,
6580		.dig_in_nid = ALC883_DIGIN_NID,
6581		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6582		.channel_mode = alc883_3ST_6ch_modes,
6583		.need_dac_fix = 1,
6584		.input_mux = &alc883_capture_source,
6585	},
6586	[ALC883_3ST_6ch] = {
6587		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6588		.init_verbs = { alc883_init_verbs },
6589		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6590		.dac_nids = alc883_dac_nids,
6591		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6592		.adc_nids = alc883_adc_nids,
6593		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6594		.channel_mode = alc883_3ST_6ch_modes,
6595		.need_dac_fix = 1,
6596		.input_mux = &alc883_capture_source,
6597	},
6598	[ALC883_6ST_DIG] = {
6599		.mixers = { alc883_base_mixer, alc883_chmode_mixer },
6600		.init_verbs = { alc883_init_verbs },
6601		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6602		.dac_nids = alc883_dac_nids,
6603		.dig_out_nid = ALC883_DIGOUT_NID,
6604		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6605		.adc_nids = alc883_adc_nids,
6606		.dig_in_nid = ALC883_DIGIN_NID,
6607		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
6608		.channel_mode = alc883_sixstack_modes,
6609		.input_mux = &alc883_capture_source,
6610	},
6611	[ALC883_TARGA_DIG] = {
6612		.mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
6613		.init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
6614		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6615		.dac_nids = alc883_dac_nids,
6616		.dig_out_nid = ALC883_DIGOUT_NID,
6617		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6618		.adc_nids = alc883_adc_nids,
6619		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6620		.channel_mode = alc883_3ST_6ch_modes,
6621		.need_dac_fix = 1,
6622		.input_mux = &alc883_capture_source,
6623		.unsol_event = alc883_tagra_unsol_event,
6624		.init_hook = alc883_tagra_automute,
6625	},
6626	[ALC883_TARGA_2ch_DIG] = {
6627		.mixers = { alc883_tagra_2ch_mixer},
6628		.init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
6629		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6630		.dac_nids = alc883_dac_nids,
6631		.dig_out_nid = ALC883_DIGOUT_NID,
6632		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6633		.adc_nids = alc883_adc_nids,
6634		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6635		.channel_mode = alc883_3ST_2ch_modes,
6636		.input_mux = &alc883_capture_source,
6637		.unsol_event = alc883_tagra_unsol_event,
6638		.init_hook = alc883_tagra_automute,
6639	},
6640	[ALC883_ACER] = {
6641		.mixers = { alc883_base_mixer,
6642			    alc883_chmode_mixer },
6643		/* On TravelMate laptops, GPIO 0 enables the internal speaker
6644		 * and the headphone jack.  Turn this on and rely on the
6645		 * standard mute methods whenever the user wants to turn
6646		 * these outputs off.
6647		 */
6648		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
6649		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6650		.dac_nids = alc883_dac_nids,
6651		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6652		.adc_nids = alc883_adc_nids,
6653		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6654		.channel_mode = alc883_3ST_2ch_modes,
6655		.input_mux = &alc883_capture_source,
6656	},
6657	[ALC883_MEDION] = {
6658		.mixers = { alc883_fivestack_mixer,
6659			    alc883_chmode_mixer },
6660		.init_verbs = { alc883_init_verbs,
6661				alc883_medion_eapd_verbs },
6662		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6663		.dac_nids = alc883_dac_nids,
6664		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6665		.adc_nids = alc883_adc_nids,
6666		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
6667		.channel_mode = alc883_sixstack_modes,
6668		.input_mux = &alc883_capture_source,
6669	},
6670	[ALC883_MEDION_MD2] = {
6671		.mixers = { alc883_medion_md2_mixer},
6672		.init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
6673		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6674		.dac_nids = alc883_dac_nids,
6675		.dig_out_nid = ALC883_DIGOUT_NID,
6676		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6677		.adc_nids = alc883_adc_nids,
6678		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6679		.channel_mode = alc883_3ST_2ch_modes,
6680		.input_mux = &alc883_capture_source,
6681		.unsol_event = alc883_medion_md2_unsol_event,
6682		.init_hook = alc883_medion_md2_automute,
6683	},
6684	[ALC883_LAPTOP_EAPD] = {
6685		.mixers = { alc883_base_mixer,
6686			    alc883_chmode_mixer },
6687		.init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
6688		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6689		.dac_nids = alc883_dac_nids,
6690		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6691		.adc_nids = alc883_adc_nids,
6692		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6693		.channel_mode = alc883_3ST_2ch_modes,
6694		.input_mux = &alc883_capture_source,
6695	},
6696	[ALC883_LENOVO_101E_2ch] = {
6697		.mixers = { alc883_lenovo_101e_2ch_mixer},
6698		.init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
6699		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6700		.dac_nids = alc883_dac_nids,
6701		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6702		.adc_nids = alc883_adc_nids,
6703		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6704		.channel_mode = alc883_3ST_2ch_modes,
6705		.input_mux = &alc883_lenovo_101e_capture_source,
6706		.unsol_event = alc883_lenovo_101e_unsol_event,
6707		.init_hook = alc883_lenovo_101e_all_automute,
6708	},
6709	[ALC883_LENOVO_NB0763] = {
6710		.mixers = { alc883_lenovo_nb0763_mixer },
6711		.init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
6712		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6713		.dac_nids = alc883_dac_nids,
6714		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6715		.adc_nids = alc883_adc_nids,
6716		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6717		.channel_mode = alc883_3ST_2ch_modes,
6718		.need_dac_fix = 1,
6719		.input_mux = &alc883_lenovo_nb0763_capture_source,
6720		.unsol_event = alc883_medion_md2_unsol_event,
6721		.init_hook = alc883_medion_md2_automute,
6722	},
6723	[ALC888_LENOVO_MS7195_DIG] = {
6724		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6725		.init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
6726		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6727		.dac_nids = alc883_dac_nids,
6728		.dig_out_nid = ALC883_DIGOUT_NID,
6729		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6730		.adc_nids = alc883_adc_nids,
6731		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6732		.channel_mode = alc883_3ST_6ch_modes,
6733		.need_dac_fix = 1,
6734		.input_mux = &alc883_capture_source,
6735		.unsol_event = alc883_lenovo_ms7195_unsol_event,
6736		.init_hook = alc888_lenovo_ms7195_front_automute,
6737	},
6738	[ALC888_HP_NETTLE] = {
6739		.mixers = { alc888_hp_nettle_mixer, alc883_chmode_mixer },
6740		.init_verbs = { alc883_init_verbs, alc888_hp_nettle_verbs },
6741		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6742		.dac_nids = alc883_dac_nids,
6743		.dig_out_nid = ALC883_DIGOUT_NID,
6744		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6745		.adc_nids = alc883_adc_nids,
6746		.dig_in_nid = ALC883_DIGIN_NID,
6747		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
6748		.channel_mode = alc883_sixstack_modes,
6749		.input_mux = &alc883_capture_source,
6750	},
6751	[ALC888_HP_LUCKNOW] = {
6752		.mixers = { alc888_hp_lucknow_mixer, alc883_chmode_mixer },
6753		.init_verbs = { alc883_init_verbs, alc888_hp_lucknow_verbs },
6754		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
6755		.dac_nids = alc883_dac_nids,
6756		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6757		.adc_nids = alc883_adc_nids,
6758		.num_channel_mode = ARRAY_SIZE(alc888_hp_lucknow_modes),
6759		.channel_mode = alc888_hp_lucknow_modes,
6760		.need_dac_fix = 1,
6761		.input_mux = &alc883_capture_source,
6762	},
6763};
6764
6765
6766/*
6767 * BIOS auto configuration
6768 */
6769static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
6770					      hda_nid_t nid, int pin_type,
6771					      int dac_idx)
6772{
6773	/* set as output */
6774	struct alc_spec *spec = codec->spec;
6775	int idx;
6776
6777	if (spec->multiout.dac_nids[dac_idx] == 0x25)
6778		idx = 4;
6779	else
6780		idx = spec->multiout.dac_nids[dac_idx] - 2;
6781
6782	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6783			    pin_type);
6784	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6785			    AMP_OUT_UNMUTE);
6786	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6787
6788}
6789
6790static void alc883_auto_init_multi_out(struct hda_codec *codec)
6791{
6792	struct alc_spec *spec = codec->spec;
6793	int i;
6794
6795	alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6796	for (i = 0; i <= HDA_SIDE; i++) {
6797		hda_nid_t nid = spec->autocfg.line_out_pins[i];
6798		int pin_type = get_pin_type(spec->autocfg.line_out_type);
6799		if (nid)
6800			alc883_auto_set_output_and_unmute(codec, nid, pin_type,
6801							  i);
6802	}
6803}
6804
6805static void alc883_auto_init_hp_out(struct hda_codec *codec)
6806{
6807	struct alc_spec *spec = codec->spec;
6808	hda_nid_t pin;
6809
6810	pin = spec->autocfg.hp_pins[0];
6811	if (pin) /* connect to front */
6812		/* use dac 0 */
6813		alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6814}
6815
6816#define alc883_is_input_pin(nid)	alc880_is_input_pin(nid)
6817#define ALC883_PIN_CD_NID		ALC880_PIN_CD_NID
6818
6819static void alc883_auto_init_analog_input(struct hda_codec *codec)
6820{
6821	struct alc_spec *spec = codec->spec;
6822	int i;
6823
6824	for (i = 0; i < AUTO_PIN_LAST; i++) {
6825		hda_nid_t nid = spec->autocfg.input_pins[i];
6826		if (alc883_is_input_pin(nid)) {
6827			snd_hda_codec_write(codec, nid, 0,
6828					    AC_VERB_SET_PIN_WIDGET_CONTROL,
6829					    (i <= AUTO_PIN_FRONT_MIC ?
6830					     PIN_VREF80 : PIN_IN));
6831			if (nid != ALC883_PIN_CD_NID)
6832				snd_hda_codec_write(codec, nid, 0,
6833						    AC_VERB_SET_AMP_GAIN_MUTE,
6834						    AMP_OUT_MUTE);
6835		}
6836	}
6837}
6838
6839/* almost identical with ALC880 parser... */
6840static int alc883_parse_auto_config(struct hda_codec *codec)
6841{
6842	struct alc_spec *spec = codec->spec;
6843	int err = alc880_parse_auto_config(codec);
6844
6845	if (err < 0)
6846		return err;
6847	else if (err > 0)
6848		/* hack - override the init verbs */
6849		spec->init_verbs[0] = alc883_auto_init_verbs;
6850	spec->mixers[spec->num_mixers] = alc883_capture_mixer;
6851	spec->num_mixers++;
6852	return err;
6853}
6854
6855/* additional initialization for auto-configuration model */
6856static void alc883_auto_init(struct hda_codec *codec)
6857{
6858	alc883_auto_init_multi_out(codec);
6859	alc883_auto_init_hp_out(codec);
6860	alc883_auto_init_analog_input(codec);
6861}
6862
6863static int patch_alc883(struct hda_codec *codec)
6864{
6865	struct alc_spec *spec;
6866	int err, board_config;
6867
6868	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6869	if (spec == NULL)
6870		return -ENOMEM;
6871
6872	codec->spec = spec;
6873
6874	board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
6875						  alc883_models,
6876						  alc883_cfg_tbl);
6877	if (board_config < 0) {
6878		printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
6879		       "trying auto-probe from BIOS...\n");
6880		board_config = ALC883_AUTO;
6881	}
6882
6883	if (board_config == ALC883_AUTO) {
6884		/* automatic parse from the BIOS config */
6885		err = alc883_parse_auto_config(codec);
6886		if (err < 0) {
6887			alc_free(codec);
6888			return err;
6889		} else if (!err) {
6890			printk(KERN_INFO
6891			       "hda_codec: Cannot set up configuration "
6892			       "from BIOS.  Using base mode...\n");
6893			board_config = ALC883_3ST_2ch_DIG;
6894		}
6895	}
6896
6897	if (board_config != ALC883_AUTO)
6898		setup_preset(spec, &alc883_presets[board_config]);
6899
6900	spec->stream_name_analog = "ALC883 Analog";
6901	spec->stream_analog_playback = &alc883_pcm_analog_playback;
6902	spec->stream_analog_capture = &alc883_pcm_analog_capture;
6903
6904	spec->stream_name_digital = "ALC883 Digital";
6905	spec->stream_digital_playback = &alc883_pcm_digital_playback;
6906	spec->stream_digital_capture = &alc883_pcm_digital_capture;
6907
6908	if (!spec->adc_nids && spec->input_mux) {
6909		spec->adc_nids = alc883_adc_nids;
6910		spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
6911	}
6912
6913	codec->patch_ops = alc_patch_ops;
6914	if (board_config == ALC883_AUTO)
6915		spec->init_hook = alc883_auto_init;
6916
6917	return 0;
6918}
6919
6920/*
6921 * ALC262 support
6922 */
6923
6924#define ALC262_DIGOUT_NID	ALC880_DIGOUT_NID
6925#define ALC262_DIGIN_NID	ALC880_DIGIN_NID
6926
6927#define alc262_dac_nids		alc260_dac_nids
6928#define alc262_adc_nids		alc882_adc_nids
6929#define alc262_adc_nids_alt	alc882_adc_nids_alt
6930
6931#define alc262_modes		alc260_modes
6932#define alc262_capture_source	alc882_capture_source
6933
6934static struct snd_kcontrol_new alc262_base_mixer[] = {
6935	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6936	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6937	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6938	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6939	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6940	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6941	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6942	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6943	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6944	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6945	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6946	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6947	/* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6948	   HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
6949	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
6950	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6951	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6952	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6953	{ } /* end */
6954};
6955
6956static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
6957	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6958	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6959	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6960	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6961	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6962	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6963	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6964	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6965	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6966	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6967	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6968	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6969	/* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6970	   HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
6971	/*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
6972	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6973	{ } /* end */
6974};
6975
6976static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
6977	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6978	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6979	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6980	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6981	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6982
6983	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6984	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6985	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6986	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6987	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6988	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6989	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6990	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6991	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6992	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6993	HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6994	HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
6995	HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
6996	HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
6997	{ } /* end */
6998};
6999
7000static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7001	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7002	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7003	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7004	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7005	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7006	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7007	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7008	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7009	HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7010	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7011	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7012	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7013	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7014	HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7015	HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7016	{ } /* end */
7017};
7018
7019static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7020	HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7021	HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7022	HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7023	{ } /* end */
7024};
7025
7026static struct snd_kcontrol_new alc262_sony_mixer[] = {
7027	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7028	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7029	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7030	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7031	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7032	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7033	{ } /* end */
7034};
7035
7036static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
7037	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7038	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7039	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7040	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7041	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7042	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7043	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7044	{ } /* end */
7045};
7046
7047#define alc262_capture_mixer		alc882_capture_mixer
7048#define alc262_capture_alt_mixer	alc882_capture_alt_mixer
7049
7050/*
7051 * generic initialization of ADC, input mixers and output mixers
7052 */
7053static struct hda_verb alc262_init_verbs[] = {
7054	/*
7055	 * Unmute ADC0-2 and set the default input to mic-in
7056	 */
7057	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7058	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7059	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7060	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7061	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7062	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7063
7064	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7065	 * mixer widget
7066	 * Note: PASD motherboards uses the Line In 2 as the input for
7067	 * front panel mic (mic 2)
7068	 */
7069	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7070	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7071	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7072	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7073	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7074	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7075
7076	/*
7077	 * Set up output mixers (0x0c - 0x0e)
7078	 */
7079	/* set vol=0 to output mixers */
7080	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7081	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7082	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7083	/* set up input amps for analog loopback */
7084	/* Amp Indices: DAC = 0, mixer = 1 */
7085	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7086	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7087	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7088	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7089	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7090	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7091
7092	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7093	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7094	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7095	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7096	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7097	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7098
7099	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7100	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7101	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7102	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7103	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7104
7105	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7106	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7107
7108	/* FIXME: use matrix-type input source selection */
7109	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7110	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7111	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7112	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7113	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7114	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7115	/* Input mixer2 */
7116	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7117	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7118	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7119	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7120	/* Input mixer3 */
7121	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7122	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7123	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7124	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7125
7126	{ }
7127};
7128
7129static struct hda_verb alc262_hippo_unsol_verbs[] = {
7130	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7131	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7132	{}
7133};
7134
7135static struct hda_verb alc262_hippo1_unsol_verbs[] = {
7136	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7137	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7138	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7139
7140	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7141	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7142	{}
7143};
7144
7145static struct hda_verb alc262_sony_unsol_verbs[] = {
7146	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7147	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7148	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},	// Front Mic
7149
7150	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7151	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7152};
7153
7154/* mute/unmute internal speaker according to the hp jack and mute state */
7155static void alc262_hippo_automute(struct hda_codec *codec, int force)
7156{
7157	struct alc_spec *spec = codec->spec;
7158	unsigned int mute;
7159
7160	if (force || !spec->sense_updated) {
7161		unsigned int present;
7162		/* need to execute and sync at first */
7163		snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
7164		present = snd_hda_codec_read(codec, 0x15, 0,
7165				    	 AC_VERB_GET_PIN_SENSE, 0);
7166		spec->jack_present = (present & 0x80000000) != 0;
7167		spec->sense_updated = 1;
7168	}
7169	if (spec->jack_present) {
7170		/* mute internal speaker */
7171		snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7172					 0x80, 0x80);
7173		snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7174					 0x80, 0x80);
7175	} else {
7176		/* unmute internal speaker if necessary */
7177		mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
7178		snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7179					 0x80, mute & 0x80);
7180		mute = snd_hda_codec_amp_read(codec, 0x15, 1, HDA_OUTPUT, 0);
7181		snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7182					 0x80, mute & 0x80);
7183	}
7184}
7185
7186/* unsolicited event for HP jack sensing */
7187static void alc262_hippo_unsol_event(struct hda_codec *codec,
7188				       unsigned int res)
7189{
7190	if ((res >> 26) != ALC880_HP_EVENT)
7191		return;
7192	alc262_hippo_automute(codec, 1);
7193}
7194
7195static void alc262_hippo1_automute(struct hda_codec *codec, int force)
7196{
7197	struct alc_spec *spec = codec->spec;
7198	unsigned int mute;
7199
7200	if (force || !spec->sense_updated) {
7201		unsigned int present;
7202		/* need to execute and sync at first */
7203		snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7204		present = snd_hda_codec_read(codec, 0x1b, 0,
7205				    	 AC_VERB_GET_PIN_SENSE, 0);
7206		spec->jack_present = (present & 0x80000000) != 0;
7207		spec->sense_updated = 1;
7208	}
7209	if (spec->jack_present) {
7210		/* mute internal speaker */
7211		snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7212					 0x80, 0x80);
7213		snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7214					 0x80, 0x80);
7215	} else {
7216		/* unmute internal speaker if necessary */
7217		mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7218		snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7219					 0x80, mute & 0x80);
7220		mute = snd_hda_codec_amp_read(codec, 0x1b, 1, HDA_OUTPUT, 0);
7221		snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7222					 0x80, mute & 0x80);
7223	}
7224}
7225
7226/* unsolicited event for HP jack sensing */
7227static void alc262_hippo1_unsol_event(struct hda_codec *codec,
7228				       unsigned int res)
7229{
7230	if ((res >> 26) != ALC880_HP_EVENT)
7231		return;
7232	alc262_hippo1_automute(codec, 1);
7233}
7234
7235/*
7236 * fujitsu model
7237 *  0x14 = headphone/spdif-out, 0x15 = internal speaker
7238 */
7239
7240#define ALC_HP_EVENT	0x37
7241
7242static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
7243	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
7244	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7245	{}
7246};
7247
7248static struct hda_input_mux alc262_fujitsu_capture_source = {
7249	.num_items = 2,
7250	.items = {
7251		{ "Mic", 0x0 },
7252		{ "CD", 0x4 },
7253	},
7254};
7255
7256static struct hda_input_mux alc262_HP_capture_source = {
7257	.num_items = 5,
7258	.items = {
7259		{ "Mic", 0x0 },
7260		{ "Front Mic", 0x3 },
7261		{ "Line", 0x2 },
7262		{ "CD", 0x4 },
7263		{ "AUX IN", 0x6 },
7264	},
7265};
7266
7267/* mute/unmute internal speaker according to the hp jack and mute state */
7268static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
7269{
7270	struct alc_spec *spec = codec->spec;
7271	unsigned int mute;
7272
7273	if (force || !spec->sense_updated) {
7274		unsigned int present;
7275		/* need to execute and sync at first */
7276		snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
7277		present = snd_hda_codec_read(codec, 0x14, 0,
7278				    	 AC_VERB_GET_PIN_SENSE, 0);
7279		spec->jack_present = (present & 0x80000000) != 0;
7280		spec->sense_updated = 1;
7281	}
7282	if (spec->jack_present) {
7283		/* mute internal speaker */
7284		snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7285					 0x80, 0x80);
7286		snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7287					 0x80, 0x80);
7288	} else {
7289		/* unmute internal speaker if necessary */
7290		mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
7291		snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7292					 0x80, mute & 0x80);
7293		mute = snd_hda_codec_amp_read(codec, 0x14, 1, HDA_OUTPUT, 0);
7294		snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7295					 0x80, mute & 0x80);
7296	}
7297}
7298
7299/* unsolicited event for HP jack sensing */
7300static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
7301				       unsigned int res)
7302{
7303	if ((res >> 26) != ALC_HP_EVENT)
7304		return;
7305	alc262_fujitsu_automute(codec, 1);
7306}
7307
7308/* bind volumes of both NID 0x0c and 0x0d */
7309static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
7310					 struct snd_ctl_elem_value *ucontrol)
7311{
7312	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7313	long *valp = ucontrol->value.integer.value;
7314	int change;
7315
7316	change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
7317					  0x7f, valp[0] & 0x7f);
7318	change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
7319					   0x7f, valp[1] & 0x7f);
7320	snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
7321				 0x7f, valp[0] & 0x7f);
7322	snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
7323				 0x7f, valp[1] & 0x7f);
7324	return change;
7325}
7326
7327/* bind hp and internal speaker mute (with plug check) */
7328static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
7329					 struct snd_ctl_elem_value *ucontrol)
7330{
7331	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7332	long *valp = ucontrol->value.integer.value;
7333	int change;
7334
7335	change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7336					  0x80, valp[0] ? 0 : 0x80);
7337	change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7338					   0x80, valp[1] ? 0 : 0x80);
7339	if (change || codec->in_resume)
7340		alc262_fujitsu_automute(codec, codec->in_resume);
7341	return change;
7342}
7343
7344static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
7345	{
7346		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7347		.name = "Master Playback Volume",
7348		.info = snd_hda_mixer_amp_volume_info,
7349		.get = snd_hda_mixer_amp_volume_get,
7350		.put = alc262_fujitsu_master_vol_put,
7351		.tlv = { .c = snd_hda_mixer_amp_tlv },
7352		.private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7353	},
7354	{
7355		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7356		.name = "Master Playback Switch",
7357		.info = snd_hda_mixer_amp_switch_info,
7358		.get = snd_hda_mixer_amp_switch_get,
7359		.put = alc262_fujitsu_master_sw_put,
7360		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7361	},
7362	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7363	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7364	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7365	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7366	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7367	{ } /* end */
7368};
7369
7370/* additional init verbs for Benq laptops */
7371static struct hda_verb alc262_EAPD_verbs[] = {
7372	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7373	{0x20, AC_VERB_SET_PROC_COEF,  0x3070},
7374	{}
7375};
7376
7377static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
7378	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7379	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7380
7381	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7382	{0x20, AC_VERB_SET_PROC_COEF,  0x3050},
7383	{}
7384};
7385
7386/* add playback controls from the parsed DAC table */
7387static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
7388					     const struct auto_pin_cfg *cfg)
7389{
7390	hda_nid_t nid;
7391	int err;
7392
7393	spec->multiout.num_dacs = 1;	/* only use one dac */
7394	spec->multiout.dac_nids = spec->private_dac_nids;
7395	spec->multiout.dac_nids[0] = 2;
7396
7397	nid = cfg->line_out_pins[0];
7398	if (nid) {
7399		err = add_control(spec, ALC_CTL_WIDGET_VOL,
7400				  "Front Playback Volume",
7401				  HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
7402		if (err < 0)
7403			return err;
7404		err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7405				  "Front Playback Switch",
7406				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
7407		if (err < 0)
7408			return err;
7409	}
7410
7411	nid = cfg->speaker_pins[0];
7412	if (nid) {
7413		if (nid == 0x16) {
7414			err = add_control(spec, ALC_CTL_WIDGET_VOL,
7415					  "Speaker Playback Volume",
7416					  HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7417							      HDA_OUTPUT));
7418			if (err < 0)
7419				return err;
7420			err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7421					  "Speaker Playback Switch",
7422					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7423							      HDA_OUTPUT));
7424			if (err < 0)
7425				return err;
7426		} else {
7427			err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7428					  "Speaker Playback Switch",
7429					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7430							      HDA_OUTPUT));
7431			if (err < 0)
7432				return err;
7433		}
7434	}
7435	nid = cfg->hp_pins[0];
7436	if (nid) {
7437		/* spec->multiout.hp_nid = 2; */
7438		if (nid == 0x16) {
7439			err = add_control(spec, ALC_CTL_WIDGET_VOL,
7440					  "Headphone Playback Volume",
7441					  HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7442							      HDA_OUTPUT));
7443			if (err < 0)
7444				return err;
7445			err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7446					  "Headphone Playback Switch",
7447					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7448							      HDA_OUTPUT));
7449			if (err < 0)
7450				return err;
7451		} else {
7452			err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7453					  "Headphone Playback Switch",
7454					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7455							      HDA_OUTPUT));
7456			if (err < 0)
7457				return err;
7458		}
7459	}
7460	return 0;
7461}
7462
7463/* identical with ALC880 */
7464#define alc262_auto_create_analog_input_ctls \
7465	alc880_auto_create_analog_input_ctls
7466
7467/*
7468 * generic initialization of ADC, input mixers and output mixers
7469 */
7470static struct hda_verb alc262_volume_init_verbs[] = {
7471	/*
7472	 * Unmute ADC0-2 and set the default input to mic-in
7473	 */
7474	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7475	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7476	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7477	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7478	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7479	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7480
7481	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7482	 * mixer widget
7483	 * Note: PASD motherboards uses the Line In 2 as the input for
7484	 * front panel mic (mic 2)
7485	 */
7486	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7487	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7488	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7489	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7490	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7491	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7492
7493	/*
7494	 * Set up output mixers (0x0c - 0x0f)
7495	 */
7496	/* set vol=0 to output mixers */
7497	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7498	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7499	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7500
7501	/* set up input amps for analog loopback */
7502	/* Amp Indices: DAC = 0, mixer = 1 */
7503	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7504	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7505	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7506	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7507	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7508	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7509
7510	/* FIXME: use matrix-type input source selection */
7511	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7512	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7513	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7514	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7515	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7516	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7517	/* Input mixer2 */
7518	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7519	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7520	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7521	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7522	/* Input mixer3 */
7523	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7524	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7525	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7526	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7527
7528	{ }
7529};
7530
7531static struct hda_verb alc262_HP_BPC_init_verbs[] = {
7532	/*
7533	 * Unmute ADC0-2 and set the default input to mic-in
7534	 */
7535	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7536	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7537	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7538	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7539	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7540	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7541
7542	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7543	 * mixer widget
7544	 * Note: PASD motherboards uses the Line In 2 as the input for
7545	 * front panel mic (mic 2)
7546	 */
7547	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7548	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7549	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7550	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7551	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7552	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7553	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
7554        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
7555
7556	/*
7557	 * Set up output mixers (0x0c - 0x0e)
7558	 */
7559	/* set vol=0 to output mixers */
7560	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7561	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7562	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7563
7564	/* set up input amps for analog loopback */
7565	/* Amp Indices: DAC = 0, mixer = 1 */
7566	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7567	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7568	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7569	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7570	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7571	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7572
7573	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7574	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7575	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7576
7577	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7578	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7579
7580	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7581	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7582
7583	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7584	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7585        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7586	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7587	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7588
7589	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7590	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7591        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7592	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7593	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7594	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7595
7596
7597	/* FIXME: use matrix-type input source selection */
7598	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7599	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7600	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7601	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7602	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7603	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7604	/* Input mixer2 */
7605	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7606	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7607	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7608	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7609	/* Input mixer3 */
7610	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7611	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7612	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7613	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7614
7615	{ }
7616};
7617
7618static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
7619	/*
7620	 * Unmute ADC0-2 and set the default input to mic-in
7621	 */
7622	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7623	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7624	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7625	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7626	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7627	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7628
7629	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7630	 * mixer widget
7631	 * Note: PASD motherboards uses the Line In 2 as the input for front
7632	 * panel mic (mic 2)
7633	 */
7634	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7635	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7636	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7637	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7638	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7639	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7640	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
7641	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
7642	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
7643	/*
7644	 * Set up output mixers (0x0c - 0x0e)
7645	 */
7646	/* set vol=0 to output mixers */
7647	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7648	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7649	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7650
7651	/* set up input amps for analog loopback */
7652	/* Amp Indices: DAC = 0, mixer = 1 */
7653	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7654	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7655	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7656	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7657	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7658	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7659
7660
7661	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },	/* HP */
7662	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	/* Mono */
7663	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* rear MIC */
7664	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },	/* Line in */
7665	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* Front MIC */
7666	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	/* Line out */
7667	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },	/* CD in */
7668
7669	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7670	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7671
7672	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7673	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7674
7675	/* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
7676	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7677	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7678	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7679	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7680	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7681
7682	/* FIXME: use matrix-type input source selection */
7683	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7684	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7685	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
7686	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
7687	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
7688	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
7689	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
7690        /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
7691	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
7692	/* Input mixer2 */
7693	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7694	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7695	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7696	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7697	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7698        /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
7699	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
7700	/* Input mixer3 */
7701	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7702	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7703	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7704	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7705	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7706        /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
7707	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
7708
7709	{ }
7710};
7711
7712/* pcm configuration: identiacal with ALC880 */
7713#define alc262_pcm_analog_playback	alc880_pcm_analog_playback
7714#define alc262_pcm_analog_capture	alc880_pcm_analog_capture
7715#define alc262_pcm_digital_playback	alc880_pcm_digital_playback
7716#define alc262_pcm_digital_capture	alc880_pcm_digital_capture
7717
7718/*
7719 * BIOS auto configuration
7720 */
7721static int alc262_parse_auto_config(struct hda_codec *codec)
7722{
7723	struct alc_spec *spec = codec->spec;
7724	int err;
7725	static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
7726
7727	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
7728					   alc262_ignore);
7729	if (err < 0)
7730		return err;
7731	if (!spec->autocfg.line_outs)
7732		return 0; /* can't find valid BIOS pin config */
7733	err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
7734	if (err < 0)
7735		return err;
7736	err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
7737	if (err < 0)
7738		return err;
7739
7740	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
7741
7742	if (spec->autocfg.dig_out_pin)
7743		spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
7744	if (spec->autocfg.dig_in_pin)
7745		spec->dig_in_nid = ALC262_DIGIN_NID;
7746
7747	if (spec->kctl_alloc)
7748		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
7749
7750	spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
7751	spec->num_mux_defs = 1;
7752	spec->input_mux = &spec->private_imux;
7753
7754	return 1;
7755}
7756
7757#define alc262_auto_init_multi_out	alc882_auto_init_multi_out
7758#define alc262_auto_init_hp_out		alc882_auto_init_hp_out
7759#define alc262_auto_init_analog_input	alc882_auto_init_analog_input
7760
7761
7762/* init callback for auto-configuration model -- overriding the default init */
7763static void alc262_auto_init(struct hda_codec *codec)
7764{
7765	alc262_auto_init_multi_out(codec);
7766	alc262_auto_init_hp_out(codec);
7767	alc262_auto_init_analog_input(codec);
7768}
7769
7770/*
7771 * configuration and preset
7772 */
7773static const char *alc262_models[ALC262_MODEL_LAST] = {
7774	[ALC262_BASIC]		= "basic",
7775	[ALC262_HIPPO]		= "hippo",
7776	[ALC262_HIPPO_1]	= "hippo_1",
7777	[ALC262_FUJITSU]	= "fujitsu",
7778	[ALC262_HP_BPC]		= "hp-bpc",
7779	[ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
7780	[ALC262_BENQ_ED8]	= "benq",
7781	[ALC262_BENQ_T31]	= "benq-t31",
7782	[ALC262_SONY_ASSAMD]	= "sony-assamd",
7783	[ALC262_AUTO]		= "auto",
7784};
7785
7786static struct snd_pci_quirk alc262_cfg_tbl[] = {
7787	SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
7788	SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
7789	SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
7790	SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
7791	SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
7792	SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
7793	SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
7794	SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
7795	SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
7796	SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
7797	SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
7798	SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
7799	SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
7800	SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
7801	SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
7802	SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
7803	SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
7804	SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
7805	SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
7806	SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
7807	SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
7808	SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
7809	SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
7810	SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
7811	SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
7812	{}
7813};
7814
7815static struct alc_config_preset alc262_presets[] = {
7816	[ALC262_BASIC] = {
7817		.mixers = { alc262_base_mixer },
7818		.init_verbs = { alc262_init_verbs },
7819		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7820		.dac_nids = alc262_dac_nids,
7821		.hp_nid = 0x03,
7822		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7823		.channel_mode = alc262_modes,
7824		.input_mux = &alc262_capture_source,
7825	},
7826	[ALC262_HIPPO] = {
7827		.mixers = { alc262_base_mixer },
7828		.init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
7829		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7830		.dac_nids = alc262_dac_nids,
7831		.hp_nid = 0x03,
7832		.dig_out_nid = ALC262_DIGOUT_NID,
7833		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7834		.channel_mode = alc262_modes,
7835		.input_mux = &alc262_capture_source,
7836		.unsol_event = alc262_hippo_unsol_event,
7837	},
7838	[ALC262_HIPPO_1] = {
7839		.mixers = { alc262_hippo1_mixer },
7840		.init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
7841		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7842		.dac_nids = alc262_dac_nids,
7843		.hp_nid = 0x02,
7844		.dig_out_nid = ALC262_DIGOUT_NID,
7845		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7846		.channel_mode = alc262_modes,
7847		.input_mux = &alc262_capture_source,
7848		.unsol_event = alc262_hippo1_unsol_event,
7849	},
7850	[ALC262_FUJITSU] = {
7851		.mixers = { alc262_fujitsu_mixer },
7852		.init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
7853		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7854		.dac_nids = alc262_dac_nids,
7855		.hp_nid = 0x03,
7856		.dig_out_nid = ALC262_DIGOUT_NID,
7857		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7858		.channel_mode = alc262_modes,
7859		.input_mux = &alc262_fujitsu_capture_source,
7860		.unsol_event = alc262_fujitsu_unsol_event,
7861	},
7862	[ALC262_HP_BPC] = {
7863		.mixers = { alc262_HP_BPC_mixer },
7864		.init_verbs = { alc262_HP_BPC_init_verbs },
7865		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7866		.dac_nids = alc262_dac_nids,
7867		.hp_nid = 0x03,
7868		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7869		.channel_mode = alc262_modes,
7870		.input_mux = &alc262_HP_capture_source,
7871	},
7872	[ALC262_HP_BPC_D7000_WF] = {
7873		.mixers = { alc262_HP_BPC_WildWest_mixer },
7874		.init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
7875		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7876		.dac_nids = alc262_dac_nids,
7877		.hp_nid = 0x03,
7878		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7879		.channel_mode = alc262_modes,
7880		.input_mux = &alc262_HP_capture_source,
7881	},
7882	[ALC262_HP_BPC_D7000_WL] = {
7883		.mixers = { alc262_HP_BPC_WildWest_mixer,
7884			    alc262_HP_BPC_WildWest_option_mixer },
7885		.init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
7886		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7887		.dac_nids = alc262_dac_nids,
7888		.hp_nid = 0x03,
7889		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7890		.channel_mode = alc262_modes,
7891		.input_mux = &alc262_HP_capture_source,
7892	},
7893	[ALC262_BENQ_ED8] = {
7894		.mixers = { alc262_base_mixer },
7895		.init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
7896		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7897		.dac_nids = alc262_dac_nids,
7898		.hp_nid = 0x03,
7899		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7900		.channel_mode = alc262_modes,
7901		.input_mux = &alc262_capture_source,
7902	},
7903	[ALC262_SONY_ASSAMD] = {
7904		.mixers = { alc262_sony_mixer },
7905		.init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
7906		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7907		.dac_nids = alc262_dac_nids,
7908		.hp_nid = 0x02,
7909		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7910		.channel_mode = alc262_modes,
7911		.input_mux = &alc262_capture_source,
7912		.unsol_event = alc262_hippo_unsol_event,
7913	},
7914	[ALC262_BENQ_T31] = {
7915		.mixers = { alc262_benq_t31_mixer },
7916		.init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
7917		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
7918		.dac_nids = alc262_dac_nids,
7919		.hp_nid = 0x03,
7920		.num_channel_mode = ARRAY_SIZE(alc262_modes),
7921		.channel_mode = alc262_modes,
7922		.input_mux = &alc262_capture_source,
7923		.unsol_event = alc262_hippo_unsol_event,
7924	},
7925};
7926
7927static int patch_alc262(struct hda_codec *codec)
7928{
7929	struct alc_spec *spec;
7930	int board_config;
7931	int err;
7932
7933	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7934	if (spec == NULL)
7935		return -ENOMEM;
7936
7937	codec->spec = spec;
7938#if 0
7939	/* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
7940	 * under-run
7941	 */
7942	{
7943	int tmp;
7944	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
7945	tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
7946	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
7947	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
7948	}
7949#endif
7950
7951	board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
7952						  alc262_models,
7953						  alc262_cfg_tbl);
7954
7955	if (board_config < 0) {
7956		printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
7957		       "trying auto-probe from BIOS...\n");
7958		board_config = ALC262_AUTO;
7959	}
7960
7961	if (board_config == ALC262_AUTO) {
7962		/* automatic parse from the BIOS config */
7963		err = alc262_parse_auto_config(codec);
7964		if (err < 0) {
7965			alc_free(codec);
7966			return err;
7967		} else if (!err) {
7968			printk(KERN_INFO
7969			       "hda_codec: Cannot set up configuration "
7970			       "from BIOS.  Using base mode...\n");
7971			board_config = ALC262_BASIC;
7972		}
7973	}
7974
7975	if (board_config != ALC262_AUTO)
7976		setup_preset(spec, &alc262_presets[board_config]);
7977
7978	spec->stream_name_analog = "ALC262 Analog";
7979	spec->stream_analog_playback = &alc262_pcm_analog_playback;
7980	spec->stream_analog_capture = &alc262_pcm_analog_capture;
7981
7982	spec->stream_name_digital = "ALC262 Digital";
7983	spec->stream_digital_playback = &alc262_pcm_digital_playback;
7984	spec->stream_digital_capture = &alc262_pcm_digital_capture;
7985
7986	if (!spec->adc_nids && spec->input_mux) {
7987		/* check whether NID 0x07 is valid */
7988		unsigned int wcap = get_wcaps(codec, 0x07);
7989
7990		/* get type */
7991		wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7992		if (wcap != AC_WID_AUD_IN) {
7993			spec->adc_nids = alc262_adc_nids_alt;
7994			spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
7995			spec->mixers[spec->num_mixers] =
7996				alc262_capture_alt_mixer;
7997			spec->num_mixers++;
7998		} else {
7999			spec->adc_nids = alc262_adc_nids;
8000			spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
8001			spec->mixers[spec->num_mixers] = alc262_capture_mixer;
8002			spec->num_mixers++;
8003		}
8004	}
8005
8006	codec->patch_ops = alc_patch_ops;
8007	if (board_config == ALC262_AUTO)
8008		spec->init_hook = alc262_auto_init;
8009
8010	return 0;
8011}
8012
8013/*
8014 *  ALC268 channel source setting (2 channel)
8015 */
8016#define ALC268_DIGOUT_NID	ALC880_DIGOUT_NID
8017#define alc268_modes		alc260_modes
8018
8019static hda_nid_t alc268_dac_nids[2] = {
8020	/* front, hp */
8021	0x02, 0x03
8022};
8023
8024static hda_nid_t alc268_adc_nids[2] = {
8025	/* ADC0-1 */
8026	0x08, 0x07
8027};
8028
8029static hda_nid_t alc268_adc_nids_alt[1] = {
8030	/* ADC0 */
8031	0x08
8032};
8033
8034static struct snd_kcontrol_new alc268_base_mixer[] = {
8035	/* output mixer control */
8036	HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
8037	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8038	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
8039	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8040	{ }
8041};
8042
8043/*
8044 * generic initialization of ADC, input mixers and output mixers
8045 */
8046static struct hda_verb alc268_base_init_verbs[] = {
8047	/* Unmute DAC0-1 and set vol = 0 */
8048	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8049	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8050	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8051	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8052	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8053	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8054
8055	/*
8056	 * Set up output mixers (0x0c - 0x0e)
8057	 */
8058	/* set vol=0 to output mixers */
8059	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8060	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8061	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8062        {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
8063
8064	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8065	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8066
8067	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8068	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8069	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8070	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8071	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8072	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8073	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8074	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8075
8076	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8077	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8078	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8079	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8080	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8081	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8082	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8083	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8084
8085	/* FIXME: use matrix-type input source selection */
8086	/* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
8087	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8088	/* Input mixer2 */
8089	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8090	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8091	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8092	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8093
8094	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8095	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8096	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8097	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8098	{ }
8099};
8100
8101/*
8102 * generic initialization of ADC, input mixers and output mixers
8103 */
8104static struct hda_verb alc268_volume_init_verbs[] = {
8105	/* set output DAC */
8106	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8107	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8108	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8109	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8110
8111	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8112	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8113	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8114	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8115	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8116
8117	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8118	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8119	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8120	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8121	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8122
8123	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8124	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8125	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8126	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8127
8128	/* set PCBEEP vol = 0 */
8129	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
8130
8131	{ }
8132};
8133
8134#define alc268_mux_enum_info alc_mux_enum_info
8135#define alc268_mux_enum_get alc_mux_enum_get
8136
8137static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
8138			       struct snd_ctl_elem_value *ucontrol)
8139{
8140	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8141	struct alc_spec *spec = codec->spec;
8142	const struct hda_input_mux *imux = spec->input_mux;
8143	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
8144	static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
8145	hda_nid_t nid = capture_mixers[adc_idx];
8146	unsigned int *cur_val = &spec->cur_mux[adc_idx];
8147	unsigned int i, idx;
8148
8149	idx = ucontrol->value.enumerated.item[0];
8150	if (idx >= imux->num_items)
8151		idx = imux->num_items - 1;
8152	if (*cur_val == idx && !codec->in_resume)
8153		return 0;
8154	for (i = 0; i < imux->num_items; i++) {
8155		unsigned int v = (i == idx) ? 0x7000 : 0x7080;
8156		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8157				    v | (imux->items[i].index << 8));
8158                snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
8159				    idx );
8160	}
8161	*cur_val = idx;
8162	return 1;
8163}
8164
8165static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
8166	HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8167	HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8168	{
8169		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8170		/* The multiple "Capture Source" controls confuse alsamixer
8171		 * So call somewhat different..
8172		 * FIXME: the controls appear in the "playback" view!
8173		 */
8174		/* .name = "Capture Source", */
8175		.name = "Input Source",
8176		.count = 1,
8177		.info = alc268_mux_enum_info,
8178		.get = alc268_mux_enum_get,
8179		.put = alc268_mux_enum_put,
8180	},
8181	{ } /* end */
8182};
8183
8184static struct snd_kcontrol_new alc268_capture_mixer[] = {
8185	HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8186	HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8187	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
8188	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
8189	{
8190		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8191		/* The multiple "Capture Source" controls confuse alsamixer
8192		 * So call somewhat different..
8193		 * FIXME: the controls appear in the "playback" view!
8194		 */
8195		/* .name = "Capture Source", */
8196		.name = "Input Source",
8197		.count = 2,
8198		.info = alc268_mux_enum_info,
8199		.get = alc268_mux_enum_get,
8200		.put = alc268_mux_enum_put,
8201	},
8202	{ } /* end */
8203};
8204
8205static struct hda_input_mux alc268_capture_source = {
8206	.num_items = 4,
8207	.items = {
8208		{ "Mic", 0x0 },
8209		{ "Front Mic", 0x1 },
8210		{ "Line", 0x2 },
8211		{ "CD", 0x3 },
8212	},
8213};
8214
8215/* create input playback/capture controls for the given pin */
8216static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
8217				    const char *ctlname, int idx)
8218{
8219	char name[32];
8220	int err;
8221
8222	sprintf(name, "%s Playback Volume", ctlname);
8223	if (nid == 0x14) {
8224		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8225				  HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
8226						      HDA_OUTPUT));
8227		if (err < 0)
8228			return err;
8229	} else if (nid == 0x15) {
8230		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8231				  HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
8232						      HDA_OUTPUT));
8233		if (err < 0)
8234			return err;
8235	} else
8236		return -1;
8237	sprintf(name, "%s Playback Switch", ctlname);
8238	err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8239			  HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
8240	if (err < 0)
8241		return err;
8242	return 0;
8243}
8244
8245/* add playback controls from the parsed DAC table */
8246static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
8247					     const struct auto_pin_cfg *cfg)
8248{
8249	hda_nid_t nid;
8250	int err;
8251
8252	spec->multiout.num_dacs = 2;	/* only use one dac */
8253	spec->multiout.dac_nids = spec->private_dac_nids;
8254	spec->multiout.dac_nids[0] = 2;
8255	spec->multiout.dac_nids[1] = 3;
8256
8257	nid = cfg->line_out_pins[0];
8258	if (nid)
8259		alc268_new_analog_output(spec, nid, "Front", 0);
8260
8261	nid = cfg->speaker_pins[0];
8262	if (nid == 0x1d) {
8263		err = add_control(spec, ALC_CTL_WIDGET_VOL,
8264				  "Speaker Playback Volume",
8265				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
8266		if (err < 0)
8267			return err;
8268	}
8269	nid = cfg->hp_pins[0];
8270	if (nid)
8271		alc268_new_analog_output(spec, nid, "Headphone", 0);
8272
8273	nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
8274	if (nid == 0x16) {
8275		err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8276				  "Mono Playback Switch",
8277				  HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
8278		if (err < 0)
8279			return err;
8280	}
8281	return 0;
8282}
8283
8284/* create playback/capture controls for input pins */
8285static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
8286						const struct auto_pin_cfg *cfg)
8287{
8288	struct hda_input_mux *imux = &spec->private_imux;
8289	int i, idx1;
8290
8291	for (i = 0; i < AUTO_PIN_LAST; i++) {
8292		switch(cfg->input_pins[i]) {
8293		case 0x18:
8294			idx1 = 0;	/* Mic 1 */
8295			break;
8296		case 0x19:
8297			idx1 = 1;	/* Mic 2 */
8298			break;
8299		case 0x1a:
8300			idx1 = 2;	/* Line In */
8301			break;
8302		case 0x1c:
8303			idx1 = 3;	/* CD */
8304			break;
8305		default:
8306			continue;
8307		}
8308		imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
8309		imux->items[imux->num_items].index = idx1;
8310		imux->num_items++;
8311	}
8312	return 0;
8313}
8314
8315static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
8316{
8317	struct alc_spec *spec = codec->spec;
8318	hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
8319	hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
8320	hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
8321	unsigned int	dac_vol1, dac_vol2;
8322
8323	if (speaker_nid) {
8324		snd_hda_codec_write(codec, speaker_nid, 0,
8325				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
8326		snd_hda_codec_write(codec, 0x0f, 0,
8327				    AC_VERB_SET_AMP_GAIN_MUTE,
8328				    AMP_IN_UNMUTE(1));
8329		snd_hda_codec_write(codec, 0x10, 0,
8330				    AC_VERB_SET_AMP_GAIN_MUTE,
8331				    AMP_IN_UNMUTE(1));
8332	} else {
8333		snd_hda_codec_write(codec, 0x0f, 0,
8334				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8335		snd_hda_codec_write(codec, 0x10, 0,
8336				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8337	}
8338
8339	dac_vol1 = dac_vol2 = 0xb000 | 0x40;	/* set max volume  */
8340	if (line_nid == 0x14)
8341		dac_vol2 = AMP_OUT_ZERO;
8342	else if (line_nid == 0x15)
8343		dac_vol1 = AMP_OUT_ZERO;
8344	if (hp_nid == 0x14)
8345		dac_vol2 = AMP_OUT_ZERO;
8346	else if (hp_nid == 0x15)
8347		dac_vol1 = AMP_OUT_ZERO;
8348	if (line_nid != 0x16 || hp_nid != 0x16 ||
8349	    spec->autocfg.line_out_pins[1] != 0x16 ||
8350	    spec->autocfg.line_out_pins[2] != 0x16)
8351		dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
8352
8353	snd_hda_codec_write(codec, 0x02, 0,
8354			    AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
8355	snd_hda_codec_write(codec, 0x03, 0,
8356			    AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
8357}
8358
8359/* pcm configuration: identiacal with ALC880 */
8360#define alc268_pcm_analog_playback	alc880_pcm_analog_playback
8361#define alc268_pcm_analog_capture	alc880_pcm_analog_capture
8362#define alc268_pcm_digital_playback	alc880_pcm_digital_playback
8363
8364/*
8365 * BIOS auto configuration
8366 */
8367static int alc268_parse_auto_config(struct hda_codec *codec)
8368{
8369	struct alc_spec *spec = codec->spec;
8370	int err;
8371	static hda_nid_t alc268_ignore[] = { 0 };
8372
8373	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8374					   alc268_ignore);
8375	if (err < 0)
8376		return err;
8377	if (!spec->autocfg.line_outs)
8378		return 0; /* can't find valid BIOS pin config */
8379
8380	err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
8381	if (err < 0)
8382		return err;
8383	err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
8384	if (err < 0)
8385		return err;
8386
8387	spec->multiout.max_channels = 2;
8388
8389	/* digital only support output */
8390	if (spec->autocfg.dig_out_pin)
8391		spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
8392
8393	if (spec->kctl_alloc)
8394		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8395
8396	spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
8397	spec->num_mux_defs = 1;
8398	spec->input_mux = &spec->private_imux;
8399
8400	return 1;
8401}
8402
8403#define alc268_auto_init_multi_out	alc882_auto_init_multi_out
8404#define alc268_auto_init_hp_out		alc882_auto_init_hp_out
8405#define alc268_auto_init_analog_input	alc882_auto_init_analog_input
8406
8407/* init callback for auto-configuration model -- overriding the default init */
8408static void alc268_auto_init(struct hda_codec *codec)
8409{
8410	alc268_auto_init_multi_out(codec);
8411	alc268_auto_init_hp_out(codec);
8412	alc268_auto_init_mono_speaker_out(codec);
8413	alc268_auto_init_analog_input(codec);
8414}
8415
8416/*
8417 * configuration and preset
8418 */
8419static const char *alc268_models[ALC268_MODEL_LAST] = {
8420	[ALC268_3ST]		= "3stack",
8421	[ALC268_AUTO]		= "auto",
8422};
8423
8424static struct snd_pci_quirk alc268_cfg_tbl[] = {
8425	SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
8426	{}
8427};
8428
8429static struct alc_config_preset alc268_presets[] = {
8430	[ALC268_3ST] = {
8431		.mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
8432		.init_verbs = { alc268_base_init_verbs },
8433		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
8434		.dac_nids = alc268_dac_nids,
8435                .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
8436                .adc_nids = alc268_adc_nids_alt,
8437		.hp_nid = 0x03,
8438		.dig_out_nid = ALC268_DIGOUT_NID,
8439		.num_channel_mode = ARRAY_SIZE(alc268_modes),
8440		.channel_mode = alc268_modes,
8441		.input_mux = &alc268_capture_source,
8442	},
8443};
8444
8445static int patch_alc268(struct hda_codec *codec)
8446{
8447	struct alc_spec *spec;
8448	int board_config;
8449	int err;
8450
8451	spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
8452	if (spec == NULL)
8453		return -ENOMEM;
8454
8455	codec->spec = spec;
8456
8457	board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
8458						  alc268_models,
8459						  alc268_cfg_tbl);
8460
8461	if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
8462		printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
8463		       "trying auto-probe from BIOS...\n");
8464		board_config = ALC268_AUTO;
8465	}
8466
8467	if (board_config == ALC268_AUTO) {
8468		/* automatic parse from the BIOS config */
8469		err = alc268_parse_auto_config(codec);
8470		if (err < 0) {
8471			alc_free(codec);
8472			return err;
8473		} else if (!err) {
8474			printk(KERN_INFO
8475			       "hda_codec: Cannot set up configuration "
8476			       "from BIOS.  Using base mode...\n");
8477			board_config = ALC268_3ST;
8478		}
8479	}
8480
8481	if (board_config != ALC268_AUTO)
8482		setup_preset(spec, &alc268_presets[board_config]);
8483
8484	spec->stream_name_analog = "ALC268 Analog";
8485	spec->stream_analog_playback = &alc268_pcm_analog_playback;
8486	spec->stream_analog_capture = &alc268_pcm_analog_capture;
8487
8488	spec->stream_name_digital = "ALC268 Digital";
8489	spec->stream_digital_playback = &alc268_pcm_digital_playback;
8490
8491	if (board_config == ALC268_AUTO) {
8492		if (!spec->adc_nids && spec->input_mux) {
8493			/* check whether NID 0x07 is valid */
8494			unsigned int wcap = get_wcaps(codec, 0x07);
8495
8496			/* get type */
8497			wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8498			if (wcap != AC_WID_AUD_IN) {
8499				spec->adc_nids = alc268_adc_nids_alt;
8500				spec->num_adc_nids =
8501					ARRAY_SIZE(alc268_adc_nids_alt);
8502				spec->mixers[spec->num_mixers] =
8503					alc268_capture_alt_mixer;
8504				spec->num_mixers++;
8505			} else {
8506				spec->adc_nids = alc268_adc_nids;
8507				spec->num_adc_nids =
8508					ARRAY_SIZE(alc268_adc_nids);
8509				spec->mixers[spec->num_mixers] =
8510					alc268_capture_mixer;
8511				spec->num_mixers++;
8512			}
8513		}
8514	}
8515	codec->patch_ops = alc_patch_ops;
8516	if (board_config == ALC268_AUTO)
8517		spec->init_hook = alc268_auto_init;
8518
8519	return 0;
8520}
8521
8522/*
8523 *  ALC861 channel source setting (2/6 channel selection for 3-stack)
8524 */
8525
8526/*
8527 * set the path ways for 2 channel output
8528 * need to set the codec line out and mic 1 pin widgets to inputs
8529 */
8530static struct hda_verb alc861_threestack_ch2_init[] = {
8531	/* set pin widget 1Ah (line in) for input */
8532	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8533	/* set pin widget 18h (mic1/2) for input, for mic also enable
8534	 * the vref
8535	 */
8536	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8537
8538	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
8539#if 0
8540	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8541	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
8542#endif
8543	{ } /* end */
8544};
8545/*
8546 * 6ch mode
8547 * need to set the codec line out and mic 1 pin widgets to outputs
8548 */
8549static struct hda_verb alc861_threestack_ch6_init[] = {
8550	/* set pin widget 1Ah (line in) for output (Back Surround)*/
8551	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8552	/* set pin widget 18h (mic1) for output (CLFE)*/
8553	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8554
8555	{ 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
8556	{ 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
8557
8558	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
8559#if 0
8560	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8561	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
8562#endif
8563	{ } /* end */
8564};
8565
8566static struct hda_channel_mode alc861_threestack_modes[2] = {
8567	{ 2, alc861_threestack_ch2_init },
8568	{ 6, alc861_threestack_ch6_init },
8569};
8570/* Set mic1 as input and unmute the mixer */
8571static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
8572	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8573	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8574	{ } /* end */
8575};
8576/* Set mic1 as output and mute mixer */
8577static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
8578	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8579	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8580	{ } /* end */
8581};
8582
8583static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
8584	{ 2, alc861_uniwill_m31_ch2_init },
8585	{ 4, alc861_uniwill_m31_ch4_init },
8586};
8587
8588/* Set mic1 and line-in as input and unmute the mixer */
8589static struct hda_verb alc861_asus_ch2_init[] = {
8590	/* set pin widget 1Ah (line in) for input */
8591	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8592	/* set pin widget 18h (mic1/2) for input, for mic also enable
8593	 * the vref
8594	 */
8595	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8596
8597	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
8598#if 0
8599	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8600	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
8601#endif
8602	{ } /* end */
8603};
8604/* Set mic1 nad line-in as output and mute mixer */
8605static struct hda_verb alc861_asus_ch6_init[] = {
8606	/* set pin widget 1Ah (line in) for output (Back Surround)*/
8607	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8608	/* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
8609	/* set pin widget 18h (mic1) for output (CLFE)*/
8610	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8611	/* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
8612	{ 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
8613	{ 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
8614
8615	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
8616#if 0
8617	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8618	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
8619#endif
8620	{ } /* end */
8621};
8622
8623static struct hda_channel_mode alc861_asus_modes[2] = {
8624	{ 2, alc861_asus_ch2_init },
8625	{ 6, alc861_asus_ch6_init },
8626};
8627
8628/* patch-ALC861 */
8629
8630static struct snd_kcontrol_new alc861_base_mixer[] = {
8631        /* output mixer control */
8632	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8633	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8634	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8635	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8636	HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
8637
8638        /*Input mixer control */
8639	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8640	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8641	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8642	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8643	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8644	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8645	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8646	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8647	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8648	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8649
8650        /* Capture mixer control */
8651	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8652	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8653	{
8654		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8655		.name = "Capture Source",
8656		.count = 1,
8657		.info = alc_mux_enum_info,
8658		.get = alc_mux_enum_get,
8659		.put = alc_mux_enum_put,
8660	},
8661	{ } /* end */
8662};
8663
8664static struct snd_kcontrol_new alc861_3ST_mixer[] = {
8665        /* output mixer control */
8666	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8667	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8668	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8669	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8670	/*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
8671
8672	/* Input mixer control */
8673	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8674	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8675	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8676	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8677	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8678	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8679	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8680	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8681	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8682	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8683
8684	/* Capture mixer control */
8685	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8686	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8687	{
8688		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8689		.name = "Capture Source",
8690		.count = 1,
8691		.info = alc_mux_enum_info,
8692		.get = alc_mux_enum_get,
8693		.put = alc_mux_enum_put,
8694	},
8695	{
8696		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8697		.name = "Channel Mode",
8698		.info = alc_ch_mode_info,
8699		.get = alc_ch_mode_get,
8700		.put = alc_ch_mode_put,
8701                .private_value = ARRAY_SIZE(alc861_threestack_modes),
8702	},
8703	{ } /* end */
8704};
8705
8706static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
8707        /* output mixer control */
8708	HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8709	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8710	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8711
8712        /*Capture mixer control */
8713	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8714	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8715	{
8716		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8717		.name = "Capture Source",
8718		.count = 1,
8719		.info = alc_mux_enum_info,
8720		.get = alc_mux_enum_get,
8721		.put = alc_mux_enum_put,
8722	},
8723
8724	{ } /* end */
8725};
8726
8727static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
8728        /* output mixer control */
8729	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8730	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8731	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8732	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8733	/*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
8734
8735	/* Input mixer control */
8736	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8737	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8738	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8739	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8740	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8741	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8742	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8743	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8744	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8745	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8746
8747	/* Capture mixer control */
8748	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8749	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8750	{
8751		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8752		.name = "Capture Source",
8753		.count = 1,
8754		.info = alc_mux_enum_info,
8755		.get = alc_mux_enum_get,
8756		.put = alc_mux_enum_put,
8757	},
8758	{
8759		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8760		.name = "Channel Mode",
8761		.info = alc_ch_mode_info,
8762		.get = alc_ch_mode_get,
8763		.put = alc_ch_mode_put,
8764                .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
8765	},
8766	{ } /* end */
8767};
8768
8769static struct snd_kcontrol_new alc861_asus_mixer[] = {
8770        /* output mixer control */
8771	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8772	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8773	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8774	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8775	HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
8776
8777	/* Input mixer control */
8778	HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8779	HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8780	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8781	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8782	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8783	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8784	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8785	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8786	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8787	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
8788
8789	/* Capture mixer control */
8790	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8791	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8792	{
8793		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8794		.name = "Capture Source",
8795		.count = 1,
8796		.info = alc_mux_enum_info,
8797		.get = alc_mux_enum_get,
8798		.put = alc_mux_enum_put,
8799	},
8800	{
8801		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8802		.name = "Channel Mode",
8803		.info = alc_ch_mode_info,
8804		.get = alc_ch_mode_get,
8805		.put = alc_ch_mode_put,
8806                .private_value = ARRAY_SIZE(alc861_asus_modes),
8807	},
8808	{ }
8809};
8810
8811/* additional mixer */
8812static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
8813	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8814	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8815	HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
8816	HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
8817	{ }
8818};
8819
8820/*
8821 * generic initialization of ADC, input mixers and output mixers
8822 */
8823static struct hda_verb alc861_base_init_verbs[] = {
8824	/*
8825	 * Unmute ADC0 and set the default input to mic-in
8826	 */
8827	/* port-A for surround (rear panel) */
8828	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8829	{ 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
8830	/* port-B for mic-in (rear panel) with vref */
8831	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8832	/* port-C for line-in (rear panel) */
8833	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8834	/* port-D for Front */
8835	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8836	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8837	/* port-E for HP out (front panel) */
8838	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
8839	/* route front PCM to HP */
8840	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8841	/* port-F for mic-in (front panel) with vref */
8842	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8843	/* port-G for CLFE (rear panel) */
8844	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8845	{ 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8846	/* port-H for side (rear panel) */
8847	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8848	{ 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
8849	/* CD-in */
8850	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8851	/* route front mic to ADC1*/
8852	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8853	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8854
8855	/* Unmute DAC0~3 & spdif out*/
8856	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8857	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8858	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8859	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8860	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8861
8862	/* Unmute Mixer 14 (mic) 1c (Line in)*/
8863	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8864        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8865	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8866        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8867
8868	/* Unmute Stereo Mixer 15 */
8869	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8870	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8871	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8872	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8873
8874	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8875	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8876	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8877	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8878	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8879	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8880	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8881	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8882	/* hp used DAC 3 (Front) */
8883	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8884        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8885
8886	{ }
8887};
8888
8889static struct hda_verb alc861_threestack_init_verbs[] = {
8890	/*
8891	 * Unmute ADC0 and set the default input to mic-in
8892	 */
8893	/* port-A for surround (rear panel) */
8894	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8895	/* port-B for mic-in (rear panel) with vref */
8896	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8897	/* port-C for line-in (rear panel) */
8898	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8899	/* port-D for Front */
8900	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8901	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8902	/* port-E for HP out (front panel) */
8903	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
8904	/* route front PCM to HP */
8905	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8906	/* port-F for mic-in (front panel) with vref */
8907	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8908	/* port-G for CLFE (rear panel) */
8909	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8910	/* port-H for side (rear panel) */
8911	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8912	/* CD-in */
8913	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8914	/* route front mic to ADC1*/
8915	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8916	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8917	/* Unmute DAC0~3 & spdif out*/
8918	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8919	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8920	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8921	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8922	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8923
8924	/* Unmute Mixer 14 (mic) 1c (Line in)*/
8925	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8926        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8927	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8928        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8929
8930	/* Unmute Stereo Mixer 15 */
8931	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8932	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8933	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8934	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8935
8936	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8937	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8938	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8939	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8940	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8941	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8942	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8943	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8944	/* hp used DAC 3 (Front) */
8945	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8946        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8947	{ }
8948};
8949
8950static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
8951	/*
8952	 * Unmute ADC0 and set the default input to mic-in
8953	 */
8954	/* port-A for surround (rear panel) */
8955	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8956	/* port-B for mic-in (rear panel) with vref */
8957	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8958	/* port-C for line-in (rear panel) */
8959	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8960	/* port-D for Front */
8961	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8962	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8963	/* port-E for HP out (front panel) */
8964	/* this has to be set to VREF80 */
8965	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8966	/* route front PCM to HP */
8967	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8968	/* port-F for mic-in (front panel) with vref */
8969	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8970	/* port-G for CLFE (rear panel) */
8971	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8972	/* port-H for side (rear panel) */
8973	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8974	/* CD-in */
8975	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8976	/* route front mic to ADC1*/
8977	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8978	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8979	/* Unmute DAC0~3 & spdif out*/
8980	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8981	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8982	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8983	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8984	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8985
8986	/* Unmute Mixer 14 (mic) 1c (Line in)*/
8987	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8988        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8989	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8990        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8991
8992	/* Unmute Stereo Mixer 15 */
8993	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8994	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8995	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8996	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8997
8998	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8999	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9000	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9001	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9002	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9003	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9004	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9005	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9006	/* hp used DAC 3 (Front) */
9007	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9008        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9009	{ }
9010};
9011
9012static struct hda_verb alc861_asus_init_verbs[] = {
9013	/*
9014	 * Unmute ADC0 and set the default input to mic-in
9015	 */
9016	/* port-A for surround (rear panel)
9017	 * according to codec#0 this is the HP jack
9018	 */
9019	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
9020	/* route front PCM to HP */
9021	{ 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
9022	/* port-B for mic-in (rear panel) with vref */
9023	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9024	/* port-C for line-in (rear panel) */
9025	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9026	/* port-D for Front */
9027	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9028	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9029	/* port-E for HP out (front panel) */
9030	/* this has to be set to VREF80 */
9031	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9032	/* route front PCM to HP */
9033	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9034	/* port-F for mic-in (front panel) with vref */
9035	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9036	/* port-G for CLFE (rear panel) */
9037	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9038	/* port-H for side (rear panel) */
9039	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9040	/* CD-in */
9041	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9042	/* route front mic to ADC1*/
9043	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9044	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9045	/* Unmute DAC0~3 & spdif out*/
9046	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9047	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9048	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9049	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9050	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9051	/* Unmute Mixer 14 (mic) 1c (Line in)*/
9052	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9053        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9054	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9055        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9056
9057	/* Unmute Stereo Mixer 15 */
9058	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9059	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9060	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9061	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9062
9063	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9064	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9065	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9066	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9067	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9068	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9069	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9070	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9071	/* hp used DAC 3 (Front) */
9072	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9073	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9074	{ }
9075};
9076
9077/* additional init verbs for ASUS laptops */
9078static struct hda_verb alc861_asus_laptop_init_verbs[] = {
9079	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
9080	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
9081	{ }
9082};
9083
9084/*
9085 * generic initialization of ADC, input mixers and output mixers
9086 */
9087static struct hda_verb alc861_auto_init_verbs[] = {
9088	/*
9089	 * Unmute ADC0 and set the default input to mic-in
9090	 */
9091	/* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
9092	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9093
9094	/* Unmute DAC0~3 & spdif out*/
9095	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9096	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9097	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9098	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9099	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9100
9101	/* Unmute Mixer 14 (mic) 1c (Line in)*/
9102	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9103	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9104	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9105	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9106
9107	/* Unmute Stereo Mixer 15 */
9108	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9109	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9110	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9111	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
9112
9113	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9114	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9115	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9116	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9117	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9118	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9119	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9120	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9121
9122	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9123	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9124	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9125	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9126	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9127	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9128	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9129	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9130
9131	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},	/* set Mic 1 */
9132
9133	{ }
9134};
9135
9136static struct hda_verb alc861_toshiba_init_verbs[] = {
9137	{0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9138
9139	{ }
9140};
9141
9142/* toggle speaker-output according to the hp-jack state */
9143static void alc861_toshiba_automute(struct hda_codec *codec)
9144{
9145	unsigned int present;
9146
9147	present = snd_hda_codec_read(codec, 0x0f, 0,
9148				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9149	snd_hda_codec_amp_update(codec, 0x16, 0, HDA_INPUT, 0,
9150				 0x80, present ? 0x80 : 0);
9151	snd_hda_codec_amp_update(codec, 0x16, 1, HDA_INPUT, 0,
9152				 0x80, present ? 0x80 : 0);
9153	snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_INPUT, 3,
9154				 0x80, present ? 0 : 0x80);
9155	snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_INPUT, 3,
9156				 0x80, present ? 0 : 0x80);
9157}
9158
9159static void alc861_toshiba_unsol_event(struct hda_codec *codec,
9160				       unsigned int res)
9161{
9162	if ((res >> 26) == ALC880_HP_EVENT)
9163		alc861_toshiba_automute(codec);
9164}
9165
9166/* pcm configuration: identiacal with ALC880 */
9167#define alc861_pcm_analog_playback	alc880_pcm_analog_playback
9168#define alc861_pcm_analog_capture	alc880_pcm_analog_capture
9169#define alc861_pcm_digital_playback	alc880_pcm_digital_playback
9170#define alc861_pcm_digital_capture	alc880_pcm_digital_capture
9171
9172
9173#define ALC861_DIGOUT_NID	0x07
9174
9175static struct hda_channel_mode alc861_8ch_modes[1] = {
9176	{ 8, NULL }
9177};
9178
9179static hda_nid_t alc861_dac_nids[4] = {
9180	/* front, surround, clfe, side */
9181	0x03, 0x06, 0x05, 0x04
9182};
9183
9184static hda_nid_t alc660_dac_nids[3] = {
9185	/* front, clfe, surround */
9186	0x03, 0x05, 0x06
9187};
9188
9189static hda_nid_t alc861_adc_nids[1] = {
9190	/* ADC0-2 */
9191	0x08,
9192};
9193
9194static struct hda_input_mux alc861_capture_source = {
9195	.num_items = 5,
9196	.items = {
9197		{ "Mic", 0x0 },
9198		{ "Front Mic", 0x3 },
9199		{ "Line", 0x1 },
9200		{ "CD", 0x4 },
9201		{ "Mixer", 0x5 },
9202	},
9203};
9204
9205/* fill in the dac_nids table from the parsed pin configuration */
9206static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
9207				     const struct auto_pin_cfg *cfg)
9208{
9209	int i;
9210	hda_nid_t nid;
9211
9212	spec->multiout.dac_nids = spec->private_dac_nids;
9213	for (i = 0; i < cfg->line_outs; i++) {
9214		nid = cfg->line_out_pins[i];
9215		if (nid) {
9216			if (i >= ARRAY_SIZE(alc861_dac_nids))
9217				continue;
9218			spec->multiout.dac_nids[i] = alc861_dac_nids[i];
9219		}
9220	}
9221	spec->multiout.num_dacs = cfg->line_outs;
9222	return 0;
9223}
9224
9225/* add playback controls from the parsed DAC table */
9226static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
9227					     const struct auto_pin_cfg *cfg)
9228{
9229	char name[32];
9230	static const char *chname[4] = {
9231		"Front", "Surround", NULL /*CLFE*/, "Side"
9232	};
9233	hda_nid_t nid;
9234	int i, idx, err;
9235
9236	for (i = 0; i < cfg->line_outs; i++) {
9237		nid = spec->multiout.dac_nids[i];
9238		if (!nid)
9239			continue;
9240		if (nid == 0x05) {
9241			/* Center/LFE */
9242			err = add_control(spec, ALC_CTL_BIND_MUTE,
9243					  "Center Playback Switch",
9244					  HDA_COMPOSE_AMP_VAL(nid, 1, 0,
9245							      HDA_OUTPUT));
9246			if (err < 0)
9247				return err;
9248			err = add_control(spec, ALC_CTL_BIND_MUTE,
9249					  "LFE Playback Switch",
9250					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9251							      HDA_OUTPUT));
9252			if (err < 0)
9253				return err;
9254		} else {
9255			for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
9256			     idx++)
9257				if (nid == alc861_dac_nids[idx])
9258					break;
9259			sprintf(name, "%s Playback Switch", chname[idx]);
9260			err = add_control(spec, ALC_CTL_BIND_MUTE, name,
9261					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9262							      HDA_OUTPUT));
9263			if (err < 0)
9264				return err;
9265		}
9266	}
9267	return 0;
9268}
9269
9270static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
9271{
9272	int err;
9273	hda_nid_t nid;
9274
9275	if (!pin)
9276		return 0;
9277
9278	if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
9279		nid = 0x03;
9280		err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9281				  "Headphone Playback Switch",
9282				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9283		if (err < 0)
9284			return err;
9285		spec->multiout.hp_nid = nid;
9286	}
9287	return 0;
9288}
9289
9290/* create playback/capture controls for input pins */
9291static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
9292						const struct auto_pin_cfg *cfg)
9293{
9294	struct hda_input_mux *imux = &spec->private_imux;
9295	int i, err, idx, idx1;
9296
9297	for (i = 0; i < AUTO_PIN_LAST; i++) {
9298		switch (cfg->input_pins[i]) {
9299		case 0x0c:
9300			idx1 = 1;
9301			idx = 2;	/* Line In */
9302			break;
9303		case 0x0f:
9304			idx1 = 2;
9305			idx = 2;	/* Line In */
9306			break;
9307		case 0x0d:
9308			idx1 = 0;
9309			idx = 1;	/* Mic In */
9310			break;
9311		case 0x10:
9312			idx1 = 3;
9313			idx = 1;	/* Mic In */
9314			break;
9315		case 0x11:
9316			idx1 = 4;
9317			idx = 0;	/* CD */
9318			break;
9319		default:
9320			continue;
9321		}
9322
9323		err = new_analog_input(spec, cfg->input_pins[i],
9324				       auto_pin_cfg_labels[i], idx, 0x15);
9325		if (err < 0)
9326			return err;
9327
9328		imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9329		imux->items[imux->num_items].index = idx1;
9330		imux->num_items++;
9331	}
9332	return 0;
9333}
9334
9335static struct snd_kcontrol_new alc861_capture_mixer[] = {
9336	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9337	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9338
9339	{
9340		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9341		/* The multiple "Capture Source" controls confuse alsamixer
9342		 * So call somewhat different..
9343		 *FIXME: the controls appear in the "playback" view!
9344		 */
9345		/* .name = "Capture Source", */
9346		.name = "Input Source",
9347		.count = 1,
9348		.info = alc_mux_enum_info,
9349		.get = alc_mux_enum_get,
9350		.put = alc_mux_enum_put,
9351	},
9352	{ } /* end */
9353};
9354
9355static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
9356					      hda_nid_t nid,
9357					      int pin_type, int dac_idx)
9358{
9359	/* set as output */
9360
9361	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9362			    pin_type);
9363	snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9364			    AMP_OUT_UNMUTE);
9365
9366}
9367
9368static void alc861_auto_init_multi_out(struct hda_codec *codec)
9369{
9370	struct alc_spec *spec = codec->spec;
9371	int i;
9372
9373	alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
9374	for (i = 0; i < spec->autocfg.line_outs; i++) {
9375		hda_nid_t nid = spec->autocfg.line_out_pins[i];
9376		int pin_type = get_pin_type(spec->autocfg.line_out_type);
9377		if (nid)
9378			alc861_auto_set_output_and_unmute(codec, nid, pin_type,
9379							  spec->multiout.dac_nids[i]);
9380	}
9381}
9382
9383static void alc861_auto_init_hp_out(struct hda_codec *codec)
9384{
9385	struct alc_spec *spec = codec->spec;
9386	hda_nid_t pin;
9387
9388	pin = spec->autocfg.hp_pins[0];
9389	if (pin) /* connect to front */
9390		alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
9391						  spec->multiout.dac_nids[0]);
9392}
9393
9394static void alc861_auto_init_analog_input(struct hda_codec *codec)
9395{
9396	struct alc_spec *spec = codec->spec;
9397	int i;
9398
9399	for (i = 0; i < AUTO_PIN_LAST; i++) {
9400		hda_nid_t nid = spec->autocfg.input_pins[i];
9401		if (nid >= 0x0c && nid <= 0x11) {
9402			snd_hda_codec_write(codec, nid, 0,
9403					    AC_VERB_SET_PIN_WIDGET_CONTROL,
9404					    i <= AUTO_PIN_FRONT_MIC ?
9405					    PIN_VREF80 : PIN_IN);
9406		}
9407	}
9408}
9409
9410/* parse the BIOS configuration and set up the alc_spec */
9411/* return 1 if successful, 0 if the proper config is not found,
9412 * or a negative error code
9413 */
9414static int alc861_parse_auto_config(struct hda_codec *codec)
9415{
9416	struct alc_spec *spec = codec->spec;
9417	int err;
9418	static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
9419
9420	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9421					   alc861_ignore);
9422	if (err < 0)
9423		return err;
9424	if (!spec->autocfg.line_outs)
9425		return 0; /* can't find valid BIOS pin config */
9426
9427	err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
9428	if (err < 0)
9429		return err;
9430	err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
9431	if (err < 0)
9432		return err;
9433	err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
9434	if (err < 0)
9435		return err;
9436	err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
9437	if (err < 0)
9438		return err;
9439
9440	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9441
9442	if (spec->autocfg.dig_out_pin)
9443		spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
9444
9445	if (spec->kctl_alloc)
9446		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9447
9448	spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
9449
9450	spec->num_mux_defs = 1;
9451	spec->input_mux = &spec->private_imux;
9452
9453	spec->adc_nids = alc861_adc_nids;
9454	spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
9455	spec->mixers[spec->num_mixers] = alc861_capture_mixer;
9456	spec->num_mixers++;
9457
9458	return 1;
9459}
9460
9461/* additional initialization for auto-configuration model */
9462static void alc861_auto_init(struct hda_codec *codec)
9463{
9464	alc861_auto_init_multi_out(codec);
9465	alc861_auto_init_hp_out(codec);
9466	alc861_auto_init_analog_input(codec);
9467}
9468
9469
9470/*
9471 * configuration and preset
9472 */
9473static const char *alc861_models[ALC861_MODEL_LAST] = {
9474	[ALC861_3ST]		= "3stack",
9475	[ALC660_3ST]		= "3stack-660",
9476	[ALC861_3ST_DIG]	= "3stack-dig",
9477	[ALC861_6ST_DIG]	= "6stack-dig",
9478	[ALC861_UNIWILL_M31]	= "uniwill-m31",
9479	[ALC861_TOSHIBA]	= "toshiba",
9480	[ALC861_ASUS]		= "asus",
9481	[ALC861_ASUS_LAPTOP]	= "asus-laptop",
9482	[ALC861_AUTO]		= "auto",
9483};
9484
9485static struct snd_pci_quirk alc861_cfg_tbl[] = {
9486	SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
9487	SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
9488	SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
9489	SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
9490	SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
9491	SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
9492	SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
9493	SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
9494	SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA),
9495	SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
9496	SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
9497	SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
9498	SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
9499	SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
9500	{}
9501};
9502
9503static struct alc_config_preset alc861_presets[] = {
9504	[ALC861_3ST] = {
9505		.mixers = { alc861_3ST_mixer },
9506		.init_verbs = { alc861_threestack_init_verbs },
9507		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9508		.dac_nids = alc861_dac_nids,
9509		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9510		.channel_mode = alc861_threestack_modes,
9511		.need_dac_fix = 1,
9512		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9513		.adc_nids = alc861_adc_nids,
9514		.input_mux = &alc861_capture_source,
9515	},
9516	[ALC861_3ST_DIG] = {
9517		.mixers = { alc861_base_mixer },
9518		.init_verbs = { alc861_threestack_init_verbs },
9519		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9520		.dac_nids = alc861_dac_nids,
9521		.dig_out_nid = ALC861_DIGOUT_NID,
9522		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9523		.channel_mode = alc861_threestack_modes,
9524		.need_dac_fix = 1,
9525		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9526		.adc_nids = alc861_adc_nids,
9527		.input_mux = &alc861_capture_source,
9528	},
9529	[ALC861_6ST_DIG] = {
9530		.mixers = { alc861_base_mixer },
9531		.init_verbs = { alc861_base_init_verbs },
9532		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9533		.dac_nids = alc861_dac_nids,
9534		.dig_out_nid = ALC861_DIGOUT_NID,
9535		.num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
9536		.channel_mode = alc861_8ch_modes,
9537		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9538		.adc_nids = alc861_adc_nids,
9539		.input_mux = &alc861_capture_source,
9540	},
9541	[ALC660_3ST] = {
9542		.mixers = { alc861_3ST_mixer },
9543		.init_verbs = { alc861_threestack_init_verbs },
9544		.num_dacs = ARRAY_SIZE(alc660_dac_nids),
9545		.dac_nids = alc660_dac_nids,
9546		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9547		.channel_mode = alc861_threestack_modes,
9548		.need_dac_fix = 1,
9549		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9550		.adc_nids = alc861_adc_nids,
9551		.input_mux = &alc861_capture_source,
9552	},
9553	[ALC861_UNIWILL_M31] = {
9554		.mixers = { alc861_uniwill_m31_mixer },
9555		.init_verbs = { alc861_uniwill_m31_init_verbs },
9556		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9557		.dac_nids = alc861_dac_nids,
9558		.dig_out_nid = ALC861_DIGOUT_NID,
9559		.num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
9560		.channel_mode = alc861_uniwill_m31_modes,
9561		.need_dac_fix = 1,
9562		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9563		.adc_nids = alc861_adc_nids,
9564		.input_mux = &alc861_capture_source,
9565	},
9566	[ALC861_TOSHIBA] = {
9567		.mixers = { alc861_toshiba_mixer },
9568		.init_verbs = { alc861_base_init_verbs,
9569				alc861_toshiba_init_verbs },
9570		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9571		.dac_nids = alc861_dac_nids,
9572		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9573		.channel_mode = alc883_3ST_2ch_modes,
9574		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9575		.adc_nids = alc861_adc_nids,
9576		.input_mux = &alc861_capture_source,
9577		.unsol_event = alc861_toshiba_unsol_event,
9578		.init_hook = alc861_toshiba_automute,
9579	},
9580	[ALC861_ASUS] = {
9581		.mixers = { alc861_asus_mixer },
9582		.init_verbs = { alc861_asus_init_verbs },
9583		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9584		.dac_nids = alc861_dac_nids,
9585		.dig_out_nid = ALC861_DIGOUT_NID,
9586		.num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
9587		.channel_mode = alc861_asus_modes,
9588		.need_dac_fix = 1,
9589		.hp_nid = 0x06,
9590		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9591		.adc_nids = alc861_adc_nids,
9592		.input_mux = &alc861_capture_source,
9593	},
9594	[ALC861_ASUS_LAPTOP] = {
9595		.mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
9596		.init_verbs = { alc861_asus_init_verbs,
9597				alc861_asus_laptop_init_verbs },
9598		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
9599		.dac_nids = alc861_dac_nids,
9600		.dig_out_nid = ALC861_DIGOUT_NID,
9601		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9602		.channel_mode = alc883_3ST_2ch_modes,
9603		.need_dac_fix = 1,
9604		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9605		.adc_nids = alc861_adc_nids,
9606		.input_mux = &alc861_capture_source,
9607	},
9608};
9609
9610
9611static int patch_alc861(struct hda_codec *codec)
9612{
9613	struct alc_spec *spec;
9614	int board_config;
9615	int err;
9616
9617	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9618	if (spec == NULL)
9619		return -ENOMEM;
9620
9621	codec->spec = spec;
9622
9623        board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
9624						  alc861_models,
9625						  alc861_cfg_tbl);
9626
9627	if (board_config < 0) {
9628		printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
9629		       "trying auto-probe from BIOS...\n");
9630		board_config = ALC861_AUTO;
9631	}
9632
9633	if (board_config == ALC861_AUTO) {
9634		/* automatic parse from the BIOS config */
9635		err = alc861_parse_auto_config(codec);
9636		if (err < 0) {
9637			alc_free(codec);
9638			return err;
9639		} else if (!err) {
9640			printk(KERN_INFO
9641			       "hda_codec: Cannot set up configuration "
9642			       "from BIOS.  Using base mode...\n");
9643		   board_config = ALC861_3ST_DIG;
9644		}
9645	}
9646
9647	if (board_config != ALC861_AUTO)
9648		setup_preset(spec, &alc861_presets[board_config]);
9649
9650	spec->stream_name_analog = "ALC861 Analog";
9651	spec->stream_analog_playback = &alc861_pcm_analog_playback;
9652	spec->stream_analog_capture = &alc861_pcm_analog_capture;
9653
9654	spec->stream_name_digital = "ALC861 Digital";
9655	spec->stream_digital_playback = &alc861_pcm_digital_playback;
9656	spec->stream_digital_capture = &alc861_pcm_digital_capture;
9657
9658	codec->patch_ops = alc_patch_ops;
9659	if (board_config == ALC861_AUTO)
9660		spec->init_hook = alc861_auto_init;
9661
9662	return 0;
9663}
9664
9665/*
9666 * ALC861-VD support
9667 *
9668 * Based on ALC882
9669 *
9670 * In addition, an independent DAC
9671 */
9672#define ALC861VD_DIGOUT_NID	0x06
9673
9674static hda_nid_t alc861vd_dac_nids[4] = {
9675	/* front, surr, clfe, side surr */
9676	0x02, 0x03, 0x04, 0x05
9677};
9678
9679/* dac_nids for ALC660vd are in a different order - according to
9680 * Realtek's driver.
9681 * This should probably tesult in a different mixer for 6stack models
9682 * of ALC660vd codecs, but for now there is only 3stack mixer
9683 * - and it is the same as in 861vd.
9684 * adc_nids in ALC660vd are (is) the same as in 861vd
9685 */
9686static hda_nid_t alc660vd_dac_nids[3] = {
9687	/* front, rear, clfe, rear_surr */
9688	0x02, 0x04, 0x03
9689};
9690
9691static hda_nid_t alc861vd_adc_nids[1] = {
9692	/* ADC0 */
9693	0x09,
9694};
9695
9696/* input MUX */
9697/* FIXME: should be a matrix-type input source selection */
9698static struct hda_input_mux alc861vd_capture_source = {
9699	.num_items = 4,
9700	.items = {
9701		{ "Mic", 0x0 },
9702		{ "Front Mic", 0x1 },
9703		{ "Line", 0x2 },
9704		{ "CD", 0x4 },
9705	},
9706};
9707
9708static struct hda_input_mux alc861vd_dallas_capture_source = {
9709	.num_items = 3,
9710	.items = {
9711		{ "Front Mic", 0x0 },
9712		{ "ATAPI Mic", 0x1 },
9713		{ "Line In", 0x5 },
9714	},
9715};
9716
9717#define alc861vd_mux_enum_info alc_mux_enum_info
9718#define alc861vd_mux_enum_get alc_mux_enum_get
9719
9720static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
9721				struct snd_ctl_elem_value *ucontrol)
9722{
9723	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9724	struct alc_spec *spec = codec->spec;
9725	const struct hda_input_mux *imux = spec->input_mux;
9726	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9727	static hda_nid_t capture_mixers[1] = { 0x22 };
9728	hda_nid_t nid = capture_mixers[adc_idx];
9729	unsigned int *cur_val = &spec->cur_mux[adc_idx];
9730	unsigned int i, idx;
9731
9732	idx = ucontrol->value.enumerated.item[0];
9733	if (idx >= imux->num_items)
9734		idx = imux->num_items - 1;
9735	if (*cur_val == idx && !codec->in_resume)
9736		return 0;
9737	for (i = 0; i < imux->num_items; i++) {
9738		unsigned int v = (i == idx) ? 0x7000 : 0x7080;
9739		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9740				    v | (imux->items[i].index << 8));
9741	}
9742	*cur_val = idx;
9743	return 1;
9744}
9745
9746/*
9747 * 2ch mode
9748 */
9749static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
9750	{ 2, NULL }
9751};
9752
9753/*
9754 * 6ch mode
9755 */
9756static struct hda_verb alc861vd_6stack_ch6_init[] = {
9757	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9758	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9759	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9760	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9761	{ } /* end */
9762};
9763
9764/*
9765 * 8ch mode
9766 */
9767static struct hda_verb alc861vd_6stack_ch8_init[] = {
9768	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9769	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9770	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9771	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9772	{ } /* end */
9773};
9774
9775static struct hda_channel_mode alc861vd_6stack_modes[2] = {
9776	{ 6, alc861vd_6stack_ch6_init },
9777	{ 8, alc861vd_6stack_ch8_init },
9778};
9779
9780static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
9781	{
9782		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9783		.name = "Channel Mode",
9784		.info = alc_ch_mode_info,
9785		.get = alc_ch_mode_get,
9786		.put = alc_ch_mode_put,
9787	},
9788	{ } /* end */
9789};
9790
9791static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
9792	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9793	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9794
9795	{
9796		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9797		/* The multiple "Capture Source" controls confuse alsamixer
9798		 * So call somewhat different..
9799		 *FIXME: the controls appear in the "playback" view!
9800		 */
9801		/* .name = "Capture Source", */
9802		.name = "Input Source",
9803		.count = 1,
9804		.info = alc861vd_mux_enum_info,
9805		.get = alc861vd_mux_enum_get,
9806		.put = alc861vd_mux_enum_put,
9807	},
9808	{ } /* end */
9809};
9810
9811/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
9812 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
9813 */
9814static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
9815	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9816	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9817
9818	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9819	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9820
9821	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
9822				HDA_OUTPUT),
9823	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
9824				HDA_OUTPUT),
9825	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9826	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9827
9828	HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
9829	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9830
9831	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9832
9833	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9834	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9835	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9836
9837	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9838	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9839	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9840
9841	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9842	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9843
9844	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9845	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9846
9847	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
9848	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
9849
9850	{ } /* end */
9851};
9852
9853static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
9854	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9855	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9856
9857	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9858
9859	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9860	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9861	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9862
9863	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9864	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9865	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9866
9867	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9868	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9869
9870	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9871	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9872
9873	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
9874	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
9875
9876	{ } /* end */
9877};
9878
9879static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
9880	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9881	/*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
9882	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9883
9884	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9885
9886	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9887	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9888	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9889
9890	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9891	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9892	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9893
9894	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9895	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9896
9897	{ } /* end */
9898};
9899
9900/* Pin assignment: Front=0x14, HP = 0x15,
9901 *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
9902 */
9903static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
9904	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9905	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9906	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9907	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
9908	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9909	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9910	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9911	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9912	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
9913	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
9914	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9915	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9916	{
9917		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9918		/* .name = "Capture Source", */
9919		.name = "Input Source",
9920		.count = 1,
9921		.info = alc882_mux_enum_info,
9922		.get = alc882_mux_enum_get,
9923		.put = alc882_mux_enum_put,
9924	},
9925	{ } /* end */
9926};
9927
9928/*
9929 * generic initialization of ADC, input mixers and output mixers
9930 */
9931static struct hda_verb alc861vd_volume_init_verbs[] = {
9932	/*
9933	 * Unmute ADC0 and set the default input to mic-in
9934	 */
9935	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9936	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9937
9938	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
9939	 * the analog-loopback mixer widget
9940	 */
9941	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9942	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9943	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9944	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9945	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9946	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
9947
9948	/* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
9949	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9950	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9951	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9952	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
9953
9954	/*
9955	 * Set up output mixers (0x02 - 0x05)
9956	 */
9957	/* set vol=0 to output mixers */
9958	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9959	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9960	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9961	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9962
9963	/* set up input amps for analog loopback */
9964	/* Amp Indices: DAC = 0, mixer = 1 */
9965	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9966	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9967	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9968	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9969	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9970	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9971	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9972	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9973
9974	{ }
9975};
9976
9977/*
9978 * 3-stack pin configuration:
9979 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
9980 */
9981static struct hda_verb alc861vd_3stack_init_verbs[] = {
9982	/*
9983	 * Set pin mode and muting
9984	 */
9985	/* set front pin widgets 0x14 for output */
9986	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9987	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9988	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9989
9990	/* Mic (rear) pin: input vref at 80% */
9991	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9992	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9993	/* Front Mic pin: input vref at 80% */
9994	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9995	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9996	/* Line In pin: input */
9997	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9998	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9999	/* Line-2 In: Headphone output (output 0 - 0x0c) */
10000	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10001	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10002	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10003	/* CD pin widget for input */
10004	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10005
10006	{ }
10007};
10008
10009/*
10010 * 6-stack pin configuration:
10011 */
10012static struct hda_verb alc861vd_6stack_init_verbs[] = {
10013	/*
10014	 * Set pin mode and muting
10015	 */
10016	/* set front pin widgets 0x14 for output */
10017	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10018	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10019	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10020
10021	/* Rear Pin: output 1 (0x0d) */
10022	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10023	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10024	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10025	/* CLFE Pin: output 2 (0x0e) */
10026	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10027	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10028	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
10029	/* Side Pin: output 3 (0x0f) */
10030	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10031	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10032	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
10033
10034	/* Mic (rear) pin: input vref at 80% */
10035	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10036	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10037	/* Front Mic pin: input vref at 80% */
10038	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10039	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10040	/* Line In pin: input */
10041	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10042	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10043	/* Line-2 In: Headphone output (output 0 - 0x0c) */
10044	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10045	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10046	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10047	/* CD pin widget for input */
10048	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10049
10050	{ }
10051};
10052
10053static struct hda_verb alc861vd_eapd_verbs[] = {
10054	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10055	{ }
10056};
10057
10058static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
10059	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10060	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10061	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10062	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10063	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10064	{}
10065};
10066
10067/* toggle speaker-output according to the hp-jack state */
10068static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
10069{
10070	unsigned int present;
10071	unsigned char bits;
10072
10073	present = snd_hda_codec_read(codec, 0x1b, 0,
10074				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10075	bits = present ? 0x80 : 0;
10076	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10077				 0x80, bits);
10078	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10079				 0x80, bits);
10080}
10081
10082static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
10083{
10084	unsigned int present;
10085	unsigned char bits;
10086
10087	present = snd_hda_codec_read(codec, 0x18, 0,
10088				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10089	bits = present ? 0x80 : 0;
10090	snd_hda_codec_amp_update(codec, 0x0b, 0, HDA_INPUT, 1,
10091				 0x80, bits);
10092	snd_hda_codec_amp_update(codec, 0x0b, 1, HDA_INPUT, 1,
10093				 0x80, bits);
10094}
10095
10096static void alc861vd_lenovo_automute(struct hda_codec *codec)
10097{
10098	alc861vd_lenovo_hp_automute(codec);
10099	alc861vd_lenovo_mic_automute(codec);
10100}
10101
10102static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
10103					unsigned int res)
10104{
10105	switch (res >> 26) {
10106	case ALC880_HP_EVENT:
10107		alc861vd_lenovo_hp_automute(codec);
10108		break;
10109	case ALC880_MIC_EVENT:
10110		alc861vd_lenovo_mic_automute(codec);
10111		break;
10112	}
10113}
10114
10115static struct hda_verb alc861vd_dallas_verbs[] = {
10116	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10117	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10118	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10119	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10120
10121	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10122	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10123	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10124	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10125	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10126	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10127	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10128	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10129
10130	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10131	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10132	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10133	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10134	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10135	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10136	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10137	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10138
10139	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10140	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10141	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10142	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10143	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10144	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10145	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10146	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10147
10148	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10149	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10150	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10151	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10152
10153	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10154	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10155	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10156
10157	{ } /* end */
10158};
10159
10160/* toggle speaker-output according to the hp-jack state */
10161static void alc861vd_dallas_automute(struct hda_codec *codec)
10162{
10163	unsigned int present;
10164
10165	present = snd_hda_codec_read(codec, 0x15, 0,
10166				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10167	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10168				 0x80, present ? 0x80 : 0);
10169	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10170				 0x80, present ? 0x80 : 0);
10171}
10172
10173static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
10174{
10175	if ((res >> 26) == ALC880_HP_EVENT)
10176		alc861vd_dallas_automute(codec);
10177}
10178
10179/* pcm configuration: identiacal with ALC880 */
10180#define alc861vd_pcm_analog_playback	alc880_pcm_analog_playback
10181#define alc861vd_pcm_analog_capture	alc880_pcm_analog_capture
10182#define alc861vd_pcm_digital_playback	alc880_pcm_digital_playback
10183#define alc861vd_pcm_digital_capture	alc880_pcm_digital_capture
10184
10185/*
10186 * configuration and preset
10187 */
10188static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
10189	[ALC660VD_3ST]		= "3stack-660",
10190	[ALC660VD_3ST_DIG]= "3stack-660-digout",
10191	[ALC861VD_3ST]		= "3stack",
10192	[ALC861VD_3ST_DIG]	= "3stack-digout",
10193	[ALC861VD_6ST_DIG]	= "6stack-digout",
10194	[ALC861VD_LENOVO]	= "lenovo",
10195	[ALC861VD_DALLAS]	= "dallas",
10196	[ALC861VD_AUTO]		= "auto",
10197};
10198
10199static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
10200	SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
10201	SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
10202	SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
10203	SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
10204	SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
10205
10206	SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),
10207	SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
10208	SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
10209	SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
10210	SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
10211	{}
10212};
10213
10214static struct alc_config_preset alc861vd_presets[] = {
10215	[ALC660VD_3ST] = {
10216		.mixers = { alc861vd_3st_mixer },
10217		.init_verbs = { alc861vd_volume_init_verbs,
10218				 alc861vd_3stack_init_verbs },
10219		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10220		.dac_nids = alc660vd_dac_nids,
10221		.num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10222		.adc_nids = alc861vd_adc_nids,
10223		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10224		.channel_mode = alc861vd_3stack_2ch_modes,
10225		.input_mux = &alc861vd_capture_source,
10226	},
10227	[ALC660VD_3ST_DIG] = {
10228		.mixers = { alc861vd_3st_mixer },
10229		.init_verbs = { alc861vd_volume_init_verbs,
10230				 alc861vd_3stack_init_verbs },
10231		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10232		.dac_nids = alc660vd_dac_nids,
10233		.dig_out_nid = ALC861VD_DIGOUT_NID,
10234		.num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10235		.adc_nids = alc861vd_adc_nids,
10236		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10237		.channel_mode = alc861vd_3stack_2ch_modes,
10238		.input_mux = &alc861vd_capture_source,
10239	},
10240	[ALC861VD_3ST] = {
10241		.mixers = { alc861vd_3st_mixer },
10242		.init_verbs = { alc861vd_volume_init_verbs,
10243				 alc861vd_3stack_init_verbs },
10244		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10245		.dac_nids = alc861vd_dac_nids,
10246		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10247		.channel_mode = alc861vd_3stack_2ch_modes,
10248		.input_mux = &alc861vd_capture_source,
10249	},
10250	[ALC861VD_3ST_DIG] = {
10251		.mixers = { alc861vd_3st_mixer },
10252		.init_verbs = { alc861vd_volume_init_verbs,
10253		 		 alc861vd_3stack_init_verbs },
10254		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10255		.dac_nids = alc861vd_dac_nids,
10256		.dig_out_nid = ALC861VD_DIGOUT_NID,
10257		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10258		.channel_mode = alc861vd_3stack_2ch_modes,
10259		.input_mux = &alc861vd_capture_source,
10260	},
10261	[ALC861VD_6ST_DIG] = {
10262		.mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
10263		.init_verbs = { alc861vd_volume_init_verbs,
10264				alc861vd_6stack_init_verbs },
10265		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10266		.dac_nids = alc861vd_dac_nids,
10267		.dig_out_nid = ALC861VD_DIGOUT_NID,
10268		.num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
10269		.channel_mode = alc861vd_6stack_modes,
10270		.input_mux = &alc861vd_capture_source,
10271	},
10272	[ALC861VD_LENOVO] = {
10273		.mixers = { alc861vd_lenovo_mixer },
10274		.init_verbs = { alc861vd_volume_init_verbs,
10275				alc861vd_3stack_init_verbs,
10276				alc861vd_eapd_verbs,
10277				alc861vd_lenovo_unsol_verbs },
10278		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10279		.dac_nids = alc660vd_dac_nids,
10280		.num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10281		.adc_nids = alc861vd_adc_nids,
10282		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10283		.channel_mode = alc861vd_3stack_2ch_modes,
10284		.input_mux = &alc861vd_capture_source,
10285		.unsol_event = alc861vd_lenovo_unsol_event,
10286		.init_hook = alc861vd_lenovo_automute,
10287	},
10288	[ALC861VD_DALLAS] = {
10289		.mixers = { alc861vd_dallas_mixer },
10290		.init_verbs = { alc861vd_dallas_verbs },
10291		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10292		.dac_nids = alc861vd_dac_nids,
10293		.num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10294		.adc_nids = alc861vd_adc_nids,
10295		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10296		.channel_mode = alc861vd_3stack_2ch_modes,
10297		.input_mux = &alc861vd_dallas_capture_source,
10298		.unsol_event = alc861vd_dallas_unsol_event,
10299		.init_hook = alc861vd_dallas_automute,
10300	},
10301};
10302
10303/*
10304 * BIOS auto configuration
10305 */
10306static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
10307				hda_nid_t nid, int pin_type, int dac_idx)
10308{
10309	/* set as output */
10310	snd_hda_codec_write(codec, nid, 0,
10311				AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
10312	snd_hda_codec_write(codec, nid, 0,
10313				AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
10314}
10315
10316static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
10317{
10318	struct alc_spec *spec = codec->spec;
10319	int i;
10320
10321	alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
10322	for (i = 0; i <= HDA_SIDE; i++) {
10323		hda_nid_t nid = spec->autocfg.line_out_pins[i];
10324		int pin_type = get_pin_type(spec->autocfg.line_out_type);
10325		if (nid)
10326			alc861vd_auto_set_output_and_unmute(codec, nid,
10327							    pin_type, i);
10328	}
10329}
10330
10331
10332static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
10333{
10334	struct alc_spec *spec = codec->spec;
10335	hda_nid_t pin;
10336
10337	pin = spec->autocfg.hp_pins[0];
10338	if (pin) /* connect to front and  use dac 0 */
10339		alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
10340}
10341
10342#define alc861vd_is_input_pin(nid)	alc880_is_input_pin(nid)
10343#define ALC861VD_PIN_CD_NID		ALC880_PIN_CD_NID
10344
10345static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
10346{
10347	struct alc_spec *spec = codec->spec;
10348	int i;
10349
10350	for (i = 0; i < AUTO_PIN_LAST; i++) {
10351		hda_nid_t nid = spec->autocfg.input_pins[i];
10352		if (alc861vd_is_input_pin(nid)) {
10353			snd_hda_codec_write(codec, nid, 0,
10354					AC_VERB_SET_PIN_WIDGET_CONTROL,
10355					i <= AUTO_PIN_FRONT_MIC ?
10356							PIN_VREF80 : PIN_IN);
10357			if (nid != ALC861VD_PIN_CD_NID)
10358				snd_hda_codec_write(codec, nid, 0,
10359						AC_VERB_SET_AMP_GAIN_MUTE,
10360						AMP_OUT_MUTE);
10361		}
10362	}
10363}
10364
10365#define alc861vd_idx_to_mixer_vol(nid)		((nid) + 0x02)
10366#define alc861vd_idx_to_mixer_switch(nid)	((nid) + 0x0c)
10367
10368/* add playback controls from the parsed DAC table */
10369/* Based on ALC880 version. But ALC861VD has separate,
10370 * different NIDs for mute/unmute switch and volume control */
10371static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
10372					     const struct auto_pin_cfg *cfg)
10373{
10374	char name[32];
10375	static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
10376	hda_nid_t nid_v, nid_s;
10377	int i, err;
10378
10379	for (i = 0; i < cfg->line_outs; i++) {
10380		if (!spec->multiout.dac_nids[i])
10381			continue;
10382		nid_v = alc861vd_idx_to_mixer_vol(
10383				alc880_dac_to_idx(
10384					spec->multiout.dac_nids[i]));
10385		nid_s = alc861vd_idx_to_mixer_switch(
10386				alc880_dac_to_idx(
10387					spec->multiout.dac_nids[i]));
10388
10389		if (i == 2) {
10390			/* Center/LFE */
10391			err = add_control(spec, ALC_CTL_WIDGET_VOL,
10392					  "Center Playback Volume",
10393					  HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
10394							      HDA_OUTPUT));
10395			if (err < 0)
10396				return err;
10397			err = add_control(spec, ALC_CTL_WIDGET_VOL,
10398					  "LFE Playback Volume",
10399					  HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
10400							      HDA_OUTPUT));
10401			if (err < 0)
10402				return err;
10403			err = add_control(spec, ALC_CTL_BIND_MUTE,
10404					  "Center Playback Switch",
10405					  HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
10406							      HDA_INPUT));
10407			if (err < 0)
10408				return err;
10409			err = add_control(spec, ALC_CTL_BIND_MUTE,
10410					  "LFE Playback Switch",
10411					  HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
10412							      HDA_INPUT));
10413			if (err < 0)
10414				return err;
10415		} else {
10416			sprintf(name, "%s Playback Volume", chname[i]);
10417			err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10418					  HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
10419							      HDA_OUTPUT));
10420			if (err < 0)
10421				return err;
10422			sprintf(name, "%s Playback Switch", chname[i]);
10423			err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10424					  HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
10425							      HDA_INPUT));
10426			if (err < 0)
10427				return err;
10428		}
10429	}
10430	return 0;
10431}
10432
10433/* add playback controls for speaker and HP outputs */
10434/* Based on ALC880 version. But ALC861VD has separate,
10435 * different NIDs for mute/unmute switch and volume control */
10436static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
10437					hda_nid_t pin, const char *pfx)
10438{
10439	hda_nid_t nid_v, nid_s;
10440	int err;
10441	char name[32];
10442
10443	if (!pin)
10444		return 0;
10445
10446	if (alc880_is_fixed_pin(pin)) {
10447		nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
10448		/* specify the DAC as the extra output */
10449		if (!spec->multiout.hp_nid)
10450			spec->multiout.hp_nid = nid_v;
10451		else
10452			spec->multiout.extra_out_nid[0] = nid_v;
10453		/* control HP volume/switch on the output mixer amp */
10454		nid_v = alc861vd_idx_to_mixer_vol(
10455				alc880_fixed_pin_idx(pin));
10456		nid_s = alc861vd_idx_to_mixer_switch(
10457				alc880_fixed_pin_idx(pin));
10458
10459		sprintf(name, "%s Playback Volume", pfx);
10460		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10461				  HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
10462		if (err < 0)
10463			return err;
10464		sprintf(name, "%s Playback Switch", pfx);
10465		err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10466				  HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
10467		if (err < 0)
10468			return err;
10469	} else if (alc880_is_multi_pin(pin)) {
10470		/* set manual connection */
10471		/* we have only a switch on HP-out PIN */
10472		sprintf(name, "%s Playback Switch", pfx);
10473		err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10474				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
10475		if (err < 0)
10476			return err;
10477	}
10478	return 0;
10479}
10480
10481/* parse the BIOS configuration and set up the alc_spec
10482 * return 1 if successful, 0 if the proper config is not found,
10483 * or a negative error code
10484 * Based on ALC880 version - had to change it to override
10485 * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
10486static int alc861vd_parse_auto_config(struct hda_codec *codec)
10487{
10488	struct alc_spec *spec = codec->spec;
10489	int err;
10490	static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
10491
10492	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10493					   alc861vd_ignore);
10494	if (err < 0)
10495		return err;
10496	if (!spec->autocfg.line_outs)
10497		return 0; /* can't find valid BIOS pin config */
10498
10499	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
10500	if (err < 0)
10501		return err;
10502	err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
10503	if (err < 0)
10504		return err;
10505	err = alc861vd_auto_create_extra_out(spec,
10506					     spec->autocfg.speaker_pins[0],
10507					     "Speaker");
10508	if (err < 0)
10509		return err;
10510	err = alc861vd_auto_create_extra_out(spec,
10511					     spec->autocfg.hp_pins[0],
10512					     "Headphone");
10513	if (err < 0)
10514		return err;
10515	err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
10516	if (err < 0)
10517		return err;
10518
10519	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10520
10521	if (spec->autocfg.dig_out_pin)
10522		spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
10523
10524	if (spec->kctl_alloc)
10525		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10526
10527	spec->init_verbs[spec->num_init_verbs++]
10528		= alc861vd_volume_init_verbs;
10529
10530	spec->num_mux_defs = 1;
10531	spec->input_mux = &spec->private_imux;
10532
10533	return 1;
10534}
10535
10536/* additional initialization for auto-configuration model */
10537static void alc861vd_auto_init(struct hda_codec *codec)
10538{
10539	alc861vd_auto_init_multi_out(codec);
10540	alc861vd_auto_init_hp_out(codec);
10541	alc861vd_auto_init_analog_input(codec);
10542}
10543
10544static int patch_alc861vd(struct hda_codec *codec)
10545{
10546	struct alc_spec *spec;
10547	int err, board_config;
10548
10549	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10550	if (spec == NULL)
10551		return -ENOMEM;
10552
10553	codec->spec = spec;
10554
10555	board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
10556						  alc861vd_models,
10557						  alc861vd_cfg_tbl);
10558
10559	if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
10560		printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
10561			"ALC861VD, trying auto-probe from BIOS...\n");
10562		board_config = ALC861VD_AUTO;
10563	}
10564
10565	if (board_config == ALC861VD_AUTO) {
10566		/* automatic parse from the BIOS config */
10567		err = alc861vd_parse_auto_config(codec);
10568		if (err < 0) {
10569			alc_free(codec);
10570			return err;
10571		} else if (!err) {
10572			printk(KERN_INFO
10573			       "hda_codec: Cannot set up configuration "
10574			       "from BIOS.  Using base mode...\n");
10575			board_config = ALC861VD_3ST;
10576		}
10577	}
10578
10579	if (board_config != ALC861VD_AUTO)
10580		setup_preset(spec, &alc861vd_presets[board_config]);
10581
10582	spec->stream_name_analog = "ALC861VD Analog";
10583	spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
10584	spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
10585
10586	spec->stream_name_digital = "ALC861VD Digital";
10587	spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
10588	spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
10589
10590	spec->adc_nids = alc861vd_adc_nids;
10591	spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
10592
10593	spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
10594	spec->num_mixers++;
10595
10596	codec->patch_ops = alc_patch_ops;
10597
10598	if (board_config == ALC861VD_AUTO)
10599		spec->init_hook = alc861vd_auto_init;
10600
10601	return 0;
10602}
10603
10604/*
10605 * ALC662 support
10606 *
10607 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
10608 * configuration.  Each pin widget can choose any input DACs and a mixer.
10609 * Each ADC is connected from a mixer of all inputs.  This makes possible
10610 * 6-channel independent captures.
10611 *
10612 * In addition, an independent DAC for the multi-playback (not used in this
10613 * driver yet).
10614 */
10615#define ALC662_DIGOUT_NID	0x06
10616#define ALC662_DIGIN_NID	0x0a
10617
10618static hda_nid_t alc662_dac_nids[4] = {
10619	/* front, rear, clfe, rear_surr */
10620	0x02, 0x03, 0x04
10621};
10622
10623static hda_nid_t alc662_adc_nids[1] = {
10624	/* ADC1-2 */
10625	0x09,
10626};
10627/* input MUX */
10628/* FIXME: should be a matrix-type input source selection */
10629
10630static struct hda_input_mux alc662_capture_source = {
10631	.num_items = 4,
10632	.items = {
10633		{ "Mic", 0x0 },
10634		{ "Front Mic", 0x1 },
10635		{ "Line", 0x2 },
10636		{ "CD", 0x4 },
10637	},
10638};
10639
10640static struct hda_input_mux alc662_lenovo_101e_capture_source = {
10641	.num_items = 2,
10642	.items = {
10643		{ "Mic", 0x1 },
10644		{ "Line", 0x2 },
10645	},
10646};
10647#define alc662_mux_enum_info alc_mux_enum_info
10648#define alc662_mux_enum_get alc_mux_enum_get
10649
10650static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
10651			       struct snd_ctl_elem_value *ucontrol)
10652{
10653	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10654	struct alc_spec *spec = codec->spec;
10655	const struct hda_input_mux *imux = spec->input_mux;
10656	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
10657	static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
10658	hda_nid_t nid = capture_mixers[adc_idx];
10659	unsigned int *cur_val = &spec->cur_mux[adc_idx];
10660	unsigned int i, idx;
10661
10662	idx = ucontrol->value.enumerated.item[0];
10663	if (idx >= imux->num_items)
10664		idx = imux->num_items - 1;
10665	if (*cur_val == idx && !codec->in_resume)
10666		return 0;
10667	for (i = 0; i < imux->num_items; i++) {
10668		unsigned int v = (i == idx) ? 0x7000 : 0x7080;
10669		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10670				    v | (imux->items[i].index << 8));
10671	}
10672	*cur_val = idx;
10673	return 1;
10674}
10675/*
10676 * 2ch mode
10677 */
10678static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
10679	{ 2, NULL }
10680};
10681
10682/*
10683 * 2ch mode
10684 */
10685static struct hda_verb alc662_3ST_ch2_init[] = {
10686	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
10687	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
10688	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
10689	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
10690	{ } /* end */
10691};
10692
10693/*
10694 * 6ch mode
10695 */
10696static struct hda_verb alc662_3ST_ch6_init[] = {
10697	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10698	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10699	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
10700	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10701	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10702	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
10703	{ } /* end */
10704};
10705
10706static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
10707	{ 2, alc662_3ST_ch2_init },
10708	{ 6, alc662_3ST_ch6_init },
10709};
10710
10711/*
10712 * 2ch mode
10713 */
10714static struct hda_verb alc662_sixstack_ch6_init[] = {
10715	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10716	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10717	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10718	{ } /* end */
10719};
10720
10721/*
10722 * 6ch mode
10723 */
10724static struct hda_verb alc662_sixstack_ch8_init[] = {
10725	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10726	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10727	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10728	{ } /* end */
10729};
10730
10731static struct hda_channel_mode alc662_5stack_modes[2] = {
10732	{ 2, alc662_sixstack_ch6_init },
10733	{ 6, alc662_sixstack_ch8_init },
10734};
10735
10736/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
10737 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
10738 */
10739
10740static struct snd_kcontrol_new alc662_base_mixer[] = {
10741	/* output mixer control */
10742	HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10743	HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
10744	HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10745	HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10746	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
10747	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
10748	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
10749	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
10750	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10751
10752	/*Input mixer control */
10753	HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
10754	HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
10755	HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
10756	HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
10757	HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
10758	HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
10759	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
10760	HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
10761
10762	/* Capture mixer control */
10763	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10764	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10765	{
10766		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10767		.name = "Capture Source",
10768		.count = 1,
10769		.info = alc_mux_enum_info,
10770		.get = alc_mux_enum_get,
10771		.put = alc_mux_enum_put,
10772	},
10773	{ } /* end */
10774};
10775
10776static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
10777	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10778	HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10779	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10780	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10781	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10782	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10783	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10784	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10785	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10786	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10787	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10788	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10789	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10790	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10791	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10792	{
10793		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10794		/* .name = "Capture Source", */
10795		.name = "Input Source",
10796		.count = 1,
10797		.info = alc662_mux_enum_info,
10798		.get = alc662_mux_enum_get,
10799		.put = alc662_mux_enum_put,
10800	},
10801	{ } /* end */
10802};
10803
10804static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
10805	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10806	HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10807	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10808	HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
10809	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
10810	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
10811	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
10812	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
10813	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10814	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10815	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10816	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10817	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10818	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10819	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10820	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10821	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10822	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10823	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10824	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10825	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10826	{
10827		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10828		/* .name = "Capture Source", */
10829		.name = "Input Source",
10830		.count = 1,
10831		.info = alc662_mux_enum_info,
10832		.get = alc662_mux_enum_get,
10833		.put = alc662_mux_enum_put,
10834	},
10835	{ } /* end */
10836};
10837
10838static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
10839	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10840	HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10841	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10842	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
10843	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10844	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10845	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10846	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10847	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10848	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10849	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10850	{
10851		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10852		/* .name = "Capture Source", */
10853		.name = "Input Source",
10854		.count = 1,
10855		.info = alc662_mux_enum_info,
10856		.get = alc662_mux_enum_get,
10857		.put = alc662_mux_enum_put,
10858	},
10859	{ } /* end */
10860};
10861
10862static struct snd_kcontrol_new alc662_chmode_mixer[] = {
10863	{
10864		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10865		.name = "Channel Mode",
10866		.info = alc_ch_mode_info,
10867		.get = alc_ch_mode_get,
10868		.put = alc_ch_mode_put,
10869	},
10870	{ } /* end */
10871};
10872
10873static struct hda_verb alc662_init_verbs[] = {
10874	/* ADC: mute amp left and right */
10875	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10876	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10877	/* Front mixer: unmute input/output amp left and right (volume = 0) */
10878
10879	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10880	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10881	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10882	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10883	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10884
10885	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10886	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10887	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10888	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10889	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10890	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10891
10892	/* Front Pin: output 0 (0x0c) */
10893	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10894	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10895
10896	/* Rear Pin: output 1 (0x0d) */
10897	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10898	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10899
10900	/* CLFE Pin: output 2 (0x0e) */
10901	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10902	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10903
10904	/* Mic (rear) pin: input vref at 80% */
10905	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10906	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10907	/* Front Mic pin: input vref at 80% */
10908	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10909	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10910	/* Line In pin: input */
10911	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10912	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10913	/* Line-2 In: Headphone output (output 0 - 0x0c) */
10914	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10915	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10916	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10917	/* CD pin widget for input */
10918	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10919
10920	/* FIXME: use matrix-type input source selection */
10921	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10922	/* Input mixer */
10923	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10924	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10925	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10926	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10927	{ }
10928};
10929
10930static struct hda_verb alc662_sue_init_verbs[] = {
10931	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
10932	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
10933        {}
10934};
10935
10936/*
10937 * generic initialization of ADC, input mixers and output mixers
10938 */
10939static struct hda_verb alc662_auto_init_verbs[] = {
10940	/*
10941	 * Unmute ADC and set the default input to mic-in
10942	 */
10943	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10944	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10945
10946	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10947	 * mixer widget
10948	 * Note: PASD motherboards uses the Line In 2 as the input for front
10949	 * panel mic (mic 2)
10950	 */
10951	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10952	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10953	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10954	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10955	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10956	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10957
10958	/*
10959	 * Set up output mixers (0x0c - 0x0f)
10960	 */
10961	/* set vol=0 to output mixers */
10962	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10963	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10964	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10965
10966	/* set up input amps for analog loopback */
10967	/* Amp Indices: DAC = 0, mixer = 1 */
10968	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10969	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10970	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10971	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10972	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10973	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10974
10975
10976	/* FIXME: use matrix-type input source selection */
10977	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10978	/* Input mixer */
10979	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10980	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10981	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10982	/*{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},*/
10983	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10984
10985	{ }
10986};
10987
10988/* capture mixer elements */
10989static struct snd_kcontrol_new alc662_capture_mixer[] = {
10990	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10991	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10992	{
10993		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10994		/* The multiple "Capture Source" controls confuse alsamixer
10995		 * So call somewhat different..
10996		 * FIXME: the controls appear in the "playback" view!
10997		 */
10998		/* .name = "Capture Source", */
10999		.name = "Input Source",
11000		.count = 1,
11001		.info = alc882_mux_enum_info,
11002		.get = alc882_mux_enum_get,
11003		.put = alc882_mux_enum_put,
11004	},
11005	{ } /* end */
11006};
11007
11008static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
11009{
11010	unsigned int present;
11011	unsigned char bits;
11012
11013	present = snd_hda_codec_read(codec, 0x14, 0,
11014				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11015	bits = present ? 0x80 : 0;
11016	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
11017				 0x80, bits);
11018	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
11019				 0x80, bits);
11020}
11021
11022static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
11023{
11024	unsigned int present;
11025	unsigned char bits;
11026
11027 	present = snd_hda_codec_read(codec, 0x1b, 0,
11028				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11029	bits = present ? 0x80 : 0;
11030	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
11031				 0x80, bits);
11032	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
11033				 0x80, bits);
11034	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11035				 0x80, bits);
11036	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11037				 0x80, bits);
11038}
11039
11040static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
11041					   unsigned int res)
11042{
11043	if ((res >> 26) == ALC880_HP_EVENT)
11044		alc662_lenovo_101e_all_automute(codec);
11045	if ((res >> 26) == ALC880_FRONT_EVENT)
11046		alc662_lenovo_101e_ispeaker_automute(codec);
11047}
11048
11049
11050/* pcm configuration: identiacal with ALC880 */
11051#define alc662_pcm_analog_playback	alc880_pcm_analog_playback
11052#define alc662_pcm_analog_capture	alc880_pcm_analog_capture
11053#define alc662_pcm_digital_playback	alc880_pcm_digital_playback
11054#define alc662_pcm_digital_capture	alc880_pcm_digital_capture
11055
11056/*
11057 * configuration and preset
11058 */
11059static const char *alc662_models[ALC662_MODEL_LAST] = {
11060	[ALC662_3ST_2ch_DIG]	= "3stack-dig",
11061	[ALC662_3ST_6ch_DIG]	= "3stack-6ch-dig",
11062	[ALC662_3ST_6ch]	= "3stack-6ch",
11063	[ALC662_5ST_DIG]	= "6stack-dig",
11064	[ALC662_LENOVO_101E]	= "lenovo-101e",
11065	[ALC662_AUTO]		= "auto",
11066};
11067
11068static struct snd_pci_quirk alc662_cfg_tbl[] = {
11069	SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
11070	{}
11071};
11072
11073static struct alc_config_preset alc662_presets[] = {
11074	[ALC662_3ST_2ch_DIG] = {
11075		.mixers = { alc662_3ST_2ch_mixer },
11076		.init_verbs = { alc662_init_verbs },
11077		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
11078		.dac_nids = alc662_dac_nids,
11079		.dig_out_nid = ALC662_DIGOUT_NID,
11080		.num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11081		.adc_nids = alc662_adc_nids,
11082		.dig_in_nid = ALC662_DIGIN_NID,
11083		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11084		.channel_mode = alc662_3ST_2ch_modes,
11085		.input_mux = &alc662_capture_source,
11086	},
11087	[ALC662_3ST_6ch_DIG] = {
11088		.mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11089		.init_verbs = { alc662_init_verbs },
11090		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
11091		.dac_nids = alc662_dac_nids,
11092		.dig_out_nid = ALC662_DIGOUT_NID,
11093		.num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11094		.adc_nids = alc662_adc_nids,
11095		.dig_in_nid = ALC662_DIGIN_NID,
11096		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11097		.channel_mode = alc662_3ST_6ch_modes,
11098		.need_dac_fix = 1,
11099		.input_mux = &alc662_capture_source,
11100	},
11101	[ALC662_3ST_6ch] = {
11102		.mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11103		.init_verbs = { alc662_init_verbs },
11104		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
11105		.dac_nids = alc662_dac_nids,
11106		.num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11107		.adc_nids = alc662_adc_nids,
11108		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11109		.channel_mode = alc662_3ST_6ch_modes,
11110		.need_dac_fix = 1,
11111		.input_mux = &alc662_capture_source,
11112	},
11113	[ALC662_5ST_DIG] = {
11114		.mixers = { alc662_base_mixer, alc662_chmode_mixer },
11115		.init_verbs = { alc662_init_verbs },
11116		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
11117		.dac_nids = alc662_dac_nids,
11118		.dig_out_nid = ALC662_DIGOUT_NID,
11119		.num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11120		.adc_nids = alc662_adc_nids,
11121		.dig_in_nid = ALC662_DIGIN_NID,
11122		.num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
11123		.channel_mode = alc662_5stack_modes,
11124		.input_mux = &alc662_capture_source,
11125	},
11126	[ALC662_LENOVO_101E] = {
11127		.mixers = { alc662_lenovo_101e_mixer },
11128		.init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
11129		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
11130		.dac_nids = alc662_dac_nids,
11131		.num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11132		.adc_nids = alc662_adc_nids,
11133		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11134		.channel_mode = alc662_3ST_2ch_modes,
11135		.input_mux = &alc662_lenovo_101e_capture_source,
11136		.unsol_event = alc662_lenovo_101e_unsol_event,
11137		.init_hook = alc662_lenovo_101e_all_automute,
11138	},
11139
11140};
11141
11142
11143/*
11144 * BIOS auto configuration
11145 */
11146
11147/* add playback controls from the parsed DAC table */
11148static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
11149					     const struct auto_pin_cfg *cfg)
11150{
11151	char name[32];
11152	static const char *chname[4] = {
11153		"Front", "Surround", NULL /*CLFE*/, "Side"
11154	};
11155	hda_nid_t nid;
11156	int i, err;
11157
11158	for (i = 0; i < cfg->line_outs; i++) {
11159		if (!spec->multiout.dac_nids[i])
11160			continue;
11161		nid = alc880_idx_to_mixer(i);
11162		if (i == 2) {
11163			/* Center/LFE */
11164			err = add_control(spec, ALC_CTL_WIDGET_VOL,
11165					  "Center Playback Volume",
11166					  HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11167							      HDA_OUTPUT));
11168			if (err < 0)
11169				return err;
11170			err = add_control(spec, ALC_CTL_WIDGET_VOL,
11171					  "LFE Playback Volume",
11172					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11173							      HDA_OUTPUT));
11174			if (err < 0)
11175				return err;
11176			err = add_control(spec, ALC_CTL_BIND_MUTE,
11177					  "Center Playback Switch",
11178					  HDA_COMPOSE_AMP_VAL(nid, 1, 2,
11179							      HDA_INPUT));
11180			if (err < 0)
11181				return err;
11182			err = add_control(spec, ALC_CTL_BIND_MUTE,
11183					  "LFE Playback Switch",
11184					  HDA_COMPOSE_AMP_VAL(nid, 2, 2,
11185							      HDA_INPUT));
11186			if (err < 0)
11187				return err;
11188		} else {
11189			sprintf(name, "%s Playback Volume", chname[i]);
11190			err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11191					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11192							      HDA_OUTPUT));
11193			if (err < 0)
11194				return err;
11195			sprintf(name, "%s Playback Switch", chname[i]);
11196			err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11197					  HDA_COMPOSE_AMP_VAL(nid, 3, 2,
11198							      HDA_INPUT));
11199			if (err < 0)
11200				return err;
11201		}
11202	}
11203	return 0;
11204}
11205
11206/* add playback controls for speaker and HP outputs */
11207static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
11208					const char *pfx)
11209{
11210	hda_nid_t nid;
11211	int err;
11212	char name[32];
11213
11214	if (!pin)
11215		return 0;
11216
11217	if (alc880_is_fixed_pin(pin)) {
11218		nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11219                /* printk("DAC nid=%x\n",nid); */
11220		/* specify the DAC as the extra output */
11221		if (!spec->multiout.hp_nid)
11222			spec->multiout.hp_nid = nid;
11223		else
11224			spec->multiout.extra_out_nid[0] = nid;
11225		/* control HP volume/switch on the output mixer amp */
11226		nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11227		sprintf(name, "%s Playback Volume", pfx);
11228		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11229				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11230		if (err < 0)
11231			return err;
11232		sprintf(name, "%s Playback Switch", pfx);
11233		err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11234				  HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
11235		if (err < 0)
11236			return err;
11237	} else if (alc880_is_multi_pin(pin)) {
11238		/* set manual connection */
11239		/* we have only a switch on HP-out PIN */
11240		sprintf(name, "%s Playback Switch", pfx);
11241		err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11242				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11243		if (err < 0)
11244			return err;
11245	}
11246	return 0;
11247}
11248
11249/* create playback/capture controls for input pins */
11250static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
11251						const struct auto_pin_cfg *cfg)
11252{
11253	struct hda_input_mux *imux = &spec->private_imux;
11254	int i, err, idx;
11255
11256	for (i = 0; i < AUTO_PIN_LAST; i++) {
11257		if (alc880_is_input_pin(cfg->input_pins[i])) {
11258			idx = alc880_input_pin_idx(cfg->input_pins[i]);
11259			err = new_analog_input(spec, cfg->input_pins[i],
11260					       auto_pin_cfg_labels[i],
11261					       idx, 0x0b);
11262			if (err < 0)
11263				return err;
11264			imux->items[imux->num_items].label =
11265				auto_pin_cfg_labels[i];
11266			imux->items[imux->num_items].index =
11267				alc880_input_pin_idx(cfg->input_pins[i]);
11268			imux->num_items++;
11269		}
11270	}
11271	return 0;
11272}
11273
11274static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
11275					      hda_nid_t nid, int pin_type,
11276					      int dac_idx)
11277{
11278	/* set as output */
11279	snd_hda_codec_write(codec, nid, 0,
11280			    AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11281	snd_hda_codec_write(codec, nid, 0,
11282			    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11283	/* need the manual connection? */
11284	if (alc880_is_multi_pin(nid)) {
11285		struct alc_spec *spec = codec->spec;
11286		int idx = alc880_multi_pin_idx(nid);
11287		snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
11288				    AC_VERB_SET_CONNECT_SEL,
11289				    alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
11290	}
11291}
11292
11293static void alc662_auto_init_multi_out(struct hda_codec *codec)
11294{
11295	struct alc_spec *spec = codec->spec;
11296	int i;
11297
11298	for (i = 0; i <= HDA_SIDE; i++) {
11299		hda_nid_t nid = spec->autocfg.line_out_pins[i];
11300		int pin_type = get_pin_type(spec->autocfg.line_out_type);
11301		if (nid)
11302			alc662_auto_set_output_and_unmute(codec, nid, pin_type,
11303							  i);
11304	}
11305}
11306
11307static void alc662_auto_init_hp_out(struct hda_codec *codec)
11308{
11309	struct alc_spec *spec = codec->spec;
11310	hda_nid_t pin;
11311
11312	pin = spec->autocfg.hp_pins[0];
11313	if (pin) /* connect to front */
11314		/* use dac 0 */
11315		alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11316}
11317
11318#define alc662_is_input_pin(nid)	alc880_is_input_pin(nid)
11319#define ALC662_PIN_CD_NID		ALC880_PIN_CD_NID
11320
11321static void alc662_auto_init_analog_input(struct hda_codec *codec)
11322{
11323	struct alc_spec *spec = codec->spec;
11324	int i;
11325
11326	for (i = 0; i < AUTO_PIN_LAST; i++) {
11327		hda_nid_t nid = spec->autocfg.input_pins[i];
11328		if (alc662_is_input_pin(nid)) {
11329			snd_hda_codec_write(codec, nid, 0,
11330					    AC_VERB_SET_PIN_WIDGET_CONTROL,
11331					    (i <= AUTO_PIN_FRONT_MIC ?
11332					     PIN_VREF80 : PIN_IN));
11333			if (nid != ALC662_PIN_CD_NID)
11334				snd_hda_codec_write(codec, nid, 0,
11335						    AC_VERB_SET_AMP_GAIN_MUTE,
11336						    AMP_OUT_MUTE);
11337		}
11338	}
11339}
11340
11341static int alc662_parse_auto_config(struct hda_codec *codec)
11342{
11343	struct alc_spec *spec = codec->spec;
11344	int err;
11345	static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
11346
11347	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11348					   alc662_ignore);
11349	if (err < 0)
11350		return err;
11351	if (!spec->autocfg.line_outs)
11352		return 0; /* can't find valid BIOS pin config */
11353
11354	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11355	if (err < 0)
11356		return err;
11357	err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
11358	if (err < 0)
11359		return err;
11360	err = alc662_auto_create_extra_out(spec,
11361					   spec->autocfg.speaker_pins[0],
11362					   "Speaker");
11363	if (err < 0)
11364		return err;
11365	err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
11366					   "Headphone");
11367	if (err < 0)
11368		return err;
11369	err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
11370	if (err < 0)
11371		return err;
11372
11373	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11374
11375	if (spec->autocfg.dig_out_pin)
11376		spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
11377
11378	if (spec->kctl_alloc)
11379		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11380
11381	spec->num_mux_defs = 1;
11382	spec->input_mux = &spec->private_imux;
11383
11384	spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
11385	spec->mixers[spec->num_mixers] = alc662_capture_mixer;
11386	spec->num_mixers++;
11387	return 1;
11388}
11389
11390/* additional initialization for auto-configuration model */
11391static void alc662_auto_init(struct hda_codec *codec)
11392{
11393	alc662_auto_init_multi_out(codec);
11394	alc662_auto_init_hp_out(codec);
11395	alc662_auto_init_analog_input(codec);
11396}
11397
11398static int patch_alc662(struct hda_codec *codec)
11399{
11400	struct alc_spec *spec;
11401	int err, board_config;
11402
11403	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11404	if (!spec)
11405		return -ENOMEM;
11406
11407	codec->spec = spec;
11408
11409	board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
11410						  alc662_models,
11411			  	                  alc662_cfg_tbl);
11412	if (board_config < 0) {
11413		printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
11414		       "trying auto-probe from BIOS...\n");
11415		board_config = ALC662_AUTO;
11416	}
11417
11418	if (board_config == ALC662_AUTO) {
11419		/* automatic parse from the BIOS config */
11420		err = alc662_parse_auto_config(codec);
11421		if (err < 0) {
11422			alc_free(codec);
11423			return err;
11424		} else if (!err) {
11425			printk(KERN_INFO
11426			       "hda_codec: Cannot set up configuration "
11427			       "from BIOS.  Using base mode...\n");
11428			board_config = ALC662_3ST_2ch_DIG;
11429		}
11430	}
11431
11432	if (board_config != ALC662_AUTO)
11433		setup_preset(spec, &alc662_presets[board_config]);
11434
11435	spec->stream_name_analog = "ALC662 Analog";
11436	spec->stream_analog_playback = &alc662_pcm_analog_playback;
11437	spec->stream_analog_capture = &alc662_pcm_analog_capture;
11438
11439	spec->stream_name_digital = "ALC662 Digital";
11440	spec->stream_digital_playback = &alc662_pcm_digital_playback;
11441	spec->stream_digital_capture = &alc662_pcm_digital_capture;
11442
11443	if (!spec->adc_nids && spec->input_mux) {
11444		spec->adc_nids = alc662_adc_nids;
11445		spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
11446	}
11447
11448	codec->patch_ops = alc_patch_ops;
11449	if (board_config == ALC662_AUTO)
11450		spec->init_hook = alc662_auto_init;
11451
11452	return 0;
11453}
11454
11455/*
11456 * patch entries
11457 */
11458struct hda_codec_preset snd_hda_preset_realtek[] = {
11459	{ .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
11460	{ .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
11461	{ .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
11462	{ .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
11463	  .patch = patch_alc861 },
11464	{ .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
11465	{ .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
11466	{ .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
11467	{ .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
11468	  .patch = patch_alc883 },
11469	{ .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
11470	  .patch = patch_alc662 },
11471	{ .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
11472	{ .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
11473	{ .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
11474	{ .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
11475	{ .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
11476	{} /* terminator */
11477};
11478