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