Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

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