pci/hda/patch_realtek.c
changeset 5035: 5b7dfa5f5b09
parent 5010:adca0a4cb8aa
child 5041:97b4a2ac9a14
manifest: 5b7dfa5f5b09
author: tiwai
date: Sat May 05 12:18:40 2007 +0200 (2 years ago)
permissions: -rw-r--r--
hda-codec - Fix ALC880 uniwill auto-mutes

Fix the auto-mute controls of ALC880 uniwill model. Split to two
individual functions to handle HP and front-mic mutes. For front-mic
mute, use snd_hda_codec_amp_update() to be consistent with mixer.
        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 */
       41 enum {
       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 */
       71 enum {
       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 */
       87 enum {
       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_AUTO,
       97 	ALC262_MODEL_LAST /* last tag */
       98 };
       99 
      100 /* ALC861 models */
      101 enum {
      102 	ALC861_3ST,
      103 	ALC660_3ST,
      104 	ALC861_3ST_DIG,
      105 	ALC861_6ST_DIG,
      106 	ALC861_UNIWILL_M31,
      107 	ALC861_TOSHIBA,
      108 	ALC861_ASUS,
      109 	ALC861_ASUS_LAPTOP,
      110 	ALC861_AUTO,
      111 	ALC861_MODEL_LAST,
      112 };
      113 
      114 /* ALC861-VD models */
      115 enum {
      116 	ALC660VD_3ST,
      117 	ALC861VD_3ST,
      118 	ALC861VD_3ST_DIG,
      119 	ALC861VD_6ST_DIG,
      120 	ALC861VD_AUTO,
      121 	ALC861VD_MODEL_LAST,
      122 };
      123 
      124 /* ALC662 models */
      125 enum {
      126 	ALC662_3ST_2ch_DIG,
      127 	ALC662_3ST_6ch_DIG,
      128 	ALC662_3ST_6ch,
      129 	ALC662_5ST_DIG,
      130 	ALC662_LENOVO_101E,
      131 	ALC662_AUTO,
      132 	ALC662_MODEL_LAST,
      133 };
      134 
      135 /* ALC882 models */
      136 enum {
      137 	ALC882_3ST_DIG,
      138 	ALC882_6ST_DIG,
      139 	ALC882_ARIMA,
      140 	ALC882_AUTO,
      141 	ALC885_MACPRO,
      142 	ALC882_MODEL_LAST,
      143 };
      144 
      145 /* ALC883 models */
      146 enum {
      147 	ALC883_3ST_2ch_DIG,
      148 	ALC883_3ST_6ch_DIG,
      149 	ALC883_3ST_6ch,
      150 	ALC883_6ST_DIG,
      151 	ALC883_TARGA_DIG,
      152 	ALC883_TARGA_2ch_DIG,
      153 	ALC888_DEMO_BOARD,
      154 	ALC883_ACER,
      155 	ALC883_MEDION,
      156 	ALC883_LAPTOP_EAPD,
      157 	ALC883_LENOVO_101E_2ch,
      158 	ALC883_AUTO,
      159 	ALC883_MODEL_LAST,
      160 };
      161 
      162 /* for GPIO Poll */
      163 #define GPIO_MASK	0x03
      164 
      165 struct alc_spec {
      166 	/* codec parameterization */
      167 	struct snd_kcontrol_new *mixers[5];	/* mixer arrays */
      168 	unsigned int num_mixers;
      169 
      170 	const struct hda_verb *init_verbs[5];	/* initialization verbs
      171 						 * don't forget NULL
      172 						 * termination!
      173 						 */
      174 	unsigned int num_init_verbs;
      175 
      176 	char *stream_name_analog;	/* analog PCM stream */
      177 	struct hda_pcm_stream *stream_analog_playback;
      178 	struct hda_pcm_stream *stream_analog_capture;
      179 
      180 	char *stream_name_digital;	/* digital PCM stream */
      181 	struct hda_pcm_stream *stream_digital_playback;
      182 	struct hda_pcm_stream *stream_digital_capture;
      183 
      184 	/* playback */
      185 	struct hda_multi_out multiout;	/* playback set-up
      186 					 * max_channels, dacs must be set
      187 					 * dig_out_nid and hp_nid are optional
      188 					 */
      189 
      190 	/* capture */
      191 	unsigned int num_adc_nids;
      192 	hda_nid_t *adc_nids;
      193 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
      194 
      195 	/* capture source */
      196 	unsigned int num_mux_defs;
      197 	const struct hda_input_mux *input_mux;
      198 	unsigned int cur_mux[3];
      199 
      200 	/* channel model */
      201 	const struct hda_channel_mode *channel_mode;
      202 	int num_channel_mode;
      203 	int need_dac_fix;
      204 
      205 	/* PCM information */
      206 	struct hda_pcm pcm_rec[3];	/* used in alc_build_pcms() */
      207 
      208 	/* dynamic controls, init_verbs and input_mux */
      209 	struct auto_pin_cfg autocfg;
      210 	unsigned int num_kctl_alloc, num_kctl_used;
      211 	struct snd_kcontrol_new *kctl_alloc;
      212 	struct hda_input_mux private_imux;
      213 	hda_nid_t private_dac_nids[5];
      214 
      215 	/* hooks */
      216 	void (*init_hook)(struct hda_codec *codec);
      217 	void (*unsol_event)(struct hda_codec *codec, unsigned int res);
      218 
      219 	/* for pin sensing */
      220 	unsigned int sense_updated: 1;
      221 	unsigned int jack_present: 1;
      222 };
      223 
      224 /*
      225  * configuration template - to be copied to the spec instance
      226  */
      227 struct alc_config_preset {
      228 	struct snd_kcontrol_new *mixers[5]; /* should be identical size
      229 					     * with spec
      230 					     */
      231 	const struct hda_verb *init_verbs[5];
      232 	unsigned int num_dacs;
      233 	hda_nid_t *dac_nids;
      234 	hda_nid_t dig_out_nid;		/* optional */
      235 	hda_nid_t hp_nid;		/* optional */
      236 	unsigned int num_adc_nids;
      237 	hda_nid_t *adc_nids;
      238 	hda_nid_t dig_in_nid;
      239 	unsigned int num_channel_mode;
      240 	const struct hda_channel_mode *channel_mode;
      241 	int need_dac_fix;
      242 	unsigned int num_mux_defs;
      243 	const struct hda_input_mux *input_mux;
      244 	void (*unsol_event)(struct hda_codec *, unsigned int);
      245 	void (*init_hook)(struct hda_codec *);
      246 };
      247 
      248 
      249 /*
      250  * input MUX handling
      251  */
      252 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
      253 			     struct snd_ctl_elem_info *uinfo)
      254 {
      255 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      256 	struct alc_spec *spec = codec->spec;
      257 	unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
      258 	if (mux_idx >= spec->num_mux_defs)
      259 		mux_idx = 0;
      260 	return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
      261 }
      262 
      263 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
      264 			    struct snd_ctl_elem_value *ucontrol)
      265 {
      266 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      267 	struct alc_spec *spec = codec->spec;
      268 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
      269 
      270 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
      271 	return 0;
      272 }
      273 
      274 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
      275 			    struct snd_ctl_elem_value *ucontrol)
      276 {
      277 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      278 	struct alc_spec *spec = codec->spec;
      279 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
      280 	unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
      281 	return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
      282 				     spec->adc_nids[adc_idx],
      283 				     &spec->cur_mux[adc_idx]);
      284 }
      285 
      286 
      287 /*
      288  * channel mode setting
      289  */
      290 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
      291 			    struct snd_ctl_elem_info *uinfo)
      292 {
      293 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      294 	struct alc_spec *spec = codec->spec;
      295 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
      296 				    spec->num_channel_mode);
      297 }
      298 
      299 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
      300 			   struct snd_ctl_elem_value *ucontrol)
      301 {
      302 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      303 	struct alc_spec *spec = codec->spec;
      304 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
      305 				   spec->num_channel_mode,
      306 				   spec->multiout.max_channels);
      307 }
      308 
      309 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
      310 			   struct snd_ctl_elem_value *ucontrol)
      311 {
      312 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      313 	struct alc_spec *spec = codec->spec;
      314 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
      315 				      spec->num_channel_mode,
      316 				      &spec->multiout.max_channels);
      317 	if (err >= 0 && spec->need_dac_fix)
      318 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
      319 	return err;
      320 }
      321 
      322 /*
      323  * Control the mode of pin widget settings via the mixer.  "pc" is used
      324  * instead of "%" to avoid consequences of accidently treating the % as 
      325  * being part of a format specifier.  Maximum allowed length of a value is
      326  * 63 characters plus NULL terminator.
      327  *
      328  * Note: some retasking pin complexes seem to ignore requests for input
      329  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
      330  * are requested.  Therefore order this list so that this behaviour will not
      331  * cause problems when mixer clients move through the enum sequentially.
      332  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
      333  * March 2006.
      334  */
      335 static char *alc_pin_mode_names[] = {
      336 	"Mic 50pc bias", "Mic 80pc bias",
      337 	"Line in", "Line out", "Headphone out",
      338 };
      339 static unsigned char alc_pin_mode_values[] = {
      340 	PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
      341 };
      342 /* The control can present all 5 options, or it can limit the options based
      343  * in the pin being assumed to be exclusively an input or an output pin.  In
      344  * addition, "input" pins may or may not process the mic bias option
      345  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
      346  * accept requests for bias as of chip versions up to March 2006) and/or
      347  * wiring in the computer.
      348  */
      349 #define ALC_PIN_DIR_IN              0x00
      350 #define ALC_PIN_DIR_OUT             0x01
      351 #define ALC_PIN_DIR_INOUT           0x02
      352 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
      353 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
      354 
      355 /* Info about the pin modes supported by the different pin direction modes. 
      356  * For each direction the minimum and maximum values are given.
      357  */
      358 static signed char alc_pin_mode_dir_info[5][2] = {
      359 	{ 0, 2 },    /* ALC_PIN_DIR_IN */
      360 	{ 3, 4 },    /* ALC_PIN_DIR_OUT */
      361 	{ 0, 4 },    /* ALC_PIN_DIR_INOUT */
      362 	{ 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
      363 	{ 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
      364 };
      365 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
      366 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
      367 #define alc_pin_mode_n_items(_dir) \
      368 	(alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
      369 
      370 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
      371 			     struct snd_ctl_elem_info *uinfo)
      372 {
      373 	unsigned int item_num = uinfo->value.enumerated.item;
      374 	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
      375 
      376 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
      377 	uinfo->count = 1;
      378 	uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
      379 
      380 	if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
      381 		item_num = alc_pin_mode_min(dir);
      382 	strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
      383 	return 0;
      384 }
      385 
      386 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
      387 			    struct snd_ctl_elem_value *ucontrol)
      388 {
      389 	unsigned int i;
      390 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      391 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      392 	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
      393 	long *valp = ucontrol->value.integer.value;
      394 	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
      395 						 AC_VERB_GET_PIN_WIDGET_CONTROL,
      396 						 0x00);
      397 
      398 	/* Find enumerated value for current pinctl setting */
      399 	i = alc_pin_mode_min(dir);
      400 	while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
      401 		i++;
      402 	*valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
      403 	return 0;
      404 }
      405 
      406 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
      407 			    struct snd_ctl_elem_value *ucontrol)
      408 {
      409 	signed int change;
      410 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      411 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      412 	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
      413 	long val = *ucontrol->value.integer.value;
      414 	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
      415 						 AC_VERB_GET_PIN_WIDGET_CONTROL,
      416 						 0x00);
      417 
      418 	if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
      419 		val = alc_pin_mode_min(dir);
      420 
      421 	change = pinctl != alc_pin_mode_values[val];
      422 	if (change) {
      423 		/* Set pin mode to that requested */
      424 		snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
      425 				    alc_pin_mode_values[val]);
      426 
      427 		/* Also enable the retasking pin's input/output as required 
      428 		 * for the requested pin mode.  Enum values of 2 or less are
      429 		 * input modes.
      430 		 *
      431 		 * Dynamically switching the input/output buffers probably
      432 		 * reduces noise slightly (particularly on input) so we'll
      433 		 * do it.  However, having both input and output buffers
      434 		 * enabled simultaneously doesn't seem to be problematic if
      435 		 * this turns out to be necessary in the future.
      436 		 */
      437 		if (val <= 2) {
      438 			snd_hda_codec_write(codec, nid, 0,
      439 					    AC_VERB_SET_AMP_GAIN_MUTE,
      440 					    AMP_OUT_MUTE);
      441 			snd_hda_codec_write(codec, nid, 0,
      442 					    AC_VERB_SET_AMP_GAIN_MUTE,
      443 					    AMP_IN_UNMUTE(0));
      444 		} else {
      445 			snd_hda_codec_write(codec, nid, 0,
      446 					    AC_VERB_SET_AMP_GAIN_MUTE,
      447 					    AMP_IN_MUTE(0));
      448 			snd_hda_codec_write(codec, nid, 0,
      449 					    AC_VERB_SET_AMP_GAIN_MUTE,
      450 					    AMP_OUT_UNMUTE);
      451 		}
      452 	}
      453 	return change;
      454 }
      455 
      456 #define ALC_PIN_MODE(xname, nid, dir) \
      457 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
      458 	  .info = alc_pin_mode_info, \
      459 	  .get = alc_pin_mode_get, \
      460 	  .put = alc_pin_mode_put, \
      461 	  .private_value = nid | (dir<<16) }
      462 
      463 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
      464  * together using a mask with more than one bit set.  This control is
      465  * currently used only by the ALC260 test model.  At this stage they are not
      466  * needed for any "production" models.
      467  */
      468 #ifdef CONFIG_SND_DEBUG
      469 static int alc_gpio_data_info(struct snd_kcontrol *kcontrol,
      470 			      struct snd_ctl_elem_info *uinfo)
      471 {
      472 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
      473 	uinfo->count = 1;
      474 	uinfo->value.integer.min = 0;
      475 	uinfo->value.integer.max = 1;
      476 	return 0;
      477 }
      478 
      479 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
      480 			     struct snd_ctl_elem_value *ucontrol)
      481 {
      482 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      483 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      484 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
      485 	long *valp = ucontrol->value.integer.value;
      486 	unsigned int val = snd_hda_codec_read(codec, nid, 0,
      487 					      AC_VERB_GET_GPIO_DATA, 0x00);
      488 
      489 	*valp = (val & mask) != 0;
      490 	return 0;
      491 }
      492 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
      493 			     struct snd_ctl_elem_value *ucontrol)
      494 {
      495 	signed int change;
      496 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      497 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      498 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
      499 	long val = *ucontrol->value.integer.value;
      500 	unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
      501 						    AC_VERB_GET_GPIO_DATA,
      502 						    0x00);
      503 
      504 	/* Set/unset the masked GPIO bit(s) as needed */
      505 	change = (val == 0 ? 0 : mask) != (gpio_data & mask);
      506 	if (val == 0)
      507 		gpio_data &= ~mask;
      508 	else
      509 		gpio_data |= mask;
      510 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
      511 
      512 	return change;
      513 }
      514 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
      515 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
      516 	  .info = alc_gpio_data_info, \
      517 	  .get = alc_gpio_data_get, \
      518 	  .put = alc_gpio_data_put, \
      519 	  .private_value = nid | (mask<<16) }
      520 #endif   /* CONFIG_SND_DEBUG */
      521 
      522 /* A switch control to allow the enabling of the digital IO pins on the
      523  * ALC260.  This is incredibly simplistic; the intention of this control is
      524  * to provide something in the test model allowing digital outputs to be
      525  * identified if present.  If models are found which can utilise these
      526  * outputs a more complete mixer control can be devised for those models if
      527  * necessary.
      528  */
      529 #ifdef CONFIG_SND_DEBUG
      530 static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
      531 			       struct snd_ctl_elem_info *uinfo)
      532 {
      533 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
      534 	uinfo->count = 1;
      535 	uinfo->value.integer.min = 0;
      536 	uinfo->value.integer.max = 1;
      537 	return 0;
      538 }
      539 
      540 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
      541 			      struct snd_ctl_elem_value *ucontrol)
      542 {
      543 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      544 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      545 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
      546 	long *valp = ucontrol->value.integer.value;
      547 	unsigned int val = snd_hda_codec_read(codec, nid, 0,
      548 					      AC_VERB_GET_DIGI_CONVERT, 0x00);
      549 
      550 	*valp = (val & mask) != 0;
      551 	return 0;
      552 }
      553 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
      554 			      struct snd_ctl_elem_value *ucontrol)
      555 {
      556 	signed int change;
      557 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
      558 	hda_nid_t nid = kcontrol->private_value & 0xffff;
      559 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
      560 	long val = *ucontrol->value.integer.value;
      561 	unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
      562 						    AC_VERB_GET_DIGI_CONVERT,
      563 						    0x00);
      564 
      565 	/* Set/unset the masked control bit(s) as needed */
      566 	change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
      567 	if (val==0)
      568 		ctrl_data &= ~mask;
      569 	else
      570 		ctrl_data |= mask;
      571 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
      572 			    ctrl_data);
      573 
      574 	return change;
      575 }
      576 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
      577 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
      578 	  .info = alc_spdif_ctrl_info, \
      579 	  .get = alc_spdif_ctrl_get, \
      580 	  .put = alc_spdif_ctrl_put, \
      581 	  .private_value = nid | (mask<<16) }
      582 #endif   /* CONFIG_SND_DEBUG */
      583 
      584 /*
      585  * set up from the preset table
      586  */
      587 static void setup_preset(struct alc_spec *spec,
      588 			 const struct alc_config_preset *preset)
      589 {
      590 	int i;
      591 
      592 	for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
      593 		spec->mixers[spec->num_mixers++] = preset->mixers[i];
      594 	for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
      595 	     i++)
      596 		spec->init_verbs[spec->num_init_verbs++] =
      597 			preset->init_verbs[i];
      598 	
      599 	spec->channel_mode = preset->channel_mode;
      600 	spec->num_channel_mode = preset->num_channel_mode;
      601 	spec->need_dac_fix = preset->need_dac_fix;
      602 
      603 	spec->multiout.max_channels = spec->channel_mode[0].channels;
      604 
      605 	spec->multiout.num_dacs = preset->num_dacs;
      606 	spec->multiout.dac_nids = preset->dac_nids;
      607 	spec->multiout.dig_out_nid = preset->dig_out_nid;
      608 	spec->multiout.hp_nid = preset->hp_nid;
      609 	
      610 	spec->num_mux_defs = preset->num_mux_defs;
      611 	if (!spec->num_mux_defs)
      612 		spec->num_mux_defs = 1;
      613 	spec->input_mux = preset->input_mux;
      614 
      615 	spec->num_adc_nids = preset->num_adc_nids;
      616 	spec->adc_nids = preset->adc_nids;
      617 	spec->dig_in_nid = preset->dig_in_nid;
      618 
      619 	spec->unsol_event = preset->unsol_event;
      620 	spec->init_hook = preset->init_hook;
      621 }
      622 
      623 /* Enable GPIO mask and set output */
      624 static struct hda_verb alc_gpio1_init_verbs[] = {
      625 	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
      626 	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
      627 	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
      628 	{ }
      629 };
      630 
      631 static struct hda_verb alc_gpio2_init_verbs[] = {
      632 	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
      633 	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
      634 	{0x01, AC_VERB_SET_GPIO_DATA, 0x02},
      635 	{ }
      636 };
      637 
      638 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
      639  *	31 ~ 16 :	Manufacture ID
      640  *	15 ~ 8	:	SKU ID
      641  *	7  ~ 0	:	Assembly ID
      642  *	port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
      643  */
      644 static void alc_subsystem_id(struct hda_codec *codec,
      645 			     unsigned int porta, unsigned int porte,
      646 			     unsigned int portd)
      647 {
      648 	unsigned int ass, tmp;
      649 
      650 	ass = codec->subsystem_id;
      651 	if (!(ass & 1))
      652 		return;
      653 
      654 	/* Override */
      655 	tmp = (ass & 0x38) >> 3;	/* external Amp control */
      656 	switch (tmp) {
      657 	case 1:
      658 		snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
      659 		break;
      660 	case 3:
      661 		snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
      662 		break;
      663 	case 5:
      664 	case 6:
      665 		if (ass & 4) {	/* bit 2 : 0 = Desktop, 1 = Laptop */
      666 			hda_nid_t port = 0;
      667 			tmp = (ass & 0x1800) >> 11;
      668 			switch (tmp) {
      669 			case 0: port = porta; break;
      670 			case 1: port = porte; break;
      671 			case 2: port = portd; break;
      672 			}
      673 			if (port)
      674 				snd_hda_codec_write(codec, port, 0,
      675 						    AC_VERB_SET_EAPD_BTLENABLE,
      676 						    2);
      677 		}
      678 		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
      679 		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF,
      680 				    (tmp == 5 ? 0x3040 : 0x3050));
      681 		break;
      682 	}
      683 }
      684 
      685 /*
      686  * ALC880 3-stack model
      687  *
      688  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
      689  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
      690  *                 F-Mic = 0x1b, HP = 0x19
      691  */
      692 
      693 static hda_nid_t alc880_dac_nids[4] = {
      694 	/* front, rear, clfe, rear_surr */
      695 	0x02, 0x05, 0x04, 0x03
      696 };
      697 
      698 static hda_nid_t alc880_adc_nids[3] = {
      699 	/* ADC0-2 */
      700 	0x07, 0x08, 0x09,
      701 };
      702 
      703 /* The datasheet says the node 0x07 is connected from inputs,
      704  * but it shows zero connection in the real implementation on some devices.
      705  * Note: this is a 915GAV bug, fixed on 915GLV
      706  */
      707 static hda_nid_t alc880_adc_nids_alt[2] = {
      708 	/* ADC1-2 */
      709 	0x08, 0x09,
      710 };
      711 
      712 #define ALC880_DIGOUT_NID	0x06
      713 #define ALC880_DIGIN_NID	0x0a
      714 
      715 static struct hda_input_mux alc880_capture_source = {
      716 	.num_items = 4,
      717 	.items = {
      718 		{ "Mic", 0x0 },
      719 		{ "Front Mic", 0x3 },
      720 		{ "Line", 0x2 },
      721 		{ "CD", 0x4 },
      722 	},
      723 };
      724 
      725 /* channel source setting (2/6 channel selection for 3-stack) */
      726 /* 2ch mode */
      727 static struct hda_verb alc880_threestack_ch2_init[] = {
      728 	/* set line-in to input, mute it */
      729 	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
      730 	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
      731 	/* set mic-in to input vref 80%, mute it */
      732 	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
      733 	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
      734 	{ } /* end */
      735 };
      736 
      737 /* 6ch mode */
      738 static struct hda_verb alc880_threestack_ch6_init[] = {
      739 	/* set line-in to output, unmute it */
      740 	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
      741 	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
      742 	/* set mic-in to output, unmute it */
      743 	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
      744 	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
      745 	{ } /* end */
      746 };
      747 
      748 static struct hda_channel_mode alc880_threestack_modes[2] = {
      749 	{ 2, alc880_threestack_ch2_init },
      750 	{ 6, alc880_threestack_ch6_init },
      751 };
      752 
      753 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
      754 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
      755 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
      756 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
      757 	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
      758 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
      759 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
      760 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
      761 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
      762 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
      763 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
      764 	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
      765 	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
      766 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
      767 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
      768 	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
      769 	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
      770 	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
      771 	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
      772 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
      773 	{
      774 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
      775 		.name = "Channel Mode",
      776 		.info = alc_ch_mode_info,
      777 		.get = alc_ch_mode_get,
      778 		.put = alc_ch_mode_put,
      779 	},
      780 	{ } /* end */
      781 };
      782 
      783 /* capture mixer elements */
      784 static struct snd_kcontrol_new alc880_capture_mixer[] = {
      785 	HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
      786 	HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
      787 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
      788 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
      789 	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
      790 	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
      791 	{
      792 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
      793 		/* The multiple "Capture Source" controls confuse alsamixer
      794 		 * So call somewhat different..
      795 		 * FIXME: the controls appear in the "playback" view!
      796 		 */
      797 		/* .name = "Capture Source", */
      798 		.name = "Input Source",
      799 		.count = 3,
      800 		.info = alc_mux_enum_info,
      801 		.get = alc_mux_enum_get,
      802 		.put = alc_mux_enum_put,
      803 	},
      804 	{ } /* end */
      805 };
      806 
      807 /* capture mixer elements (in case NID 0x07 not available) */
      808 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
      809 	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
      810 	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
      811 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
      812 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
      813 	{
      814 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
      815 		/* The multiple "Capture Source" controls confuse alsamixer
      816 		 * So call somewhat different..
      817 		 * FIXME: the controls appear in the "playback" view!
      818 		 */
      819 		/* .name = "Capture Source", */
      820 		.name = "Input Source",
      821 		.count = 2,
      822 		.info = alc_mux_enum_info,
      823 		.get = alc_mux_enum_get,
      824 		.put = alc_mux_enum_put,
      825 	},
      826 	{ } /* end */
      827 };
      828 
      829 
      830 
      831 /*
      832  * ALC880 5-stack model
      833  *
      834  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
      835  *      Side = 0x02 (0xd)
      836  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
      837  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
      838  */
      839 
      840 /* additional mixers to alc880_three_stack_mixer */
      841 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
      842 	HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
      843 	HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
      844 	{ } /* end */
      845 };
      846 
      847 /* channel source setting (6/8 channel selection for 5-stack) */
      848 /* 6ch mode */
      849 static struct hda_verb alc880_fivestack_ch6_init[] = {
      850 	/* set line-in to input, mute it */
      851 	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
      852 	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
      853 	{ } /* end */
      854 };
      855 
      856 /* 8ch mode */
      857 static struct hda_verb alc880_fivestack_ch8_init[] = {
      858 	/* set line-in to output, unmute it */
      859 	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
      860 	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
      861 	{ } /* end */
      862 };
      863 
      864 static struct hda_channel_mode alc880_fivestack_modes[2] = {
      865 	{ 6, alc880_fivestack_ch6_init },
      866 	{ 8, alc880_fivestack_ch8_init },
      867 };
      868 
      869 
      870 /*
      871  * ALC880 6-stack model
      872  *
      873  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
      874  *      Side = 0x05 (0x0f)
      875  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
      876  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
      877  */
      878 
      879 static hda_nid_t alc880_6st_dac_nids[4] = {
      880 	/* front, rear, clfe, rear_surr */
      881 	0x02, 0x03, 0x04, 0x05
      882 };
      883 
      884 static struct hda_input_mux alc880_6stack_capture_source = {
      885 	.num_items = 4,
      886 	.items = {
      887 		{ "Mic", 0x0 },
      888 		{ "Front Mic", 0x1 },
      889 		{ "Line", 0x2 },
      890 		{ "CD", 0x4 },
      891 	},
      892 };
      893 
      894 /* fixed 8-channels */
      895 static struct hda_channel_mode alc880_sixstack_modes[1] = {
      896 	{ 8, NULL },
      897 };
      898 
      899 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
      900 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
      901 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
      902 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
      903 	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
      904 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
      905 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
      906 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
      907 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
      908 	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
      909 	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
      910 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
      911 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
      912 	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
      913 	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
      914 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
      915 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
      916 	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
      917 	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
      918 	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
      919 	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
      920 	{
      921 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
      922 		.name = "Channel Mode",
      923 		.info = alc_ch_mode_info,
      924 		.get = alc_ch_mode_get,
      925 		.put = alc_ch_mode_put,
      926 	},
      927 	{ } /* end */
      928 };
      929 
      930 
      931 /*
      932  * ALC880 W810 model
      933  *
      934  * W810 has rear IO for:
      935  * Front (DAC 02)
      936  * Surround (DAC 03)
      937  * Center/LFE (DAC 04)
      938  * Digital out (06)
      939  *
      940  * The system also has a pair of internal speakers, and a headphone jack.
      941  * These are both connected to Line2 on the codec, hence to DAC 02.
      942  * 
      943  * There is a variable resistor to control the speaker or headphone
      944  * volume. This is a hardware-only device without a software API.
      945  *
      946  * Plugging headphones in will disable the internal speakers. This is
      947  * implemented in hardware, not via the driver using jack sense. In
      948  * a similar fashion, plugging into the rear socket marked "front" will
      949  * disable both the speakers and headphones.
      950  *
      951  * For input, there's a microphone jack, and an "audio in" jack.
      952  * These may not do anything useful with this driver yet, because I
      953  * haven't setup any initialization verbs for these yet...
      954  */
      955 
      956 static hda_nid_t alc880_w810_dac_nids[3] = {
      957 	/* front, rear/surround, clfe */
      958 	0x02, 0x03, 0x04
      959 };
      960 
      961 /* fixed 6 channels */
      962 static struct hda_channel_mode alc880_w810_modes[1] = {
      963 	{ 6, NULL }
      964 };
      965 
      966 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
      967 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
      968 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
      969 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
      970 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
      971 	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
      972 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
      973 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
      974 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
      975 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
      976 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
      977 	{ } /* end */
      978 };
      979 
      980 
      981 /*
      982  * Z710V model
      983  *
      984  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
      985  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
      986  *                 Line = 0x1a
      987  */
      988 
      989 static hda_nid_t alc880_z71v_dac_nids[1] = {
      990 	0x02
      991 };
      992 #define ALC880_Z71V_HP_DAC	0x03
      993 
      994 /* fixed 2 channels */
      995 static struct hda_channel_mode alc880_2_jack_modes[1] = {
      996 	{ 2, NULL }
      997 };
      998 
      999 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
     1000 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1001 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
     1002 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1003 	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
     1004 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     1005 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     1006 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1007 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1008 	{ } /* end */
     1009 };
     1010 
     1011 
     1012 /* FIXME! */
     1013 /*
     1014  * ALC880 F1734 model
     1015  *
     1016  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
     1017  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
     1018  */
     1019 
     1020 static hda_nid_t alc880_f1734_dac_nids[1] = {
     1021 	0x03
     1022 };
     1023 #define ALC880_F1734_HP_DAC	0x02
     1024 
     1025 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
     1026 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1027 	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
     1028 	HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1029 	HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
     1030 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     1031 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     1032 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1033 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1034 	{ } /* end */
     1035 };
     1036 
     1037 
     1038 /* FIXME! */
     1039 /*
     1040  * ALC880 ASUS model
     1041  *
     1042  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
     1043  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
     1044  *  Mic = 0x18, Line = 0x1a
     1045  */
     1046 
     1047 #define alc880_asus_dac_nids	alc880_w810_dac_nids	/* identical with w810 */
     1048 #define alc880_asus_modes	alc880_threestack_modes	/* 2/6 channel mode */
     1049 
     1050 static struct snd_kcontrol_new alc880_asus_mixer[] = {
     1051 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1052 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
     1053 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1054 	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
     1055 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
     1056 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
     1057 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
     1058 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
     1059 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     1060 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     1061 	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
     1062 	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
     1063 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1064 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1065 	{
     1066 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1067 		.name = "Channel Mode",
     1068 		.info = alc_ch_mode_info,
     1069 		.get = alc_ch_mode_get,
     1070 		.put = alc_ch_mode_put,
     1071 	},
     1072 	{ } /* end */
     1073 };
     1074 
     1075 /* FIXME! */
     1076 /*
     1077  * ALC880 ASUS W1V model
     1078  *
     1079  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
     1080  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
     1081  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
     1082  */
     1083 
     1084 /* additional mixers to alc880_asus_mixer */
     1085 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
     1086 	HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
     1087 	HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
     1088 	{ } /* end */
     1089 };
     1090 
     1091 /* additional mixers to alc880_asus_mixer */
     1092 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
     1093 	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
     1094 	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
     1095 	{ } /* end */
     1096 };
     1097 
     1098 /* TCL S700 */
     1099 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
     1100 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1101 	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
     1102 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
     1103 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
     1104 	HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
     1105 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
     1106 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
     1107 	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
     1108 	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
     1109 	{
     1110 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1111 		/* The multiple "Capture Source" controls confuse alsamixer
     1112 		 * So call somewhat different..
     1113 		 * FIXME: the controls appear in the "playback" view!
     1114 		 */
     1115 		/* .name = "Capture Source", */
     1116 		.name = "Input Source",
     1117 		.count = 1,
     1118 		.info = alc_mux_enum_info,
     1119 		.get = alc_mux_enum_get,
     1120 		.put = alc_mux_enum_put,
     1121 	},
     1122 	{ } /* end */
     1123 };
     1124 
     1125 /* Uniwill */
     1126 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
     1127 	HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1128 	HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
     1129 	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1130 	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
     1131 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
     1132 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
     1133 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
     1134 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
     1135 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     1136 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     1137 	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
     1138 	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
     1139 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1140 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1141 	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
     1142 	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
     1143 	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
     1144 	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
     1145 	{
     1146 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1147 		.name = "Channel Mode",
     1148 		.info = alc_ch_mode_info,
     1149 		.get = alc_ch_mode_get,
     1150 		.put = alc_ch_mode_put,
     1151 	},
     1152 	{ } /* end */
     1153 };
     1154 
     1155 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
     1156 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1157 	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
     1158 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1159 	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
     1160 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     1161 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     1162 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1163 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1164 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
     1165 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
     1166 	{ } /* end */
     1167 };
     1168 
     1169 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
     1170 	HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1171 	HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
     1172 	HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     1173 	HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
     1174 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1175 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1176 	{ } /* end */
     1177 };
     1178 
     1179 /*
     1180  * build control elements
     1181  */
     1182 static int alc_build_controls(struct hda_codec *codec)
     1183 {
     1184 	struct alc_spec *spec = codec->spec;
     1185 	int err;
     1186 	int i;
     1187 
     1188 	for (i = 0; i < spec->num_mixers; i++) {
     1189 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
     1190 		if (err < 0)
     1191 			return err;
     1192 	}
     1193 
     1194 	if (spec->multiout.dig_out_nid) {
     1195 		err = snd_hda_create_spdif_out_ctls(codec,
     1196 						    spec->multiout.dig_out_nid);
     1197 		if (err < 0)
     1198 			return err;
     1199 	}
     1200 	if (spec->dig_in_nid) {
     1201 		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
     1202 		if (err < 0)
     1203 			return err;
     1204 	}
     1205 	return 0;
     1206 }
     1207 
     1208 
     1209 /*
     1210  * initialize the codec volumes, etc
     1211  */
     1212 
     1213 /*
     1214  * generic initialization of ADC, input mixers and output mixers
     1215  */
     1216 static struct hda_verb alc880_volume_init_verbs[] = {
     1217 	/*
     1218 	 * Unmute ADC0-2 and set the default input to mic-in
     1219 	 */
     1220 	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
     1221 	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1222 	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
     1223 	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1224 	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
     1225 	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1226 
     1227 	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
     1228 	 * mixer widget
     1229 	 * Note: PASD motherboards uses the Line In 2 as the input for front
     1230 	 * panel mic (mic 2)
     1231 	 */
     1232 	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
     1233 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1234 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1235 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
     1236 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
     1237 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
     1238 
     1239 	/*
     1240 	 * Set up output mixers (0x0c - 0x0f)
     1241 	 */
     1242 	/* set vol=0 to output mixers */
     1243 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     1244 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     1245 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     1246 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     1247 	/* set up input amps for analog loopback */
     1248 	/* Amp Indices: DAC = 0, mixer = 1 */
     1249 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     1250 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     1251 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     1252 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     1253 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     1254 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     1255 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     1256 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     1257 
     1258 	{ }
     1259 };
     1260 
     1261 /*
     1262  * 3-stack pin configuration:
     1263  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
     1264  */
     1265 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
     1266 	/*
     1267 	 * preset connection lists of input pins
     1268 	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
     1269 	 */
     1270 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
     1271 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
     1272 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
     1273 
     1274 	/*
     1275 	 * Set pin mode and muting
     1276 	 */
     1277 	/* set front pin widgets 0x14 for output */
     1278 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1279 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1280 	/* Mic1 (rear panel) pin widget for input and vref at 80% */
     1281 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1282 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1283 	/* Mic2 (as headphone out) for HP output */
     1284 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1285 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1286 	/* Line In pin widget for input */
     1287 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1288 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1289 	/* Line2 (as front mic) pin widget for input and vref at 80% */
     1290 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1291 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1292 	/* CD pin widget for input */
     1293 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1294 
     1295 	{ }
     1296 };
     1297 
     1298 /*
     1299  * 5-stack pin configuration:
     1300  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
     1301  * line-in/side = 0x1a, f-mic = 0x1b
     1302  */
     1303 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
     1304 	/*
     1305 	 * preset connection lists of input pins
     1306 	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
     1307 	 */
     1308 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
     1309 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
     1310 
     1311 	/*
     1312 	 * Set pin mode and muting
     1313 	 */
     1314 	/* set pin widgets 0x14-0x17 for output */
     1315 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1316 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1317 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1318 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1319 	/* unmute pins for output (no gain on this amp) */
     1320 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1321 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1322 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1323 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1324 
     1325 	/* Mic1 (rear panel) pin widget for input and vref at 80% */
     1326 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1327 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1328 	/* Mic2 (as headphone out) for HP output */
     1329 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1330 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1331 	/* Line In pin widget for input */
     1332 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1333 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1334 	/* Line2 (as front mic) pin widget for input and vref at 80% */
     1335 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1336 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1337 	/* CD pin widget for input */
     1338 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1339 
     1340 	{ }
     1341 };
     1342 
     1343 /*
     1344  * W810 pin configuration:
     1345  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
     1346  */
     1347 static struct hda_verb alc880_pin_w810_init_verbs[] = {
     1348 	/* hphone/speaker input selector: front DAC */
     1349 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
     1350 
     1351 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1352 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1353 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1354 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1355 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1356 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1357 
     1358 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1359 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1360 
     1361 	{ }
     1362 };
     1363 
     1364 /*
     1365  * Z71V pin configuration:
     1366  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
     1367  */
     1368 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
     1369 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1370 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1371 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1372 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1373 
     1374 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1375 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1376 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1377 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1378 
     1379 	{ }
     1380 };
     1381 
     1382 /*
     1383  * 6-stack pin configuration:
     1384  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
     1385  * f-mic = 0x19, line = 0x1a, HP = 0x1b
     1386  */
     1387 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
     1388 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
     1389 
     1390 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1391 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1392 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1393 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1394 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1395 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1396 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1397 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1398 
     1399 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1400 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1401 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1402 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1403 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1404 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1405 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1406 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1407 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1408 	
     1409 	{ }
     1410 };
     1411 
     1412 /*
     1413  * Uniwill pin configuration:
     1414  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
     1415  * line = 0x1a
     1416  */
     1417 static struct hda_verb alc880_uniwill_init_verbs[] = {
     1418 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
     1419 
     1420 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1421 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1422 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1423 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1424 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1425 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1426 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1427 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1428 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1429 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1430 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1431 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1432 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1433 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1434 
     1435 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1436 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1437 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1438 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1439 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1440 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1441 	/* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
     1442 	/* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
     1443 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1444 
     1445 	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
     1446 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
     1447 
     1448 	{ }
     1449 };
     1450 
     1451 /*
     1452 * Uniwill P53
     1453 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
     1454  */
     1455 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
     1456 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
     1457 
     1458 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1459 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1460 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1461 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1462 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1463 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1464 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1465 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1466 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1467 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1468 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
     1469 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
     1470 
     1471 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1472 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1473 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1474 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1475 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1476 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1477 
     1478 	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
     1479 	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
     1480 
     1481 	{ }
     1482 };
     1483 
     1484 static struct hda_verb alc880_beep_init_verbs[] = {
     1485 	{ 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
     1486 	{ }
     1487 };
     1488 
     1489 /* toggle speaker-output according to the hp-jack state */
     1490 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
     1491 {
     1492  	unsigned int present;
     1493 	unsigned char bits;
     1494 
     1495  	present = snd_hda_codec_read(codec, 0x14, 0,
     1496 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1497 	bits = present ? 0x80 : 0;
     1498 	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
     1499 				 0x80, bits);
     1500 	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
     1501 				 0x80, bits);
     1502 	snd_hda_codec_amp_update(codec, 0x16, 0, HDA_OUTPUT, 0,
     1503 				 0x80, bits);
     1504 	snd_hda_codec_amp_update(codec, 0x16, 1, HDA_OUTPUT, 0,
     1505 				 0x80, bits);
     1506 }
     1507 
     1508 /* auto-toggle front mic */
     1509 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
     1510 {
     1511  	unsigned int present;
     1512 	unsigned char bits;
     1513 
     1514 	present = snd_hda_codec_read(codec, 0x18, 0,
     1515 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1516 	bits = present ? 0x80 : 0;
     1517 	snd_hda_codec_amp_update(codec, 0x0b, 0, HDA_INPUT, 1,
     1518 				 0x80, bits);
     1519 	snd_hda_codec_amp_update(codec, 0x0b, 1, HDA_INPUT, 1,
     1520 				 0x80, bits);
     1521 }
     1522 
     1523 static void alc880_uniwill_automute(struct hda_codec *codec)
     1524 {
     1525 	alc880_uniwill_hp_automute(codec);
     1526 	alc880_uniwill_mic_automute(codec);
     1527 }
     1528 
     1529 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
     1530 				       unsigned int res)
     1531 {
     1532 	/* Looks like the unsol event is incompatible with the standard
     1533 	 * definition.  4bit tag is placed at 28 bit!
     1534 	 */
     1535 	switch (res >> 28) {
     1536 	case ALC880_HP_EVENT:
     1537 		alc880_uniwill_hp_automute(codec);
     1538 		break;
     1539 	case ALC880_MIC_EVENT:
     1540 		alc880_uniwill_mic_automute(codec);
     1541 		break;
     1542 	}
     1543 }
     1544 
     1545 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
     1546 {
     1547  	unsigned int present;
     1548 	unsigned char bits;
     1549 
     1550  	present = snd_hda_codec_read(codec, 0x14, 0,
     1551 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1552 	bits = present ? 0x80 : 0;
     1553 	snd_hda_codec_amp_update(codec, 0x15, 0, HDA_INPUT, 0,
     1554 				 0x80, bits);
     1555 	snd_hda_codec_amp_update(codec, 0x15, 1, HDA_INPUT, 0,
     1556 				 0x80, bits);
     1557 }
     1558 
     1559 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
     1560 {
     1561 	unsigned int present;
     1562 	
     1563 	present = snd_hda_codec_read(codec, 0x21, 0,
     1564 				     AC_VERB_GET_VOLUME_KNOB_CONTROL, 0) & 0x7f;
     1565 
     1566 	snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
     1567 				 0x7f, present);
     1568 	snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
     1569 				 0x7f,  present);
     1570 
     1571 	snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
     1572 				 0x7f,  present);
     1573 	snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
     1574 				 0x7f, present);
     1575 
     1576 }
     1577 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
     1578 					   unsigned int res)
     1579 {
     1580 	/* Looks like the unsol event is incompatible with the standard
     1581 	 * definition.  4bit tag is placed at 28 bit!
     1582 	 */
     1583 	if ((res >> 28) == ALC880_HP_EVENT)
     1584 		alc880_uniwill_p53_hp_automute(codec);
     1585 	if ((res >> 28) == ALC880_DCVOL_EVENT)
     1586 		alc880_uniwill_p53_dcvol_automute(codec);
     1587 }
     1588 
     1589 /* FIXME! */
     1590 /*
     1591  * F1734 pin configuration:
     1592  * HP = 0x14, speaker-out = 0x15, mic = 0x18
     1593  */
     1594 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
     1595 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
     1596 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
     1597 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
     1598 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
     1599 
     1600 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1601 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1602 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1603 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1604 
     1605 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1606 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1607 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1608 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1609 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1610 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1611 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1612 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1613 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1614 
     1615 	{ }
     1616 };
     1617 
     1618 /* FIXME! */
     1619 /*
     1620  * ASUS pin configuration:
     1621  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
     1622  */
     1623 static struct hda_verb alc880_pin_asus_init_verbs[] = {
     1624 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
     1625 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
     1626 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
     1627 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
     1628 
     1629 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1630 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1631 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1632 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1633 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1634 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1635 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1636 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1637 
     1638 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1639 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1640 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1641 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1642 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1643 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     1644 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1645 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1646 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1647 	
     1648 	{ }
     1649 };
     1650 
     1651 /* Enable GPIO mask and set output */
     1652 #define alc880_gpio1_init_verbs	alc_gpio1_init_verbs
     1653 #define alc880_gpio2_init_verbs	alc_gpio2_init_verbs
     1654 
     1655 /* Clevo m520g init */
     1656 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
     1657 	/* headphone output */
     1658 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
     1659 	/* line-out */
     1660 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1661 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1662 	/* Line-in */
     1663 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1664 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1665 	/* CD */
     1666 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1667 	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1668 	/* Mic1 (rear panel) */
     1669 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1670 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1671 	/* Mic2 (front panel) */
     1672 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1673 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1674 	/* headphone */
     1675 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1676 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1677         /* change to EAPD mode */
     1678 	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
     1679 	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},
     1680 
     1681 	{ }
     1682 };
     1683 
     1684 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
     1685 	/* change to EAPD mode */
     1686 	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
     1687 	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},
     1688 
     1689 	/* Headphone output */
     1690 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1691 	/* Front output*/
     1692 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     1693 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
     1694 
     1695 	/* Line In pin widget for input */
     1696 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1697 	/* CD pin widget for input */
     1698 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1699 	/* Mic1 (rear panel) pin widget for input and vref at 80% */
     1700 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1701 
     1702 	/* change to EAPD mode */
     1703 	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
     1704 	{0x20, AC_VERB_SET_PROC_COEF,  0x3070},
     1705 
     1706 	{ }
     1707 };
     1708 
     1709 /*
     1710  * LG m1 express dual
     1711  *
     1712  * Pin assignment:
     1713  *   Rear Line-In/Out (blue): 0x14
     1714  *   Build-in Mic-In: 0x15
     1715  *   Speaker-out: 0x17
     1716  *   HP-Out (green): 0x1b
     1717  *   Mic-In/Out (red): 0x19
     1718  *   SPDIF-Out: 0x1e
     1719  */
     1720 
     1721 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
     1722 static hda_nid_t alc880_lg_dac_nids[3] = {
     1723 	0x05, 0x02, 0x03
     1724 };
     1725 
     1726 /* seems analog CD is not working */
     1727 static struct hda_input_mux alc880_lg_capture_source = {
     1728 	.num_items = 3,
     1729 	.items = {
     1730 		{ "Mic", 0x1 },
     1731 		{ "Line", 0x5 },
     1732 		{ "Internal Mic", 0x6 },
     1733 	},
     1734 };
     1735 
     1736 /* 2,4,6 channel modes */
     1737 static struct hda_verb alc880_lg_ch2_init[] = {
     1738 	/* set line-in and mic-in to input */
     1739 	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
     1740 	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
     1741 	{ }
     1742 };
     1743 
     1744 static struct hda_verb alc880_lg_ch4_init[] = {
     1745 	/* set line-in to out and mic-in to input */
     1746 	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1747 	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
     1748 	{ }
     1749 };
     1750 
     1751 static struct hda_verb alc880_lg_ch6_init[] = {
     1752 	/* set line-in and mic-in to output */
     1753 	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1754 	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1755 	{ }
     1756 };
     1757 
     1758 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
     1759 	{ 2, alc880_lg_ch2_init },
     1760 	{ 4, alc880_lg_ch4_init },
     1761 	{ 6, alc880_lg_ch6_init },
     1762 };
     1763 
     1764 static struct snd_kcontrol_new alc880_lg_mixer[] = {
     1765 	/* FIXME: it's not really "master" but front channels */
     1766 	HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
     1767 	HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
     1768 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1769 	HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
     1770 	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
     1771 	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
     1772 	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
     1773 	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
     1774 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
     1775 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
     1776 	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
     1777 	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
     1778 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
     1779 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
     1780 	{
     1781 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1782 		.name = "Channel Mode",
     1783 		.info = alc_ch_mode_info,
     1784 		.get = alc_ch_mode_get,
     1785 		.put = alc_ch_mode_put,
     1786 	},
     1787 	{ } /* end */
     1788 };
     1789 
     1790 static struct hda_verb alc880_lg_init_verbs[] = {
     1791 	/* set capture source to mic-in */
     1792 	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1793 	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1794 	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1795 	/* mute all amp mixer inputs */
     1796 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
     1797 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
     1798 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
     1799 	/* line-in to input */
     1800 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1801 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1802 	/* built-in mic */
     1803 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1804 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1805 	/* speaker-out */
     1806 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1807 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1808 	/* mic-in to input */
     1809 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
     1810 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1811 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1812 	/* HP-out */
     1813 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
     1814 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1815 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1816 	/* jack sense */
     1817 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
     1818 	{ }
     1819 };
     1820 
     1821 /* toggle speaker-output according to the hp-jack state */
     1822 static void alc880_lg_automute(struct hda_codec *codec)
     1823 {
     1824 	unsigned int present;
     1825 	unsigned char bits;
     1826 
     1827 	present = snd_hda_codec_read(codec, 0x1b, 0,
     1828 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1829 	bits = present ? 0x80 : 0;
     1830 	snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
     1831 				 0x80, bits);
     1832 	snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
     1833 				 0x80, bits);
     1834 }
     1835 
     1836 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
     1837 {
     1838 	/* Looks like the unsol event is incompatible with the standard
     1839 	 * definition.  4bit tag is placed at 28 bit!
     1840 	 */
     1841 	if ((res >> 28) == 0x01)
     1842 		alc880_lg_automute(codec);
     1843 }
     1844 
     1845 /*
     1846  * LG LW20
     1847  *
     1848  * Pin assignment:
     1849  *   Speaker-out: 0x14
     1850  *   Mic-In: 0x18
     1851  *   Built-in Mic-In: 0x19 (?)
     1852  *   HP-Out: 0x1b
     1853  *   SPDIF-Out: 0x1e
     1854  */
     1855 
     1856 /* seems analog CD is not working */
     1857 static struct hda_input_mux alc880_lg_lw_capture_source = {
     1858 	.num_items = 2,
     1859 	.items = {
     1860 		{ "Mic", 0x0 },
     1861 		{ "Internal Mic", 0x1 },
     1862 	},
     1863 };
     1864 
     1865 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
     1866 	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1867 	HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
     1868 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1869 	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1870 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
     1871 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
     1872 	{ } /* end */
     1873 };
     1874 
     1875 static struct hda_verb alc880_lg_lw_init_verbs[] = {
     1876 	/* set capture source to mic-in */
     1877 	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1878 	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1879 	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1880 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
     1881 	/* speaker-out */
     1882 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1883 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1884 	/* HP-out */
     1885 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
     1886 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1887 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1888 	/* mic-in to input */
     1889 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1890 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1891 	/* built-in mic */
     1892 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1893 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1894 	/* jack sense */
     1895 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
     1896 	{ }
     1897 };
     1898 
     1899 /* toggle speaker-output according to the hp-jack state */
     1900 static void alc880_lg_lw_automute(struct hda_codec *codec)
     1901 {
     1902 	unsigned int present;
     1903 	unsigned char bits;
     1904 
     1905 	present = snd_hda_codec_read(codec, 0x1b, 0,
     1906 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1907 	bits = present ? 0x80 : 0;
     1908 	snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
     1909 				 0x80, bits);
     1910 	snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
     1911 				 0x80, bits);
     1912 }
     1913 
     1914 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
     1915 {
     1916 	/* Looks like the unsol event is incompatible with the standard
     1917 	 * definition.  4bit tag is placed at 28 bit!
     1918 	 */
     1919 	if ((res >> 28) == 0x01)
     1920 		alc880_lg_lw_automute(codec);
     1921 }
     1922 
     1923 /*
     1924  * Common callbacks
     1925  */
     1926 
     1927 static int alc_init(struct hda_codec *codec)
     1928 {
     1929 	struct alc_spec *spec = codec->spec;
     1930 	unsigned int i;
     1931 
     1932 	for (i = 0; i < spec->num_init_verbs; i++)
     1933 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
     1934 
     1935 	if (spec->init_hook)
     1936 		spec->init_hook(codec);
     1937 
     1938 	return 0;
     1939 }
     1940 
     1941 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
     1942 {
     1943 	struct alc_spec *spec = codec->spec;
     1944 
     1945 	if (spec->unsol_event)
     1946 		spec->unsol_event(codec, res);
     1947 }
     1948 
     1949 #ifdef CONFIG_PM
     1950 /*
     1951  * resume
     1952  */
     1953 static int alc_resume(struct hda_codec *codec)
     1954 {
     1955 	struct alc_spec *spec = codec->spec;
     1956 	int i;
     1957 
     1958 	alc_init(codec);
     1959 	for (i = 0; i < spec->num_mixers; i++)
     1960 		snd_hda_resume_ctls(codec, spec->mixers[i]);
     1961 	if (spec->multiout.dig_out_nid)
     1962 		snd_hda_resume_spdif_out(codec);
     1963 	if (spec->dig_in_nid)
     1964 		snd_hda_resume_spdif_in(codec);
     1965 
     1966 	return 0;
     1967 }
     1968 #endif
     1969 
     1970 /*
     1971  * Analog playback callbacks
     1972  */
     1973 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
     1974 				    struct hda_codec *codec,
     1975 				    struct snd_pcm_substream *substream)
     1976 {
     1977 	struct alc_spec *spec = codec->spec;
     1978 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
     1979 }
     1980 
     1981 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
     1982 				       struct hda_codec *codec,
     1983 				       unsigned int stream_tag,
     1984 				       unsigned int format,
     1985 				       struct snd_pcm_substream *substream)
     1986 {
     1987 	struct alc_spec *spec = codec->spec;
     1988 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
     1989 						stream_tag, format, substream);
     1990 }
     1991 
     1992 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
     1993 				       struct hda_codec *codec,
     1994 				       struct snd_pcm_substream *substream)
     1995 {
     1996 	struct alc_spec *spec = codec->spec;
     1997 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
     1998 }
     1999 
     2000 /*
     2001  * Digital out
     2002  */
     2003 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
     2004 					struct hda_codec *codec,
     2005 					struct snd_pcm_substream *substream)
     2006 {
     2007 	struct alc_spec *spec = codec->spec;
     2008 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
     2009 }
     2010 
     2011 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
     2012 					   struct hda_codec *codec,
     2013 					   unsigned int stream_tag,
     2014 					   unsigned int format,
     2015 					   struct snd_pcm_substream *substream)
     2016 {
     2017 	struct alc_spec *spec = codec->spec;
     2018 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
     2019 					     stream_tag, format, substream);
     2020 }
     2021 
     2022 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
     2023 					 struct hda_codec *codec,
     2024 					 struct snd_pcm_substream *substream)
     2025 {
     2026 	struct alc_spec *spec = codec->spec;
     2027 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
     2028 }
     2029 
     2030 /*
     2031  * Analog capture
     2032  */
     2033 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
     2034 				      struct hda_codec *codec,
     2035 				      unsigned int stream_tag,
     2036 				      unsigned int format,
     2037 				      struct snd_pcm_substream *substream)
     2038 {
     2039 	struct alc_spec *spec = codec->spec;
     2040 
     2041 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
     2042 				   stream_tag, 0, format);
     2043 	return 0;
     2044 }
     2045 
     2046 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
     2047 				      struct hda_codec *codec,
     2048 				      struct snd_pcm_substream *substream)
     2049 {
     2050 	struct alc_spec *spec = codec->spec;
     2051 
     2052 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
     2053 				   0, 0, 0);
     2054 	return 0;
     2055 }
     2056 
     2057 
     2058 /*
     2059  */
     2060 static struct hda_pcm_stream alc880_pcm_analog_playback = {
     2061 	.substreams = 1,
     2062 	.channels_min = 2,
     2063 	.channels_max = 8,
     2064 	/* NID is set in alc_build_pcms */
     2065 	.ops = {
     2066 		.open = alc880_playback_pcm_open,
     2067 		.prepare = alc880_playback_pcm_prepare,
     2068 		.cleanup = alc880_playback_pcm_cleanup
     2069 	},
     2070 };
     2071 
     2072 static struct hda_pcm_stream alc880_pcm_analog_capture = {
     2073 	.substreams = 2,
     2074 	.channels_min = 2,
     2075 	.channels_max = 2,
     2076 	/* NID is set in alc_build_pcms */
     2077 	.ops = {
     2078 		.prepare = alc880_capture_pcm_prepare,
     2079 		.cleanup = alc880_capture_pcm_cleanup
     2080 	},
     2081 };
     2082 
     2083 static struct hda_pcm_stream alc880_pcm_digital_playback = {
     2084 	.substreams = 1,
     2085 	.channels_min = 2,
     2086 	.channels_max = 2,
     2087 	/* NID is set in alc_build_pcms */
     2088 	.ops = {
     2089 		.open = alc880_dig_playback_pcm_open,
     2090 		.close = alc880_dig_playback_pcm_close,
     2091 		.prepare = alc880_dig_playback_pcm_prepare
     2092 	},
     2093 };
     2094 
     2095 static struct hda_pcm_stream alc880_pcm_digital_capture = {
     2096 	.substreams = 1,
     2097 	.channels_min = 2,
     2098 	.channels_max = 2,
     2099 	/* NID is set in alc_build_pcms */
     2100 };
     2101 
     2102 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
     2103 static struct hda_pcm_stream alc_pcm_null_playback = {
     2104 	.substreams = 0,
     2105 	.channels_min = 0,
     2106 	.channels_max = 0,
     2107 };
     2108 
     2109 static int alc_build_pcms(struct hda_codec *codec)
     2110 {
     2111 	struct alc_spec *spec = codec->spec;
     2112 	struct hda_pcm *info = spec->pcm_rec;
     2113 	int i;
     2114 
     2115 	codec->num_pcms = 1;
     2116 	codec->pcm_info = info;
     2117 
     2118 	info->name = spec->stream_name_analog;
     2119 	if (spec->stream_analog_playback) {
     2120 		snd_assert(spec->multiout.dac_nids, return -EINVAL);
     2121 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
     2122 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
     2123 	}
     2124 	if (spec->stream_analog_capture) {
     2125 		snd_assert(spec->adc_nids, return -EINVAL);
     2126 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
     2127 		info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
     2128 	}
     2129 
     2130 	if (spec->channel_mode) {
     2131 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
     2132 		for (i = 0; i < spec->num_channel_mode; i++) {
     2133 			if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
     2134 				info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
     2135 			}
     2136 		}
     2137 	}
     2138 
     2139 	/* SPDIF for stream index #1 */
     2140 	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
     2141 		codec->num_pcms = 2;
     2142 		info = spec->pcm_rec + 1;
     2143 		info->name = spec->stream_name_digital;
     2144 		if (spec->multiout.dig_out_nid &&
     2145 		    spec->stream_digital_playback) {
     2146 			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
     2147 			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
     2148 		}
     2149 		if (spec->dig_in_nid &&
     2150 		    spec->stream_digital_capture) {
     2151 			info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
     2152 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
     2153 		}
     2154 	}
     2155 
     2156 	/* If the use of more than one ADC is requested for the current
     2157 	 * model, configure a second analog capture-only PCM.
     2158 	 */
     2159 	/* Additional Analaog capture for index #2 */
     2160 	if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
     2161 	    spec->adc_nids) {
     2162 		codec->num_pcms = 3;
     2163 		info = spec->pcm_rec + 2;
     2164 		info->name = spec->stream_name_analog;
     2165 		/* No playback stream for second PCM */
     2166 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
     2167 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
     2168 		if (spec->stream_analog_capture) {
     2169 			info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
     2170 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
     2171 		}
     2172 	}
     2173 
     2174 	return 0;
     2175 }
     2176 
     2177 static void alc_free(struct hda_codec *codec)
     2178 {
     2179 	struct alc_spec *spec = codec->spec;
     2180 	unsigned int i;
     2181 
     2182 	if (!spec)
     2183 		return;
     2184 
     2185 	if (spec->kctl_alloc) {
     2186 		for (i = 0; i < spec->num_kctl_used; i++)
     2187 			kfree(spec->kctl_alloc[i].name);
     2188 		kfree(spec->kctl_alloc);
     2189 	}
     2190 	kfree(spec);
     2191 }
     2192 
     2193 /*
     2194  */
     2195 static struct hda_codec_ops alc_patch_ops = {
     2196 	.build_controls = alc_build_controls,
     2197 	.build_pcms = alc_build_pcms,
     2198 	.init = alc_init,
     2199 	.free = alc_free,
     2200 	.unsol_event = alc_unsol_event,
     2201 #ifdef CONFIG_PM
     2202 	.resume = alc_resume,
     2203 #endif
     2204 };
     2205 
     2206 
     2207 /*
     2208  * Test configuration for debugging
     2209  *
     2210  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
     2211  * enum controls.
     2212  */
     2213 #ifdef CONFIG_SND_DEBUG
     2214 static hda_nid_t alc880_test_dac_nids[4] = {
     2215 	0x02, 0x03, 0x04, 0x05
     2216 };
     2217 
     2218 static struct hda_input_mux alc880_test_capture_source = {
     2219 	.num_items = 7,
     2220 	.items = {
     2221 		{ "In-1", 0x0 },
     2222 		{ "In-2", 0x1 },
     2223 		{ "In-3", 0x2 },
     2224 		{ "In-4", 0x3 },
     2225 		{ "CD", 0x4 },
     2226 		{ "Front", 0x5 },
     2227 		{ "Surround", 0x6 },
     2228 	},
     2229 };
     2230 
     2231 static struct hda_channel_mode alc880_test_modes[4] = {
     2232 	{ 2, NULL },
     2233 	{ 4, NULL },
     2234 	{ 6, NULL },
     2235 	{ 8, NULL },
     2236 };
     2237 
     2238 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
     2239 				 struct snd_ctl_elem_info *uinfo)
     2240 {
     2241 	static char *texts[] = {
     2242 		"N/A", "Line Out", "HP Out",
     2243 		"In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
     2244 	};
     2245 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2246 	uinfo->count = 1;
     2247 	uinfo->value.enumerated.items = 8;
     2248 	if (uinfo->value.enumerated.item >= 8)
     2249 		uinfo->value.enumerated.item = 7;
     2250 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2251 	return 0;
     2252 }
     2253 
     2254 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
     2255 				struct snd_ctl_elem_value *ucontrol)
     2256 {
     2257 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     2258 	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
     2259 	unsigned int pin_ctl, item = 0;
     2260 
     2261 	pin_ctl = snd_hda_codec_read(codec, nid, 0,
     2262 				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
     2263 	if (pin_ctl & AC_PINCTL_OUT_EN) {
     2264 		if (pin_ctl & AC_PINCTL_HP_EN)
     2265 			item = 2;
     2266 		else
     2267 			item = 1;
     2268 	} else if (pin_ctl & AC_PINCTL_IN_EN) {
     2269 		switch (pin_ctl & AC_PINCTL_VREFEN) {
     2270 		case AC_PINCTL_VREF_HIZ: item = 3; break;
     2271 		case AC_PINCTL_VREF_50:  item = 4; break;
     2272 		case AC_PINCTL_VREF_GRD: item = 5; break;
     2273 		case AC_PINCTL_VREF_80:  item = 6; break;
     2274 		case AC_PINCTL_VREF_100: item = 7; break;
     2275 		}
     2276 	}
     2277 	ucontrol->value.enumerated.item[0] = item;
     2278 	return 0;
     2279 }
     2280 
     2281 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
     2282 				struct snd_ctl_elem_value *ucontrol)
     2283 {
     2284 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     2285 	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
     2286 	static unsigned int ctls[] = {
     2287 		0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
     2288 		AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
     2289 		AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
     2290 		AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
     2291 		AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
     2292 		AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
     2293 	};
     2294 	unsigned int old_ctl, new_ctl;
     2295 
     2296 	old_ctl = snd_hda_codec_read(codec, nid, 0,
     2297 				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
     2298 	new_ctl = ctls[ucontrol->value.enumerated.item[0]];
     2299 	if (old_ctl != new_ctl) {
     2300 		snd_hda_codec_write(codec, nid, 0,
     2301 				    AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
     2302 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
     2303 				    (ucontrol->value.enumerated.item[0] >= 3 ?
     2304 				     0xb080 : 0xb000));
     2305 		return 1;
     2306 	}
     2307 	return 0;
     2308 }
     2309 
     2310 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
     2311 				 struct snd_ctl_elem_info *uinfo)
     2312 {
     2313 	static char *texts[] = {
     2314 		"Front", "Surround", "CLFE", "Side"
     2315 	};
     2316 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2317 	uinfo->count = 1;
     2318 	uinfo->value.enumerated.items = 4;
     2319 	if (uinfo->value.enumerated.item >= 4)
     2320 		uinfo->value.enumerated.item = 3;
     2321 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2322 	return 0;
     2323 }
     2324 
     2325 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
     2326 				struct snd_ctl_elem_value *ucontrol)
     2327 {
     2328 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     2329 	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
     2330 	unsigned int sel;
     2331 
     2332 	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
     2333 	ucontrol->value.enumerated.item[0] = sel & 3;
     2334 	return 0;
     2335 }
     2336 
     2337 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
     2338 				struct snd_ctl_elem_value *ucontrol)
     2339 {
     2340 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     2341 	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
     2342 	unsigned int sel;
     2343 
     2344 	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
     2345 	if (ucontrol->value.enumerated.item[0] != sel) {
     2346 		sel = ucontrol->value.enumerated.item[0] & 3;
     2347 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
     2348 		return 1;
     2349 	}
     2350 	return 0;
     2351 }
     2352 
     2353 #define PIN_CTL_TEST(xname,nid) {			\
     2354 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
     2355 			.name = xname,		       \
     2356 			.info = alc_test_pin_ctl_info, \
     2357 			.get = alc_test_pin_ctl_get,   \
     2358 			.put = alc_test_pin_ctl_put,   \
     2359 			.private_value = nid	       \
     2360 			}
     2361 
     2362 #define PIN_SRC_TEST(xname,nid) {			\
     2363 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
     2364 			.name = xname,		       \
     2365 			.info = alc_test_pin_src_info, \
     2366 			.get = alc_test_pin_src_get,   \
     2367 			.put = alc_test_pin_src_put,   \
     2368 			.private_value = nid	       \
     2369 			}
     2370 
     2371 static struct snd_kcontrol_new alc880_test_mixer[] = {
     2372 	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     2373 	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
     2374 	HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
     2375 	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
     2376 	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
     2377 	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
     2378 	HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
     2379 	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
     2380 	PIN_CTL_TEST("Front Pin Mode", 0x14),
     2381 	PIN_CTL_TEST("Surround Pin Mode", 0x15),
     2382 	PIN_CTL_TEST("CLFE Pin Mode", 0x16),
     2383 	PIN_CTL_TEST("Side Pin Mode", 0x17),
     2384 	PIN_CTL_TEST("In-1 Pin Mode", 0x18),
     2385 	PIN_CTL_TEST("In-2 Pin Mode", 0x19),
     2386 	PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
     2387 	PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
     2388 	PIN_SRC_TEST("In-1 Pin Source", 0x18),
     2389 	PIN_SRC_TEST("In-2 Pin Source", 0x19),
     2390 	PIN_SRC_TEST("In-3 Pin Source", 0x1a),
     2391 	PIN_SRC_TEST("In-4 Pin Source", 0x1b),
     2392 	HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
     2393 	HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
     2394 	HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
     2395 	HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
     2396 	HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
     2397 	HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
     2398 	HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
     2399 	HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
     2400 	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
     2401 	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
     2402 	{
     2403 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     2404 		.name = "Channel Mode",
     2405 		.info = alc_ch_mode_info,
     2406 		.get = alc_ch_mode_get,
     2407 		.put = alc_ch_mode_put,
     2408 	},
     2409 	{ } /* end */
     2410 };
     2411 
     2412 static struct hda_verb alc880_test_init_verbs[] = {
     2413 	/* Unmute inputs of 0x0c - 0x0f */
     2414 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     2415 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     2416 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     2417 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     2418 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     2419 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     2420 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     2421 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     2422 	/* Vol output for 0x0c-0x0f */
     2423 	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     2424 	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     2425 	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     2426 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     2427 	/* Set output pins 0x14-0x17 */
     2428 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     2429 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     2430 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     2431 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     2432 	/* Unmute output pins 0x14-0x17 */
     2433 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     2434 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     2435 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     2436 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     2437 	/* Set input pins 0x18-0x1c */
     2438 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     2439 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     2440 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     2441 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     2442 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     2443 	/* Mute input pins 0x18-0x1b */
     2444 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     2445 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     2446 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     2447 	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     2448 	/* ADC set up */
     2449 	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     2450 	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
     2451 	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     2452 	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
     2453 	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     2454 	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
     2455 	/* Analog input/passthru */
     2456 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     2457 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     2458 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
     2459 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
     2460 	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
     2461 	{ }
     2462 };
     2463 #endif
     2464 
     2465 /*
     2466  */
     2467 
     2468 static const char *alc880_models[ALC880_MODEL_LAST] = {
     2469 	[ALC880_3ST]		= "3stack",
     2470 	[ALC880_TCL_S700]	= "tcl",
     2471 	[ALC880_3ST_DIG]	= "3stack-digout",
     2472 	[ALC880_CLEVO]		= "clevo",
     2473 	[ALC880_5ST]		= "5stack",
     2474 	[ALC880_5ST_DIG]	= "5stack-digout",
     2475 	[ALC880_W810]		= "w810",
     2476 	[ALC880_Z71V]		= "z71v",
     2477 	[ALC880_6ST]		= "6stack",
     2478 	[ALC880_6ST_DIG]	= "6stack-digout",
     2479 	[ALC880_ASUS]		= "asus",
     2480 	[ALC880_ASUS_W1V]	= "asus-w1v",
     2481 	[ALC880_ASUS_DIG]	= "asus-dig",
     2482 	[ALC880_ASUS_DIG2]	= "asus-dig2",
     2483 	[ALC880_UNIWILL_DIG]	= "uniwill",
     2484 	[ALC880_UNIWILL_P53]	= "uniwill-p53",
     2485 	[ALC880_FUJITSU]	= "fujitsu",
     2486 	[ALC880_F1734]		= "F1734",
     2487 	[ALC880_LG]		= "lg",
     2488 	[ALC880_LG_LW]		= "lg-lw",
     2489 #ifdef CONFIG_SND_DEBUG
     2490 	[ALC880_TEST]		= "test",
     2491 #endif
     2492 	[ALC880_AUTO]		= "auto",
     2493 };
     2494 
     2495 static struct snd_pci_quirk alc880_cfg_tbl[] = {
     2496 	/* Broken BIOS configuration */
     2497 	SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
     2498 	SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
     2499 
     2500 	SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
     2501 	SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
     2502 	SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
     2503 	SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
     2504 	SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
     2505 	SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
     2506 	SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
     2507 	SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
     2508 	SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
     2509 
     2510 	SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
     2511 	SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
     2512 
     2513 	SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
     2514 	SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
     2515 	SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
     2516 	SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
     2517 	SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
     2518 	SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
     2519 	SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
     2520 	/* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
     2521 	SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
     2522 	SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
     2523 	SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
     2524 	SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
     2525 	SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
     2526 	SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
     2527 	SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
     2528 
     2529 	SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
     2530 	SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
     2531 	SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
     2532 	SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
     2533 	SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
     2534 	SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
     2535 	SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
     2536 	SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
     2537 	SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
     2538 	SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
     2539 	SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
     2540 	SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
     2541 	SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
     2542 	SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
     2543 	SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
     2544 	SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
     2545 	SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
     2546 	SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
     2547 
     2548 	SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
     2549 	SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
     2550 	SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
     2551 	SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
     2552 
     2553 	SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
     2554 	SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
     2555 	SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
     2556 	SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
     2557 
     2558 	SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
     2559 	SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
     2560 	SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
     2561 	SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
     2562 
     2563 	SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
     2564 	SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
     2565 	SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
     2566 	SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
     2567 	SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
     2568 	SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
     2569 	SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
     2570 	SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
     2571 	SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
     2572 	SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
     2573 	SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
     2574 
     2575 	{}
     2576 };
     2577 
     2578 /*
     2579  * ALC880 codec presets
     2580  */
     2581 static struct alc_config_preset alc880_presets[] = {
     2582 	[ALC880_3ST] = {
     2583 		.mixers = { alc880_three_stack_mixer },
     2584 		.init_verbs = { alc880_volume_init_verbs,
     2585 				alc880_pin_3stack_init_verbs },
     2586 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2587 		.dac_nids = alc880_dac_nids,
     2588 		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
     2589 		.channel_mode = alc880_threestack_modes,
     2590 		.need_dac_fix = 1,
     2591 		.input_mux = &alc880_capture_source,
     2592 	},
     2593 	[ALC880_3ST_DIG] = {
     2594 		.mixers = { alc880_three_stack_mixer },
     2595 		.init_verbs = { alc880_volume_init_verbs,
     2596 				alc880_pin_3stack_init_verbs },
     2597 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2598 		.dac_nids = alc880_dac_nids,
     2599 		.dig_out_nid = ALC880_DIGOUT_NID,
     2600 		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
     2601 		.channel_mode = alc880_threestack_modes,
     2602 		.need_dac_fix = 1,
     2603 		.input_mux = &alc880_capture_source,
     2604 	},
     2605 	[ALC880_TCL_S700] = {
     2606 		.mixers = { alc880_tcl_s700_mixer },
     2607 		.init_verbs = { alc880_volume_init_verbs,
     2608 				alc880_pin_tcl_S700_init_verbs,
     2609 				alc880_gpio2_init_verbs },
     2610 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2611 		.dac_nids = alc880_dac_nids,
     2612 		.hp_nid = 0x03,
     2613 		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2614 		.channel_mode = alc880_2_jack_modes,
     2615 		.input_mux = &alc880_capture_source,
     2616 	},
     2617 	[ALC880_5ST] = {
     2618 		.mixers = { alc880_three_stack_mixer,
     2619 			    alc880_five_stack_mixer},
     2620 		.init_verbs = { alc880_volume_init_verbs,
     2621 				alc880_pin_5stack_init_verbs },
     2622 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2623 		.dac_nids = alc880_dac_nids,
     2624 		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
     2625 		.channel_mode = alc880_fivestack_modes,
     2626 		.input_mux = &alc880_capture_source,
     2627 	},
     2628 	[ALC880_5ST_DIG] = {
     2629 		.mixers = { alc880_three_stack_mixer,
     2630 			    alc880_five_stack_mixer },
     2631 		.init_verbs = { alc880_volume_init_verbs,
     2632 				alc880_pin_5stack_init_verbs },
     2633 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2634 		.dac_nids = alc880_dac_nids,
     2635 		.dig_out_nid = ALC880_DIGOUT_NID,
     2636 		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
     2637 		.channel_mode = alc880_fivestack_modes,
     2638 		.input_mux = &alc880_capture_source,
     2639 	},
     2640 	[ALC880_6ST] = {
     2641 		.mixers = { alc880_six_stack_mixer },
     2642 		.init_verbs = { alc880_volume_init_verbs,
     2643 				alc880_pin_6stack_init_verbs },
     2644 		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
     2645 		.dac_nids = alc880_6st_dac_nids,
     2646 		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
     2647 		.channel_mode = alc880_sixstack_modes,
     2648 		.input_mux = &alc880_6stack_capture_source,
     2649 	},
     2650 	[ALC880_6ST_DIG] = {
     2651 		.mixers = { alc880_six_stack_mixer },
     2652 		.init_verbs = { alc880_volume_init_verbs,
     2653 				alc880_pin_6stack_init_verbs },
     2654 		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
     2655 		.dac_nids = alc880_6st_dac_nids,
     2656 		.dig_out_nid = ALC880_DIGOUT_NID,
     2657 		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
     2658 		.channel_mode = alc880_sixstack_modes,
     2659 		.input_mux = &alc880_6stack_capture_source,
     2660 	},
     2661 	[ALC880_W810] = {
     2662 		.mixers = { alc880_w810_base_mixer },
     2663 		.init_verbs = { alc880_volume_init_verbs,
     2664 				alc880_pin_w810_init_verbs,
     2665 				alc880_gpio2_init_verbs },
     2666 		.num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
     2667 		.dac_nids = alc880_w810_dac_nids,
     2668 		.dig_out_nid = ALC880_DIGOUT_NID,
     2669 		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
     2670 		.channel_mode = alc880_w810_modes,
     2671 		.input_mux = &alc880_capture_source,
     2672 	},
     2673 	[ALC880_Z71V] = {
     2674 		.mixers = { alc880_z71v_mixer },
     2675 		.init_verbs = { alc880_volume_init_verbs,
     2676 				alc880_pin_z71v_init_verbs },
     2677 		.num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
     2678 		.dac_nids = alc880_z71v_dac_nids,
     2679 		.dig_out_nid = ALC880_DIGOUT_NID,
     2680 		.hp_nid = 0x03,
     2681 		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2682 		.channel_mode = alc880_2_jack_modes,
     2683 		.input_mux = &alc880_capture_source,
     2684 	},
     2685 	[ALC880_F1734] = {
     2686 		.mixers = { alc880_f1734_mixer },
     2687 		.init_verbs = { alc880_volume_init_verbs,
     2688 				alc880_pin_f1734_init_verbs },
     2689 		.num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
     2690 		.dac_nids = alc880_f1734_dac_nids,
     2691 		.hp_nid = 0x02,
     2692 		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2693 		.channel_mode = alc880_2_jack_modes,
     2694 		.input_mux = &alc880_capture_source,
     2695 	},
     2696 	[ALC880_ASUS] = {
     2697 		.mixers = { alc880_asus_mixer },
     2698 		.init_verbs = { alc880_volume_init_verbs,
     2699 				alc880_pin_asus_init_verbs,
     2700 				alc880_gpio1_init_verbs },
     2701 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2702 		.dac_nids = alc880_asus_dac_nids,
     2703 		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
     2704 		.channel_mode = alc880_asus_modes,
     2705 		.need_dac_fix = 1,
     2706 		.input_mux = &alc880_capture_source,
     2707 	},
     2708 	[ALC880_ASUS_DIG] = {
     2709 		.mixers = { alc880_asus_mixer },
     2710 		.init_verbs = { alc880_volume_init_verbs,
     2711 				alc880_pin_asus_init_verbs,
     2712 				alc880_gpio1_init_verbs },
     2713 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2714 		.dac_nids = alc880_asus_dac_nids,
     2715 		.dig_out_nid = ALC880_DIGOUT_NID,
     2716 		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
     2717 		.channel_mode = alc880_asus_modes,
     2718 		.need_dac_fix = 1,
     2719 		.input_mux = &alc880_capture_source,
     2720 	},
     2721 	[ALC880_ASUS_DIG2] = {
     2722 		.mixers = { alc880_asus_mixer },
     2723 		.init_verbs = { alc880_volume_init_verbs,
     2724 				alc880_pin_asus_init_verbs,
     2725 				alc880_gpio2_init_verbs }, /* use GPIO2 */
     2726 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2727 		.dac_nids = alc880_asus_dac_nids,
     2728 		.dig_out_nid = ALC880_DIGOUT_NID,
     2729 		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
     2730 		.channel_mode = alc880_asus_modes,
     2731 		.need_dac_fix = 1,
     2732 		.input_mux = &alc880_capture_source,
     2733 	},
     2734 	[ALC880_ASUS_W1V] = {
     2735 		.mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
     2736 		.init_verbs = { alc880_volume_init_verbs,
     2737 				alc880_pin_asus_init_verbs,
     2738 				alc880_gpio1_init_verbs },
     2739 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2740 		.dac_nids = alc880_asus_dac_nids,
     2741 		.dig_out_nid = ALC880_DIGOUT_NID,
     2742 		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
     2743 		.channel_mode = alc880_asus_modes,
     2744 		.need_dac_fix = 1,
     2745 		.input_mux = &alc880_capture_source,
     2746 	},
     2747 	[ALC880_UNIWILL_DIG] = {
     2748 		.mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
     2749 		.init_verbs = { alc880_volume_init_verbs,
     2750 				alc880_pin_asus_init_verbs },
     2751 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2752 		.dac_nids = alc880_asus_dac_nids,
     2753 		.dig_out_nid = ALC880_DIGOUT_NID,
     2754 		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
     2755 		.channel_mode = alc880_asus_modes,
     2756 		.need_dac_fix = 1,
     2757 		.input_mux = &alc880_capture_source,
     2758 	},
     2759 	[ALC880_UNIWILL] = {
     2760 		.mixers = { alc880_uniwill_mixer },
     2761 		.init_verbs = { alc880_volume_init_verbs,
     2762 				alc880_uniwill_init_verbs },
     2763 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2764 		.dac_nids = alc880_asus_dac_nids,
     2765 		.dig_out_nid = ALC880_DIGOUT_NID,
     2766 		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
     2767 		.channel_mode = alc880_threestack_modes,
     2768 		.need_dac_fix = 1,
     2769 		.input_mux = &alc880_capture_source,
     2770 		.unsol_event = alc880_uniwill_unsol_event,
     2771 		.init_hook = alc880_uniwill_automute,
     2772 	},
     2773 	[ALC880_UNIWILL_P53] = {
     2774 		.mixers = { alc880_uniwill_p53_mixer },
     2775 		.init_verbs = { alc880_volume_init_verbs,
     2776 				alc880_uniwill_p53_init_verbs },
     2777 		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
     2778 		.dac_nids = alc880_asus_dac_nids,
     2779 		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
     2780 		.channel_mode = alc880_threestack_modes,
     2781 		.input_mux = &alc880_capture_source,
     2782 		.unsol_event = alc880_uniwill_p53_unsol_event,
     2783 		.init_hook = alc880_uniwill_p53_hp_automute,
     2784 	},
     2785 	[ALC880_FUJITSU] = {
     2786 		.mixers = { alc880_fujitsu_mixer,
     2787 			    alc880_pcbeep_mixer, },
     2788 		.init_verbs = { alc880_volume_init_verbs,
     2789 				alc880_uniwill_p53_init_verbs,
     2790 	       			alc880_beep_init_verbs },
     2791 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2792 		.dac_nids = alc880_dac_nids,
     2793 		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2794 		.channel_mode = alc880_2_jack_modes,
     2795 		.input_mux = &alc880_capture_source,
     2796 		.unsol_event = alc880_uniwill_p53_unsol_event,
     2797 		.init_hook = alc880_uniwill_p53_hp_automute,
     2798 	},
     2799 	[ALC880_CLEVO] = {
     2800 		.mixers = { alc880_three_stack_mixer },
     2801 		.init_verbs = { alc880_volume_init_verbs,
     2802 				alc880_pin_clevo_init_verbs },
     2803 		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
     2804 		.dac_nids = alc880_dac_nids,
     2805 		.hp_nid = 0x03,
     2806 		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
     2807 		.channel_mode = alc880_threestack_modes,
     2808 		.need_dac_fix = 1,
     2809 		.input_mux = &alc880_capture_source,
     2810 	},
     2811 	[ALC880_LG] = {
     2812 		.mixers = { alc880_lg_mixer },
     2813 		.init_verbs = { alc880_volume_init_verbs,
     2814 				alc880_lg_init_verbs },
     2815 		.num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
     2816 		.dac_nids = alc880_lg_dac_nids,
     2817 		.dig_out_nid = ALC880_DIGOUT_NID,
     2818 		.num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
     2819 		.channel_mode = alc880_lg_ch_modes,
     2820 		.need_dac_fix = 1,
     2821 		.input_mux = &alc880_lg_capture_source,
     2822 		.unsol_event = alc880_lg_unsol_event,
     2823 		.init_hook = alc880_lg_automute,
     2824 	},
     2825 	[ALC880_LG_LW] = {
     2826 		.mixers = { alc880_lg_lw_mixer },
     2827 		.init_verbs = { alc880_volume_init_verbs,
     2828 				alc880_lg_lw_init_verbs },
     2829 		.num_dacs = 1,
     2830 		.dac_nids = alc880_dac_nids,
     2831 		.dig_out_nid = ALC880_DIGOUT_NID,
     2832 		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2833 		.channel_mode = alc880_2_jack_modes,
     2834 		.input_mux = &alc880_lg_lw_capture_source,
     2835 		.unsol_event = alc880_lg_lw_unsol_event,
     2836 		.init_hook = alc880_lg_lw_automute,
     2837 	},
     2838 #ifdef CONFIG_SND_DEBUG
     2839 	[ALC880_TEST] = {
     2840 		.mixers = { alc880_test_mixer },
     2841 		.init_verbs = { alc880_test_init_verbs },
     2842 		.num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
     2843 		.dac_nids = alc880_test_dac_nids,
     2844 		.dig_out_nid = ALC880_DIGOUT_NID,
     2845 		.num_channel_mode = ARRAY_SIZE(alc880_test_modes),
     2846 		.channel_mode = alc880_test_modes,
     2847 		.input_mux = &alc880_test_capture_source,
     2848 	},
     2849 #endif
     2850 };
     2851 
     2852 /*
     2853  * Automatic parse of I/O pins from the BIOS configuration
     2854  */
     2855 
     2856 #define NUM_CONTROL_ALLOC	32
     2857 #define NUM_VERB_ALLOC		32
     2858 
     2859 enum {
     2860 	ALC_CTL_WIDGET_VOL,
     2861 	ALC_CTL_WIDGET_MUTE,
     2862 	ALC_CTL_BIND_MUTE,
     2863 };
     2864 static struct snd_kcontrol_new alc880_control_templates[] = {
     2865 	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
     2866 	HDA_CODEC_MUTE(NULL, 0, 0, 0),
     2867 	HDA_BIND_MUTE(NULL, 0, 0, 0),
     2868 };
     2869 
     2870 /* add dynamic controls */
     2871 static int add_control(struct alc_spec *spec, int type, const char *name,
     2872 		       unsigned long val)
     2873 {
     2874 	struct snd_kcontrol_new *knew;
     2875 
     2876 	if (spec->num_kctl_used >= spec->num_kctl_alloc) {
     2877 		int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
     2878 
     2879 		/* array + terminator */
     2880 		knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
     2881 		if (!knew)
     2882 			return -ENOMEM;
     2883 		if (spec->kctl_alloc) {
     2884 			memcpy(knew, spec->kctl_alloc,
     2885 			       sizeof(*knew) * spec->num_kctl_alloc);
     2886 			kfree(spec->kctl_alloc);
     2887 		}
     2888 		spec->kctl_alloc = knew;
     2889 		spec->num_kctl_alloc = num;
     2890 	}
     2891 
     2892 	knew = &spec->kctl_alloc[spec->num_kctl_used];
     2893 	*knew = alc880_control_templates[type];
     2894 	knew->name = kstrdup(name, GFP_KERNEL);
     2895 	if (!knew->name)
     2896 		return -ENOMEM;
     2897 	knew->private_value = val;
     2898 	spec->num_kctl_used++;
     2899 	return 0;
     2900 }
     2901 
     2902 #define alc880_is_fixed_pin(nid)	((nid) >= 0x14 && (nid) <= 0x17)
     2903 #define alc880_fixed_pin_idx(nid)	((nid) - 0x14)
     2904 #define alc880_is_multi_pin(nid)	((nid) >= 0x18)
     2905 #define alc880_multi_pin_idx(nid)	((nid) - 0x18)
     2906 #define alc880_is_input_pin(nid)	((nid) >= 0x18)
     2907 #define alc880_input_pin_idx(nid)	((nid) - 0x18)
     2908 #define alc880_idx_to_dac(nid)		((nid) + 0x02)
     2909 #define alc880_dac_to_idx(nid)		((nid) - 0x02)
     2910 #define alc880_idx_to_mixer(nid)	((nid) + 0x0c)
     2911 #define alc880_idx_to_selector(nid)	((nid) + 0x10)
     2912 #define ALC880_PIN_CD_NID		0x1c
     2913 
     2914 /* fill in the dac_nids table from the parsed pin configuration */
     2915 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
     2916 				     const struct auto_pin_cfg *cfg)
     2917 {
     2918 	hda_nid_t nid;
     2919 	int assigned[4];
     2920 	int i, j;
     2921 
     2922 	memset(assigned, 0, sizeof(assigned));
     2923 	spec->multiout.dac_nids = spec->private_dac_nids;
     2924 
     2925 	/* check the pins hardwired to audio widget */
     2926 	for (i = 0; i < cfg->line_outs; i++) {
     2927 		nid = cfg->line_out_pins[i];
     2928 		if (alc880_is_fixed_pin(nid)) {
     2929 			int idx = alc880_fixed_pin_idx(nid);
     2930 			spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
     2931 			assigned[idx] = 1;
     2932 		}
     2933 	}
     2934 	/* left pins can be connect to any audio widget */
     2935 	for (i = 0; i < cfg->line_outs; i++) {
     2936 		nid = cfg->line_out_pins[i];
     2937 		if (alc880_is_fixed_pin(nid))
     2938 			continue;
     2939 		/* search for an empty channel */
     2940 		for (j = 0; j < cfg->line_outs; j++) {
     2941 			if (!assigned[j]) {
     2942 				spec->multiout.dac_nids[i] =
     2943 					alc880_idx_to_dac(j);
     2944 				assigned[j] = 1;
     2945 				break;
     2946 			}
     2947 		}
     2948 	}
     2949 	spec->multiout.num_dacs = cfg->line_outs;
     2950 	return 0;
     2951 }
     2952 
     2953 /* add playback controls from the parsed DAC table */
     2954 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
     2955 					     const struct auto_pin_cfg *cfg)
     2956 {
     2957 	char name[32];
     2958 	static const char *chname[4] = {
     2959 		"Front", "Surround", NULL /*CLFE*/, "Side"
     2960 	};
     2961 	hda_nid_t nid;
     2962 	int i, err;
     2963 
     2964 	for (i = 0; i < cfg->line_outs; i++) {
     2965 		if (!spec->multiout.dac_nids[i])
     2966 			continue;
     2967 		nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
     2968 		if (i == 2) {
     2969 			/* Center/LFE */
     2970 			err = add_control(spec, ALC_CTL_WIDGET_VOL,
     2971 					  "Center Playback Volume",
     2972 					  HDA_COMPOSE_AMP_VAL(nid, 1, 0,
     2973 							      HDA_OUTPUT));
     2974 			if (err < 0)
     2975 				return err;
     2976 			err = add_control(spec, ALC_CTL_WIDGET_VOL,
     2977 					  "LFE Playback Volume",
     2978 					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
     2979 							      HDA_OUTPUT));
     2980 			if (err < 0)
     2981 				return err;
     2982 			err = add_control(spec, ALC_CTL_BIND_MUTE,
     2983 					  "Center Playback Switch",
     2984 					  HDA_COMPOSE_AMP_VAL(nid, 1, 2,
     2985 							      HDA_INPUT));
     2986 			if (err < 0)
     2987 				return err;
     2988 			err = add_control(spec, ALC_CTL_BIND_MUTE,
     2989 					  "LFE Playback Switch",
     2990 					  HDA_COMPOSE_AMP_VAL(nid, 2, 2,
     2991 							      HDA_INPUT));
     2992 			if (err < 0)
     2993 				return err;
     2994 		} else {
     2995 			sprintf(name, "%s Playback Volume", chname[i]);
     2996 			err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
     2997 					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
     2998 							      HDA_OUTPUT));
     2999 			if (err < 0)
     3000 				return err;
     3001 			sprintf(name, "%s Playback Switch", chname[i]);
     3002 			err = add_control(spec, ALC_CTL_BIND_MUTE, name,
     3003 					  HDA_COMPOSE_AMP_VAL(nid, 3, 2,
     3004 							      HDA_INPUT));
     3005 			if (err < 0)
     3006 				return err;
     3007 		}
     3008 	}
     3009 	return 0;
     3010 }
     3011 
     3012 /* add playback controls for speaker and HP outputs */
     3013 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
     3014 					const char *pfx)
     3015 {
     3016 	hda_nid_t nid;
     3017 	int err;
     3018 	char name[32];
     3019 
     3020 	if (!pin)
     3021 		return 0;
     3022 
     3023 	if (alc880_is_fixed_pin(pin)) {
     3024 		nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
     3025 		/* specify the DAC as the extra output */
     3026 		if (!spec->multiout.hp_nid)
     3027 			spec->multiout.hp_nid = nid;
     3028 		else
     3029 			spec->multiout.extra_out_nid[0] = nid;
     3030 		/* control HP volume/switch on the output mixer amp */
     3031 		nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
     3032 		sprintf(name, "%s Playback Volume", pfx);
     3033 		err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
     3034 				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
     3035 		if (err < 0)
     3036 			return err;
     3037 		sprintf(name, "%s Playback Switch", pfx);
     3038 		err = add_control(spec, ALC_CTL_BIND_MUTE, name,
     3039 				  HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
     3040 		if (err < 0)
     3041 			return err;
     3042 	} else if (alc880_is_multi_pin(pin)) {
     3043 		/* set manual connection */
     3044 		/* we have only a switch on HP-out PIN */
     3045 		sprintf(name, "%s Playback Switch", pfx);
     3046 		err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
     3047 				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
     3048 		if (err < 0)
     3049 			return err;
     3050 	}
     3051 	return 0;
     3052 }
     3053 
     3054 /* create input playback/capture controls for the given pin */
     3055 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
     3056 			    const char *ctlname,
     3057 			    int idx, hda_nid_t mix_nid)
     3058 {
     3059 	char name[32];
     3060 	int err;
     3061 
     3062 	sprintf(name, "%s Playback Volume", ctlname);
     3063 	err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
     3064 			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
     3065 	if (err < 0)
     3066 		return err;
     3067 	sprintf(name, "%s Playback Switch", ctlname);
     3068 	err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
     3069 			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
     3070 	if (err < 0)
     3071 		return err;
     3072 	return 0;
     3073 }
     3074 
     3075 /* create playback/capture controls for input pins */
     3076 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
     3077 						const struct auto_pin_cfg *cfg)
     3078 {
     3079 	struct hda_input_mux *imux = &spec->private_imux;
     3080 	int i, err, idx;
     3081 
     3082 	for (i = 0; i < AUTO_PIN_LAST; i++) {
     3083 		if (alc880_is_input_pin(cfg->input_pins[i])) {
     3084 			idx = alc880_input_pin_idx(cfg->input_pins[i]);
     3085 			err = new_analog_input(spec, cfg->input_pins[i],
     3086 					       auto_pin_cfg_labels[i],
     3087 					       idx, 0x0b);
     3088 			if (err < 0)
     3089 				return err;
     3090 			imux->items[imux->num_items].label =
     3091 				auto_pin_cfg_labels[i];
     3092 			imux->items[imux->num_items].index =
     3093 				alc880_input_pin_idx(cfg->input_pins[i]);
     3094 			imux->num_items++;
     3095 		}
     3096 	}
     3097 	return 0;
     3098 }
     3099 
     3100 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
     3101 					      hda_nid_t nid, int pin_type,
     3102 					      int dac_idx)
     3103 {
     3104 	/* set as output */
     3105 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
     3106 			    pin_type);
     3107 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
     3108 			    AMP_OUT_UNMUTE);
     3109 	/* need the manual connection? */
     3110 	if (alc880_is_multi_pin(nid)) {
     3111 		struct alc_spec *spec = codec->spec;
     3112 		int idx = alc880_multi_pin_idx(nid);
     3113 		snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
     3114 				    AC_VERB_SET_CONNECT_SEL,
     3115 				    alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
     3116 	}
     3117 }
     3118 
     3119 static int get_pin_type(int line_out_type)
     3120 {
     3121 	if (line_out_type == AUTO_PIN_HP_OUT)
     3122 		return PIN_HP;
     3123 	else
     3124 		return PIN_OUT;
     3125 }
     3126 
     3127 static void alc880_auto_init_multi_out(struct hda_codec *codec)
     3128 {
     3129 	struct alc_spec *spec = codec->spec;
     3130 	int i;
     3131 	
     3132 	alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
     3133 	for (i = 0; i < spec->autocfg.line_outs; i++) {
     3134 		hda_nid_t nid = spec->autocfg.line_out_pins[i];
     3135 		int pin_type = get_pin_type(spec->autocfg.line_out_type);
     3136 		alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
     3137 	}
     3138 }
     3139 
     3140 static void alc880_auto_init_extra_out(struct hda_codec *codec)
     3141 {
     3142 	struct alc_spec *spec = codec->spec;
     3143 	hda_nid_t pin;
     3144 
     3145 	pin = spec->autocfg.speaker_pins[0];
     3146 	if (pin) /* connect to front */
     3147 		alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
     3148 	pin = spec->autocfg.hp_pins[0];
     3149 	if (pin) /* connect to front */
     3150 		alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
     3151 }
     3152 
     3153 static void alc880_auto_init_analog_input(struct hda_codec *codec)
     3154 {
     3155 	struct alc_spec *spec = codec->spec;
     3156 	int i;
     3157 
     3158 	for (i = 0; i < AUTO_PIN_LAST; i++) {
     3159 		hda_nid_t nid = spec->autocfg.input_pins[i];
     3160 		if (alc880_is_input_pin(nid)) {
     3161 			snd_hda_codec_write(codec, nid, 0,
     3162 					    AC_VERB_SET_PIN_WIDGET_CONTROL,
     3163 					    i <= AUTO_PIN_FRONT_MIC ?
     3164 					    PIN_VREF80 : PIN_IN);
     3165 			if (nid != ALC880_PIN_CD_NID)
     3166 				snd_hda_codec_write(codec, nid, 0,
     3167 						    AC_VERB_SET_AMP_GAIN_MUTE,
     3168 						    AMP_OUT_MUTE);
     3169 		}
     3170 	}
     3171 }
     3172 
     3173 /* parse the BIOS configuration and set up the alc_spec */
     3174 /* return 1 if successful, 0 if the proper config is not found,
     3175  * or a negative error code
     3176  */
     3177 static int alc880_parse_auto_config(struct hda_codec *codec)
     3178 {
     3179 	struct alc_spec *spec = codec->spec;
     3180 	int err;
     3181 	static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
     3182 
     3183 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
     3184 					   alc880_ignore);
     3185 	if (err < 0)
     3186 		return err;
     3187 	if (!spec->autocfg.line_outs)
     3188 		return 0; /* can't find valid BIOS pin config */
     3189 
     3190 	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
     3191 	if (err < 0)
     3192 		return err;
     3193 	err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
     3194 	if (err < 0)
     3195 		return err;
     3196 	err = alc880_auto_create_extra_out(spec,
     3197 					   spec->autocfg.speaker_pins[0],
     3198 					   "Speaker");
     3199 	if (err < 0)
     3200 		return err;
     3201 	err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
     3202 					   "Headphone");
     3203 	if (err < 0)
     3204 		return err;
     3205 	err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
     3206 	if (err < 0)
     3207 		return err;
     3208 
     3209 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
     3210 
     3211 	if (spec->autocfg.dig_out_pin)
     3212 		spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
     3213 	if (spec->autocfg.dig_in_pin)
     3214 		spec->dig_in_nid = ALC880_DIGIN_NID;
     3215 
     3216 	if (spec->kctl_alloc)
     3217 		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
     3218 
     3219 	spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
     3220 
     3221 	spec->num_mux_defs = 1;
     3222 	spec->input_mux = &spec->private_imux;
     3223 
     3224 	return 1;
     3225 }
     3226 
     3227 /* additional initialization for auto-configuration model */
     3228 static void alc880_auto_init(struct hda_codec *codec)
     3229 {
     3230 	alc880_auto_init_multi_out(codec);
     3231 	alc880_auto_init_extra_out(codec);
     3232 	alc880_auto_init_analog_input(codec);
     3233 }
     3234 
     3235 /*
     3236  * OK, here we have finally the patch for ALC880
     3237  */
     3238 
     3239 static int patch_alc880(struct hda_codec *codec)
     3240 {
     3241 	struct alc_spec *spec;
     3242 	int board_config;
     3243 	int err;
     3244 
     3245 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
     3246 	if (spec == NULL)
     3247 		return -ENOMEM;
     3248 
     3249 	codec->spec = spec;
     3250 
     3251 	board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
     3252 						  alc880_models,
     3253 						  alc880_cfg_tbl);
     3254 	if (board_config < 0) {
     3255 		printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
     3256 		       "trying auto-probe from BIOS...\n");
     3257 		board_config = ALC880_AUTO;
     3258 	}
     3259 
     3260 	if (board_config == ALC880_AUTO) {
     3261 		/* automatic parse from the BIOS config */
     3262 		err = alc880_parse_auto_config(codec);
     3263 		if (err < 0) {
     3264 			alc_free(codec);
     3265 			return err;
     3266 		} else if (!err) {
     3267 			printk(KERN_INFO
     3268 			       "hda_codec: Cannot set up configuration "
     3269 			       "from BIOS.  Using 3-stack mode...\n");
     3270 			board_config = ALC880_3ST;
     3271 		}
     3272 	}
     3273 
     3274 	if (board_config != ALC880_AUTO)
     3275 		setup_preset(spec, &alc880_presets[board_config]);
     3276 
     3277 	spec->stream_name_analog = "ALC880 Analog";
     3278 	spec->stream_analog_playback = &alc880_pcm_analog_playback;
     3279 	spec->stream_analog_capture = &alc880_pcm_analog_capture;
     3280 
     3281 	spec->stream_name_digital = "ALC880 Digital";
     3282 	spec->stream_digital_playback = &alc880_pcm_digital_playback;
     3283 	spec->stream_digital_capture = &alc880_pcm_digital_capture;
     3284 
     3285 	if (!spec->adc_nids && spec->input_mux) {
     3286 		/* check whether NID 0x07 is valid */
     3287 		unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
     3288 		/* get type */
     3289 		wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
     3290 		if (wcap != AC_WID_AUD_IN) {
     3291 			spec->adc_nids = alc880_adc_nids_alt;
     3292 			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
     3293 			spec->mixers[spec->num_mixers] =
     3294 				alc880_capture_alt_mixer;
     3295 			spec->num_mixers++;
     3296 		} else {
     3297 			spec->adc_nids = alc880_adc_nids;
     3298 			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
     3299 			spec->mixers[spec->num_mixers] = alc880_capture_mixer;
     3300 			spec->num_mixers++;
     3301 		}
     3302 	}
     3303 
     3304 	codec->patch_ops = alc_patch_ops;
     3305 	if (board_config == ALC880_AUTO)
     3306 		spec->init_hook = alc880_auto_init;
     3307 
     3308 	return 0;
     3309 }
     3310 
     3311 
     3312 /*
     3313  * ALC260 support
     3314  */
     3315 
     3316 static hda_nid_t alc260_dac_nids[1] = {
     3317 	/* front */
     3318 	0x02,
     3319 };
     3320 
     3321 static hda_nid_t alc260_adc_nids[1] = {
     3322 	/* ADC0 */
     3323 	0x04,
     3324 };
     3325 
     3326 static hda_nid_t alc260_adc_nids_alt[1] = {
     3327 	/* ADC1 */
     3328 	0x05,
     3329 };
     3330 
     3331 static hda_nid_t alc260_hp_adc_nids[2] = {
     3332 	/* ADC1, 0 */
     3333 	0x05, 0x04
     3334 };
     3335 
     3336 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
     3337  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
     3338  */
     3339 static hda_nid_t alc260_dual_adc_nids[2] = {
     3340 	/* ADC0, ADC1 */
     3341 	0x04, 0x05
     3342 };
     3343 
     3344 #define ALC260_DIGOUT_NID	0x03
     3345 #define ALC260_DIGIN_NID	0x06
     3346 
     3347 static struct hda_input_mux alc260_capture_source = {
     3348 	.num_items = 4,
     3349 	.items = {
     3350 		{ "Mic", 0x0 },
     3351 		{ "Front Mic", 0x1 },
     3352 		{ "Line", 0x2 },
     3353 		{ "CD", 0x4 },
     3354 	},
     3355 };
     3356 
     3357 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
     3358  * headphone jack and the internal CD lines since these are the only pins at
     3359  * which audio can appear.  For flexibility, also allow the option of
     3360  * recording the mixer output on the second ADC (ADC0 doesn't have a
     3361  * connection to the mixer output).
     3362  */
     3363 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
     3364 	{
     3365 		.num_items = 3,
     3366 		.items = {
     3367 			{ "Mic/Line", 0x0 },
     3368 			{ "CD", 0x4 },
     3369 			{ "Headphone", 0x2 },
     3370 		},
     3371 	},
     3372 	{
     3373 		.num_items = 4,
     3374 		.items = {
     3375 			{ "Mic/Line", 0x0 },
     3376 			{ "CD", 0x4 },
     3377 			{ "Headphone", 0x2 },
     3378 			{ "Mixer", 0x5 },
     3379 		},
     3380 	},
     3381 
     3382 };
     3383 
     3384 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
     3385  * the Fujitsu S702x, but jacks are marked differently.
     3386  */
     3387 static struct hda_input_mux alc260_acer_capture_sources[2] = {
     3388 	{
     3389 		.num_items = 4,
     3390 		.items = {
     3391 			{ "Mic", 0x0 },
     3392 			{ "Line", 0x2 },
     3393 			{ "CD", 0x4 },
     3394 			{ "Headphone", 0x5 },
     3395 		},
     3396 	},
     3397 	{
     3398 		.num_items = 5,
     3399 		.items = {
     3400 			{ "Mic", 0x0 },
     3401 			{ "Line", 0x2 },
     3402 			{ "CD", 0x4 },
     3403 			{ "Headphone", 0x6 },
     3404 			{ "Mixer", 0x5 },
     3405 		},
     3406 	},
     3407 };
     3408 /*
     3409  * This is just place-holder, so there's something for alc_build_pcms to look
     3410  * at when it calculates the maximum number of channels. ALC260 has no mixer
     3411  * element which allows changing the channel mode, so the verb list is
     3412  * never used.
     3413  */
     3414 static struct hda_channel_mode alc260_modes[1] = {
     3415 	{ 2, NULL },
     3416 };
     3417 
     3418 
     3419 /* Mixer combinations
     3420  *
     3421  * basic: base_output + input + pc_beep + capture
     3422  * HP: base_output + input + capture_alt
     3423  * HP_3013: hp_3013 + input + capture
     3424  * fujitsu: fujitsu + capture
     3425  * acer: acer + capture
     3426  */
     3427 
     3428 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
     3429 	HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3430 	HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
     3431 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
     3432 	HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
     3433 	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
     3434 	HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
     3435 	{ } /* end */
     3436 };
     3437 
     3438 static struct snd_kcontrol_new alc260_input_mixer[] = {
     3439 	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     3440 	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     3441 	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
     3442 	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
     3443 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
     3444 	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
     3445 	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
     3446 	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
     3447 	{ } /* end */
     3448 };
     3449 
     3450 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
     3451 	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
     3452 	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
     3453 	{ } /* end */
     3454 };
     3455 
     3456 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
     3457 	HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
     3458 	HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
     3459 	HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
     3460 	HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
     3461 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3462 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
     3463 	HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
     3464 	HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
     3465 	{ } /* end */
     3466 };
     3467 
     3468 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
     3469  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
     3470  */
     3471 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
     3472 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3473 	HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
     3474 	ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
     3475 	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     3476 	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     3477 	HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
     3478 	HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
     3479 	ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
     3480 	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
     3481 	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
     3482 	HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
     3483 	HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
     3484 	{ } /* end */
     3485 };
     3486 
     3487 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
     3488  * versions of the ALC260 don't act on requests to enable mic bias from NID
     3489  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
     3490  * datasheet doesn't mention this restriction.  At this stage it's not clear
     3491  * whether this behaviour is intentional or is a hardware bug in chip
     3492  * revisions available in early 2006.  Therefore for now allow the
     3493  * "Headphone Jack Mode" control to span all choices, but if it turns out
     3494  * that the lack of mic bias for this NID is intentional we could change the
     3495  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
     3496  *
     3497  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
     3498  * don't appear to make the mic bias available from the "line" jack, even
     3499  * though the NID used for this jack (0x14) can supply it.  The theory is
     3500  * that perhaps Acer have included blocking capacitors between the ALC260
     3501  * and the output jack.  If this turns out to be the case for all such
     3502  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
     3503  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
     3504  *
     3505  * The C20x Tablet series have a mono internal speaker which is controlled
     3506  * via the chip's Mono sum widget and pin complex, so include the necessary
     3507  * controls for such models.  On models without a "mono speaker" the control
     3508  * won't do anything.
     3509  */
     3510 static struct snd_kcontrol_new alc260_acer_mixer[] = {
     3511 	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3512 	HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
     3513 	ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
     3514 	HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
     3515 			      HDA_OUTPUT),
     3516 	HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
     3517 			   HDA_INPUT),
     3518 	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     3519 	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     3520 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
     3521 	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
     3522 	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
     3523 	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
     3524 	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
     3525 	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
     3526 	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
     3527 	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
     3528 	{ } /* end */
     3529 };
     3530 
     3531 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
     3532  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
     3533  */
     3534 static struct snd_kcontrol_new alc260_will_mixer[] = {
     3535 	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3536 	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
     3537 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
     3538 	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
     3539 	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
     3540 	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
     3541 	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
     3542 	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
     3543 	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     3544 	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     3545 	HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
     3546 	HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
     3547 	{ } /* end */
     3548 };
     3549 
     3550 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
     3551  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
     3552  */
     3553 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
     3554 	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3555 	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
     3556 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
     3557 	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
     3558 	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
     3559 	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
     3560 	HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
     3561 	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
     3562 	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
     3563 	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
     3564 	{ } /* end */
     3565 };
     3566 
     3567 /* capture mixer elements */
     3568 static struct snd_kcontrol_new alc260_capture_mixer[] = {
     3569 	HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
     3570 	HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
     3571 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
     3572 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),