~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/pci/hda/patch_realtek.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.11 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.84 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.154 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.201 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.201 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.77 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 #include "hda_beep.h"
 34 
 35 #define ALC880_FRONT_EVENT              0x01
 36 #define ALC880_DCVOL_EVENT              0x02
 37 #define ALC880_HP_EVENT                 0x04
 38 #define ALC880_MIC_EVENT                0x08
 39 
 40 /* ALC880 board config type */
 41 enum {
 42         ALC880_3ST,
 43         ALC880_3ST_DIG,
 44         ALC880_5ST,
 45         ALC880_5ST_DIG,
 46         ALC880_W810,
 47         ALC880_Z71V,
 48         ALC880_6ST,
 49         ALC880_6ST_DIG,
 50         ALC880_F1734,
 51         ALC880_ASUS,
 52         ALC880_ASUS_DIG,
 53         ALC880_ASUS_W1V,
 54         ALC880_ASUS_DIG2,
 55         ALC880_FUJITSU,
 56         ALC880_UNIWILL_DIG,
 57         ALC880_UNIWILL,
 58         ALC880_UNIWILL_P53,
 59         ALC880_CLEVO,
 60         ALC880_TCL_S700,
 61         ALC880_LG,
 62         ALC880_LG_LW,
 63         ALC880_MEDION_RIM,
 64 #ifdef CONFIG_SND_DEBUG
 65         ALC880_TEST,
 66 #endif
 67         ALC880_AUTO,
 68         ALC880_MODEL_LAST /* last tag */
 69 };
 70 
 71 /* ALC260 models */
 72 enum {
 73         ALC260_BASIC,
 74         ALC260_HP,
 75         ALC260_HP_DC7600,
 76         ALC260_HP_3013,
 77         ALC260_FUJITSU_S702X,
 78         ALC260_ACER,
 79         ALC260_WILL,
 80         ALC260_REPLACER_672V,
 81         ALC260_FAVORIT100,
 82 #ifdef CONFIG_SND_DEBUG
 83         ALC260_TEST,
 84 #endif
 85         ALC260_AUTO,
 86         ALC260_MODEL_LAST /* last tag */
 87 };
 88 
 89 /* ALC262 models */
 90 enum {
 91         ALC262_BASIC,
 92         ALC262_HIPPO,
 93         ALC262_HIPPO_1,
 94         ALC262_FUJITSU,
 95         ALC262_HP_BPC,
 96         ALC262_HP_BPC_D7000_WL,
 97         ALC262_HP_BPC_D7000_WF,
 98         ALC262_HP_TC_T5735,
 99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112 
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129 
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_AMIC,
135         ALC269_ASUS_DMIC,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141 
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155 
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170 
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC663_ASUS_MODE7,
192         ALC663_ASUS_MODE8,
193         ALC272_DELL,
194         ALC272_DELL_ZM1,
195         ALC272_SAMSUNG_NC10,
196         ALC662_AUTO,
197         ALC662_MODEL_LAST,
198 };
199 
200 /* ALC882 models */
201 enum {
202         ALC882_3ST_DIG,
203         ALC882_6ST_DIG,
204         ALC882_ARIMA,
205         ALC882_W2JC,
206         ALC882_TARGA,
207         ALC882_ASUS_A7J,
208         ALC882_ASUS_A7M,
209         ALC885_MACPRO,
210         ALC885_MBP3,
211         ALC885_MB5,
212         ALC885_IMAC24,
213         ALC883_3ST_2ch_DIG,
214         ALC883_3ST_6ch_DIG,
215         ALC883_3ST_6ch,
216         ALC883_6ST_DIG,
217         ALC883_TARGA_DIG,
218         ALC883_TARGA_2ch_DIG,
219         ALC883_TARGA_8ch_DIG,
220         ALC883_ACER,
221         ALC883_ACER_ASPIRE,
222         ALC888_ACER_ASPIRE_4930G,
223         ALC888_ACER_ASPIRE_6530G,
224         ALC888_ACER_ASPIRE_8930G,
225         ALC888_ACER_ASPIRE_7730G,
226         ALC883_MEDION,
227         ALC883_MEDION_MD2,
228         ALC883_LAPTOP_EAPD,
229         ALC883_LENOVO_101E_2ch,
230         ALC883_LENOVO_NB0763,
231         ALC888_LENOVO_MS7195_DIG,
232         ALC888_LENOVO_SKY,
233         ALC883_HAIER_W66,
234         ALC888_3ST_HP,
235         ALC888_6ST_DELL,
236         ALC883_MITAC,
237         ALC883_CLEVO_M540R,
238         ALC883_CLEVO_M720,
239         ALC883_FUJITSU_PI2515,
240         ALC888_FUJITSU_XA3530,
241         ALC883_3ST_6ch_INTEL,
242         ALC889A_INTEL,
243         ALC889_INTEL,
244         ALC888_ASUS_M90V,
245         ALC888_ASUS_EEE1601,
246         ALC889A_MB31,
247         ALC1200_ASUS_P5Q,
248         ALC883_SONY_VAIO_TT,
249         ALC882_AUTO,
250         ALC882_MODEL_LAST,
251 };
252 
253 /* for GPIO Poll */
254 #define GPIO_MASK       0x03
255 
256 /* extra amp-initialization sequence types */
257 enum {
258         ALC_INIT_NONE,
259         ALC_INIT_DEFAULT,
260         ALC_INIT_GPIO1,
261         ALC_INIT_GPIO2,
262         ALC_INIT_GPIO3,
263 };
264 
265 struct alc_mic_route {
266         hda_nid_t pin;
267         unsigned char mux_idx;
268         unsigned char amix_idx;
269 };
270 
271 #define MUX_IDX_UNDEF   ((unsigned char)-1)
272 
273 struct alc_spec {
274         /* codec parameterization */
275         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
276         unsigned int num_mixers;
277         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
278         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
279 
280         const struct hda_verb *init_verbs[10];  /* initialization verbs
281                                                  * don't forget NULL
282                                                  * termination!
283                                                  */
284         unsigned int num_init_verbs;
285 
286         char stream_name_analog[32];    /* analog PCM stream */
287         struct hda_pcm_stream *stream_analog_playback;
288         struct hda_pcm_stream *stream_analog_capture;
289         struct hda_pcm_stream *stream_analog_alt_playback;
290         struct hda_pcm_stream *stream_analog_alt_capture;
291 
292         char stream_name_digital[32];   /* digital PCM stream */
293         struct hda_pcm_stream *stream_digital_playback;
294         struct hda_pcm_stream *stream_digital_capture;
295 
296         /* playback */
297         struct hda_multi_out multiout;  /* playback set-up
298                                          * max_channels, dacs must be set
299                                          * dig_out_nid and hp_nid are optional
300                                          */
301         hda_nid_t alt_dac_nid;
302         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
303         int dig_out_type;
304 
305         /* capture */
306         unsigned int num_adc_nids;
307         hda_nid_t *adc_nids;
308         hda_nid_t *capsrc_nids;
309         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
310 
311         /* capture source */
312         unsigned int num_mux_defs;
313         const struct hda_input_mux *input_mux;
314         unsigned int cur_mux[3];
315         struct alc_mic_route ext_mic;
316         struct alc_mic_route int_mic;
317 
318         /* channel model */
319         const struct hda_channel_mode *channel_mode;
320         int num_channel_mode;
321         int need_dac_fix;
322         int const_channel_count;
323         int ext_channel_count;
324 
325         /* PCM information */
326         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
327 
328         /* dynamic controls, init_verbs and input_mux */
329         struct auto_pin_cfg autocfg;
330         struct snd_array kctls;
331         struct hda_input_mux private_imux[3];
332         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
333         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
334         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
335 
336         /* hooks */
337         void (*init_hook)(struct hda_codec *codec);
338         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
339 
340         /* for pin sensing */
341         unsigned int sense_updated: 1;
342         unsigned int jack_present: 1;
343         unsigned int master_sw: 1;
344         unsigned int auto_mic:1;
345 
346         /* other flags */
347         unsigned int no_analog :1; /* digital I/O only */
348         int init_amp;
349 
350         /* for virtual master */
351         hda_nid_t vmaster_nid;
352 #ifdef CONFIG_SND_HDA_POWER_SAVE
353         struct hda_loopback_check loopback;
354 #endif
355 
356         /* for PLL fix */
357         hda_nid_t pll_nid;
358         unsigned int pll_coef_idx, pll_coef_bit;
359 };
360 
361 /*
362  * configuration template - to be copied to the spec instance
363  */
364 struct alc_config_preset {
365         struct snd_kcontrol_new *mixers[5]; /* should be identical size
366                                              * with spec
367                                              */
368         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
369         const struct hda_verb *init_verbs[5];
370         unsigned int num_dacs;
371         hda_nid_t *dac_nids;
372         hda_nid_t dig_out_nid;          /* optional */
373         hda_nid_t hp_nid;               /* optional */
374         hda_nid_t *slave_dig_outs;
375         unsigned int num_adc_nids;
376         hda_nid_t *adc_nids;
377         hda_nid_t *capsrc_nids;
378         hda_nid_t dig_in_nid;
379         unsigned int num_channel_mode;
380         const struct hda_channel_mode *channel_mode;
381         int need_dac_fix;
382         int const_channel_count;
383         unsigned int num_mux_defs;
384         const struct hda_input_mux *input_mux;
385         void (*unsol_event)(struct hda_codec *, unsigned int);
386         void (*setup)(struct hda_codec *);
387         void (*init_hook)(struct hda_codec *);
388 #ifdef CONFIG_SND_HDA_POWER_SAVE
389         struct hda_amp_list *loopbacks;
390 #endif
391 };
392 
393 
394 /*
395  * input MUX handling
396  */
397 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
398                              struct snd_ctl_elem_info *uinfo)
399 {
400         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401         struct alc_spec *spec = codec->spec;
402         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
403         if (mux_idx >= spec->num_mux_defs)
404                 mux_idx = 0;
405         if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
406                 mux_idx = 0;
407         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
408 }
409 
410 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
411                             struct snd_ctl_elem_value *ucontrol)
412 {
413         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
414         struct alc_spec *spec = codec->spec;
415         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
416 
417         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
418         return 0;
419 }
420 
421 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
422                             struct snd_ctl_elem_value *ucontrol)
423 {
424         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425         struct alc_spec *spec = codec->spec;
426         const struct hda_input_mux *imux;
427         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
428         unsigned int mux_idx;
429         hda_nid_t nid = spec->capsrc_nids ?
430                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
431         unsigned int type;
432 
433         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
434         imux = &spec->input_mux[mux_idx];
435         if (!imux->num_items && mux_idx > 0)
436                 imux = &spec->input_mux[0];
437         if (!imux->num_items)
438                 return 0;
439 
440         type = get_wcaps_type(get_wcaps(codec, nid));
441         if (type == AC_WID_AUD_MIX) {
442                 /* Matrix-mixer style (e.g. ALC882) */
443                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
444                 unsigned int i, idx;
445 
446                 idx = ucontrol->value.enumerated.item[0];
447                 if (idx >= imux->num_items)
448                         idx = imux->num_items - 1;
449                 if (*cur_val == idx)
450                         return 0;
451                 for (i = 0; i < imux->num_items; i++) {
452                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
453                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
454                                                  imux->items[i].index,
455                                                  HDA_AMP_MUTE, v);
456                 }
457                 *cur_val = idx;
458                 return 1;
459         } else {
460                 /* MUX style (e.g. ALC880) */
461                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
462                                              &spec->cur_mux[adc_idx]);
463         }
464 }
465 
466 /*
467  * channel mode setting
468  */
469 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
470                             struct snd_ctl_elem_info *uinfo)
471 {
472         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
473         struct alc_spec *spec = codec->spec;
474         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
475                                     spec->num_channel_mode);
476 }
477 
478 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
479                            struct snd_ctl_elem_value *ucontrol)
480 {
481         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
482         struct alc_spec *spec = codec->spec;
483         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
484                                    spec->num_channel_mode,
485                                    spec->ext_channel_count);
486 }
487 
488 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
489                            struct snd_ctl_elem_value *ucontrol)
490 {
491         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
492         struct alc_spec *spec = codec->spec;
493         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
494                                       spec->num_channel_mode,
495                                       &spec->ext_channel_count);
496         if (err >= 0 && !spec->const_channel_count) {
497                 spec->multiout.max_channels = spec->ext_channel_count;
498                 if (spec->need_dac_fix)
499                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
500         }
501         return err;
502 }
503 
504 /*
505  * Control the mode of pin widget settings via the mixer.  "pc" is used
506  * instead of "%" to avoid consequences of accidently treating the % as
507  * being part of a format specifier.  Maximum allowed length of a value is
508  * 63 characters plus NULL terminator.
509  *
510  * Note: some retasking pin complexes seem to ignore requests for input
511  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
512  * are requested.  Therefore order this list so that this behaviour will not
513  * cause problems when mixer clients move through the enum sequentially.
514  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
515  * March 2006.
516  */
517 static char *alc_pin_mode_names[] = {
518         "Mic 50pc bias", "Mic 80pc bias",
519         "Line in", "Line out", "Headphone out",
520 };
521 static unsigned char alc_pin_mode_values[] = {
522         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
523 };
524 /* The control can present all 5 options, or it can limit the options based
525  * in the pin being assumed to be exclusively an input or an output pin.  In
526  * addition, "input" pins may or may not process the mic bias option
527  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
528  * accept requests for bias as of chip versions up to March 2006) and/or
529  * wiring in the computer.
530  */
531 #define ALC_PIN_DIR_IN              0x00
532 #define ALC_PIN_DIR_OUT             0x01
533 #define ALC_PIN_DIR_INOUT           0x02
534 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
535 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
536 
537 /* Info about the pin modes supported by the different pin direction modes.
538  * For each direction the minimum and maximum values are given.
539  */
540 static signed char alc_pin_mode_dir_info[5][2] = {
541         { 0, 2 },    /* ALC_PIN_DIR_IN */
542         { 3, 4 },    /* ALC_PIN_DIR_OUT */
543         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
544         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
545         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
546 };
547 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
548 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
549 #define alc_pin_mode_n_items(_dir) \
550         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
551 
552 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
553                              struct snd_ctl_elem_info *uinfo)
554 {
555         unsigned int item_num = uinfo->value.enumerated.item;
556         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
557 
558         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
559         uinfo->count = 1;
560         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
561 
562         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
563                 item_num = alc_pin_mode_min(dir);
564         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
565         return 0;
566 }
567 
568 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
569                             struct snd_ctl_elem_value *ucontrol)
570 {
571         unsigned int i;
572         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
573         hda_nid_t nid = kcontrol->private_value & 0xffff;
574         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
575         long *valp = ucontrol->value.integer.value;
576         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
577                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
578                                                  0x00);
579 
580         /* Find enumerated value for current pinctl setting */
581         i = alc_pin_mode_min(dir);
582         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
583                 i++;
584         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
585         return 0;
586 }
587 
588 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
589                             struct snd_ctl_elem_value *ucontrol)
590 {
591         signed int change;
592         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
593         hda_nid_t nid = kcontrol->private_value & 0xffff;
594         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
595         long val = *ucontrol->value.integer.value;
596         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
597                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
598                                                  0x00);
599 
600         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
601                 val = alc_pin_mode_min(dir);
602 
603         change = pinctl != alc_pin_mode_values[val];
604         if (change) {
605                 /* Set pin mode to that requested */
606                 snd_hda_codec_write_cache(codec, nid, 0,
607                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
608                                           alc_pin_mode_values[val]);
609 
610                 /* Also enable the retasking pin's input/output as required
611                  * for the requested pin mode.  Enum values of 2 or less are
612                  * input modes.
613                  *
614                  * Dynamically switching the input/output buffers probably
615                  * reduces noise slightly (particularly on input) so we'll
616                  * do it.  However, having both input and output buffers
617                  * enabled simultaneously doesn't seem to be problematic if
618                  * this turns out to be necessary in the future.
619                  */
620                 if (val <= 2) {
621                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
622                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
623                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
624                                                  HDA_AMP_MUTE, 0);
625                 } else {
626                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
627                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
628                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
629                                                  HDA_AMP_MUTE, 0);
630                 }
631         }
632         return change;
633 }
634 
635 #define ALC_PIN_MODE(xname, nid, dir) \
636         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
637           .info = alc_pin_mode_info, \
638           .get = alc_pin_mode_get, \
639           .put = alc_pin_mode_put, \
640           .private_value = nid | (dir<<16) }
641 
642 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
643  * together using a mask with more than one bit set.  This control is
644  * currently used only by the ALC260 test model.  At this stage they are not
645  * needed for any "production" models.
646  */
647 #ifdef CONFIG_SND_DEBUG
648 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
649 
650 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
651                              struct snd_ctl_elem_value *ucontrol)
652 {
653         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654         hda_nid_t nid = kcontrol->private_value & 0xffff;
655         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
656         long *valp = ucontrol->value.integer.value;
657         unsigned int val = snd_hda_codec_read(codec, nid, 0,
658                                               AC_VERB_GET_GPIO_DATA, 0x00);
659 
660         *valp = (val & mask) != 0;
661         return 0;
662 }
663 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
664                              struct snd_ctl_elem_value *ucontrol)
665 {
666         signed int change;
667         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668         hda_nid_t nid = kcontrol->private_value & 0xffff;
669         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
670         long val = *ucontrol->value.integer.value;
671         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
672                                                     AC_VERB_GET_GPIO_DATA,
673                                                     0x00);
674 
675         /* Set/unset the masked GPIO bit(s) as needed */
676         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
677         if (val == 0)
678                 gpio_data &= ~mask;
679         else
680                 gpio_data |= mask;
681         snd_hda_codec_write_cache(codec, nid, 0,
682                                   AC_VERB_SET_GPIO_DATA, gpio_data);
683 
684         return change;
685 }
686 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
687         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
688           .info = alc_gpio_data_info, \
689           .get = alc_gpio_data_get, \
690           .put = alc_gpio_data_put, \
691           .private_value = nid | (mask<<16) }
692 #endif   /* CONFIG_SND_DEBUG */
693 
694 /* A switch control to allow the enabling of the digital IO pins on the
695  * ALC260.  This is incredibly simplistic; the intention of this control is
696  * to provide something in the test model allowing digital outputs to be
697  * identified if present.  If models are found which can utilise these
698  * outputs a more complete mixer control can be devised for those models if
699  * necessary.
700  */
701 #ifdef CONFIG_SND_DEBUG
702 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
703 
704 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
705                               struct snd_ctl_elem_value *ucontrol)
706 {
707         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
708         hda_nid_t nid = kcontrol->private_value & 0xffff;
709         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
710         long *valp = ucontrol->value.integer.value;
711         unsigned int val = snd_hda_codec_read(codec, nid, 0,
712                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
713 
714         *valp = (val & mask) != 0;
715         return 0;
716 }
717 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
718                               struct snd_ctl_elem_value *ucontrol)
719 {
720         signed int change;
721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722         hda_nid_t nid = kcontrol->private_value & 0xffff;
723         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
724         long val = *ucontrol->value.integer.value;
725         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
726                                                     AC_VERB_GET_DIGI_CONVERT_1,
727                                                     0x00);
728 
729         /* Set/unset the masked control bit(s) as needed */
730         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
731         if (val==0)
732                 ctrl_data &= ~mask;
733         else
734                 ctrl_data |= mask;
735         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
736                                   ctrl_data);
737 
738         return change;
739 }
740 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
741         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
742           .info = alc_spdif_ctrl_info, \
743           .get = alc_spdif_ctrl_get, \
744           .put = alc_spdif_ctrl_put, \
745           .private_value = nid | (mask<<16) }
746 #endif   /* CONFIG_SND_DEBUG */
747 
748 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
749  * Again, this is only used in the ALC26x test models to help identify when
750  * the EAPD line must be asserted for features to work.
751  */
752 #ifdef CONFIG_SND_DEBUG
753 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
754 
755 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
756                               struct snd_ctl_elem_value *ucontrol)
757 {
758         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
759         hda_nid_t nid = kcontrol->private_value & 0xffff;
760         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
761         long *valp = ucontrol->value.integer.value;
762         unsigned int val = snd_hda_codec_read(codec, nid, 0,
763                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
764 
765         *valp = (val & mask) != 0;
766         return 0;
767 }
768 
769 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
770                               struct snd_ctl_elem_value *ucontrol)
771 {
772         int change;
773         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
774         hda_nid_t nid = kcontrol->private_value & 0xffff;
775         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
776         long val = *ucontrol->value.integer.value;
777         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
778                                                     AC_VERB_GET_EAPD_BTLENABLE,
779                                                     0x00);
780 
781         /* Set/unset the masked control bit(s) as needed */
782         change = (!val ? 0 : mask) != (ctrl_data & mask);
783         if (!val)
784                 ctrl_data &= ~mask;
785         else
786                 ctrl_data |= mask;
787         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
788                                   ctrl_data);
789 
790         return change;
791 }
792 
793 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
794         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
795           .info = alc_eapd_ctrl_info, \
796           .get = alc_eapd_ctrl_get, \
797           .put = alc_eapd_ctrl_put, \
798           .private_value = nid | (mask<<16) }
799 #endif   /* CONFIG_SND_DEBUG */
800 
801 /*
802  * set up the input pin config (depending on the given auto-pin type)
803  */
804 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
805                               int auto_pin_type)
806 {
807         unsigned int val = PIN_IN;
808 
809         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
810                 unsigned int pincap;
811                 pincap = snd_hda_query_pin_caps(codec, nid);
812                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
813                 if (pincap & AC_PINCAP_VREF_80)
814                         val = PIN_VREF80;
815                 else if (pincap & AC_PINCAP_VREF_50)
816                         val = PIN_VREF50;
817                 else if (pincap & AC_PINCAP_VREF_100)
818                         val = PIN_VREF100;
819                 else if (pincap & AC_PINCAP_VREF_GRD)
820                         val = PIN_VREFGRD;
821         }
822         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
823 }
824 
825 /*
826  */
827 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
828 {
829         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
830                 return;
831         spec->mixers[spec->num_mixers++] = mix;
832 }
833 
834 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
835 {
836         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
837                 return;
838         spec->init_verbs[spec->num_init_verbs++] = verb;
839 }
840 
841 #ifdef CONFIG_PROC_FS
842 /*
843  * hook for proc
844  */
845 static void print_realtek_coef(struct snd_info_buffer *buffer,
846                                struct hda_codec *codec, hda_nid_t nid)
847 {
848         int coeff;
849 
850         if (nid != 0x20)
851                 return;
852         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
853         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
854         coeff = snd_hda_codec_read(codec, nid, 0,
855                                    AC_VERB_GET_COEF_INDEX, 0);
856         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
857 }
858 #else
859 #define print_realtek_coef      NULL
860 #endif
861 
862 /*
863  * set up from the preset table
864  */
865 static void setup_preset(struct hda_codec *codec,
866                          const struct alc_config_preset *preset)
867 {
868         struct alc_spec *spec = codec->spec;
869         int i;
870 
871         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
872                 add_mixer(spec, preset->mixers[i]);
873         spec->cap_mixer = preset->cap_mixer;
874         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
875              i++)
876                 add_verb(spec, preset->init_verbs[i]);
877 
878         spec->channel_mode = preset->channel_mode;
879         spec->num_channel_mode = preset->num_channel_mode;
880         spec->need_dac_fix = preset->need_dac_fix;
881         spec->const_channel_count = preset->const_channel_count;
882 
883         if (preset->const_channel_count)
884                 spec->multiout.max_channels = preset->const_channel_count;
885         else
886                 spec->multiout.max_channels = spec->channel_mode[0].channels;
887         spec->ext_channel_count = spec->channel_mode[0].channels;
888 
889         spec->multiout.num_dacs = preset->num_dacs;
890         spec->multiout.dac_nids = preset->dac_nids;
891         spec->multiout.dig_out_nid = preset->dig_out_nid;
892         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
893         spec->multiout.hp_nid = preset->hp_nid;
894 
895         spec->num_mux_defs = preset->num_mux_defs;
896         if (!spec->num_mux_defs)
897                 spec->num_mux_defs = 1;
898         spec->input_mux = preset->input_mux;
899 
900         spec->num_adc_nids = preset->num_adc_nids;
901         spec->adc_nids = preset->adc_nids;
902         spec->capsrc_nids = preset->capsrc_nids;
903         spec->dig_in_nid = preset->dig_in_nid;
904 
905         spec->unsol_event = preset->unsol_event;
906         spec->init_hook = preset->init_hook;
907 #ifdef CONFIG_SND_HDA_POWER_SAVE
908         spec->loopback.amplist = preset->loopbacks;
909 #endif
910 
911         if (preset->setup)
912                 preset->setup(codec);
913 }
914 
915 /* Enable GPIO mask and set output */
916 static struct hda_verb alc_gpio1_init_verbs[] = {
917         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
918         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
919         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
920         { }
921 };
922 
923 static struct hda_verb alc_gpio2_init_verbs[] = {
924         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
925         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
926         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
927         { }
928 };
929 
930 static struct hda_verb alc_gpio3_init_verbs[] = {
931         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
932         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
933         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
934         { }
935 };
936 
937 /*
938  * Fix hardware PLL issue
939  * On some codecs, the analog PLL gating control must be off while
940  * the default value is 1.
941  */
942 static void alc_fix_pll(struct hda_codec *codec)
943 {
944         struct alc_spec *spec = codec->spec;
945         unsigned int val;
946 
947         if (!spec->pll_nid)
948                 return;
949         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
950                             spec->pll_coef_idx);
951         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
952                                  AC_VERB_GET_PROC_COEF, 0);
953         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
954                             spec->pll_coef_idx);
955         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
956                             val & ~(1 << spec->pll_coef_bit));
957 }
958 
959 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
960                              unsigned int coef_idx, unsigned int coef_bit)
961 {
962         struct alc_spec *spec = codec->spec;
963         spec->pll_nid = nid;
964         spec->pll_coef_idx = coef_idx;
965         spec->pll_coef_bit = coef_bit;
966         alc_fix_pll(codec);
967 }
968 
969 static void alc_automute_pin(struct hda_codec *codec)
970 {
971         struct alc_spec *spec = codec->spec;
972         unsigned int present, pincap;
973         unsigned int nid = spec->autocfg.hp_pins[0];
974         int i;
975 
976         if (!nid)
977                 return;
978         pincap = snd_hda_query_pin_caps(codec, nid);
979         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
980                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
981         present = snd_hda_codec_read(codec, nid, 0,
982                                      AC_VERB_GET_PIN_SENSE, 0);
983         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
984         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
985                 nid = spec->autocfg.speaker_pins[i];
986                 if (!nid)
987                         break;
988                 snd_hda_codec_write(codec, nid, 0,
989                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
990                                     spec->jack_present ? 0 : PIN_OUT);
991         }
992 }
993 
994 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
995                                 hda_nid_t nid)
996 {
997         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
998         int i, nums;
999 
1000         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
1001         for (i = 0; i < nums; i++)
1002                 if (conn[i] == nid)
1003                         return i;
1004         return -1;
1005 }
1006 
1007 static void alc_mic_automute(struct hda_codec *codec)
1008 {
1009         struct alc_spec *spec = codec->spec;
1010         struct alc_mic_route *dead, *alive;
1011         unsigned int present, type;
1012         hda_nid_t cap_nid;
1013 
1014         if (!spec->auto_mic)
1015                 return;
1016         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1017                 return;
1018         if (snd_BUG_ON(!spec->adc_nids))
1019                 return;
1020 
1021         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1022 
1023         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1024                                      AC_VERB_GET_PIN_SENSE, 0);
1025         present &= AC_PINSENSE_PRESENCE;
1026         if (present) {
1027                 alive = &spec->ext_mic;
1028                 dead = &spec->int_mic;
1029         } else {
1030                 alive = &spec->int_mic;
1031                 dead = &spec->ext_mic;
1032         }
1033 
1034         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1035         if (type == AC_WID_AUD_MIX) {
1036                 /* Matrix-mixer style (e.g. ALC882) */
1037                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1038                                          alive->mux_idx,
1039                                          HDA_AMP_MUTE, 0);
1040                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1041                                          dead->mux_idx,
1042                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1043         } else {
1044                 /* MUX style (e.g. ALC880) */
1045                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1046                                           AC_VERB_SET_CONNECT_SEL,
1047                                           alive->mux_idx);
1048         }
1049 
1050         /* FIXME: analog mixer */
1051 }
1052 
1053 /* unsolicited event for HP jack sensing */
1054 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1055 {
1056         if (codec->vendor_id == 0x10ec0880)
1057                 res >>= 28;
1058         else
1059                 res >>= 26;
1060         switch (res) {
1061         case ALC880_HP_EVENT:
1062                 alc_automute_pin(codec);
1063                 break;
1064         case ALC880_MIC_EVENT:
1065                 alc_mic_automute(codec);
1066                 break;
1067         }
1068 }
1069 
1070 static void alc_inithook(struct hda_codec *codec)
1071 {
1072         alc_automute_pin(codec);
1073         alc_mic_automute(codec);
1074 }
1075 
1076 /* additional initialization for ALC888 variants */
1077 static void alc888_coef_init(struct hda_codec *codec)
1078 {
1079         unsigned int tmp;
1080 
1081         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1082         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1083         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1084         if ((tmp & 0xf0) == 0x20)
1085                 /* alc888S-VC */
1086                 snd_hda_codec_read(codec, 0x20, 0,
1087                                    AC_VERB_SET_PROC_COEF, 0x830);
1088          else
1089                  /* alc888-VB */
1090                  snd_hda_codec_read(codec, 0x20, 0,
1091                                     AC_VERB_SET_PROC_COEF, 0x3030);
1092 }
1093 
1094 static void alc889_coef_init(struct hda_codec *codec)
1095 {
1096         unsigned int tmp;
1097 
1098         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1099         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1100         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1101         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1102 }
1103 
1104 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1105 {
1106         unsigned int tmp;
1107 
1108         switch (type) {
1109         case ALC_INIT_GPIO1:
1110                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1111                 break;
1112         case ALC_INIT_GPIO2:
1113                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1114                 break;
1115         case ALC_INIT_GPIO3:
1116                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1117                 break;
1118         case ALC_INIT_DEFAULT:
1119                 switch (codec->vendor_id) {
1120                 case 0x10ec0260:
1121                         snd_hda_codec_write(codec, 0x0f, 0,
1122                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1123                         snd_hda_codec_write(codec, 0x10, 0,
1124                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1125                         break;
1126                 case 0x10ec0262:
1127                 case 0x10ec0267:
1128                 case 0x10ec0268:
1129                 case 0x10ec0269:
1130                 case 0x10ec0272:
1131                 case 0x10ec0660:
1132                 case 0x10ec0662:
1133                 case 0x10ec0663:
1134                 case 0x10ec0862:
1135                 case 0x10ec0889:
1136                         snd_hda_codec_write(codec, 0x14, 0,
1137                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1138                         snd_hda_codec_write(codec, 0x15, 0,
1139                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1140                         break;
1141                 }
1142                 switch (codec->vendor_id) {
1143                 case 0x10ec0260:
1144                         snd_hda_codec_write(codec, 0x1a, 0,
1145                                             AC_VERB_SET_COEF_INDEX, 7);
1146                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1147                                                  AC_VERB_GET_PROC_COEF, 0);
1148                         snd_hda_codec_write(codec, 0x1a, 0,
1149                                             AC_VERB_SET_COEF_INDEX, 7);
1150                         snd_hda_codec_write(codec, 0x1a, 0,
1151                                             AC_VERB_SET_PROC_COEF,
1152                                             tmp | 0x2010);
1153                         break;
1154                 case 0x10ec0262:
1155                 case 0x10ec0880:
1156                 case 0x10ec0882:
1157                 case 0x10ec0883:
1158                 case 0x10ec0885:
1159                 case 0x10ec0887:
1160                 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
1161                         alc889_coef_init(codec);
1162                         break;
1163                 case 0x10ec0888:
1164                         alc888_coef_init(codec);
1165                         break;
1166                 case 0x10ec0267:
1167                 case 0x10ec0268:
1168                         snd_hda_codec_write(codec, 0x20, 0,
1169                                             AC_VERB_SET_COEF_INDEX, 7);
1170                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1171                                                  AC_VERB_GET_PROC_COEF, 0);
1172                         snd_hda_codec_write(codec, 0x20, 0,
1173                                             AC_VERB_SET_COEF_INDEX, 7);
1174                         snd_hda_codec_write(codec, 0x20, 0,
1175                                             AC_VERB_SET_PROC_COEF,
1176                                             tmp | 0x3000);
1177                         break;
1178                 }
1179                 break;
1180         }
1181 }
1182 
1183 static void alc_init_auto_hp(struct hda_codec *codec)
1184 {
1185         struct alc_spec *spec = codec->spec;
1186 
1187         if (!spec->autocfg.hp_pins[0])
1188                 return;
1189 
1190         if (!spec->autocfg.speaker_pins[0]) {
1191                 if (spec->autocfg.line_out_pins[0] &&
1192                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1193                         spec->autocfg.speaker_pins[0] =
1194                                 spec->autocfg.line_out_pins[0];
1195                 else
1196                         return;
1197         }
1198 
1199         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1200                     spec->autocfg.hp_pins[0]);
1201         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1202                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1203                                   AC_USRSP_EN | ALC880_HP_EVENT);
1204         spec->unsol_event = alc_sku_unsol_event;
1205 }
1206 
1207 static void alc_init_auto_mic(struct hda_codec *codec)
1208 {
1209         struct alc_spec *spec = codec->spec;
1210         struct auto_pin_cfg *cfg = &spec->autocfg;
1211         hda_nid_t fixed, ext;
1212         int i;
1213 
1214         /* there must be only two mic inputs exclusively */
1215         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1216                 if (cfg->input_pins[i])
1217                         return;
1218 
1219         fixed = ext = 0;
1220         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1221                 hda_nid_t nid = cfg->input_pins[i];
1222                 unsigned int defcfg;
1223                 if (!nid)
1224                         return;
1225                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1226                 switch (get_defcfg_connect(defcfg)) {
1227                 case AC_JACK_PORT_FIXED:
1228                         if (fixed)
1229                                 return; /* already occupied */
1230                         fixed = nid;
1231                         break;
1232                 case AC_JACK_PORT_COMPLEX:
1233                         if (ext)
1234                                 return; /* already occupied */
1235                         ext = nid;
1236                         break;
1237                 default:
1238                         return; /* invalid entry */
1239                 }
1240         }
1241         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1242                 return; /* no unsol support */
1243         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1244                     ext, fixed);
1245         spec->ext_mic.pin = ext;
1246         spec->int_mic.pin = fixed;
1247         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1248         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1249         spec->auto_mic = 1;
1250         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1251                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1252                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1253         spec->unsol_event = alc_sku_unsol_event;
1254 }
1255 
1256 /* check subsystem ID and set up device-specific initialization;
1257  * return 1 if initialized, 0 if invalid SSID
1258  */
1259 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1260  *      31 ~ 16 :       Manufacture ID
1261  *      15 ~ 8  :       SKU ID
1262  *      7  ~ 0  :       Assembly ID
1263  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1264  */
1265 static int alc_subsystem_id(struct hda_codec *codec,
1266                             hda_nid_t porta, hda_nid_t porte,
1267                             hda_nid_t portd)
1268 {
1269         unsigned int ass, tmp, i;
1270         unsigned nid;
1271         struct alc_spec *spec = codec->spec;
1272 
1273         ass = codec->subsystem_id & 0xffff;
1274         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1275                 goto do_sku;
1276 
1277         /* invalid SSID, check the special NID pin defcfg instead */
1278         /*
1279          * 31~30        : port connectivity
1280          * 29~21        : reserve
1281          * 20           : PCBEEP input
1282          * 19~16        : Check sum (15:1)
1283          * 15~1         : Custom
1284          * 0            : override
1285         */
1286         nid = 0x1d;
1287         if (codec->vendor_id == 0x10ec0260)
1288                 nid = 0x17;
1289         ass = snd_hda_codec_get_pincfg(codec, nid);
1290         snd_printd("realtek: No valid SSID, "
1291                    "checking pincfg 0x%08x for NID 0x%x\n",
1292                    ass, nid);
1293         if (!(ass & 1) && !(ass & 0x100000))
1294                 return 0;
1295         if ((ass >> 30) != 1)   /* no physical connection */
1296                 return 0;
1297 
1298         /* check sum */
1299         tmp = 0;
1300         for (i = 1; i < 16; i++) {
1301                 if ((ass >> i) & 1)
1302                         tmp++;
1303         }
1304         if (((ass >> 16) & 0xf) != tmp)
1305                 return 0;
1306 do_sku:
1307         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1308                    ass & 0xffff, codec->vendor_id);
1309         /*
1310          * 0 : override
1311          * 1 :  Swap Jack
1312          * 2 : 0 --> Desktop, 1 --> Laptop
1313          * 3~5 : External Amplifier control
1314          * 7~6 : Reserved
1315         */
1316         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1317         switch (tmp) {
1318         case 1:
1319                 spec->init_amp = ALC_INIT_GPIO1;
1320                 break;
1321         case 3:
1322                 spec->init_amp = ALC_INIT_GPIO2;
1323                 break;
1324         case 7:
1325                 spec->init_amp = ALC_INIT_GPIO3;
1326                 break;
1327         case 5:
1328                 spec->init_amp = ALC_INIT_DEFAULT;
1329                 break;
1330         }
1331 
1332         /* is laptop or Desktop and enable the function "Mute internal speaker
1333          * when the external headphone out jack is plugged"
1334          */
1335         if (!(ass & 0x8000))
1336                 return 1;
1337         /*
1338          * 10~8 : Jack location
1339          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1340          * 14~13: Resvered
1341          * 15   : 1 --> enable the function "Mute internal speaker
1342          *              when the external headphone out jack is plugged"
1343          */
1344         if (!spec->autocfg.hp_pins[0] &&
1345             !(spec->autocfg.line_out_pins[0] &&
1346               spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1347                 hda_nid_t nid;
1348                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1349                 if (tmp == 0)
1350                         nid = porta;
1351                 else if (tmp == 1)
1352                         nid = porte;
1353                 else if (tmp == 2)
1354                         nid = portd;
1355                 else
1356                         return 1;
1357                 for (i = 0; i < spec->autocfg.line_outs; i++)
1358                         if (spec->autocfg.line_out_pins[i] == nid)
1359                                 return 1;
1360                 spec->autocfg.hp_pins[0] = nid;
1361         }
1362 
1363         alc_init_auto_hp(codec);
1364         alc_init_auto_mic(codec);
1365         return 1;
1366 }
1367 
1368 static void alc_ssid_check(struct hda_codec *codec,
1369                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1370 {
1371         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1372                 struct alc_spec *spec = codec->spec;
1373                 snd_printd("realtek: "
1374                            "Enable default setup for auto mode as fallback\n");
1375                 spec->init_amp = ALC_INIT_DEFAULT;
1376                 alc_init_auto_hp(codec);
1377                 alc_init_auto_mic(codec);
1378         }
1379 }
1380 
1381 /*
1382  * Fix-up pin default configurations and add default verbs
1383  */
1384 
1385 struct alc_pincfg {
1386         hda_nid_t nid;
1387         u32 val;
1388 };
1389 
1390 struct alc_fixup {
1391         const struct alc_pincfg *pins;
1392         const struct hda_verb *verbs;
1393 };
1394 
1395 static void alc_pick_fixup(struct hda_codec *codec,
1396                            const struct snd_pci_quirk *quirk,
1397                            const struct alc_fixup *fix)
1398 {
1399         const struct alc_pincfg *cfg;
1400 
1401         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1402         if (!quirk)
1403                 return;
1404 
1405         fix += quirk->value;
1406         cfg = fix->pins;
1407         if (cfg) {
1408                 for (; cfg->nid; cfg++)
1409                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1410         }
1411         if (fix->verbs)
1412                 add_verb(codec->spec, fix->verbs);
1413 }
1414 
1415 /*
1416  * ALC888
1417  */
1418 
1419 /*
1420  * 2ch mode
1421  */
1422 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1423 /* Mic-in jack as mic in */
1424         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1425         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1426 /* Line-in jack as Line in */
1427         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1428         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1429 /* Line-Out as Front */
1430         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1431         { } /* end */
1432 };
1433 
1434 /*
1435  * 4ch mode
1436  */
1437 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1438 /* Mic-in jack as mic in */
1439         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1440         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1441 /* Line-in jack as Surround */
1442         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1443         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1444 /* Line-Out as Front */
1445         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1446         { } /* end */
1447 };
1448 
1449 /*
1450  * 6ch mode
1451  */
1452 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1453 /* Mic-in jack as CLFE */
1454         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1455         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1456 /* Line-in jack as Surround */
1457         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1458         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1459 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1460         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1461         { } /* end */
1462 };
1463 
1464 /*
1465  * 8ch mode
1466  */
1467 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1468 /* Mic-in jack as CLFE */
1469         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1470         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1471 /* Line-in jack as Surround */
1472         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1473         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1474 /* Line-Out as Side */
1475         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1476         { } /* end */
1477 };
1478 
1479 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1480         { 2, alc888_4ST_ch2_intel_init },
1481         { 4, alc888_4ST_ch4_intel_init },
1482         { 6, alc888_4ST_ch6_intel_init },
1483         { 8, alc888_4ST_ch8_intel_init },
1484 };
1485 
1486 /*
1487  * ALC888 Fujitsu Siemens Amillo xa3530
1488  */
1489 
1490 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1491 /* Front Mic: set to PIN_IN (empty by default) */
1492         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1493 /* Connect Internal HP to Front */
1494         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1495         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1497 /* Connect Bass HP to Front */
1498         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1499         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1500         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1501 /* Connect Line-Out side jack (SPDIF) to Side */
1502         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1503         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1504         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1505 /* Connect Mic jack to CLFE */
1506         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1507         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1508         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1509 /* Connect Line-in jack to Surround */
1510         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1511         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1512         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1513 /* Connect HP out jack to Front */
1514         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1515         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1517 /* Enable unsolicited event for HP jack and Line-out jack */
1518         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1519         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1520         {}
1521 };
1522 
1523 static void alc_automute_amp(struct hda_codec *codec)
1524 {
1525         struct alc_spec *spec = codec->spec;
1526         unsigned int val, mute, pincap;
1527         hda_nid_t nid;
1528         int i;
1529 
1530         spec->jack_present = 0;
1531         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1532                 nid = spec->autocfg.hp_pins[i];
1533                 if (!nid)
1534                         break;
1535                 pincap = snd_hda_query_pin_caps(codec, nid);
1536                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1537                         snd_hda_codec_read(codec, nid, 0,
1538                                            AC_VERB_SET_PIN_SENSE, 0);
1539                 val = snd_hda_codec_read(codec, nid, 0,
1540                                          AC_VERB_GET_PIN_SENSE, 0);
1541                 if (val & AC_PINSENSE_PRESENCE) {
1542                         spec->jack_present = 1;
1543                         break;
1544                 }
1545         }
1546 
1547         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1548         /* Toggle internal speakers muting */
1549         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1550                 nid = spec->autocfg.speaker_pins[i];
1551                 if (!nid)
1552                         break;
1553                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1554                                          HDA_AMP_MUTE, mute);
1555         }
1556 }
1557 
1558 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1559                                          unsigned int res)
1560 {
1561         if (codec->vendor_id == 0x10ec0880)
1562                 res >>= 28;
1563         else
1564                 res >>= 26;
1565         if (res == ALC880_HP_EVENT)
1566                 alc_automute_amp(codec);
1567 }
1568 
1569 static void alc889_automute_setup(struct hda_codec *codec)
1570 {
1571         struct alc_spec *spec = codec->spec;
1572 
1573         spec->autocfg.hp_pins[0] = 0x15;
1574         spec->autocfg.speaker_pins[0] = 0x14;
1575         spec->autocfg.speaker_pins[1] = 0x16;
1576         spec->autocfg.speaker_pins[2] = 0x17;
1577         spec->autocfg.speaker_pins[3] = 0x19;
1578         spec->autocfg.speaker_pins[4] = 0x1a;
1579 }
1580 
1581 static void alc889_intel_init_hook(struct hda_codec *codec)
1582 {
1583         alc889_coef_init(codec);
1584         alc_automute_amp(codec);
1585 }
1586 
1587 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1588 {
1589         struct alc_spec *spec = codec->spec;
1590 
1591         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1592         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1593         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1594         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1595 }
1596 
1597 /*
1598  * ALC888 Acer Aspire 4930G model
1599  */
1600 
1601 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1602 /* Front Mic: set to PIN_IN (empty by default) */
1603         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1604 /* Unselect Front Mic by default in input mixer 3 */
1605         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1606 /* Enable unsolicited event for HP jack */
1607         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1608 /* Connect Internal HP to front */
1609         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1610         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1611         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1612 /* Connect HP out to front */
1613         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1614         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1615         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1616         { }
1617 };
1618 
1619 /*
1620  * ALC888 Acer Aspire 6530G model
1621  */
1622 
1623 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1624 /* Bias voltage on for external mic port */
1625         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1626 /* Front Mic: set to PIN_IN (empty by default) */
1627         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1628 /* Unselect Front Mic by default in input mixer 3 */
1629         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1630 /* Enable unsolicited event for HP jack */
1631         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1632 /* Enable speaker output */
1633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1634         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1635 /* Enable headphone output */
1636         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1637         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1638         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1639         { }
1640 };
1641 
1642 /*
1643  * ALC889 Acer Aspire 8930G model
1644  */
1645 
1646 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1647 /* Front Mic: set to PIN_IN (empty by default) */
1648         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1649 /* Unselect Front Mic by default in input mixer 3 */
1650         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1651 /* Enable unsolicited event for HP jack */
1652         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1653 /* Connect Internal Front to Front */
1654         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1655         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1656         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1657 /* Connect Internal Rear to Rear */
1658         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1659         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1660         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1661 /* Connect Internal CLFE to CLFE */
1662         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1663         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1664         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1665 /* Connect HP out to Front */
1666         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1667         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1668         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1669 /* Enable all DACs */
1670 /*  DAC DISABLE/MUTE 1? */
1671 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1672         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1673         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1674 /*  DAC DISABLE/MUTE 2? */
1675 /*  some bit here disables the other DACs. Init=0x4900 */
1676         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1677         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1678 /* Enable amplifiers */
1679         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1680         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1681 /* DMIC fix
1682  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1683  * which makes the stereo useless. However, either the mic or the ALC889
1684  * makes the signal become a difference/sum signal instead of standard
1685  * stereo, which is annoying. So instead we flip this bit which makes the
1686  * codec replicate the sum signal to both channels, turning it into a
1687  * normal mono mic.
1688  */
1689 /*  DMIC_CONTROL? Init value = 0x0001 */
1690         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1691         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1692         { }
1693 };
1694 
1695 static struct hda_input_mux alc888_2_capture_sources[2] = {
1696         /* Front mic only available on one ADC */
1697         {
1698                 .num_items = 4,
1699                 .items = {
1700                         { "Mic", 0x0 },
1701                         { "Line", 0x2 },
1702                         { "CD", 0x4 },
1703                         { "Front Mic", 0xb },
1704                 },
1705         },
1706         {
1707                 .num_items = 3,
1708                 .items = {
1709                         { "Mic", 0x0 },
1710                         { "Line", 0x2 },
1711                         { "CD", 0x4 },
1712                 },
1713         }
1714 };
1715 
1716 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1717         /* Interal mic only available on one ADC */
1718         {
1719                 .num_items = 5,
1720                 .items = {
1721                         { "Ext Mic", 0x0 },
1722                         { "Line In", 0x2 },
1723                         { "CD", 0x4 },
1724                         { "Input Mix", 0xa },
1725                         { "Int Mic", 0xb },
1726                 },
1727         },
1728         {
1729                 .num_items = 4,
1730                 .items = {
1731                         { "Ext Mic", 0x0 },
1732                         { "Line In", 0x2 },
1733                         { "CD", 0x4 },
1734                         { "Input Mix", 0xa },
1735                 },
1736         }
1737 };
1738 
1739 static struct hda_input_mux alc889_capture_sources[3] = {
1740         /* Digital mic only available on first "ADC" */
1741         {
1742                 .num_items = 5,
1743                 .items = {
1744                         { "Mic", 0x0 },
1745                         { "Line", 0x2 },
1746                         { "CD", 0x4 },
1747                         { "Front Mic", 0xb },
1748                         { "Input Mix", 0xa },
1749                 },
1750         },
1751         {
1752                 .num_items = 4,
1753                 .items = {
1754                         { "Mic", 0x0 },
1755                         { "Line", 0x2 },
1756                         { "CD", 0x4 },
1757                         { "Input Mix", 0xa },
1758                 },
1759         },
1760         {
1761                 .num_items = 4,
1762                 .items = {
1763                         { "Mic", 0x0 },
1764                         { "Line", 0x2 },
1765                         { "CD", 0x4 },
1766                         { "Input Mix", 0xa },
1767                 },
1768         }
1769 };
1770 
1771 static struct snd_kcontrol_new alc888_base_mixer[] = {
1772         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1773         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1774         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1775         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1776         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1777                 HDA_OUTPUT),
1778         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1779         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1780         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1781         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1782         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1783         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1784         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1785         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1786         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1787         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1788         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1789         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1790         { } /* end */
1791 };
1792 
1793 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1794 {
1795         struct alc_spec *spec = codec->spec;
1796 
1797         spec->autocfg.hp_pins[0] = 0x15;
1798         spec->autocfg.speaker_pins[0] = 0x14;
1799 }
1800 
1801 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1802 {
1803         struct alc_spec *spec = codec->spec;
1804 
1805         spec->autocfg.hp_pins[0] = 0x15;
1806         spec->autocfg.speaker_pins[0] = 0x14;
1807         spec->autocfg.speaker_pins[1] = 0x16;
1808         spec->autocfg.speaker_pins[2] = 0x17;
1809 }
1810 
1811 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1812 {
1813         struct alc_spec *spec = codec->spec;
1814 
1815         spec->autocfg.hp_pins[0] = 0x15;
1816         spec->autocfg.speaker_pins[0] = 0x14;
1817         spec->autocfg.speaker_pins[1] = 0x16;
1818         spec->autocfg.speaker_pins[2] = 0x1b;
1819 }
1820 
1821 /*
1822  * ALC880 3-stack model
1823  *
1824  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1825  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1826  *                 F-Mic = 0x1b, HP = 0x19
1827  */
1828 
1829 static hda_nid_t alc880_dac_nids[4] = {
1830         /* front, rear, clfe, rear_surr */
1831         0x02, 0x05, 0x04, 0x03
1832 };
1833 
1834 static hda_nid_t alc880_adc_nids[3] = {
1835         /* ADC0-2 */
1836         0x07, 0x08, 0x09,
1837 };
1838 
1839 /* The datasheet says the node 0x07 is connected from inputs,
1840  * but it shows zero connection in the real implementation on some devices.
1841  * Note: this is a 915GAV bug, fixed on 915GLV
1842  */
1843 static hda_nid_t alc880_adc_nids_alt[2] = {
1844         /* ADC1-2 */
1845         0x08, 0x09,
1846 };
1847 
1848 #define ALC880_DIGOUT_NID       0x06
1849 #define ALC880_DIGIN_NID        0x0a
1850 
1851 static struct hda_input_mux alc880_capture_source = {
1852         .num_items = 4,
1853         .items = {
1854                 { "Mic", 0x0 },
1855                 { "Front Mic", 0x3 },
1856                 { "Line", 0x2 },
1857                 { "CD", 0x4 },
1858         },
1859 };
1860 
1861 /* channel source setting (2/6 channel selection for 3-stack) */
1862 /* 2ch mode */
1863 static struct hda_verb alc880_threestack_ch2_init[] = {
1864         /* set line-in to input, mute it */
1865         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1866         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1867         /* set mic-in to input vref 80%, mute it */
1868         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1869         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1870         { } /* end */
1871 };
1872 
1873 /* 6ch mode */
1874 static struct hda_verb alc880_threestack_ch6_init[] = {
1875         /* set line-in to output, unmute it */
1876         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1877         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1878         /* set mic-in to output, unmute it */
1879         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1880         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1881         { } /* end */
1882 };
1883 
1884 static struct hda_channel_mode alc880_threestack_modes[2] = {
1885         { 2, alc880_threestack_ch2_init },
1886         { 6, alc880_threestack_ch6_init },
1887 };
1888 
1889 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1890         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1891         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1892         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1893         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1894         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1895         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1896         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1897         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1898         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1899         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1900         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1901         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1902         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1904         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1905         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1906         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1907         {
1908                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1909                 .name = "Channel Mode",
1910                 .info = alc_ch_mode_info,
1911                 .get = alc_ch_mode_get,
1912                 .put = alc_ch_mode_put,
1913         },
1914         { } /* end */
1915 };
1916 
1917 /* capture mixer elements */
1918 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1919                             struct snd_ctl_elem_info *uinfo)
1920 {
1921         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1922         struct alc_spec *spec = codec->spec;
1923         int err;
1924 
1925         mutex_lock(&codec->control_mutex);
1926         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1927                                                       HDA_INPUT);
1928         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1929         mutex_unlock(&codec->control_mutex);
1930         return err;
1931 }
1932 
1933 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1934                            unsigned int size, unsigned int __user *tlv)
1935 {
1936         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1937         struct alc_spec *spec = codec->spec;
1938         int err;
1939 
1940         mutex_lock(&codec->control_mutex);
1941         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1942                                                       HDA_INPUT);
1943         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1944         mutex_unlock(&codec->control_mutex);
1945         return err;
1946 }
1947 
1948 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1949                              struct snd_ctl_elem_value *ucontrol);
1950 
1951 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1952                                  struct snd_ctl_elem_value *ucontrol,
1953                                  getput_call_t func)
1954 {
1955         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1956         struct alc_spec *spec = codec->spec;
1957         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1958         int err;
1959 
1960         mutex_lock(&codec->control_mutex);
1961         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1962                                                       3, 0, HDA_INPUT);
1963         err = func(kcontrol, ucontrol);
1964         mutex_unlock(&codec->control_mutex);
1965         return err;
1966 }
1967 
1968 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1969                            struct snd_ctl_elem_value *ucontrol)
1970 {
1971         return alc_cap_getput_caller(kcontrol, ucontrol,
1972                                      snd_hda_mixer_amp_volume_get);
1973 }
1974 
1975 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1976                            struct snd_ctl_elem_value *ucontrol)
1977 {
1978         return alc_cap_getput_caller(kcontrol, ucontrol,
1979                                      snd_hda_mixer_amp_volume_put);
1980 }
1981 
1982 /* capture mixer elements */
1983 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1984 
1985 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1986                           struct snd_ctl_elem_value *ucontrol)
1987 {
1988         return alc_cap_getput_caller(kcontrol, ucontrol,
1989                                      snd_hda_mixer_amp_switch_get);
1990 }
1991 
1992 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1993                           struct snd_ctl_elem_value *ucontrol)
1994 {
1995         return alc_cap_getput_caller(kcontrol, ucontrol,
1996                                      snd_hda_mixer_amp_switch_put);
1997 }
1998 
1999 #define _DEFINE_CAPMIX(num) \
2000         { \
2001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2002                 .name = "Capture Switch", \
2003                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2004                 .count = num, \
2005                 .info = alc_cap_sw_info, \
2006                 .get = alc_cap_sw_get, \
2007                 .put = alc_cap_sw_put, \
2008         }, \
2009         { \
2010                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2011                 .name = "Capture Volume", \
2012                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2013                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2014                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2015                 .count = num, \
2016                 .info = alc_cap_vol_info, \
2017                 .get = alc_cap_vol_get, \
2018                 .put = alc_cap_vol_put, \
2019                 .tlv = { .c = alc_cap_vol_tlv }, \
2020         }
2021 
2022 #define _DEFINE_CAPSRC(num) \
2023         { \
2024                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2025                 /* .name = "Capture Source", */ \
2026                 .name = "Input Source", \
2027                 .count = num, \
2028                 .info = alc_mux_enum_info, \
2029                 .get = alc_mux_enum_get, \
2030                 .put = alc_mux_enum_put, \
2031         }
2032 
2033 #define DEFINE_CAPMIX(num) \
2034 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2035         _DEFINE_CAPMIX(num),                                  \
2036         _DEFINE_CAPSRC(num),                                  \
2037         { } /* end */                                         \
2038 }
2039 
2040 #define DEFINE_CAPMIX_NOSRC(num) \
2041 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2042         _DEFINE_CAPMIX(num),                                        \
2043         { } /* end */                                               \
2044 }
2045 
2046 /* up to three ADCs */
2047 DEFINE_CAPMIX(1);
2048 DEFINE_CAPMIX(2);
2049 DEFINE_CAPMIX(3);
2050 DEFINE_CAPMIX_NOSRC(1);
2051 DEFINE_CAPMIX_NOSRC(2);
2052 DEFINE_CAPMIX_NOSRC(3);
2053 
2054 /*
2055  * ALC880 5-stack model
2056  *
2057  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2058  *      Side = 0x02 (0xd)
2059  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2060  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2061  */
2062 
2063 /* additional mixers to alc880_three_stack_mixer */
2064 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2065         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2066         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2067         { } /* end */
2068 };
2069 
2070 /* channel source setting (6/8 channel selection for 5-stack) */
2071 /* 6ch mode */
2072 static struct hda_verb alc880_fivestack_ch6_init[] = {
2073         /* set line-in to input, mute it */
2074         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2075         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2076         { } /* end */
2077 };
2078 
2079 /* 8ch mode */
2080 static struct hda_verb alc880_fivestack_ch8_init[] = {
2081         /* set line-in to output, unmute it */
2082         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2083         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2084         { } /* end */
2085 };
2086 
2087 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2088         { 6, alc880_fivestack_ch6_init },
2089         { 8, alc880_fivestack_ch8_init },
2090 };
2091 
2092 
2093 /*
2094  * ALC880 6-stack model
2095  *
2096  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2097  *      Side = 0x05 (0x0f)
2098  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2099  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2100  */
2101 
2102 static hda_nid_t alc880_6st_dac_nids[4] = {
2103         /* front, rear, clfe, rear_surr */
2104         0x02, 0x03, 0x04, 0x05
2105 };
2106 
2107 static struct hda_input_mux alc880_6stack_capture_source = {
2108         .num_items = 4,
2109         .items = {
2110                 { "Mic", 0x0 },
2111                 { "Front Mic", 0x1 },
2112                 { "Line", 0x2 },
2113                 { "CD", 0x4 },
2114         },
2115 };
2116 
2117 /* fixed 8-channels */
2118 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2119         { 8, NULL },
2120 };
2121 
2122 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2123         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2124         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2125         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2126         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2127         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2128         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2129         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2130         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2131         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2132         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2133         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2134         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2135         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2136         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2137         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2139         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2140         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2141         {
2142                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2143                 .name = "Channel Mode",
2144                 .info = alc_ch_mode_info,
2145                 .get = alc_ch_mode_get,
2146                 .put = alc_ch_mode_put,
2147         },
2148         { } /* end */
2149 };
2150 
2151 
2152 /*
2153  * ALC880 W810 model
2154  *
2155  * W810 has rear IO for:
2156  * Front (DAC 02)
2157  * Surround (DAC 03)
2158  * Center/LFE (DAC 04)
2159  * Digital out (06)
2160  *
2161  * The system also has a pair of internal speakers, and a headphone jack.
2162  * These are both connected to Line2 on the codec, hence to DAC 02.
2163  *
2164  * There is a variable resistor to control the speaker or headphone
2165  * volume. This is a hardware-only device without a software API.
2166  *
2167  * Plugging headphones in will disable the internal speakers. This is
2168  * implemented in hardware, not via the driver using jack sense. In
2169  * a similar fashion, plugging into the rear socket marked "front" will
2170  * disable both the speakers and headphones.
2171  *
2172  * For input, there's a microphone jack, and an "audio in" jack.
2173  * These may not do anything useful with this driver yet, because I
2174  * haven't setup any initialization verbs for these yet...
2175  */
2176 
2177 static hda_nid_t alc880_w810_dac_nids[3] = {
2178         /* front, rear/surround, clfe */
2179         0x02, 0x03, 0x04
2180 };
2181 
2182 /* fixed 6 channels */
2183 static struct hda_channel_mode alc880_w810_modes[1] = {
2184         { 6, NULL }
2185 };
2186 
2187 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2188 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2189         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2190         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2191         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2192         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2193         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2194         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2195         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2196         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2197         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2198         { } /* end */
2199 };
2200 
2201 
2202 /*
2203  * Z710V model
2204  *
2205  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2206  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2207  *                 Line = 0x1a
2208  */
2209 
2210 static hda_nid_t alc880_z71v_dac_nids[1] = {
2211         0x02
2212 };
2213 #define ALC880_Z71V_HP_DAC      0x03
2214 
2215 /* fixed 2 channels */
2216 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2217         { 2, NULL }
2218 };
2219 
2220 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2221         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2222         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2223         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2224         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2225         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2226         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2227         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2228         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2229         { } /* end */
2230 };
2231 
2232 
2233 /*
2234  * ALC880 F1734 model
2235  *
2236  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2237  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2238  */
2239 
2240 static hda_nid_t alc880_f1734_dac_nids[1] = {
2241         0x03
2242 };
2243 #define ALC880_F1734_HP_DAC     0x02
2244 
2245 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2246         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2247         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2248         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2249         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2250         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2251         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2252         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2253         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2254         { } /* end */
2255 };
2256 
2257 static struct hda_input_mux alc880_f1734_capture_source = {
2258         .num_items = 2,
2259         .items = {
2260                 { "Mic", 0x1 },
2261                 { "CD", 0x4 },
2262         },
2263 };
2264 
2265 
2266 /*
2267  * ALC880 ASUS model
2268  *
2269  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2270  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2271  *  Mic = 0x18, Line = 0x1a
2272  */
2273 
2274 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2275 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2276 
2277 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2278         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2279         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2281         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2282         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2283         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2284         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2285         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2286         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2287         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2288         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2289         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2291         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2292         {
2293                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2294                 .name = "Channel Mode",
2295                 .info = alc_ch_mode_info,
2296                 .get = alc_ch_mode_get,
2297                 .put = alc_ch_mode_put,
2298         },
2299         { } /* end */
2300 };
2301 
2302 /*
2303  * ALC880 ASUS W1V model
2304  *
2305  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2306  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2307  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2308  */
2309 
2310 /* additional mixers to alc880_asus_mixer */
2311 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2312         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2313         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2314         { } /* end */
2315 };
2316 
2317 /* TCL S700 */
2318 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2319         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2320         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2321         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2322         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2323         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2324         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2325         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2326         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2327         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2328         { } /* end */
2329 };
2330 
2331 /* Uniwill */
2332 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2333         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2334         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2336         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2337         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2338         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2339         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2340         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2341         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2342         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2343         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2344         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2345         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2346         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2347         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2348         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2349         {
2350                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2351                 .name = "Channel Mode",
2352                 .info = alc_ch_mode_info,
2353                 .get = alc_ch_mode_get,
2354                 .put = alc_ch_mode_put,
2355         },
2356         { } /* end */
2357 };
2358 
2359 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2360         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2361         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2362         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2363         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2364         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2365         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2366         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2367         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2369         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2370         { } /* end */
2371 };
2372 
2373 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2374         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2375         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2376         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2377         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2378         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2379         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2380         { } /* end */
2381 };
2382 
2383 /*
2384  * virtual master controls
2385  */
2386 
2387 /*
2388  * slave controls for virtual master
2389  */
2390 static const char *alc_slave_vols[] = {
2391         "Front Playback Volume",
2392         "Surround Playback Volume",
2393         "Center Playback Volume",
2394         "LFE Playback Volume",
2395         "Side Playback Volume",
2396         "Headphone Playback Volume",
2397         "Speaker Playback Volume",
2398         "Mono Playback Volume",
2399         "Line-Out Playback Volume",
2400         "PCM Playback Volume",
2401         NULL,
2402 };
2403 
2404 static const char *alc_slave_sws[] = {
2405         "Front Playback Switch",
2406         "Surround Playback Switch",
2407         "Center Playback Switch",
2408         "LFE Playback Switch",
2409         "Side Playback Switch",
2410         "Headphone Playback Switch",
2411         "Speaker Playback Switch",
2412         "Mono Playback Switch",
2413         "IEC958 Playback Switch",
2414         "Line-Out Playback Switch",
2415         "PCM Playback Switch",
2416         NULL,
2417 };
2418 
2419 /*
2420  * build control elements
2421  */
2422 
2423 static void alc_free_kctls(struct hda_codec *codec);
2424 
2425 /* additional beep mixers; the actual parameters are overwritten at build */
2426 static struct snd_kcontrol_new alc_beep_mixer[] = {
2427         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2428         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2429         { } /* end */
2430 };
2431 
2432 static int alc_build_controls(struct hda_codec *codec)
2433 {
2434         struct alc_spec *spec = codec->spec;
2435         int err;
2436         int i;
2437 
2438         for (i = 0; i < spec->num_mixers; i++) {
2439                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2440                 if (err < 0)
2441                         return err;
2442         }
2443         if (spec->cap_mixer) {
2444                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2445                 if (err < 0)
2446                         return err;
2447         }
2448         if (spec->multiout.dig_out_nid) {
2449                 err = snd_hda_create_spdif_out_ctls(codec,
2450                                                     spec->multiout.dig_out_nid);
2451                 if (err < 0)
2452                         return err;
2453                 if (!spec->no_analog) {
2454                         err = snd_hda_create_spdif_share_sw(codec,
2455                                                             &spec->multiout);
2456                         if (err < 0)
2457                                 return err;
2458                         spec->multiout.share_spdif = 1;
2459                 }
2460         }
2461         if (spec->dig_in_nid) {
2462                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2463                 if (err < 0)
2464                         return err;
2465         }
2466 
2467         /* create beep controls if needed */
2468         if (spec->beep_amp) {
2469                 struct snd_kcontrol_new *knew;
2470                 for (knew = alc_beep_mixer; knew->name; knew++) {
2471                         struct snd_kcontrol *kctl;
2472                         kctl = snd_ctl_new1(knew, codec);
2473                         if (!kctl)
2474                                 return -ENOMEM;
2475                         kctl->private_value = spec->beep_amp;
2476                         err = snd_hda_ctl_add(codec, kctl);
2477                         if (err < 0)
2478                                 return err;
2479                 }
2480         }
2481 
2482         /* if we have no master control, let's create it */
2483         if (!spec->no_analog &&
2484             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2485                 unsigned int vmaster_tlv[4];
2486                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2487                                         HDA_OUTPUT, vmaster_tlv);
2488                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2489                                           vmaster_tlv, alc_slave_vols);
2490                 if (err < 0)
2491                         return err;
2492         }
2493         if (!spec->no_analog &&
2494             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2495                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2496                                           NULL, alc_slave_sws);
2497                 if (err < 0)
2498                         return err;
2499         }
2500 
2501         alc_free_kctls(codec); /* no longer needed */
2502         return 0;
2503 }
2504 
2505 
2506 /*
2507  * initialize the codec volumes, etc
2508  */
2509 
2510 /*
2511  * generic initialization of ADC, input mixers and output mixers
2512  */
2513 static struct hda_verb alc880_volume_init_verbs[] = {
2514         /*
2515          * Unmute ADC0-2 and set the default input to mic-in
2516          */
2517         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2518         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2519         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2520         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2521         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2522         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2523 
2524         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2525          * mixer widget
2526          * Note: PASD motherboards uses the Line In 2 as the input for front
2527          * panel mic (mic 2)
2528          */
2529         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2530         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2531         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2532         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2533         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2535         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2536         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2537 
2538         /*
2539          * Set up output mixers (0x0c - 0x0f)
2540          */
2541         /* set vol=0 to output mixers */
2542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2544         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2545         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2546         /* set up input amps for analog loopback */
2547         /* Amp Indices: DAC = 0, mixer = 1 */
2548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2550         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2552         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2553         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2554         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2555         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2556 
2557         { }
2558 };
2559 
2560 /*
2561  * 3-stack pin configuration:
2562  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2563  */
2564 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2565         /*
2566          * preset connection lists of input pins
2567          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2568          */
2569         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2570         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2571         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2572 
2573         /*
2574          * Set pin mode and muting
2575          */
2576         /* set front pin widgets 0x14 for output */
2577         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2578         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2579         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2580         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2581         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2582         /* Mic2 (as headphone out) for HP output */
2583         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2584         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2585         /* Line In pin widget for input */
2586         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2587         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2588         /* Line2 (as front mic) pin widget for input and vref at 80% */
2589         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2590         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2591         /* CD pin widget for input */
2592         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2593 
2594         { }
2595 };
2596 
2597 /*
2598  * 5-stack pin configuration:
2599  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2600  * line-in/side = 0x1a, f-mic = 0x1b
2601  */
2602 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2603         /*
2604          * preset connection lists of input pins
2605          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2606          */
2607         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2608         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2609 
2610         /*
2611          * Set pin mode and muting
2612          */
2613         /* set pin widgets 0x14-0x17 for output */
2614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2615         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2616         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2617         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2618         /* unmute pins for output (no gain on this amp) */
2619         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2620         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2621         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2622         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623 
2624         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2625         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2626         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2627         /* Mic2 (as headphone out) for HP output */
2628         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2629         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2630         /* Line In pin widget for input */
2631         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2632         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2633         /* Line2 (as front mic) pin widget for input and vref at 80% */
2634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2635         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2636         /* CD pin widget for input */
2637         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2638 
2639         { }
2640 };
2641 
2642 /*
2643  * W810 pin configuration:
2644  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2645  */
2646 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2647         /* hphone/speaker input selector: front DAC */
2648         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2649 
2650         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2651         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2652         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2653         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2654         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2655         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2656 
2657         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2658         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2659 
2660         { }
2661 };
2662 
2663 /*
2664  * Z71V pin configuration:
2665  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2666  */
2667 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2668         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2669         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2670         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2671         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2672 
2673         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2674         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2675         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2676         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2677 
2678         { }
2679 };
2680 
2681 /*
2682  * 6-stack pin configuration:
2683  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2684  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2685  */
2686 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2687         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2688 
2689         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2690         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2691         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2692         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2693         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2694         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2695         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2696         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2697 
2698         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2699         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2700         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2701         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2702         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2703         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2704         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2705         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2706         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2707 
2708         { }
2709 };
2710 
2711 /*
2712  * Uniwill pin configuration:
2713  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2714  * line = 0x1a
2715  */
2716 static struct hda_verb alc880_uniwill_init_verbs[] = {
2717         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2718 
2719         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2720         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2721         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2722         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2723         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2724         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2725         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2727         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2728         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2729         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2730         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2731         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2732         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2733 
2734         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2735         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2736         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2737         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2738         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2739         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2740         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2741         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2742         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2743 
2744         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2745         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2746 
2747         { }
2748 };
2749 
2750 /*
2751 * Uniwill P53
2752 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2753  */
2754 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2755         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2756 
2757         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2758         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2759         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2760         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2761         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2762         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2763         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2764         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2765         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2766         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2767         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2768         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2769 
2770         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2771         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2772         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2773         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2774         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2775         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2776 
2777         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2778         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2779 
2780         { }
2781 };
2782 
2783 static struct hda_verb alc880_beep_init_verbs[] = {
2784         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2785         { }
2786 };
2787 
2788 /* auto-toggle front mic */
2789 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2790 {
2791         unsigned int present;
2792         unsigned char bits;
2793 
2794         present = snd_hda_codec_read(codec, 0x18, 0,
2795                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2796         bits = present ? HDA_AMP_MUTE : 0;
2797         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2798 }
2799 
2800 static void alc880_uniwill_setup(struct hda_codec *codec)
2801 {
2802         struct alc_spec *spec = codec->spec;
2803 
2804         spec->autocfg.hp_pins[0] = 0x14;
2805         spec->autocfg.speaker_pins[0] = 0x15;
2806         spec->autocfg.speaker_pins[0] = 0x16;
2807 }
2808 
2809 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2810 {
2811         alc_automute_amp(codec);
2812         alc880_uniwill_mic_automute(codec);
2813 }
2814 
2815 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2816                                        unsigned int res)
2817 {
2818         /* Looks like the unsol event is incompatible with the standard
2819          * definition.  4bit tag is placed at 28 bit!
2820          */
2821         switch (res >> 28) {
2822         case ALC880_MIC_EVENT:
2823                 alc880_uniwill_mic_automute(codec);
2824                 break;
2825         default:
2826                 alc_automute_amp_unsol_event(codec, res);
2827                 break;
2828         }
2829 }
2830 
2831 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2832 {
2833         struct alc_spec *spec = codec->spec;
2834 
2835         spec->autocfg.hp_pins[0] = 0x14;
2836         spec->autocfg.speaker_pins[0] = 0x15;
2837 }
2838 
2839 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2840 {
2841         unsigned int present;
2842 
2843         present = snd_hda_codec_read(codec, 0x21, 0,
2844                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2845         present &= HDA_AMP_VOLMASK;
2846         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2847                                  HDA_AMP_VOLMASK, present);
2848         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2849                                  HDA_AMP_VOLMASK, present);
2850 }
2851 
2852 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2853                                            unsigned int res)
2854 {
2855         /* Looks like the unsol event is incompatible with the standard
2856          * definition.  4bit tag is placed at 28 bit!
2857          */
2858         if ((res >> 28) == ALC880_DCVOL_EVENT)
2859                 alc880_uniwill_p53_dcvol_automute(codec);
2860         else
2861                 alc_automute_amp_unsol_event(codec, res);
2862 }
2863 
2864 /*
2865  * F1734 pin configuration:
2866  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2867  */
2868 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2869         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2870         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2871         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2872         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2873         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2874 
2875         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2876         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2877         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2878         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2879 
2880         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2881         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2882         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2883         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2884         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2885         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2886         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2887         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2888         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2889 
2890         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2891         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2892 
2893         { }
2894 };
2895 
2896 /*
2897  * ASUS pin configuration:
2898  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2899  */
2900 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2901         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2902         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2903         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2904         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2905 
2906         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2907         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2908         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2910         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2911         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2912         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2914 
2915         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2916         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2917         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2918         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2919         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2920         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2922         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2923         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2924 
2925         { }
2926 };
2927 
2928 /* Enable GPIO mask and set output */
2929 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2930 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2931 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2932 
2933 /* Clevo m520g init */
2934 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2935         /* headphone output */
2936         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2937         /* line-out */
2938         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2939         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2940         /* Line-in */
2941         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2942         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2943         /* CD */
2944         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2945         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2946         /* Mic1 (rear panel) */
2947         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2949         /* Mic2 (front panel) */
2950         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2951         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2952         /* headphone */
2953         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2954         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2955         /* change to EAPD mode */
2956         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2957         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2958 
2959         { }
2960 };
2961 
2962 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2963         /* change to EAPD mode */
2964         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2965         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2966 
2967         /* Headphone output */
2968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2969         /* Front output*/
2970         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2971         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2972 
2973         /* Line In pin widget for input */
2974         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2975         /* CD pin widget for input */
2976         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2977         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2978         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2979 
2980         /* change to EAPD mode */
2981         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2982         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2983 
2984         { }
2985 };
2986 
2987 /*
2988  * LG m1 express dual
2989  *
2990  * Pin assignment:
2991  *   Rear Line-In/Out (blue): 0x14
2992  *   Build-in Mic-In: 0x15
2993  *   Speaker-out: 0x17
2994  *   HP-Out (green): 0x1b
2995  *   Mic-In/Out (red): 0x19
2996  *   SPDIF-Out: 0x1e
2997  */
2998 
2999 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3000 static hda_nid_t alc880_lg_dac_nids[3] = {
3001         0x05, 0x02, 0x03
3002 };
3003 
3004 /* seems analog CD is not working */
3005 static struct hda_input_mux alc880_lg_capture_source = {
3006         .num_items = 3,
3007         .items = {
3008                 { "Mic", 0x1 },
3009                 { "Line", 0x5 },
3010                 { "Internal Mic", 0x6 },
3011         },
3012 };
3013 
3014 /* 2,4,6 channel modes */
3015 static struct hda_verb alc880_lg_ch2_init[] = {
3016         /* set line-in and mic-in to input */
3017         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3018         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3019         { }
3020 };
3021 
3022 static struct hda_verb alc880_lg_ch4_init[] = {
3023         /* set line-in to out and mic-in to input */
3024         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3025         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3026         { }
3027 };
3028 
3029 static struct hda_verb alc880_lg_ch6_init[] = {
3030         /* set line-in and mic-in to output */
3031         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3032         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3033         { }
3034 };
3035 
3036 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3037         { 2, alc880_lg_ch2_init },
3038         { 4, alc880_lg_ch4_init },
3039         { 6, alc880_lg_ch6_init },
3040 };
3041 
3042 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3043         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3044         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3045         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3046         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3047         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3048         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3049         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3050         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3051         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3052         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3053         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3054         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3055         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3056         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3057         {
3058                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3059                 .name = "Channel Mode",
3060                 .info = alc_ch_mode_info,
3061                 .get = alc_ch_mode_get,
3062                 .put = alc_ch_mode_put,
3063         },
3064         { } /* end */
3065 };
3066 
3067 static struct hda_verb alc880_lg_init_verbs[] = {
3068         /* set capture source to mic-in */
3069         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3071         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3072         /* mute all amp mixer inputs */
3073         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3074         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3075         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3076         /* line-in to input */
3077         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3078         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3079         /* built-in mic */
3080         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3081         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3082         /* speaker-out */
3083         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3084         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3085         /* mic-in to input */
3086         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3087         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3088         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3089         /* HP-out */
3090         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3091         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3092         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3093         /* jack sense */
3094         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3095         { }
3096 };
3097 
3098 /* toggle speaker-output according to the hp-jack state */
3099 static void alc880_lg_setup(struct hda_codec *codec)
3100 {
3101         struct alc_spec *spec = codec->spec;
3102 
3103         spec->autocfg.hp_pins[0] = 0x1b;
3104         spec->autocfg.speaker_pins[0] = 0x17;
3105 }
3106 
3107 /*
3108  * LG LW20
3109  *
3110  * Pin assignment:
3111  *   Speaker-out: 0x14
3112  *   Mic-In: 0x18
3113  *   Built-in Mic-In: 0x19
3114  *   Line-In: 0x1b
3115  *   HP-Out: 0x1a
3116  *   SPDIF-Out: 0x1e
3117  */
3118 
3119 static struct hda_input_mux alc880_lg_lw_capture_source = {
3120         .num_items = 3,
3121         .items = {
3122                 { "Mic", 0x0 },
3123                 { "Internal Mic", 0x1 },
3124                 { "Line In", 0x2 },
3125         },
3126 };
3127 
3128 #define alc880_lg_lw_modes alc880_threestack_modes
3129 
3130 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3131         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3132         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3133         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3134         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3135         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3136         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3137         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3138         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3139         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3140         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3141         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3142         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3143         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3144         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3145         {
3146                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3147                 .name = "Channel Mode",
3148                 .info = alc_ch_mode_info,
3149                 .get = alc_ch_mode_get,
3150                 .put = alc_ch_mode_put,
3151         },
3152         { } /* end */
3153 };
3154 
3155 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3156         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3157         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3158         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3159 
3160         /* set capture source to mic-in */
3161         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3162         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3163         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3165         /* speaker-out */
3166         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3167         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3168         /* HP-out */
3169         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3171         /* mic-in to input */
3172         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3173         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3174         /* built-in mic */
3175         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3176         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3177         /* jack sense */
3178         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3179         { }
3180 };
3181 
3182 /* toggle speaker-output according to the hp-jack state */
3183 static void alc880_lg_lw_setup(struct hda_codec *codec)
3184 {
3185         struct alc_spec *spec = codec->spec;
3186 
3187         spec->autocfg.hp_pins[0] = 0x1b;
3188         spec->autocfg.speaker_pins[0] = 0x14;
3189 }
3190 
3191 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3192         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3193         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3194         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3195         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3196         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3197         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3198         { } /* end */
3199 };
3200 
3201 static struct hda_input_mux alc880_medion_rim_capture_source = {
3202         .num_items = 2,
3203         .items = {
3204                 { "Mic", 0x0 },
3205                 { "Internal Mic", 0x1 },
3206         },
3207 };
3208 
3209 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3210         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3211 
3212         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3213         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3214 
3215         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3216         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3217         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3218         /* Mic2 (as headphone out) for HP output */
3219         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3220         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3221         /* Internal Speaker */
3222         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3223         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3224 
3225         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3226         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3227 
3228         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3229         { }
3230 };
3231 
3232 /* toggle speaker-output according to the hp-jack state */
3233 static void alc880_medion_rim_automute(struct hda_codec *codec)
3234 {
3235         struct alc_spec *spec = codec->spec;
3236         alc_automute_amp(codec);
3237         /* toggle EAPD */
3238         if (spec->jack_present)
3239                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3240         else
3241                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3242 }
3243 
3244 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3245                                           unsigned int res)
3246 {
3247         /* Looks like the unsol event is incompatible with the standard
3248          * definition.  4bit tag is placed at 28 bit!
3249          */
3250         if ((res >> 28) == ALC880_HP_EVENT)
3251                 alc880_medion_rim_automute(codec);
3252 }
3253 
3254 static void alc880_medion_rim_setup(struct hda_codec *codec)
3255 {
3256         struct alc_spec *spec = codec->spec;
3257 
3258         spec->autocfg.hp_pins[0] = 0x14;
3259         spec->autocfg.speaker_pins[0] = 0x1b;
3260 }
3261 
3262 #ifdef CONFIG_SND_HDA_POWER_SAVE
3263 static struct hda_amp_list alc880_loopbacks[] = {
3264         { 0x0b, HDA_INPUT, 0 },
3265         { 0x0b, HDA_INPUT, 1 },
3266         { 0x0b, HDA_INPUT, 2 },
3267         { 0x0b, HDA_INPUT, 3 },
3268         { 0x0b, HDA_INPUT, 4 },
3269         { } /* end */
3270 };
3271 
3272 static struct hda_amp_list alc880_lg_loopbacks[] = {
3273         { 0x0b, HDA_INPUT, 1 },
3274         { 0x0b, HDA_INPUT, 6 },
3275         { 0x0b, HDA_INPUT, 7 },
3276         { } /* end */
3277 };
3278 #endif
3279 
3280 /*
3281  * Common callbacks
3282  */
3283 
3284 static int alc_init(struct hda_codec *codec)
3285 {
3286         struct alc_spec *spec = codec->spec;
3287         unsigned int i;
3288 
3289         alc_fix_pll(codec);
3290         alc_auto_init_amp(codec, spec->init_amp);
3291 
3292         for (i = 0; i < spec->num_init_verbs; i++)
3293                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3294 
3295         if (spec->init_hook)
3296                 spec->init_hook(codec);
3297 
3298         return 0;
3299 }
3300 
3301 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3302 {
3303         struct alc_spec *spec = codec->spec;
3304 
3305         if (spec->unsol_event)
3306                 spec->unsol_event(codec, res);
3307 }
3308 
3309 #ifdef CONFIG_SND_HDA_POWER_SAVE
3310 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3311 {
3312         struct alc_spec *spec = codec->spec;
3313         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3314 }
3315 #endif
3316 
3317 /*
3318  * Analog playback callbacks
3319  */
3320 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3321                                     struct hda_codec *codec,
3322                                     struct snd_pcm_substream *substream)
3323 {
3324         struct alc_spec *spec = codec->spec;
3325         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3326                                              hinfo);
3327 }
3328 
3329 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3330                                        struct hda_codec *codec,
3331                                        unsigned int stream_tag,
3332                                        unsigned int format,
3333                                        struct snd_pcm_substream *substream)
3334 {
3335         struct alc_spec *spec = codec->spec;
3336         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3337                                                 stream_tag, format, substream);
3338 }
3339 
3340 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3341                                        struct hda_codec *codec,
3342                                        struct snd_pcm_substream *substream)
3343 {
3344         struct alc_spec *spec = codec->spec;
3345         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3346 }
3347 
3348 /*
3349  * Digital out
3350  */
3351 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3352                                         struct hda_codec *codec,
3353                                         struct snd_pcm_substream *substream)
3354 {
3355         struct alc_spec *spec = codec->spec;
3356         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3357 }
3358 
3359 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3360                                            struct hda_codec *codec,
3361                                            unsigned int stream_tag,
3362                                            unsigned int format,
3363                                            struct snd_pcm_substream *substream)
3364 {
3365         struct alc_spec *spec = codec->spec;
3366         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3367                                              stream_tag, format, substream);
3368 }
3369 
3370 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3371                                            struct hda_codec *codec,
3372                                            struct snd_pcm_substream *substream)
3373 {
3374         struct alc_spec *spec = codec->spec;
3375         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3376 }
3377 
3378 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3379                                          struct hda_codec *codec,
3380                                          struct snd_pcm_substream *substream)
3381 {
3382         struct alc_spec *spec = codec->spec;
3383         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3384 }
3385 
3386 /*
3387  * Analog capture
3388  */
3389 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3390                                       struct hda_codec *codec,
3391                                       unsigned int stream_tag,
3392                                       unsigned int format,
3393                                       struct snd_pcm_substream *substream)
3394 {
3395         struct alc_spec *spec = codec->spec;
3396 
3397         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3398                                    stream_tag, 0, format);
3399         return 0;
3400 }
3401 
3402 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3403                                       struct hda_codec *codec,
3404                                       struct snd_pcm_substream *substream)
3405 {
3406         struct alc_spec *spec = codec->spec;
3407 
3408         snd_hda_codec_cleanup_stream(codec,
3409                                      spec->adc_nids[substream->number + 1]);
3410         return 0;
3411 }
3412 
3413 
3414 /*
3415  */
3416 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3417         .substreams = 1,
3418         .channels_min = 2,
3419         .channels_max = 8,
3420         /* NID is set in alc_build_pcms */
3421         .ops = {
3422                 .open = alc880_playback_pcm_open,
3423                 .prepare = alc880_playback_pcm_prepare,
3424                 .cleanup = alc880_playback_pcm_cleanup
3425         },
3426 };
3427 
3428 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3429         .substreams = 1,
3430         .channels_min = 2,
3431         .channels_max = 2,
3432         /* NID is set in alc_build_pcms */
3433 };
3434 
3435 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3436         .substreams = 1,
3437         .channels_min = 2,
3438         .channels_max = 2,
3439         /* NID is set in alc_build_pcms */
3440 };
3441 
3442 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3443         .substreams = 2, /* can be overridden */
3444         .channels_min = 2,
3445         .channels_max = 2,
3446         /* NID is set in alc_build_pcms */
3447         .ops = {
3448                 .prepare = alc880_alt_capture_pcm_prepare,
3449                 .cleanup = alc880_alt_capture_pcm_cleanup
3450         },
3451 };
3452 
3453 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3454         .substreams = 1,
3455         .channels_min = 2,
3456         .channels_max = 2,
3457         /* NID is set in alc_build_pcms */
3458         .ops = {
3459                 .open = alc880_dig_playback_pcm_open,
3460                 .close = alc880_dig_playback_pcm_close,
3461                 .prepare = alc880_dig_playback_pcm_prepare,
3462                 .cleanup = alc880_dig_playback_pcm_cleanup
3463         },
3464 };
3465 
3466 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3467         .substreams = 1,
3468         .channels_min = 2,
3469         .channels_max = 2,
3470         /* NID is set in alc_build_pcms */
3471 };
3472 
3473 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3474 static struct hda_pcm_stream alc_pcm_null_stream = {
3475         .substreams = 0,
3476         .channels_min = 0,
3477         .channels_max = 0,
3478 };
3479 
3480 static int alc_build_pcms(struct hda_codec *codec)
3481 {
3482         struct alc_spec *spec = codec->spec;
3483         struct hda_pcm *info = spec->pcm_rec;
3484         int i;
3485 
3486         codec->num_pcms = 1;
3487         codec->pcm_info = info;
3488 
3489         if (spec->no_analog)
3490                 goto skip_analog;
3491 
3492         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3493                  "%s Analog", codec->chip_name);
3494         info->name = spec->stream_name_analog;
3495         
3496         if (spec->stream_analog_playback) {
3497                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3498                         return -EINVAL;
3499                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3500                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3501         }
3502         if (spec->stream_analog_capture) {
3503                 if (snd_BUG_ON(!spec->adc_nids))
3504                         return -EINVAL;
3505                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3506                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3507         }
3508 
3509         if (spec->channel_mode) {
3510                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3511                 for (i = 0; i < spec->num_channel_mode; i++) {
3512                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3513                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3514                         }
3515                 }
3516         }
3517 
3518  skip_analog:
3519         /* SPDIF for stream index #1 */
3520         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3521                 snprintf(spec->stream_name_digital,
3522                          sizeof(spec->stream_name_digital),
3523                          "%s Digital", codec->chip_name);
3524                 codec->num_pcms = 2;
3525                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3526                 info = spec->pcm_rec + 1;
3527                 info->name = spec->stream_name_digital;
3528                 if (spec->dig_out_type)
3529                         info->pcm_type = spec->dig_out_type;
3530                 else
3531                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3532                 if (spec->multiout.dig_out_nid &&
3533                     spec->stream_digital_playback) {
3534                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3535                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3536                 }
3537                 if (spec->dig_in_nid &&
3538                     spec->stream_digital_capture) {
3539                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3540                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3541                 }
3542                 /* FIXME: do we need this for all Realtek codec models? */
3543                 codec->spdif_status_reset = 1;
3544         }
3545 
3546         if (spec->no_analog)
3547                 return 0;
3548 
3549         /* If the use of more than one ADC is requested for the current
3550          * model, configure a second analog capture-only PCM.
3551          */
3552         /* Additional Analaog capture for index #2 */
3553         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3554             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3555                 codec->num_pcms = 3;
3556                 info = spec->pcm_rec + 2;
3557                 info->name = spec->stream_name_analog;
3558                 if (spec->alt_dac_nid) {
3559                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3560                                 *spec->stream_analog_alt_playback;
3561                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3562                                 spec->alt_dac_nid;
3563                 } else {
3564                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3565                                 alc_pcm_null_stream;
3566                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3567                 }
3568                 if (spec->num_adc_nids > 1) {
3569                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3570                                 *spec->stream_analog_alt_capture;
3571                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3572                                 spec->adc_nids[1];
3573                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3574                                 spec->num_adc_nids - 1;
3575                 } else {
3576                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3577                                 alc_pcm_null_stream;
3578                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3579                 }
3580         }
3581 
3582         return 0;
3583 }
3584 
3585 static void alc_free_kctls(struct hda_codec *codec)
3586 {
3587         struct alc_spec *spec = codec->spec;
3588 
3589         if (spec->kctls.list) {
3590                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3591                 int i;
3592                 for (i = 0; i < spec->kctls.used; i++)
3593                         kfree(kctl[i].name);
3594         }
3595         snd_array_free(&spec->kctls);
3596 }
3597 
3598 static void alc_free(struct hda_codec *codec)
3599 {
3600         struct alc_spec *spec = codec->spec;
3601 
3602         if (!spec)
3603                 return;
3604 
3605         alc_free_kctls(codec);
3606         kfree(spec);
3607         snd_hda_detach_beep_device(codec);
3608 }
3609 
3610 #ifdef SND_HDA_NEEDS_RESUME
3611 static int alc_resume(struct hda_codec *codec)
3612 {
3613         codec->patch_ops.init(codec);
3614         snd_hda_codec_resume_amp(codec);
3615         snd_hda_codec_resume_cache(codec);
3616         return 0;
3617 }
3618 #endif
3619 
3620 /*
3621  */
3622 static struct hda_codec_ops alc_patch_ops = {
3623         .build_controls = alc_build_controls,
3624         .build_pcms = alc_build_pcms,
3625         .init = alc_init,
3626         .free = alc_free,
3627         .unsol_event = alc_unsol_event,
3628 #ifdef SND_HDA_NEEDS_RESUME
3629         .resume = alc_resume,
3630 #endif
3631 #ifdef CONFIG_SND_HDA_POWER_SAVE
3632         .check_power_status = alc_check_power_status,
3633 #endif
3634 };
3635 
3636 
3637 /*
3638  * Test configuration for debugging
3639  *
3640  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3641  * enum controls.
3642  */
3643 #ifdef CONFIG_SND_DEBUG
3644 static hda_nid_t alc880_test_dac_nids[4] = {
3645         0x02, 0x03, 0x04, 0x05
3646 };
3647 
3648 static struct hda_input_mux alc880_test_capture_source = {
3649         .num_items = 7,
3650         .items = {
3651                 { "In-1", 0x0 },
3652                 { "In-2", 0x1 },
3653                 { "In-3", 0x2 },
3654                 { "In-4", 0x3 },
3655                 { "CD", 0x4 },
3656                 { "Front", 0x5 },
3657                 { "Surround", 0x6 },
3658         },
3659 };
3660 
3661 static struct hda_channel_mode alc880_test_modes[4] = {
3662         { 2, NULL },
3663         { 4, NULL },
3664         { 6, NULL },
3665         { 8, NULL },
3666 };
3667 
3668 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3669                                  struct snd_ctl_elem_info *uinfo)
3670 {
3671         static char *texts[] = {
3672                 "N/A", "Line Out", "HP Out",
3673                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3674         };
3675         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3676         uinfo->count = 1;
3677         uinfo->value.enumerated.items = 8;
3678         if (uinfo->value.enumerated.item >= 8)
3679                 uinfo->value.enumerated.item = 7;
3680         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3681         return 0;
3682 }
3683 
3684 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3685                                 struct snd_ctl_elem_value *ucontrol)
3686 {
3687         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3688         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3689         unsigned int pin_ctl, item = 0;
3690 
3691         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3692                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3693         if (pin_ctl & AC_PINCTL_OUT_EN) {
3694                 if (pin_ctl & AC_PINCTL_HP_EN)
3695                         item = 2;
3696                 else
3697                         item = 1;
3698         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3699                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3700                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3701                 case AC_PINCTL_VREF_50:  item = 4; break;
3702                 case AC_PINCTL_VREF_GRD: item = 5; break;
3703                 case AC_PINCTL_VREF_80:  item = 6; break;
3704                 case AC_PINCTL_VREF_100: item = 7; break;
3705                 }
3706         }
3707         ucontrol->value.enumerated.item[0] = item;
3708         return 0;
3709 }
3710 
3711 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3712                                 struct snd_ctl_elem_value *ucontrol)
3713 {
3714         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3715         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3716         static unsigned int ctls[] = {
3717                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3718                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3719                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3720                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3721                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3722                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3723         };
3724         unsigned int old_ctl, new_ctl;
3725 
3726         old_ctl = snd_hda_codec_read(codec, nid, 0,
3727                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3728         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3729         if (old_ctl != new_ctl) {
3730                 int val;
3731                 snd_hda_codec_write_cache(codec, nid, 0,
3732                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3733                                           new_ctl);
3734                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3735                         HDA_AMP_MUTE : 0;
3736                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3737                                          HDA_AMP_MUTE, val);
3738                 return 1;
3739         }
3740         return 0;
3741 }
3742 
3743 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3744                                  struct snd_ctl_elem_info *uinfo)
3745 {
3746         static char *texts[] = {
3747                 "Front", "Surround", "CLFE", "Side"
3748         };
3749         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3750         uinfo->count = 1;
3751         uinfo->value.enumerated.items = 4;
3752         if (uinfo->value.enumerated.item >= 4)
3753                 uinfo->value.enumerated.item = 3;
3754         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3755         return 0;
3756 }
3757 
3758 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3759                                 struct snd_ctl_elem_value *ucontrol)
3760 {
3761         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3762         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3763         unsigned int sel;
3764 
3765         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3766         ucontrol->value.enumerated.item[0] = sel & 3;
3767         return 0;
3768 }
3769 
3770 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3771                                 struct snd_ctl_elem_value *ucontrol)
3772 {
3773         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3774         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3775         unsigned int sel;
3776 
3777         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3778         if (ucontrol->value.enumerated.item[0] != sel) {
3779                 sel = ucontrol->value.enumerated.item[0] & 3;
3780                 snd_hda_codec_write_cache(codec, nid, 0,
3781                                           AC_VERB_SET_CONNECT_SEL, sel);
3782                 return 1;
3783         }
3784         return 0;
3785 }
3786 
3787 #define PIN_CTL_TEST(xname,nid) {                       \
3788                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3789                         .name = xname,                 \
3790                         .info = alc_test_pin_ctl_info, \
3791                         .get = alc_test_pin_ctl_get,   \
3792                         .put = alc_test_pin_ctl_put,   \
3793                         .private_value = nid           \
3794                         }
3795 
3796 #define PIN_SRC_TEST(xname,nid) {                       \
3797                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3798                         .name = xname,                 \
3799                         .info = alc_test_pin_src_info, \
3800                         .get = alc_test_pin_src_get,   \
3801                         .put = alc_test_pin_src_put,   \
3802                         .private_value = nid           \
3803                         }
3804 
3805 static struct snd_kcontrol_new alc880_test_mixer[] = {
3806         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3807         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3808         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3809         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3810         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3811         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3812         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3813         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3814         PIN_CTL_TEST("Front Pin Mode", 0x14),
3815         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3816         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3817         PIN_CTL_TEST("Side Pin Mode", 0x17),
3818         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3819         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3820         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3821         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3822         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3823         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3824         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3825         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3826         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3827         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3828         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3829         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3830         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3831         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3832         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3833         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3834         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3835         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3836         {
3837                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3838                 .name = "Channel Mode",
3839                 .info = alc_ch_mode_info,
3840                 .get = alc_ch_mode_get,
3841                 .put = alc_ch_mode_put,
3842         },
3843         { } /* end */
3844 };
3845 
3846 static struct hda_verb alc880_test_init_verbs[] = {
3847         /* Unmute inputs of 0x0c - 0x0f */
3848         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3850         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3853         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3854         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3855         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3856         /* Vol output for 0x0c-0x0f */
3857         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3858         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3859         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3860         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3861         /* Set output pins 0x14-0x17 */
3862         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3863         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3864         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3865         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3866         /* Unmute output pins 0x14-0x17 */
3867         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3868         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3869         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3870         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3871         /* Set input pins 0x18-0x1c */
3872         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3873         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3874         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3875         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3876         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3877         /* Mute input pins 0x18-0x1b */
3878         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3879         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3880         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3881         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3882         /* ADC set up */
3883         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3884         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3885         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3886         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3887         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3888         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3889         /* Analog input/passthru */
3890         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3891         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3892         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3893         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3894         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3895         { }
3896 };
3897 #endif
3898 
3899 /*
3900  */
3901 
3902 static const char *alc880_models[ALC880_MODEL_LAST] = {
3903         [ALC880_3ST]            = "3stack",
3904         [ALC880_TCL_S700]       = "tcl",
3905         [ALC880_3ST_DIG]        = "3stack-digout",
3906         [ALC880_CLEVO]          = "clevo",
3907         [ALC880_5ST]            = "5stack",
3908         [ALC880_5ST_DIG]        = "5stack-digout",
3909         [ALC880_W810]           = "w810",
3910         [ALC880_Z71V]           = "z71v",
3911         [ALC880_6ST]            = "6stack",
3912         [ALC880_6ST_DIG]        = "6stack-digout",
3913         [ALC880_ASUS]           = "asus",
3914         [ALC880_ASUS_W1V]       = "asus-w1v",
3915         [ALC880_ASUS_DIG]       = "asus-dig",
3916         [ALC880_ASUS_DIG2]      = "asus-dig2",
3917         [ALC880_UNIWILL_DIG]    = "uniwill",
3918         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3919         [ALC880_FUJITSU]        = "fujitsu",
3920         [ALC880_F1734]          = "F1734",
3921         [ALC880_LG]             = "lg",
3922         [ALC880_LG_LW]          = "lg-lw",
3923         [ALC880_MEDION_RIM]     = "medion",
3924 #ifdef CONFIG_SND_DEBUG
3925         [ALC880_TEST]           = "test",
3926 #endif
3927         [ALC880_AUTO]           = "auto",
3928 };
3929 
3930 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3931         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3932         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3933         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3934         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3935         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3936         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3937         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3938         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3939         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3940         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3941         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3942         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3943         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3944         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3945         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3946         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3947         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3948         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3949         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3950         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3951         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3952         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3953         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3954         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3955         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3956         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3957         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3958         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3959         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3960         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3961         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3962         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3963         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3964         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3965         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3966         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3967         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3968         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3969         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3970         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3971         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3972         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3973         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3974         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3975         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3976         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3977         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3978         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3979         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3980         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
3981         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3982         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3983         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3984         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_LG),
3985         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3986         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3987         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3988         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3989         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3990         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3991         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3992         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3993         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3994         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3995         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3996         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3997         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3998         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3999         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
4000         /* default Intel */
4001         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4002         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
4003         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
4004         {}
4005 };
4006 
4007 /*
4008  * ALC880 codec presets
4009  */
4010 static struct alc_config_preset alc880_presets[] = {
4011         [ALC880_3ST] = {
4012                 .mixers = { alc880_three_stack_mixer },
4013                 .init_verbs = { alc880_volume_init_verbs,
4014                                 alc880_pin_3stack_init_verbs },
4015                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4016                 .dac_nids = alc880_dac_nids,
4017                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4018                 .channel_mode = alc880_threestack_modes,
4019                 .need_dac_fix = 1,
4020                 .input_mux = &alc880_capture_source,
4021         },
4022         [ALC880_3ST_DIG] = {
4023                 .mixers = { alc880_three_stack_mixer },
4024                 .init_verbs = { alc880_volume_init_verbs,
4025                                 alc880_pin_3stack_init_verbs },
4026                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4027                 .dac_nids = alc880_dac_nids,
4028                 .dig_out_nid = ALC880_DIGOUT_NID,
4029                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4030                 .channel_mode = alc880_threestack_modes,
4031                 .need_dac_fix = 1,
4032                 .input_mux = &alc880_capture_source,
4033         },
4034         [ALC880_TCL_S700] = {
4035                 .mixers = { alc880_tcl_s700_mixer },
4036                 .init_verbs = { alc880_volume_init_verbs,
4037                                 alc880_pin_tcl_S700_init_verbs,
4038                                 alc880_gpio2_init_verbs },
4039                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4040                 .dac_nids = alc880_dac_nids,
4041                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4042                 .num_adc_nids = 1, /* single ADC */
4043                 .hp_nid = 0x03,
4044                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4045                 .channel_mode = alc880_2_jack_modes,
4046                 .input_mux = &alc880_capture_source,
4047         },
4048         [ALC880_5ST] = {
4049                 .mixers = { alc880_three_stack_mixer,
4050                             alc880_five_stack_mixer},
4051                 .init_verbs = { alc880_volume_init_verbs,
4052                                 alc880_pin_5stack_init_verbs },
4053                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4054                 .dac_nids = alc880_dac_nids,
4055                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4056                 .channel_mode = alc880_fivestack_modes,
4057                 .input_mux = &alc880_capture_source,
4058         },
4059         [ALC880_5ST_DIG] = {
4060                 .mixers = { alc880_three_stack_mixer,
4061                             alc880_five_stack_mixer },
4062                 .init_verbs = { alc880_volume_init_verbs,
4063                                 alc880_pin_5stack_init_verbs },
4064                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4065                 .dac_nids = alc880_dac_nids,
4066                 .dig_out_nid = ALC880_DIGOUT_NID,
4067                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4068                 .channel_mode = alc880_fivestack_modes,
4069                 .input_mux = &alc880_capture_source,
4070         },
4071         [ALC880_6ST] = {
4072                 .mixers = { alc880_six_stack_mixer },
4073                 .init_verbs = { alc880_volume_init_verbs,
4074                                 alc880_pin_6stack_init_verbs },
4075                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4076                 .dac_nids = alc880_6st_dac_nids,
4077                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4078                 .channel_mode = alc880_sixstack_modes,
4079                 .input_mux = &alc880_6stack_capture_source,
4080         },
4081         [ALC880_6ST_DIG] = {
4082                 .mixers = { alc880_six_stack_mixer },
4083                 .init_verbs = { alc880_volume_init_verbs,
4084                                 alc880_pin_6stack_init_verbs },
4085                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4086                 .dac_nids = alc880_6st_dac_nids,
4087                 .dig_out_nid = ALC880_DIGOUT_NID,
4088                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4089                 .channel_mode = alc880_sixstack_modes,
4090                 .input_mux = &alc880_6stack_capture_source,
4091         },
4092         [ALC880_W810] = {
4093                 .mixers = { alc880_w810_base_mixer },
4094                 .init_verbs = { alc880_volume_init_verbs,
4095                                 alc880_pin_w810_init_verbs,
4096                                 alc880_gpio2_init_verbs },
4097                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4098                 .dac_nids = alc880_w810_dac_nids,
4099                 .dig_out_nid = ALC880_DIGOUT_NID,
4100                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4101                 .channel_mode = alc880_w810_modes,
4102                 .input_mux = &alc880_capture_source,
4103         },
4104         [ALC880_Z71V] = {
4105                 .mixers = { alc880_z71v_mixer },
4106                 .init_verbs = { alc880_volume_init_verbs,
4107                                 alc880_pin_z71v_init_verbs },
4108                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4109                 .dac_nids = alc880_z71v_dac_nids,
4110                 .dig_out_nid = ALC880_DIGOUT_NID,
4111                 .hp_nid = 0x03,
4112                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4113                 .channel_mode = alc880_2_jack_modes,
4114                 .input_mux = &alc880_capture_source,
4115         },
4116         [ALC880_F1734] = {
4117                 .mixers = { alc880_f1734_mixer },
4118                 .init_verbs = { alc880_volume_init_verbs,
4119                                 alc880_pin_f1734_init_verbs },
4120                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4121                 .dac_nids = alc880_f1734_dac_nids,
4122                 .hp_nid = 0x02,
4123                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4124                 .channel_mode = alc880_2_jack_modes,
4125                 .input_mux = &alc880_f1734_capture_source,
4126                 .unsol_event = alc880_uniwill_p53_unsol_event,
4127                 .setup = alc880_uniwill_p53_setup,
4128                 .init_hook = alc_automute_amp,
4129         },
4130         [ALC880_ASUS] = {
4131                 .mixers = { alc880_asus_mixer },
4132                 .init_verbs = { alc880_volume_init_verbs,
4133                                 alc880_pin_asus_init_verbs,
4134                                 alc880_gpio1_init_verbs },
4135                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4136                 .dac_nids = alc880_asus_dac_nids,
4137                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4138                 .channel_mode = alc880_asus_modes,
4139                 .need_dac_fix = 1,
4140                 .input_mux = &alc880_capture_source,
4141         },
4142         [ALC880_ASUS_DIG] = {
4143                 .mixers = { alc880_asus_mixer },
4144                 .init_verbs = { alc880_volume_init_verbs,
4145                                 alc880_pin_asus_init_verbs,
4146                                 alc880_gpio1_init_verbs },
4147                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4148                 .dac_nids = alc880_asus_dac_nids,
4149                 .dig_out_nid = ALC880_DIGOUT_NID,
4150                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4151                 .channel_mode = alc880_asus_modes,
4152                 .need_dac_fix = 1,
4153                 .input_mux = &alc880_capture_source,
4154         },
4155         [ALC880_ASUS_DIG2] = {
4156                 .mixers = { alc880_asus_mixer },
4157                 .init_verbs = { alc880_volume_init_verbs,
4158                                 alc880_pin_asus_init_verbs,
4159                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4160                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4161                 .dac_nids = alc880_asus_dac_nids,
4162                 .dig_out_nid = ALC880_DIGOUT_NID,
4163                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4164                 .channel_mode = alc880_asus_modes,
4165                 .need_dac_fix = 1,
4166                 .input_mux = &alc880_capture_source,
4167         },
4168         [ALC880_ASUS_W1V] = {
4169                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4170                 .init_verbs = { alc880_volume_init_verbs,
4171                                 alc880_pin_asus_init_verbs,
4172                                 alc880_gpio1_init_verbs },
4173                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4174                 .dac_nids = alc880_asus_dac_nids,
4175                 .dig_out_nid = ALC880_DIGOUT_NID,
4176                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4177                 .channel_mode = alc880_asus_modes,
4178                 .need_dac_fix = 1,
4179                 .input_mux = &alc880_capture_source,
4180         },
4181         [ALC880_UNIWILL_DIG] = {
4182                 .mixers = { alc880_asus_mixer },
4183                 .init_verbs = { alc880_volume_init_verbs,
4184                                 alc880_pin_asus_init_verbs },
4185                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4186                 .dac_nids = alc880_asus_dac_nids,
4187                 .dig_out_nid = ALC880_DIGOUT_NID,
4188                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4189                 .channel_mode = alc880_asus_modes,
4190                 .need_dac_fix = 1,
4191                 .input_mux = &alc880_capture_source,
4192         },
4193         [ALC880_UNIWILL] = {
4194                 .mixers = { alc880_uniwill_mixer },
4195                 .init_verbs = { alc880_volume_init_verbs,
4196                                 alc880_uniwill_init_verbs },
4197                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4198                 .dac_nids = alc880_asus_dac_nids,
4199                 .dig_out_nid = ALC880_DIGOUT_NID,
4200                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4201                 .channel_mode = alc880_threestack_modes,
4202                 .need_dac_fix = 1,
4203                 .input_mux = &alc880_capture_source,
4204                 .unsol_event = alc880_uniwill_unsol_event,
4205                 .setup = alc880_uniwill_setup,
4206                 .init_hook = alc880_uniwill_init_hook,
4207         },
4208         [ALC880_UNIWILL_P53] = {
4209                 .mixers = { alc880_uniwill_p53_mixer },
4210                 .init_verbs = { alc880_volume_init_verbs,
4211                                 alc880_uniwill_p53_init_verbs },
4212                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4213                 .dac_nids = alc880_asus_dac_nids,
4214                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4215                 .channel_mode = alc880_threestack_modes,
4216                 .input_mux = &alc880_capture_source,
4217                 .unsol_event = alc880_uniwill_p53_unsol_event,
4218                 .setup = alc880_uniwill_p53_setup,
4219                 .init_hook = alc_automute_amp,
4220         },
4221         [ALC880_FUJITSU] = {
4222                 .mixers = { alc880_fujitsu_mixer },
4223                 .init_verbs = { alc880_volume_init_verbs,
4224                                 alc880_uniwill_p53_init_verbs,
4225                                 alc880_beep_init_verbs },
4226                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4227                 .dac_nids = alc880_dac_nids,
4228                 .dig_out_nid = ALC880_DIGOUT_NID,
4229                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4230                 .channel_mode = alc880_2_jack_modes,
4231                 .input_mux = &alc880_capture_source,
4232                 .unsol_event = alc880_uniwill_p53_unsol_event,
4233                 .setup = alc880_uniwill_p53_setup,
4234                 .init_hook = alc_automute_amp,
4235         },
4236         [ALC880_CLEVO] = {
4237                 .mixers = { alc880_three_stack_mixer },
4238                 .init_verbs = { alc880_volume_init_verbs,
4239                                 alc880_pin_clevo_init_verbs },
4240                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4241                 .dac_nids = alc880_dac_nids,
4242                 .hp_nid = 0x03,
4243                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4244                 .channel_mode = alc880_threestack_modes,
4245                 .need_dac_fix = 1,
4246                 .input_mux = &alc880_capture_source,
4247         },
4248         [ALC880_LG] = {
4249                 .mixers = { alc880_lg_mixer },
4250                 .init_verbs = { alc880_volume_init_verbs,
4251                                 alc880_lg_init_verbs },
4252                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4253                 .dac_nids = alc880_lg_dac_nids,
4254                 .dig_out_nid = ALC880_DIGOUT_NID,
4255                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4256                 .channel_mode = alc880_lg_ch_modes,
4257                 .need_dac_fix = 1,
4258                 .input_mux = &alc880_lg_capture_source,
4259                 .unsol_event = alc_automute_amp_unsol_event,
4260                 .setup = alc880_lg_setup,
4261                 .init_hook = alc_automute_amp,
4262 #ifdef CONFIG_SND_HDA_POWER_SAVE
4263                 .loopbacks = alc880_lg_loopbacks,
4264 #endif
4265         },
4266         [ALC880_LG_LW] = {
4267                 .mixers = { alc880_lg_lw_mixer },
4268                 .init_verbs = { alc880_volume_init_verbs,
4269                                 alc880_lg_lw_init_verbs },
4270                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4271                 .dac_nids = alc880_dac_nids,
4272                 .dig_out_nid = ALC880_DIGOUT_NID,
4273                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4274                 .channel_mode = alc880_lg_lw_modes,
4275                 .input_mux = &alc880_lg_lw_capture_source,
4276                 .unsol_event = alc_automute_amp_unsol_event,
4277                 .setup = alc880_lg_lw_setup,
4278                 .init_hook = alc_automute_amp,
4279         },
4280         [ALC880_MEDION_RIM] = {
4281                 .mixers = { alc880_medion_rim_mixer },
4282                 .init_verbs = { alc880_volume_init_verbs,
4283                                 alc880_medion_rim_init_verbs,
4284                                 alc_gpio2_init_verbs },
4285                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4286                 .dac_nids = alc880_dac_nids,
4287                 .dig_out_nid = ALC880_DIGOUT_NID,
4288                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4289                 .channel_mode = alc880_2_jack_modes,
4290                 .input_mux = &alc880_medion_rim_capture_source,
4291                 .unsol_event = alc880_medion_rim_unsol_event,
4292                 .setup = alc880_medion_rim_setup,
4293                 .init_hook = alc880_medion_rim_automute,
4294         },
4295 #ifdef CONFIG_SND_DEBUG
4296         [ALC880_TEST] = {
4297                 .mixers = { alc880_test_mixer },
4298                 .init_verbs = { alc880_test_init_verbs },
4299                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4300                 .dac_nids = alc880_test_dac_nids,
4301                 .dig_out_nid = ALC880_DIGOUT_NID,
4302                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4303                 .channel_mode = alc880_test_modes,
4304                 .input_mux = &alc880_test_capture_source,
4305         },
4306 #endif
4307 };
4308 
4309 /*
4310  * Automatic parse of I/O pins from the BIOS configuration
4311  */
4312 
4313 enum {
4314         ALC_CTL_WIDGET_VOL,
4315         ALC_CTL_WIDGET_MUTE,
4316         ALC_CTL_BIND_MUTE,
4317 };
4318 static struct snd_kcontrol_new alc880_control_templates[] = {
4319         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4320         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4321         HDA_BIND_MUTE(NULL, 0, 0, 0),
4322 };
4323 
4324 /* add dynamic controls */
4325 static int add_control(struct alc_spec *spec, int type, const char *name,
4326                        unsigned long val)
4327 {
4328         struct snd_kcontrol_new *knew;
4329 
4330         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4331         knew = snd_array_new(&spec->kctls);
4332         if (!knew)
4333                 return -ENOMEM;
4334         *knew = alc880_control_templates[type];
4335         knew->name = kstrdup(name, GFP_KERNEL);
4336         if (!knew->name)
4337                 return -ENOMEM;
4338         knew->private_value = val;
4339         return 0;
4340 }
4341 
4342 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4343 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4344 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4345 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4346 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4347 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4348 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4349 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4350 #define ALC880_PIN_CD_NID               0x1c
4351 
4352 /* fill in the dac_nids table from the parsed pin configuration */
4353 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4354                                      const struct auto_pin_cfg *cfg)
4355 {
4356         hda_nid_t nid;
4357         int assigned[4];
4358         int i, j;
4359 
4360         memset(assigned, 0, sizeof(assigned));
4361         spec->multiout.dac_nids = spec->private_dac_nids;
4362 
4363         /* check the pins hardwired to audio widget */
4364         for (i = 0; i < cfg->line_outs; i++) {
4365                 nid = cfg->line_out_pins[i];
4366                 if (alc880_is_fixed_pin(nid)) {
4367                         int idx = alc880_fixed_pin_idx(nid);
4368                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4369                         assigned[idx] = 1;
4370                 }
4371         }
4372         /* left pins can be connect to any audio widget */
4373         for (i = 0; i < cfg->line_outs; i++) {
4374                 nid = cfg->line_out_pins[i];
4375                 if (alc880_is_fixed_pin(nid))
4376                         continue;
4377                 /* search for an empty channel */
4378                 for (j = 0; j < cfg->line_outs; j++) {
4379                         if (!assigned[j]) {
4380                                 spec->multiout.dac_nids[i] =
4381                                         alc880_idx_to_dac(j);
4382                                 assigned[j] = 1;
4383                                 break;
4384                         }
4385                 }
4386         }
4387         spec->multiout.num_dacs = cfg->line_outs;
4388         return 0;
4389 }
4390 
4391 /* add playback controls from the parsed DAC table */
4392 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4393                                              const struct auto_pin_cfg *cfg)
4394 {
4395         char name[32];
4396         static const char *chname[4] = {
4397                 "Front", "Surround", NULL /*CLFE*/, "Side"
4398         };
4399         hda_nid_t nid;
4400         int i, err;
4401 
4402         for (i = 0; i < cfg->line_outs; i++) {
4403                 if (!spec->multiout.dac_nids[i])
4404                         continue;
4405                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4406                 if (i == 2) {
4407                         /* Center/LFE */
4408                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4409                                           "Center Playback Volume",
4410                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4411                                                               HDA_OUTPUT));
4412                         if (err < 0)
4413                                 return err;
4414                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4415                                           "LFE Playback Volume",
4416                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4417                                                               HDA_OUTPUT));
4418                         if (err < 0)
4419                                 return err;
4420                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4421                                           "Center Playback Switch",
4422                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4423                                                               HDA_INPUT));
4424                         if (err < 0)
4425                                 return err;
4426                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4427                                           "LFE Playback Switch",
4428                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4429                                                               HDA_INPUT));
4430                         if (err < 0)
4431                                 return err;
4432                 } else {
4433                         const char *pfx;
4434                         if (cfg->line_outs == 1 &&
4435                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4436                                 pfx = "Speaker";
4437                         else
4438                                 pfx = chname[i];
4439                         sprintf(name, "%s Playback Volume", pfx);
4440                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4441                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4442                                                               HDA_OUTPUT));
4443                         if (err < 0)
4444                                 return err;
4445                         sprintf(name, "%s Playback Switch", pfx);
4446                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4447                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4448                                                               HDA_INPUT));
4449                         if (err < 0)
4450                                 return err;
4451                 }
4452         }
4453         return 0;
4454 }
4455 
4456 /* add playback controls for speaker and HP outputs */
4457 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4458                                         const char *pfx)
4459 {
4460         hda_nid_t nid;
4461         int err;
4462         char name[32];
4463 
4464         if (!pin)
4465                 return 0;
4466 
4467         if (alc880_is_fixed_pin(pin)) {
4468                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4469                 /* specify the DAC as the extra output */
4470                 if (!spec->multiout.hp_nid)
4471                         spec->multiout.hp_nid = nid;
4472                 else
4473                         spec->multiout.extra_out_nid[0] = nid;
4474                 /* control HP volume/switch on the output mixer amp */
4475                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4476                 sprintf(name, "%s Playback Volume", pfx);
4477                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4478                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4479                 if (err < 0)
4480                         return err;
4481                 sprintf(name, "%s Playback Switch", pfx);
4482                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4483                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4484                 if (err < 0)
4485                         return err;
4486         } else if (alc880_is_multi_pin(pin)) {
4487                 /* set manual connection */
4488                 /* we have only a switch on HP-out PIN */
4489                 sprintf(name, "%s Playback Switch", pfx);
4490                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4491                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4492                 if (err < 0)
4493                         return err;
4494         }
4495         return 0;
4496 }
4497 
4498 /* create input playback/capture controls for the given pin */
4499 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4500                             const char *ctlname,
4501                             int idx, hda_nid_t mix_nid)
4502 {
4503         char name[32];
4504         int err;
4505 
4506         sprintf(name, "%s Playback Volume", ctlname);
4507         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4508                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4509         if (err < 0)
4510                 return err;
4511         sprintf(name, "%s Playback Switch", ctlname);
4512         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4513                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4514         if (err < 0)
4515                 return err;
4516         return 0;
4517 }
4518 
4519 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4520 {
4521         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4522         return (pincap & AC_PINCAP_IN) != 0;
4523 }
4524 
4525 /* create playback/capture controls for input pins */
4526 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4527                                       const struct auto_pin_cfg *cfg,
4528                                       hda_nid_t mixer,
4529                                       hda_nid_t cap1, hda_nid_t cap2)
4530 {
4531         struct alc_spec *spec = codec->spec;
4532         struct hda_input_mux *imux = &spec->private_imux[0];
4533         int i, err, idx;
4534 
4535         for (i = 0; i < AUTO_PIN_LAST; i++) {
4536                 hda_nid_t pin;
4537 
4538                 pin = cfg->input_pins[i];
4539                 if (!alc_is_input_pin(codec, pin))
4540                         continue;
4541 
4542                 if (mixer) {
4543                         idx = get_connection_index(codec, mixer, pin);
4544                         if (idx >= 0) {
4545                                 err = new_analog_input(spec, pin,
4546                                                        auto_pin_cfg_labels[i],
4547                                                        idx, mixer);
4548                                 if (err < 0)
4549                                         return err;
4550                         }
4551                 }
4552 
4553                 if (!cap1)
4554                         continue;
4555                 idx = get_connection_index(codec, cap1, pin);
4556                 if (idx < 0 && cap2)
4557                         idx = get_connection_index(codec, cap2, pin);
4558                 if (idx >= 0) {
4559                         imux->items[imux->num_items].label =
4560                                 auto_pin_cfg_labels[i];
4561                         imux->items[imux->num_items].index = idx;
4562                         imux->num_items++;
4563                 }
4564         }
4565         return 0;
4566 }
4567 
4568 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4569                                                 const struct auto_pin_cfg *cfg)
4570 {
4571         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4572 }
4573 
4574 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4575                                unsigned int pin_type)
4576 {
4577         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4578                             pin_type);
4579         /* unmute pin */
4580         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4581                             AMP_OUT_UNMUTE);
4582 }
4583 
4584 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4585                                               hda_nid_t nid, int pin_type,
4586                                               int dac_idx)
4587 {
4588         alc_set_pin_output(codec, nid, pin_type);
4589         /* need the manual connection? */
4590         if (alc880_is_multi_pin(nid)) {
4591                 struct alc_spec *spec = codec->spec;
4592                 int idx = alc880_multi_pin_idx(nid);
4593                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4594                                     AC_VERB_SET_CONNECT_SEL,
4595                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4596         }
4597 }
4598 
4599 static int get_pin_type(int line_out_type)
4600 {
4601         if (line_out_type == AUTO_PIN_HP_OUT)
4602                 return PIN_HP;
4603         else
4604                 return PIN_OUT;
4605 }
4606 
4607 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4608 {
4609         struct alc_spec *spec = codec->spec;
4610         int i;
4611 
4612         for (i = 0; i < spec->autocfg.line_outs; i++) {
4613                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4614                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4615                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4616         }
4617 }
4618 
4619 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4620 {
4621         struct alc_spec *spec = codec->spec;
4622         hda_nid_t pin;
4623 
4624         pin = spec->autocfg.speaker_pins[0];
4625         if (pin) /* connect to front */
4626                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4627         pin = spec->autocfg.hp_pins[0];
4628         if (pin) /* connect to front */
4629                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4630 }
4631 
4632 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4633 {
4634         struct alc_spec *spec = codec->spec;
4635         int i;
4636 
4637         for (i = 0; i < AUTO_PIN_LAST; i++) {
4638                 hda_nid_t nid = spec->autocfg.input_pins[i];
4639                 if (alc_is_input_pin(codec, nid)) {
4640                         alc_set_input_pin(codec, nid, i);
4641                         if (nid != ALC880_PIN_CD_NID &&
4642                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4643                                 snd_hda_codec_write(codec, nid, 0,
4644                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4645                                                     AMP_OUT_MUTE);
4646                 }
4647         }
4648 }
4649 
4650 /* parse the BIOS configuration and set up the alc_spec */
4651 /* return 1 if successful, 0 if the proper config is not found,
4652  * or a negative error code
4653  */
4654 static int alc880_parse_auto_config(struct hda_codec *codec)
4655 {
4656         struct alc_spec *spec = codec->spec;
4657         int i, err;
4658         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4659 
4660         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4661                                            alc880_ignore);
4662         if (err < 0)
4663                 return err;
4664         if (!spec->autocfg.line_outs)
4665                 return 0; /* can't find valid BIOS pin config */
4666 
4667         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4668         if (err < 0)
4669                 return err;
4670         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4671         if (err < 0)
4672                 return err;
4673         err = alc880_auto_create_extra_out(spec,
4674                                            spec->autocfg.speaker_pins[0],
4675                                            "Speaker");
4676         if (err < 0)
4677                 return err;
4678         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4679                                            "Headphone");
4680         if (err < 0)
4681                 return err;
4682         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4683         if (err < 0)
4684                 return err;
4685 
4686         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4687 
4688         /* check multiple SPDIF-out (for recent codecs) */
4689         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4690                 hda_nid_t dig_nid;
4691                 err = snd_hda_get_connections(codec,
4692                                               spec->autocfg.dig_out_pins[i],
4693                                               &dig_nid, 1);
4694                 if (err < 0)
4695                         continue;
4696                 if (!i)
4697                         spec->multiout.dig_out_nid = dig_nid;
4698                 else {
4699                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4700                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4701                                 break;
4702                         spec->slave_dig_outs[i - 1] = dig_nid;
4703                 }
4704         }
4705         if (spec->autocfg.dig_in_pin)
4706                 spec->dig_in_nid = ALC880_DIGIN_NID;
4707 
4708         if (spec->kctls.list)
4709                 add_mixer(spec, spec->kctls.list);
4710 
4711         add_verb(spec, alc880_volume_init_verbs);
4712 
4713         spec->num_mux_defs = 1;
4714         spec->input_mux = &spec->private_imux[0];
4715 
4716         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4717 
4718         return 1;
4719 }
4720 
4721 /* additional initialization for auto-configuration model */
4722 static void alc880_auto_init(struct hda_codec *codec)
4723 {
4724         struct alc_spec *spec = codec->spec;
4725         alc880_auto_init_multi_out(codec);
4726         alc880_auto_init_extra_out(codec);
4727         alc880_auto_init_analog_input(codec);
4728         if (spec->unsol_event)
4729                 alc_inithook(codec);
4730 }
4731 
4732 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4733  * one of two digital mic pins, e.g. on ALC272
4734  */
4735 static void fixup_automic_adc(struct hda_codec *codec)
4736 {
4737         struct alc_spec *spec = codec->spec;
4738         int i;
4739 
4740         for (i = 0; i < spec->num_adc_nids; i++) {
4741                 hda_nid_t cap = spec->capsrc_nids ?
4742                         spec->capsrc_nids[i] : spec->adc_nids[i];
4743                 int iidx, eidx;
4744 
4745                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4746                 if (iidx < 0)
4747                         continue;
4748                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4749                 if (eidx < 0)
4750                         continue;
4751                 spec->int_mic.mux_idx = iidx;
4752                 spec->ext_mic.mux_idx = eidx;
4753                 if (spec->capsrc_nids)
4754                         spec->capsrc_nids += i;
4755                 spec->adc_nids += i;
4756                 spec->num_adc_nids = 1;
4757                 return;
4758         }
4759         snd_printd(KERN_INFO "hda_codec: %s: "
4760                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4761                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4762         spec->auto_mic = 0; /* disable auto-mic to be sure */
4763 }
4764 
4765 static void set_capture_mixer(struct hda_codec *codec)
4766 {
4767         struct alc_spec *spec = codec->spec;
4768         static struct snd_kcontrol_new *caps[2][3] = {
4769                 { alc_capture_mixer_nosrc1,
4770                   alc_capture_mixer_nosrc2,
4771                   alc_capture_mixer_nosrc3 },
4772                 { alc_capture_mixer1,
4773                   alc_capture_mixer2,
4774                   alc_capture_mixer3 },
4775         };
4776         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4777                 int mux;
4778                 if (spec->auto_mic) {
4779                         mux = 0;
4780                         fixup_automic_adc(codec);
4781                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4782                         mux = 1;
4783                 else
4784                         mux = 0;
4785                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4786         }
4787 }
4788 
4789 #define set_beep_amp(spec, nid, idx, dir) \
4790         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4791 
4792 /*
4793  * OK, here we have finally the patch for ALC880
4794  */
4795 
4796 static int patch_alc880(struct hda_codec *codec)
4797 {
4798         struct alc_spec *spec;
4799         int board_config;
4800         int err;
4801 
4802         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4803         if (spec == NULL)
4804                 return -ENOMEM;
4805 
4806         codec->spec = spec;
4807 
4808         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4809                                                   alc880_models,
4810                                                   alc880_cfg_tbl);
4811         if (board_config < 0) {
4812                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4813                        codec->chip_name);
4814                 board_config = ALC880_AUTO;
4815         }
4816 
4817         if (board_config == ALC880_AUTO) {
4818                 /* automatic parse from the BIOS config */
4819                 err = alc880_parse_auto_config(codec);
4820                 if (err < 0) {
4821                         alc_free(codec);
4822                         return err;
4823                 } else if (!err) {
4824                         printk(KERN_INFO
4825                                "hda_codec: Cannot set up configuration "
4826                                "from BIOS.  Using 3-stack mode...\n");
4827                         board_config = ALC880_3ST;
4828                 }
4829         }
4830 
4831         err = snd_hda_attach_beep_device(codec, 0x1);
4832         if (err < 0) {
4833                 alc_free(codec);
4834                 return err;
4835         }
4836 
4837         if (board_config != ALC880_AUTO)
4838                 setup_preset(codec, &alc880_presets[board_config]);
4839 
4840         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4841         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4842         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4843 
4844         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4845         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4846 
4847         if (!spec->adc_nids && spec->input_mux) {
4848                 /* check whether NID 0x07 is valid */
4849                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4850                 /* get type */
4851                 wcap = get_wcaps_type(wcap);
4852                 if (wcap != AC_WID_AUD_IN) {
4853                         spec->adc_nids = alc880_adc_nids_alt;
4854                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4855                 } else {
4856                         spec->adc_nids = alc880_adc_nids;
4857                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4858                 }
4859         }
4860         set_capture_mixer(codec);
4861         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4862 
4863         spec->vmaster_nid = 0x0c;
4864 
4865         codec->patch_ops = alc_patch_ops;
4866         if (board_config == ALC880_AUTO)
4867                 spec->init_hook = alc880_auto_init;
4868 #ifdef CONFIG_SND_HDA_POWER_SAVE
4869         if (!spec->loopback.amplist)
4870                 spec->loopback.amplist = alc880_loopbacks;
4871 #endif
4872         codec->proc_widget_hook = print_realtek_coef;
4873 
4874         return 0;
4875 }
4876 
4877 
4878 /*
4879  * ALC260 support
4880  */
4881 
4882 static hda_nid_t alc260_dac_nids[1] = {
4883         /* front */
4884         0x02,
4885 };
4886 
4887 static hda_nid_t alc260_adc_nids[1] = {
4888         /* ADC0 */
4889         0x04,
4890 };
4891 
4892 static hda_nid_t alc260_adc_nids_alt[1] = {
4893         /* ADC1 */
4894         0x05,
4895 };
4896 
4897 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4898  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4899  */
4900 static hda_nid_t alc260_dual_adc_nids[2] = {
4901         /* ADC0, ADC1 */
4902         0x04, 0x05
4903 };
4904 
4905 #define ALC260_DIGOUT_NID       0x03
4906 #define ALC260_DIGIN_NID        0x06
4907 
4908 static struct hda_input_mux alc260_capture_source = {
4909         .num_items = 4,
4910         .items = {
4911                 { "Mic", 0x0 },
4912                 { "Front Mic", 0x1 },
4913                 { "Line", 0x2 },
4914                 { "CD", 0x4 },
4915         },
4916 };
4917 
4918 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4919  * headphone jack and the internal CD lines since these are the only pins at
4920  * which audio can appear.  For flexibility, also allow the option of
4921  * recording the mixer output on the second ADC (ADC0 doesn't have a
4922  * connection to the mixer output).
4923  */
4924 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4925         {
4926                 .num_items = 3,
4927                 .items = {
4928                         { "Mic/Line", 0x0 },
4929                         { "CD", 0x4 },
4930                         { "Headphone", 0x2 },
4931                 },
4932         },
4933         {
4934                 .num_items = 4,
4935                 .items = {
4936                         { "Mic/Line", 0x0 },
4937                         { "CD", 0x4 },
4938                         { "Headphone", 0x2 },
4939                         { "Mixer", 0x5 },
4940                 },
4941         },
4942 
4943 };
4944 
4945 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4946  * the Fujitsu S702x, but jacks are marked differently.
4947  */
4948 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4949         {
4950                 .num_items = 4,
4951                 .items = {
4952                         { "Mic", 0x0 },
4953                         { "Line", 0x2 },
4954                         { "CD", 0x4 },
4955                         { "Headphone", 0x5 },
4956                 },
4957         },
4958         {
4959                 .num_items = 5,
4960                 .items = {
4961                         { "Mic", 0x0 },
4962                         { "Line", 0x2 },
4963                         { "CD", 0x4 },
4964                         { "Headphone", 0x6 },
4965                         { "Mixer", 0x5 },
4966                 },
4967         },
4968 };
4969 
4970 /* Maxdata Favorit 100XS */
4971 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4972         {
4973                 .num_items = 2,
4974                 .items = {
4975                         { "Line/Mic", 0x0 },
4976                         { "CD", 0x4 },
4977                 },
4978         },
4979         {
4980                 .num_items = 3,
4981                 .items = {
4982                         { "Line/Mic", 0x0 },
4983                         { "CD", 0x4 },
4984                         { "Mixer", 0x5 },
4985                 },
4986         },
4987 };
4988 
4989 /*
4990  * This is just place-holder, so there's something for alc_build_pcms to look
4991  * at when it calculates the maximum number of channels. ALC260 has no mixer
4992  * element which allows changing the channel mode, so the verb list is
4993  * never used.
4994  */
4995 static struct hda_channel_mode alc260_modes[1] = {
4996         { 2, NULL },
4997 };
4998 
4999 
5000 /* Mixer combinations
5001  *
5002  * basic: base_output + input + pc_beep + capture
5003  * HP: base_output + input + capture_alt
5004  * HP_3013: hp_3013 + input + capture
5005  * fujitsu: fujitsu + capture
5006  * acer: acer + capture
5007  */
5008 
5009 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5010         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5011         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5012         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5013         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5014         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5015         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5016         { } /* end */
5017 };
5018 
5019 static struct snd_kcontrol_new alc260_input_mixer[] = {
5020         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5021         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5022         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5023         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5024         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5025         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5026         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5027         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5028         { } /* end */
5029 };
5030 
5031 /* update HP, line and mono out pins according to the master switch */
5032 static void alc260_hp_master_update(struct hda_codec *codec,
5033                                     hda_nid_t hp, hda_nid_t line,
5034                                     hda_nid_t mono)
5035 {
5036         struct alc_spec *spec = codec->spec;
5037         unsigned int val = spec->master_sw ? PIN_HP : 0;
5038         /* change HP and line-out pins */
5039         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5040                             val);
5041         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5042                             val);
5043         /* mono (speaker) depending on the HP jack sense */
5044         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5045         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5046                             val);
5047 }
5048 
5049 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5050                                    struct snd_ctl_elem_value *ucontrol)
5051 {
5052         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5053         struct alc_spec *spec = codec->spec;
5054         *ucontrol->value.integer.value = spec->master_sw;
5055         return 0;
5056 }
5057 
5058 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5059                                    struct snd_ctl_elem_value *ucontrol)
5060 {
5061         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5062         struct alc_spec *spec = codec->spec;
5063         int val = !!*ucontrol->value.integer.value;
5064         hda_nid_t hp, line, mono;
5065 
5066         if (val == spec->master_sw)
5067                 return 0;
5068         spec->master_sw = val;
5069         hp = (kcontrol->private_value >> 16) & 0xff;
5070         line = (kcontrol->private_value >> 8) & 0xff;
5071         mono = kcontrol->private_value & 0xff;
5072         alc260_hp_master_update(codec, hp, line, mono);
5073         return 1;
5074 }
5075 
5076 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5077         {
5078                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5079                 .name = "Master Playback Switch",
5080                 .info = snd_ctl_boolean_mono_info,
5081                 .get = alc260_hp_master_sw_get,
5082                 .put = alc260_hp_master_sw_put,
5083                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5084         },
5085         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5086         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5087         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5088         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5089         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5090                               HDA_OUTPUT),
5091         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5092         { } /* end */
5093 };
5094 
5095 static struct hda_verb alc260_hp_unsol_verbs[] = {
5096         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5097         {},
5098 };
5099 
5100 static void alc260_hp_automute(struct hda_codec *codec)
5101 {
5102         struct alc_spec *spec = codec->spec;
5103         unsigned int present;
5104 
5105         present = snd_hda_codec_read(codec, 0x10, 0,
5106                                      AC_VERB_GET_PIN_SENSE, 0);
5107         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5108         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5109 }
5110 
5111 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5112 {
5113         if ((res >> 26) == ALC880_HP_EVENT)
5114                 alc260_hp_automute(codec);
5115 }
5116 
5117 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5118         {
5119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5120                 .name = "Master Playback Switch",
5121                 .info = snd_ctl_boolean_mono_info,
5122                 .get = alc260_hp_master_sw_get,
5123                 .put = alc260_hp_master_sw_put,
5124                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5125         },
5126         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5127         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5128         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5129         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5130         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5131         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5132         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5133         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5134         { } /* end */
5135 };
5136 
5137 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5138         .ops = &snd_hda_bind_vol,
5139         .values = {
5140                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5141                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5142                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5143                 0
5144         },
5145 };
5146 
5147 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5148         .ops = &snd_hda_bind_sw,
5149         .values = {
5150                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5151                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5152                 0
5153         },
5154 };
5155 
5156 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5157         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5158         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5159         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5160         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5161         { } /* end */
5162 };
5163 
5164 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5165         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5166         {},
5167 };
5168 
5169 static void alc260_hp_3013_automute(struct hda_codec *codec)
5170 {
5171         struct alc_spec *spec = codec->spec;
5172         unsigned int present;
5173 
5174         present = snd_hda_codec_read(codec, 0x15, 0,
5175                                      AC_VERB_GET_PIN_SENSE, 0);
5176         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5177         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5178 }
5179 
5180 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5181                                        unsigned int res)
5182 {
5183         if ((res >> 26) == ALC880_HP_EVENT)
5184                 alc260_hp_3013_automute(codec);
5185 }
5186 
5187 static void alc260_hp_3012_automute(struct hda_codec *codec)
5188 {
5189         unsigned int present, bits;
5190 
5191         present = snd_hda_codec_read(codec, 0x10, 0,
5192                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5193 
5194         bits = present ? 0 : PIN_OUT;
5195         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5196                             bits);
5197         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5198                             bits);
5199         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5200                             bits);
5201 }
5202 
5203 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5204                                        unsigned int res)
5205 {
5206         if ((res >> 26) == ALC880_HP_EVENT)
5207                 alc260_hp_3012_automute(codec);
5208 }
5209 
5210 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5211  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5212  */
5213 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5214         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5215         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5216         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5217         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5218         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5219         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5220         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5221         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5222         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5223         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5224         { } /* end */
5225 };
5226 
5227 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5228  * versions of the ALC260 don't act on requests to enable mic bias from NID
5229  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5230  * datasheet doesn't mention this restriction.  At this stage it's not clear
5231  * whether this behaviour is intentional or is a hardware bug in chip
5232  * revisions available in early 2006.  Therefore for now allow the
5233  * "Headphone Jack Mode" control to span all choices, but if it turns out
5234  * that the lack of mic bias for this NID is intentional we could change the
5235  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5236  *
5237  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5238  * don't appear to make the mic bias available from the "line" jack, even
5239  * though the NID used for this jack (0x14) can supply it.  The theory is
5240  * that perhaps Acer have included blocking capacitors between the ALC260
5241  * and the output jack.  If this turns out to be the case for all such
5242  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5243  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5244  *
5245  * The C20x Tablet series have a mono internal speaker which is controlled
5246  * via the chip's Mono sum widget and pin complex, so include the necessary
5247  * controls for such models.  On models without a "mono speaker" the control
5248  * won't do anything.
5249  */
5250 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5251         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5252         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5253         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5254         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5255                               HDA_OUTPUT),
5256         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5257                            HDA_INPUT),
5258         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5259         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5260         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5261         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5262         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5263         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5264         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5265         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5266         { } /* end */
5267 };
5268 
5269 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5270  */
5271 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5272         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5273         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5274         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5275         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5276         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5277         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5278         { } /* end */
5279 };
5280 
5281 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5282  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5283  */
5284 static struct snd_kcontrol_new alc260_will_mixer[] = {
5285         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5286         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5287         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5288         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5289         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5290         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5291         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5292         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5293         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5294         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5295         { } /* end */
5296 };
5297 
5298 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5299  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5300  */
5301 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5302         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5303         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5304         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5305         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5306         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5307         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5308         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5309         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5310         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5311         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5312         { } /* end */
5313 };
5314 
5315 /*
5316  * initialization verbs
5317  */
5318 static struct hda_verb alc260_init_verbs[] = {
5319         /* Line In pin widget for input */
5320         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5321         /* CD pin widget for input */
5322         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5323         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5324         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5325         /* Mic2 (front panel) pin widget for input and vref at 80% */
5326         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5327         /* LINE-2 is used for line-out in rear */
5328         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5329         /* select line-out */
5330         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5331         /* LINE-OUT pin */
5332         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5333         /* enable HP */
5334         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5335         /* enable Mono */
5336         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5337         /* mute capture amp left and right */
5338         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339         /* set connection select to line in (default select for this ADC) */
5340         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5341         /* mute capture amp left and right */
5342         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5343         /* set connection select to line in (default select for this ADC) */
5344         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5345         /* set vol=0 Line-Out mixer amp left and right */
5346         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5347         /* unmute pin widget amp left and right (no gain on this amp) */
5348         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5349         /* set vol=0 HP mixer amp left and right */
5350         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5351         /* unmute pin widget amp left and right (no gain on this amp) */
5352         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         /* set vol=0 Mono mixer amp left and right */
5354         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5355         /* unmute pin widget amp left and right (no gain on this amp) */
5356         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5357         /* unmute LINE-2 out pin */
5358         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5359         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5360          * Line In 2 = 0x03
5361          */
5362         /* mute analog inputs */
5363         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5364         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5365         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5368         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5369         /* mute Front out path */
5370         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5371         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5372         /* mute Headphone out path */
5373         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5374         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5375         /* mute Mono out path */
5376         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5377         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5378         { }
5379 };
5380 
5381 #if 0 /* should be identical with alc260_init_verbs? */
5382 static struct hda_verb alc260_hp_init_verbs[] = {
5383         /* Headphone and output */
5384         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5385         /* mono output */
5386         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5387         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5388         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5389         /* Mic2 (front panel) pin widget for input and vref at 80% */
5390         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5391         /* Line In pin widget for input */
5392         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5393         /* Line-2 pin widget for output */
5394         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5395         /* CD pin widget for input */
5396         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5397         /* unmute amp left and right */
5398         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5399         /* set connection select to line in (default select for this ADC) */
5400         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5401         /* unmute Line-Out mixer amp left and right (volume = 0) */
5402         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5403         /* mute pin widget amp left and right (no gain on this amp) */
5404         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5405         /* unmute HP mixer amp left and right (volume = 0) */
5406         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5407         /* mute pin widget amp left and right (no gain on this amp) */
5408         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5409         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5410          * Line In 2 = 0x03
5411          */
5412         /* mute analog inputs */
5413         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5414         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5415         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5416         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5418         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5419         /* Unmute Front out path */
5420         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5421         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5422         /* Unmute Headphone out path */
5423         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5424         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5425         /* Unmute Mono out path */
5426         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5427         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5428         { }
5429 };
5430 #endif
5431 
5432 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5433         /* Line out and output */
5434         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5435         /* mono output */
5436         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5437         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5438         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5439         /* Mic2 (front panel) pin widget for input and vref at 80% */
5440         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5441         /* Line In pin widget for input */
5442         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5443         /* Headphone pin widget for output */
5444         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5445         /* CD pin widget for input */
5446         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5447         /* unmute amp left and right */
5448         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5449         /* set connection select to line in (default select for this ADC) */
5450         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5451         /* unmute Line-Out mixer amp left and right (volume = 0) */
5452         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5453         /* mute pin widget amp left and right (no gain on this amp) */
5454         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5455         /* unmute HP mixer amp left and right (volume = 0) */
5456         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5457         /* mute pin widget amp left and right (no gain on this amp) */
5458         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5459         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5460          * Line In 2 = 0x03
5461          */
5462         /* mute analog inputs */
5463         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5464         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5465         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5466         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5467         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5468         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5469         /* Unmute Front out path */
5470         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5471         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5472         /* Unmute Headphone out path */
5473         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5474         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5475         /* Unmute Mono out path */
5476         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5477         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5478         { }
5479 };
5480 
5481 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5482  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5483  * audio = 0x16, internal speaker = 0x10.
5484  */
5485 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5486         /* Disable all GPIOs */
5487         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5488         /* Internal speaker is connected to headphone pin */
5489         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5490         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5491         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5492         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5493         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5494         /* Ensure all other unused pins are disabled and muted. */
5495         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5496         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5497         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5498         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5499         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5500         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5501         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5502         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5503 
5504         /* Disable digital (SPDIF) pins */
5505         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5506         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5507 
5508         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5509          * when acting as an output.
5510          */
5511         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5512 
5513         /* Start with output sum widgets muted and their output gains at min */
5514         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5515         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5516         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5517         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5518         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5519         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5520         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5521         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5522         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5523 
5524         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5525         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5526         /* Unmute Line1 pin widget output buffer since it starts as an output.
5527          * If the pin mode is changed by the user the pin mode control will
5528          * take care of enabling the pin's input/output buffers as needed.
5529          * Therefore there's no need to enable the input buffer at this
5530          * stage.
5531          */
5532         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5533         /* Unmute input buffer of pin widget used for Line-in (no equiv
5534          * mixer ctrl)
5535          */
5536         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5537 
5538         /* Mute capture amp left and right */
5539         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5540         /* Set ADC connection select to match default mixer setting - line
5541          * in (on mic1 pin)
5542          */
5543         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5544 
5545         /* Do the same for the second ADC: mute capture input amp and
5546          * set ADC connection to line in (on mic1 pin)
5547          */
5548         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5549         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5550 
5551         /* Mute all inputs to mixer widget (even unconnected ones) */
5552         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5553         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5554         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5556         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5559         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5560 
5561         { }
5562 };
5563 
5564 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5565  * similar laptops (adapted from Fujitsu init verbs).
5566  */
5567 static struct hda_verb alc260_acer_init_verbs[] = {
5568         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5569          * the headphone jack.  Turn this on and rely on the standard mute
5570          * methods whenever the user wants to turn these outputs off.
5571          */
5572         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5573         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5574         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5575         /* Internal speaker/Headphone jack is connected to Line-out pin */
5576         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5577         /* Internal microphone/Mic jack is connected to Mic1 pin */
5578         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5579         /* Line In jack is connected to Line1 pin */
5580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5581         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5582         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5583         /* Ensure all other unused pins are disabled and muted. */
5584         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5585         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5586         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5587         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5588         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5589         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5590         /* Disable digital (SPDIF) pins */
5591         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5592         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5593 
5594         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5595          * bus when acting as outputs.
5596          */
5597         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5598         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5599 
5600         /* Start with output sum widgets muted and their output gains at min */
5601         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5602         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5603         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5604         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5605         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5606         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5607         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5608         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5609         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5610 
5611         /* Unmute Line-out pin widget amp left and right
5612          * (no equiv mixer ctrl)
5613          */
5614         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5615         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5616         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5617         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5618          * inputs. If the pin mode is changed by the user the pin mode control
5619          * will take care of enabling the pin's input/output buffers as needed.
5620          * Therefore there's no need to enable the input buffer at this
5621          * stage.
5622          */
5623         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5625 
5626         /* Mute capture amp left and right */
5627         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5628         /* Set ADC connection select to match default mixer setting - mic
5629          * (on mic1 pin)
5630          */
5631         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5632 
5633         /* Do similar with the second ADC: mute capture input amp and
5634          * set ADC connection to mic to match ALSA's default state.
5635          */
5636         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5637         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5638 
5639         /* Mute all inputs to mixer widget (even unconnected ones) */
5640         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5641         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5642         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5643         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5644         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5645         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5646         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5647         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5648 
5649         { }
5650 };
5651 
5652 /* Initialisation sequence for Maxdata Favorit 100XS
5653  * (adapted from Acer init verbs).
5654  */
5655 static struct hda_verb alc260_favorit100_init_verbs[] = {
5656         /* GPIO 0 enables the output jack.
5657          * Turn this on and rely on the standard mute
5658          * methods whenever the user wants to turn these outputs off.
5659          */
5660         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5661         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5662         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5663         /* Line/Mic input jack is connected to Mic1 pin */
5664         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5665         /* Ensure all other unused pins are disabled and muted. */
5666         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5667         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5668         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5669         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5670         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5671         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5672         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5673         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5674         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5675         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5676         /* Disable digital (SPDIF) pins */
5677         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5678         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5679 
5680         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5681          * bus when acting as outputs.
5682          */
5683         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5684         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5685 
5686         /* Start with output sum widgets muted and their output gains at min */
5687         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5688         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5689         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5690         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5691         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5692         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5693         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5694         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5695         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5696 
5697         /* Unmute Line-out pin widget amp left and right
5698          * (no equiv mixer ctrl)
5699          */
5700         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5701         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5702          * inputs. If the pin mode is changed by the user the pin mode control
5703          * will take care of enabling the pin's input/output buffers as needed.
5704          * Therefore there's no need to enable the input buffer at this
5705          * stage.
5706          */
5707         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5708 
5709         /* Mute capture amp left and right */
5710         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5711         /* Set ADC connection select to match default mixer setting - mic
5712          * (on mic1 pin)
5713          */
5714         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5715 
5716         /* Do similar with the second ADC: mute capture input amp and
5717          * set ADC connection to mic to match ALSA's default state.
5718          */
5719         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5720         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5721 
5722         /* Mute all inputs to mixer widget (even unconnected ones) */
5723         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5724         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5725         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5727         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5728         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5729         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5731 
5732         { }
5733 };
5734 
5735 static struct hda_verb alc260_will_verbs[] = {
5736         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5737         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5738         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5739         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5740         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5741         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5742         {}
5743 };
5744 
5745 static struct hda_verb alc260_replacer_672v_verbs[] = {
5746         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5747         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5748         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5749 
5750         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5751         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5752         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5753 
5754         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5755         {}
5756 };
5757 
5758 /* toggle speaker-output according to the hp-jack state */
5759 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5760 {
5761         unsigned int present;
5762 
5763         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5764         present = snd_hda_codec_read(codec, 0x0f, 0,
5765                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5766         if (present) {
5767                 snd_hda_codec_write_cache(codec, 0x01, 0,
5768                                           AC_VERB_SET_GPIO_DATA, 1);
5769                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5770                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5771                                           PIN_HP);
5772         } else {
5773                 snd_hda_codec_write_cache(codec, 0x01, 0,
5774                                           AC_VERB_SET_GPIO_DATA, 0);
5775                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5776                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5777                                           PIN_OUT);
5778         }
5779 }
5780 
5781 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5782                                        unsigned int res)
5783 {
5784         if ((res >> 26) == ALC880_HP_EVENT)
5785                 alc260_replacer_672v_automute(codec);
5786 }
5787 
5788 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5789         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5790         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5791         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5792         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5793         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5794         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5795         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5796         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5797         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5798         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5799         {}
5800 };
5801 
5802 /* Test configuration for debugging, modelled after the ALC880 test
5803  * configuration.
5804  */
5805 #ifdef CONFIG_SND_DEBUG
5806 static hda_nid_t alc260_test_dac_nids[1] = {
5807         0x02,
5808 };
5809 static hda_nid_t alc260_test_adc_nids[2] = {
5810         0x04, 0x05,
5811 };
5812 /* For testing the ALC260, each input MUX needs its own definition since
5813  * the signal assignments are different.  This assumes that the first ADC
5814  * is NID 0x04.
5815  */
5816 static struct hda_input_mux alc260_test_capture_sources[2] = {
5817         {
5818                 .num_items = 7,
5819                 .items = {
5820                         { "MIC1 pin", 0x0 },
5821                         { "MIC2 pin", 0x1 },
5822                         { "LINE1 pin", 0x2 },
5823                         { "LINE2 pin", 0x3 },
5824                         { "CD pin", 0x4 },
5825                         { "LINE-OUT pin", 0x5 },
5826                         { "HP-OUT pin", 0x6 },
5827                 },
5828         },
5829         {
5830                 .num_items = 8,
5831                 .items = {
5832                         { "MIC1 pin", 0x0 },
5833                         { "MIC2 pin", 0x1 },
5834                         { "LINE1 pin", 0x2 },
5835                         { "LINE2 pin", 0x3 },
5836                         { "CD pin", 0x4 },
5837                         { "Mixer", 0x5 },
5838                         { "LINE-OUT pin", 0x6 },
5839                         { "HP-OUT pin", 0x7 },
5840                 },
5841         },
5842 };
5843 static struct snd_kcontrol_new alc260_test_mixer[] = {
5844         /* Output driver widgets */
5845         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5846         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5847         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5848         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5849         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5850         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5851 
5852         /* Modes for retasking pin widgets
5853          * Note: the ALC260 doesn't seem to act on requests to enable mic
5854          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5855          * mention this restriction.  At this stage it's not clear whether
5856          * this behaviour is intentional or is a hardware bug in chip
5857          * revisions available at least up until early 2006.  Therefore for
5858          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5859          * choices, but if it turns out that the lack of mic bias for these
5860          * NIDs is intentional we could change their modes from
5861          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5862          */
5863         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5864         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5865         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5866         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5867         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5868         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5869 
5870         /* Loopback mixer controls */
5871         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5872         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5873         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5874         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5875         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5876         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5877         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5878         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5879         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5880         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5881         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5882         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5883         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5884         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5885 
5886         /* Controls for GPIO pins, assuming they are configured as outputs */
5887         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5888         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5889         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5890         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5891 
5892         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5893          * is ambigious as to which NID is which; testing on laptops which
5894          * make this output available should provide clarification.
5895          */
5896         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5897         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5898 
5899         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5900          * this output to turn on an external amplifier.
5901          */
5902         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5903         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5904 
5905         { } /* end */
5906 };
5907 static struct hda_verb alc260_test_init_verbs[] = {
5908         /* Enable all GPIOs as outputs with an initial value of 0 */
5909         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5910         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5911         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5912 
5913         /* Enable retasking pins as output, initially without power amp */
5914         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5915         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5916         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5918         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5919         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5920 
5921         /* Disable digital (SPDIF) pins initially, but users can enable
5922          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5923          * payload also sets the generation to 0, output to be in "consumer"
5924          * PCM format, copyright asserted, no pre-emphasis and no validity
5925          * control.
5926          */
5927         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5928         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5929 
5930         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5931          * OUT1 sum bus when acting as an output.
5932          */
5933         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5934         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5935         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5936         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5937 
5938         /* Start with output sum widgets muted and their output gains at min */
5939         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5940         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5941         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5942         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5943         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5944         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5945         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5946         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5947         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5948 
5949         /* Unmute retasking pin widget output buffers since the default
5950          * state appears to be output.  As the pin mode is changed by the
5951          * user the pin mode control will take care of enabling the pin's
5952          * input/output buffers as needed.
5953          */
5954         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5955         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5956         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5957         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5958         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5959         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5960         /* Also unmute the mono-out pin widget */
5961         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5962 
5963         /* Mute capture amp left and right */
5964         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5965         /* Set ADC connection select to match default mixer setting (mic1
5966          * pin)
5967          */
5968         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5969 
5970         /* Do the same for the second ADC: mute capture input amp and
5971          * set ADC connection to mic1 pin
5972          */
5973         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5974         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5975 
5976         /* Mute all inputs to mixer widget (even unconnected ones) */
5977         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5978         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5979         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5980         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5981         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5982         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5984         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5985 
5986         { }
5987 };
5988 #endif
5989 
5990 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5991 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5992 
5993 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5994 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5995 
5996 /*
5997  * for BIOS auto-configuration
5998  */
5999 
6000 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6001                                         const char *pfx, int *vol_bits)
6002 {
6003         hda_nid_t nid_vol;
6004         unsigned long vol_val, sw_val;
6005         char name[32];
6006         int err;
6007 
6008         if (nid >= 0x0f && nid < 0x11) {
6009                 nid_vol = nid - 0x7;
6010                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6011                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6012         } else if (nid == 0x11) {
6013                 nid_vol = nid - 0x7;
6014                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6015                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6016         } else if (nid >= 0x12 && nid <= 0x15) {
6017                 nid_vol = 0x08;
6018                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6019                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6020         } else
6021                 return 0; /* N/A */
6022 
6023         if (!(*vol_bits & (1 << nid_vol))) {
6024                 /* first control for the volume widget */
6025                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);