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 (19 months 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&