ALSA: hda - Use ALC880_FIXUP_FUJITSU for FSC Amilo M1437
[linux-3.10.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for Realtek ALC 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@just42.net>
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 <linux/dmi.h>
31 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_auto_parser.h"
37 #include "hda_jack.h"
38 #include "hda_generic.h"
39
40 /* unsol event tags */
41 #define ALC_DCVOL_EVENT         0x08
42
43 /* for GPIO Poll */
44 #define GPIO_MASK       0x03
45
46 /* extra amp-initialization sequence types */
47 enum {
48         ALC_INIT_NONE,
49         ALC_INIT_DEFAULT,
50         ALC_INIT_GPIO1,
51         ALC_INIT_GPIO2,
52         ALC_INIT_GPIO3,
53 };
54
55 enum {
56         ALC_HEADSET_MODE_UNKNOWN,
57         ALC_HEADSET_MODE_UNPLUGGED,
58         ALC_HEADSET_MODE_HEADSET,
59         ALC_HEADSET_MODE_MIC,
60         ALC_HEADSET_MODE_HEADPHONE,
61 };
62
63 enum {
64         ALC_HEADSET_TYPE_UNKNOWN,
65         ALC_HEADSET_TYPE_CTIA,
66         ALC_HEADSET_TYPE_OMTP,
67 };
68
69 struct alc_customize_define {
70         unsigned int  sku_cfg;
71         unsigned char port_connectivity;
72         unsigned char check_sum;
73         unsigned char customization;
74         unsigned char external_amp;
75         unsigned int  enable_pcbeep:1;
76         unsigned int  platform_type:1;
77         unsigned int  swap:1;
78         unsigned int  override:1;
79         unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
80 };
81
82 struct alc_spec {
83         struct hda_gen_spec gen; /* must be at head */
84
85         /* codec parameterization */
86         const struct snd_kcontrol_new *mixers[5];       /* mixer arrays */
87         unsigned int num_mixers;
88         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
89
90         struct alc_customize_define cdefine;
91         unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
92
93         /* inverted dmic fix */
94         unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
95         unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
96         hda_nid_t inv_dmic_pin;
97
98         /* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
99         int mute_led_polarity;
100         hda_nid_t mute_led_nid;
101
102         unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
103
104         hda_nid_t headset_mic_pin;
105         hda_nid_t headphone_mic_pin;
106         int current_headset_mode;
107         int current_headset_type;
108
109         /* hooks */
110         void (*init_hook)(struct hda_codec *codec);
111 #ifdef CONFIG_PM
112         void (*power_hook)(struct hda_codec *codec);
113 #endif
114         void (*shutup)(struct hda_codec *codec);
115
116         int init_amp;
117         int codec_variant;      /* flag for other variants */
118
119         /* for PLL fix */
120         hda_nid_t pll_nid;
121         unsigned int pll_coef_idx, pll_coef_bit;
122         unsigned int coef0;
123 };
124
125 /*
126  * Append the given mixer and verb elements for the later use
127  * The mixer array is referred in build_controls(), and init_verbs are
128  * called in init().
129  */
130 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
131 {
132         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
133                 return;
134         spec->mixers[spec->num_mixers++] = mix;
135 }
136
137 /*
138  * GPIO setup tables, used in initialization
139  */
140 /* Enable GPIO mask and set output */
141 static const struct hda_verb alc_gpio1_init_verbs[] = {
142         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
143         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
144         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
145         { }
146 };
147
148 static const struct hda_verb alc_gpio2_init_verbs[] = {
149         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
150         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
151         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
152         { }
153 };
154
155 static const struct hda_verb alc_gpio3_init_verbs[] = {
156         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
157         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
158         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
159         { }
160 };
161
162 /*
163  * Fix hardware PLL issue
164  * On some codecs, the analog PLL gating control must be off while
165  * the default value is 1.
166  */
167 static void alc_fix_pll(struct hda_codec *codec)
168 {
169         struct alc_spec *spec = codec->spec;
170         unsigned int val;
171
172         if (!spec->pll_nid)
173                 return;
174         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
175                             spec->pll_coef_idx);
176         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
177                                  AC_VERB_GET_PROC_COEF, 0);
178         if (val == -1)
179                 return;
180         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
181                             spec->pll_coef_idx);
182         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
183                             val & ~(1 << spec->pll_coef_bit));
184 }
185
186 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
187                              unsigned int coef_idx, unsigned int coef_bit)
188 {
189         struct alc_spec *spec = codec->spec;
190         spec->pll_nid = nid;
191         spec->pll_coef_idx = coef_idx;
192         spec->pll_coef_bit = coef_bit;
193         alc_fix_pll(codec);
194 }
195
196 /* update the master volume per volume-knob's unsol event */
197 static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
198 {
199         unsigned int val;
200         struct snd_kcontrol *kctl;
201         struct snd_ctl_elem_value *uctl;
202
203         kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
204         if (!kctl)
205                 return;
206         uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
207         if (!uctl)
208                 return;
209         val = snd_hda_codec_read(codec, jack->nid, 0,
210                                  AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
211         val &= HDA_AMP_VOLMASK;
212         uctl->value.integer.value[0] = val;
213         uctl->value.integer.value[1] = val;
214         kctl->put(kctl, uctl);
215         kfree(uctl);
216 }
217
218 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
219 {
220         /* For some reason, the res given from ALC880 is broken.
221            Here we adjust it properly. */
222         snd_hda_jack_unsol_event(codec, res >> 2);
223 }
224
225 /* additional initialization for ALC888 variants */
226 static void alc888_coef_init(struct hda_codec *codec)
227 {
228         unsigned int tmp;
229
230         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
231         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
232         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
233         if ((tmp & 0xf0) == 0x20)
234                 /* alc888S-VC */
235                 snd_hda_codec_read(codec, 0x20, 0,
236                                    AC_VERB_SET_PROC_COEF, 0x830);
237          else
238                  /* alc888-VB */
239                  snd_hda_codec_read(codec, 0x20, 0,
240                                     AC_VERB_SET_PROC_COEF, 0x3030);
241 }
242
243 /* additional initialization for ALC889 variants */
244 static void alc889_coef_init(struct hda_codec *codec)
245 {
246         unsigned int tmp;
247
248         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
249         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
250         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
251         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
252 }
253
254 /* turn on/off EAPD control (only if available) */
255 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
256 {
257         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
258                 return;
259         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
260                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
261                                     on ? 2 : 0);
262 }
263
264 /* turn on/off EAPD controls of the codec */
265 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
266 {
267         /* We currently only handle front, HP */
268         static hda_nid_t pins[] = {
269                 0x0f, 0x10, 0x14, 0x15, 0x17, 0
270         };
271         hda_nid_t *p;
272         for (p = pins; *p; p++)
273                 set_eapd(codec, *p, on);
274 }
275
276 /* generic shutup callback;
277  * just turning off EPAD and a little pause for avoiding pop-noise
278  */
279 static void alc_eapd_shutup(struct hda_codec *codec)
280 {
281         alc_auto_setup_eapd(codec, false);
282         msleep(200);
283 }
284
285 /* generic EAPD initialization */
286 static void alc_auto_init_amp(struct hda_codec *codec, int type)
287 {
288         unsigned int tmp;
289
290         alc_auto_setup_eapd(codec, true);
291         switch (type) {
292         case ALC_INIT_GPIO1:
293                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
294                 break;
295         case ALC_INIT_GPIO2:
296                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
297                 break;
298         case ALC_INIT_GPIO3:
299                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
300                 break;
301         case ALC_INIT_DEFAULT:
302                 switch (codec->vendor_id) {
303                 case 0x10ec0260:
304                         snd_hda_codec_write(codec, 0x1a, 0,
305                                             AC_VERB_SET_COEF_INDEX, 7);
306                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
307                                                  AC_VERB_GET_PROC_COEF, 0);
308                         snd_hda_codec_write(codec, 0x1a, 0,
309                                             AC_VERB_SET_COEF_INDEX, 7);
310                         snd_hda_codec_write(codec, 0x1a, 0,
311                                             AC_VERB_SET_PROC_COEF,
312                                             tmp | 0x2010);
313                         break;
314                 case 0x10ec0262:
315                 case 0x10ec0880:
316                 case 0x10ec0882:
317                 case 0x10ec0883:
318                 case 0x10ec0885:
319                 case 0x10ec0887:
320                 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
321                 case 0x10ec0900:
322                         alc889_coef_init(codec);
323                         break;
324                 case 0x10ec0888:
325                         alc888_coef_init(codec);
326                         break;
327 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
328                 case 0x10ec0267:
329                 case 0x10ec0268:
330                         snd_hda_codec_write(codec, 0x20, 0,
331                                             AC_VERB_SET_COEF_INDEX, 7);
332                         tmp = snd_hda_codec_read(codec, 0x20, 0,
333                                                  AC_VERB_GET_PROC_COEF, 0);
334                         snd_hda_codec_write(codec, 0x20, 0,
335                                             AC_VERB_SET_COEF_INDEX, 7);
336                         snd_hda_codec_write(codec, 0x20, 0,
337                                             AC_VERB_SET_PROC_COEF,
338                                             tmp | 0x3000);
339                         break;
340 #endif /* XXX */
341                 }
342                 break;
343         }
344 }
345
346
347 /*
348  * Realtek SSID verification
349  */
350
351 /* Could be any non-zero and even value. When used as fixup, tells
352  * the driver to ignore any present sku defines.
353  */
354 #define ALC_FIXUP_SKU_IGNORE (2)
355
356 static void alc_fixup_sku_ignore(struct hda_codec *codec,
357                                  const struct hda_fixup *fix, int action)
358 {
359         struct alc_spec *spec = codec->spec;
360         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
361                 spec->cdefine.fixup = 1;
362                 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
363         }
364 }
365
366 static int alc_auto_parse_customize_define(struct hda_codec *codec)
367 {
368         unsigned int ass, tmp, i;
369         unsigned nid = 0;
370         struct alc_spec *spec = codec->spec;
371
372         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
373
374         if (spec->cdefine.fixup) {
375                 ass = spec->cdefine.sku_cfg;
376                 if (ass == ALC_FIXUP_SKU_IGNORE)
377                         return -1;
378                 goto do_sku;
379         }
380
381         ass = codec->subsystem_id & 0xffff;
382         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
383                 goto do_sku;
384
385         nid = 0x1d;
386         if (codec->vendor_id == 0x10ec0260)
387                 nid = 0x17;
388         ass = snd_hda_codec_get_pincfg(codec, nid);
389
390         if (!(ass & 1)) {
391                 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
392                        codec->chip_name, ass);
393                 return -1;
394         }
395
396         /* check sum */
397         tmp = 0;
398         for (i = 1; i < 16; i++) {
399                 if ((ass >> i) & 1)
400                         tmp++;
401         }
402         if (((ass >> 16) & 0xf) != tmp)
403                 return -1;
404
405         spec->cdefine.port_connectivity = ass >> 30;
406         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
407         spec->cdefine.check_sum = (ass >> 16) & 0xf;
408         spec->cdefine.customization = ass >> 8;
409 do_sku:
410         spec->cdefine.sku_cfg = ass;
411         spec->cdefine.external_amp = (ass & 0x38) >> 3;
412         spec->cdefine.platform_type = (ass & 0x4) >> 2;
413         spec->cdefine.swap = (ass & 0x2) >> 1;
414         spec->cdefine.override = ass & 0x1;
415
416         snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
417                    nid, spec->cdefine.sku_cfg);
418         snd_printd("SKU: port_connectivity=0x%x\n",
419                    spec->cdefine.port_connectivity);
420         snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
421         snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
422         snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
423         snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
424         snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
425         snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
426         snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
427
428         return 0;
429 }
430
431 /* return the position of NID in the list, or -1 if not found */
432 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
433 {
434         int i;
435         for (i = 0; i < nums; i++)
436                 if (list[i] == nid)
437                         return i;
438         return -1;
439 }
440 /* return true if the given NID is found in the list */
441 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
442 {
443         return find_idx_in_nid_list(nid, list, nums) >= 0;
444 }
445
446 /* check subsystem ID and set up device-specific initialization;
447  * return 1 if initialized, 0 if invalid SSID
448  */
449 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
450  *      31 ~ 16 :       Manufacture ID
451  *      15 ~ 8  :       SKU ID
452  *      7  ~ 0  :       Assembly ID
453  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
454  */
455 static int alc_subsystem_id(struct hda_codec *codec,
456                             hda_nid_t porta, hda_nid_t porte,
457                             hda_nid_t portd, hda_nid_t porti)
458 {
459         unsigned int ass, tmp, i;
460         unsigned nid;
461         struct alc_spec *spec = codec->spec;
462
463         if (spec->cdefine.fixup) {
464                 ass = spec->cdefine.sku_cfg;
465                 if (ass == ALC_FIXUP_SKU_IGNORE)
466                         return 0;
467                 goto do_sku;
468         }
469
470         ass = codec->subsystem_id & 0xffff;
471         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
472                 goto do_sku;
473
474         /* invalid SSID, check the special NID pin defcfg instead */
475         /*
476          * 31~30        : port connectivity
477          * 29~21        : reserve
478          * 20           : PCBEEP input
479          * 19~16        : Check sum (15:1)
480          * 15~1         : Custom
481          * 0            : override
482         */
483         nid = 0x1d;
484         if (codec->vendor_id == 0x10ec0260)
485                 nid = 0x17;
486         ass = snd_hda_codec_get_pincfg(codec, nid);
487         snd_printd("realtek: No valid SSID, "
488                    "checking pincfg 0x%08x for NID 0x%x\n",
489                    ass, nid);
490         if (!(ass & 1))
491                 return 0;
492         if ((ass >> 30) != 1)   /* no physical connection */
493                 return 0;
494
495         /* check sum */
496         tmp = 0;
497         for (i = 1; i < 16; i++) {
498                 if ((ass >> i) & 1)
499                         tmp++;
500         }
501         if (((ass >> 16) & 0xf) != tmp)
502                 return 0;
503 do_sku:
504         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
505                    ass & 0xffff, codec->vendor_id);
506         /*
507          * 0 : override
508          * 1 :  Swap Jack
509          * 2 : 0 --> Desktop, 1 --> Laptop
510          * 3~5 : External Amplifier control
511          * 7~6 : Reserved
512         */
513         tmp = (ass & 0x38) >> 3;        /* external Amp control */
514         switch (tmp) {
515         case 1:
516                 spec->init_amp = ALC_INIT_GPIO1;
517                 break;
518         case 3:
519                 spec->init_amp = ALC_INIT_GPIO2;
520                 break;
521         case 7:
522                 spec->init_amp = ALC_INIT_GPIO3;
523                 break;
524         case 5:
525         default:
526                 spec->init_amp = ALC_INIT_DEFAULT;
527                 break;
528         }
529
530         /* is laptop or Desktop and enable the function "Mute internal speaker
531          * when the external headphone out jack is plugged"
532          */
533         if (!(ass & 0x8000))
534                 return 1;
535         /*
536          * 10~8 : Jack location
537          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
538          * 14~13: Resvered
539          * 15   : 1 --> enable the function "Mute internal speaker
540          *              when the external headphone out jack is plugged"
541          */
542         if (!spec->gen.autocfg.hp_pins[0] &&
543             !(spec->gen.autocfg.line_out_pins[0] &&
544               spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
545                 hda_nid_t nid;
546                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
547                 if (tmp == 0)
548                         nid = porta;
549                 else if (tmp == 1)
550                         nid = porte;
551                 else if (tmp == 2)
552                         nid = portd;
553                 else if (tmp == 3)
554                         nid = porti;
555                 else
556                         return 1;
557                 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
558                                       spec->gen.autocfg.line_outs))
559                         return 1;
560                 spec->gen.autocfg.hp_pins[0] = nid;
561         }
562         return 1;
563 }
564
565 /* Check the validity of ALC subsystem-id
566  * ports contains an array of 4 pin NIDs for port-A, E, D and I */
567 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
568 {
569         if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
570                 struct alc_spec *spec = codec->spec;
571                 snd_printd("realtek: "
572                            "Enable default setup for auto mode as fallback\n");
573                 spec->init_amp = ALC_INIT_DEFAULT;
574         }
575 }
576
577 /*
578  * COEF access helper functions
579  */
580 static int alc_read_coef_idx(struct hda_codec *codec,
581                         unsigned int coef_idx)
582 {
583         unsigned int val;
584         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
585                                 coef_idx);
586         val = snd_hda_codec_read(codec, 0x20, 0,
587                                 AC_VERB_GET_PROC_COEF, 0);
588         return val;
589 }
590
591 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
592                                                         unsigned int coef_val)
593 {
594         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
595                             coef_idx);
596         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
597                             coef_val);
598 }
599
600 /* a special bypass for COEF 0; read the cached value at the second time */
601 static unsigned int alc_get_coef0(struct hda_codec *codec)
602 {
603         struct alc_spec *spec = codec->spec;
604         if (!spec->coef0)
605                 spec->coef0 = alc_read_coef_idx(codec, 0);
606         return spec->coef0;
607 }
608
609 /*
610  */
611
612 static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
613 {
614         struct hda_gen_spec *spec = codec->spec;
615         if (spec->dyn_adc_switch)
616                 adc_idx = spec->dyn_adc_idx[imux_idx];
617         return spec->adc_nids[adc_idx];
618 }
619
620 static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
621 {
622         struct alc_spec *spec = codec->spec;
623         struct hda_input_mux *imux = &spec->gen.input_mux;
624         struct nid_path *path;
625         hda_nid_t nid;
626         int i, dir, parm;
627         unsigned int val;
628
629         for (i = 0; i < imux->num_items; i++) {
630                 if (spec->gen.imux_pins[i] == spec->inv_dmic_pin)
631                         break;
632         }
633         if (i >= imux->num_items)
634                 return;
635
636         path = snd_hda_get_nid_path(codec, spec->inv_dmic_pin,
637                                     get_adc_nid(codec, adc_idx, i));
638         val = path->ctls[NID_PATH_MUTE_CTL];
639         if (!val)
640                 return;
641         nid = get_amp_nid_(val);
642         dir = get_amp_direction_(val);
643         parm = AC_AMP_SET_RIGHT |
644                 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
645
646         /* flush all cached amps at first */
647         snd_hda_codec_flush_cache(codec);
648
649         /* we care only right channel */
650         val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
651         if (val & 0x80) /* if already muted, we don't need to touch */
652                 return;
653         val |= 0x80;
654         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
655                             parm | val);
656 }
657
658 /*
659  * Inverted digital-mic handling
660  *
661  * First off, it's a bit tricky.  The "Inverted Internal Mic Capture Switch"
662  * gives the additional mute only to the right channel of the digital mic
663  * capture stream.  This is a workaround for avoiding the almost silence
664  * by summing the stereo stream from some (known to be ForteMedia)
665  * digital mic unit.
666  *
667  * The logic is to call alc_inv_dmic_sync() after each action (possibly)
668  * modifying ADC amp.  When the mute flag is set, it mutes the R-channel
669  * without caching so that the cache can still keep the original value.
670  * The cached value is then restored when the flag is set off or any other
671  * than d-mic is used as the current input source.
672  */
673 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
674 {
675         struct alc_spec *spec = codec->spec;
676         int src, nums;
677
678         if (!spec->inv_dmic_fixup)
679                 return;
680         if (!spec->inv_dmic_muted && !force)
681                 return;
682         nums = spec->gen.dyn_adc_switch ? 1 : spec->gen.num_adc_nids;
683         for (src = 0; src < nums; src++) {
684                 bool dmic_fixup = false;
685
686                 if (spec->inv_dmic_muted &&
687                     spec->gen.imux_pins[spec->gen.cur_mux[src]] == spec->inv_dmic_pin)
688                         dmic_fixup = true;
689                 if (!dmic_fixup && !force)
690                         continue;
691                 alc_inv_dmic_sync_adc(codec, src);
692         }
693 }
694
695 static void alc_inv_dmic_hook(struct hda_codec *codec,
696                              struct snd_ctl_elem_value *ucontrol)
697 {
698         alc_inv_dmic_sync(codec, false);
699 }
700
701 static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
702                                struct snd_ctl_elem_value *ucontrol)
703 {
704         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
705         struct alc_spec *spec = codec->spec;
706
707         ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
708         return 0;
709 }
710
711 static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
712                                struct snd_ctl_elem_value *ucontrol)
713 {
714         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715         struct alc_spec *spec = codec->spec;
716         unsigned int val = !ucontrol->value.integer.value[0];
717
718         if (val == spec->inv_dmic_muted)
719                 return 0;
720         spec->inv_dmic_muted = val;
721         alc_inv_dmic_sync(codec, true);
722         return 0;
723 }
724
725 static const struct snd_kcontrol_new alc_inv_dmic_sw = {
726         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
727         .name = "Inverted Internal Mic Capture Switch",
728         .info = snd_ctl_boolean_mono_info,
729         .get = alc_inv_dmic_sw_get,
730         .put = alc_inv_dmic_sw_put,
731 };
732
733 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
734 {
735         struct alc_spec *spec = codec->spec;
736
737         if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &alc_inv_dmic_sw))
738                 return -ENOMEM;
739         spec->inv_dmic_fixup = 1;
740         spec->inv_dmic_muted = 0;
741         spec->inv_dmic_pin = nid;
742         spec->gen.cap_sync_hook = alc_inv_dmic_hook;
743         return 0;
744 }
745
746 /* typically the digital mic is put at node 0x12 */
747 static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
748                                     const struct hda_fixup *fix, int action)
749 {
750         if (action == HDA_FIXUP_ACT_PROBE)
751                 alc_add_inv_dmic_mixer(codec, 0x12);
752 }
753
754
755 #ifdef CONFIG_SND_HDA_INPUT_BEEP
756 /* additional beep mixers; the actual parameters are overwritten at build */
757 static const struct snd_kcontrol_new alc_beep_mixer[] = {
758         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
759         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
760         { } /* end */
761 };
762 #endif
763
764 static int alc_build_controls(struct hda_codec *codec)
765 {
766         struct alc_spec *spec = codec->spec;
767         int i, err;
768
769         err = snd_hda_gen_build_controls(codec);
770         if (err < 0)
771                 return err;
772
773         for (i = 0; i < spec->num_mixers; i++) {
774                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
775                 if (err < 0)
776                         return err;
777         }
778
779 #ifdef CONFIG_SND_HDA_INPUT_BEEP
780         /* create beep controls if needed */
781         if (spec->beep_amp) {
782                 const struct snd_kcontrol_new *knew;
783                 for (knew = alc_beep_mixer; knew->name; knew++) {
784                         struct snd_kcontrol *kctl;
785                         kctl = snd_ctl_new1(knew, codec);
786                         if (!kctl)
787                                 return -ENOMEM;
788                         kctl->private_value = spec->beep_amp;
789                         err = snd_hda_ctl_add(codec, 0, kctl);
790                         if (err < 0)
791                                 return err;
792                 }
793         }
794 #endif
795
796         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
797         return 0;
798 }
799
800
801 /*
802  * Common callbacks
803  */
804
805 static int alc_init(struct hda_codec *codec)
806 {
807         struct alc_spec *spec = codec->spec;
808
809         if (spec->init_hook)
810                 spec->init_hook(codec);
811
812         alc_fix_pll(codec);
813         alc_auto_init_amp(codec, spec->init_amp);
814
815         snd_hda_gen_init(codec);
816
817         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
818
819         return 0;
820 }
821
822 static inline void alc_shutup(struct hda_codec *codec)
823 {
824         struct alc_spec *spec = codec->spec;
825
826         if (spec && spec->shutup)
827                 spec->shutup(codec);
828         snd_hda_shutup_pins(codec);
829 }
830
831 #define alc_free        snd_hda_gen_free
832
833 #ifdef CONFIG_PM
834 static void alc_power_eapd(struct hda_codec *codec)
835 {
836         alc_auto_setup_eapd(codec, false);
837 }
838
839 static int alc_suspend(struct hda_codec *codec)
840 {
841         struct alc_spec *spec = codec->spec;
842         alc_shutup(codec);
843         if (spec && spec->power_hook)
844                 spec->power_hook(codec);
845         return 0;
846 }
847 #endif
848
849 #ifdef CONFIG_PM
850 static int alc_resume(struct hda_codec *codec)
851 {
852         msleep(150); /* to avoid pop noise */
853         codec->patch_ops.init(codec);
854         snd_hda_codec_resume_amp(codec);
855         snd_hda_codec_resume_cache(codec);
856         alc_inv_dmic_sync(codec, true);
857         hda_call_check_power_status(codec, 0x01);
858         return 0;
859 }
860 #endif
861
862 /*
863  */
864 static const struct hda_codec_ops alc_patch_ops = {
865         .build_controls = alc_build_controls,
866         .build_pcms = snd_hda_gen_build_pcms,
867         .init = alc_init,
868         .free = alc_free,
869         .unsol_event = snd_hda_jack_unsol_event,
870 #ifdef CONFIG_PM
871         .resume = alc_resume,
872         .suspend = alc_suspend,
873         .check_power_status = snd_hda_gen_check_power_status,
874 #endif
875         .reboot_notify = alc_shutup,
876 };
877
878
879 /* replace the codec chip_name with the given string */
880 static int alc_codec_rename(struct hda_codec *codec, const char *name)
881 {
882         kfree(codec->chip_name);
883         codec->chip_name = kstrdup(name, GFP_KERNEL);
884         if (!codec->chip_name) {
885                 alc_free(codec);
886                 return -ENOMEM;
887         }
888         return 0;
889 }
890
891 /*
892  * Rename codecs appropriately from COEF value
893  */
894 struct alc_codec_rename_table {
895         unsigned int vendor_id;
896         unsigned short coef_mask;
897         unsigned short coef_bits;
898         const char *name;
899 };
900
901 static struct alc_codec_rename_table rename_tbl[] = {
902         { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
903         { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
904         { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
905         { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
906         { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
907         { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
908         { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
909         { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
910         { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
911         { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
912         { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
913         { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
914         { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
915         { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
916         { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
917         { } /* terminator */
918 };
919
920 static int alc_codec_rename_from_preset(struct hda_codec *codec)
921 {
922         const struct alc_codec_rename_table *p;
923
924         for (p = rename_tbl; p->vendor_id; p++) {
925                 if (p->vendor_id != codec->vendor_id)
926                         continue;
927                 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
928                         return alc_codec_rename(codec, p->name);
929         }
930         return 0;
931 }
932
933
934 /*
935  * Digital-beep handlers
936  */
937 #ifdef CONFIG_SND_HDA_INPUT_BEEP
938 #define set_beep_amp(spec, nid, idx, dir) \
939         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
940
941 static const struct snd_pci_quirk beep_white_list[] = {
942         SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
943         SND_PCI_QUIRK(0x1043, 0x115d, "ASUS", 1),
944         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
945         SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1),
946         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
947         SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
948         SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
949         SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
950         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
951         {}
952 };
953
954 static inline int has_cdefine_beep(struct hda_codec *codec)
955 {
956         struct alc_spec *spec = codec->spec;
957         const struct snd_pci_quirk *q;
958         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
959         if (q)
960                 return q->value;
961         return spec->cdefine.enable_pcbeep;
962 }
963 #else
964 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
965 #define has_cdefine_beep(codec)         0
966 #endif
967
968 /* parse the BIOS configuration and set up the alc_spec */
969 /* return 1 if successful, 0 if the proper config is not found,
970  * or a negative error code
971  */
972 static int alc_parse_auto_config(struct hda_codec *codec,
973                                  const hda_nid_t *ignore_nids,
974                                  const hda_nid_t *ssid_nids)
975 {
976         struct alc_spec *spec = codec->spec;
977         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
978         int err;
979
980         err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
981                                        spec->parse_flags);
982         if (err < 0)
983                 return err;
984
985         if (ssid_nids)
986                 alc_ssid_check(codec, ssid_nids);
987
988         err = snd_hda_gen_parse_auto_config(codec, cfg);
989         if (err < 0)
990                 return err;
991
992         return 1;
993 }
994
995 /* common preparation job for alc_spec */
996 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
997 {
998         struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
999         int err;
1000
1001         if (!spec)
1002                 return -ENOMEM;
1003         codec->spec = spec;
1004         snd_hda_gen_spec_init(&spec->gen);
1005         spec->gen.mixer_nid = mixer_nid;
1006         spec->gen.own_eapd_ctl = 1;
1007         codec->single_adc_amp = 1;
1008         /* FIXME: do we need this for all Realtek codec models? */
1009         codec->spdif_status_reset = 1;
1010
1011         err = alc_codec_rename_from_preset(codec);
1012         if (err < 0) {
1013                 kfree(spec);
1014                 return err;
1015         }
1016         return 0;
1017 }
1018
1019 static int alc880_parse_auto_config(struct hda_codec *codec)
1020 {
1021         static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
1022         static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
1023         return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
1024 }
1025
1026 /*
1027  * ALC880 fix-ups
1028  */
1029 enum {
1030         ALC880_FIXUP_GPIO1,
1031         ALC880_FIXUP_GPIO2,
1032         ALC880_FIXUP_MEDION_RIM,
1033         ALC880_FIXUP_LG,
1034         ALC880_FIXUP_LG_LW25,
1035         ALC880_FIXUP_W810,
1036         ALC880_FIXUP_EAPD_COEF,
1037         ALC880_FIXUP_TCL_S700,
1038         ALC880_FIXUP_VOL_KNOB,
1039         ALC880_FIXUP_FUJITSU,
1040         ALC880_FIXUP_F1734,
1041         ALC880_FIXUP_UNIWILL,
1042         ALC880_FIXUP_UNIWILL_DIG,
1043         ALC880_FIXUP_Z71V,
1044         ALC880_FIXUP_ASUS_W5A,
1045         ALC880_FIXUP_3ST_BASE,
1046         ALC880_FIXUP_3ST,
1047         ALC880_FIXUP_3ST_DIG,
1048         ALC880_FIXUP_5ST_BASE,
1049         ALC880_FIXUP_5ST,
1050         ALC880_FIXUP_5ST_DIG,
1051         ALC880_FIXUP_6ST_BASE,
1052         ALC880_FIXUP_6ST,
1053         ALC880_FIXUP_6ST_DIG,
1054         ALC880_FIXUP_6ST_AUTOMUTE,
1055 };
1056
1057 /* enable the volume-knob widget support on NID 0x21 */
1058 static void alc880_fixup_vol_knob(struct hda_codec *codec,
1059                                   const struct hda_fixup *fix, int action)
1060 {
1061         if (action == HDA_FIXUP_ACT_PROBE)
1062                 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
1063 }
1064
1065 static const struct hda_fixup alc880_fixups[] = {
1066         [ALC880_FIXUP_GPIO1] = {
1067                 .type = HDA_FIXUP_VERBS,
1068                 .v.verbs = alc_gpio1_init_verbs,
1069         },
1070         [ALC880_FIXUP_GPIO2] = {
1071                 .type = HDA_FIXUP_VERBS,
1072                 .v.verbs = alc_gpio2_init_verbs,
1073         },
1074         [ALC880_FIXUP_MEDION_RIM] = {
1075                 .type = HDA_FIXUP_VERBS,
1076                 .v.verbs = (const struct hda_verb[]) {
1077                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1078                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1079                         { }
1080                 },
1081                 .chained = true,
1082                 .chain_id = ALC880_FIXUP_GPIO2,
1083         },
1084         [ALC880_FIXUP_LG] = {
1085                 .type = HDA_FIXUP_PINS,
1086                 .v.pins = (const struct hda_pintbl[]) {
1087                         /* disable bogus unused pins */
1088                         { 0x16, 0x411111f0 },
1089                         { 0x18, 0x411111f0 },
1090                         { 0x1a, 0x411111f0 },
1091                         { }
1092                 }
1093         },
1094         [ALC880_FIXUP_LG_LW25] = {
1095                 .type = HDA_FIXUP_PINS,
1096                 .v.pins = (const struct hda_pintbl[]) {
1097                         { 0x1a, 0x0181344f }, /* line-in */
1098                         { 0x1b, 0x0321403f }, /* headphone */
1099                         { }
1100                 }
1101         },
1102         [ALC880_FIXUP_W810] = {
1103                 .type = HDA_FIXUP_PINS,
1104                 .v.pins = (const struct hda_pintbl[]) {
1105                         /* disable bogus unused pins */
1106                         { 0x17, 0x411111f0 },
1107                         { }
1108                 },
1109                 .chained = true,
1110                 .chain_id = ALC880_FIXUP_GPIO2,
1111         },
1112         [ALC880_FIXUP_EAPD_COEF] = {
1113                 .type = HDA_FIXUP_VERBS,
1114                 .v.verbs = (const struct hda_verb[]) {
1115                         /* change to EAPD mode */
1116                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1117                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1118                         {}
1119                 },
1120         },
1121         [ALC880_FIXUP_TCL_S700] = {
1122                 .type = HDA_FIXUP_VERBS,
1123                 .v.verbs = (const struct hda_verb[]) {
1124                         /* change to EAPD mode */
1125                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1126                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3070 },
1127                         {}
1128                 },
1129                 .chained = true,
1130                 .chain_id = ALC880_FIXUP_GPIO2,
1131         },
1132         [ALC880_FIXUP_VOL_KNOB] = {
1133                 .type = HDA_FIXUP_FUNC,
1134                 .v.func = alc880_fixup_vol_knob,
1135         },
1136         [ALC880_FIXUP_FUJITSU] = {
1137                 /* override all pins as BIOS on old Amilo is broken */
1138                 .type = HDA_FIXUP_PINS,
1139                 .v.pins = (const struct hda_pintbl[]) {
1140                         { 0x14, 0x0121401f }, /* HP */
1141                         { 0x15, 0x99030120 }, /* speaker */
1142                         { 0x16, 0x99030130 }, /* bass speaker */
1143                         { 0x17, 0x411111f0 }, /* N/A */
1144                         { 0x18, 0x411111f0 }, /* N/A */
1145                         { 0x19, 0x01a19950 }, /* mic-in */
1146                         { 0x1a, 0x411111f0 }, /* N/A */
1147                         { 0x1b, 0x411111f0 }, /* N/A */
1148                         { 0x1c, 0x411111f0 }, /* N/A */
1149                         { 0x1d, 0x411111f0 }, /* N/A */
1150                         { 0x1e, 0x01454140 }, /* SPDIF out */
1151                         { }
1152                 },
1153                 .chained = true,
1154                 .chain_id = ALC880_FIXUP_VOL_KNOB,
1155         },
1156         [ALC880_FIXUP_F1734] = {
1157                 /* almost compatible with FUJITSU, but no bass and SPDIF */
1158                 .type = HDA_FIXUP_PINS,
1159                 .v.pins = (const struct hda_pintbl[]) {
1160                         { 0x14, 0x0121401f }, /* HP */
1161                         { 0x15, 0x99030120 }, /* speaker */
1162                         { 0x16, 0x411111f0 }, /* N/A */
1163                         { 0x17, 0x411111f0 }, /* N/A */
1164                         { 0x18, 0x411111f0 }, /* N/A */
1165                         { 0x19, 0x01a19950 }, /* mic-in */
1166                         { 0x1a, 0x411111f0 }, /* N/A */
1167                         { 0x1b, 0x411111f0 }, /* N/A */
1168                         { 0x1c, 0x411111f0 }, /* N/A */
1169                         { 0x1d, 0x411111f0 }, /* N/A */
1170                         { 0x1e, 0x411111f0 }, /* N/A */
1171                         { }
1172                 },
1173                 .chained = true,
1174                 .chain_id = ALC880_FIXUP_VOL_KNOB,
1175         },
1176         [ALC880_FIXUP_UNIWILL] = {
1177                 /* need to fix HP and speaker pins to be parsed correctly */
1178                 .type = HDA_FIXUP_PINS,
1179                 .v.pins = (const struct hda_pintbl[]) {
1180                         { 0x14, 0x0121411f }, /* HP */
1181                         { 0x15, 0x99030120 }, /* speaker */
1182                         { 0x16, 0x99030130 }, /* bass speaker */
1183                         { }
1184                 },
1185         },
1186         [ALC880_FIXUP_UNIWILL_DIG] = {
1187                 .type = HDA_FIXUP_PINS,
1188                 .v.pins = (const struct hda_pintbl[]) {
1189                         /* disable bogus unused pins */
1190                         { 0x17, 0x411111f0 },
1191                         { 0x19, 0x411111f0 },
1192                         { 0x1b, 0x411111f0 },
1193                         { 0x1f, 0x411111f0 },
1194                         { }
1195                 }
1196         },
1197         [ALC880_FIXUP_Z71V] = {
1198                 .type = HDA_FIXUP_PINS,
1199                 .v.pins = (const struct hda_pintbl[]) {
1200                         /* set up the whole pins as BIOS is utterly broken */
1201                         { 0x14, 0x99030120 }, /* speaker */
1202                         { 0x15, 0x0121411f }, /* HP */
1203                         { 0x16, 0x411111f0 }, /* N/A */
1204                         { 0x17, 0x411111f0 }, /* N/A */
1205                         { 0x18, 0x01a19950 }, /* mic-in */
1206                         { 0x19, 0x411111f0 }, /* N/A */
1207                         { 0x1a, 0x01813031 }, /* line-in */
1208                         { 0x1b, 0x411111f0 }, /* N/A */
1209                         { 0x1c, 0x411111f0 }, /* N/A */
1210                         { 0x1d, 0x411111f0 }, /* N/A */
1211                         { 0x1e, 0x0144111e }, /* SPDIF */
1212                         { }
1213                 }
1214         },
1215         [ALC880_FIXUP_ASUS_W5A] = {
1216                 .type = HDA_FIXUP_PINS,
1217                 .v.pins = (const struct hda_pintbl[]) {
1218                         /* set up the whole pins as BIOS is utterly broken */
1219                         { 0x14, 0x0121411f }, /* HP */
1220                         { 0x15, 0x411111f0 }, /* N/A */
1221                         { 0x16, 0x411111f0 }, /* N/A */
1222                         { 0x17, 0x411111f0 }, /* N/A */
1223                         { 0x18, 0x90a60160 }, /* mic */
1224                         { 0x19, 0x411111f0 }, /* N/A */
1225                         { 0x1a, 0x411111f0 }, /* N/A */
1226                         { 0x1b, 0x411111f0 }, /* N/A */
1227                         { 0x1c, 0x411111f0 }, /* N/A */
1228                         { 0x1d, 0x411111f0 }, /* N/A */
1229                         { 0x1e, 0xb743111e }, /* SPDIF out */
1230                         { }
1231                 },
1232                 .chained = true,
1233                 .chain_id = ALC880_FIXUP_GPIO1,
1234         },
1235         [ALC880_FIXUP_3ST_BASE] = {
1236                 .type = HDA_FIXUP_PINS,
1237                 .v.pins = (const struct hda_pintbl[]) {
1238                         { 0x14, 0x01014010 }, /* line-out */
1239                         { 0x15, 0x411111f0 }, /* N/A */
1240                         { 0x16, 0x411111f0 }, /* N/A */
1241                         { 0x17, 0x411111f0 }, /* N/A */
1242                         { 0x18, 0x01a19c30 }, /* mic-in */
1243                         { 0x19, 0x0121411f }, /* HP */
1244                         { 0x1a, 0x01813031 }, /* line-in */
1245                         { 0x1b, 0x02a19c40 }, /* front-mic */
1246                         { 0x1c, 0x411111f0 }, /* N/A */
1247                         { 0x1d, 0x411111f0 }, /* N/A */
1248                         /* 0x1e is filled in below */
1249                         { 0x1f, 0x411111f0 }, /* N/A */
1250                         { }
1251                 }
1252         },
1253         [ALC880_FIXUP_3ST] = {
1254                 .type = HDA_FIXUP_PINS,
1255                 .v.pins = (const struct hda_pintbl[]) {
1256                         { 0x1e, 0x411111f0 }, /* N/A */
1257                         { }
1258                 },
1259                 .chained = true,
1260                 .chain_id = ALC880_FIXUP_3ST_BASE,
1261         },
1262         [ALC880_FIXUP_3ST_DIG] = {
1263                 .type = HDA_FIXUP_PINS,
1264                 .v.pins = (const struct hda_pintbl[]) {
1265                         { 0x1e, 0x0144111e }, /* SPDIF */
1266                         { }
1267                 },
1268                 .chained = true,
1269                 .chain_id = ALC880_FIXUP_3ST_BASE,
1270         },
1271         [ALC880_FIXUP_5ST_BASE] = {
1272                 .type = HDA_FIXUP_PINS,
1273                 .v.pins = (const struct hda_pintbl[]) {
1274                         { 0x14, 0x01014010 }, /* front */
1275                         { 0x15, 0x411111f0 }, /* N/A */
1276                         { 0x16, 0x01011411 }, /* CLFE */
1277                         { 0x17, 0x01016412 }, /* surr */
1278                         { 0x18, 0x01a19c30 }, /* mic-in */
1279                         { 0x19, 0x0121411f }, /* HP */
1280                         { 0x1a, 0x01813031 }, /* line-in */
1281                         { 0x1b, 0x02a19c40 }, /* front-mic */
1282                         { 0x1c, 0x411111f0 }, /* N/A */
1283                         { 0x1d, 0x411111f0 }, /* N/A */
1284                         /* 0x1e is filled in below */
1285                         { 0x1f, 0x411111f0 }, /* N/A */
1286                         { }
1287                 }
1288         },
1289         [ALC880_FIXUP_5ST] = {
1290                 .type = HDA_FIXUP_PINS,
1291                 .v.pins = (const struct hda_pintbl[]) {
1292                         { 0x1e, 0x411111f0 }, /* N/A */
1293                         { }
1294                 },
1295                 .chained = true,
1296                 .chain_id = ALC880_FIXUP_5ST_BASE,
1297         },
1298         [ALC880_FIXUP_5ST_DIG] = {
1299                 .type = HDA_FIXUP_PINS,
1300                 .v.pins = (const struct hda_pintbl[]) {
1301                         { 0x1e, 0x0144111e }, /* SPDIF */
1302                         { }
1303                 },
1304                 .chained = true,
1305                 .chain_id = ALC880_FIXUP_5ST_BASE,
1306         },
1307         [ALC880_FIXUP_6ST_BASE] = {
1308                 .type = HDA_FIXUP_PINS,
1309                 .v.pins = (const struct hda_pintbl[]) {
1310                         { 0x14, 0x01014010 }, /* front */
1311                         { 0x15, 0x01016412 }, /* surr */
1312                         { 0x16, 0x01011411 }, /* CLFE */
1313                         { 0x17, 0x01012414 }, /* side */
1314                         { 0x18, 0x01a19c30 }, /* mic-in */
1315                         { 0x19, 0x02a19c40 }, /* front-mic */
1316                         { 0x1a, 0x01813031 }, /* line-in */
1317                         { 0x1b, 0x0121411f }, /* HP */
1318                         { 0x1c, 0x411111f0 }, /* N/A */
1319                         { 0x1d, 0x411111f0 }, /* N/A */
1320                         /* 0x1e is filled in below */
1321                         { 0x1f, 0x411111f0 }, /* N/A */
1322                         { }
1323                 }
1324         },
1325         [ALC880_FIXUP_6ST] = {
1326                 .type = HDA_FIXUP_PINS,
1327                 .v.pins = (const struct hda_pintbl[]) {
1328                         { 0x1e, 0x411111f0 }, /* N/A */
1329                         { }
1330                 },
1331                 .chained = true,
1332                 .chain_id = ALC880_FIXUP_6ST_BASE,
1333         },
1334         [ALC880_FIXUP_6ST_DIG] = {
1335                 .type = HDA_FIXUP_PINS,
1336                 .v.pins = (const struct hda_pintbl[]) {
1337                         { 0x1e, 0x0144111e }, /* SPDIF */
1338                         { }
1339                 },
1340                 .chained = true,
1341                 .chain_id = ALC880_FIXUP_6ST_BASE,
1342         },
1343         [ALC880_FIXUP_6ST_AUTOMUTE] = {
1344                 .type = HDA_FIXUP_PINS,
1345                 .v.pins = (const struct hda_pintbl[]) {
1346                         { 0x1b, 0x0121401f }, /* HP with jack detect */
1347                         { }
1348                 },
1349                 .chained_before = true,
1350                 .chain_id = ALC880_FIXUP_6ST_BASE,
1351         },
1352 };
1353
1354 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
1355         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
1356         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
1357         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
1358         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
1359         SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
1360         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
1361         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
1362         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
1363         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
1364         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
1365         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
1366         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
1367         SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
1368         SND_PCI_QUIRK(0x1734, 0x107c, "FSC Amilo M1437", ALC880_FIXUP_FUJITSU),
1369         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
1370         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
1371         SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
1372         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
1373         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
1374         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
1375         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_FIXUP_LG_LW25),
1376         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
1377
1378         /* Below is the copied entries from alc880_quirks.c.
1379          * It's not quite sure whether BIOS sets the correct pin-config table
1380          * on these machines, thus they are kept to be compatible with
1381          * the old static quirks.  Once when it's confirmed to work without
1382          * these overrides, it'd be better to remove.
1383          */
1384         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
1385         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
1386         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
1387         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
1388         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
1389         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
1390         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
1391         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
1392         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
1393         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
1394         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
1395         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
1396         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
1397         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
1398         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
1399         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
1400         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
1401         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
1402         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
1403         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
1404         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
1405         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
1406         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
1407         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1408         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1409         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1410         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1411         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1412         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1413         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1414         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1415         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1416         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1417         /* default Intel */
1418         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
1419         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
1420         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
1421         {}
1422 };
1423
1424 static const struct hda_model_fixup alc880_fixup_models[] = {
1425         {.id = ALC880_FIXUP_3ST, .name = "3stack"},
1426         {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
1427         {.id = ALC880_FIXUP_5ST, .name = "5stack"},
1428         {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
1429         {.id = ALC880_FIXUP_6ST, .name = "6stack"},
1430         {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
1431         {.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
1432         {}
1433 };
1434
1435
1436 /*
1437  * OK, here we have finally the patch for ALC880
1438  */
1439 static int patch_alc880(struct hda_codec *codec)
1440 {
1441         struct alc_spec *spec;
1442         int err;
1443
1444         err = alc_alloc_spec(codec, 0x0b);
1445         if (err < 0)
1446                 return err;
1447
1448         spec = codec->spec;
1449         spec->gen.need_dac_fix = 1;
1450         spec->gen.beep_nid = 0x01;
1451
1452         snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
1453                        alc880_fixups);
1454         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1455
1456         /* automatic parse from the BIOS config */
1457         err = alc880_parse_auto_config(codec);
1458         if (err < 0)
1459                 goto error;
1460
1461         if (!spec->gen.no_analog)
1462                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
1463
1464         codec->patch_ops = alc_patch_ops;
1465         codec->patch_ops.unsol_event = alc880_unsol_event;
1466
1467
1468         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1469
1470         return 0;
1471
1472  error:
1473         alc_free(codec);
1474         return err;
1475 }
1476
1477
1478 /*
1479  * ALC260 support
1480  */
1481 static int alc260_parse_auto_config(struct hda_codec *codec)
1482 {
1483         static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
1484         static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
1485         return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
1486 }
1487
1488 /*
1489  * Pin config fixes
1490  */
1491 enum {
1492         ALC260_FIXUP_HP_DC5750,
1493         ALC260_FIXUP_HP_PIN_0F,
1494         ALC260_FIXUP_COEF,
1495         ALC260_FIXUP_GPIO1,
1496         ALC260_FIXUP_GPIO1_TOGGLE,
1497         ALC260_FIXUP_REPLACER,
1498         ALC260_FIXUP_HP_B1900,
1499         ALC260_FIXUP_KN1,
1500         ALC260_FIXUP_FSC_S7020,
1501         ALC260_FIXUP_FSC_S7020_JWSE,
1502         ALC260_FIXUP_VAIO_PINS,
1503 };
1504
1505 static void alc260_gpio1_automute(struct hda_codec *codec)
1506 {
1507         struct alc_spec *spec = codec->spec;
1508         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1509                             spec->gen.hp_jack_present);
1510 }
1511
1512 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
1513                                       const struct hda_fixup *fix, int action)
1514 {
1515         struct alc_spec *spec = codec->spec;
1516         if (action == HDA_FIXUP_ACT_PROBE) {
1517                 /* although the machine has only one output pin, we need to
1518                  * toggle GPIO1 according to the jack state
1519                  */
1520                 spec->gen.automute_hook = alc260_gpio1_automute;
1521                 spec->gen.detect_hp = 1;
1522                 spec->gen.automute_speaker = 1;
1523                 spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
1524                 snd_hda_jack_detect_enable_callback(codec, 0x0f, HDA_GEN_HP_EVENT,
1525                                                     snd_hda_gen_hp_automute);
1526                 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
1527         }
1528 }
1529
1530 static void alc260_fixup_kn1(struct hda_codec *codec,
1531                              const struct hda_fixup *fix, int action)
1532 {
1533         struct alc_spec *spec = codec->spec;
1534         static const struct hda_pintbl pincfgs[] = {
1535                 { 0x0f, 0x02214000 }, /* HP/speaker */
1536                 { 0x12, 0x90a60160 }, /* int mic */
1537                 { 0x13, 0x02a19000 }, /* ext mic */
1538                 { 0x18, 0x01446000 }, /* SPDIF out */
1539                 /* disable bogus I/O pins */
1540                 { 0x10, 0x411111f0 },
1541                 { 0x11, 0x411111f0 },
1542                 { 0x14, 0x411111f0 },
1543                 { 0x15, 0x411111f0 },
1544                 { 0x16, 0x411111f0 },
1545                 { 0x17, 0x411111f0 },
1546                 { 0x19, 0x411111f0 },
1547                 { }
1548         };
1549
1550         switch (action) {
1551         case HDA_FIXUP_ACT_PRE_PROBE:
1552                 snd_hda_apply_pincfgs(codec, pincfgs);
1553                 break;
1554         case HDA_FIXUP_ACT_PROBE:
1555                 spec->init_amp = ALC_INIT_NONE;
1556                 break;
1557         }
1558 }
1559
1560 static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1561                                    const struct hda_fixup *fix, int action)
1562 {
1563         struct alc_spec *spec = codec->spec;
1564         if (action == HDA_FIXUP_ACT_PROBE)
1565                 spec->init_amp = ALC_INIT_NONE;
1566 }
1567
1568 static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
1569                                    const struct hda_fixup *fix, int action)
1570 {
1571         struct alc_spec *spec = codec->spec;
1572         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1573                 spec->gen.add_jack_modes = 1;
1574                 spec->gen.hp_mic = 1;
1575         }
1576 }
1577
1578 static const struct hda_fixup alc260_fixups[] = {
1579         [ALC260_FIXUP_HP_DC5750] = {
1580                 .type = HDA_FIXUP_PINS,
1581                 .v.pins = (const struct hda_pintbl[]) {
1582                         { 0x11, 0x90130110 }, /* speaker */
1583                         { }
1584                 }
1585         },
1586         [ALC260_FIXUP_HP_PIN_0F] = {
1587                 .type = HDA_FIXUP_PINS,
1588                 .v.pins = (const struct hda_pintbl[]) {
1589                         { 0x0f, 0x01214000 }, /* HP */
1590                         { }
1591                 }
1592         },
1593         [ALC260_FIXUP_COEF] = {
1594                 .type = HDA_FIXUP_VERBS,
1595                 .v.verbs = (const struct hda_verb[]) {
1596                         { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1597                         { 0x1a, AC_VERB_SET_PROC_COEF,  0x3040 },
1598                         { }
1599                 },
1600         },
1601         [ALC260_FIXUP_GPIO1] = {
1602                 .type = HDA_FIXUP_VERBS,
1603                 .v.verbs = alc_gpio1_init_verbs,
1604         },
1605         [ALC260_FIXUP_GPIO1_TOGGLE] = {
1606                 .type = HDA_FIXUP_FUNC,
1607                 .v.func = alc260_fixup_gpio1_toggle,
1608                 .chained = true,
1609                 .chain_id = ALC260_FIXUP_HP_PIN_0F,
1610         },
1611         [ALC260_FIXUP_REPLACER] = {
1612                 .type = HDA_FIXUP_VERBS,
1613                 .v.verbs = (const struct hda_verb[]) {
1614                         { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1615                         { 0x1a, AC_VERB_SET_PROC_COEF,  0x3050 },
1616                         { }
1617                 },
1618                 .chained = true,
1619                 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
1620         },
1621         [ALC260_FIXUP_HP_B1900] = {
1622                 .type = HDA_FIXUP_FUNC,
1623                 .v.func = alc260_fixup_gpio1_toggle,
1624                 .chained = true,
1625                 .chain_id = ALC260_FIXUP_COEF,
1626         },
1627         [ALC260_FIXUP_KN1] = {
1628                 .type = HDA_FIXUP_FUNC,
1629                 .v.func = alc260_fixup_kn1,
1630         },
1631         [ALC260_FIXUP_FSC_S7020] = {
1632                 .type = HDA_FIXUP_FUNC,
1633                 .v.func = alc260_fixup_fsc_s7020,
1634         },
1635         [ALC260_FIXUP_FSC_S7020_JWSE] = {
1636                 .type = HDA_FIXUP_FUNC,
1637                 .v.func = alc260_fixup_fsc_s7020_jwse,
1638                 .chained = true,
1639                 .chain_id = ALC260_FIXUP_FSC_S7020,
1640         },
1641         [ALC260_FIXUP_VAIO_PINS] = {
1642                 .type = HDA_FIXUP_PINS,
1643                 .v.pins = (const struct hda_pintbl[]) {
1644                         /* Pin configs are missing completely on some VAIOs */
1645                         { 0x0f, 0x01211020 },
1646                         { 0x10, 0x0001003f },
1647                         { 0x11, 0x411111f0 },
1648                         { 0x12, 0x01a15930 },
1649                         { 0x13, 0x411111f0 },
1650                         { 0x14, 0x411111f0 },
1651                         { 0x15, 0x411111f0 },
1652                         { 0x16, 0x411111f0 },
1653                         { 0x17, 0x411111f0 },
1654                         { 0x18, 0x411111f0 },
1655                         { 0x19, 0x411111f0 },
1656                         { }
1657                 }
1658         },
1659 };
1660
1661 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
1662         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
1663         SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
1664         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
1665         SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
1666         SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
1667         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_FIXUP_VAIO_PINS),
1668         SND_PCI_QUIRK(0x104d, 0x81e2, "Sony VAIO TX", ALC260_FIXUP_HP_PIN_0F),
1669         SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
1670         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
1671         SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
1672         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
1673         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
1674         {}
1675 };
1676
1677 static const struct hda_model_fixup alc260_fixup_models[] = {
1678         {.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
1679         {.id = ALC260_FIXUP_COEF, .name = "coef"},
1680         {.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
1681         {.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
1682         {}
1683 };
1684
1685 /*
1686  */
1687 static int patch_alc260(struct hda_codec *codec)
1688 {
1689         struct alc_spec *spec;
1690         int err;
1691
1692         err = alc_alloc_spec(codec, 0x07);
1693         if (err < 0)
1694                 return err;
1695
1696         spec = codec->spec;
1697         /* as quite a few machines require HP amp for speaker outputs,
1698          * it's easier to enable it unconditionally; even if it's unneeded,
1699          * it's almost harmless.
1700          */
1701         spec->gen.prefer_hp_amp = 1;
1702         spec->gen.beep_nid = 0x01;
1703
1704         snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
1705                            alc260_fixups);
1706         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1707
1708         /* automatic parse from the BIOS config */
1709         err = alc260_parse_auto_config(codec);
1710         if (err < 0)
1711                 goto error;
1712
1713         if (!spec->gen.no_analog)
1714                 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
1715
1716         codec->patch_ops = alc_patch_ops;
1717         spec->shutup = alc_eapd_shutup;
1718
1719         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1720
1721         return 0;
1722
1723  error:
1724         alc_free(codec);
1725         return err;
1726 }
1727
1728
1729 /*
1730  * ALC882/883/885/888/889 support
1731  *
1732  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
1733  * configuration.  Each pin widget can choose any input DACs and a mixer.
1734  * Each ADC is connected from a mixer of all inputs.  This makes possible
1735  * 6-channel independent captures.
1736  *
1737  * In addition, an independent DAC for the multi-playback (not used in this
1738  * driver yet).
1739  */
1740
1741 /*
1742  * Pin config fixes
1743  */
1744 enum {
1745         ALC882_FIXUP_ABIT_AW9D_MAX,
1746         ALC882_FIXUP_LENOVO_Y530,
1747         ALC882_FIXUP_PB_M5210,
1748         ALC882_FIXUP_ACER_ASPIRE_7736,
1749         ALC882_FIXUP_ASUS_W90V,
1750         ALC889_FIXUP_CD,
1751         ALC889_FIXUP_VAIO_TT,
1752         ALC888_FIXUP_EEE1601,
1753         ALC882_FIXUP_EAPD,
1754         ALC883_FIXUP_EAPD,
1755         ALC883_FIXUP_ACER_EAPD,
1756         ALC882_FIXUP_GPIO1,
1757         ALC882_FIXUP_GPIO2,
1758         ALC882_FIXUP_GPIO3,
1759         ALC889_FIXUP_COEF,
1760         ALC882_FIXUP_ASUS_W2JC,
1761         ALC882_FIXUP_ACER_ASPIRE_4930G,
1762         ALC882_FIXUP_ACER_ASPIRE_8930G,
1763         ALC882_FIXUP_ASPIRE_8930G_VERBS,
1764         ALC885_FIXUP_MACPRO_GPIO,
1765         ALC889_FIXUP_DAC_ROUTE,
1766         ALC889_FIXUP_MBP_VREF,
1767         ALC889_FIXUP_IMAC91_VREF,
1768         ALC889_FIXUP_MBA11_VREF,
1769         ALC889_FIXUP_MBA21_VREF,
1770         ALC889_FIXUP_MP11_VREF,
1771         ALC882_FIXUP_INV_DMIC,
1772         ALC882_FIXUP_NO_PRIMARY_HP,
1773         ALC887_FIXUP_ASUS_BASS,
1774 };
1775
1776 static void alc889_fixup_coef(struct hda_codec *codec,
1777                               const struct hda_fixup *fix, int action)
1778 {
1779         if (action != HDA_FIXUP_ACT_INIT)
1780                 return;
1781         alc889_coef_init(codec);
1782 }
1783
1784 /* toggle speaker-output according to the hp-jack state */
1785 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1786 {
1787         unsigned int gpiostate, gpiomask, gpiodir;
1788
1789         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1790                                        AC_VERB_GET_GPIO_DATA, 0);
1791
1792         if (!muted)
1793                 gpiostate |= (1 << pin);
1794         else
1795                 gpiostate &= ~(1 << pin);
1796
1797         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1798                                       AC_VERB_GET_GPIO_MASK, 0);
1799         gpiomask |= (1 << pin);
1800
1801         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1802                                      AC_VERB_GET_GPIO_DIRECTION, 0);
1803         gpiodir |= (1 << pin);
1804
1805
1806         snd_hda_codec_write(codec, codec->afg, 0,
1807                             AC_VERB_SET_GPIO_MASK, gpiomask);
1808         snd_hda_codec_write(codec, codec->afg, 0,
1809                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1810
1811         msleep(1);
1812
1813         snd_hda_codec_write(codec, codec->afg, 0,
1814                             AC_VERB_SET_GPIO_DATA, gpiostate);
1815 }
1816
1817 /* set up GPIO at initialization */
1818 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
1819                                      const struct hda_fixup *fix, int action)
1820 {
1821         if (action != HDA_FIXUP_ACT_INIT)
1822                 return;
1823         alc882_gpio_mute(codec, 0, 0);
1824         alc882_gpio_mute(codec, 1, 0);
1825 }
1826
1827 /* Fix the connection of some pins for ALC889:
1828  * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
1829  * work correctly (bko#42740)
1830  */
1831 static void alc889_fixup_dac_route(struct hda_codec *codec,
1832                                    const struct hda_fixup *fix, int action)
1833 {
1834         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1835                 /* fake the connections during parsing the tree */
1836                 hda_nid_t conn1[2] = { 0x0c, 0x0d };
1837                 hda_nid_t conn2[2] = { 0x0e, 0x0f };
1838                 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
1839                 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
1840                 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
1841                 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
1842         } else if (action == HDA_FIXUP_ACT_PROBE) {
1843                 /* restore the connections */
1844                 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
1845                 snd_hda_override_conn_list(codec, 0x14, 5, conn);
1846                 snd_hda_override_conn_list(codec, 0x15, 5, conn);
1847                 snd_hda_override_conn_list(codec, 0x18, 5, conn);
1848                 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
1849         }
1850 }
1851
1852 /* Set VREF on HP pin */
1853 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
1854                                   const struct hda_fixup *fix, int action)
1855 {
1856         struct alc_spec *spec = codec->spec;
1857         static hda_nid_t nids[2] = { 0x14, 0x15 };
1858         int i;
1859
1860         if (action != HDA_FIXUP_ACT_INIT)
1861                 return;
1862         for (i = 0; i < ARRAY_SIZE(nids); i++) {
1863                 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
1864                 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
1865                         continue;
1866                 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1867                 val |= AC_PINCTL_VREF_80;
1868                 snd_hda_set_pin_ctl(codec, nids[i], val);
1869                 spec->gen.keep_vref_in_automute = 1;
1870                 break;
1871         }
1872 }
1873
1874 static void alc889_fixup_mac_pins(struct hda_codec *codec,
1875                                   const hda_nid_t *nids, int num_nids)
1876 {
1877         struct alc_spec *spec = codec->spec;
1878         int i;
1879
1880         for (i = 0; i < num_nids; i++) {
1881                 unsigned int val;
1882                 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1883                 val |= AC_PINCTL_VREF_50;
1884                 snd_hda_set_pin_ctl(codec, nids[i], val);
1885         }
1886         spec->gen.keep_vref_in_automute = 1;
1887 }
1888
1889 /* Set VREF on speaker pins on imac91 */
1890 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
1891                                      const struct hda_fixup *fix, int action)
1892 {
1893         static hda_nid_t nids[2] = { 0x18, 0x1a };
1894
1895         if (action == HDA_FIXUP_ACT_INIT)
1896                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1897 }
1898
1899 /* Set VREF on speaker pins on mba11 */
1900 static void alc889_fixup_mba11_vref(struct hda_codec *codec,
1901                                     const struct hda_fixup *fix, int action)
1902 {
1903         static hda_nid_t nids[1] = { 0x18 };
1904
1905         if (action == HDA_FIXUP_ACT_INIT)
1906                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1907 }
1908
1909 /* Set VREF on speaker pins on mba21 */
1910 static void alc889_fixup_mba21_vref(struct hda_codec *codec,
1911                                     const struct hda_fixup *fix, int action)
1912 {
1913         static hda_nid_t nids[2] = { 0x18, 0x19 };
1914
1915         if (action == HDA_FIXUP_ACT_INIT)
1916                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1917 }
1918
1919 /* Don't take HP output as primary
1920  * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1921  * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
1922  */
1923 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
1924                                        const struct hda_fixup *fix, int action)
1925 {
1926         struct alc_spec *spec = codec->spec;
1927         if (action == HDA_FIXUP_ACT_PRE_PROBE)
1928                 spec->gen.no_primary_hp = 1;
1929 }
1930
1931 static const struct hda_fixup alc882_fixups[] = {
1932         [ALC882_FIXUP_ABIT_AW9D_MAX] = {
1933                 .type = HDA_FIXUP_PINS,
1934                 .v.pins = (const struct hda_pintbl[]) {
1935                         { 0x15, 0x01080104 }, /* side */
1936                         { 0x16, 0x01011012 }, /* rear */
1937                         { 0x17, 0x01016011 }, /* clfe */
1938                         { }
1939                 }
1940         },
1941         [ALC882_FIXUP_LENOVO_Y530] = {
1942                 .type = HDA_FIXUP_PINS,
1943                 .v.pins = (const struct hda_pintbl[]) {
1944                         { 0x15, 0x99130112 }, /* rear int speakers */
1945                         { 0x16, 0x99130111 }, /* subwoofer */
1946                         { }
1947                 }
1948         },
1949         [ALC882_FIXUP_PB_M5210] = {
1950                 .type = HDA_FIXUP_PINCTLS,
1951                 .v.pins = (const struct hda_pintbl[]) {
1952                         { 0x19, PIN_VREF50 },
1953                         {}
1954                 }
1955         },
1956         [ALC882_FIXUP_ACER_ASPIRE_7736] = {
1957                 .type = HDA_FIXUP_FUNC,
1958                 .v.func = alc_fixup_sku_ignore,
1959         },
1960         [ALC882_FIXUP_ASUS_W90V] = {
1961                 .type = HDA_FIXUP_PINS,
1962                 .v.pins = (const struct hda_pintbl[]) {
1963                         { 0x16, 0x99130110 }, /* fix sequence for CLFE */
1964                         { }
1965                 }
1966         },
1967         [ALC889_FIXUP_CD] = {
1968                 .type = HDA_FIXUP_PINS,
1969                 .v.pins = (const struct hda_pintbl[]) {
1970                         { 0x1c, 0x993301f0 }, /* CD */
1971                         { }
1972                 }
1973         },
1974         [ALC889_FIXUP_VAIO_TT] = {
1975                 .type = HDA_FIXUP_PINS,
1976                 .v.pins = (const struct hda_pintbl[]) {
1977                         { 0x17, 0x90170111 }, /* hidden surround speaker */
1978                         { }
1979                 }
1980         },
1981         [ALC888_FIXUP_EEE1601] = {
1982                 .type = HDA_FIXUP_VERBS,
1983                 .v.verbs = (const struct hda_verb[]) {
1984                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
1985                         { 0x20, AC_VERB_SET_PROC_COEF,  0x0838 },
1986                         { }
1987                 }
1988         },
1989         [ALC882_FIXUP_EAPD] = {
1990                 .type = HDA_FIXUP_VERBS,
1991                 .v.verbs = (const struct hda_verb[]) {
1992                         /* change to EAPD mode */
1993                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1994                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
1995                         { }
1996                 }
1997         },
1998         [ALC883_FIXUP_EAPD] = {
1999                 .type = HDA_FIXUP_VERBS,
2000                 .v.verbs = (const struct hda_verb[]) {
2001                         /* change to EAPD mode */
2002                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2003                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2004                         { }
2005                 }
2006         },
2007         [ALC883_FIXUP_ACER_EAPD] = {
2008                 .type = HDA_FIXUP_VERBS,
2009                 .v.verbs = (const struct hda_verb[]) {
2010                         /* eanable EAPD on Acer laptops */
2011                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2012                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2013                         { }
2014                 }
2015         },
2016         [ALC882_FIXUP_GPIO1] = {
2017                 .type = HDA_FIXUP_VERBS,
2018                 .v.verbs = alc_gpio1_init_verbs,
2019         },
2020         [ALC882_FIXUP_GPIO2] = {
2021                 .type = HDA_FIXUP_VERBS,
2022                 .v.verbs = alc_gpio2_init_verbs,
2023         },
2024         [ALC882_FIXUP_GPIO3] = {
2025                 .type = HDA_FIXUP_VERBS,
2026                 .v.verbs = alc_gpio3_init_verbs,
2027         },
2028         [ALC882_FIXUP_ASUS_W2JC] = {
2029                 .type = HDA_FIXUP_VERBS,
2030                 .v.verbs = alc_gpio1_init_verbs,
2031                 .chained = true,
2032                 .chain_id = ALC882_FIXUP_EAPD,
2033         },
2034         [ALC889_FIXUP_COEF] = {
2035                 .type = HDA_FIXUP_FUNC,
2036                 .v.func = alc889_fixup_coef,
2037         },
2038         [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
2039                 .type = HDA_FIXUP_PINS,
2040                 .v.pins = (const struct hda_pintbl[]) {
2041                         { 0x16, 0x99130111 }, /* CLFE speaker */
2042                         { 0x17, 0x99130112 }, /* surround speaker */
2043                         { }
2044                 },
2045                 .chained = true,
2046                 .chain_id = ALC882_FIXUP_GPIO1,
2047         },
2048         [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
2049                 .type = HDA_FIXUP_PINS,
2050                 .v.pins = (const struct hda_pintbl[]) {
2051                         { 0x16, 0x99130111 }, /* CLFE speaker */
2052                         { 0x1b, 0x99130112 }, /* surround speaker */
2053                         { }
2054                 },
2055                 .chained = true,
2056                 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
2057         },
2058         [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
2059                 /* additional init verbs for Acer Aspire 8930G */
2060                 .type = HDA_FIXUP_VERBS,
2061                 .v.verbs = (const struct hda_verb[]) {
2062                         /* Enable all DACs */
2063                         /* DAC DISABLE/MUTE 1? */
2064                         /*  setting bits 1-5 disables DAC nids 0x02-0x06
2065                          *  apparently. Init=0x38 */
2066                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
2067                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2068                         /* DAC DISABLE/MUTE 2? */
2069                         /*  some bit here disables the other DACs.
2070                          *  Init=0x4900 */
2071                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
2072                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2073                         /* DMIC fix
2074                          * This laptop has a stereo digital microphone.
2075                          * The mics are only 1cm apart which makes the stereo
2076                          * useless. However, either the mic or the ALC889
2077                          * makes the signal become a difference/sum signal
2078                          * instead of standard stereo, which is annoying.
2079                          * So instead we flip this bit which makes the
2080                          * codec replicate the sum signal to both channels,
2081                          * turning it into a normal mono mic.
2082                          */
2083                         /* DMIC_CONTROL? Init value = 0x0001 */
2084                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2085                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
2086                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2087                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2088                         { }
2089                 },
2090                 .chained = true,
2091                 .chain_id = ALC882_FIXUP_GPIO1,
2092         },
2093         [ALC885_FIXUP_MACPRO_GPIO] = {
2094                 .type = HDA_FIXUP_FUNC,
2095                 .v.func = alc885_fixup_macpro_gpio,
2096         },
2097         [ALC889_FIXUP_DAC_ROUTE] = {
2098                 .type = HDA_FIXUP_FUNC,
2099                 .v.func = alc889_fixup_dac_route,
2100         },
2101         [ALC889_FIXUP_MBP_VREF] = {
2102                 .type = HDA_FIXUP_FUNC,
2103                 .v.func = alc889_fixup_mbp_vref,
2104                 .chained = true,
2105                 .chain_id = ALC882_FIXUP_GPIO1,
2106         },
2107         [ALC889_FIXUP_IMAC91_VREF] = {
2108                 .type = HDA_FIXUP_FUNC,
2109                 .v.func = alc889_fixup_imac91_vref,
2110                 .chained = true,
2111                 .chain_id = ALC882_FIXUP_GPIO1,
2112         },
2113         [ALC889_FIXUP_MBA11_VREF] = {
2114                 .type = HDA_FIXUP_FUNC,
2115                 .v.func = alc889_fixup_mba11_vref,
2116                 .chained = true,
2117                 .chain_id = ALC889_FIXUP_MBP_VREF,
2118         },
2119         [ALC889_FIXUP_MBA21_VREF] = {
2120                 .type = HDA_FIXUP_FUNC,
2121                 .v.func = alc889_fixup_mba21_vref,
2122                 .chained = true,
2123                 .chain_id = ALC889_FIXUP_MBP_VREF,
2124         },
2125         [ALC889_FIXUP_MP11_VREF] = {
2126                 .type = HDA_FIXUP_FUNC,
2127                 .v.func = alc889_fixup_mba11_vref,
2128                 .chained = true,
2129                 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2130         },
2131         [ALC882_FIXUP_INV_DMIC] = {
2132                 .type = HDA_FIXUP_FUNC,
2133                 .v.func = alc_fixup_inv_dmic_0x12,
2134         },
2135         [ALC882_FIXUP_NO_PRIMARY_HP] = {
2136                 .type = HDA_FIXUP_FUNC,
2137                 .v.func = alc882_fixup_no_primary_hp,
2138         },
2139         [ALC887_FIXUP_ASUS_BASS] = {
2140                 .type = HDA_FIXUP_PINS,
2141                 .v.pins = (const struct hda_pintbl[]) {
2142                         {0x16, 0x99130130}, /* bass speaker */
2143                         {}
2144                 },
2145         },
2146 };
2147
2148 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2149         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
2150         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2151         SND_PCI_QUIRK(0x1025, 0x0107, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2152         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
2153         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2154         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
2155         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
2156         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
2157                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2158         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
2159                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2160         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
2161                       ALC882_FIXUP_ACER_ASPIRE_8930G),
2162         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
2163                       ALC882_FIXUP_ACER_ASPIRE_8930G),
2164         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
2165                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2166         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
2167                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2168         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
2169                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2170         SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
2171         SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
2172                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2173         SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
2174         SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
2175         SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
2176         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
2177         SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
2178         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
2179         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
2180         SND_PCI_QUIRK(0x1043, 0x84bc, "ASUS ET2700", ALC887_FIXUP_ASUS_BASS),
2181         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
2182         SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2183         SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
2184
2185         /* All Apple entries are in codec SSIDs */
2186         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2187         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2188         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2189         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC889_FIXUP_MP11_VREF),
2190         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2191         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
2192         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
2193         SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
2194         SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
2195         SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBA11_VREF),
2196         SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBA21_VREF),
2197         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
2198         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2199         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
2200         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
2201         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
2202         SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
2203         SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
2204         SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
2205         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2206         SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2207         SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_MBA11_VREF),
2208
2209         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
2210         SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
2211         SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
2212         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
2213         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
2214         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2215         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
2216         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
2217         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
2218         {}
2219 };
2220
2221 static const struct hda_model_fixup alc882_fixup_models[] = {
2222         {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
2223         {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
2224         {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
2225         {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
2226         {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
2227         {}
2228 };
2229
2230 /*
2231  * BIOS auto configuration
2232  */
2233 /* almost identical with ALC880 parser... */
2234 static int alc882_parse_auto_config(struct hda_codec *codec)
2235 {
2236         static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
2237         static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2238         return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
2239 }
2240
2241 /*
2242  */
2243 static int patch_alc882(struct hda_codec *codec)
2244 {
2245         struct alc_spec *spec;
2246         int err;
2247
2248         err = alc_alloc_spec(codec, 0x0b);
2249         if (err < 0)
2250                 return err;
2251
2252         spec = codec->spec;
2253
2254         switch (codec->vendor_id) {
2255         case 0x10ec0882:
2256         case 0x10ec0885:
2257         case 0x10ec0900:
2258                 break;
2259         default:
2260                 /* ALC883 and variants */
2261                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2262                 break;
2263         }
2264
2265         snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
2266                        alc882_fixups);
2267         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2268
2269         alc_auto_parse_customize_define(codec);
2270
2271         if (has_cdefine_beep(codec))
2272                 spec->gen.beep_nid = 0x01;
2273
2274         /* automatic parse from the BIOS config */
2275         err = alc882_parse_auto_config(codec);
2276         if (err < 0)
2277                 goto error;
2278
2279         if (!spec->gen.no_analog && spec->gen.beep_nid)
2280                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2281
2282         codec->patch_ops = alc_patch_ops;
2283
2284         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2285
2286         return 0;
2287
2288  error:
2289         alc_free(codec);
2290         return err;
2291 }
2292
2293
2294 /*
2295  * ALC262 support
2296  */
2297 static int alc262_parse_auto_config(struct hda_codec *codec)
2298 {
2299         static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
2300         static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2301         return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
2302 }
2303
2304 /*
2305  * Pin config fixes
2306  */
2307 enum {
2308         ALC262_FIXUP_FSC_H270,
2309         ALC262_FIXUP_FSC_S7110,
2310         ALC262_FIXUP_HP_Z200,
2311         ALC262_FIXUP_TYAN,
2312         ALC262_FIXUP_LENOVO_3000,
2313         ALC262_FIXUP_BENQ,
2314         ALC262_FIXUP_BENQ_T31,
2315         ALC262_FIXUP_INV_DMIC,
2316 };
2317
2318 static const struct hda_fixup alc262_fixups[] = {
2319         [ALC262_FIXUP_FSC_H270] = {
2320                 .type = HDA_FIXUP_PINS,
2321                 .v.pins = (const struct hda_pintbl[]) {
2322                         { 0x14, 0x99130110 }, /* speaker */
2323                         { 0x15, 0x0221142f }, /* front HP */
2324                         { 0x1b, 0x0121141f }, /* rear HP */
2325                         { }
2326                 }
2327         },
2328         [ALC262_FIXUP_FSC_S7110] = {
2329                 .type = HDA_FIXUP_PINS,
2330                 .v.pins = (const struct hda_pintbl[]) {
2331                         { 0x15, 0x90170110 }, /* speaker */
2332                         { }
2333                 },
2334                 .chained = true,
2335                 .chain_id = ALC262_FIXUP_BENQ,
2336         },
2337         [ALC262_FIXUP_HP_Z200] = {
2338                 .type = HDA_FIXUP_PINS,
2339                 .v.pins = (const struct hda_pintbl[]) {
2340                         { 0x16, 0x99130120 }, /* internal speaker */
2341                         { }
2342                 }
2343         },
2344         [ALC262_FIXUP_TYAN] = {
2345                 .type = HDA_FIXUP_PINS,
2346                 .v.pins = (const struct hda_pintbl[]) {
2347                         { 0x14, 0x1993e1f0 }, /* int AUX */
2348                         { }
2349                 }
2350         },
2351         [ALC262_FIXUP_LENOVO_3000] = {
2352                 .type = HDA_FIXUP_PINCTLS,
2353                 .v.pins = (const struct hda_pintbl[]) {
2354                         { 0x19, PIN_VREF50 },
2355                         {}
2356                 },
2357                 .chained = true,
2358                 .chain_id = ALC262_FIXUP_BENQ,
2359         },
2360         [ALC262_FIXUP_BENQ] = {
2361                 .type = HDA_FIXUP_VERBS,
2362                 .v.verbs = (const struct hda_verb[]) {
2363                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2364                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2365                         {}
2366                 }
2367         },
2368         [ALC262_FIXUP_BENQ_T31] = {
2369                 .type = HDA_FIXUP_VERBS,
2370                 .v.verbs = (const struct hda_verb[]) {
2371                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2372                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2373                         {}
2374                 }
2375         },
2376         [ALC262_FIXUP_INV_DMIC] = {
2377                 .type = HDA_FIXUP_FUNC,
2378                 .v.func = alc_fixup_inv_dmic_0x12,
2379         },
2380 };
2381
2382 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
2383         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
2384         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
2385         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
2386         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
2387         SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
2388         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
2389         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
2390         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
2391         {}
2392 };
2393
2394 static const struct hda_model_fixup alc262_fixup_models[] = {
2395         {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
2396         {}
2397 };
2398
2399 /*
2400  */
2401 static int patch_alc262(struct hda_codec *codec)
2402 {
2403         struct alc_spec *spec;
2404         int err;
2405
2406         err = alc_alloc_spec(codec, 0x0b);
2407         if (err < 0)
2408                 return err;
2409
2410         spec = codec->spec;
2411         spec->gen.shared_mic_vref_pin = 0x18;
2412
2413 #if 0
2414         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
2415          * under-run
2416          */
2417         {
2418         int tmp;
2419         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2420         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
2421         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2422         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
2423         }
2424 #endif
2425         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2426
2427         snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
2428                        alc262_fixups);
2429         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2430
2431         alc_auto_parse_customize_define(codec);
2432
2433         if (has_cdefine_beep(codec))
2434                 spec->gen.beep_nid = 0x01;
2435
2436         /* automatic parse from the BIOS config */
2437         err = alc262_parse_auto_config(codec);
2438         if (err < 0)
2439                 goto error;
2440
2441         if (!spec->gen.no_analog && spec->gen.beep_nid)
2442                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2443
2444         codec->patch_ops = alc_patch_ops;
2445         spec->shutup = alc_eapd_shutup;
2446
2447         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2448
2449         return 0;
2450
2451  error:
2452         alc_free(codec);
2453         return err;
2454 }
2455
2456 /*
2457  *  ALC268
2458  */
2459 /* bind Beep switches of both NID 0x0f and 0x10 */
2460 static const struct hda_bind_ctls alc268_bind_beep_sw = {
2461         .ops = &snd_hda_bind_sw,
2462         .values = {
2463                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
2464                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
2465                 0
2466         },
2467 };
2468
2469 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
2470         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
2471         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
2472         { }
2473 };
2474
2475 /* set PCBEEP vol = 0, mute connections */
2476 static const struct hda_verb alc268_beep_init_verbs[] = {
2477         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2478         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2479         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2480         { }
2481 };
2482
2483 enum {
2484         ALC268_FIXUP_INV_DMIC,
2485         ALC268_FIXUP_HP_EAPD,
2486         ALC268_FIXUP_SPDIF,
2487 };
2488
2489 static const struct hda_fixup alc268_fixups[] = {
2490         [ALC268_FIXUP_INV_DMIC] = {
2491                 .type = HDA_FIXUP_FUNC,
2492                 .v.func = alc_fixup_inv_dmic_0x12,
2493         },
2494         [ALC268_FIXUP_HP_EAPD] = {
2495                 .type = HDA_FIXUP_VERBS,
2496                 .v.verbs = (const struct hda_verb[]) {
2497                         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
2498                         {}
2499                 }
2500         },
2501         [ALC268_FIXUP_SPDIF] = {
2502                 .type = HDA_FIXUP_PINS,
2503                 .v.pins = (const struct hda_pintbl[]) {
2504                         { 0x1e, 0x014b1180 }, /* enable SPDIF out */
2505                         {}
2506                 }
2507         },
2508 };
2509
2510 static const struct hda_model_fixup alc268_fixup_models[] = {
2511         {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
2512         {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
2513         {}
2514 };
2515
2516 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2517         SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
2518         SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
2519         /* below is codec SSID since multiple Toshiba laptops have the
2520          * same PCI SSID 1179:ff00
2521          */
2522         SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
2523         {}
2524 };
2525
2526 /*
2527  * BIOS auto configuration
2528  */
2529 static int alc268_parse_auto_config(struct hda_codec *codec)
2530 {
2531         static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2532         return alc_parse_auto_config(codec, NULL, alc268_ssids);
2533 }
2534
2535 /*
2536  */
2537 static int patch_alc268(struct hda_codec *codec)
2538 {
2539         struct alc_spec *spec;
2540         int err;
2541
2542         /* ALC268 has no aa-loopback mixer */
2543         err = alc_alloc_spec(codec, 0);
2544         if (err < 0)
2545                 return err;
2546
2547         spec = codec->spec;
2548         spec->gen.beep_nid = 0x01;
2549
2550         snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2551         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2552
2553         /* automatic parse from the BIOS config */
2554         err = alc268_parse_auto_config(codec);
2555         if (err < 0)
2556                 goto error;
2557
2558         if (err > 0 && !spec->gen.no_analog &&
2559             spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2560                 add_mixer(spec, alc268_beep_mixer);
2561                 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2562                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2563                         /* override the amp caps for beep generator */
2564                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
2565                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
2566                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
2567                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2568                                           (0 << AC_AMPCAP_MUTE_SHIFT));
2569         }
2570
2571         codec->patch_ops = alc_patch_ops;
2572         spec->shutup = alc_eapd_shutup;
2573
2574         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2575
2576         return 0;
2577
2578  error:
2579         alc_free(codec);
2580         return err;
2581 }
2582
2583 /*
2584  * ALC269
2585  */
2586
2587 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2588                              struct hda_codec *codec,
2589                              struct snd_pcm_substream *substream)
2590 {
2591         struct hda_gen_spec *spec = codec->spec;
2592         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2593                                              hinfo);
2594 }
2595
2596 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2597                                 struct hda_codec *codec,
2598                                 unsigned int stream_tag,
2599                                 unsigned int format,
2600                                 struct snd_pcm_substream *substream)
2601 {
2602         struct hda_gen_spec *spec = codec->spec;
2603         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2604                                                 stream_tag, format, substream);
2605 }
2606
2607 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2608                                 struct hda_codec *codec,
2609                                 struct snd_pcm_substream *substream)
2610 {
2611         struct hda_gen_spec *spec = codec->spec;
2612         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2613 }
2614
2615 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2616         .substreams = 1,
2617         .channels_min = 2,
2618         .channels_max = 8,
2619         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2620         /* NID is set in alc_build_pcms */
2621         .ops = {
2622                 .open = playback_pcm_open,
2623                 .prepare = playback_pcm_prepare,
2624                 .cleanup = playback_pcm_cleanup
2625         },
2626 };
2627
2628 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2629         .substreams = 1,
2630         .channels_min = 2,
2631         .channels_max = 2,
2632         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2633         /* NID is set in alc_build_pcms */
2634 };
2635
2636 /* different alc269-variants */
2637 enum {
2638         ALC269_TYPE_ALC269VA,
2639         ALC269_TYPE_ALC269VB,
2640         ALC269_TYPE_ALC269VC,
2641         ALC269_TYPE_ALC269VD,
2642         ALC269_TYPE_ALC280,
2643         ALC269_TYPE_ALC282,
2644         ALC269_TYPE_ALC284,
2645         ALC269_TYPE_ALC286,
2646         ALC269_TYPE_ALC255,
2647 };
2648
2649 /*
2650  * BIOS auto configuration
2651  */
2652 static int alc269_parse_auto_config(struct hda_codec *codec)
2653 {
2654         static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
2655         static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
2656         static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2657         struct alc_spec *spec = codec->spec;
2658         const hda_nid_t *ssids;
2659
2660         switch (spec->codec_variant) {
2661         case ALC269_TYPE_ALC269VA:
2662         case ALC269_TYPE_ALC269VC:
2663         case ALC269_TYPE_ALC280:
2664         case ALC269_TYPE_ALC284:
2665                 ssids = alc269va_ssids;
2666                 break;
2667         case ALC269_TYPE_ALC269VB:
2668         case ALC269_TYPE_ALC269VD:
2669         case ALC269_TYPE_ALC282:
2670         case ALC269_TYPE_ALC286:
2671         case ALC269_TYPE_ALC255:
2672                 ssids = alc269_ssids;
2673                 break;
2674         default:
2675                 ssids = alc269_ssids;
2676                 break;
2677         }
2678
2679         return alc_parse_auto_config(codec, alc269_ignore, ssids);
2680 }
2681
2682 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
2683 {
2684         int val = alc_read_coef_idx(codec, 0x04);
2685         if (val == -1)
2686                 return;
2687         if (power_up)
2688                 val |= 1 << 11;
2689         else
2690                 val &= ~(1 << 11);
2691         alc_write_coef_idx(codec, 0x04, val);
2692 }
2693
2694 static void alc269_shutup(struct hda_codec *codec)
2695 {
2696         struct alc_spec *spec = codec->spec;
2697
2698         if (spec->codec_variant != ALC269_TYPE_ALC269VB)
2699                 return;
2700
2701         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2702                 alc269vb_toggle_power_output(codec, 0);
2703         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2704                         (alc_get_coef0(codec) & 0x00ff) == 0x018) {
2705                 msleep(150);
2706         }
2707 }
2708
2709 #ifdef CONFIG_PM
2710 static int alc269_resume(struct hda_codec *codec)
2711 {
2712         struct alc_spec *spec = codec->spec;
2713
2714         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2715                 alc269vb_toggle_power_output(codec, 0);
2716         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2717                         (alc_get_coef0(codec) & 0x00ff) == 0x018) {
2718                 msleep(150);
2719         }
2720
2721         codec->patch_ops.init(codec);
2722
2723         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2724                 alc269vb_toggle_power_output(codec, 1);
2725         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2726                         (alc_get_coef0(codec) & 0x00ff) == 0x017) {
2727                 msleep(200);
2728         }
2729
2730         snd_hda_codec_resume_amp(codec);
2731         snd_hda_codec_resume_cache(codec);
2732         hda_call_check_power_status(codec, 0x01);
2733         return 0;
2734 }
2735 #endif /* CONFIG_PM */
2736
2737 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
2738                                                  const struct hda_fixup *fix, int action)
2739 {
2740         struct alc_spec *spec = codec->spec;
2741
2742         if (action == HDA_FIXUP_ACT_PRE_PROBE)
2743                 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
2744 }
2745
2746 static void alc269_fixup_hweq(struct hda_codec *codec,
2747                                const struct hda_fixup *fix, int action)
2748 {
2749         int coef;
2750
2751         if (action != HDA_FIXUP_ACT_INIT)
2752                 return;
2753         coef = alc_read_coef_idx(codec, 0x1e);
2754         alc_write_coef_idx(codec, 0x1e, coef | 0x80);
2755 }
2756
2757 static void alc271_fixup_dmic(struct hda_codec *codec,
2758                               const struct hda_fixup *fix, int action)
2759 {
2760         static const struct hda_verb verbs[] = {
2761                 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
2762                 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
2763                 {}
2764         };
2765         unsigned int cfg;
2766
2767         if (strcmp(codec->chip_name, "ALC271X") &&
2768             strcmp(codec->chip_name, "ALC269VB"))
2769                 return;
2770         cfg = snd_hda_codec_get_pincfg(codec, 0x12);
2771         if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
2772                 snd_hda_sequence_write(codec, verbs);
2773 }
2774
2775 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
2776                                  const struct hda_fixup *fix, int action)
2777 {
2778         struct alc_spec *spec = codec->spec;
2779
2780         if (action != HDA_FIXUP_ACT_PROBE)
2781                 return;
2782
2783         /* Due to a hardware problem on Lenovo Ideadpad, we need to
2784          * fix the sample rate of analog I/O to 44.1kHz
2785          */
2786         spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
2787         spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
2788 }
2789
2790 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
2791                                      const struct hda_fixup *fix, int action)
2792 {
2793         int coef;
2794
2795         if (action != HDA_FIXUP_ACT_INIT)
2796                 return;
2797         /* The digital-mic unit sends PDM (differential signal) instead of
2798          * the standard PCM, thus you can't record a valid mono stream as is.
2799          * Below is a workaround specific to ALC269 to control the dmic
2800          * signal source as mono.
2801          */
2802         coef = alc_read_coef_idx(codec, 0x07);
2803         alc_write_coef_idx(codec, 0x07, coef | 0x80);
2804 }
2805
2806 static void alc269_quanta_automute(struct hda_codec *codec)
2807 {
2808         snd_hda_gen_update_outputs(codec);
2809
2810         snd_hda_codec_write(codec, 0x20, 0,
2811                         AC_VERB_SET_COEF_INDEX, 0x0c);
2812         snd_hda_codec_write(codec, 0x20, 0,
2813                         AC_VERB_SET_PROC_COEF, 0x680);
2814
2815         snd_hda_codec_write(codec, 0x20, 0,
2816                         AC_VERB_SET_COEF_INDEX, 0x0c);
2817         snd_hda_codec_write(codec, 0x20, 0,
2818                         AC_VERB_SET_PROC_COEF, 0x480);
2819 }
2820
2821 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
2822                                      const struct hda_fixup *fix, int action)
2823 {
2824         struct alc_spec *spec = codec->spec;
2825         if (action != HDA_FIXUP_ACT_PROBE)
2826                 return;
2827         spec->gen.automute_hook = alc269_quanta_automute;
2828 }
2829
2830 static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
2831                                          struct hda_jack_tbl *jack)
2832 {
2833         struct alc_spec *spec = codec->spec;
2834         int vref;
2835         msleep(200);
2836         snd_hda_gen_hp_automute(codec, jack);
2837
2838         vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
2839         msleep(100);
2840         snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2841                             vref);
2842         msleep(500);
2843         snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2844                             vref);
2845 }
2846
2847 static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
2848                                      const struct hda_fixup *fix, int action)
2849 {
2850         struct alc_spec *spec = codec->spec;
2851         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2852                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
2853                 spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
2854         }
2855 }
2856
2857
2858 /* update mute-LED according to the speaker mute state via mic VREF pin */
2859 static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
2860 {
2861         struct hda_codec *codec = private_data;
2862         struct alc_spec *spec = codec->spec;
2863         unsigned int pinval;
2864
2865         if (spec->mute_led_polarity)
2866                 enabled = !enabled;
2867         pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid);
2868         pinval &= ~AC_PINCTL_VREFEN;
2869         pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80;
2870         if (spec->mute_led_nid)
2871                 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
2872 }
2873
2874 /* Make sure the led works even in runtime suspend */
2875 static unsigned int led_power_filter(struct hda_codec *codec,
2876                                                   hda_nid_t nid,
2877                                                   unsigned int power_state)
2878 {
2879         struct alc_spec *spec = codec->spec;
2880
2881         if (power_state != AC_PWRST_D3 || nid != spec->mute_led_nid)
2882                 return power_state;
2883
2884         /* Set pin ctl again, it might have just been set to 0 */
2885         snd_hda_set_pin_ctl(codec, nid,
2886                             snd_hda_codec_get_pin_target(codec, nid));
2887
2888         return AC_PWRST_D0;
2889 }
2890
2891 static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
2892                                      const struct hda_fixup *fix, int action)
2893 {
2894         struct alc_spec *spec = codec->spec;
2895         const struct dmi_device *dev = NULL;
2896
2897         if (action != HDA_FIXUP_ACT_PRE_PROBE)
2898                 return;
2899
2900         while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2901                 int pol, pin;
2902                 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
2903                         continue;
2904                 if (pin < 0x0a || pin >= 0x10)
2905                         break;
2906                 spec->mute_led_polarity = pol;
2907                 spec->mute_led_nid = pin - 0x0a + 0x18;
2908                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2909                 spec->gen.vmaster_mute_enum = 1;
2910                 codec->power_filter = led_power_filter;
2911                 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
2912                            spec->mute_led_polarity);
2913                 break;
2914         }
2915 }
2916
2917 static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
2918                                 const struct hda_fixup *fix, int action)
2919 {
2920         struct alc_spec *spec = codec->spec;
2921         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2922                 spec->mute_led_polarity = 0;
2923                 spec->mute_led_nid = 0x18;
2924                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2925                 spec->gen.vmaster_mute_enum = 1;
2926                 codec->power_filter = led_power_filter;
2927         }
2928 }
2929
2930 static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
2931                                 const struct hda_fixup *fix, int action)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2935                 spec->mute_led_polarity = 0;
2936                 spec->mute_led_nid = 0x19;
2937                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2938                 spec->gen.vmaster_mute_enum = 1;
2939                 codec->power_filter = led_power_filter;
2940         }
2941 }
2942
2943 /* turn on/off mute LED per vmaster hook */
2944 static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled)
2945 {
2946         struct hda_codec *codec = private_data;
2947         struct alc_spec *spec = codec->spec;
2948         unsigned int oldval = spec->gpio_led;
2949
2950         if (enabled)
2951                 spec->gpio_led &= ~0x08;
2952         else
2953                 spec->gpio_led |= 0x08;
2954         if (spec->gpio_led != oldval)
2955                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2956                                     spec->gpio_led);
2957 }
2958
2959 /* turn on/off mic-mute LED per capture hook */
2960 static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec,
2961                                struct snd_ctl_elem_value *ucontrol)
2962 {
2963         struct alc_spec *spec = codec->spec;
2964         unsigned int oldval = spec->gpio_led;
2965
2966         if (!ucontrol)
2967                 return;
2968
2969         if (ucontrol->value.integer.value[0] ||
2970             ucontrol->value.integer.value[1])
2971                 spec->gpio_led &= ~0x10;
2972         else
2973                 spec->gpio_led |= 0x10;
2974         if (spec->gpio_led != oldval)
2975                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2976                                     spec->gpio_led);
2977 }
2978
2979 static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
2980                                 const struct hda_fixup *fix, int action)
2981 {
2982         struct alc_spec *spec = codec->spec;
2983         static const struct hda_verb gpio_init[] = {
2984                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
2985                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
2986                 {}
2987         };
2988
2989         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2990                 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook;
2991                 spec->gen.cap_sync_hook = alc269_fixup_hp_gpio_mic_mute_hook;
2992                 spec->gpio_led = 0;
2993                 snd_hda_add_verbs(codec, gpio_init);
2994         }
2995 }
2996
2997 static void alc_headset_mode_unplugged(struct hda_codec *codec)
2998 {
2999         int val;
3000
3001         switch (codec->vendor_id) {
3002         case 0x10ec0283:
3003                 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3004                 alc_write_coef_idx(codec, 0x45, 0xc429);
3005                 val = alc_read_coef_idx(codec, 0x35);
3006                 alc_write_coef_idx(codec, 0x35, val & 0xbfff);
3007                 alc_write_coef_idx(codec, 0x06, 0x2104);
3008                 alc_write_coef_idx(codec, 0x1a, 0x0001);
3009                 alc_write_coef_idx(codec, 0x26, 0x0004);
3010                 alc_write_coef_idx(codec, 0x32, 0x42a3);
3011                 break;
3012         case 0x10ec0292:
3013                 alc_write_coef_idx(codec, 0x76, 0x000e);
3014                 alc_write_coef_idx(codec, 0x6c, 0x2400);
3015                 alc_write_coef_idx(codec, 0x18, 0x7308);
3016                 alc_write_coef_idx(codec, 0x6b, 0xc429);
3017                 break;
3018         case 0x10ec0668:
3019                 alc_write_coef_idx(codec, 0x15, 0x0d40);
3020                 alc_write_coef_idx(codec, 0xb7, 0x802b);
3021                 break;
3022         }
3023         snd_printdd("Headset jack set to unplugged mode.\n");
3024 }
3025
3026
3027 static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3028                                     hda_nid_t mic_pin)
3029 {
3030         int val;
3031
3032         switch (codec->vendor_id) {
3033         case 0x10ec0283:
3034                 alc_write_coef_idx(codec, 0x45, 0xc429);
3035                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3036                 val = alc_read_coef_idx(codec, 0x35);
3037                 alc_write_coef_idx(codec, 0x35, val | 1<<14);
3038                 alc_write_coef_idx(codec, 0x06, 0x2100);
3039                 alc_write_coef_idx(codec, 0x1a, 0x0021);
3040                 alc_write_coef_idx(codec, 0x26, 0x008c);
3041                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3042                 break;
3043         case 0x10ec0292:
3044                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3045                 alc_write_coef_idx(codec, 0x19, 0xa208);
3046                 alc_write_coef_idx(codec, 0x2e, 0xacf0);
3047                 break;
3048         case 0x10ec0668:
3049                 alc_write_coef_idx(codec, 0x11, 0x0001);
3050                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3051                 alc_write_coef_idx(codec, 0xb7, 0x802b);
3052                 alc_write_coef_idx(codec, 0xb5, 0x1040);
3053                 val = alc_read_coef_idx(codec, 0xc3);
3054                 alc_write_coef_idx(codec, 0xc3, val | 1<<12);
3055                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3056                 break;
3057         }
3058         snd_printdd("Headset jack set to mic-in mode.\n");
3059 }
3060
3061 static void alc_headset_mode_default(struct hda_codec *codec)
3062 {
3063         switch (codec->vendor_id) {
3064         case 0x10ec0283:
3065                 alc_write_coef_idx(codec, 0x06, 0x2100);
3066                 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3067                 break;
3068         case 0x10ec0292:
3069                 alc_write_coef_idx(codec, 0x76, 0x000e);
3070                 alc_write_coef_idx(codec, 0x6c, 0x2400);
3071                 alc_write_coef_idx(codec, 0x6b, 0xc429);
3072                 alc_write_coef_idx(codec, 0x18, 0x7308);
3073                 break;
3074         case 0x10ec0668:
3075                 alc_write_coef_idx(codec, 0x11, 0x0041);
3076                 alc_write_coef_idx(codec, 0x15, 0x0d40);
3077                 alc_write_coef_idx(codec, 0xb7, 0x802b);
3078                 break;
3079         }
3080         snd_printdd("Headset jack set to headphone (default) mode.\n");
3081 }
3082
3083 /* Iphone type */
3084 static void alc_headset_mode_ctia(struct hda_codec *codec)
3085 {
3086         switch (codec->vendor_id) {
3087         case 0x10ec0283:
3088                 alc_write_coef_idx(codec, 0x45, 0xd429);
3089                 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3090                 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3091                 break;
3092         case 0x10ec0292:
3093                 alc_write_coef_idx(codec, 0x6b, 0xd429);
3094                 alc_write_coef_idx(codec, 0x76, 0x0008);
3095                 alc_write_coef_idx(codec, 0x18, 0x7388);
3096                 break;
3097         case 0x10ec0668:
3098                 alc_write_coef_idx(codec, 0x11, 0x0001);
3099                 alc_write_coef_idx(codec, 0x15, 0x0d60);
3100                 alc_write_coef_idx(codec, 0xc3, 0x0000);
3101                 break;
3102         }
3103         snd_printdd("Headset jack set to iPhone-style headset mode.\n");
3104 }
3105
3106 /* Nokia type */
3107 static void alc_headset_mode_omtp(struct hda_codec *codec)
3108 {
3109         switch (codec->vendor_id) {
3110         case 0x10ec0283:
3111                 alc_write_coef_idx(codec, 0x45, 0xe429);
3112                 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3113                 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3114                 break;
3115         case 0x10ec0292:
3116                 alc_write_coef_idx(codec, 0x6b, 0xe429);
3117                 alc_write_coef_idx(codec, 0x76, 0x0008);
3118                 alc_write_coef_idx(codec, 0x18, 0x7388);
3119                 break;
3120         case 0x10ec0668:
3121                 alc_write_coef_idx(codec, 0x11, 0x0001);
3122                 alc_write_coef_idx(codec, 0x15, 0x0d50);
3123                 alc_write_coef_idx(codec, 0xc3, 0x0000);
3124                 break;
3125         }
3126         snd_printdd("Headset jack set to Nokia-style headset mode.\n");
3127 }
3128
3129 static void alc_determine_headset_type(struct hda_codec *codec)
3130 {
3131         int val;
3132         bool is_ctia = false;
3133         struct alc_spec *spec = codec->spec;
3134
3135         switch (codec->vendor_id) {
3136         case 0x10ec0283:
3137                 alc_write_coef_idx(codec, 0x45, 0xd029);
3138                 msleep(300);
3139                 val = alc_read_coef_idx(codec, 0x46);
3140                 is_ctia = (val & 0x0070) == 0x0070;
3141                 break;
3142         case 0x10ec0292:
3143                 alc_write_coef_idx(codec, 0x6b, 0xd429);
3144                 msleep(300);
3145                 val = alc_read_coef_idx(codec, 0x6c);
3146                 is_ctia = (val & 0x001c) == 0x001c;
3147                 break;
3148         case 0x10ec0668:
3149                 alc_write_coef_idx(codec, 0x11, 0x0001);
3150                 alc_write_coef_idx(codec, 0xb7, 0x802b);
3151                 alc_write_coef_idx(codec, 0x15, 0x0d60);
3152                 alc_write_coef_idx(codec, 0xc3, 0x0c00);
3153                 msleep(300);
3154                 val = alc_read_coef_idx(codec, 0xbe);
3155                 is_ctia = (val & 0x1c02) == 0x1c02;
3156                 break;
3157         }
3158
3159         snd_printdd("Headset jack detected iPhone-style headset: %s\n",
3160                     is_ctia ? "yes" : "no");
3161         spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3162 }
3163
3164 static void alc_update_headset_mode(struct hda_codec *codec)
3165 {
3166         struct alc_spec *spec = codec->spec;
3167
3168         hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
3169         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3170
3171         int new_headset_mode;
3172
3173         if (!snd_hda_jack_detect(codec, hp_pin))
3174                 new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
3175         else if (mux_pin == spec->headset_mic_pin)
3176                 new_headset_mode = ALC_HEADSET_MODE_HEADSET;
3177         else if (mux_pin == spec->headphone_mic_pin)
3178                 new_headset_mode = ALC_HEADSET_MODE_MIC;
3179         else
3180                 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3181
3182         if (new_headset_mode == spec->current_headset_mode) {
3183                 snd_hda_gen_update_outputs(codec);
3184                 return;
3185         }
3186
3187         switch (new_headset_mode) {
3188         case ALC_HEADSET_MODE_UNPLUGGED:
3189                 alc_headset_mode_unplugged(codec);
3190                 spec->gen.hp_jack_present = false;
3191                 break;
3192         case ALC_HEADSET_MODE_HEADSET:
3193                 if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
3194                         alc_determine_headset_type(codec);
3195                 if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
3196                         alc_headset_mode_ctia(codec);
3197                 else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
3198                         alc_headset_mode_omtp(codec);
3199                 spec->gen.hp_jack_present = true;
3200                 break;
3201         case ALC_HEADSET_MODE_MIC:
3202                 alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
3203                 spec->gen.hp_jack_present = false;
3204                 break;
3205         case ALC_HEADSET_MODE_HEADPHONE:
3206                 alc_headset_mode_default(codec);
3207                 spec->gen.hp_jack_present = true;
3208                 break;
3209         }
3210         if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
3211                 snd_hda_set_pin_ctl_cache(codec, hp_pin,
3212                                           AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3213                 if (spec->headphone_mic_pin)
3214                         snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
3215                                                   PIN_VREFHIZ);
3216         }
3217         spec->current_headset_mode = new_headset_mode;
3218
3219         snd_hda_gen_update_outputs(codec);
3220 }
3221
3222 static void alc_update_headset_mode_hook(struct hda_codec *codec,
3223                              struct snd_ctl_elem_value *ucontrol)
3224 {
3225         alc_update_headset_mode(codec);
3226 }
3227
3228 static void alc_update_headset_jack_cb(struct hda_codec *codec, struct hda_jack_tbl *jack)
3229 {
3230         struct alc_spec *spec = codec->spec;
3231         spec->current_headset_type = ALC_HEADSET_MODE_UNKNOWN;
3232         snd_hda_gen_hp_automute(codec, jack);
3233 }
3234
3235 static void alc_probe_headset_mode(struct hda_codec *codec)
3236 {
3237         int i;
3238         struct alc_spec *spec = codec->spec;
3239         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3240
3241         /* Find mic pins */
3242         for (i = 0; i < cfg->num_inputs; i++) {
3243                 if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
3244                         spec->headset_mic_pin = cfg->inputs[i].pin;
3245                 if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
3246                         spec->headphone_mic_pin = cfg->inputs[i].pin;
3247         }
3248
3249         spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
3250         spec->gen.automute_hook = alc_update_headset_mode;
3251         spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
3252 }
3253
3254 static void alc_fixup_headset_mode(struct hda_codec *codec,
3255                                 const struct hda_fixup *fix, int action)
3256 {
3257         struct alc_spec *spec = codec->spec;
3258
3259         switch (action) {
3260         case HDA_FIXUP_ACT_PRE_PROBE:
3261                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
3262                 break;
3263         case HDA_FIXUP_ACT_PROBE:
3264                 alc_probe_headset_mode(codec);
3265                 break;
3266         case HDA_FIXUP_ACT_INIT:
3267                 spec->current_headset_mode = 0;
3268                 alc_update_headset_mode(codec);
3269                 break;
3270         }
3271 }
3272
3273 static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3274                                 const struct hda_fixup *fix, int action)
3275 {
3276         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3277                 struct alc_spec *spec = codec->spec;
3278                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3279         }
3280         else
3281                 alc_fixup_headset_mode(codec, fix, action);
3282 }
3283
3284 static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3285                                 const struct hda_fixup *fix, int action)
3286 {
3287         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3288                 int val;
3289                 alc_write_coef_idx(codec, 0xc4, 0x8000);
3290                 val = alc_read_coef_idx(codec, 0xc2);
3291                 alc_write_coef_idx(codec, 0xc2, val & 0xfe);
3292                 snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
3293         }
3294         alc_fixup_headset_mode(codec, fix, action);
3295 }
3296
3297 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
3298                                     const struct hda_fixup *fix,
3299                                     int action)
3300 {
3301         struct alc_spec *spec = codec->spec;
3302
3303         if (action == HDA_FIXUP_ACT_PROBE) {
3304                 if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
3305                                !spec->gen.autocfg.hp_pins[0]))
3306                         return;
3307                 snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
3308                                              spec->gen.autocfg.hp_pins[0]);
3309         }
3310 }
3311
3312 static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
3313                                              const struct hda_fixup *fix,
3314                                              int action)
3315 {
3316         struct alc_spec *spec = codec->spec;
3317         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3318         int i;
3319
3320         /* The mic boosts on level 2 and 3 are too noisy
3321            on the internal mic input.
3322            Therefore limit the boost to 0 or 1. */
3323
3324         if (action != HDA_FIXUP_ACT_PROBE)
3325                 return;
3326
3327         for (i = 0; i < cfg->num_inputs; i++) {
3328                 hda_nid_t nid = cfg->inputs[i].pin;
3329                 unsigned int defcfg;
3330                 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3331                         continue;
3332                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3333                 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
3334                         continue;
3335
3336                 snd_hda_override_amp_caps(codec, nid, HDA_INPUT,
3337                                           (0x00 << AC_AMPCAP_OFFSET_SHIFT) |
3338                                           (0x01 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3339                                           (0x2f << AC_AMPCAP_STEP_SIZE_SHIFT) |
3340                                           (0 << AC_AMPCAP_MUTE_SHIFT));
3341         }
3342 }
3343
3344 static void alc290_fixup_mono_speakers(struct hda_codec *codec,
3345                                        const struct hda_fixup *fix, int action)
3346 {
3347         if (action == HDA_FIXUP_ACT_PRE_PROBE)
3348                 /* Remove DAC node 0x03, as it seems to be
3349                    giving mono output */
3350                 snd_hda_override_wcaps(codec, 0x03, 0);
3351 }
3352
3353 enum {
3354         ALC269_FIXUP_SONY_VAIO,
3355         ALC275_FIXUP_SONY_VAIO_GPIO2,
3356         ALC269_FIXUP_DELL_M101Z,
3357         ALC269_FIXUP_SKU_IGNORE,
3358         ALC269_FIXUP_ASUS_G73JW,
3359         ALC269_FIXUP_LENOVO_EAPD,
3360         ALC275_FIXUP_SONY_HWEQ,
3361         ALC271_FIXUP_DMIC,
3362         ALC269_FIXUP_PCM_44K,
3363         ALC269_FIXUP_STEREO_DMIC,
3364         ALC269_FIXUP_QUANTA_MUTE,
3365         ALC269_FIXUP_LIFEBOOK,
3366         ALC269_FIXUP_LIFEBOOK_EXTMIC,
3367         ALC269_FIXUP_LIFEBOOK_HP_PIN,
3368         ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT,
3369         ALC269_FIXUP_AMIC,
3370         ALC269_FIXUP_DMIC,
3371         ALC269VB_FIXUP_AMIC,
3372         ALC269VB_FIXUP_DMIC,
3373         ALC269_FIXUP_HP_MUTE_LED,
3374         ALC269_FIXUP_HP_MUTE_LED_MIC1,
3375         ALC269_FIXUP_HP_MUTE_LED_MIC2,
3376         ALC269_FIXUP_HP_GPIO_LED,
3377         ALC269_FIXUP_INV_DMIC,
3378         ALC269_FIXUP_LENOVO_DOCK,
3379         ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
3380         ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
3381         ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
3382         ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
3383         ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
3384         ALC290_FIXUP_MONO_SPEAKERS,
3385         ALC269_FIXUP_HEADSET_MODE,
3386         ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
3387         ALC269_FIXUP_ASPIRE_HEADSET_MIC,
3388         ALC269_FIXUP_ASUS_X101_FUNC,
3389         ALC269_FIXUP_ASUS_X101_VERB,
3390         ALC269_FIXUP_ASUS_X101,
3391         ALC271_FIXUP_AMIC_MIC2,
3392         ALC271_FIXUP_HP_GATE_MIC_JACK,
3393         ALC269_FIXUP_ACER_AC700,
3394         ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
3395 };
3396
3397 static const struct hda_fixup alc269_fixups[] = {
3398         [ALC269_FIXUP_SONY_VAIO] = {
3399                 .type = HDA_FIXUP_PINCTLS,
3400                 .v.pins = (const struct hda_pintbl[]) {
3401                         {0x19, PIN_VREFGRD},
3402                         {}
3403                 }
3404         },
3405         [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
3406                 .type = HDA_FIXUP_VERBS,
3407                 .v.verbs = (const struct hda_verb[]) {
3408                         {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
3409                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
3410                         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
3411                         { }
3412                 },
3413                 .chained = true,
3414                 .chain_id = ALC269_FIXUP_SONY_VAIO
3415         },
3416         [ALC269_FIXUP_DELL_M101Z] = {
3417                 .type = HDA_FIXUP_VERBS,
3418                 .v.verbs = (const struct hda_verb[]) {
3419                         /* Enables internal speaker */
3420                         {0x20, AC_VERB_SET_COEF_INDEX, 13},
3421                         {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
3422                         {}
3423                 }
3424         },
3425         [ALC269_FIXUP_SKU_IGNORE] = {
3426                 .type = HDA_FIXUP_FUNC,
3427                 .v.func = alc_fixup_sku_ignore,
3428         },
3429         [ALC269_FIXUP_ASUS_G73JW] = {
3430                 .type = HDA_FIXUP_PINS,
3431                 .v.pins = (const struct hda_pintbl[]) {
3432                         { 0x17, 0x99130111 }, /* subwoofer */
3433                         { }
3434                 }
3435         },
3436         [ALC269_FIXUP_LENOVO_EAPD] = {
3437                 .type = HDA_FIXUP_VERBS,
3438                 .v.verbs = (const struct hda_verb[]) {
3439                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
3440                         {}
3441                 }
3442         },
3443         [ALC275_FIXUP_SONY_HWEQ] = {
3444                 .type = HDA_FIXUP_FUNC,
3445                 .v.func = alc269_fixup_hweq,
3446                 .chained = true,
3447                 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
3448         },
3449         [ALC271_FIXUP_DMIC] = {
3450                 .type = HDA_FIXUP_FUNC,
3451                 .v.func = alc271_fixup_dmic,
3452         },
3453         [ALC269_FIXUP_PCM_44K] = {
3454                 .type = HDA_FIXUP_FUNC,
3455                 .v.func = alc269_fixup_pcm_44k,
3456                 .chained = true,
3457                 .chain_id = ALC269_FIXUP_QUANTA_MUTE
3458         },
3459         [ALC269_FIXUP_STEREO_DMIC] = {
3460                 .type = HDA_FIXUP_FUNC,
3461                 .v.func = alc269_fixup_stereo_dmic,
3462         },
3463         [ALC269_FIXUP_QUANTA_MUTE] = {
3464                 .type = HDA_FIXUP_FUNC,
3465                 .v.func = alc269_fixup_quanta_mute,
3466         },
3467         [ALC269_FIXUP_LIFEBOOK] = {
3468                 .type = HDA_FIXUP_PINS,
3469                 .v.pins = (const struct hda_pintbl[]) {
3470                         { 0x1a, 0x2101103f }, /* dock line-out */
3471                         { 0x1b, 0x23a11040 }, /* dock mic-in */
3472                         { }
3473                 },
3474                 .chained = true,
3475                 .chain_id = ALC269_FIXUP_QUANTA_MUTE
3476         },
3477         [ALC269_FIXUP_LIFEBOOK_EXTMIC] = {
3478                 .type = HDA_FIXUP_PINS,
3479                 .v.pins = (const struct hda_pintbl[]) {
3480                         { 0x19, 0x01a1903c }, /* headset mic, with jack detect */
3481                         { }
3482                 },
3483         },
3484         [ALC269_FIXUP_LIFEBOOK_HP_PIN] = {
3485                 .type = HDA_FIXUP_PINS,
3486                 .v.pins = (const struct hda_pintbl[]) {
3487                         { 0x21, 0x0221102f }, /* HP out */
3488                         { }
3489                 },
3490         },
3491         [ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT] = {
3492                 .type = HDA_FIXUP_FUNC,
3493                 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
3494         },
3495         [ALC269_FIXUP_AMIC] = {
3496                 .type = HDA_FIXUP_PINS,
3497                 .v.pins = (const struct hda_pintbl[]) {
3498                         { 0x14, 0x99130110 }, /* speaker */
3499                         { 0x15, 0x0121401f }, /* HP out */
3500                         { 0x18, 0x01a19c20 }, /* mic */
3501                         { 0x19, 0x99a3092f }, /* int-mic */
3502                         { }
3503                 },
3504         },
3505         [ALC269_FIXUP_DMIC] = {
3506                 .type = HDA_FIXUP_PINS,
3507                 .v.pins = (const struct hda_pintbl[]) {
3508                         { 0x12, 0x99a3092f }, /* int-mic */
3509                         { 0x14, 0x99130110 }, /* speaker */
3510                         { 0x15, 0x0121401f }, /* HP out */
3511                         { 0x18, 0x01a19c20 }, /* mic */
3512                         { }
3513                 },
3514         },
3515         [ALC269VB_FIXUP_AMIC] = {
3516                 .type = HDA_FIXUP_PINS,
3517                 .v.pins = (const struct hda_pintbl[]) {
3518                         { 0x14, 0x99130110 }, /* speaker */
3519                         { 0x18, 0x01a19c20 }, /* mic */
3520                         { 0x19, 0x99a3092f }, /* int-mic */
3521                         { 0x21, 0x0121401f }, /* HP out */
3522                         { }
3523                 },
3524         },
3525         [ALC269VB_FIXUP_DMIC] = {
3526                 .type = HDA_FIXUP_PINS,
3527                 .v.pins = (const struct hda_pintbl[]) {
3528                         { 0x12, 0x99a3092f }, /* int-mic */
3529                         { 0x14, 0x99130110 }, /* speaker */
3530                         { 0x18, 0x01a19c20 }, /* mic */
3531                         { 0x21, 0x0121401f }, /* HP out */
3532                         { }
3533                 },
3534         },
3535         [ALC269_FIXUP_HP_MUTE_LED] = {
3536                 .type = HDA_FIXUP_FUNC,
3537                 .v.func = alc269_fixup_hp_mute_led,
3538         },
3539         [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
3540                 .type = HDA_FIXUP_FUNC,
3541                 .v.func = alc269_fixup_hp_mute_led_mic1,
3542         },
3543         [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
3544                 .type = HDA_FIXUP_FUNC,
3545                 .v.func = alc269_fixup_hp_mute_led_mic2,
3546         },
3547         [ALC269_FIXUP_HP_GPIO_LED] = {
3548                 .type = HDA_FIXUP_FUNC,
3549                 .v.func = alc269_fixup_hp_gpio_led,
3550         },
3551         [ALC269_FIXUP_INV_DMIC] = {
3552                 .type = HDA_FIXUP_FUNC,
3553                 .v.func = alc_fixup_inv_dmic_0x12,
3554         },
3555         [ALC269_FIXUP_LENOVO_DOCK] = {
3556                 .type = HDA_FIXUP_PINS,
3557                 .v.pins = (const struct hda_pintbl[]) {
3558                         { 0x19, 0x23a11040 }, /* dock mic */
3559                         { 0x1b, 0x2121103f }, /* dock headphone */
3560                         { }
3561                 },
3562                 .chained = true,
3563                 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
3564         },
3565         [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
3566                 .type = HDA_FIXUP_FUNC,
3567                 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
3568         },
3569         [ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
3570                 .type = HDA_FIXUP_PINS,
3571                 .v.pins = (const struct hda_pintbl[]) {
3572                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3573                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
3574                         { }
3575                 },
3576                 .chained = true,
3577                 .chain_id = ALC269_FIXUP_HEADSET_MODE
3578         },
3579         [ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
3580                 .type = HDA_FIXUP_PINS,
3581                 .v.pins = (const struct hda_pintbl[]) {
3582                         { 0x16, 0x21014020 }, /* dock line out */
3583                         { 0x19, 0x21a19030 }, /* dock mic */
3584                         { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3585                         { }
3586                 },
3587                 .chained = true,
3588                 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3589         },
3590         [ALC269_FIXUP_DELL3_MIC_NO_PRESENCE] = {
3591                 .type = HDA_FIXUP_PINS,
3592                 .v.pins = (const struct hda_pintbl[]) {
3593                         { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3594                         { }
3595                 },
3596                 .chained = true,
3597                 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3598         },
3599         [ALC269_FIXUP_HEADSET_MODE] = {
3600                 .type = HDA_FIXUP_FUNC,
3601                 .v.func = alc_fixup_headset_mode,
3602         },
3603         [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
3604                 .type = HDA_FIXUP_FUNC,
3605                 .v.func = alc_fixup_headset_mode_no_hp_mic,
3606         },
3607         [ALC269_FIXUP_ASPIRE_HEADSET_MIC] = {
3608                 .type = HDA_FIXUP_PINS,
3609                 .v.pins = (const struct hda_pintbl[]) {
3610                         { 0x19, 0x01a1913c }, /* headset mic w/o jack detect */
3611                         { }
3612                 },
3613                 .chained = true,
3614                 .chain_id = ALC269_FIXUP_HEADSET_MODE,
3615         },
3616         [ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
3617                 .type = HDA_FIXUP_PINS,
3618                 .v.pins = (const struct hda_pintbl[]) {
3619                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3620                         { }
3621                 },
3622         },
3623         [ALC269_FIXUP_ASUS_X101_FUNC] = {
3624                 .type = HDA_FIXUP_FUNC,
3625                 .v.func = alc269_fixup_x101_headset_mic,
3626         },
3627         [ALC269_FIXUP_ASUS_X101_VERB] = {
3628                 .type = HDA_FIXUP_VERBS,
3629                 .v.verbs = (const struct hda_verb[]) {
3630                         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3631                         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
3632                         {0x20, AC_VERB_SET_PROC_COEF,  0x0310},
3633                         { }
3634                 },
3635                 .chained = true,
3636                 .chain_id = ALC269_FIXUP_ASUS_X101_FUNC
3637         },
3638         [ALC269_FIXUP_ASUS_X101] = {
3639                 .type = HDA_FIXUP_PINS,
3640                 .v.pins = (const struct hda_pintbl[]) {
3641                         { 0x18, 0x04a1182c }, /* Headset mic */
3642                         { }
3643                 },
3644                 .chained = true,
3645                 .chain_id = ALC269_FIXUP_ASUS_X101_VERB
3646         },
3647         [ALC271_FIXUP_AMIC_MIC2] = {
3648                 .type = HDA_FIXUP_PINS,
3649                 .v.pins = (const struct hda_pintbl[]) {
3650                         { 0x14, 0x99130110 }, /* speaker */
3651                         { 0x19, 0x01a19c20 }, /* mic */
3652                         { 0x1b, 0x99a7012f }, /* int-mic */
3653                         { 0x21, 0x0121401f }, /* HP out */
3654                         { }
3655                 },
3656         },
3657         [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
3658                 .type = HDA_FIXUP_FUNC,
3659                 .v.func = alc271_hp_gate_mic_jack,
3660                 .chained = true,
3661                 .chain_id = ALC271_FIXUP_AMIC_MIC2,
3662         },
3663         [ALC269_FIXUP_ACER_AC700] = {
3664                 .type = HDA_FIXUP_PINS,
3665                 .v.pins = (const struct hda_pintbl[]) {
3666                         { 0x12, 0x99a3092f }, /* int-mic */
3667                         { 0x14, 0x99130110 }, /* speaker */
3668                         { 0x18, 0x03a11c20 }, /* mic */
3669                         { 0x1e, 0x0346101e }, /* SPDIF1 */
3670                         { 0x21, 0x0321101f }, /* HP out */
3671                         { }
3672                 },
3673                 .chained = true,
3674                 .chain_id = ALC271_FIXUP_DMIC,
3675         },
3676         [ALC269_FIXUP_LIMIT_INT_MIC_BOOST] = {
3677                 .type = HDA_FIXUP_FUNC,
3678                 .v.func = alc269_fixup_limit_int_mic_boost,
3679         },
3680         [ALC290_FIXUP_MONO_SPEAKERS] = {
3681                 .type = HDA_FIXUP_FUNC,
3682                 .v.func = alc290_fixup_mono_speakers,
3683                 .chained = true,
3684                 .chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
3685         },
3686 };
3687
3688 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3689         SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
3690         SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
3691         SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
3692         SND_PCI_QUIRK(0x1028, 0x05bd, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3693         SND_PCI_QUIRK(0x1028, 0x05be, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3694         SND_PCI_QUIRK(0x1028, 0x05c4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3695         SND_PCI_QUIRK(0x1028, 0x05c5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3696         SND_PCI_QUIRK(0x1028, 0x05c6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3697         SND_PCI_QUIRK(0x1028, 0x05c7, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3698         SND_PCI_QUIRK(0x1028, 0x05c8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3699         SND_PCI_QUIRK(0x1028, 0x05c9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3700         SND_PCI_QUIRK(0x1028, 0x05ca, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3701         SND_PCI_QUIRK(0x1028, 0x05cb, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3702         SND_PCI_QUIRK(0x1028, 0x05de, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3703         SND_PCI_QUIRK(0x1028, 0x05e0, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3704         SND_PCI_QUIRK(0x1028, 0x05e9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3705         SND_PCI_QUIRK(0x1028, 0x05ea, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3706         SND_PCI_QUIRK(0x1028, 0x05eb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3707         SND_PCI_QUIRK(0x1028, 0x05ec, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3708         SND_PCI_QUIRK(0x1028, 0x05ed, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3709         SND_PCI_QUIRK(0x1028, 0x05ee, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3710         SND_PCI_QUIRK(0x1028, 0x05f3, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3711         SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3712         SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3713         SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3714         SND_PCI_QUIRK(0x1028, 0x05f8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3715         SND_PCI_QUIRK(0x1028, 0x05f9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3716         SND_PCI_QUIRK(0x1028, 0x05fb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3717         SND_PCI_QUIRK(0x1028, 0x0606, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3718         SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3719         SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3720         SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3721         SND_PCI_QUIRK(0x1028, 0x0614, "Dell Inspiron 3135", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3722         SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_MONO_SPEAKERS),
3723         SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS),
3724         SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
3725         SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
3726         SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
3727         SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
3728         SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
3729         SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3730         SND_PCI_QUIRK(0x1043, 0x115d, "Asus 1015E", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3731         SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
3732         SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
3733         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
3734         SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
3735         SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
3736         SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3737         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
3738         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
3739         SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3740         SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3741         SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
3742         SND_PCI_QUIRK(0x104d, 0x90b5, "Sony VAIO Pro 11", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
3743         SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
3744         SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
3745         SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
3746         SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
3747         SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
3748         SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
3749         SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
3750         SND_PCI_QUIRK(0x1025, 0x072d, "Acer Aspire V5-571G", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
3751         SND_PCI_QUIRK(0x1025, 0x080d, "Acer Aspire V5-122P", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
3752         SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
3753         SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
3754         SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
3755         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
3756         SND_PCI_QUIRK(0x10cf, 0x159f, "Lifebook E780", ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT),
3757         SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
3758         SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
3759         SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
3760         SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
3761         SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
3762         SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
3763         SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
3764         SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
3765         SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
3766         SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
3767         SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
3768         SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
3769         SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
3770         SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
3771         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
3772         SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
3773
3774 #if 0
3775         /* Below is a quirk table taken from the old code.
3776          * Basically the device should work as is without the fixup table.
3777          * If BIOS doesn't give a proper info, enable the corresponding
3778          * fixup entry.
3779          */
3780         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
3781                       ALC269_FIXUP_AMIC),
3782         SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
3783         SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
3784         SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
3785         SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
3786         SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
3787         SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
3788         SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
3789         SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
3790         SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
3791         SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
3792         SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
3793         SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
3794         SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
3795         SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
3796         SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
3797         SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
3798         SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
3799         SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
3800         SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
3801         SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
3802         SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
3803         SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
3804         SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
3805         SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
3806         SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
3807         SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
3808         SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
3809         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
3810         SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
3811         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
3812         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
3813         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
3814         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
3815         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
3816         SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
3817         SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
3818         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
3819         SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
3820         SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
3821 #endif
3822         {}
3823 };
3824
3825 static const struct hda_model_fixup alc269_fixup_models[] = {
3826         {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
3827         {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
3828         {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
3829         {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
3830         {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
3831         {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
3832         {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
3833         {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
3834         {.id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "dell-headset-dock"},
3835         {}
3836 };
3837
3838
3839 static void alc269_fill_coef(struct hda_codec *codec)
3840 {
3841         struct alc_spec *spec = codec->spec;
3842         int val;
3843
3844         if (spec->codec_variant != ALC269_TYPE_ALC269VB)
3845                 return;
3846
3847         if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
3848                 alc_write_coef_idx(codec, 0xf, 0x960b);
3849                 alc_write_coef_idx(codec, 0xe, 0x8817);
3850         }
3851
3852         if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
3853                 alc_write_coef_idx(codec, 0xf, 0x960b);
3854                 alc_write_coef_idx(codec, 0xe, 0x8814);
3855         }
3856
3857         if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
3858                 val = alc_read_coef_idx(codec, 0x04);
3859                 /* Power up output pin */
3860                 if (val != -1)
3861                         alc_write_coef_idx(codec, 0x04, val | (1<<11));
3862         }
3863
3864         if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
3865                 val = alc_read_coef_idx(codec, 0xd);
3866                 if (val != -1 && (val & 0x0c00) >> 10 != 0x1) {
3867                         /* Capless ramp up clock control */
3868                         alc_write_coef_idx(codec, 0xd, val | (1<<10));
3869                 }
3870                 val = alc_read_coef_idx(codec, 0x17);
3871                 if (val != -1 && (val & 0x01c0) >> 6 != 0x4) {
3872                         /* Class D power on reset */
3873                         alc_write_coef_idx(codec, 0x17, val | (1<<7));
3874                 }
3875         }
3876
3877         val = alc_read_coef_idx(codec, 0xd); /* Class D */
3878         if (val != -1)
3879                 alc_write_coef_idx(codec, 0xd, val | (1<<14));
3880
3881         val = alc_read_coef_idx(codec, 0x4); /* HP */
3882         if (val != -1)
3883                 alc_write_coef_idx(codec, 0x4, val | (1<<11));
3884 }
3885
3886 /*
3887  */
3888 static int patch_alc269(struct hda_codec *codec)
3889 {
3890         struct alc_spec *spec;
3891         int err;
3892
3893         err = alc_alloc_spec(codec, 0x0b);
3894         if (err < 0)
3895                 return err;
3896
3897         spec = codec->spec;
3898         spec->gen.shared_mic_vref_pin = 0x18;
3899
3900         snd_hda_pick_fixup(codec, alc269_fixup_models,
3901                        alc269_fixup_tbl, alc269_fixups);
3902         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3903
3904         alc_auto_parse_customize_define(codec);
3905
3906         if (has_cdefine_beep(codec))
3907                 spec->gen.beep_nid = 0x01;
3908
3909         switch (codec->vendor_id) {
3910         case 0x10ec0269:
3911                 spec->codec_variant = ALC269_TYPE_ALC269VA;
3912                 switch (alc_get_coef0(codec) & 0x00f0) {
3913                 case 0x0010:
3914                         if (codec->bus->pci->subsystem_vendor == 0x1025 &&
3915                             spec->cdefine.platform_type == 1)
3916                                 err = alc_codec_rename(codec, "ALC271X");
3917                         spec->codec_variant = ALC269_TYPE_ALC269VB;
3918                         break;
3919                 case 0x0020:
3920                         if (codec->bus->pci->subsystem_vendor == 0x17aa &&
3921                             codec->bus->pci->subsystem_device == 0x21f3)
3922                                 err = alc_codec_rename(codec, "ALC3202");
3923                         spec->codec_variant = ALC269_TYPE_ALC269VC;
3924                         break;
3925                 case 0x0030:
3926                         spec->codec_variant = ALC269_TYPE_ALC269VD;
3927                         break;
3928                 default:
3929                         alc_fix_pll_init(codec, 0x20, 0x04, 15);
3930                 }
3931                 if (err < 0)
3932                         goto error;
3933                 spec->init_hook = alc269_fill_coef;
3934                 alc269_fill_coef(codec);
3935                 break;
3936
3937         case 0x10ec0280:
3938         case 0x10ec0290:
3939                 spec->codec_variant = ALC269_TYPE_ALC280;
3940                 break;
3941         case 0x10ec0233:
3942         case 0x10ec0282:
3943         case 0x10ec0283:
3944                 spec->codec_variant = ALC269_TYPE_ALC282;
3945                 break;
3946         case 0x10ec0284:
3947         case 0x10ec0292:
3948                 spec->codec_variant = ALC269_TYPE_ALC284;
3949                 break;
3950         case 0x10ec0286:
3951         case 0x10ec0288:
3952                 spec->codec_variant = ALC269_TYPE_ALC286;
3953                 break;
3954         case 0x10ec0255:
3955                 spec->codec_variant = ALC269_TYPE_ALC255;
3956                 break;
3957         }
3958
3959         /* automatic parse from the BIOS config */
3960         err = alc269_parse_auto_config(codec);
3961         if (err < 0)
3962                 goto error;
3963
3964         if (!spec->gen.no_analog && spec->gen.beep_nid)
3965                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
3966
3967         codec->patch_ops = alc_patch_ops;
3968 #ifdef CONFIG_PM
3969         codec->patch_ops.resume = alc269_resume;
3970 #endif
3971         spec->shutup = alc269_shutup;
3972
3973         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3974
3975         return 0;
3976
3977  error:
3978         alc_free(codec);
3979         return err;
3980 }
3981
3982 /*
3983  * ALC861
3984  */
3985
3986 static int alc861_parse_auto_config(struct hda_codec *codec)
3987 {
3988         static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
3989         static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
3990         return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
3991 }
3992
3993 /* Pin config fixes */
3994 enum {
3995         ALC861_FIXUP_FSC_AMILO_PI1505,
3996         ALC861_FIXUP_AMP_VREF_0F,
3997         ALC861_FIXUP_NO_JACK_DETECT,
3998         ALC861_FIXUP_ASUS_A6RP,
3999         ALC660_FIXUP_ASUS_W7J,
4000 };
4001
4002 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
4003 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
4004                         const struct hda_fixup *fix, int action)
4005 {
4006         struct alc_spec *spec = codec->spec;
4007         unsigned int val;
4008
4009         if (action != HDA_FIXUP_ACT_INIT)
4010                 return;
4011         val = snd_hda_codec_get_pin_target(codec, 0x0f);
4012         if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
4013                 val |= AC_PINCTL_IN_EN;
4014         val |= AC_PINCTL_VREF_50;
4015         snd_hda_set_pin_ctl(codec, 0x0f, val);
4016         spec->gen.keep_vref_in_automute = 1;
4017 }
4018
4019 /* suppress the jack-detection */
4020 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
4021                                      const struct hda_fixup *fix, int action)
4022 {
4023         if (action == HDA_FIXUP_ACT_PRE_PROBE)
4024                 codec->no_jack_detect = 1;
4025 }
4026
4027 static const struct hda_fixup alc861_fixups[] = {
4028         [ALC861_FIXUP_FSC_AMILO_PI1505] = {
4029                 .type = HDA_FIXUP_PINS,
4030                 .v.pins = (const struct hda_pintbl[]) {
4031                         { 0x0b, 0x0221101f }, /* HP */
4032                         { 0x0f, 0x90170310 }, /* speaker */
4033                         { }
4034                 }
4035         },
4036         [ALC861_FIXUP_AMP_VREF_0F] = {
4037                 .type = HDA_FIXUP_FUNC,
4038                 .v.func = alc861_fixup_asus_amp_vref_0f,
4039         },
4040         [ALC861_FIXUP_NO_JACK_DETECT] = {
4041                 .type = HDA_FIXUP_FUNC,
4042                 .v.func = alc_fixup_no_jack_detect,
4043         },
4044         [ALC861_FIXUP_ASUS_A6RP] = {
4045                 .type = HDA_FIXUP_FUNC,
4046                 .v.func = alc861_fixup_asus_amp_vref_0f,
4047                 .chained = true,
4048                 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
4049         },
4050         [ALC660_FIXUP_ASUS_W7J] = {
4051                 .type = HDA_FIXUP_VERBS,
4052                 .v.verbs = (const struct hda_verb[]) {
4053                         /* ASUS W7J needs a magic pin setup on unused NID 0x10
4054                          * for enabling outputs
4055                          */
4056                         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4057                         { }
4058                 },
4059         }
4060 };
4061
4062 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4063         SND_PCI_QUIRK(0x1043, 0x1253, "ASUS W7J", ALC660_FIXUP_ASUS_W7J),
4064         SND_PCI_QUIRK(0x1043, 0x1263, "ASUS Z35HL", ALC660_FIXUP_ASUS_W7J),
4065         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
4066         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
4067         SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
4068         SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
4069         SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
4070         SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
4071         {}
4072 };
4073
4074 /*
4075  */
4076 static int patch_alc861(struct hda_codec *codec)
4077 {
4078         struct alc_spec *spec;
4079         int err;
4080
4081         err = alc_alloc_spec(codec, 0x15);
4082         if (err < 0)
4083                 return err;
4084
4085         spec = codec->spec;
4086         spec->gen.beep_nid = 0x23;
4087
4088         snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4089         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4090
4091         /* automatic parse from the BIOS config */
4092         err = alc861_parse_auto_config(codec);
4093         if (err < 0)
4094                 goto error;
4095
4096         if (!spec->gen.no_analog)
4097                 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
4098
4099         codec->patch_ops = alc_patch_ops;
4100 #ifdef CONFIG_PM
4101         spec->power_hook = alc_power_eapd;
4102 #endif
4103
4104         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4105
4106         return 0;
4107
4108  error:
4109         alc_free(codec);
4110         return err;
4111 }
4112
4113 /*
4114  * ALC861-VD support
4115  *
4116  * Based on ALC882
4117  *
4118  * In addition, an independent DAC
4119  */
4120 static int alc861vd_parse_auto_config(struct hda_codec *codec)
4121 {
4122         static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
4123         static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4124         return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
4125 }
4126
4127 enum {
4128         ALC660VD_FIX_ASUS_GPIO1,
4129         ALC861VD_FIX_DALLAS,
4130 };
4131
4132 /* exclude VREF80 */
4133 static void alc861vd_fixup_dallas(struct hda_codec *codec,
4134                                   const struct hda_fixup *fix, int action)
4135 {
4136         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4137                 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
4138                 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
4139         }
4140 }
4141
4142 static const struct hda_fixup alc861vd_fixups[] = {
4143         [ALC660VD_FIX_ASUS_GPIO1] = {
4144                 .type = HDA_FIXUP_VERBS,
4145                 .v.verbs = (const struct hda_verb[]) {
4146                         /* reset GPIO1 */
4147                         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
4148                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4149                         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4150                         { }
4151                 }
4152         },
4153         [ALC861VD_FIX_DALLAS] = {
4154                 .type = HDA_FIXUP_FUNC,
4155                 .v.func = alc861vd_fixup_dallas,
4156         },
4157 };
4158
4159 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
4160         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
4161         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
4162         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
4163         {}
4164 };
4165
4166 /*
4167  */
4168 static int patch_alc861vd(struct hda_codec *codec)
4169 {
4170         struct alc_spec *spec;
4171         int err;
4172
4173         err = alc_alloc_spec(codec, 0x0b);
4174         if (err < 0)
4175                 return err;
4176
4177         spec = codec->spec;
4178         spec->gen.beep_nid = 0x23;
4179
4180         snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
4181         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4182
4183         /* automatic parse from the BIOS config */
4184         err = alc861vd_parse_auto_config(codec);
4185         if (err < 0)
4186                 goto error;
4187
4188         if (!spec->gen.no_analog)
4189                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4190
4191         codec->patch_ops = alc_patch_ops;
4192
4193         spec->shutup = alc_eapd_shutup;
4194
4195         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4196
4197         return 0;
4198
4199  error:
4200         alc_free(codec);
4201         return err;
4202 }
4203
4204 /*
4205  * ALC662 support
4206  *
4207  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
4208  * configuration.  Each pin widget can choose any input DACs and a mixer.
4209  * Each ADC is connected from a mixer of all inputs.  This makes possible
4210  * 6-channel independent captures.
4211  *
4212  * In addition, an independent DAC for the multi-playback (not used in this
4213  * driver yet).
4214  */
4215
4216 /*
4217  * BIOS auto configuration
4218  */
4219
4220 static int alc662_parse_auto_config(struct hda_codec *codec)
4221 {
4222         static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
4223         static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
4224         static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4225         const hda_nid_t *ssids;
4226
4227         if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
4228             codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
4229             codec->vendor_id == 0x10ec0671)
4230                 ssids = alc663_ssids;
4231         else
4232                 ssids = alc662_ssids;
4233         return alc_parse_auto_config(codec, alc662_ignore, ssids);
4234 }
4235
4236 static void alc272_fixup_mario(struct hda_codec *codec,
4237                                const struct hda_fixup *fix, int action)
4238 {
4239         if (action != HDA_FIXUP_ACT_PRE_PROBE)
4240                 return;
4241         if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
4242                                       (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
4243                                       (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
4244                                       (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4245                                       (0 << AC_AMPCAP_MUTE_SHIFT)))
4246                 printk(KERN_WARNING
4247                        "hda_codec: failed to override amp caps for NID 0x2\n");
4248 }
4249
4250 enum {
4251         ALC662_FIXUP_ASPIRE,
4252         ALC662_FIXUP_IDEAPAD,
4253         ALC272_FIXUP_MARIO,
4254         ALC662_FIXUP_CZC_P10T,
4255         ALC662_FIXUP_SKU_IGNORE,
4256         ALC662_FIXUP_HP_RP5800,
4257         ALC662_FIXUP_ASUS_MODE1,
4258         ALC662_FIXUP_ASUS_MODE2,
4259         ALC662_FIXUP_ASUS_MODE3,
4260         ALC662_FIXUP_ASUS_MODE4,
4261         ALC662_FIXUP_ASUS_MODE5,
4262         ALC662_FIXUP_ASUS_MODE6,
4263         ALC662_FIXUP_ASUS_MODE7,
4264         ALC662_FIXUP_ASUS_MODE8,
4265         ALC662_FIXUP_NO_JACK_DETECT,
4266         ALC662_FIXUP_ZOTAC_Z68,
4267         ALC662_FIXUP_INV_DMIC,
4268         ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
4269         ALC668_FIXUP_HEADSET_MODE,
4270 };
4271
4272 static const struct hda_fixup alc662_fixups[] = {
4273         [ALC662_FIXUP_ASPIRE] = {
4274                 .type = HDA_FIXUP_PINS,
4275                 .v.pins = (const struct hda_pintbl[]) {
4276                         { 0x15, 0x99130112 }, /* subwoofer */
4277                         { }
4278                 }
4279         },
4280         [ALC662_FIXUP_IDEAPAD] = {
4281                 .type = HDA_FIXUP_PINS,
4282                 .v.pins = (const struct hda_pintbl[]) {
4283                         { 0x17, 0x99130112 }, /* subwoofer */
4284                         { }
4285                 }
4286         },
4287         [ALC272_FIXUP_MARIO] = {
4288                 .type = HDA_FIXUP_FUNC,
4289                 .v.func = alc272_fixup_mario,
4290         },
4291         [ALC662_FIXUP_CZC_P10T] = {
4292                 .type = HDA_FIXUP_VERBS,
4293                 .v.verbs = (const struct hda_verb[]) {
4294                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4295                         {}
4296                 }
4297         },
4298         [ALC662_FIXUP_SKU_IGNORE] = {
4299                 .type = HDA_FIXUP_FUNC,
4300                 .v.func = alc_fixup_sku_ignore,
4301         },
4302         [ALC662_FIXUP_HP_RP5800] = {
4303                 .type = HDA_FIXUP_PINS,
4304                 .v.pins = (const struct hda_pintbl[]) {
4305                         { 0x14, 0x0221201f }, /* HP out */
4306                         { }
4307                 },
4308                 .chained = true,
4309                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4310         },
4311         [ALC662_FIXUP_ASUS_MODE1] = {
4312                 .type = HDA_FIXUP_PINS,
4313                 .v.pins = (const struct hda_pintbl[]) {
4314                         { 0x14, 0x99130110 }, /* speaker */
4315                         { 0x18, 0x01a19c20 }, /* mic */
4316                         { 0x19, 0x99a3092f }, /* int-mic */
4317                         { 0x21, 0x0121401f }, /* HP out */
4318                         { }
4319                 },
4320                 .chained = true,
4321                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4322         },
4323         [ALC662_FIXUP_ASUS_MODE2] = {
4324                 .type = HDA_FIXUP_PINS,
4325                 .v.pins = (const struct hda_pintbl[]) {
4326                         { 0x14, 0x99130110 }, /* speaker */
4327                         { 0x18, 0x01a19820 }, /* mic */
4328                         { 0x19, 0x99a3092f }, /* int-mic */
4329                         { 0x1b, 0x0121401f }, /* HP out */
4330                         { }
4331                 },
4332                 .chained = true,
4333                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4334         },
4335         [ALC662_FIXUP_ASUS_MODE3] = {
4336                 .type = HDA_FIXUP_PINS,
4337                 .v.pins = (const struct hda_pintbl[]) {
4338                         { 0x14, 0x99130110 }, /* speaker */
4339                         { 0x15, 0x0121441f }, /* HP */
4340                         { 0x18, 0x01a19840 }, /* mic */
4341                         { 0x19, 0x99a3094f }, /* int-mic */
4342                         { 0x21, 0x01211420 }, /* HP2 */
4343                         { }
4344                 },
4345                 .chained = true,
4346                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4347         },
4348         [ALC662_FIXUP_ASUS_MODE4] = {
4349                 .type = HDA_FIXUP_PINS,
4350                 .v.pins = (const struct hda_pintbl[]) {
4351                         { 0x14, 0x99130110 }, /* speaker */
4352                         { 0x16, 0x99130111 }, /* speaker */
4353                         { 0x18, 0x01a19840 }, /* mic */
4354                         { 0x19, 0x99a3094f }, /* int-mic */
4355                         { 0x21, 0x0121441f }, /* HP */
4356                         { }
4357                 },
4358                 .chained = true,
4359                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4360         },
4361         [ALC662_FIXUP_ASUS_MODE5] = {
4362                 .type = HDA_FIXUP_PINS,
4363                 .v.pins = (const struct hda_pintbl[]) {
4364                         { 0x14, 0x99130110 }, /* speaker */
4365                         { 0x15, 0x0121441f }, /* HP */
4366                         { 0x16, 0x99130111 }, /* speaker */
4367                         { 0x18, 0x01a19840 }, /* mic */
4368                         { 0x19, 0x99a3094f }, /* int-mic */
4369                         { }
4370                 },
4371                 .chained = true,
4372                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4373         },
4374         [ALC662_FIXUP_ASUS_MODE6] = {
4375                 .type = HDA_FIXUP_PINS,
4376                 .v.pins = (const struct hda_pintbl[]) {
4377                         { 0x14, 0x99130110 }, /* speaker */
4378                         { 0x15, 0x01211420 }, /* HP2 */
4379                         { 0x18, 0x01a19840 }, /* mic */
4380                         { 0x19, 0x99a3094f }, /* int-mic */
4381                         { 0x1b, 0x0121441f }, /* HP */
4382                         { }
4383                 },
4384                 .chained = true,
4385                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4386         },
4387         [ALC662_FIXUP_ASUS_MODE7] = {
4388                 .type = HDA_FIXUP_PINS,
4389                 .v.pins = (const struct hda_pintbl[]) {
4390                         { 0x14, 0x99130110 }, /* speaker */
4391                         { 0x17, 0x99130111 }, /* speaker */
4392                         { 0x18, 0x01a19840 }, /* mic */
4393                         { 0x19, 0x99a3094f }, /* int-mic */
4394                         { 0x1b, 0x01214020 }, /* HP */
4395                         { 0x21, 0x0121401f }, /* HP */
4396                         { }
4397                 },
4398                 .chained = true,
4399                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4400         },
4401         [ALC662_FIXUP_ASUS_MODE8] = {
4402                 .type = HDA_FIXUP_PINS,
4403                 .v.pins = (const struct hda_pintbl[]) {
4404                         { 0x14, 0x99130110 }, /* speaker */
4405                         { 0x12, 0x99a30970 }, /* int-mic */
4406                         { 0x15, 0x01214020 }, /* HP */
4407                         { 0x17, 0x99130111 }, /* speaker */
4408                         { 0x18, 0x01a19840 }, /* mic */
4409                         { 0x21, 0x0121401f }, /* HP */
4410                         { }
4411                 },
4412                 .chained = true,
4413                 .chain_id = ALC662_FIXUP_SKU_IGNORE
4414         },
4415         [ALC662_FIXUP_NO_JACK_DETECT] = {
4416                 .type = HDA_FIXUP_FUNC,
4417                 .v.func = alc_fixup_no_jack_detect,
4418         },
4419         [ALC662_FIXUP_ZOTAC_Z68] = {
4420                 .type = HDA_FIXUP_PINS,
4421                 .v.pins = (const struct hda_pintbl[]) {
4422                         { 0x1b, 0x02214020 }, /* Front HP */
4423                         { }
4424                 }
4425         },
4426         [ALC662_FIXUP_INV_DMIC] = {
4427                 .type = HDA_FIXUP_FUNC,
4428                 .v.func = alc_fixup_inv_dmic_0x12,
4429         },
4430         [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
4431                 .type = HDA_FIXUP_PINS,
4432                 .v.pins = (const struct hda_pintbl[]) {
4433                         { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
4434                         { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
4435                         { }
4436                 },
4437                 .chained = true,
4438                 .chain_id = ALC668_FIXUP_HEADSET_MODE
4439         },
4440         [ALC668_FIXUP_HEADSET_MODE] = {
4441                 .type = HDA_FIXUP_FUNC,
4442                 .v.func = alc_fixup_headset_mode_alc668,
4443         },
4444 };
4445
4446 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
4447         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
4448         SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),
4449         SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
4450         SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
4451         SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
4452         SND_PCI_QUIRK(0x1025, 0x034a, "Gateway LT27", ALC662_FIXUP_INV_DMIC),
4453         SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
4454         SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4455         SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4456         SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
4457         SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_ASUS_MODE4),
4458         SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_ASUS_MODE4),
4459         SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
4460         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
4461         SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
4462         SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
4463         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
4464         SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
4465         SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
4466
4467 #if 0
4468         /* Below is a quirk table taken from the old code.
4469          * Basically the device should work as is without the fixup table.
4470          * If BIOS doesn't give a proper info, enable the corresponding
4471          * fixup entry.
4472          */
4473         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
4474         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
4475         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
4476         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
4477         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4478         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4479         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4480         SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
4481         SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
4482         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4483         SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
4484         SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
4485         SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
4486         SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
4487         SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
4488         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4489         SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
4490         SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
4491         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4492         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4493         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4494         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4495         SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
4496         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
4497         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
4498         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4499         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
4500         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4501         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4502         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
4503         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4504         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4505         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
4506         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
4507         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
4508         SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
4509         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
4510         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
4511         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
4512         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4513         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
4514         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
4515         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4516         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
4517         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
4518         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
4519         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
4520         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
4521         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4522         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
4523 #endif
4524         {}
4525 };
4526
4527 static const struct hda_model_fixup alc662_fixup_models[] = {
4528         {.id = ALC272_FIXUP_MARIO, .name = "mario"},
4529         {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
4530         {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
4531         {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
4532         {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
4533         {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
4534         {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
4535         {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
4536         {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
4537         {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
4538         {.id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
4539         {}
4540 };
4541
4542 static void alc662_fill_coef(struct hda_codec *codec)
4543 {
4544         int val, coef;
4545
4546         coef = alc_get_coef0(codec);
4547
4548         switch (codec->vendor_id) {
4549         case 0x10ec0662:
4550                 if ((coef & 0x00f0) == 0x0030) {
4551                         val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
4552                         alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
4553                 }
4554                 break;
4555         case 0x10ec0272:
4556         case 0x10ec0273:
4557         case 0x10ec0663:
4558         case 0x10ec0665:
4559         case 0x10ec0670:
4560         case 0x10ec0671:
4561         case 0x10ec0672:
4562                 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
4563                 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4564                 break;
4565         }
4566 }
4567
4568 /*
4569  */
4570 static int patch_alc662(struct hda_codec *codec)
4571 {
4572         struct alc_spec *spec;
4573         int err;
4574
4575         err = alc_alloc_spec(codec, 0x0b);
4576         if (err < 0)
4577                 return err;
4578
4579         spec = codec->spec;
4580
4581         /* handle multiple HPs as is */
4582         spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
4583
4584         alc_fix_pll_init(codec, 0x20, 0x04, 15);
4585
4586         spec->init_hook = alc662_fill_coef;
4587         alc662_fill_coef(codec);
4588
4589         snd_hda_pick_fixup(codec, alc662_fixup_models,
4590                        alc662_fixup_tbl, alc662_fixups);
4591         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4592
4593         alc_auto_parse_customize_define(codec);
4594
4595         if (has_cdefine_beep(codec))
4596                 spec->gen.beep_nid = 0x01;
4597
4598         if ((alc_get_coef0(codec) & (1 << 14)) &&
4599             codec->bus->pci->subsystem_vendor == 0x1025 &&
4600             spec->cdefine.platform_type == 1) {
4601                 err = alc_codec_rename(codec, "ALC272X");
4602                 if (err < 0)
4603                         goto error;
4604         }
4605
4606         /* automatic parse from the BIOS config */
4607         err = alc662_parse_auto_config(codec);
4608         if (err < 0)
4609                 goto error;
4610
4611         if (!spec->gen.no_analog && spec->gen.beep_nid) {
4612                 switch (codec->vendor_id) {
4613                 case 0x10ec0662:
4614                         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4615                         break;
4616                 case 0x10ec0272:
4617                 case 0x10ec0663:
4618                 case 0x10ec0665:
4619                 case 0x10ec0668:
4620                         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
4621                         break;
4622                 case 0x10ec0273:
4623                         set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
4624                         break;
4625                 }
4626         }
4627
4628         codec->patch_ops = alc_patch_ops;
4629         spec->shutup = alc_eapd_shutup;
4630
4631         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4632
4633         return 0;
4634
4635  error:
4636         alc_free(codec);
4637         return err;
4638 }
4639
4640 /*
4641  * ALC680 support
4642  */
4643
4644 static int alc680_parse_auto_config(struct hda_codec *codec)
4645 {
4646         return alc_parse_auto_config(codec, NULL, NULL);
4647 }
4648
4649 /*
4650  */
4651 static int patch_alc680(struct hda_codec *codec)
4652 {
4653         int err;
4654
4655         /* ALC680 has no aa-loopback mixer */
4656         err = alc_alloc_spec(codec, 0);
4657         if (err < 0)
4658                 return err;
4659
4660         /* automatic parse from the BIOS config */
4661         err = alc680_parse_auto_config(codec);
4662         if (err < 0) {
4663                 alc_free(codec);
4664                 return err;
4665         }
4666
4667         codec->patch_ops = alc_patch_ops;
4668
4669         return 0;
4670 }
4671
4672 /*
4673  * patch entries
4674  */
4675 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
4676         { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
4677         { .id = 0x10ec0231, .name = "ALC231", .patch = patch_alc269 },
4678         { .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 },
4679         { .id = 0x10ec0255, .name = "ALC255", .patch = patch_alc269 },
4680         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
4681         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
4682         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
4683         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
4684         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
4685         { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
4686         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
4687         { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
4688         { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
4689         { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
4690         { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
4691         { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
4692         { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
4693         { .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 },
4694         { .id = 0x10ec0288, .name = "ALC288", .patch = patch_alc269 },
4695         { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
4696         { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
4697         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
4698           .patch = patch_alc861 },
4699         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
4700         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
4701         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
4702         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
4703           .patch = patch_alc882 },
4704         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
4705           .patch = patch_alc662 },
4706         { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
4707           .patch = patch_alc662 },
4708         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
4709         { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
4710         { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
4711         { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
4712         { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
4713         { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
4714         { .id = 0x10ec0867, .name = "ALC891", .patch = patch_alc882 },
4715         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
4716         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
4717         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
4718         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
4719           .patch = patch_alc882 },
4720         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
4721           .patch = patch_alc882 },
4722         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
4723         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
4724         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
4725           .patch = patch_alc882 },
4726         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
4727         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
4728         { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
4729         { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
4730         { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
4731         {} /* terminator */
4732 };
4733
4734 MODULE_ALIAS("snd-hda-codec-id:10ec*");
4735
4736 MODULE_LICENSE("GPL");
4737 MODULE_DESCRIPTION("Realtek HD-audio codec");
4738
4739 static struct hda_codec_preset_list realtek_list = {
4740         .preset = snd_hda_preset_realtek,
4741         .owner = THIS_MODULE,
4742 };
4743
4744 static int __init patch_realtek_init(void)
4745 {
4746         return snd_hda_add_codec_preset(&realtek_list);
4747 }
4748
4749 static void __exit patch_realtek_exit(void)
4750 {
4751         snd_hda_delete_codec_preset(&realtek_list);
4752 }
4753
4754 module_init(patch_realtek_init)
4755 module_exit(patch_realtek_exit)