af27d67efa826c51a88f302125ffcdcd659a5fd7
[GitHub/mt8127/android_kernel_alcatel_ttab.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 ALC889_FIXUP_MP41_VREF,
1772 ALC882_FIXUP_INV_DMIC,
1773 ALC882_FIXUP_NO_PRIMARY_HP,
1774 ALC887_FIXUP_ASUS_BASS,
1775 };
1776
1777 static void alc889_fixup_coef(struct hda_codec *codec,
1778 const struct hda_fixup *fix, int action)
1779 {
1780 if (action != HDA_FIXUP_ACT_INIT)
1781 return;
1782 alc889_coef_init(codec);
1783 }
1784
1785 /* toggle speaker-output according to the hp-jack state */
1786 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1787 {
1788 unsigned int gpiostate, gpiomask, gpiodir;
1789
1790 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1791 AC_VERB_GET_GPIO_DATA, 0);
1792
1793 if (!muted)
1794 gpiostate |= (1 << pin);
1795 else
1796 gpiostate &= ~(1 << pin);
1797
1798 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1799 AC_VERB_GET_GPIO_MASK, 0);
1800 gpiomask |= (1 << pin);
1801
1802 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1803 AC_VERB_GET_GPIO_DIRECTION, 0);
1804 gpiodir |= (1 << pin);
1805
1806
1807 snd_hda_codec_write(codec, codec->afg, 0,
1808 AC_VERB_SET_GPIO_MASK, gpiomask);
1809 snd_hda_codec_write(codec, codec->afg, 0,
1810 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1811
1812 msleep(1);
1813
1814 snd_hda_codec_write(codec, codec->afg, 0,
1815 AC_VERB_SET_GPIO_DATA, gpiostate);
1816 }
1817
1818 /* set up GPIO at initialization */
1819 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
1820 const struct hda_fixup *fix, int action)
1821 {
1822 if (action != HDA_FIXUP_ACT_INIT)
1823 return;
1824 alc882_gpio_mute(codec, 0, 0);
1825 alc882_gpio_mute(codec, 1, 0);
1826 }
1827
1828 /* Fix the connection of some pins for ALC889:
1829 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
1830 * work correctly (bko#42740)
1831 */
1832 static void alc889_fixup_dac_route(struct hda_codec *codec,
1833 const struct hda_fixup *fix, int action)
1834 {
1835 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1836 /* fake the connections during parsing the tree */
1837 hda_nid_t conn1[2] = { 0x0c, 0x0d };
1838 hda_nid_t conn2[2] = { 0x0e, 0x0f };
1839 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
1840 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
1841 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
1842 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
1843 } else if (action == HDA_FIXUP_ACT_PROBE) {
1844 /* restore the connections */
1845 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
1846 snd_hda_override_conn_list(codec, 0x14, 5, conn);
1847 snd_hda_override_conn_list(codec, 0x15, 5, conn);
1848 snd_hda_override_conn_list(codec, 0x18, 5, conn);
1849 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
1850 }
1851 }
1852
1853 /* Set VREF on HP pin */
1854 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
1855 const struct hda_fixup *fix, int action)
1856 {
1857 struct alc_spec *spec = codec->spec;
1858 static hda_nid_t nids[3] = { 0x14, 0x15, 0x19 };
1859 int i;
1860
1861 if (action != HDA_FIXUP_ACT_INIT)
1862 return;
1863 for (i = 0; i < ARRAY_SIZE(nids); i++) {
1864 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
1865 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
1866 continue;
1867 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1868 val |= AC_PINCTL_VREF_80;
1869 snd_hda_set_pin_ctl(codec, nids[i], val);
1870 spec->gen.keep_vref_in_automute = 1;
1871 break;
1872 }
1873 }
1874
1875 static void alc889_fixup_mac_pins(struct hda_codec *codec,
1876 const hda_nid_t *nids, int num_nids)
1877 {
1878 struct alc_spec *spec = codec->spec;
1879 int i;
1880
1881 for (i = 0; i < num_nids; i++) {
1882 unsigned int val;
1883 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1884 val |= AC_PINCTL_VREF_50;
1885 snd_hda_set_pin_ctl(codec, nids[i], val);
1886 }
1887 spec->gen.keep_vref_in_automute = 1;
1888 }
1889
1890 /* Set VREF on speaker pins on imac91 */
1891 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
1892 const struct hda_fixup *fix, int action)
1893 {
1894 static hda_nid_t nids[2] = { 0x18, 0x1a };
1895
1896 if (action == HDA_FIXUP_ACT_INIT)
1897 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1898 }
1899
1900 /* Set VREF on speaker pins on mba11 */
1901 static void alc889_fixup_mba11_vref(struct hda_codec *codec,
1902 const struct hda_fixup *fix, int action)
1903 {
1904 static hda_nid_t nids[1] = { 0x18 };
1905
1906 if (action == HDA_FIXUP_ACT_INIT)
1907 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1908 }
1909
1910 /* Set VREF on speaker pins on mba21 */
1911 static void alc889_fixup_mba21_vref(struct hda_codec *codec,
1912 const struct hda_fixup *fix, int action)
1913 {
1914 static hda_nid_t nids[2] = { 0x18, 0x19 };
1915
1916 if (action == HDA_FIXUP_ACT_INIT)
1917 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1918 }
1919
1920 /* Don't take HP output as primary
1921 * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1922 * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
1923 */
1924 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
1925 const struct hda_fixup *fix, int action)
1926 {
1927 struct alc_spec *spec = codec->spec;
1928 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1929 spec->gen.no_primary_hp = 1;
1930 }
1931
1932 static const struct hda_fixup alc882_fixups[] = {
1933 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
1934 .type = HDA_FIXUP_PINS,
1935 .v.pins = (const struct hda_pintbl[]) {
1936 { 0x15, 0x01080104 }, /* side */
1937 { 0x16, 0x01011012 }, /* rear */
1938 { 0x17, 0x01016011 }, /* clfe */
1939 { }
1940 }
1941 },
1942 [ALC882_FIXUP_LENOVO_Y530] = {
1943 .type = HDA_FIXUP_PINS,
1944 .v.pins = (const struct hda_pintbl[]) {
1945 { 0x15, 0x99130112 }, /* rear int speakers */
1946 { 0x16, 0x99130111 }, /* subwoofer */
1947 { }
1948 }
1949 },
1950 [ALC882_FIXUP_PB_M5210] = {
1951 .type = HDA_FIXUP_PINCTLS,
1952 .v.pins = (const struct hda_pintbl[]) {
1953 { 0x19, PIN_VREF50 },
1954 {}
1955 }
1956 },
1957 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
1958 .type = HDA_FIXUP_FUNC,
1959 .v.func = alc_fixup_sku_ignore,
1960 },
1961 [ALC882_FIXUP_ASUS_W90V] = {
1962 .type = HDA_FIXUP_PINS,
1963 .v.pins = (const struct hda_pintbl[]) {
1964 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
1965 { }
1966 }
1967 },
1968 [ALC889_FIXUP_CD] = {
1969 .type = HDA_FIXUP_PINS,
1970 .v.pins = (const struct hda_pintbl[]) {
1971 { 0x1c, 0x993301f0 }, /* CD */
1972 { }
1973 }
1974 },
1975 [ALC889_FIXUP_VAIO_TT] = {
1976 .type = HDA_FIXUP_PINS,
1977 .v.pins = (const struct hda_pintbl[]) {
1978 { 0x17, 0x90170111 }, /* hidden surround speaker */
1979 { }
1980 }
1981 },
1982 [ALC888_FIXUP_EEE1601] = {
1983 .type = HDA_FIXUP_VERBS,
1984 .v.verbs = (const struct hda_verb[]) {
1985 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
1986 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
1987 { }
1988 }
1989 },
1990 [ALC882_FIXUP_EAPD] = {
1991 .type = HDA_FIXUP_VERBS,
1992 .v.verbs = (const struct hda_verb[]) {
1993 /* change to EAPD mode */
1994 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1995 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
1996 { }
1997 }
1998 },
1999 [ALC883_FIXUP_EAPD] = {
2000 .type = HDA_FIXUP_VERBS,
2001 .v.verbs = (const struct hda_verb[]) {
2002 /* change to EAPD mode */
2003 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2004 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2005 { }
2006 }
2007 },
2008 [ALC883_FIXUP_ACER_EAPD] = {
2009 .type = HDA_FIXUP_VERBS,
2010 .v.verbs = (const struct hda_verb[]) {
2011 /* eanable EAPD on Acer laptops */
2012 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2013 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2014 { }
2015 }
2016 },
2017 [ALC882_FIXUP_GPIO1] = {
2018 .type = HDA_FIXUP_VERBS,
2019 .v.verbs = alc_gpio1_init_verbs,
2020 },
2021 [ALC882_FIXUP_GPIO2] = {
2022 .type = HDA_FIXUP_VERBS,
2023 .v.verbs = alc_gpio2_init_verbs,
2024 },
2025 [ALC882_FIXUP_GPIO3] = {
2026 .type = HDA_FIXUP_VERBS,
2027 .v.verbs = alc_gpio3_init_verbs,
2028 },
2029 [ALC882_FIXUP_ASUS_W2JC] = {
2030 .type = HDA_FIXUP_VERBS,
2031 .v.verbs = alc_gpio1_init_verbs,
2032 .chained = true,
2033 .chain_id = ALC882_FIXUP_EAPD,
2034 },
2035 [ALC889_FIXUP_COEF] = {
2036 .type = HDA_FIXUP_FUNC,
2037 .v.func = alc889_fixup_coef,
2038 },
2039 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
2040 .type = HDA_FIXUP_PINS,
2041 .v.pins = (const struct hda_pintbl[]) {
2042 { 0x16, 0x99130111 }, /* CLFE speaker */
2043 { 0x17, 0x99130112 }, /* surround speaker */
2044 { }
2045 },
2046 .chained = true,
2047 .chain_id = ALC882_FIXUP_GPIO1,
2048 },
2049 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
2050 .type = HDA_FIXUP_PINS,
2051 .v.pins = (const struct hda_pintbl[]) {
2052 { 0x16, 0x99130111 }, /* CLFE speaker */
2053 { 0x1b, 0x99130112 }, /* surround speaker */
2054 { }
2055 },
2056 .chained = true,
2057 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
2058 },
2059 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
2060 /* additional init verbs for Acer Aspire 8930G */
2061 .type = HDA_FIXUP_VERBS,
2062 .v.verbs = (const struct hda_verb[]) {
2063 /* Enable all DACs */
2064 /* DAC DISABLE/MUTE 1? */
2065 /* setting bits 1-5 disables DAC nids 0x02-0x06
2066 * apparently. Init=0x38 */
2067 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
2068 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2069 /* DAC DISABLE/MUTE 2? */
2070 /* some bit here disables the other DACs.
2071 * Init=0x4900 */
2072 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
2073 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2074 /* DMIC fix
2075 * This laptop has a stereo digital microphone.
2076 * The mics are only 1cm apart which makes the stereo
2077 * useless. However, either the mic or the ALC889
2078 * makes the signal become a difference/sum signal
2079 * instead of standard stereo, which is annoying.
2080 * So instead we flip this bit which makes the
2081 * codec replicate the sum signal to both channels,
2082 * turning it into a normal mono mic.
2083 */
2084 /* DMIC_CONTROL? Init value = 0x0001 */
2085 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2086 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
2087 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2088 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2089 { }
2090 },
2091 .chained = true,
2092 .chain_id = ALC882_FIXUP_GPIO1,
2093 },
2094 [ALC885_FIXUP_MACPRO_GPIO] = {
2095 .type = HDA_FIXUP_FUNC,
2096 .v.func = alc885_fixup_macpro_gpio,
2097 },
2098 [ALC889_FIXUP_DAC_ROUTE] = {
2099 .type = HDA_FIXUP_FUNC,
2100 .v.func = alc889_fixup_dac_route,
2101 },
2102 [ALC889_FIXUP_MBP_VREF] = {
2103 .type = HDA_FIXUP_FUNC,
2104 .v.func = alc889_fixup_mbp_vref,
2105 .chained = true,
2106 .chain_id = ALC882_FIXUP_GPIO1,
2107 },
2108 [ALC889_FIXUP_IMAC91_VREF] = {
2109 .type = HDA_FIXUP_FUNC,
2110 .v.func = alc889_fixup_imac91_vref,
2111 .chained = true,
2112 .chain_id = ALC882_FIXUP_GPIO1,
2113 },
2114 [ALC889_FIXUP_MBA11_VREF] = {
2115 .type = HDA_FIXUP_FUNC,
2116 .v.func = alc889_fixup_mba11_vref,
2117 .chained = true,
2118 .chain_id = ALC889_FIXUP_MBP_VREF,
2119 },
2120 [ALC889_FIXUP_MBA21_VREF] = {
2121 .type = HDA_FIXUP_FUNC,
2122 .v.func = alc889_fixup_mba21_vref,
2123 .chained = true,
2124 .chain_id = ALC889_FIXUP_MBP_VREF,
2125 },
2126 [ALC889_FIXUP_MP11_VREF] = {
2127 .type = HDA_FIXUP_FUNC,
2128 .v.func = alc889_fixup_mba11_vref,
2129 .chained = true,
2130 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2131 },
2132 [ALC889_FIXUP_MP41_VREF] = {
2133 .type = HDA_FIXUP_FUNC,
2134 .v.func = alc889_fixup_mbp_vref,
2135 .chained = true,
2136 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2137 },
2138 [ALC882_FIXUP_INV_DMIC] = {
2139 .type = HDA_FIXUP_FUNC,
2140 .v.func = alc_fixup_inv_dmic_0x12,
2141 },
2142 [ALC882_FIXUP_NO_PRIMARY_HP] = {
2143 .type = HDA_FIXUP_FUNC,
2144 .v.func = alc882_fixup_no_primary_hp,
2145 },
2146 [ALC887_FIXUP_ASUS_BASS] = {
2147 .type = HDA_FIXUP_PINS,
2148 .v.pins = (const struct hda_pintbl[]) {
2149 {0x16, 0x99130130}, /* bass speaker */
2150 {}
2151 },
2152 },
2153 };
2154
2155 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2156 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
2157 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2158 SND_PCI_QUIRK(0x1025, 0x0107, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2159 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
2160 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2161 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
2162 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
2163 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
2164 ALC882_FIXUP_ACER_ASPIRE_4930G),
2165 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
2166 ALC882_FIXUP_ACER_ASPIRE_4930G),
2167 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
2168 ALC882_FIXUP_ACER_ASPIRE_8930G),
2169 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
2170 ALC882_FIXUP_ACER_ASPIRE_8930G),
2171 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
2172 ALC882_FIXUP_ACER_ASPIRE_4930G),
2173 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
2174 ALC882_FIXUP_ACER_ASPIRE_4930G),
2175 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
2176 ALC882_FIXUP_ACER_ASPIRE_4930G),
2177 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
2178 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
2179 ALC882_FIXUP_ACER_ASPIRE_4930G),
2180 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
2181 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
2182 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
2183 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
2184 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
2185 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
2186 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
2187 SND_PCI_QUIRK(0x1043, 0x84bc, "ASUS ET2700", ALC887_FIXUP_ASUS_BASS),
2188 SND_PCI_QUIRK(0x1043, 0x8691, "ASUS ROG Ranger VIII", ALC882_FIXUP_GPIO3),
2189 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
2190 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2191 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
2192 SND_PCI_QUIRK(0x104d, 0x9044, "Sony VAIO AiO", ALC882_FIXUP_NO_PRIMARY_HP),
2193
2194 /* All Apple entries are in codec SSIDs */
2195 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2196 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2197 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2198 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC889_FIXUP_MP11_VREF),
2199 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2200 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
2201 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
2202 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
2203 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
2204 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBA11_VREF),
2205 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBA21_VREF),
2206 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
2207 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2208 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
2209 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
2210 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
2211 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
2212 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 4,1/5,1", ALC889_FIXUP_MP41_VREF),
2213 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
2214 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2215 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2216 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_MBA11_VREF),
2217
2218 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
2219 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
2220 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
2221 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
2222 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
2223 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2224 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
2225 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
2226 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
2227 {}
2228 };
2229
2230 static const struct hda_model_fixup alc882_fixup_models[] = {
2231 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
2232 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
2233 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
2234 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
2235 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
2236 {}
2237 };
2238
2239 /*
2240 * BIOS auto configuration
2241 */
2242 /* almost identical with ALC880 parser... */
2243 static int alc882_parse_auto_config(struct hda_codec *codec)
2244 {
2245 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
2246 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2247 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
2248 }
2249
2250 /*
2251 */
2252 static int patch_alc882(struct hda_codec *codec)
2253 {
2254 struct alc_spec *spec;
2255 int err;
2256
2257 err = alc_alloc_spec(codec, 0x0b);
2258 if (err < 0)
2259 return err;
2260
2261 spec = codec->spec;
2262
2263 switch (codec->vendor_id) {
2264 case 0x10ec0882:
2265 case 0x10ec0885:
2266 case 0x10ec0900:
2267 break;
2268 default:
2269 /* ALC883 and variants */
2270 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2271 break;
2272 }
2273
2274 snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
2275 alc882_fixups);
2276 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2277
2278 alc_auto_parse_customize_define(codec);
2279
2280 if (has_cdefine_beep(codec))
2281 spec->gen.beep_nid = 0x01;
2282
2283 /* automatic parse from the BIOS config */
2284 err = alc882_parse_auto_config(codec);
2285 if (err < 0)
2286 goto error;
2287
2288 if (!spec->gen.no_analog && spec->gen.beep_nid)
2289 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2290
2291 codec->patch_ops = alc_patch_ops;
2292
2293 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2294
2295 return 0;
2296
2297 error:
2298 alc_free(codec);
2299 return err;
2300 }
2301
2302
2303 /*
2304 * ALC262 support
2305 */
2306 static int alc262_parse_auto_config(struct hda_codec *codec)
2307 {
2308 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
2309 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2310 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
2311 }
2312
2313 /*
2314 * Pin config fixes
2315 */
2316 enum {
2317 ALC262_FIXUP_FSC_H270,
2318 ALC262_FIXUP_FSC_S7110,
2319 ALC262_FIXUP_HP_Z200,
2320 ALC262_FIXUP_TYAN,
2321 ALC262_FIXUP_LENOVO_3000,
2322 ALC262_FIXUP_BENQ,
2323 ALC262_FIXUP_BENQ_T31,
2324 ALC262_FIXUP_INV_DMIC,
2325 };
2326
2327 static const struct hda_fixup alc262_fixups[] = {
2328 [ALC262_FIXUP_FSC_H270] = {
2329 .type = HDA_FIXUP_PINS,
2330 .v.pins = (const struct hda_pintbl[]) {
2331 { 0x14, 0x99130110 }, /* speaker */
2332 { 0x15, 0x0221142f }, /* front HP */
2333 { 0x1b, 0x0121141f }, /* rear HP */
2334 { }
2335 }
2336 },
2337 [ALC262_FIXUP_FSC_S7110] = {
2338 .type = HDA_FIXUP_PINS,
2339 .v.pins = (const struct hda_pintbl[]) {
2340 { 0x15, 0x90170110 }, /* speaker */
2341 { }
2342 },
2343 .chained = true,
2344 .chain_id = ALC262_FIXUP_BENQ,
2345 },
2346 [ALC262_FIXUP_HP_Z200] = {
2347 .type = HDA_FIXUP_PINS,
2348 .v.pins = (const struct hda_pintbl[]) {
2349 { 0x16, 0x99130120 }, /* internal speaker */
2350 { }
2351 }
2352 },
2353 [ALC262_FIXUP_TYAN] = {
2354 .type = HDA_FIXUP_PINS,
2355 .v.pins = (const struct hda_pintbl[]) {
2356 { 0x14, 0x1993e1f0 }, /* int AUX */
2357 { }
2358 }
2359 },
2360 [ALC262_FIXUP_LENOVO_3000] = {
2361 .type = HDA_FIXUP_PINCTLS,
2362 .v.pins = (const struct hda_pintbl[]) {
2363 { 0x19, PIN_VREF50 },
2364 {}
2365 },
2366 .chained = true,
2367 .chain_id = ALC262_FIXUP_BENQ,
2368 },
2369 [ALC262_FIXUP_BENQ] = {
2370 .type = HDA_FIXUP_VERBS,
2371 .v.verbs = (const struct hda_verb[]) {
2372 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2373 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2374 {}
2375 }
2376 },
2377 [ALC262_FIXUP_BENQ_T31] = {
2378 .type = HDA_FIXUP_VERBS,
2379 .v.verbs = (const struct hda_verb[]) {
2380 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2381 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2382 {}
2383 }
2384 },
2385 [ALC262_FIXUP_INV_DMIC] = {
2386 .type = HDA_FIXUP_FUNC,
2387 .v.func = alc_fixup_inv_dmic_0x12,
2388 },
2389 };
2390
2391 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
2392 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
2393 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
2394 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
2395 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
2396 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
2397 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
2398 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
2399 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
2400 {}
2401 };
2402
2403 static const struct hda_model_fixup alc262_fixup_models[] = {
2404 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
2405 {}
2406 };
2407
2408 /*
2409 */
2410 static int patch_alc262(struct hda_codec *codec)
2411 {
2412 struct alc_spec *spec;
2413 int err;
2414
2415 err = alc_alloc_spec(codec, 0x0b);
2416 if (err < 0)
2417 return err;
2418
2419 spec = codec->spec;
2420 spec->gen.shared_mic_vref_pin = 0x18;
2421
2422 #if 0
2423 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
2424 * under-run
2425 */
2426 {
2427 int tmp;
2428 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2429 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
2430 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2431 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
2432 }
2433 #endif
2434 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2435
2436 snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
2437 alc262_fixups);
2438 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2439
2440 alc_auto_parse_customize_define(codec);
2441
2442 if (has_cdefine_beep(codec))
2443 spec->gen.beep_nid = 0x01;
2444
2445 /* automatic parse from the BIOS config */
2446 err = alc262_parse_auto_config(codec);
2447 if (err < 0)
2448 goto error;
2449
2450 if (!spec->gen.no_analog && spec->gen.beep_nid)
2451 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2452
2453 codec->patch_ops = alc_patch_ops;
2454 spec->shutup = alc_eapd_shutup;
2455
2456 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2457
2458 return 0;
2459
2460 error:
2461 alc_free(codec);
2462 return err;
2463 }
2464
2465 /*
2466 * ALC268
2467 */
2468 /* bind Beep switches of both NID 0x0f and 0x10 */
2469 static const struct hda_bind_ctls alc268_bind_beep_sw = {
2470 .ops = &snd_hda_bind_sw,
2471 .values = {
2472 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
2473 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
2474 0
2475 },
2476 };
2477
2478 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
2479 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
2480 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
2481 { }
2482 };
2483
2484 /* set PCBEEP vol = 0, mute connections */
2485 static const struct hda_verb alc268_beep_init_verbs[] = {
2486 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2487 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2488 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2489 { }
2490 };
2491
2492 enum {
2493 ALC268_FIXUP_INV_DMIC,
2494 ALC268_FIXUP_HP_EAPD,
2495 ALC268_FIXUP_SPDIF,
2496 };
2497
2498 static const struct hda_fixup alc268_fixups[] = {
2499 [ALC268_FIXUP_INV_DMIC] = {
2500 .type = HDA_FIXUP_FUNC,
2501 .v.func = alc_fixup_inv_dmic_0x12,
2502 },
2503 [ALC268_FIXUP_HP_EAPD] = {
2504 .type = HDA_FIXUP_VERBS,
2505 .v.verbs = (const struct hda_verb[]) {
2506 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
2507 {}
2508 }
2509 },
2510 [ALC268_FIXUP_SPDIF] = {
2511 .type = HDA_FIXUP_PINS,
2512 .v.pins = (const struct hda_pintbl[]) {
2513 { 0x1e, 0x014b1180 }, /* enable SPDIF out */
2514 {}
2515 }
2516 },
2517 };
2518
2519 static const struct hda_model_fixup alc268_fixup_models[] = {
2520 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
2521 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
2522 {}
2523 };
2524
2525 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2526 SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
2527 SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
2528 /* below is codec SSID since multiple Toshiba laptops have the
2529 * same PCI SSID 1179:ff00
2530 */
2531 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
2532 {}
2533 };
2534
2535 /*
2536 * BIOS auto configuration
2537 */
2538 static int alc268_parse_auto_config(struct hda_codec *codec)
2539 {
2540 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2541 return alc_parse_auto_config(codec, NULL, alc268_ssids);
2542 }
2543
2544 /*
2545 */
2546 static int patch_alc268(struct hda_codec *codec)
2547 {
2548 struct alc_spec *spec;
2549 int err;
2550
2551 /* ALC268 has no aa-loopback mixer */
2552 err = alc_alloc_spec(codec, 0);
2553 if (err < 0)
2554 return err;
2555
2556 spec = codec->spec;
2557 spec->gen.beep_nid = 0x01;
2558
2559 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2560 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2561
2562 /* automatic parse from the BIOS config */
2563 err = alc268_parse_auto_config(codec);
2564 if (err < 0)
2565 goto error;
2566
2567 if (err > 0 && !spec->gen.no_analog &&
2568 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2569 add_mixer(spec, alc268_beep_mixer);
2570 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2571 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2572 /* override the amp caps for beep generator */
2573 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
2574 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
2575 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
2576 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2577 (0 << AC_AMPCAP_MUTE_SHIFT));
2578 }
2579
2580 codec->patch_ops = alc_patch_ops;
2581 spec->shutup = alc_eapd_shutup;
2582
2583 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2584
2585 return 0;
2586
2587 error:
2588 alc_free(codec);
2589 return err;
2590 }
2591
2592 /*
2593 * ALC269
2594 */
2595
2596 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2597 struct hda_codec *codec,
2598 struct snd_pcm_substream *substream)
2599 {
2600 struct hda_gen_spec *spec = codec->spec;
2601 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2602 hinfo);
2603 }
2604
2605 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2606 struct hda_codec *codec,
2607 unsigned int stream_tag,
2608 unsigned int format,
2609 struct snd_pcm_substream *substream)
2610 {
2611 struct hda_gen_spec *spec = codec->spec;
2612 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2613 stream_tag, format, substream);
2614 }
2615
2616 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2617 struct hda_codec *codec,
2618 struct snd_pcm_substream *substream)
2619 {
2620 struct hda_gen_spec *spec = codec->spec;
2621 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2622 }
2623
2624 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2625 .substreams = 1,
2626 .channels_min = 2,
2627 .channels_max = 8,
2628 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2629 /* NID is set in alc_build_pcms */
2630 .ops = {
2631 .open = playback_pcm_open,
2632 .prepare = playback_pcm_prepare,
2633 .cleanup = playback_pcm_cleanup
2634 },
2635 };
2636
2637 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2638 .substreams = 1,
2639 .channels_min = 2,
2640 .channels_max = 2,
2641 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2642 /* NID is set in alc_build_pcms */
2643 };
2644
2645 /* different alc269-variants */
2646 enum {
2647 ALC269_TYPE_ALC269VA,
2648 ALC269_TYPE_ALC269VB,
2649 ALC269_TYPE_ALC269VC,
2650 ALC269_TYPE_ALC269VD,
2651 ALC269_TYPE_ALC280,
2652 ALC269_TYPE_ALC282,
2653 ALC269_TYPE_ALC284,
2654 ALC269_TYPE_ALC286,
2655 ALC269_TYPE_ALC255,
2656 };
2657
2658 /*
2659 * BIOS auto configuration
2660 */
2661 static int alc269_parse_auto_config(struct hda_codec *codec)
2662 {
2663 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
2664 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
2665 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2666 struct alc_spec *spec = codec->spec;
2667 const hda_nid_t *ssids;
2668
2669 switch (spec->codec_variant) {
2670 case ALC269_TYPE_ALC269VA:
2671 case ALC269_TYPE_ALC269VC:
2672 case ALC269_TYPE_ALC280:
2673 case ALC269_TYPE_ALC284:
2674 ssids = alc269va_ssids;
2675 break;
2676 case ALC269_TYPE_ALC269VB:
2677 case ALC269_TYPE_ALC269VD:
2678 case ALC269_TYPE_ALC282:
2679 case ALC269_TYPE_ALC286:
2680 case ALC269_TYPE_ALC255:
2681 ssids = alc269_ssids;
2682 break;
2683 default:
2684 ssids = alc269_ssids;
2685 break;
2686 }
2687
2688 return alc_parse_auto_config(codec, alc269_ignore, ssids);
2689 }
2690
2691 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
2692 {
2693 int val = alc_read_coef_idx(codec, 0x04);
2694 if (val == -1)
2695 return;
2696 if (power_up)
2697 val |= 1 << 11;
2698 else
2699 val &= ~(1 << 11);
2700 alc_write_coef_idx(codec, 0x04, val);
2701 }
2702
2703 static void alc269_shutup(struct hda_codec *codec)
2704 {
2705 struct alc_spec *spec = codec->spec;
2706
2707 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
2708 return;
2709
2710 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2711 alc269vb_toggle_power_output(codec, 0);
2712 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2713 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
2714 msleep(150);
2715 }
2716 }
2717
2718 #ifdef CONFIG_PM
2719 static int alc269_resume(struct hda_codec *codec)
2720 {
2721 struct alc_spec *spec = codec->spec;
2722
2723 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2724 alc269vb_toggle_power_output(codec, 0);
2725 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2726 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
2727 msleep(150);
2728 }
2729
2730 codec->patch_ops.init(codec);
2731
2732 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2733 alc269vb_toggle_power_output(codec, 1);
2734 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2735 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
2736 msleep(200);
2737 }
2738
2739 snd_hda_codec_resume_amp(codec);
2740 snd_hda_codec_resume_cache(codec);
2741 hda_call_check_power_status(codec, 0x01);
2742 return 0;
2743 }
2744 #endif /* CONFIG_PM */
2745
2746 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
2747 const struct hda_fixup *fix, int action)
2748 {
2749 struct alc_spec *spec = codec->spec;
2750
2751 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2752 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
2753 }
2754
2755 static void alc269_fixup_hweq(struct hda_codec *codec,
2756 const struct hda_fixup *fix, int action)
2757 {
2758 int coef;
2759
2760 if (action != HDA_FIXUP_ACT_INIT)
2761 return;
2762 coef = alc_read_coef_idx(codec, 0x1e);
2763 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
2764 }
2765
2766 static void alc271_fixup_dmic(struct hda_codec *codec,
2767 const struct hda_fixup *fix, int action)
2768 {
2769 static const struct hda_verb verbs[] = {
2770 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
2771 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
2772 {}
2773 };
2774 unsigned int cfg;
2775
2776 if (strcmp(codec->chip_name, "ALC271X") &&
2777 strcmp(codec->chip_name, "ALC269VB"))
2778 return;
2779 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
2780 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
2781 snd_hda_sequence_write(codec, verbs);
2782 }
2783
2784 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
2785 const struct hda_fixup *fix, int action)
2786 {
2787 struct alc_spec *spec = codec->spec;
2788
2789 if (action != HDA_FIXUP_ACT_PROBE)
2790 return;
2791
2792 /* Due to a hardware problem on Lenovo Ideadpad, we need to
2793 * fix the sample rate of analog I/O to 44.1kHz
2794 */
2795 spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
2796 spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
2797 }
2798
2799 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
2800 const struct hda_fixup *fix, int action)
2801 {
2802 int coef;
2803
2804 if (action != HDA_FIXUP_ACT_INIT)
2805 return;
2806 /* The digital-mic unit sends PDM (differential signal) instead of
2807 * the standard PCM, thus you can't record a valid mono stream as is.
2808 * Below is a workaround specific to ALC269 to control the dmic
2809 * signal source as mono.
2810 */
2811 coef = alc_read_coef_idx(codec, 0x07);
2812 alc_write_coef_idx(codec, 0x07, coef | 0x80);
2813 }
2814
2815 static void alc269_quanta_automute(struct hda_codec *codec)
2816 {
2817 snd_hda_gen_update_outputs(codec);
2818
2819 snd_hda_codec_write(codec, 0x20, 0,
2820 AC_VERB_SET_COEF_INDEX, 0x0c);
2821 snd_hda_codec_write(codec, 0x20, 0,
2822 AC_VERB_SET_PROC_COEF, 0x680);
2823
2824 snd_hda_codec_write(codec, 0x20, 0,
2825 AC_VERB_SET_COEF_INDEX, 0x0c);
2826 snd_hda_codec_write(codec, 0x20, 0,
2827 AC_VERB_SET_PROC_COEF, 0x480);
2828 }
2829
2830 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
2831 const struct hda_fixup *fix, int action)
2832 {
2833 struct alc_spec *spec = codec->spec;
2834 if (action != HDA_FIXUP_ACT_PROBE)
2835 return;
2836 spec->gen.automute_hook = alc269_quanta_automute;
2837 }
2838
2839 static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
2840 struct hda_jack_tbl *jack)
2841 {
2842 struct alc_spec *spec = codec->spec;
2843 int vref;
2844 msleep(200);
2845 snd_hda_gen_hp_automute(codec, jack);
2846
2847 vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
2848 msleep(100);
2849 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2850 vref);
2851 msleep(500);
2852 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2853 vref);
2854 }
2855
2856 static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
2857 const struct hda_fixup *fix, int action)
2858 {
2859 struct alc_spec *spec = codec->spec;
2860 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2861 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
2862 spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
2863 }
2864 }
2865
2866
2867 /* update mute-LED according to the speaker mute state via mic VREF pin */
2868 static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
2869 {
2870 struct hda_codec *codec = private_data;
2871 struct alc_spec *spec = codec->spec;
2872 unsigned int pinval;
2873
2874 if (spec->mute_led_polarity)
2875 enabled = !enabled;
2876 pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid);
2877 pinval &= ~AC_PINCTL_VREFEN;
2878 pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80;
2879 if (spec->mute_led_nid)
2880 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
2881 }
2882
2883 /* Make sure the led works even in runtime suspend */
2884 static unsigned int led_power_filter(struct hda_codec *codec,
2885 hda_nid_t nid,
2886 unsigned int power_state)
2887 {
2888 struct alc_spec *spec = codec->spec;
2889
2890 if (power_state != AC_PWRST_D3 || nid != spec->mute_led_nid)
2891 return power_state;
2892
2893 /* Set pin ctl again, it might have just been set to 0 */
2894 snd_hda_set_pin_ctl(codec, nid,
2895 snd_hda_codec_get_pin_target(codec, nid));
2896
2897 return AC_PWRST_D0;
2898 }
2899
2900 static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
2901 const struct hda_fixup *fix, int action)
2902 {
2903 struct alc_spec *spec = codec->spec;
2904 const struct dmi_device *dev = NULL;
2905
2906 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2907 return;
2908
2909 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2910 int pol, pin;
2911 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
2912 continue;
2913 if (pin < 0x0a || pin >= 0x10)
2914 break;
2915 spec->mute_led_polarity = pol;
2916 spec->mute_led_nid = pin - 0x0a + 0x18;
2917 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2918 spec->gen.vmaster_mute_enum = 1;
2919 codec->power_filter = led_power_filter;
2920 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
2921 spec->mute_led_polarity);
2922 break;
2923 }
2924 }
2925
2926 static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
2927 const struct hda_fixup *fix, int action)
2928 {
2929 struct alc_spec *spec = codec->spec;
2930 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2931 spec->mute_led_polarity = 0;
2932 spec->mute_led_nid = 0x18;
2933 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2934 spec->gen.vmaster_mute_enum = 1;
2935 codec->power_filter = led_power_filter;
2936 }
2937 }
2938
2939 static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
2940 const struct hda_fixup *fix, int action)
2941 {
2942 struct alc_spec *spec = codec->spec;
2943 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2944 spec->mute_led_polarity = 0;
2945 spec->mute_led_nid = 0x19;
2946 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2947 spec->gen.vmaster_mute_enum = 1;
2948 codec->power_filter = led_power_filter;
2949 }
2950 }
2951
2952 /* turn on/off mute LED per vmaster hook */
2953 static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled)
2954 {
2955 struct hda_codec *codec = private_data;
2956 struct alc_spec *spec = codec->spec;
2957 unsigned int oldval = spec->gpio_led;
2958
2959 if (enabled)
2960 spec->gpio_led &= ~0x08;
2961 else
2962 spec->gpio_led |= 0x08;
2963 if (spec->gpio_led != oldval)
2964 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2965 spec->gpio_led);
2966 }
2967
2968 /* turn on/off mic-mute LED per capture hook */
2969 static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec,
2970 struct snd_ctl_elem_value *ucontrol)
2971 {
2972 struct alc_spec *spec = codec->spec;
2973 unsigned int oldval = spec->gpio_led;
2974
2975 if (!ucontrol)
2976 return;
2977
2978 if (ucontrol->value.integer.value[0] ||
2979 ucontrol->value.integer.value[1])
2980 spec->gpio_led &= ~0x10;
2981 else
2982 spec->gpio_led |= 0x10;
2983 if (spec->gpio_led != oldval)
2984 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2985 spec->gpio_led);
2986 }
2987
2988 static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
2989 const struct hda_fixup *fix, int action)
2990 {
2991 struct alc_spec *spec = codec->spec;
2992 static const struct hda_verb gpio_init[] = {
2993 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
2994 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
2995 {}
2996 };
2997
2998 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2999 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook;
3000 spec->gen.cap_sync_hook = alc269_fixup_hp_gpio_mic_mute_hook;
3001 spec->gpio_led = 0;
3002 snd_hda_add_verbs(codec, gpio_init);
3003 }
3004 }
3005
3006 static void alc_headset_mode_unplugged(struct hda_codec *codec)
3007 {
3008 int val;
3009
3010 switch (codec->vendor_id) {
3011 case 0x10ec0283:
3012 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3013 alc_write_coef_idx(codec, 0x45, 0xc429);
3014 val = alc_read_coef_idx(codec, 0x35);
3015 alc_write_coef_idx(codec, 0x35, val & 0xbfff);
3016 alc_write_coef_idx(codec, 0x06, 0x2104);
3017 alc_write_coef_idx(codec, 0x1a, 0x0001);
3018 alc_write_coef_idx(codec, 0x26, 0x0004);
3019 alc_write_coef_idx(codec, 0x32, 0x42a3);
3020 break;
3021 case 0x10ec0292:
3022 alc_write_coef_idx(codec, 0x76, 0x000e);
3023 alc_write_coef_idx(codec, 0x6c, 0x2400);
3024 alc_write_coef_idx(codec, 0x18, 0x7308);
3025 alc_write_coef_idx(codec, 0x6b, 0xc429);
3026 break;
3027 case 0x10ec0668:
3028 alc_write_coef_idx(codec, 0x15, 0x0d40);
3029 alc_write_coef_idx(codec, 0xb7, 0x802b);
3030 break;
3031 }
3032 snd_printdd("Headset jack set to unplugged mode.\n");
3033 }
3034
3035
3036 static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3037 hda_nid_t mic_pin)
3038 {
3039 int val;
3040
3041 switch (codec->vendor_id) {
3042 case 0x10ec0283:
3043 alc_write_coef_idx(codec, 0x45, 0xc429);
3044 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3045 val = alc_read_coef_idx(codec, 0x35);
3046 alc_write_coef_idx(codec, 0x35, val | 1<<14);
3047 alc_write_coef_idx(codec, 0x06, 0x2100);
3048 alc_write_coef_idx(codec, 0x1a, 0x0021);
3049 alc_write_coef_idx(codec, 0x26, 0x008c);
3050 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3051 break;
3052 case 0x10ec0292:
3053 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3054 alc_write_coef_idx(codec, 0x19, 0xa208);
3055 alc_write_coef_idx(codec, 0x2e, 0xacf0);
3056 break;
3057 case 0x10ec0668:
3058 alc_write_coef_idx(codec, 0x11, 0x0001);
3059 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3060 alc_write_coef_idx(codec, 0xb7, 0x802b);
3061 alc_write_coef_idx(codec, 0xb5, 0x1040);
3062 val = alc_read_coef_idx(codec, 0xc3);
3063 alc_write_coef_idx(codec, 0xc3, val | 1<<12);
3064 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3065 break;
3066 }
3067 snd_printdd("Headset jack set to mic-in mode.\n");
3068 }
3069
3070 static void alc_headset_mode_default(struct hda_codec *codec)
3071 {
3072 switch (codec->vendor_id) {
3073 case 0x10ec0283:
3074 alc_write_coef_idx(codec, 0x06, 0x2100);
3075 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3076 break;
3077 case 0x10ec0292:
3078 alc_write_coef_idx(codec, 0x76, 0x000e);
3079 alc_write_coef_idx(codec, 0x6c, 0x2400);
3080 alc_write_coef_idx(codec, 0x6b, 0xc429);
3081 alc_write_coef_idx(codec, 0x18, 0x7308);
3082 break;
3083 case 0x10ec0668:
3084 alc_write_coef_idx(codec, 0x11, 0x0041);
3085 alc_write_coef_idx(codec, 0x15, 0x0d40);
3086 alc_write_coef_idx(codec, 0xb7, 0x802b);
3087 break;
3088 }
3089 snd_printdd("Headset jack set to headphone (default) mode.\n");
3090 }
3091
3092 /* Iphone type */
3093 static void alc_headset_mode_ctia(struct hda_codec *codec)
3094 {
3095 switch (codec->vendor_id) {
3096 case 0x10ec0283:
3097 alc_write_coef_idx(codec, 0x45, 0xd429);
3098 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3099 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3100 break;
3101 case 0x10ec0292:
3102 alc_write_coef_idx(codec, 0x6b, 0xd429);
3103 alc_write_coef_idx(codec, 0x76, 0x0008);
3104 alc_write_coef_idx(codec, 0x18, 0x7388);
3105 break;
3106 case 0x10ec0668:
3107 alc_write_coef_idx(codec, 0x11, 0x0001);
3108 alc_write_coef_idx(codec, 0x15, 0x0d60);
3109 alc_write_coef_idx(codec, 0xc3, 0x0000);
3110 break;
3111 }
3112 snd_printdd("Headset jack set to iPhone-style headset mode.\n");
3113 }
3114
3115 /* Nokia type */
3116 static void alc_headset_mode_omtp(struct hda_codec *codec)
3117 {
3118 switch (codec->vendor_id) {
3119 case 0x10ec0283:
3120 alc_write_coef_idx(codec, 0x45, 0xe429);
3121 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3122 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3123 break;
3124 case 0x10ec0292:
3125 alc_write_coef_idx(codec, 0x6b, 0xe429);
3126 alc_write_coef_idx(codec, 0x76, 0x0008);
3127 alc_write_coef_idx(codec, 0x18, 0x7388);
3128 break;
3129 case 0x10ec0668:
3130 alc_write_coef_idx(codec, 0x11, 0x0001);
3131 alc_write_coef_idx(codec, 0x15, 0x0d50);
3132 alc_write_coef_idx(codec, 0xc3, 0x0000);
3133 break;
3134 }
3135 snd_printdd("Headset jack set to Nokia-style headset mode.\n");
3136 }
3137
3138 static void alc_determine_headset_type(struct hda_codec *codec)
3139 {
3140 int val;
3141 bool is_ctia = false;
3142 struct alc_spec *spec = codec->spec;
3143
3144 switch (codec->vendor_id) {
3145 case 0x10ec0283:
3146 alc_write_coef_idx(codec, 0x45, 0xd029);
3147 msleep(300);
3148 val = alc_read_coef_idx(codec, 0x46);
3149 is_ctia = (val & 0x0070) == 0x0070;
3150 break;
3151 case 0x10ec0292:
3152 alc_write_coef_idx(codec, 0x6b, 0xd429);
3153 msleep(300);
3154 val = alc_read_coef_idx(codec, 0x6c);
3155 is_ctia = (val & 0x001c) == 0x001c;
3156 break;
3157 case 0x10ec0668:
3158 alc_write_coef_idx(codec, 0x11, 0x0001);
3159 alc_write_coef_idx(codec, 0xb7, 0x802b);
3160 alc_write_coef_idx(codec, 0x15, 0x0d60);
3161 alc_write_coef_idx(codec, 0xc3, 0x0c00);
3162 msleep(300);
3163 val = alc_read_coef_idx(codec, 0xbe);
3164 is_ctia = (val & 0x1c02) == 0x1c02;
3165 break;
3166 }
3167
3168 snd_printdd("Headset jack detected iPhone-style headset: %s\n",
3169 is_ctia ? "yes" : "no");
3170 spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3171 }
3172
3173 static void alc_update_headset_mode(struct hda_codec *codec)
3174 {
3175 struct alc_spec *spec = codec->spec;
3176
3177 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
3178 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3179
3180 int new_headset_mode;
3181
3182 if (!snd_hda_jack_detect(codec, hp_pin))
3183 new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
3184 else if (mux_pin == spec->headset_mic_pin)
3185 new_headset_mode = ALC_HEADSET_MODE_HEADSET;
3186 else if (mux_pin == spec->headphone_mic_pin)
3187 new_headset_mode = ALC_HEADSET_MODE_MIC;
3188 else
3189 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3190
3191 if (new_headset_mode == spec->current_headset_mode) {
3192 snd_hda_gen_update_outputs(codec);
3193 return;
3194 }
3195
3196 switch (new_headset_mode) {
3197 case ALC_HEADSET_MODE_UNPLUGGED:
3198 alc_headset_mode_unplugged(codec);
3199 spec->gen.hp_jack_present = false;
3200 break;
3201 case ALC_HEADSET_MODE_HEADSET:
3202 if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
3203 alc_determine_headset_type(codec);
3204 if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
3205 alc_headset_mode_ctia(codec);
3206 else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
3207 alc_headset_mode_omtp(codec);
3208 spec->gen.hp_jack_present = true;
3209 break;
3210 case ALC_HEADSET_MODE_MIC:
3211 alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
3212 spec->gen.hp_jack_present = false;
3213 break;
3214 case ALC_HEADSET_MODE_HEADPHONE:
3215 alc_headset_mode_default(codec);
3216 spec->gen.hp_jack_present = true;
3217 break;
3218 }
3219 if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
3220 snd_hda_set_pin_ctl_cache(codec, hp_pin,
3221 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3222 if (spec->headphone_mic_pin)
3223 snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
3224 PIN_VREFHIZ);
3225 }
3226 spec->current_headset_mode = new_headset_mode;
3227
3228 snd_hda_gen_update_outputs(codec);
3229 }
3230
3231 static void alc_update_headset_mode_hook(struct hda_codec *codec,
3232 struct snd_ctl_elem_value *ucontrol)
3233 {
3234 alc_update_headset_mode(codec);
3235 }
3236
3237 static void alc_update_headset_jack_cb(struct hda_codec *codec, struct hda_jack_tbl *jack)
3238 {
3239 struct alc_spec *spec = codec->spec;
3240 spec->current_headset_type = ALC_HEADSET_MODE_UNKNOWN;
3241 snd_hda_gen_hp_automute(codec, jack);
3242 }
3243
3244 static void alc_probe_headset_mode(struct hda_codec *codec)
3245 {
3246 int i;
3247 struct alc_spec *spec = codec->spec;
3248 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3249
3250 /* Find mic pins */
3251 for (i = 0; i < cfg->num_inputs; i++) {
3252 if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
3253 spec->headset_mic_pin = cfg->inputs[i].pin;
3254 if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
3255 spec->headphone_mic_pin = cfg->inputs[i].pin;
3256 }
3257
3258 spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
3259 spec->gen.automute_hook = alc_update_headset_mode;
3260 spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
3261 }
3262
3263 static void alc_fixup_headset_mode(struct hda_codec *codec,
3264 const struct hda_fixup *fix, int action)
3265 {
3266 struct alc_spec *spec = codec->spec;
3267
3268 switch (action) {
3269 case HDA_FIXUP_ACT_PRE_PROBE:
3270 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
3271 break;
3272 case HDA_FIXUP_ACT_PROBE:
3273 alc_probe_headset_mode(codec);
3274 break;
3275 case HDA_FIXUP_ACT_INIT:
3276 spec->current_headset_mode = 0;
3277 alc_update_headset_mode(codec);
3278 break;
3279 }
3280 }
3281
3282 static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3283 const struct hda_fixup *fix, int action)
3284 {
3285 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3286 struct alc_spec *spec = codec->spec;
3287 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3288 }
3289 else
3290 alc_fixup_headset_mode(codec, fix, action);
3291 }
3292
3293 static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3294 const struct hda_fixup *fix, int action)
3295 {
3296 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3297 int val;
3298 alc_write_coef_idx(codec, 0xc4, 0x8000);
3299 val = alc_read_coef_idx(codec, 0xc2);
3300 alc_write_coef_idx(codec, 0xc2, val & 0xfe);
3301 snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
3302 }
3303 alc_fixup_headset_mode(codec, fix, action);
3304 }
3305
3306 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
3307 const struct hda_fixup *fix,
3308 int action)
3309 {
3310 struct alc_spec *spec = codec->spec;
3311
3312 if (action == HDA_FIXUP_ACT_PROBE) {
3313 if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
3314 !spec->gen.autocfg.hp_pins[0]))
3315 return;
3316 snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
3317 spec->gen.autocfg.hp_pins[0]);
3318 }
3319 }
3320
3321 static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
3322 const struct hda_fixup *fix,
3323 int action)
3324 {
3325 struct alc_spec *spec = codec->spec;
3326 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3327 int i;
3328
3329 /* The mic boosts on level 2 and 3 are too noisy
3330 on the internal mic input.
3331 Therefore limit the boost to 0 or 1. */
3332
3333 if (action != HDA_FIXUP_ACT_PROBE)
3334 return;
3335
3336 for (i = 0; i < cfg->num_inputs; i++) {
3337 hda_nid_t nid = cfg->inputs[i].pin;
3338 unsigned int defcfg;
3339 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3340 continue;
3341 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3342 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
3343 continue;
3344
3345 snd_hda_override_amp_caps(codec, nid, HDA_INPUT,
3346 (0x00 << AC_AMPCAP_OFFSET_SHIFT) |
3347 (0x01 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3348 (0x2f << AC_AMPCAP_STEP_SIZE_SHIFT) |
3349 (0 << AC_AMPCAP_MUTE_SHIFT));
3350 }
3351 }
3352
3353 static void alc290_fixup_mono_speakers(struct hda_codec *codec,
3354 const struct hda_fixup *fix, int action)
3355 {
3356 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3357 /* Remove DAC node 0x03, as it seems to be
3358 giving mono output */
3359 snd_hda_override_wcaps(codec, 0x03, 0);
3360 }
3361
3362 enum {
3363 ALC269_FIXUP_SONY_VAIO,
3364 ALC275_FIXUP_SONY_VAIO_GPIO2,
3365 ALC269_FIXUP_DELL_M101Z,
3366 ALC269_FIXUP_SKU_IGNORE,
3367 ALC269_FIXUP_ASUS_G73JW,
3368 ALC269_FIXUP_LENOVO_EAPD,
3369 ALC275_FIXUP_SONY_HWEQ,
3370 ALC271_FIXUP_DMIC,
3371 ALC269_FIXUP_PCM_44K,
3372 ALC269_FIXUP_STEREO_DMIC,
3373 ALC269_FIXUP_QUANTA_MUTE,
3374 ALC269_FIXUP_LIFEBOOK,
3375 ALC269_FIXUP_LIFEBOOK_EXTMIC,
3376 ALC269_FIXUP_LIFEBOOK_HP_PIN,
3377 ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT,
3378 ALC269_FIXUP_AMIC,
3379 ALC269_FIXUP_DMIC,
3380 ALC269VB_FIXUP_AMIC,
3381 ALC269VB_FIXUP_DMIC,
3382 ALC269_FIXUP_HP_MUTE_LED,
3383 ALC269_FIXUP_HP_MUTE_LED_MIC1,
3384 ALC269_FIXUP_HP_MUTE_LED_MIC2,
3385 ALC269_FIXUP_HP_GPIO_LED,
3386 ALC269_FIXUP_INV_DMIC,
3387 ALC269_FIXUP_LENOVO_DOCK,
3388 ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
3389 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
3390 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
3391 ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
3392 ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
3393 ALC290_FIXUP_MONO_SPEAKERS,
3394 ALC269_FIXUP_HEADSET_MODE,
3395 ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
3396 ALC269_FIXUP_ASPIRE_HEADSET_MIC,
3397 ALC269_FIXUP_ASUS_X101_FUNC,
3398 ALC269_FIXUP_ASUS_X101_VERB,
3399 ALC269_FIXUP_ASUS_X101,
3400 ALC271_FIXUP_AMIC_MIC2,
3401 ALC271_FIXUP_HP_GATE_MIC_JACK,
3402 ALC269_FIXUP_ACER_AC700,
3403 ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
3404 };
3405
3406 static const struct hda_fixup alc269_fixups[] = {
3407 [ALC269_FIXUP_SONY_VAIO] = {
3408 .type = HDA_FIXUP_PINCTLS,
3409 .v.pins = (const struct hda_pintbl[]) {
3410 {0x19, PIN_VREFGRD},
3411 {}
3412 }
3413 },
3414 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
3415 .type = HDA_FIXUP_VERBS,
3416 .v.verbs = (const struct hda_verb[]) {
3417 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
3418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
3419 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
3420 { }
3421 },
3422 .chained = true,
3423 .chain_id = ALC269_FIXUP_SONY_VAIO
3424 },
3425 [ALC269_FIXUP_DELL_M101Z] = {
3426 .type = HDA_FIXUP_VERBS,
3427 .v.verbs = (const struct hda_verb[]) {
3428 /* Enables internal speaker */
3429 {0x20, AC_VERB_SET_COEF_INDEX, 13},
3430 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
3431 {}
3432 }
3433 },
3434 [ALC269_FIXUP_SKU_IGNORE] = {
3435 .type = HDA_FIXUP_FUNC,
3436 .v.func = alc_fixup_sku_ignore,
3437 },
3438 [ALC269_FIXUP_ASUS_G73JW] = {
3439 .type = HDA_FIXUP_PINS,
3440 .v.pins = (const struct hda_pintbl[]) {
3441 { 0x17, 0x99130111 }, /* subwoofer */
3442 { }
3443 }
3444 },
3445 [ALC269_FIXUP_LENOVO_EAPD] = {
3446 .type = HDA_FIXUP_VERBS,
3447 .v.verbs = (const struct hda_verb[]) {
3448 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
3449 {}
3450 }
3451 },
3452 [ALC275_FIXUP_SONY_HWEQ] = {
3453 .type = HDA_FIXUP_FUNC,
3454 .v.func = alc269_fixup_hweq,
3455 .chained = true,
3456 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
3457 },
3458 [ALC271_FIXUP_DMIC] = {
3459 .type = HDA_FIXUP_FUNC,
3460 .v.func = alc271_fixup_dmic,
3461 },
3462 [ALC269_FIXUP_PCM_44K] = {
3463 .type = HDA_FIXUP_FUNC,
3464 .v.func = alc269_fixup_pcm_44k,
3465 .chained = true,
3466 .chain_id = ALC269_FIXUP_QUANTA_MUTE
3467 },
3468 [ALC269_FIXUP_STEREO_DMIC] = {
3469 .type = HDA_FIXUP_FUNC,
3470 .v.func = alc269_fixup_stereo_dmic,
3471 },
3472 [ALC269_FIXUP_QUANTA_MUTE] = {
3473 .type = HDA_FIXUP_FUNC,
3474 .v.func = alc269_fixup_quanta_mute,
3475 },
3476 [ALC269_FIXUP_LIFEBOOK] = {
3477 .type = HDA_FIXUP_PINS,
3478 .v.pins = (const struct hda_pintbl[]) {
3479 { 0x1a, 0x2101103f }, /* dock line-out */
3480 { 0x1b, 0x23a11040 }, /* dock mic-in */
3481 { }
3482 },
3483 .chained = true,
3484 .chain_id = ALC269_FIXUP_QUANTA_MUTE
3485 },
3486 [ALC269_FIXUP_LIFEBOOK_EXTMIC] = {
3487 .type = HDA_FIXUP_PINS,
3488 .v.pins = (const struct hda_pintbl[]) {
3489 { 0x19, 0x01a1903c }, /* headset mic, with jack detect */
3490 { }
3491 },
3492 },
3493 [ALC269_FIXUP_LIFEBOOK_HP_PIN] = {
3494 .type = HDA_FIXUP_PINS,
3495 .v.pins = (const struct hda_pintbl[]) {
3496 { 0x21, 0x0221102f }, /* HP out */
3497 { }
3498 },
3499 },
3500 [ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT] = {
3501 .type = HDA_FIXUP_FUNC,
3502 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
3503 },
3504 [ALC269_FIXUP_AMIC] = {
3505 .type = HDA_FIXUP_PINS,
3506 .v.pins = (const struct hda_pintbl[]) {
3507 { 0x14, 0x99130110 }, /* speaker */
3508 { 0x15, 0x0121401f }, /* HP out */
3509 { 0x18, 0x01a19c20 }, /* mic */
3510 { 0x19, 0x99a3092f }, /* int-mic */
3511 { }
3512 },
3513 },
3514 [ALC269_FIXUP_DMIC] = {
3515 .type = HDA_FIXUP_PINS,
3516 .v.pins = (const struct hda_pintbl[]) {
3517 { 0x12, 0x99a3092f }, /* int-mic */
3518 { 0x14, 0x99130110 }, /* speaker */
3519 { 0x15, 0x0121401f }, /* HP out */
3520 { 0x18, 0x01a19c20 }, /* mic */
3521 { }
3522 },
3523 },
3524 [ALC269VB_FIXUP_AMIC] = {
3525 .type = HDA_FIXUP_PINS,
3526 .v.pins = (const struct hda_pintbl[]) {
3527 { 0x14, 0x99130110 }, /* speaker */
3528 { 0x18, 0x01a19c20 }, /* mic */
3529 { 0x19, 0x99a3092f }, /* int-mic */
3530 { 0x21, 0x0121401f }, /* HP out */
3531 { }
3532 },
3533 },
3534 [ALC269VB_FIXUP_DMIC] = {
3535 .type = HDA_FIXUP_PINS,
3536 .v.pins = (const struct hda_pintbl[]) {
3537 { 0x12, 0x99a3092f }, /* int-mic */
3538 { 0x14, 0x99130110 }, /* speaker */
3539 { 0x18, 0x01a19c20 }, /* mic */
3540 { 0x21, 0x0121401f }, /* HP out */
3541 { }
3542 },
3543 },
3544 [ALC269_FIXUP_HP_MUTE_LED] = {
3545 .type = HDA_FIXUP_FUNC,
3546 .v.func = alc269_fixup_hp_mute_led,
3547 },
3548 [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
3549 .type = HDA_FIXUP_FUNC,
3550 .v.func = alc269_fixup_hp_mute_led_mic1,
3551 },
3552 [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
3553 .type = HDA_FIXUP_FUNC,
3554 .v.func = alc269_fixup_hp_mute_led_mic2,
3555 },
3556 [ALC269_FIXUP_HP_GPIO_LED] = {
3557 .type = HDA_FIXUP_FUNC,
3558 .v.func = alc269_fixup_hp_gpio_led,
3559 },
3560 [ALC269_FIXUP_INV_DMIC] = {
3561 .type = HDA_FIXUP_FUNC,
3562 .v.func = alc_fixup_inv_dmic_0x12,
3563 },
3564 [ALC269_FIXUP_LENOVO_DOCK] = {
3565 .type = HDA_FIXUP_PINS,
3566 .v.pins = (const struct hda_pintbl[]) {
3567 { 0x19, 0x23a11040 }, /* dock mic */
3568 { 0x1b, 0x2121103f }, /* dock headphone */
3569 { }
3570 },
3571 .chained = true,
3572 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
3573 },
3574 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
3575 .type = HDA_FIXUP_FUNC,
3576 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
3577 },
3578 [ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
3579 .type = HDA_FIXUP_PINS,
3580 .v.pins = (const struct hda_pintbl[]) {
3581 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3582 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
3583 { }
3584 },
3585 .chained = true,
3586 .chain_id = ALC269_FIXUP_HEADSET_MODE
3587 },
3588 [ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
3589 .type = HDA_FIXUP_PINS,
3590 .v.pins = (const struct hda_pintbl[]) {
3591 { 0x16, 0x21014020 }, /* dock line out */
3592 { 0x19, 0x21a19030 }, /* dock mic */
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_DELL3_MIC_NO_PRESENCE] = {
3600 .type = HDA_FIXUP_PINS,
3601 .v.pins = (const struct hda_pintbl[]) {
3602 { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3603 { }
3604 },
3605 .chained = true,
3606 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3607 },
3608 [ALC269_FIXUP_HEADSET_MODE] = {
3609 .type = HDA_FIXUP_FUNC,
3610 .v.func = alc_fixup_headset_mode,
3611 },
3612 [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
3613 .type = HDA_FIXUP_FUNC,
3614 .v.func = alc_fixup_headset_mode_no_hp_mic,
3615 },
3616 [ALC269_FIXUP_ASPIRE_HEADSET_MIC] = {
3617 .type = HDA_FIXUP_PINS,
3618 .v.pins = (const struct hda_pintbl[]) {
3619 { 0x19, 0x01a1913c }, /* headset mic w/o jack detect */
3620 { }
3621 },
3622 .chained = true,
3623 .chain_id = ALC269_FIXUP_HEADSET_MODE,
3624 },
3625 [ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
3626 .type = HDA_FIXUP_PINS,
3627 .v.pins = (const struct hda_pintbl[]) {
3628 { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3629 { }
3630 },
3631 },
3632 [ALC269_FIXUP_ASUS_X101_FUNC] = {
3633 .type = HDA_FIXUP_FUNC,
3634 .v.func = alc269_fixup_x101_headset_mic,
3635 },
3636 [ALC269_FIXUP_ASUS_X101_VERB] = {
3637 .type = HDA_FIXUP_VERBS,
3638 .v.verbs = (const struct hda_verb[]) {
3639 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3640 {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
3641 {0x20, AC_VERB_SET_PROC_COEF, 0x0310},
3642 { }
3643 },
3644 .chained = true,
3645 .chain_id = ALC269_FIXUP_ASUS_X101_FUNC
3646 },
3647 [ALC269_FIXUP_ASUS_X101] = {
3648 .type = HDA_FIXUP_PINS,
3649 .v.pins = (const struct hda_pintbl[]) {
3650 { 0x18, 0x04a1182c }, /* Headset mic */
3651 { }
3652 },
3653 .chained = true,
3654 .chain_id = ALC269_FIXUP_ASUS_X101_VERB
3655 },
3656 [ALC271_FIXUP_AMIC_MIC2] = {
3657 .type = HDA_FIXUP_PINS,
3658 .v.pins = (const struct hda_pintbl[]) {
3659 { 0x14, 0x99130110 }, /* speaker */
3660 { 0x19, 0x01a19c20 }, /* mic */
3661 { 0x1b, 0x99a7012f }, /* int-mic */
3662 { 0x21, 0x0121401f }, /* HP out */
3663 { }
3664 },
3665 },
3666 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
3667 .type = HDA_FIXUP_FUNC,
3668 .v.func = alc271_hp_gate_mic_jack,
3669 .chained = true,
3670 .chain_id = ALC271_FIXUP_AMIC_MIC2,
3671 },
3672 [ALC269_FIXUP_ACER_AC700] = {
3673 .type = HDA_FIXUP_PINS,
3674 .v.pins = (const struct hda_pintbl[]) {
3675 { 0x12, 0x99a3092f }, /* int-mic */
3676 { 0x14, 0x99130110 }, /* speaker */
3677 { 0x18, 0x03a11c20 }, /* mic */
3678 { 0x1e, 0x0346101e }, /* SPDIF1 */
3679 { 0x21, 0x0321101f }, /* HP out */
3680 { }
3681 },
3682 .chained = true,
3683 .chain_id = ALC271_FIXUP_DMIC,
3684 },
3685 [ALC269_FIXUP_LIMIT_INT_MIC_BOOST] = {
3686 .type = HDA_FIXUP_FUNC,
3687 .v.func = alc269_fixup_limit_int_mic_boost,
3688 },
3689 [ALC290_FIXUP_MONO_SPEAKERS] = {
3690 .type = HDA_FIXUP_FUNC,
3691 .v.func = alc290_fixup_mono_speakers,
3692 .chained = true,
3693 .chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
3694 },
3695 };
3696
3697 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3698 SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
3699 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
3700 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
3701 SND_PCI_QUIRK(0x1028, 0x05bd, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3702 SND_PCI_QUIRK(0x1028, 0x05be, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3703 SND_PCI_QUIRK(0x1028, 0x05c4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3704 SND_PCI_QUIRK(0x1028, 0x05c5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3705 SND_PCI_QUIRK(0x1028, 0x05c6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3706 SND_PCI_QUIRK(0x1028, 0x05c7, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3707 SND_PCI_QUIRK(0x1028, 0x05c8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3708 SND_PCI_QUIRK(0x1028, 0x05c9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3709 SND_PCI_QUIRK(0x1028, 0x05ca, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3710 SND_PCI_QUIRK(0x1028, 0x05cb, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3711 SND_PCI_QUIRK(0x1028, 0x05de, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3712 SND_PCI_QUIRK(0x1028, 0x05e0, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3713 SND_PCI_QUIRK(0x1028, 0x05e9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3714 SND_PCI_QUIRK(0x1028, 0x05ea, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3715 SND_PCI_QUIRK(0x1028, 0x05eb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3716 SND_PCI_QUIRK(0x1028, 0x05ec, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3717 SND_PCI_QUIRK(0x1028, 0x05ed, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3718 SND_PCI_QUIRK(0x1028, 0x05ee, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3719 SND_PCI_QUIRK(0x1028, 0x05f3, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3720 SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3721 SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3722 SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3723 SND_PCI_QUIRK(0x1028, 0x05f8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3724 SND_PCI_QUIRK(0x1028, 0x05f9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3725 SND_PCI_QUIRK(0x1028, 0x05fb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3726 SND_PCI_QUIRK(0x1028, 0x0606, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3727 SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3728 SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3729 SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3730 SND_PCI_QUIRK(0x1028, 0x0614, "Dell Inspiron 3135", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3731 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_MONO_SPEAKERS),
3732 SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS),
3733 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
3734 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
3735 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
3736 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
3737 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
3738 SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3739 SND_PCI_QUIRK(0x1043, 0x115d, "Asus 1015E", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3740 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
3741 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
3742 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
3743 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
3744 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
3745 SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3746 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
3747 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
3748 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3749 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3750 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
3751 SND_PCI_QUIRK(0x104d, 0x90b5, "Sony VAIO Pro 11", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
3752 SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
3753 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
3754 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
3755 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
3756 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
3757 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
3758 SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
3759 SND_PCI_QUIRK(0x1025, 0x072d, "Acer Aspire V5-571G", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
3760 SND_PCI_QUIRK(0x1025, 0x080d, "Acer Aspire V5-122P", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
3761 SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
3762 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
3763 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
3764 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
3765 SND_PCI_QUIRK(0x10cf, 0x159f, "Lifebook E780", ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT),
3766 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
3767 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
3768 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
3769 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
3770 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
3771 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
3772 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
3773 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
3774 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
3775 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
3776 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
3777 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
3778 SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
3779 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
3780 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
3781 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
3782
3783 #if 0
3784 /* Below is a quirk table taken from the old code.
3785 * Basically the device should work as is without the fixup table.
3786 * If BIOS doesn't give a proper info, enable the corresponding
3787 * fixup entry.
3788 */
3789 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
3790 ALC269_FIXUP_AMIC),
3791 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
3792 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
3793 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
3794 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
3795 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
3796 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
3797 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
3798 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
3799 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
3800 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
3801 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
3802 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
3803 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
3804 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
3805 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
3806 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
3807 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
3808 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
3809 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
3810 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
3811 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
3812 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
3813 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
3814 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
3815 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
3816 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
3817 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
3818 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
3819 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
3820 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
3821 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
3822 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
3823 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
3824 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
3825 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
3826 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
3827 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
3828 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
3829 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
3830 #endif
3831 {}
3832 };
3833
3834 static const struct hda_model_fixup alc269_fixup_models[] = {
3835 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
3836 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
3837 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
3838 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
3839 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
3840 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
3841 {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
3842 {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
3843 {.id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "dell-headset-dock"},
3844 {}
3845 };
3846
3847
3848 static void alc269_fill_coef(struct hda_codec *codec)
3849 {
3850 struct alc_spec *spec = codec->spec;
3851 int val;
3852
3853 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
3854 return;
3855
3856 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
3857 alc_write_coef_idx(codec, 0xf, 0x960b);
3858 alc_write_coef_idx(codec, 0xe, 0x8817);
3859 }
3860
3861 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
3862 alc_write_coef_idx(codec, 0xf, 0x960b);
3863 alc_write_coef_idx(codec, 0xe, 0x8814);
3864 }
3865
3866 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
3867 val = alc_read_coef_idx(codec, 0x04);
3868 /* Power up output pin */
3869 if (val != -1)
3870 alc_write_coef_idx(codec, 0x04, val | (1<<11));
3871 }
3872
3873 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
3874 val = alc_read_coef_idx(codec, 0xd);
3875 if (val != -1 && (val & 0x0c00) >> 10 != 0x1) {
3876 /* Capless ramp up clock control */
3877 alc_write_coef_idx(codec, 0xd, val | (1<<10));
3878 }
3879 val = alc_read_coef_idx(codec, 0x17);
3880 if (val != -1 && (val & 0x01c0) >> 6 != 0x4) {
3881 /* Class D power on reset */
3882 alc_write_coef_idx(codec, 0x17, val | (1<<7));
3883 }
3884 }
3885
3886 val = alc_read_coef_idx(codec, 0xd); /* Class D */
3887 if (val != -1)
3888 alc_write_coef_idx(codec, 0xd, val | (1<<14));
3889
3890 val = alc_read_coef_idx(codec, 0x4); /* HP */
3891 if (val != -1)
3892 alc_write_coef_idx(codec, 0x4, val | (1<<11));
3893 }
3894
3895 /*
3896 */
3897 static int patch_alc269(struct hda_codec *codec)
3898 {
3899 struct alc_spec *spec;
3900 int err;
3901
3902 err = alc_alloc_spec(codec, 0x0b);
3903 if (err < 0)
3904 return err;
3905
3906 spec = codec->spec;
3907 spec->gen.shared_mic_vref_pin = 0x18;
3908
3909 snd_hda_pick_fixup(codec, alc269_fixup_models,
3910 alc269_fixup_tbl, alc269_fixups);
3911 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3912
3913 alc_auto_parse_customize_define(codec);
3914
3915 if (has_cdefine_beep(codec))
3916 spec->gen.beep_nid = 0x01;
3917
3918 switch (codec->vendor_id) {
3919 case 0x10ec0269:
3920 spec->codec_variant = ALC269_TYPE_ALC269VA;
3921 switch (alc_get_coef0(codec) & 0x00f0) {
3922 case 0x0010:
3923 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
3924 spec->cdefine.platform_type == 1)
3925 err = alc_codec_rename(codec, "ALC271X");
3926 spec->codec_variant = ALC269_TYPE_ALC269VB;
3927 break;
3928 case 0x0020:
3929 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
3930 codec->bus->pci->subsystem_device == 0x21f3)
3931 err = alc_codec_rename(codec, "ALC3202");
3932 spec->codec_variant = ALC269_TYPE_ALC269VC;
3933 break;
3934 case 0x0030:
3935 spec->codec_variant = ALC269_TYPE_ALC269VD;
3936 break;
3937 default:
3938 alc_fix_pll_init(codec, 0x20, 0x04, 15);
3939 }
3940 if (err < 0)
3941 goto error;
3942 spec->init_hook = alc269_fill_coef;
3943 alc269_fill_coef(codec);
3944 break;
3945
3946 case 0x10ec0280:
3947 case 0x10ec0290:
3948 spec->codec_variant = ALC269_TYPE_ALC280;
3949 break;
3950 case 0x10ec0233:
3951 case 0x10ec0282:
3952 case 0x10ec0283:
3953 spec->codec_variant = ALC269_TYPE_ALC282;
3954 break;
3955 case 0x10ec0284:
3956 case 0x10ec0292:
3957 spec->codec_variant = ALC269_TYPE_ALC284;
3958 break;
3959 case 0x10ec0286:
3960 case 0x10ec0288:
3961 spec->codec_variant = ALC269_TYPE_ALC286;
3962 break;
3963 case 0x10ec0255:
3964 spec->codec_variant = ALC269_TYPE_ALC255;
3965 break;
3966 }
3967
3968 /* automatic parse from the BIOS config */
3969 err = alc269_parse_auto_config(codec);
3970 if (err < 0)
3971 goto error;
3972
3973 if (!spec->gen.no_analog && spec->gen.beep_nid)
3974 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
3975
3976 codec->patch_ops = alc_patch_ops;
3977 #ifdef CONFIG_PM
3978 codec->patch_ops.resume = alc269_resume;
3979 #endif
3980 spec->shutup = alc269_shutup;
3981
3982 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3983
3984 return 0;
3985
3986 error:
3987 alc_free(codec);
3988 return err;
3989 }
3990
3991 /*
3992 * ALC861
3993 */
3994
3995 static int alc861_parse_auto_config(struct hda_codec *codec)
3996 {
3997 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
3998 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
3999 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
4000 }
4001
4002 /* Pin config fixes */
4003 enum {
4004 ALC861_FIXUP_FSC_AMILO_PI1505,
4005 ALC861_FIXUP_AMP_VREF_0F,
4006 ALC861_FIXUP_NO_JACK_DETECT,
4007 ALC861_FIXUP_ASUS_A6RP,
4008 ALC660_FIXUP_ASUS_W7J,
4009 };
4010
4011 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
4012 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
4013 const struct hda_fixup *fix, int action)
4014 {
4015 struct alc_spec *spec = codec->spec;
4016 unsigned int val;
4017
4018 if (action != HDA_FIXUP_ACT_INIT)
4019 return;
4020 val = snd_hda_codec_get_pin_target(codec, 0x0f);
4021 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
4022 val |= AC_PINCTL_IN_EN;
4023 val |= AC_PINCTL_VREF_50;
4024 snd_hda_set_pin_ctl(codec, 0x0f, val);
4025 spec->gen.keep_vref_in_automute = 1;
4026 }
4027
4028 /* suppress the jack-detection */
4029 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
4030 const struct hda_fixup *fix, int action)
4031 {
4032 if (action == HDA_FIXUP_ACT_PRE_PROBE)
4033 codec->no_jack_detect = 1;
4034 }
4035
4036 static const struct hda_fixup alc861_fixups[] = {
4037 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
4038 .type = HDA_FIXUP_PINS,
4039 .v.pins = (const struct hda_pintbl[]) {
4040 { 0x0b, 0x0221101f }, /* HP */
4041 { 0x0f, 0x90170310 }, /* speaker */
4042 { }
4043 }
4044 },
4045 [ALC861_FIXUP_AMP_VREF_0F] = {
4046 .type = HDA_FIXUP_FUNC,
4047 .v.func = alc861_fixup_asus_amp_vref_0f,
4048 },
4049 [ALC861_FIXUP_NO_JACK_DETECT] = {
4050 .type = HDA_FIXUP_FUNC,
4051 .v.func = alc_fixup_no_jack_detect,
4052 },
4053 [ALC861_FIXUP_ASUS_A6RP] = {
4054 .type = HDA_FIXUP_FUNC,
4055 .v.func = alc861_fixup_asus_amp_vref_0f,
4056 .chained = true,
4057 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
4058 },
4059 [ALC660_FIXUP_ASUS_W7J] = {
4060 .type = HDA_FIXUP_VERBS,
4061 .v.verbs = (const struct hda_verb[]) {
4062 /* ASUS W7J needs a magic pin setup on unused NID 0x10
4063 * for enabling outputs
4064 */
4065 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4066 { }
4067 },
4068 }
4069 };
4070
4071 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4072 SND_PCI_QUIRK(0x1043, 0x1253, "ASUS W7J", ALC660_FIXUP_ASUS_W7J),
4073 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS Z35HL", ALC660_FIXUP_ASUS_W7J),
4074 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
4075 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
4076 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
4077 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
4078 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
4079 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
4080 {}
4081 };
4082
4083 /*
4084 */
4085 static int patch_alc861(struct hda_codec *codec)
4086 {
4087 struct alc_spec *spec;
4088 int err;
4089
4090 err = alc_alloc_spec(codec, 0x15);
4091 if (err < 0)
4092 return err;
4093
4094 spec = codec->spec;
4095 spec->gen.beep_nid = 0x23;
4096
4097 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4098 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4099
4100 /* automatic parse from the BIOS config */
4101 err = alc861_parse_auto_config(codec);
4102 if (err < 0)
4103 goto error;
4104
4105 if (!spec->gen.no_analog)
4106 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
4107
4108 codec->patch_ops = alc_patch_ops;
4109 #ifdef CONFIG_PM
4110 spec->power_hook = alc_power_eapd;
4111 #endif
4112
4113 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4114
4115 return 0;
4116
4117 error:
4118 alc_free(codec);
4119 return err;
4120 }
4121
4122 /*
4123 * ALC861-VD support
4124 *
4125 * Based on ALC882
4126 *
4127 * In addition, an independent DAC
4128 */
4129 static int alc861vd_parse_auto_config(struct hda_codec *codec)
4130 {
4131 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
4132 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4133 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
4134 }
4135
4136 enum {
4137 ALC660VD_FIX_ASUS_GPIO1,
4138 ALC861VD_FIX_DALLAS,
4139 };
4140
4141 /* exclude VREF80 */
4142 static void alc861vd_fixup_dallas(struct hda_codec *codec,
4143 const struct hda_fixup *fix, int action)
4144 {
4145 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4146 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
4147 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
4148 }
4149 }
4150
4151 static const struct hda_fixup alc861vd_fixups[] = {
4152 [ALC660VD_FIX_ASUS_GPIO1] = {
4153 .type = HDA_FIXUP_VERBS,
4154 .v.verbs = (const struct hda_verb[]) {
4155 /* reset GPIO1 */
4156 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
4157 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4158 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4159 { }
4160 }
4161 },
4162 [ALC861VD_FIX_DALLAS] = {
4163 .type = HDA_FIXUP_FUNC,
4164 .v.func = alc861vd_fixup_dallas,
4165 },
4166 };
4167
4168 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
4169 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
4170 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
4171 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
4172 {}
4173 };
4174
4175 /*
4176 */
4177 static int patch_alc861vd(struct hda_codec *codec)
4178 {
4179 struct alc_spec *spec;
4180 int err;
4181
4182 err = alc_alloc_spec(codec, 0x0b);
4183 if (err < 0)
4184 return err;
4185
4186 spec = codec->spec;
4187 spec->gen.beep_nid = 0x23;
4188
4189 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
4190 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4191
4192 /* automatic parse from the BIOS config */
4193 err = alc861vd_parse_auto_config(codec);
4194 if (err < 0)
4195 goto error;
4196
4197 if (!spec->gen.no_analog)
4198 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4199
4200 codec->patch_ops = alc_patch_ops;
4201
4202 spec->shutup = alc_eapd_shutup;
4203
4204 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4205
4206 return 0;
4207
4208 error:
4209 alc_free(codec);
4210 return err;
4211 }
4212
4213 /*
4214 * ALC662 support
4215 *
4216 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
4217 * configuration. Each pin widget can choose any input DACs and a mixer.
4218 * Each ADC is connected from a mixer of all inputs. This makes possible
4219 * 6-channel independent captures.
4220 *
4221 * In addition, an independent DAC for the multi-playback (not used in this
4222 * driver yet).
4223 */
4224
4225 /*
4226 * BIOS auto configuration
4227 */
4228
4229 static int alc662_parse_auto_config(struct hda_codec *codec)
4230 {
4231 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
4232 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
4233 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4234 const hda_nid_t *ssids;
4235
4236 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
4237 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
4238 codec->vendor_id == 0x10ec0671)
4239 ssids = alc663_ssids;
4240 else
4241 ssids = alc662_ssids;
4242 return alc_parse_auto_config(codec, alc662_ignore, ssids);
4243 }
4244
4245 static void alc272_fixup_mario(struct hda_codec *codec,
4246 const struct hda_fixup *fix, int action)
4247 {
4248 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4249 return;
4250 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
4251 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
4252 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
4253 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4254 (0 << AC_AMPCAP_MUTE_SHIFT)))
4255 printk(KERN_WARNING
4256 "hda_codec: failed to override amp caps for NID 0x2\n");
4257 }
4258
4259 enum {
4260 ALC662_FIXUP_ASPIRE,
4261 ALC662_FIXUP_IDEAPAD,
4262 ALC272_FIXUP_MARIO,
4263 ALC662_FIXUP_CZC_P10T,
4264 ALC662_FIXUP_SKU_IGNORE,
4265 ALC662_FIXUP_HP_RP5800,
4266 ALC662_FIXUP_ASUS_MODE1,
4267 ALC662_FIXUP_ASUS_MODE2,
4268 ALC662_FIXUP_ASUS_MODE3,
4269 ALC662_FIXUP_ASUS_MODE4,
4270 ALC662_FIXUP_ASUS_MODE5,
4271 ALC662_FIXUP_ASUS_MODE6,
4272 ALC662_FIXUP_ASUS_MODE7,
4273 ALC662_FIXUP_ASUS_MODE8,
4274 ALC662_FIXUP_NO_JACK_DETECT,
4275 ALC662_FIXUP_ZOTAC_Z68,
4276 ALC662_FIXUP_INV_DMIC,
4277 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
4278 ALC668_FIXUP_HEADSET_MODE,
4279 };
4280
4281 static const struct hda_fixup alc662_fixups[] = {
4282 [ALC662_FIXUP_ASPIRE] = {
4283 .type = HDA_FIXUP_PINS,
4284 .v.pins = (const struct hda_pintbl[]) {
4285 { 0x15, 0x99130112 }, /* subwoofer */
4286 { }
4287 }
4288 },
4289 [ALC662_FIXUP_IDEAPAD] = {
4290 .type = HDA_FIXUP_PINS,
4291 .v.pins = (const struct hda_pintbl[]) {
4292 { 0x17, 0x99130112 }, /* subwoofer */
4293 { }
4294 }
4295 },
4296 [ALC272_FIXUP_MARIO] = {
4297 .type = HDA_FIXUP_FUNC,
4298 .v.func = alc272_fixup_mario,
4299 },
4300 [ALC662_FIXUP_CZC_P10T] = {
4301 .type = HDA_FIXUP_VERBS,
4302 .v.verbs = (const struct hda_verb[]) {
4303 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4304 {}
4305 }
4306 },
4307 [ALC662_FIXUP_SKU_IGNORE] = {
4308 .type = HDA_FIXUP_FUNC,
4309 .v.func = alc_fixup_sku_ignore,
4310 },
4311 [ALC662_FIXUP_HP_RP5800] = {
4312 .type = HDA_FIXUP_PINS,
4313 .v.pins = (const struct hda_pintbl[]) {
4314 { 0x14, 0x0221201f }, /* HP out */
4315 { }
4316 },
4317 .chained = true,
4318 .chain_id = ALC662_FIXUP_SKU_IGNORE
4319 },
4320 [ALC662_FIXUP_ASUS_MODE1] = {
4321 .type = HDA_FIXUP_PINS,
4322 .v.pins = (const struct hda_pintbl[]) {
4323 { 0x14, 0x99130110 }, /* speaker */
4324 { 0x18, 0x01a19c20 }, /* mic */
4325 { 0x19, 0x99a3092f }, /* int-mic */
4326 { 0x21, 0x0121401f }, /* HP out */
4327 { }
4328 },
4329 .chained = true,
4330 .chain_id = ALC662_FIXUP_SKU_IGNORE
4331 },
4332 [ALC662_FIXUP_ASUS_MODE2] = {
4333 .type = HDA_FIXUP_PINS,
4334 .v.pins = (const struct hda_pintbl[]) {
4335 { 0x14, 0x99130110 }, /* speaker */
4336 { 0x18, 0x01a19820 }, /* mic */
4337 { 0x19, 0x99a3092f }, /* int-mic */
4338 { 0x1b, 0x0121401f }, /* HP out */
4339 { }
4340 },
4341 .chained = true,
4342 .chain_id = ALC662_FIXUP_SKU_IGNORE
4343 },
4344 [ALC662_FIXUP_ASUS_MODE3] = {
4345 .type = HDA_FIXUP_PINS,
4346 .v.pins = (const struct hda_pintbl[]) {
4347 { 0x14, 0x99130110 }, /* speaker */
4348 { 0x15, 0x0121441f }, /* HP */
4349 { 0x18, 0x01a19840 }, /* mic */
4350 { 0x19, 0x99a3094f }, /* int-mic */
4351 { 0x21, 0x01211420 }, /* HP2 */
4352 { }
4353 },
4354 .chained = true,
4355 .chain_id = ALC662_FIXUP_SKU_IGNORE
4356 },
4357 [ALC662_FIXUP_ASUS_MODE4] = {
4358 .type = HDA_FIXUP_PINS,
4359 .v.pins = (const struct hda_pintbl[]) {
4360 { 0x14, 0x99130110 }, /* speaker */
4361 { 0x16, 0x99130111 }, /* speaker */
4362 { 0x18, 0x01a19840 }, /* mic */
4363 { 0x19, 0x99a3094f }, /* int-mic */
4364 { 0x21, 0x0121441f }, /* HP */
4365 { }
4366 },
4367 .chained = true,
4368 .chain_id = ALC662_FIXUP_SKU_IGNORE
4369 },
4370 [ALC662_FIXUP_ASUS_MODE5] = {
4371 .type = HDA_FIXUP_PINS,
4372 .v.pins = (const struct hda_pintbl[]) {
4373 { 0x14, 0x99130110 }, /* speaker */
4374 { 0x15, 0x0121441f }, /* HP */
4375 { 0x16, 0x99130111 }, /* speaker */
4376 { 0x18, 0x01a19840 }, /* mic */
4377 { 0x19, 0x99a3094f }, /* int-mic */
4378 { }
4379 },
4380 .chained = true,
4381 .chain_id = ALC662_FIXUP_SKU_IGNORE
4382 },
4383 [ALC662_FIXUP_ASUS_MODE6] = {
4384 .type = HDA_FIXUP_PINS,
4385 .v.pins = (const struct hda_pintbl[]) {
4386 { 0x14, 0x99130110 }, /* speaker */
4387 { 0x15, 0x01211420 }, /* HP2 */
4388 { 0x18, 0x01a19840 }, /* mic */
4389 { 0x19, 0x99a3094f }, /* int-mic */
4390 { 0x1b, 0x0121441f }, /* HP */
4391 { }
4392 },
4393 .chained = true,
4394 .chain_id = ALC662_FIXUP_SKU_IGNORE
4395 },
4396 [ALC662_FIXUP_ASUS_MODE7] = {
4397 .type = HDA_FIXUP_PINS,
4398 .v.pins = (const struct hda_pintbl[]) {
4399 { 0x14, 0x99130110 }, /* speaker */
4400 { 0x17, 0x99130111 }, /* speaker */
4401 { 0x18, 0x01a19840 }, /* mic */
4402 { 0x19, 0x99a3094f }, /* int-mic */
4403 { 0x1b, 0x01214020 }, /* HP */
4404 { 0x21, 0x0121401f }, /* HP */
4405 { }
4406 },
4407 .chained = true,
4408 .chain_id = ALC662_FIXUP_SKU_IGNORE
4409 },
4410 [ALC662_FIXUP_ASUS_MODE8] = {
4411 .type = HDA_FIXUP_PINS,
4412 .v.pins = (const struct hda_pintbl[]) {
4413 { 0x14, 0x99130110 }, /* speaker */
4414 { 0x12, 0x99a30970 }, /* int-mic */
4415 { 0x15, 0x01214020 }, /* HP */
4416 { 0x17, 0x99130111 }, /* speaker */
4417 { 0x18, 0x01a19840 }, /* mic */
4418 { 0x21, 0x0121401f }, /* HP */
4419 { }
4420 },
4421 .chained = true,
4422 .chain_id = ALC662_FIXUP_SKU_IGNORE
4423 },
4424 [ALC662_FIXUP_NO_JACK_DETECT] = {
4425 .type = HDA_FIXUP_FUNC,
4426 .v.func = alc_fixup_no_jack_detect,
4427 },
4428 [ALC662_FIXUP_ZOTAC_Z68] = {
4429 .type = HDA_FIXUP_PINS,
4430 .v.pins = (const struct hda_pintbl[]) {
4431 { 0x1b, 0x02214020 }, /* Front HP */
4432 { }
4433 }
4434 },
4435 [ALC662_FIXUP_INV_DMIC] = {
4436 .type = HDA_FIXUP_FUNC,
4437 .v.func = alc_fixup_inv_dmic_0x12,
4438 },
4439 [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
4440 .type = HDA_FIXUP_PINS,
4441 .v.pins = (const struct hda_pintbl[]) {
4442 { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
4443 { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
4444 { }
4445 },
4446 .chained = true,
4447 .chain_id = ALC668_FIXUP_HEADSET_MODE
4448 },
4449 [ALC668_FIXUP_HEADSET_MODE] = {
4450 .type = HDA_FIXUP_FUNC,
4451 .v.func = alc_fixup_headset_mode_alc668,
4452 },
4453 };
4454
4455 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
4456 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
4457 SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),
4458 SND_PCI_QUIRK(0x1025, 0x0241, "Packard Bell DOTS", ALC662_FIXUP_INV_DMIC),
4459 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
4460 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
4461 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
4462 SND_PCI_QUIRK(0x1025, 0x034a, "Gateway LT27", ALC662_FIXUP_INV_DMIC),
4463 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
4464 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4465 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4466 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
4467 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_ASUS_MODE4),
4468 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_ASUS_MODE4),
4469 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
4470 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
4471 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
4472 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
4473 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
4474 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
4475 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
4476
4477 #if 0
4478 /* Below is a quirk table taken from the old code.
4479 * Basically the device should work as is without the fixup table.
4480 * If BIOS doesn't give a proper info, enable the corresponding
4481 * fixup entry.
4482 */
4483 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
4484 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
4485 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
4486 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
4487 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4488 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4489 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4490 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
4491 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
4492 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4493 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
4494 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
4495 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
4496 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
4497 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
4498 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4499 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
4500 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
4501 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4502 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4503 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4504 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4505 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
4506 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
4507 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
4508 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4509 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
4510 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
4511 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4512 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
4513 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4514 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4515 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
4516 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
4517 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
4518 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
4519 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
4520 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
4521 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
4522 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
4523 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
4524 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
4525 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4526 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
4527 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
4528 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
4529 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
4530 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
4531 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
4532 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
4533 #endif
4534 {}
4535 };
4536
4537 static const struct hda_model_fixup alc662_fixup_models[] = {
4538 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
4539 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
4540 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
4541 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
4542 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
4543 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
4544 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
4545 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
4546 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
4547 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
4548 {.id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
4549 {}
4550 };
4551
4552 static void alc662_fill_coef(struct hda_codec *codec)
4553 {
4554 int val, coef;
4555
4556 coef = alc_get_coef0(codec);
4557
4558 switch (codec->vendor_id) {
4559 case 0x10ec0662:
4560 if ((coef & 0x00f0) == 0x0030) {
4561 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
4562 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
4563 }
4564 break;
4565 case 0x10ec0272:
4566 case 0x10ec0273:
4567 case 0x10ec0663:
4568 case 0x10ec0665:
4569 case 0x10ec0670:
4570 case 0x10ec0671:
4571 case 0x10ec0672:
4572 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
4573 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4574 break;
4575 }
4576 }
4577
4578 /*
4579 */
4580 static int patch_alc662(struct hda_codec *codec)
4581 {
4582 struct alc_spec *spec;
4583 int err;
4584
4585 err = alc_alloc_spec(codec, 0x0b);
4586 if (err < 0)
4587 return err;
4588
4589 spec = codec->spec;
4590
4591 /* handle multiple HPs as is */
4592 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
4593
4594 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4595
4596 spec->init_hook = alc662_fill_coef;
4597 alc662_fill_coef(codec);
4598
4599 snd_hda_pick_fixup(codec, alc662_fixup_models,
4600 alc662_fixup_tbl, alc662_fixups);
4601 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4602
4603 alc_auto_parse_customize_define(codec);
4604
4605 if (has_cdefine_beep(codec))
4606 spec->gen.beep_nid = 0x01;
4607
4608 if ((alc_get_coef0(codec) & (1 << 14)) &&
4609 codec->bus->pci->subsystem_vendor == 0x1025 &&
4610 spec->cdefine.platform_type == 1) {
4611 err = alc_codec_rename(codec, "ALC272X");
4612 if (err < 0)
4613 goto error;
4614 }
4615
4616 /* automatic parse from the BIOS config */
4617 err = alc662_parse_auto_config(codec);
4618 if (err < 0)
4619 goto error;
4620
4621 if (!spec->gen.no_analog && spec->gen.beep_nid) {
4622 switch (codec->vendor_id) {
4623 case 0x10ec0662:
4624 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4625 break;
4626 case 0x10ec0272:
4627 case 0x10ec0663:
4628 case 0x10ec0665:
4629 case 0x10ec0668:
4630 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
4631 break;
4632 case 0x10ec0273:
4633 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
4634 break;
4635 }
4636 }
4637
4638 codec->patch_ops = alc_patch_ops;
4639 spec->shutup = alc_eapd_shutup;
4640
4641 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4642
4643 return 0;
4644
4645 error:
4646 alc_free(codec);
4647 return err;
4648 }
4649
4650 /*
4651 * ALC680 support
4652 */
4653
4654 static int alc680_parse_auto_config(struct hda_codec *codec)
4655 {
4656 return alc_parse_auto_config(codec, NULL, NULL);
4657 }
4658
4659 /*
4660 */
4661 static int patch_alc680(struct hda_codec *codec)
4662 {
4663 int err;
4664
4665 /* ALC680 has no aa-loopback mixer */
4666 err = alc_alloc_spec(codec, 0);
4667 if (err < 0)
4668 return err;
4669
4670 /* automatic parse from the BIOS config */
4671 err = alc680_parse_auto_config(codec);
4672 if (err < 0) {
4673 alc_free(codec);
4674 return err;
4675 }
4676
4677 codec->patch_ops = alc_patch_ops;
4678
4679 return 0;
4680 }
4681
4682 /*
4683 * patch entries
4684 */
4685 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
4686 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
4687 { .id = 0x10ec0231, .name = "ALC231", .patch = patch_alc269 },
4688 { .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 },
4689 { .id = 0x10ec0255, .name = "ALC255", .patch = patch_alc269 },
4690 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
4691 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
4692 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
4693 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
4694 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
4695 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
4696 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
4697 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
4698 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
4699 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
4700 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
4701 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
4702 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
4703 { .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 },
4704 { .id = 0x10ec0288, .name = "ALC288", .patch = patch_alc269 },
4705 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
4706 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
4707 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
4708 .patch = patch_alc861 },
4709 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
4710 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
4711 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
4712 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
4713 .patch = patch_alc882 },
4714 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
4715 .patch = patch_alc662 },
4716 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
4717 .patch = patch_alc662 },
4718 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
4719 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
4720 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
4721 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
4722 { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
4723 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
4724 { .id = 0x10ec0867, .name = "ALC891", .patch = patch_alc882 },
4725 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
4726 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
4727 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
4728 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
4729 .patch = patch_alc882 },
4730 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
4731 .patch = patch_alc882 },
4732 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
4733 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
4734 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
4735 .patch = patch_alc882 },
4736 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
4737 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
4738 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
4739 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
4740 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
4741 {} /* terminator */
4742 };
4743
4744 MODULE_ALIAS("snd-hda-codec-id:10ec*");
4745
4746 MODULE_LICENSE("GPL");
4747 MODULE_DESCRIPTION("Realtek HD-audio codec");
4748
4749 static struct hda_codec_preset_list realtek_list = {
4750 .preset = snd_hda_preset_realtek,
4751 .owner = THIS_MODULE,
4752 };
4753
4754 static int __init patch_realtek_init(void)
4755 {
4756 return snd_hda_add_codec_preset(&realtek_list);
4757 }
4758
4759 static void __exit patch_realtek_exit(void)
4760 {
4761 snd_hda_delete_codec_preset(&realtek_list);
4762 }
4763
4764 module_init(patch_realtek_init)
4765 module_exit(patch_realtek_exit)