]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - sound/pci/hda/patch_realtek.c
ALSA: hda/realtek - Replace ALC260 model=acer with the auto-parser
[mirror_ubuntu-bionic-kernel.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@physics.adelaide.edu.au>
10 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
35 #include "hda_beep.h"
36 #include "hda_jack.h"
37
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
43
44 /* for GPIO Poll */
45 #define GPIO_MASK 0x03
46
47 /* extra amp-initialization sequence types */
48 enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54 };
55
56 struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
67 };
68
69 struct alc_fixup;
70
71 struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75 };
76
77 enum {
78 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
81 };
82
83 struct alc_spec {
84 /* codec parameterization */
85 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
86 unsigned int num_mixers;
87 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
88 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
89
90 const struct hda_verb *init_verbs[10]; /* initialization verbs
91 * don't forget NULL
92 * termination!
93 */
94 unsigned int num_init_verbs;
95
96 char stream_name_analog[32]; /* analog PCM stream */
97 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
101
102 char stream_name_digital[32]; /* digital PCM stream */
103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
105
106 /* playback */
107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
111 hda_nid_t alt_dac_nid;
112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
113 int dig_out_type;
114
115 /* capture */
116 unsigned int num_adc_nids;
117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
120 hda_nid_t mixer_nid; /* analog-mixer NID */
121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
123
124 /* capture setup for dynamic dual-adc switch */
125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
129 /* capture source */
130 unsigned int num_mux_defs;
131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
136
137 /* channel model */
138 const struct hda_channel_mode *channel_mode;
139 int num_channel_mode;
140 int need_dac_fix;
141 int const_channel_count;
142 int ext_channel_count;
143
144 /* PCM information */
145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
146
147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
149 struct alc_customize_define cdefine;
150 struct snd_array kctls;
151 struct hda_input_mux private_imux[3];
152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
158
159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
162 #ifdef CONFIG_SND_HDA_POWER_SAVE
163 void (*power_hook)(struct hda_codec *codec);
164 #endif
165 void (*shutup)(struct hda_codec *codec);
166 void (*automute_hook)(struct hda_codec *codec);
167
168 /* for pin sensing */
169 unsigned int hp_jack_present:1;
170 unsigned int line_jack_present:1;
171 unsigned int master_mute:1;
172 unsigned int auto_mic:1;
173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
180 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
181
182 /* other flags */
183 unsigned int no_analog :1; /* digital I/O only */
184 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
185 unsigned int single_input_src:1;
186 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
187 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
188 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
189
190 /* auto-mute control */
191 int automute_mode;
192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
193
194 int init_amp;
195 int codec_variant; /* flag for other variants */
196
197 /* for virtual master */
198 hda_nid_t vmaster_nid;
199 #ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
201 #endif
202
203 /* for PLL fix */
204 hda_nid_t pll_nid;
205 unsigned int pll_coef_idx, pll_coef_bit;
206 unsigned int coef0;
207
208 /* fix-up list */
209 int fixup_id;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
212
213 /* multi-io */
214 int multi_ios;
215 struct alc_multi_io multi_io[4];
216
217 /* bind volumes */
218 struct snd_array bind_ctls;
219 };
220
221 #define ALC_MODEL_AUTO 0 /* common for all chips */
222
223 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
225 {
226 if (!nid)
227 return false;
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
230 return true;
231 return false;
232 }
233
234 #define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236 #define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
238
239 /*
240 * input MUX handling
241 */
242 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
244 {
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
249 mux_idx = 0;
250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
251 mux_idx = 0;
252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
253 }
254
255 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
257 {
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
263 return 0;
264 }
265
266 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
267 {
268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
270
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
278 return true;
279 }
280 return false;
281 }
282
283 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
284 {
285 return spec->capsrc_nids ?
286 spec->capsrc_nids[idx] : spec->adc_nids[idx];
287 }
288
289 static void call_update_outputs(struct hda_codec *codec);
290
291 /* select the given imux item; either unmute exclusively or select the route */
292 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
293 unsigned int idx, bool force)
294 {
295 struct alc_spec *spec = codec->spec;
296 const struct hda_input_mux *imux;
297 unsigned int mux_idx;
298 int i, type, num_conns;
299 hda_nid_t nid;
300
301 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
302 imux = &spec->input_mux[mux_idx];
303 if (!imux->num_items && mux_idx > 0)
304 imux = &spec->input_mux[0];
305 if (!imux->num_items)
306 return 0;
307
308 if (idx >= imux->num_items)
309 idx = imux->num_items - 1;
310 if (spec->cur_mux[adc_idx] == idx && !force)
311 return 0;
312 spec->cur_mux[adc_idx] = idx;
313
314 /* for shared I/O, change the pin-control accordingly */
315 if (spec->shared_mic_hp) {
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP jack.
318 */
319 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
320 AC_VERB_SET_PIN_WIDGET_CONTROL,
321 spec->cur_mux[adc_idx] ?
322 PIN_VREF80 : PIN_HP);
323 spec->automute_speaker = !spec->cur_mux[adc_idx];
324 call_update_outputs(codec);
325 }
326
327 if (spec->dyn_adc_switch) {
328 alc_dyn_adc_pcm_resetup(codec, idx);
329 adc_idx = spec->dyn_adc_idx[idx];
330 }
331
332 nid = get_capsrc(spec, adc_idx);
333
334 /* no selection? */
335 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
336 if (num_conns <= 1)
337 return 1;
338
339 type = get_wcaps_type(get_wcaps(codec, nid));
340 if (type == AC_WID_AUD_MIX) {
341 /* Matrix-mixer style (e.g. ALC882) */
342 int active = imux->items[idx].index;
343 for (i = 0; i < num_conns; i++) {
344 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
345 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
346 HDA_AMP_MUTE, v);
347 }
348 } else {
349 /* MUX style (e.g. ALC880) */
350 snd_hda_codec_write_cache(codec, nid, 0,
351 AC_VERB_SET_CONNECT_SEL,
352 imux->items[idx].index);
353 }
354 return 1;
355 }
356
357 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_value *ucontrol)
359 {
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362 return alc_mux_select(codec, adc_idx,
363 ucontrol->value.enumerated.item[0], false);
364 }
365
366 /*
367 * set up the input pin config (depending on the given auto-pin type)
368 */
369 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
370 int auto_pin_type)
371 {
372 unsigned int val = PIN_IN;
373
374 if (auto_pin_type == AUTO_PIN_MIC) {
375 unsigned int pincap;
376 unsigned int oldval;
377 oldval = snd_hda_codec_read(codec, nid, 0,
378 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
379 pincap = snd_hda_query_pin_caps(codec, nid);
380 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
381 /* if the default pin setup is vref50, we give it priority */
382 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
383 val = PIN_VREF80;
384 else if (pincap & AC_PINCAP_VREF_50)
385 val = PIN_VREF50;
386 else if (pincap & AC_PINCAP_VREF_100)
387 val = PIN_VREF100;
388 else if (pincap & AC_PINCAP_VREF_GRD)
389 val = PIN_VREFGRD;
390 }
391 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
392 }
393
394 /*
395 * Append the given mixer and verb elements for the later use
396 * The mixer array is referred in build_controls(), and init_verbs are
397 * called in init().
398 */
399 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
400 {
401 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
402 return;
403 spec->mixers[spec->num_mixers++] = mix;
404 }
405
406 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
407 {
408 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
409 return;
410 spec->init_verbs[spec->num_init_verbs++] = verb;
411 }
412
413 /*
414 * GPIO setup tables, used in initialization
415 */
416 /* Enable GPIO mask and set output */
417 static const struct hda_verb alc_gpio1_init_verbs[] = {
418 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
421 { }
422 };
423
424 static const struct hda_verb alc_gpio2_init_verbs[] = {
425 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
428 { }
429 };
430
431 static const struct hda_verb alc_gpio3_init_verbs[] = {
432 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
435 { }
436 };
437
438 /*
439 * Fix hardware PLL issue
440 * On some codecs, the analog PLL gating control must be off while
441 * the default value is 1.
442 */
443 static void alc_fix_pll(struct hda_codec *codec)
444 {
445 struct alc_spec *spec = codec->spec;
446 unsigned int val;
447
448 if (!spec->pll_nid)
449 return;
450 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
451 spec->pll_coef_idx);
452 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
453 AC_VERB_GET_PROC_COEF, 0);
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
455 spec->pll_coef_idx);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
457 val & ~(1 << spec->pll_coef_bit));
458 }
459
460 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
461 unsigned int coef_idx, unsigned int coef_bit)
462 {
463 struct alc_spec *spec = codec->spec;
464 spec->pll_nid = nid;
465 spec->pll_coef_idx = coef_idx;
466 spec->pll_coef_bit = coef_bit;
467 alc_fix_pll(codec);
468 }
469
470 /*
471 * Jack detections for HP auto-mute and mic-switch
472 */
473
474 /* check each pin in the given array; returns true if any of them is plugged */
475 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
476 {
477 int i, present = 0;
478
479 for (i = 0; i < num_pins; i++) {
480 hda_nid_t nid = pins[i];
481 if (!nid)
482 break;
483 present |= snd_hda_jack_detect(codec, nid);
484 }
485 return present;
486 }
487
488 /* standard HP/line-out auto-mute helper */
489 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
490 bool mute, bool hp_out)
491 {
492 struct alc_spec *spec = codec->spec;
493 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
494 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
495 int i;
496
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
499 unsigned int val;
500 if (!nid)
501 break;
502 switch (spec->automute_mode) {
503 case ALC_AUTOMUTE_PIN:
504 /* don't reset VREF value in case it's controlling
505 * the amp (see alc861_fixup_asus_amp_vref_0f())
506 */
507 if (spec->keep_vref_in_automute) {
508 val = snd_hda_codec_read(codec, nid, 0,
509 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
510 val &= ~PIN_HP;
511 } else
512 val = 0;
513 val |= pin_bits;
514 snd_hda_codec_write(codec, nid, 0,
515 AC_VERB_SET_PIN_WIDGET_CONTROL,
516 val);
517 break;
518 case ALC_AUTOMUTE_AMP:
519 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
520 HDA_AMP_MUTE, mute_bits);
521 break;
522 case ALC_AUTOMUTE_MIXER:
523 nid = spec->automute_mixer_nid[i];
524 if (!nid)
525 break;
526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
527 HDA_AMP_MUTE, mute_bits);
528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
529 HDA_AMP_MUTE, mute_bits);
530 break;
531 }
532 }
533 }
534
535 /* Toggle outputs muting */
536 static void update_outputs(struct hda_codec *codec)
537 {
538 struct alc_spec *spec = codec->spec;
539 int on;
540
541 /* Control HP pins/amps depending on master_mute state;
542 * in general, HP pins/amps control should be enabled in all cases,
543 * but currently set only for master_mute, just to be safe
544 */
545 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
547 spec->autocfg.hp_pins, spec->master_mute, true);
548
549 if (!spec->automute_speaker)
550 on = 0;
551 else
552 on = spec->hp_jack_present | spec->line_jack_present;
553 on |= spec->master_mute;
554 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
555 spec->autocfg.speaker_pins, on, false);
556
557 /* toggle line-out mutes if needed, too */
558 /* if LO is a copy of either HP or Speaker, don't need to handle it */
559 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
560 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
561 return;
562 if (!spec->automute_lo)
563 on = 0;
564 else
565 on = spec->hp_jack_present;
566 on |= spec->master_mute;
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
568 spec->autocfg.line_out_pins, on, false);
569 }
570
571 static void call_update_outputs(struct hda_codec *codec)
572 {
573 struct alc_spec *spec = codec->spec;
574 if (spec->automute_hook)
575 spec->automute_hook(codec);
576 else
577 update_outputs(codec);
578 }
579
580 /* standard HP-automute helper */
581 static void alc_hp_automute(struct hda_codec *codec)
582 {
583 struct alc_spec *spec = codec->spec;
584
585 spec->hp_jack_present =
586 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins);
588 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
589 return;
590 call_update_outputs(codec);
591 }
592
593 /* standard line-out-automute helper */
594 static void alc_line_automute(struct hda_codec *codec)
595 {
596 struct alc_spec *spec = codec->spec;
597
598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
600 return;
601
602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
605 if (!spec->automute_speaker || !spec->detect_lo)
606 return;
607 call_update_outputs(codec);
608 }
609
610 #define get_connection_index(codec, mux, nid) \
611 snd_hda_get_conn_index(codec, mux, nid, 0)
612
613 /* standard mic auto-switch helper */
614 static void alc_mic_automute(struct hda_codec *codec)
615 {
616 struct alc_spec *spec = codec->spec;
617 hda_nid_t *pins = spec->imux_pins;
618
619 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
620 return;
621 if (snd_BUG_ON(!spec->adc_nids))
622 return;
623 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
624 return;
625
626 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
627 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
628 else if (spec->dock_mic_idx >= 0 &&
629 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
630 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
631 else
632 alc_mux_select(codec, 0, spec->int_mic_idx, false);
633 }
634
635 /* handle the specified unsol action (ALC_XXX_EVENT) */
636 static void alc_exec_unsol_event(struct hda_codec *codec, int action)
637 {
638 switch (action) {
639 case ALC_HP_EVENT:
640 alc_hp_automute(codec);
641 break;
642 case ALC_FRONT_EVENT:
643 alc_line_automute(codec);
644 break;
645 case ALC_MIC_EVENT:
646 alc_mic_automute(codec);
647 break;
648 }
649 snd_hda_jack_report_sync(codec);
650 }
651
652 /* unsolicited event for HP jack sensing */
653 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
654 {
655 if (codec->vendor_id == 0x10ec0880)
656 res >>= 28;
657 else
658 res >>= 26;
659 res = snd_hda_jack_get_action(codec, res);
660 alc_exec_unsol_event(codec, res);
661 }
662
663 /* call init functions of standard auto-mute helpers */
664 static void alc_inithook(struct hda_codec *codec)
665 {
666 alc_hp_automute(codec);
667 alc_line_automute(codec);
668 alc_mic_automute(codec);
669 }
670
671 /* additional initialization for ALC888 variants */
672 static void alc888_coef_init(struct hda_codec *codec)
673 {
674 unsigned int tmp;
675
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
677 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
679 if ((tmp & 0xf0) == 0x20)
680 /* alc888S-VC */
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x830);
683 else
684 /* alc888-VB */
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x3030);
687 }
688
689 /* additional initialization for ALC889 variants */
690 static void alc889_coef_init(struct hda_codec *codec)
691 {
692 unsigned int tmp;
693
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
698 }
699
700 /* turn on/off EAPD control (only if available) */
701 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
702 {
703 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
704 return;
705 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
707 on ? 2 : 0);
708 }
709
710 /* turn on/off EAPD controls of the codec */
711 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
712 {
713 /* We currently only handle front, HP */
714 static hda_nid_t pins[] = {
715 0x0f, 0x10, 0x14, 0x15, 0
716 };
717 hda_nid_t *p;
718 for (p = pins; *p; p++)
719 set_eapd(codec, *p, on);
720 }
721
722 /* generic shutup callback;
723 * just turning off EPAD and a little pause for avoiding pop-noise
724 */
725 static void alc_eapd_shutup(struct hda_codec *codec)
726 {
727 alc_auto_setup_eapd(codec, false);
728 msleep(200);
729 }
730
731 /* generic EAPD initialization */
732 static void alc_auto_init_amp(struct hda_codec *codec, int type)
733 {
734 unsigned int tmp;
735
736 alc_auto_setup_eapd(codec, true);
737 switch (type) {
738 case ALC_INIT_GPIO1:
739 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
740 break;
741 case ALC_INIT_GPIO2:
742 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
743 break;
744 case ALC_INIT_GPIO3:
745 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
746 break;
747 case ALC_INIT_DEFAULT:
748 switch (codec->vendor_id) {
749 case 0x10ec0260:
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x1a, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_PROC_COEF,
758 tmp | 0x2010);
759 break;
760 case 0x10ec0262:
761 case 0x10ec0880:
762 case 0x10ec0882:
763 case 0x10ec0883:
764 case 0x10ec0885:
765 case 0x10ec0887:
766 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
767 alc889_coef_init(codec);
768 break;
769 case 0x10ec0888:
770 alc888_coef_init(codec);
771 break;
772 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
773 case 0x10ec0267:
774 case 0x10ec0268:
775 snd_hda_codec_write(codec, 0x20, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x20, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x20, 0,
780 AC_VERB_SET_COEF_INDEX, 7);
781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_PROC_COEF,
783 tmp | 0x3000);
784 break;
785 #endif /* XXX */
786 }
787 break;
788 }
789 }
790
791 /*
792 * Auto-Mute mode mixer enum support
793 */
794 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
796 {
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
799 static const char * const texts2[] = {
800 "Disabled", "Enabled"
801 };
802 static const char * const texts3[] = {
803 "Disabled", "Speaker Only", "Line-Out+Speaker"
804 };
805 const char * const *texts;
806
807 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
808 uinfo->count = 1;
809 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
810 uinfo->value.enumerated.items = 3;
811 texts = texts3;
812 } else {
813 uinfo->value.enumerated.items = 2;
814 texts = texts2;
815 }
816 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
817 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
818 strcpy(uinfo->value.enumerated.name,
819 texts[uinfo->value.enumerated.item]);
820 return 0;
821 }
822
823 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825 {
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
828 unsigned int val = 0;
829 if (spec->automute_speaker)
830 val++;
831 if (spec->automute_lo)
832 val++;
833
834 ucontrol->value.enumerated.item[0] = val;
835 return 0;
836 }
837
838 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840 {
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
843
844 switch (ucontrol->value.enumerated.item[0]) {
845 case 0:
846 if (!spec->automute_speaker && !spec->automute_lo)
847 return 0;
848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
850 break;
851 case 1:
852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
854 return 0;
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
859 return 0;
860 spec->automute_lo = 1;
861 } else
862 return -EINVAL;
863 break;
864 case 2:
865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
866 return -EINVAL;
867 if (spec->automute_speaker && spec->automute_lo)
868 return 0;
869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
871 break;
872 default:
873 return -EINVAL;
874 }
875 call_update_outputs(codec);
876 return 1;
877 }
878
879 static const struct snd_kcontrol_new alc_automute_mode_enum = {
880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
885 };
886
887 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
888 {
889 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
890 return snd_array_new(&spec->kctls);
891 }
892
893 static int alc_add_automute_mode_enum(struct hda_codec *codec)
894 {
895 struct alc_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
897
898 knew = alc_kcontrol_new(spec);
899 if (!knew)
900 return -ENOMEM;
901 *knew = alc_automute_mode_enum;
902 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
903 if (!knew->name)
904 return -ENOMEM;
905 return 0;
906 }
907
908 /*
909 * Check the availability of HP/line-out auto-mute;
910 * Set up appropriately if really supported
911 */
912 static void alc_init_automute(struct hda_codec *codec)
913 {
914 struct alc_spec *spec = codec->spec;
915 struct auto_pin_cfg *cfg = &spec->autocfg;
916 int present = 0;
917 int i;
918
919 if (cfg->hp_pins[0])
920 present++;
921 if (cfg->line_out_pins[0])
922 present++;
923 if (cfg->speaker_pins[0])
924 present++;
925 if (present < 2) /* need two different output types */
926 return;
927
928 if (!cfg->speaker_pins[0] &&
929 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
930 memcpy(cfg->speaker_pins, cfg->line_out_pins,
931 sizeof(cfg->speaker_pins));
932 cfg->speaker_outs = cfg->line_outs;
933 }
934
935 if (!cfg->hp_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_HP_OUT) {
937 memcpy(cfg->hp_pins, cfg->line_out_pins,
938 sizeof(cfg->hp_pins));
939 cfg->hp_outs = cfg->line_outs;
940 }
941
942 spec->automute_mode = ALC_AUTOMUTE_PIN;
943
944 for (i = 0; i < cfg->hp_outs; i++) {
945 hda_nid_t nid = cfg->hp_pins[i];
946 if (!is_jack_detectable(codec, nid))
947 continue;
948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
949 nid);
950 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
951 spec->detect_hp = 1;
952 }
953
954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
955 if (cfg->speaker_outs)
956 for (i = 0; i < cfg->line_outs; i++) {
957 hda_nid_t nid = cfg->line_out_pins[i];
958 if (!is_jack_detectable(codec, nid))
959 continue;
960 snd_printdd("realtek: Enable Line-Out "
961 "auto-muting on NID 0x%x\n", nid);
962 snd_hda_jack_detect_enable(codec, nid,
963 ALC_FRONT_EVENT);
964 spec->detect_lo = 1;
965 }
966 spec->automute_lo_possible = spec->detect_hp;
967 }
968
969 spec->automute_speaker_possible = cfg->speaker_outs &&
970 (spec->detect_hp || spec->detect_lo);
971
972 spec->automute_lo = spec->automute_lo_possible;
973 spec->automute_speaker = spec->automute_speaker_possible;
974
975 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
976 /* create a control for automute mode */
977 alc_add_automute_mode_enum(codec);
978 spec->unsol_event = alc_sku_unsol_event;
979 }
980 }
981
982 /* return the position of NID in the list, or -1 if not found */
983 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
984 {
985 int i;
986 for (i = 0; i < nums; i++)
987 if (list[i] == nid)
988 return i;
989 return -1;
990 }
991
992 /* check whether dynamic ADC-switching is available */
993 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
994 {
995 struct alc_spec *spec = codec->spec;
996 struct hda_input_mux *imux = &spec->private_imux[0];
997 int i, n, idx;
998 hda_nid_t cap, pin;
999
1000 if (imux != spec->input_mux) /* no dynamic imux? */
1001 return false;
1002
1003 for (n = 0; n < spec->num_adc_nids; n++) {
1004 cap = spec->private_capsrc_nids[n];
1005 for (i = 0; i < imux->num_items; i++) {
1006 pin = spec->imux_pins[i];
1007 if (!pin)
1008 return false;
1009 if (get_connection_index(codec, cap, pin) < 0)
1010 break;
1011 }
1012 if (i >= imux->num_items)
1013 return true; /* no ADC-switch is needed */
1014 }
1015
1016 for (i = 0; i < imux->num_items; i++) {
1017 pin = spec->imux_pins[i];
1018 for (n = 0; n < spec->num_adc_nids; n++) {
1019 cap = spec->private_capsrc_nids[n];
1020 idx = get_connection_index(codec, cap, pin);
1021 if (idx >= 0) {
1022 imux->items[i].index = idx;
1023 spec->dyn_adc_idx[i] = n;
1024 break;
1025 }
1026 }
1027 }
1028
1029 snd_printdd("realtek: enabling ADC switching\n");
1030 spec->dyn_adc_switch = 1;
1031 return true;
1032 }
1033
1034 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1035 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1036 {
1037 struct alc_spec *spec = codec->spec;
1038 struct hda_input_mux *imux;
1039 static char * const texts[3] = {
1040 "Mic", "Internal Mic", "Dock Mic"
1041 };
1042 int i;
1043
1044 if (!spec->auto_mic)
1045 return false;
1046 imux = &spec->private_imux[0];
1047 if (spec->input_mux == imux)
1048 return true;
1049 spec->imux_pins[0] = spec->ext_mic_pin;
1050 spec->imux_pins[1] = spec->int_mic_pin;
1051 spec->imux_pins[2] = spec->dock_mic_pin;
1052 for (i = 0; i < 3; i++) {
1053 strcpy(imux->items[i].label, texts[i]);
1054 if (spec->imux_pins[i]) {
1055 hda_nid_t pin = spec->imux_pins[i];
1056 int c;
1057 for (c = 0; c < spec->num_adc_nids; c++) {
1058 hda_nid_t cap = get_capsrc(spec, c);
1059 int idx = get_connection_index(codec, cap, pin);
1060 if (idx >= 0) {
1061 imux->items[i].index = idx;
1062 break;
1063 }
1064 }
1065 imux->num_items = i + 1;
1066 }
1067 }
1068 spec->num_mux_defs = 1;
1069 spec->input_mux = imux;
1070 return true;
1071 }
1072
1073 /* check whether all auto-mic pins are valid; setup indices if OK */
1074 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1075 {
1076 struct alc_spec *spec = codec->spec;
1077 const struct hda_input_mux *imux;
1078
1079 if (!spec->auto_mic)
1080 return false;
1081 if (spec->auto_mic_valid_imux)
1082 return true; /* already checked */
1083
1084 /* fill up imux indices */
1085 if (!alc_check_dyn_adc_switch(codec)) {
1086 spec->auto_mic = 0;
1087 return false;
1088 }
1089
1090 imux = spec->input_mux;
1091 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1092 spec->imux_pins, imux->num_items);
1093 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1098 spec->auto_mic = 0;
1099 return false; /* no corresponding imux */
1100 }
1101
1102 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1103 if (spec->dock_mic_pin)
1104 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1105 ALC_MIC_EVENT);
1106
1107 spec->auto_mic_valid_imux = 1;
1108 spec->auto_mic = 1;
1109 return true;
1110 }
1111
1112 /*
1113 * Check the availability of auto-mic switch;
1114 * Set up if really supported
1115 */
1116 static void alc_init_auto_mic(struct hda_codec *codec)
1117 {
1118 struct alc_spec *spec = codec->spec;
1119 struct auto_pin_cfg *cfg = &spec->autocfg;
1120 hda_nid_t fixed, ext, dock;
1121 int i;
1122
1123 if (spec->shared_mic_hp)
1124 return; /* no auto-mic for the shared I/O */
1125
1126 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1127
1128 fixed = ext = dock = 0;
1129 for (i = 0; i < cfg->num_inputs; i++) {
1130 hda_nid_t nid = cfg->inputs[i].pin;
1131 unsigned int defcfg;
1132 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1133 switch (snd_hda_get_input_pin_attr(defcfg)) {
1134 case INPUT_PIN_ATTR_INT:
1135 if (fixed)
1136 return; /* already occupied */
1137 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1138 return; /* invalid type */
1139 fixed = nid;
1140 break;
1141 case INPUT_PIN_ATTR_UNUSED:
1142 return; /* invalid entry */
1143 case INPUT_PIN_ATTR_DOCK:
1144 if (dock)
1145 return; /* already occupied */
1146 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1147 return; /* invalid type */
1148 dock = nid;
1149 break;
1150 default:
1151 if (ext)
1152 return; /* already occupied */
1153 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1154 return; /* invalid type */
1155 ext = nid;
1156 break;
1157 }
1158 }
1159 if (!ext && dock) {
1160 ext = dock;
1161 dock = 0;
1162 }
1163 if (!ext || !fixed)
1164 return;
1165 if (!is_jack_detectable(codec, ext))
1166 return; /* no unsol support */
1167 if (dock && !is_jack_detectable(codec, dock))
1168 return; /* no unsol support */
1169
1170 /* check imux indices */
1171 spec->ext_mic_pin = ext;
1172 spec->int_mic_pin = fixed;
1173 spec->dock_mic_pin = dock;
1174
1175 spec->auto_mic = 1;
1176 if (!alc_auto_mic_check_imux(codec))
1177 return;
1178
1179 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1180 ext, fixed, dock);
1181 spec->unsol_event = alc_sku_unsol_event;
1182 }
1183
1184 /* check the availabilities of auto-mute and auto-mic switches */
1185 static void alc_auto_check_switches(struct hda_codec *codec)
1186 {
1187 alc_init_automute(codec);
1188 alc_init_auto_mic(codec);
1189 }
1190
1191 /*
1192 * Realtek SSID verification
1193 */
1194
1195 /* Could be any non-zero and even value. When used as fixup, tells
1196 * the driver to ignore any present sku defines.
1197 */
1198 #define ALC_FIXUP_SKU_IGNORE (2)
1199
1200 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1201 {
1202 unsigned int ass, tmp, i;
1203 unsigned nid = 0;
1204 struct alc_spec *spec = codec->spec;
1205
1206 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1207
1208 if (spec->cdefine.fixup) {
1209 ass = spec->cdefine.sku_cfg;
1210 if (ass == ALC_FIXUP_SKU_IGNORE)
1211 return -1;
1212 goto do_sku;
1213 }
1214
1215 ass = codec->subsystem_id & 0xffff;
1216 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1217 goto do_sku;
1218
1219 nid = 0x1d;
1220 if (codec->vendor_id == 0x10ec0260)
1221 nid = 0x17;
1222 ass = snd_hda_codec_get_pincfg(codec, nid);
1223
1224 if (!(ass & 1)) {
1225 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1226 codec->chip_name, ass);
1227 return -1;
1228 }
1229
1230 /* check sum */
1231 tmp = 0;
1232 for (i = 1; i < 16; i++) {
1233 if ((ass >> i) & 1)
1234 tmp++;
1235 }
1236 if (((ass >> 16) & 0xf) != tmp)
1237 return -1;
1238
1239 spec->cdefine.port_connectivity = ass >> 30;
1240 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1241 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1242 spec->cdefine.customization = ass >> 8;
1243 do_sku:
1244 spec->cdefine.sku_cfg = ass;
1245 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1246 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1247 spec->cdefine.swap = (ass & 0x2) >> 1;
1248 spec->cdefine.override = ass & 0x1;
1249
1250 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1251 nid, spec->cdefine.sku_cfg);
1252 snd_printd("SKU: port_connectivity=0x%x\n",
1253 spec->cdefine.port_connectivity);
1254 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1255 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1256 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1257 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1258 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1259 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1260 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1261
1262 return 0;
1263 }
1264
1265 /* return true if the given NID is found in the list */
1266 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1267 {
1268 return find_idx_in_nid_list(nid, list, nums) >= 0;
1269 }
1270
1271 /* check subsystem ID and set up device-specific initialization;
1272 * return 1 if initialized, 0 if invalid SSID
1273 */
1274 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1275 * 31 ~ 16 : Manufacture ID
1276 * 15 ~ 8 : SKU ID
1277 * 7 ~ 0 : Assembly ID
1278 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1279 */
1280 static int alc_subsystem_id(struct hda_codec *codec,
1281 hda_nid_t porta, hda_nid_t porte,
1282 hda_nid_t portd, hda_nid_t porti)
1283 {
1284 unsigned int ass, tmp, i;
1285 unsigned nid;
1286 struct alc_spec *spec = codec->spec;
1287
1288 if (spec->cdefine.fixup) {
1289 ass = spec->cdefine.sku_cfg;
1290 if (ass == ALC_FIXUP_SKU_IGNORE)
1291 return 0;
1292 goto do_sku;
1293 }
1294
1295 ass = codec->subsystem_id & 0xffff;
1296 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1297 goto do_sku;
1298
1299 /* invalid SSID, check the special NID pin defcfg instead */
1300 /*
1301 * 31~30 : port connectivity
1302 * 29~21 : reserve
1303 * 20 : PCBEEP input
1304 * 19~16 : Check sum (15:1)
1305 * 15~1 : Custom
1306 * 0 : override
1307 */
1308 nid = 0x1d;
1309 if (codec->vendor_id == 0x10ec0260)
1310 nid = 0x17;
1311 ass = snd_hda_codec_get_pincfg(codec, nid);
1312 snd_printd("realtek: No valid SSID, "
1313 "checking pincfg 0x%08x for NID 0x%x\n",
1314 ass, nid);
1315 if (!(ass & 1))
1316 return 0;
1317 if ((ass >> 30) != 1) /* no physical connection */
1318 return 0;
1319
1320 /* check sum */
1321 tmp = 0;
1322 for (i = 1; i < 16; i++) {
1323 if ((ass >> i) & 1)
1324 tmp++;
1325 }
1326 if (((ass >> 16) & 0xf) != tmp)
1327 return 0;
1328 do_sku:
1329 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1330 ass & 0xffff, codec->vendor_id);
1331 /*
1332 * 0 : override
1333 * 1 : Swap Jack
1334 * 2 : 0 --> Desktop, 1 --> Laptop
1335 * 3~5 : External Amplifier control
1336 * 7~6 : Reserved
1337 */
1338 tmp = (ass & 0x38) >> 3; /* external Amp control */
1339 switch (tmp) {
1340 case 1:
1341 spec->init_amp = ALC_INIT_GPIO1;
1342 break;
1343 case 3:
1344 spec->init_amp = ALC_INIT_GPIO2;
1345 break;
1346 case 7:
1347 spec->init_amp = ALC_INIT_GPIO3;
1348 break;
1349 case 5:
1350 default:
1351 spec->init_amp = ALC_INIT_DEFAULT;
1352 break;
1353 }
1354
1355 /* is laptop or Desktop and enable the function "Mute internal speaker
1356 * when the external headphone out jack is plugged"
1357 */
1358 if (!(ass & 0x8000))
1359 return 1;
1360 /*
1361 * 10~8 : Jack location
1362 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1363 * 14~13: Resvered
1364 * 15 : 1 --> enable the function "Mute internal speaker
1365 * when the external headphone out jack is plugged"
1366 */
1367 if (!spec->autocfg.hp_pins[0] &&
1368 !(spec->autocfg.line_out_pins[0] &&
1369 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1370 hda_nid_t nid;
1371 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1372 if (tmp == 0)
1373 nid = porta;
1374 else if (tmp == 1)
1375 nid = porte;
1376 else if (tmp == 2)
1377 nid = portd;
1378 else if (tmp == 3)
1379 nid = porti;
1380 else
1381 return 1;
1382 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1383 spec->autocfg.line_outs))
1384 return 1;
1385 spec->autocfg.hp_pins[0] = nid;
1386 }
1387 return 1;
1388 }
1389
1390 /* Check the validity of ALC subsystem-id
1391 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1392 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1393 {
1394 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1395 struct alc_spec *spec = codec->spec;
1396 snd_printd("realtek: "
1397 "Enable default setup for auto mode as fallback\n");
1398 spec->init_amp = ALC_INIT_DEFAULT;
1399 }
1400 }
1401
1402 /*
1403 * Fix-up pin default configurations and add default verbs
1404 */
1405
1406 struct alc_pincfg {
1407 hda_nid_t nid;
1408 u32 val;
1409 };
1410
1411 struct alc_model_fixup {
1412 const int id;
1413 const char *name;
1414 };
1415
1416 struct alc_fixup {
1417 int type;
1418 bool chained;
1419 int chain_id;
1420 union {
1421 unsigned int sku;
1422 const struct alc_pincfg *pins;
1423 const struct hda_verb *verbs;
1424 void (*func)(struct hda_codec *codec,
1425 const struct alc_fixup *fix,
1426 int action);
1427 } v;
1428 };
1429
1430 enum {
1431 ALC_FIXUP_INVALID,
1432 ALC_FIXUP_SKU,
1433 ALC_FIXUP_PINS,
1434 ALC_FIXUP_VERBS,
1435 ALC_FIXUP_FUNC,
1436 };
1437
1438 enum {
1439 ALC_FIXUP_ACT_PRE_PROBE,
1440 ALC_FIXUP_ACT_PROBE,
1441 ALC_FIXUP_ACT_INIT,
1442 };
1443
1444 static void alc_apply_fixup(struct hda_codec *codec, int action)
1445 {
1446 struct alc_spec *spec = codec->spec;
1447 int id = spec->fixup_id;
1448 #ifdef CONFIG_SND_DEBUG_VERBOSE
1449 const char *modelname = spec->fixup_name;
1450 #endif
1451 int depth = 0;
1452
1453 if (!spec->fixup_list)
1454 return;
1455
1456 while (id >= 0) {
1457 const struct alc_fixup *fix = spec->fixup_list + id;
1458 const struct alc_pincfg *cfg;
1459
1460 switch (fix->type) {
1461 case ALC_FIXUP_SKU:
1462 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1463 break;
1464 snd_printdd(KERN_INFO "hda_codec: %s: "
1465 "Apply sku override for %s\n",
1466 codec->chip_name, modelname);
1467 spec->cdefine.sku_cfg = fix->v.sku;
1468 spec->cdefine.fixup = 1;
1469 break;
1470 case ALC_FIXUP_PINS:
1471 cfg = fix->v.pins;
1472 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1473 break;
1474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply pincfg for %s\n",
1476 codec->chip_name, modelname);
1477 for (; cfg->nid; cfg++)
1478 snd_hda_codec_set_pincfg(codec, cfg->nid,
1479 cfg->val);
1480 break;
1481 case ALC_FIXUP_VERBS:
1482 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1483 break;
1484 snd_printdd(KERN_INFO "hda_codec: %s: "
1485 "Apply fix-verbs for %s\n",
1486 codec->chip_name, modelname);
1487 add_verb(codec->spec, fix->v.verbs);
1488 break;
1489 case ALC_FIXUP_FUNC:
1490 if (!fix->v.func)
1491 break;
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply fix-func for %s\n",
1494 codec->chip_name, modelname);
1495 fix->v.func(codec, fix, action);
1496 break;
1497 default:
1498 snd_printk(KERN_ERR "hda_codec: %s: "
1499 "Invalid fixup type %d\n",
1500 codec->chip_name, fix->type);
1501 break;
1502 }
1503 if (!fix->chained)
1504 break;
1505 if (++depth > 10)
1506 break;
1507 id = fix->chain_id;
1508 }
1509 }
1510
1511 static void alc_pick_fixup(struct hda_codec *codec,
1512 const struct alc_model_fixup *models,
1513 const struct snd_pci_quirk *quirk,
1514 const struct alc_fixup *fixlist)
1515 {
1516 struct alc_spec *spec = codec->spec;
1517 const struct snd_pci_quirk *q;
1518 int id = -1;
1519 const char *name = NULL;
1520
1521 if (codec->modelname && models) {
1522 while (models->name) {
1523 if (!strcmp(codec->modelname, models->name)) {
1524 id = models->id;
1525 name = models->name;
1526 break;
1527 }
1528 models++;
1529 }
1530 }
1531 if (id < 0) {
1532 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1533 if (q) {
1534 id = q->value;
1535 #ifdef CONFIG_SND_DEBUG_VERBOSE
1536 name = q->name;
1537 #endif
1538 }
1539 }
1540 if (id < 0) {
1541 for (q = quirk; q->subvendor; q++) {
1542 unsigned int vendorid =
1543 q->subdevice | (q->subvendor << 16);
1544 if (vendorid == codec->subsystem_id) {
1545 id = q->value;
1546 #ifdef CONFIG_SND_DEBUG_VERBOSE
1547 name = q->name;
1548 #endif
1549 break;
1550 }
1551 }
1552 }
1553
1554 spec->fixup_id = id;
1555 if (id >= 0) {
1556 spec->fixup_list = fixlist;
1557 spec->fixup_name = name;
1558 }
1559 }
1560
1561 /*
1562 * COEF access helper functions
1563 */
1564 static int alc_read_coef_idx(struct hda_codec *codec,
1565 unsigned int coef_idx)
1566 {
1567 unsigned int val;
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1569 coef_idx);
1570 val = snd_hda_codec_read(codec, 0x20, 0,
1571 AC_VERB_GET_PROC_COEF, 0);
1572 return val;
1573 }
1574
1575 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1576 unsigned int coef_val)
1577 {
1578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1579 coef_idx);
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1581 coef_val);
1582 }
1583
1584 /* a special bypass for COEF 0; read the cached value at the second time */
1585 static unsigned int alc_get_coef0(struct hda_codec *codec)
1586 {
1587 struct alc_spec *spec = codec->spec;
1588 if (!spec->coef0)
1589 spec->coef0 = alc_read_coef_idx(codec, 0);
1590 return spec->coef0;
1591 }
1592
1593 /*
1594 * Digital I/O handling
1595 */
1596
1597 /* set right pin controls for digital I/O */
1598 static void alc_auto_init_digital(struct hda_codec *codec)
1599 {
1600 struct alc_spec *spec = codec->spec;
1601 int i;
1602 hda_nid_t pin, dac;
1603
1604 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1605 pin = spec->autocfg.dig_out_pins[i];
1606 if (!pin)
1607 continue;
1608 snd_hda_codec_write(codec, pin, 0,
1609 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1610 if (!i)
1611 dac = spec->multiout.dig_out_nid;
1612 else
1613 dac = spec->slave_dig_outs[i - 1];
1614 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1615 continue;
1616 snd_hda_codec_write(codec, dac, 0,
1617 AC_VERB_SET_AMP_GAIN_MUTE,
1618 AMP_OUT_UNMUTE);
1619 }
1620 pin = spec->autocfg.dig_in_pin;
1621 if (pin)
1622 snd_hda_codec_write(codec, pin, 0,
1623 AC_VERB_SET_PIN_WIDGET_CONTROL,
1624 PIN_IN);
1625 }
1626
1627 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1628 static void alc_auto_parse_digital(struct hda_codec *codec)
1629 {
1630 struct alc_spec *spec = codec->spec;
1631 int i, err, nums;
1632 hda_nid_t dig_nid;
1633
1634 /* support multiple SPDIFs; the secondary is set up as a slave */
1635 nums = 0;
1636 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1637 hda_nid_t conn[4];
1638 err = snd_hda_get_connections(codec,
1639 spec->autocfg.dig_out_pins[i],
1640 conn, ARRAY_SIZE(conn));
1641 if (err <= 0)
1642 continue;
1643 dig_nid = conn[0]; /* assume the first element is audio-out */
1644 if (!nums) {
1645 spec->multiout.dig_out_nid = dig_nid;
1646 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1647 } else {
1648 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1649 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1650 break;
1651 spec->slave_dig_outs[nums - 1] = dig_nid;
1652 }
1653 nums++;
1654 }
1655
1656 if (spec->autocfg.dig_in_pin) {
1657 dig_nid = codec->start_nid;
1658 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1659 unsigned int wcaps = get_wcaps(codec, dig_nid);
1660 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1661 continue;
1662 if (!(wcaps & AC_WCAP_DIGITAL))
1663 continue;
1664 if (!(wcaps & AC_WCAP_CONN_LIST))
1665 continue;
1666 err = get_connection_index(codec, dig_nid,
1667 spec->autocfg.dig_in_pin);
1668 if (err >= 0) {
1669 spec->dig_in_nid = dig_nid;
1670 break;
1671 }
1672 }
1673 }
1674 }
1675
1676 /*
1677 * capture mixer elements
1678 */
1679 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_info *uinfo)
1681 {
1682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1683 struct alc_spec *spec = codec->spec;
1684 unsigned long val;
1685 int err;
1686
1687 mutex_lock(&codec->control_mutex);
1688 if (spec->vol_in_capsrc)
1689 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1690 else
1691 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1692 kcontrol->private_value = val;
1693 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1694 mutex_unlock(&codec->control_mutex);
1695 return err;
1696 }
1697
1698 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1699 unsigned int size, unsigned int __user *tlv)
1700 {
1701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1702 struct alc_spec *spec = codec->spec;
1703 unsigned long val;
1704 int err;
1705
1706 mutex_lock(&codec->control_mutex);
1707 if (spec->vol_in_capsrc)
1708 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1709 else
1710 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1711 kcontrol->private_value = val;
1712 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1713 mutex_unlock(&codec->control_mutex);
1714 return err;
1715 }
1716
1717 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_value *ucontrol);
1719
1720 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1721 struct snd_ctl_elem_value *ucontrol,
1722 getput_call_t func, bool check_adc_switch)
1723 {
1724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1725 struct alc_spec *spec = codec->spec;
1726 int i, err = 0;
1727
1728 mutex_lock(&codec->control_mutex);
1729 if (check_adc_switch && spec->dyn_adc_switch) {
1730 for (i = 0; i < spec->num_adc_nids; i++) {
1731 kcontrol->private_value =
1732 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1733 3, 0, HDA_INPUT);
1734 err = func(kcontrol, ucontrol);
1735 if (err < 0)
1736 goto error;
1737 }
1738 } else {
1739 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1740 if (spec->vol_in_capsrc)
1741 kcontrol->private_value =
1742 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1743 3, 0, HDA_OUTPUT);
1744 else
1745 kcontrol->private_value =
1746 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1747 3, 0, HDA_INPUT);
1748 err = func(kcontrol, ucontrol);
1749 }
1750 error:
1751 mutex_unlock(&codec->control_mutex);
1752 return err;
1753 }
1754
1755 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1757 {
1758 return alc_cap_getput_caller(kcontrol, ucontrol,
1759 snd_hda_mixer_amp_volume_get, false);
1760 }
1761
1762 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1764 {
1765 return alc_cap_getput_caller(kcontrol, ucontrol,
1766 snd_hda_mixer_amp_volume_put, true);
1767 }
1768
1769 /* capture mixer elements */
1770 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1771
1772 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
1774 {
1775 return alc_cap_getput_caller(kcontrol, ucontrol,
1776 snd_hda_mixer_amp_switch_get, false);
1777 }
1778
1779 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_value *ucontrol)
1781 {
1782 return alc_cap_getput_caller(kcontrol, ucontrol,
1783 snd_hda_mixer_amp_switch_put, true);
1784 }
1785
1786 #define _DEFINE_CAPMIX(num) \
1787 { \
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1789 .name = "Capture Switch", \
1790 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1791 .count = num, \
1792 .info = alc_cap_sw_info, \
1793 .get = alc_cap_sw_get, \
1794 .put = alc_cap_sw_put, \
1795 }, \
1796 { \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Volume", \
1799 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1800 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1801 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1802 .count = num, \
1803 .info = alc_cap_vol_info, \
1804 .get = alc_cap_vol_get, \
1805 .put = alc_cap_vol_put, \
1806 .tlv = { .c = alc_cap_vol_tlv }, \
1807 }
1808
1809 #define _DEFINE_CAPSRC(num) \
1810 { \
1811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 /* .name = "Capture Source", */ \
1813 .name = "Input Source", \
1814 .count = num, \
1815 .info = alc_mux_enum_info, \
1816 .get = alc_mux_enum_get, \
1817 .put = alc_mux_enum_put, \
1818 }
1819
1820 #define DEFINE_CAPMIX(num) \
1821 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1822 _DEFINE_CAPMIX(num), \
1823 _DEFINE_CAPSRC(num), \
1824 { } /* end */ \
1825 }
1826
1827 #define DEFINE_CAPMIX_NOSRC(num) \
1828 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1829 _DEFINE_CAPMIX(num), \
1830 { } /* end */ \
1831 }
1832
1833 /* up to three ADCs */
1834 DEFINE_CAPMIX(1);
1835 DEFINE_CAPMIX(2);
1836 DEFINE_CAPMIX(3);
1837 DEFINE_CAPMIX_NOSRC(1);
1838 DEFINE_CAPMIX_NOSRC(2);
1839 DEFINE_CAPMIX_NOSRC(3);
1840
1841 /*
1842 * virtual master controls
1843 */
1844
1845 /*
1846 * slave controls for virtual master
1847 */
1848 static const char * const alc_slave_pfxs[] = {
1849 "Front", "Surround", "Center", "LFE", "Side",
1850 "Headphone", "Speaker", "Mono", "Line-Out",
1851 "CLFE", "Bass Speaker", "PCM",
1852 NULL,
1853 };
1854
1855 /*
1856 * build control elements
1857 */
1858
1859 #define NID_MAPPING (-1)
1860
1861 #define SUBDEV_SPEAKER_ (0 << 6)
1862 #define SUBDEV_HP_ (1 << 6)
1863 #define SUBDEV_LINE_ (2 << 6)
1864 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1865 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1866 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1867
1868 static void alc_free_kctls(struct hda_codec *codec);
1869
1870 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1871 /* additional beep mixers; the actual parameters are overwritten at build */
1872 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1873 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1874 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1875 { } /* end */
1876 };
1877 #endif
1878
1879 static int __alc_build_controls(struct hda_codec *codec)
1880 {
1881 struct alc_spec *spec = codec->spec;
1882 struct snd_kcontrol *kctl = NULL;
1883 const struct snd_kcontrol_new *knew;
1884 int i, j, err;
1885 unsigned int u;
1886 hda_nid_t nid;
1887
1888 for (i = 0; i < spec->num_mixers; i++) {
1889 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1890 if (err < 0)
1891 return err;
1892 }
1893 if (spec->cap_mixer) {
1894 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1895 if (err < 0)
1896 return err;
1897 }
1898 if (spec->multiout.dig_out_nid) {
1899 err = snd_hda_create_spdif_out_ctls(codec,
1900 spec->multiout.dig_out_nid,
1901 spec->multiout.dig_out_nid);
1902 if (err < 0)
1903 return err;
1904 if (!spec->no_analog) {
1905 err = snd_hda_create_spdif_share_sw(codec,
1906 &spec->multiout);
1907 if (err < 0)
1908 return err;
1909 spec->multiout.share_spdif = 1;
1910 }
1911 }
1912 if (spec->dig_in_nid) {
1913 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1914 if (err < 0)
1915 return err;
1916 }
1917
1918 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1919 /* create beep controls if needed */
1920 if (spec->beep_amp) {
1921 const struct snd_kcontrol_new *knew;
1922 for (knew = alc_beep_mixer; knew->name; knew++) {
1923 struct snd_kcontrol *kctl;
1924 kctl = snd_ctl_new1(knew, codec);
1925 if (!kctl)
1926 return -ENOMEM;
1927 kctl->private_value = spec->beep_amp;
1928 err = snd_hda_ctl_add(codec, 0, kctl);
1929 if (err < 0)
1930 return err;
1931 }
1932 }
1933 #endif
1934
1935 /* if we have no master control, let's create it */
1936 if (!spec->no_analog &&
1937 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1938 unsigned int vmaster_tlv[4];
1939 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1940 HDA_OUTPUT, vmaster_tlv);
1941 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1942 vmaster_tlv, alc_slave_pfxs,
1943 "Playback Volume");
1944 if (err < 0)
1945 return err;
1946 }
1947 if (!spec->no_analog &&
1948 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1949 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1950 NULL, alc_slave_pfxs,
1951 "Playback Switch");
1952 if (err < 0)
1953 return err;
1954 }
1955
1956 /* assign Capture Source enums to NID */
1957 if (spec->capsrc_nids || spec->adc_nids) {
1958 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1959 if (!kctl)
1960 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1961 for (i = 0; kctl && i < kctl->count; i++) {
1962 err = snd_hda_add_nid(codec, kctl, i,
1963 get_capsrc(spec, i));
1964 if (err < 0)
1965 return err;
1966 }
1967 }
1968 if (spec->cap_mixer && spec->adc_nids) {
1969 const char *kname = kctl ? kctl->id.name : NULL;
1970 for (knew = spec->cap_mixer; knew->name; knew++) {
1971 if (kname && strcmp(knew->name, kname) == 0)
1972 continue;
1973 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1974 for (i = 0; kctl && i < kctl->count; i++) {
1975 err = snd_hda_add_nid(codec, kctl, i,
1976 spec->adc_nids[i]);
1977 if (err < 0)
1978 return err;
1979 }
1980 }
1981 }
1982
1983 /* other nid->control mapping */
1984 for (i = 0; i < spec->num_mixers; i++) {
1985 for (knew = spec->mixers[i]; knew->name; knew++) {
1986 if (knew->iface != NID_MAPPING)
1987 continue;
1988 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1989 if (kctl == NULL)
1990 continue;
1991 u = knew->subdevice;
1992 for (j = 0; j < 4; j++, u >>= 8) {
1993 nid = u & 0x3f;
1994 if (nid == 0)
1995 continue;
1996 switch (u & 0xc0) {
1997 case SUBDEV_SPEAKER_:
1998 nid = spec->autocfg.speaker_pins[nid];
1999 break;
2000 case SUBDEV_LINE_:
2001 nid = spec->autocfg.line_out_pins[nid];
2002 break;
2003 case SUBDEV_HP_:
2004 nid = spec->autocfg.hp_pins[nid];
2005 break;
2006 default:
2007 continue;
2008 }
2009 err = snd_hda_add_nid(codec, kctl, 0, nid);
2010 if (err < 0)
2011 return err;
2012 }
2013 u = knew->private_value;
2014 for (j = 0; j < 4; j++, u >>= 8) {
2015 nid = u & 0xff;
2016 if (nid == 0)
2017 continue;
2018 err = snd_hda_add_nid(codec, kctl, 0, nid);
2019 if (err < 0)
2020 return err;
2021 }
2022 }
2023 }
2024
2025 alc_free_kctls(codec); /* no longer needed */
2026
2027 return 0;
2028 }
2029
2030 static int alc_build_controls(struct hda_codec *codec)
2031 {
2032 struct alc_spec *spec = codec->spec;
2033 int err = __alc_build_controls(codec);
2034 if (err < 0)
2035 return err;
2036 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2037 }
2038
2039
2040 /*
2041 * Common callbacks
2042 */
2043
2044 static void alc_init_special_input_src(struct hda_codec *codec);
2045
2046 static int alc_init(struct hda_codec *codec)
2047 {
2048 struct alc_spec *spec = codec->spec;
2049 unsigned int i;
2050
2051 alc_fix_pll(codec);
2052 alc_auto_init_amp(codec, spec->init_amp);
2053
2054 for (i = 0; i < spec->num_init_verbs; i++)
2055 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2056 alc_init_special_input_src(codec);
2057
2058 if (spec->init_hook)
2059 spec->init_hook(codec);
2060
2061 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2062
2063 snd_hda_jack_report_sync(codec);
2064
2065 hda_call_check_power_status(codec, 0x01);
2066 return 0;
2067 }
2068
2069 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2070 {
2071 struct alc_spec *spec = codec->spec;
2072
2073 if (spec->unsol_event)
2074 spec->unsol_event(codec, res);
2075 }
2076
2077 #ifdef CONFIG_SND_HDA_POWER_SAVE
2078 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2079 {
2080 struct alc_spec *spec = codec->spec;
2081 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2082 }
2083 #endif
2084
2085 /*
2086 * Analog playback callbacks
2087 */
2088 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2089 struct hda_codec *codec,
2090 struct snd_pcm_substream *substream)
2091 {
2092 struct alc_spec *spec = codec->spec;
2093 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2094 hinfo);
2095 }
2096
2097 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2098 struct hda_codec *codec,
2099 unsigned int stream_tag,
2100 unsigned int format,
2101 struct snd_pcm_substream *substream)
2102 {
2103 struct alc_spec *spec = codec->spec;
2104 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2105 stream_tag, format, substream);
2106 }
2107
2108 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2109 struct hda_codec *codec,
2110 struct snd_pcm_substream *substream)
2111 {
2112 struct alc_spec *spec = codec->spec;
2113 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2114 }
2115
2116 /*
2117 * Digital out
2118 */
2119 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2120 struct hda_codec *codec,
2121 struct snd_pcm_substream *substream)
2122 {
2123 struct alc_spec *spec = codec->spec;
2124 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2125 }
2126
2127 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2128 struct hda_codec *codec,
2129 unsigned int stream_tag,
2130 unsigned int format,
2131 struct snd_pcm_substream *substream)
2132 {
2133 struct alc_spec *spec = codec->spec;
2134 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2135 stream_tag, format, substream);
2136 }
2137
2138 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2139 struct hda_codec *codec,
2140 struct snd_pcm_substream *substream)
2141 {
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2144 }
2145
2146 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2147 struct hda_codec *codec,
2148 struct snd_pcm_substream *substream)
2149 {
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2152 }
2153
2154 /*
2155 * Analog capture
2156 */
2157 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2158 struct hda_codec *codec,
2159 unsigned int stream_tag,
2160 unsigned int format,
2161 struct snd_pcm_substream *substream)
2162 {
2163 struct alc_spec *spec = codec->spec;
2164
2165 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2166 stream_tag, 0, format);
2167 return 0;
2168 }
2169
2170 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2171 struct hda_codec *codec,
2172 struct snd_pcm_substream *substream)
2173 {
2174 struct alc_spec *spec = codec->spec;
2175
2176 snd_hda_codec_cleanup_stream(codec,
2177 spec->adc_nids[substream->number + 1]);
2178 return 0;
2179 }
2180
2181 /* analog capture with dynamic dual-adc changes */
2182 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2183 struct hda_codec *codec,
2184 unsigned int stream_tag,
2185 unsigned int format,
2186 struct snd_pcm_substream *substream)
2187 {
2188 struct alc_spec *spec = codec->spec;
2189 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2190 spec->cur_adc_stream_tag = stream_tag;
2191 spec->cur_adc_format = format;
2192 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2193 return 0;
2194 }
2195
2196 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2197 struct hda_codec *codec,
2198 struct snd_pcm_substream *substream)
2199 {
2200 struct alc_spec *spec = codec->spec;
2201 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2202 spec->cur_adc = 0;
2203 return 0;
2204 }
2205
2206 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2207 .substreams = 1,
2208 .channels_min = 2,
2209 .channels_max = 2,
2210 .nid = 0, /* fill later */
2211 .ops = {
2212 .prepare = dyn_adc_capture_pcm_prepare,
2213 .cleanup = dyn_adc_capture_pcm_cleanup
2214 },
2215 };
2216
2217 /*
2218 */
2219 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2220 .substreams = 1,
2221 .channels_min = 2,
2222 .channels_max = 8,
2223 /* NID is set in alc_build_pcms */
2224 .ops = {
2225 .open = alc_playback_pcm_open,
2226 .prepare = alc_playback_pcm_prepare,
2227 .cleanup = alc_playback_pcm_cleanup
2228 },
2229 };
2230
2231 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2232 .substreams = 1,
2233 .channels_min = 2,
2234 .channels_max = 2,
2235 /* NID is set in alc_build_pcms */
2236 };
2237
2238 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2239 .substreams = 1,
2240 .channels_min = 2,
2241 .channels_max = 2,
2242 /* NID is set in alc_build_pcms */
2243 };
2244
2245 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2246 .substreams = 2, /* can be overridden */
2247 .channels_min = 2,
2248 .channels_max = 2,
2249 /* NID is set in alc_build_pcms */
2250 .ops = {
2251 .prepare = alc_alt_capture_pcm_prepare,
2252 .cleanup = alc_alt_capture_pcm_cleanup
2253 },
2254 };
2255
2256 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2257 .substreams = 1,
2258 .channels_min = 2,
2259 .channels_max = 2,
2260 /* NID is set in alc_build_pcms */
2261 .ops = {
2262 .open = alc_dig_playback_pcm_open,
2263 .close = alc_dig_playback_pcm_close,
2264 .prepare = alc_dig_playback_pcm_prepare,
2265 .cleanup = alc_dig_playback_pcm_cleanup
2266 },
2267 };
2268
2269 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2270 .substreams = 1,
2271 .channels_min = 2,
2272 .channels_max = 2,
2273 /* NID is set in alc_build_pcms */
2274 };
2275
2276 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2277 static const struct hda_pcm_stream alc_pcm_null_stream = {
2278 .substreams = 0,
2279 .channels_min = 0,
2280 .channels_max = 0,
2281 };
2282
2283 static int alc_build_pcms(struct hda_codec *codec)
2284 {
2285 struct alc_spec *spec = codec->spec;
2286 struct hda_pcm *info = spec->pcm_rec;
2287 const struct hda_pcm_stream *p;
2288 bool have_multi_adcs;
2289 int i;
2290
2291 codec->num_pcms = 1;
2292 codec->pcm_info = info;
2293
2294 if (spec->no_analog)
2295 goto skip_analog;
2296
2297 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2298 "%s Analog", codec->chip_name);
2299 info->name = spec->stream_name_analog;
2300
2301 if (spec->multiout.num_dacs > 0) {
2302 p = spec->stream_analog_playback;
2303 if (!p)
2304 p = &alc_pcm_analog_playback;
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2307 }
2308 if (spec->adc_nids) {
2309 p = spec->stream_analog_capture;
2310 if (!p) {
2311 if (spec->dyn_adc_switch)
2312 p = &dyn_adc_pcm_analog_capture;
2313 else
2314 p = &alc_pcm_analog_capture;
2315 }
2316 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2317 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2318 }
2319
2320 if (spec->channel_mode) {
2321 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2322 for (i = 0; i < spec->num_channel_mode; i++) {
2323 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2325 }
2326 }
2327 }
2328
2329 skip_analog:
2330 /* SPDIF for stream index #1 */
2331 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2332 snprintf(spec->stream_name_digital,
2333 sizeof(spec->stream_name_digital),
2334 "%s Digital", codec->chip_name);
2335 codec->num_pcms = 2;
2336 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2337 info = spec->pcm_rec + 1;
2338 info->name = spec->stream_name_digital;
2339 if (spec->dig_out_type)
2340 info->pcm_type = spec->dig_out_type;
2341 else
2342 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2343 if (spec->multiout.dig_out_nid) {
2344 p = spec->stream_digital_playback;
2345 if (!p)
2346 p = &alc_pcm_digital_playback;
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2349 }
2350 if (spec->dig_in_nid) {
2351 p = spec->stream_digital_capture;
2352 if (!p)
2353 p = &alc_pcm_digital_capture;
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2355 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2356 }
2357 /* FIXME: do we need this for all Realtek codec models? */
2358 codec->spdif_status_reset = 1;
2359 }
2360
2361 if (spec->no_analog)
2362 return 0;
2363
2364 /* If the use of more than one ADC is requested for the current
2365 * model, configure a second analog capture-only PCM.
2366 */
2367 have_multi_adcs = (spec->num_adc_nids > 1) &&
2368 !spec->dyn_adc_switch && !spec->auto_mic &&
2369 (!spec->input_mux || spec->input_mux->num_items > 1);
2370 /* Additional Analaog capture for index #2 */
2371 if (spec->alt_dac_nid || have_multi_adcs) {
2372 codec->num_pcms = 3;
2373 info = spec->pcm_rec + 2;
2374 info->name = spec->stream_name_analog;
2375 if (spec->alt_dac_nid) {
2376 p = spec->stream_analog_alt_playback;
2377 if (!p)
2378 p = &alc_pcm_analog_alt_playback;
2379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2380 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2381 spec->alt_dac_nid;
2382 } else {
2383 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2384 alc_pcm_null_stream;
2385 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2386 }
2387 if (have_multi_adcs) {
2388 p = spec->stream_analog_alt_capture;
2389 if (!p)
2390 p = &alc_pcm_analog_alt_capture;
2391 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2392 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2393 spec->adc_nids[1];
2394 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2395 spec->num_adc_nids - 1;
2396 } else {
2397 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2398 alc_pcm_null_stream;
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2400 }
2401 }
2402
2403 return 0;
2404 }
2405
2406 static inline void alc_shutup(struct hda_codec *codec)
2407 {
2408 struct alc_spec *spec = codec->spec;
2409
2410 if (spec && spec->shutup)
2411 spec->shutup(codec);
2412 snd_hda_shutup_pins(codec);
2413 }
2414
2415 static void alc_free_kctls(struct hda_codec *codec)
2416 {
2417 struct alc_spec *spec = codec->spec;
2418
2419 if (spec->kctls.list) {
2420 struct snd_kcontrol_new *kctl = spec->kctls.list;
2421 int i;
2422 for (i = 0; i < spec->kctls.used; i++)
2423 kfree(kctl[i].name);
2424 }
2425 snd_array_free(&spec->kctls);
2426 }
2427
2428 static void alc_free_bind_ctls(struct hda_codec *codec)
2429 {
2430 struct alc_spec *spec = codec->spec;
2431 if (spec->bind_ctls.list) {
2432 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2433 int i;
2434 for (i = 0; i < spec->bind_ctls.used; i++)
2435 kfree(ctl[i]);
2436 }
2437 snd_array_free(&spec->bind_ctls);
2438 }
2439
2440 static void alc_free(struct hda_codec *codec)
2441 {
2442 struct alc_spec *spec = codec->spec;
2443
2444 if (!spec)
2445 return;
2446
2447 alc_shutup(codec);
2448 alc_free_kctls(codec);
2449 alc_free_bind_ctls(codec);
2450 kfree(spec);
2451 snd_hda_detach_beep_device(codec);
2452 }
2453
2454 #ifdef CONFIG_SND_HDA_POWER_SAVE
2455 static void alc_power_eapd(struct hda_codec *codec)
2456 {
2457 alc_auto_setup_eapd(codec, false);
2458 }
2459
2460 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2461 {
2462 struct alc_spec *spec = codec->spec;
2463 alc_shutup(codec);
2464 if (spec && spec->power_hook)
2465 spec->power_hook(codec);
2466 return 0;
2467 }
2468 #endif
2469
2470 #ifdef CONFIG_PM
2471 static int alc_resume(struct hda_codec *codec)
2472 {
2473 msleep(150); /* to avoid pop noise */
2474 codec->patch_ops.init(codec);
2475 snd_hda_codec_resume_amp(codec);
2476 snd_hda_codec_resume_cache(codec);
2477 hda_call_check_power_status(codec, 0x01);
2478 return 0;
2479 }
2480 #endif
2481
2482 /*
2483 */
2484 static const struct hda_codec_ops alc_patch_ops = {
2485 .build_controls = alc_build_controls,
2486 .build_pcms = alc_build_pcms,
2487 .init = alc_init,
2488 .free = alc_free,
2489 .unsol_event = alc_unsol_event,
2490 #ifdef CONFIG_PM
2491 .resume = alc_resume,
2492 #endif
2493 #ifdef CONFIG_SND_HDA_POWER_SAVE
2494 .suspend = alc_suspend,
2495 .check_power_status = alc_check_power_status,
2496 #endif
2497 .reboot_notify = alc_shutup,
2498 };
2499
2500 /* replace the codec chip_name with the given string */
2501 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2502 {
2503 kfree(codec->chip_name);
2504 codec->chip_name = kstrdup(name, GFP_KERNEL);
2505 if (!codec->chip_name) {
2506 alc_free(codec);
2507 return -ENOMEM;
2508 }
2509 return 0;
2510 }
2511
2512 /*
2513 * Rename codecs appropriately from COEF value
2514 */
2515 struct alc_codec_rename_table {
2516 unsigned int vendor_id;
2517 unsigned short coef_mask;
2518 unsigned short coef_bits;
2519 const char *name;
2520 };
2521
2522 static struct alc_codec_rename_table rename_tbl[] = {
2523 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2524 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2525 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2526 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2527 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2528 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2529 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2530 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2531 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2532 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2533 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2534 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2535 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2536 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2537 { } /* terminator */
2538 };
2539
2540 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2541 {
2542 const struct alc_codec_rename_table *p;
2543
2544 for (p = rename_tbl; p->vendor_id; p++) {
2545 if (p->vendor_id != codec->vendor_id)
2546 continue;
2547 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2548 return alc_codec_rename(codec, p->name);
2549 }
2550 return 0;
2551 }
2552
2553 /*
2554 * Automatic parse of I/O pins from the BIOS configuration
2555 */
2556
2557 enum {
2558 ALC_CTL_WIDGET_VOL,
2559 ALC_CTL_WIDGET_MUTE,
2560 ALC_CTL_BIND_MUTE,
2561 ALC_CTL_BIND_VOL,
2562 ALC_CTL_BIND_SW,
2563 };
2564 static const struct snd_kcontrol_new alc_control_templates[] = {
2565 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2566 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2567 HDA_BIND_MUTE(NULL, 0, 0, 0),
2568 HDA_BIND_VOL(NULL, 0),
2569 HDA_BIND_SW(NULL, 0),
2570 };
2571
2572 /* add dynamic controls */
2573 static int add_control(struct alc_spec *spec, int type, const char *name,
2574 int cidx, unsigned long val)
2575 {
2576 struct snd_kcontrol_new *knew;
2577
2578 knew = alc_kcontrol_new(spec);
2579 if (!knew)
2580 return -ENOMEM;
2581 *knew = alc_control_templates[type];
2582 knew->name = kstrdup(name, GFP_KERNEL);
2583 if (!knew->name)
2584 return -ENOMEM;
2585 knew->index = cidx;
2586 if (get_amp_nid_(val))
2587 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2588 knew->private_value = val;
2589 return 0;
2590 }
2591
2592 static int add_control_with_pfx(struct alc_spec *spec, int type,
2593 const char *pfx, const char *dir,
2594 const char *sfx, int cidx, unsigned long val)
2595 {
2596 char name[32];
2597 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2598 return add_control(spec, type, name, cidx, val);
2599 }
2600
2601 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2602 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2603 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2605 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2607 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2609
2610 static const char * const channel_name[4] = {
2611 "Front", "Surround", "CLFE", "Side"
2612 };
2613
2614 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2615 bool can_be_master, int *index)
2616 {
2617 struct auto_pin_cfg *cfg = &spec->autocfg;
2618
2619 *index = 0;
2620 if (cfg->line_outs == 1 && !spec->multi_ios &&
2621 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2622 return "Master";
2623
2624 switch (cfg->line_out_type) {
2625 case AUTO_PIN_SPEAKER_OUT:
2626 if (cfg->line_outs == 1)
2627 return "Speaker";
2628 if (cfg->line_outs == 2)
2629 return ch ? "Bass Speaker" : "Speaker";
2630 break;
2631 case AUTO_PIN_HP_OUT:
2632 /* for multi-io case, only the primary out */
2633 if (ch && spec->multi_ios)
2634 break;
2635 *index = ch;
2636 return "Headphone";
2637 default:
2638 if (cfg->line_outs == 1 && !spec->multi_ios)
2639 return "PCM";
2640 break;
2641 }
2642 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2643 return "PCM";
2644
2645 return channel_name[ch];
2646 }
2647
2648 /* create input playback/capture controls for the given pin */
2649 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2650 const char *ctlname, int ctlidx,
2651 int idx, hda_nid_t mix_nid)
2652 {
2653 int err;
2654
2655 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2656 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2657 if (err < 0)
2658 return err;
2659 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2660 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 if (err < 0)
2662 return err;
2663 return 0;
2664 }
2665
2666 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2667 {
2668 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2669 return (pincap & AC_PINCAP_IN) != 0;
2670 }
2671
2672 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2673 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2674 {
2675 struct alc_spec *spec = codec->spec;
2676 hda_nid_t nid;
2677 hda_nid_t *adc_nids = spec->private_adc_nids;
2678 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2679 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2680 int i, nums = 0;
2681
2682 if (spec->shared_mic_hp)
2683 max_nums = 1; /* no multi streams with the shared HP/mic */
2684
2685 nid = codec->start_nid;
2686 for (i = 0; i < codec->num_nodes; i++, nid++) {
2687 hda_nid_t src;
2688 const hda_nid_t *list;
2689 unsigned int caps = get_wcaps(codec, nid);
2690 int type = get_wcaps_type(caps);
2691
2692 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2693 continue;
2694 adc_nids[nums] = nid;
2695 cap_nids[nums] = nid;
2696 src = nid;
2697 for (;;) {
2698 int n;
2699 type = get_wcaps_type(get_wcaps(codec, src));
2700 if (type == AC_WID_PIN)
2701 break;
2702 if (type == AC_WID_AUD_SEL) {
2703 cap_nids[nums] = src;
2704 break;
2705 }
2706 n = snd_hda_get_conn_list(codec, src, &list);
2707 if (n > 1) {
2708 cap_nids[nums] = src;
2709 break;
2710 } else if (n != 1)
2711 break;
2712 src = *list;
2713 }
2714 if (++nums >= max_nums)
2715 break;
2716 }
2717 spec->adc_nids = spec->private_adc_nids;
2718 spec->capsrc_nids = spec->private_capsrc_nids;
2719 spec->num_adc_nids = nums;
2720 return nums;
2721 }
2722
2723 /* create playback/capture controls for input pins */
2724 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2725 {
2726 struct alc_spec *spec = codec->spec;
2727 const struct auto_pin_cfg *cfg = &spec->autocfg;
2728 hda_nid_t mixer = spec->mixer_nid;
2729 struct hda_input_mux *imux = &spec->private_imux[0];
2730 int num_adcs;
2731 int i, c, err, idx, type_idx = 0;
2732 const char *prev_label = NULL;
2733
2734 num_adcs = alc_auto_fill_adc_caps(codec);
2735 if (num_adcs < 0)
2736 return 0;
2737
2738 for (i = 0; i < cfg->num_inputs; i++) {
2739 hda_nid_t pin;
2740 const char *label;
2741
2742 pin = cfg->inputs[i].pin;
2743 if (!alc_is_input_pin(codec, pin))
2744 continue;
2745
2746 label = hda_get_autocfg_input_label(codec, cfg, i);
2747 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2748 label = "Headphone Mic";
2749 if (prev_label && !strcmp(label, prev_label))
2750 type_idx++;
2751 else
2752 type_idx = 0;
2753 prev_label = label;
2754
2755 if (mixer) {
2756 idx = get_connection_index(codec, mixer, pin);
2757 if (idx >= 0) {
2758 err = new_analog_input(spec, pin,
2759 label, type_idx,
2760 idx, mixer);
2761 if (err < 0)
2762 return err;
2763 }
2764 }
2765
2766 for (c = 0; c < num_adcs; c++) {
2767 hda_nid_t cap = get_capsrc(spec, c);
2768 idx = get_connection_index(codec, cap, pin);
2769 if (idx >= 0) {
2770 spec->imux_pins[imux->num_items] = pin;
2771 snd_hda_add_imux_item(imux, label, idx, NULL);
2772 break;
2773 }
2774 }
2775 }
2776
2777 spec->num_mux_defs = 1;
2778 spec->input_mux = imux;
2779
2780 return 0;
2781 }
2782
2783 /* create a shared input with the headphone out */
2784 static int alc_auto_create_shared_input(struct hda_codec *codec)
2785 {
2786 struct alc_spec *spec = codec->spec;
2787 struct auto_pin_cfg *cfg = &spec->autocfg;
2788 unsigned int defcfg;
2789 hda_nid_t nid;
2790
2791 /* only one internal input pin? */
2792 if (cfg->num_inputs != 1)
2793 return 0;
2794 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2795 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2796 return 0;
2797
2798 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2799 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2800 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2801 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2802 else
2803 return 0; /* both not available */
2804
2805 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2806 return 0; /* no input */
2807
2808 cfg->inputs[1].pin = nid;
2809 cfg->inputs[1].type = AUTO_PIN_MIC;
2810 cfg->num_inputs = 2;
2811 spec->shared_mic_hp = 1;
2812 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2813 return 0;
2814 }
2815
2816 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2817 unsigned int pin_type)
2818 {
2819 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2820 pin_type);
2821 /* unmute pin */
2822 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2823 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2824 AMP_OUT_UNMUTE);
2825 }
2826
2827 static int get_pin_type(int line_out_type)
2828 {
2829 if (line_out_type == AUTO_PIN_HP_OUT)
2830 return PIN_HP;
2831 else
2832 return PIN_OUT;
2833 }
2834
2835 static void alc_auto_init_analog_input(struct hda_codec *codec)
2836 {
2837 struct alc_spec *spec = codec->spec;
2838 struct auto_pin_cfg *cfg = &spec->autocfg;
2839 int i;
2840
2841 for (i = 0; i < cfg->num_inputs; i++) {
2842 hda_nid_t nid = cfg->inputs[i].pin;
2843 if (alc_is_input_pin(codec, nid)) {
2844 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2845 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2846 snd_hda_codec_write(codec, nid, 0,
2847 AC_VERB_SET_AMP_GAIN_MUTE,
2848 AMP_OUT_MUTE);
2849 }
2850 }
2851
2852 /* mute all loopback inputs */
2853 if (spec->mixer_nid) {
2854 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2855 for (i = 0; i < nums; i++)
2856 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2857 AC_VERB_SET_AMP_GAIN_MUTE,
2858 AMP_IN_MUTE(i));
2859 }
2860 }
2861
2862 /* convert from MIX nid to DAC */
2863 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2864 {
2865 hda_nid_t list[5];
2866 int i, num;
2867
2868 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2869 return nid;
2870 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2871 for (i = 0; i < num; i++) {
2872 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2873 return list[i];
2874 }
2875 return 0;
2876 }
2877
2878 /* go down to the selector widget before the mixer */
2879 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2880 {
2881 hda_nid_t srcs[5];
2882 int num = snd_hda_get_connections(codec, pin, srcs,
2883 ARRAY_SIZE(srcs));
2884 if (num != 1 ||
2885 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2886 return pin;
2887 return srcs[0];
2888 }
2889
2890 /* get MIX nid connected to the given pin targeted to DAC */
2891 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2892 hda_nid_t dac)
2893 {
2894 hda_nid_t mix[5];
2895 int i, num;
2896
2897 pin = alc_go_down_to_selector(codec, pin);
2898 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2899 for (i = 0; i < num; i++) {
2900 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2901 return mix[i];
2902 }
2903 return 0;
2904 }
2905
2906 /* select the connection from pin to DAC if needed */
2907 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2908 hda_nid_t dac)
2909 {
2910 hda_nid_t mix[5];
2911 int i, num;
2912
2913 pin = alc_go_down_to_selector(codec, pin);
2914 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2915 if (num < 2)
2916 return 0;
2917 for (i = 0; i < num; i++) {
2918 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2919 snd_hda_codec_update_cache(codec, pin, 0,
2920 AC_VERB_SET_CONNECT_SEL, i);
2921 return 0;
2922 }
2923 }
2924 return 0;
2925 }
2926
2927 /* look for an empty DAC slot */
2928 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2929 {
2930 struct alc_spec *spec = codec->spec;
2931 hda_nid_t srcs[5];
2932 int i, num;
2933
2934 pin = alc_go_down_to_selector(codec, pin);
2935 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2936 for (i = 0; i < num; i++) {
2937 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2938 if (!nid)
2939 continue;
2940 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2941 ARRAY_SIZE(spec->private_dac_nids)))
2942 continue;
2943 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2944 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2945 continue;
2946 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2947 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2948 continue;
2949 return nid;
2950 }
2951 return 0;
2952 }
2953
2954 /* check whether the DAC is reachable from the pin */
2955 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2956 hda_nid_t pin, hda_nid_t dac)
2957 {
2958 hda_nid_t srcs[5];
2959 int i, num;
2960
2961 pin = alc_go_down_to_selector(codec, pin);
2962 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2963 for (i = 0; i < num; i++) {
2964 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2965 if (nid == dac)
2966 return true;
2967 }
2968 return false;
2969 }
2970
2971 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2972 {
2973 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2974 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2975 return alc_auto_look_for_dac(codec, pin);
2976 return 0;
2977 }
2978
2979 /* return 0 if no possible DAC is found, 1 if one or more found */
2980 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2981 const hda_nid_t *pins, hda_nid_t *dacs)
2982 {
2983 int i;
2984
2985 if (num_outs && !dacs[0]) {
2986 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2987 if (!dacs[0])
2988 return 0;
2989 }
2990
2991 for (i = 1; i < num_outs; i++)
2992 dacs[i] = get_dac_if_single(codec, pins[i]);
2993 for (i = 1; i < num_outs; i++) {
2994 if (!dacs[i])
2995 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2996 }
2997 return 1;
2998 }
2999
3000 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3001 unsigned int location, int offset);
3002 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3003 hda_nid_t pin, hda_nid_t dac);
3004
3005 /* fill in the dac_nids table from the parsed pin configuration */
3006 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3007 {
3008 struct alc_spec *spec = codec->spec;
3009 struct auto_pin_cfg *cfg = &spec->autocfg;
3010 unsigned int location, defcfg;
3011 int num_pins;
3012 bool redone = false;
3013 int i;
3014
3015 again:
3016 /* set num_dacs once to full for alc_auto_look_for_dac() */
3017 spec->multiout.num_dacs = cfg->line_outs;
3018 spec->multiout.hp_out_nid[0] = 0;
3019 spec->multiout.extra_out_nid[0] = 0;
3020 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3021 spec->multiout.dac_nids = spec->private_dac_nids;
3022 spec->multi_ios = 0;
3023
3024 /* fill hard-wired DACs first */
3025 if (!redone) {
3026 for (i = 0; i < cfg->line_outs; i++)
3027 spec->private_dac_nids[i] =
3028 get_dac_if_single(codec, cfg->line_out_pins[i]);
3029 if (cfg->hp_outs)
3030 spec->multiout.hp_out_nid[0] =
3031 get_dac_if_single(codec, cfg->hp_pins[0]);
3032 if (cfg->speaker_outs)
3033 spec->multiout.extra_out_nid[0] =
3034 get_dac_if_single(codec, cfg->speaker_pins[0]);
3035 }
3036
3037 for (i = 0; i < cfg->line_outs; i++) {
3038 hda_nid_t pin = cfg->line_out_pins[i];
3039 if (spec->private_dac_nids[i])
3040 continue;
3041 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3042 if (!spec->private_dac_nids[i] && !redone) {
3043 /* if we can't find primary DACs, re-probe without
3044 * checking the hard-wired DACs
3045 */
3046 redone = true;
3047 goto again;
3048 }
3049 }
3050
3051 /* re-count num_dacs and squash invalid entries */
3052 spec->multiout.num_dacs = 0;
3053 for (i = 0; i < cfg->line_outs; i++) {
3054 if (spec->private_dac_nids[i])
3055 spec->multiout.num_dacs++;
3056 else {
3057 memmove(spec->private_dac_nids + i,
3058 spec->private_dac_nids + i + 1,
3059 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3060 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3061 }
3062 }
3063
3064 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3065 /* try to fill multi-io first */
3066 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3067 location = get_defcfg_location(defcfg);
3068
3069 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
3070 if (num_pins > 0) {
3071 spec->multi_ios = num_pins;
3072 spec->ext_channel_count = 2;
3073 spec->multiout.num_dacs = num_pins + 1;
3074 }
3075 }
3076
3077 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3078 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3079 spec->multiout.hp_out_nid);
3080 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3081 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3082 cfg->speaker_pins,
3083 spec->multiout.extra_out_nid);
3084 /* if no speaker volume is assigned, try again as the primary
3085 * output
3086 */
3087 if (!err && cfg->speaker_outs > 0 &&
3088 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3089 cfg->hp_outs = cfg->line_outs;
3090 memcpy(cfg->hp_pins, cfg->line_out_pins,
3091 sizeof(cfg->hp_pins));
3092 cfg->line_outs = cfg->speaker_outs;
3093 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3094 sizeof(cfg->speaker_pins));
3095 cfg->speaker_outs = 0;
3096 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3097 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3098 redone = false;
3099 goto again;
3100 }
3101 }
3102
3103 if (!spec->multi_ios &&
3104 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3105 cfg->hp_outs) {
3106 /* try multi-ios with HP + inputs */
3107 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3108 location = get_defcfg_location(defcfg);
3109
3110 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3111 if (num_pins > 0) {
3112 spec->multi_ios = num_pins;
3113 spec->ext_channel_count = 2;
3114 spec->multiout.num_dacs = num_pins + 1;
3115 }
3116 }
3117
3118 if (cfg->line_out_pins[0])
3119 spec->vmaster_nid =
3120 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3121 spec->multiout.dac_nids[0]);
3122 return 0;
3123 }
3124
3125 static inline unsigned int get_ctl_pos(unsigned int data)
3126 {
3127 hda_nid_t nid = get_amp_nid_(data);
3128 unsigned int dir = get_amp_direction_(data);
3129 return (nid << 1) | dir;
3130 }
3131
3132 #define is_ctl_used(bits, data) \
3133 test_bit(get_ctl_pos(data), bits)
3134 #define mark_ctl_usage(bits, data) \
3135 set_bit(get_ctl_pos(data), bits)
3136
3137 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3138 const char *pfx, int cidx,
3139 hda_nid_t nid, unsigned int chs)
3140 {
3141 struct alc_spec *spec = codec->spec;
3142 unsigned int val;
3143 if (!nid)
3144 return 0;
3145 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3146 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3147 return 0;
3148 mark_ctl_usage(spec->vol_ctls, val);
3149 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3150 val);
3151 }
3152
3153 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3154 const char *pfx, int cidx,
3155 hda_nid_t nid)
3156 {
3157 int chs = 1;
3158 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3159 chs = 3;
3160 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3161 }
3162
3163 /* create a mute-switch for the given mixer widget;
3164 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3165 */
3166 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3167 const char *pfx, int cidx,
3168 hda_nid_t nid, unsigned int chs)
3169 {
3170 struct alc_spec *spec = codec->spec;
3171 int wid_type;
3172 int type;
3173 unsigned long val;
3174 if (!nid)
3175 return 0;
3176 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3177 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3178 type = ALC_CTL_WIDGET_MUTE;
3179 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3180 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3181 type = ALC_CTL_WIDGET_MUTE;
3182 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3183 } else {
3184 type = ALC_CTL_BIND_MUTE;
3185 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3186 }
3187 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3188 return 0;
3189 mark_ctl_usage(spec->sw_ctls, val);
3190 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3191 }
3192
3193 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3194 int cidx, hda_nid_t nid)
3195 {
3196 int chs = 1;
3197 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3198 chs = 3;
3199 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3200 }
3201
3202 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3203 hda_nid_t pin, hda_nid_t dac)
3204 {
3205 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3206 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3207 return pin;
3208 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3209 return mix;
3210 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3211 return dac;
3212 return 0;
3213 }
3214
3215 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3216 hda_nid_t pin, hda_nid_t dac)
3217 {
3218 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3219 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3220 return dac;
3221 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3222 return mix;
3223 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3224 return pin;
3225 return 0;
3226 }
3227
3228 /* add playback controls from the parsed DAC table */
3229 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3230 const struct auto_pin_cfg *cfg)
3231 {
3232 struct alc_spec *spec = codec->spec;
3233 int i, err, noutputs;
3234
3235 noutputs = cfg->line_outs;
3236 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3237 noutputs += spec->multi_ios;
3238
3239 for (i = 0; i < noutputs; i++) {
3240 const char *name;
3241 int index;
3242 hda_nid_t dac, pin;
3243 hda_nid_t sw, vol;
3244
3245 dac = spec->multiout.dac_nids[i];
3246 if (!dac)
3247 continue;
3248 if (i >= cfg->line_outs)
3249 pin = spec->multi_io[i - 1].pin;
3250 else
3251 pin = cfg->line_out_pins[i];
3252
3253 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3254 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3255 name = alc_get_line_out_pfx(spec, i, true, &index);
3256 if (!name || !strcmp(name, "CLFE")) {
3257 /* Center/LFE */
3258 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3259 if (err < 0)
3260 return err;
3261 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3262 if (err < 0)
3263 return err;
3264 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3265 if (err < 0)
3266 return err;
3267 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3268 if (err < 0)
3269 return err;
3270 } else {
3271 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3272 if (err < 0)
3273 return err;
3274 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3275 if (err < 0)
3276 return err;
3277 }
3278 }
3279 return 0;
3280 }
3281
3282 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3283 hda_nid_t dac, const char *pfx,
3284 int cidx)
3285 {
3286 struct alc_spec *spec = codec->spec;
3287 hda_nid_t sw, vol;
3288 int err;
3289
3290 if (!dac) {
3291 unsigned int val;
3292 /* the corresponding DAC is already occupied */
3293 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3294 return 0; /* no way */
3295 /* create a switch only */
3296 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3297 if (is_ctl_used(spec->sw_ctls, val))
3298 return 0; /* already created */
3299 mark_ctl_usage(spec->sw_ctls, val);
3300 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3301 }
3302
3303 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3304 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3305 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3306 if (err < 0)
3307 return err;
3308 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3309 if (err < 0)
3310 return err;
3311 return 0;
3312 }
3313
3314 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3315 unsigned int nums,
3316 struct hda_ctl_ops *ops)
3317 {
3318 struct alc_spec *spec = codec->spec;
3319 struct hda_bind_ctls **ctlp, *ctl;
3320 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3321 ctlp = snd_array_new(&spec->bind_ctls);
3322 if (!ctlp)
3323 return NULL;
3324 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3325 *ctlp = ctl;
3326 if (ctl)
3327 ctl->ops = ops;
3328 return ctl;
3329 }
3330
3331 /* add playback controls for speaker and HP outputs */
3332 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3333 const hda_nid_t *pins,
3334 const hda_nid_t *dacs,
3335 const char *pfx)
3336 {
3337 struct alc_spec *spec = codec->spec;
3338 struct hda_bind_ctls *ctl;
3339 char name[32];
3340 int i, n, err;
3341
3342 if (!num_pins || !pins[0])
3343 return 0;
3344
3345 if (num_pins == 1) {
3346 hda_nid_t dac = *dacs;
3347 if (!dac)
3348 dac = spec->multiout.dac_nids[0];
3349 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3350 }
3351
3352 if (dacs[num_pins - 1]) {
3353 /* OK, we have a multi-output system with individual volumes */
3354 for (i = 0; i < num_pins; i++) {
3355 if (num_pins >= 3) {
3356 snprintf(name, sizeof(name), "%s %s",
3357 pfx, channel_name[i]);
3358 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3359 name, 0);
3360 } else {
3361 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3362 pfx, i);
3363 }
3364 if (err < 0)
3365 return err;
3366 }
3367 return 0;
3368 }
3369
3370 /* Let's create a bind-controls */
3371 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3372 if (!ctl)
3373 return -ENOMEM;
3374 n = 0;
3375 for (i = 0; i < num_pins; i++) {
3376 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3377 ctl->values[n++] =
3378 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3379 }
3380 if (n) {
3381 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3382 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3383 if (err < 0)
3384 return err;
3385 }
3386
3387 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3388 if (!ctl)
3389 return -ENOMEM;
3390 n = 0;
3391 for (i = 0; i < num_pins; i++) {
3392 hda_nid_t vol;
3393 if (!pins[i] || !dacs[i])
3394 continue;
3395 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3396 if (vol)
3397 ctl->values[n++] =
3398 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3399 }
3400 if (n) {
3401 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3402 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3403 if (err < 0)
3404 return err;
3405 }
3406 return 0;
3407 }
3408
3409 static int alc_auto_create_hp_out(struct hda_codec *codec)
3410 {
3411 struct alc_spec *spec = codec->spec;
3412 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3413 spec->autocfg.hp_pins,
3414 spec->multiout.hp_out_nid,
3415 "Headphone");
3416 }
3417
3418 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3419 {
3420 struct alc_spec *spec = codec->spec;
3421 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3422 spec->autocfg.speaker_pins,
3423 spec->multiout.extra_out_nid,
3424 "Speaker");
3425 }
3426
3427 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3428 hda_nid_t pin, int pin_type,
3429 hda_nid_t dac)
3430 {
3431 int i, num;
3432 hda_nid_t nid, mix = 0;
3433 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3434
3435 alc_set_pin_output(codec, pin, pin_type);
3436 nid = alc_go_down_to_selector(codec, pin);
3437 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3438 for (i = 0; i < num; i++) {
3439 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3440 continue;
3441 mix = srcs[i];
3442 break;
3443 }
3444 if (!mix)
3445 return;
3446
3447 /* need the manual connection? */
3448 if (num > 1)
3449 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3450 /* unmute mixer widget inputs */
3451 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3452 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3453 AMP_IN_UNMUTE(0));
3454 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3455 AMP_IN_UNMUTE(1));
3456 }
3457 /* initialize volume */
3458 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3459 if (nid)
3460 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3461 AMP_OUT_ZERO);
3462
3463 /* unmute DAC if it's not assigned to a mixer */
3464 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3465 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3466 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3467 AMP_OUT_ZERO);
3468 }
3469
3470 static void alc_auto_init_multi_out(struct hda_codec *codec)
3471 {
3472 struct alc_spec *spec = codec->spec;
3473 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3474 int i;
3475
3476 for (i = 0; i <= HDA_SIDE; i++) {
3477 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3478 if (nid)
3479 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3480 spec->multiout.dac_nids[i]);
3481 }
3482 }
3483
3484 static void alc_auto_init_extra_out(struct hda_codec *codec)
3485 {
3486 struct alc_spec *spec = codec->spec;
3487 int i;
3488 hda_nid_t pin, dac;
3489
3490 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3491 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3492 break;
3493 pin = spec->autocfg.hp_pins[i];
3494 if (!pin)
3495 break;
3496 dac = spec->multiout.hp_out_nid[i];
3497 if (!dac) {
3498 if (i > 0 && spec->multiout.hp_out_nid[0])
3499 dac = spec->multiout.hp_out_nid[0];
3500 else
3501 dac = spec->multiout.dac_nids[0];
3502 }
3503 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3504 }
3505 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3506 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3507 break;
3508 pin = spec->autocfg.speaker_pins[i];
3509 if (!pin)
3510 break;
3511 dac = spec->multiout.extra_out_nid[i];
3512 if (!dac) {
3513 if (i > 0 && spec->multiout.extra_out_nid[0])
3514 dac = spec->multiout.extra_out_nid[0];
3515 else
3516 dac = spec->multiout.dac_nids[0];
3517 }
3518 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3519 }
3520 }
3521
3522 /*
3523 * multi-io helper
3524 */
3525 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3526 unsigned int location,
3527 int offset)
3528 {
3529 struct alc_spec *spec = codec->spec;
3530 struct auto_pin_cfg *cfg = &spec->autocfg;
3531 hda_nid_t prime_dac = spec->private_dac_nids[0];
3532 int type, i, dacs, num_pins = 0;
3533
3534 dacs = spec->multiout.num_dacs;
3535 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3536 for (i = 0; i < cfg->num_inputs; i++) {
3537 hda_nid_t nid = cfg->inputs[i].pin;
3538 hda_nid_t dac = 0;
3539 unsigned int defcfg, caps;
3540 if (cfg->inputs[i].type != type)
3541 continue;
3542 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3543 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3544 continue;
3545 if (location && get_defcfg_location(defcfg) != location)
3546 continue;
3547 caps = snd_hda_query_pin_caps(codec, nid);
3548 if (!(caps & AC_PINCAP_OUT))
3549 continue;
3550 if (offset && offset + num_pins < dacs) {
3551 dac = spec->private_dac_nids[offset + num_pins];
3552 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3553 dac = 0;
3554 }
3555 if (!dac)
3556 dac = alc_auto_look_for_dac(codec, nid);
3557 if (!dac)
3558 continue;
3559 spec->multi_io[num_pins].pin = nid;
3560 spec->multi_io[num_pins].dac = dac;
3561 num_pins++;
3562 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3563 }
3564 }
3565 spec->multiout.num_dacs = dacs;
3566 if (num_pins < 2) {
3567 /* clear up again */
3568 memset(spec->private_dac_nids + dacs, 0,
3569 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
3570 spec->private_dac_nids[0] = prime_dac;
3571 return 0;
3572 }
3573 return num_pins;
3574 }
3575
3576 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3577 struct snd_ctl_elem_info *uinfo)
3578 {
3579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3580 struct alc_spec *spec = codec->spec;
3581
3582 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3583 uinfo->count = 1;
3584 uinfo->value.enumerated.items = spec->multi_ios + 1;
3585 if (uinfo->value.enumerated.item > spec->multi_ios)
3586 uinfo->value.enumerated.item = spec->multi_ios;
3587 sprintf(uinfo->value.enumerated.name, "%dch",
3588 (uinfo->value.enumerated.item + 1) * 2);
3589 return 0;
3590 }
3591
3592 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3593 struct snd_ctl_elem_value *ucontrol)
3594 {
3595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3596 struct alc_spec *spec = codec->spec;
3597 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3598 return 0;
3599 }
3600
3601 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3602 {
3603 struct alc_spec *spec = codec->spec;
3604 hda_nid_t nid = spec->multi_io[idx].pin;
3605
3606 if (!spec->multi_io[idx].ctl_in)
3607 spec->multi_io[idx].ctl_in =
3608 snd_hda_codec_read(codec, nid, 0,
3609 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3610 if (output) {
3611 snd_hda_codec_update_cache(codec, nid, 0,
3612 AC_VERB_SET_PIN_WIDGET_CONTROL,
3613 PIN_OUT);
3614 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3615 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3616 HDA_AMP_MUTE, 0);
3617 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3618 } else {
3619 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3620 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3621 HDA_AMP_MUTE, HDA_AMP_MUTE);
3622 snd_hda_codec_update_cache(codec, nid, 0,
3623 AC_VERB_SET_PIN_WIDGET_CONTROL,
3624 spec->multi_io[idx].ctl_in);
3625 }
3626 return 0;
3627 }
3628
3629 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3630 struct snd_ctl_elem_value *ucontrol)
3631 {
3632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3633 struct alc_spec *spec = codec->spec;
3634 int i, ch;
3635
3636 ch = ucontrol->value.enumerated.item[0];
3637 if (ch < 0 || ch > spec->multi_ios)
3638 return -EINVAL;
3639 if (ch == (spec->ext_channel_count - 1) / 2)
3640 return 0;
3641 spec->ext_channel_count = (ch + 1) * 2;
3642 for (i = 0; i < spec->multi_ios; i++)
3643 alc_set_multi_io(codec, i, i < ch);
3644 spec->multiout.max_channels = spec->ext_channel_count;
3645 if (spec->need_dac_fix && !spec->const_channel_count)
3646 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3647 return 1;
3648 }
3649
3650 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3652 .name = "Channel Mode",
3653 .info = alc_auto_ch_mode_info,
3654 .get = alc_auto_ch_mode_get,
3655 .put = alc_auto_ch_mode_put,
3656 };
3657
3658 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3659 {
3660 struct alc_spec *spec = codec->spec;
3661
3662 if (spec->multi_ios > 0) {
3663 struct snd_kcontrol_new *knew;
3664
3665 knew = alc_kcontrol_new(spec);
3666 if (!knew)
3667 return -ENOMEM;
3668 *knew = alc_auto_channel_mode_enum;
3669 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3670 if (!knew->name)
3671 return -ENOMEM;
3672 }
3673 return 0;
3674 }
3675
3676 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3677 * active input pins
3678 */
3679 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3680 {
3681 struct alc_spec *spec = codec->spec;
3682 const struct hda_input_mux *imux;
3683 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3684 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3685 int i, n, nums;
3686
3687 imux = spec->input_mux;
3688 if (!imux)
3689 return;
3690 if (spec->dyn_adc_switch)
3691 return;
3692
3693 nums = 0;
3694 for (n = 0; n < spec->num_adc_nids; n++) {
3695 hda_nid_t cap = spec->private_capsrc_nids[n];
3696 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3697 for (i = 0; i < imux->num_items; i++) {
3698 hda_nid_t pin = spec->imux_pins[i];
3699 if (pin) {
3700 if (get_connection_index(codec, cap, pin) < 0)
3701 break;
3702 } else if (num_conns <= imux->items[i].index)
3703 break;
3704 }
3705 if (i >= imux->num_items) {
3706 adc_nids[nums] = spec->private_adc_nids[n];
3707 capsrc_nids[nums++] = cap;
3708 }
3709 }
3710 if (!nums) {
3711 /* check whether ADC-switch is possible */
3712 if (!alc_check_dyn_adc_switch(codec)) {
3713 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3714 " using fallback 0x%x\n",
3715 codec->chip_name, spec->private_adc_nids[0]);
3716 spec->num_adc_nids = 1;
3717 spec->auto_mic = 0;
3718 return;
3719 }
3720 } else if (nums != spec->num_adc_nids) {
3721 memcpy(spec->private_adc_nids, adc_nids,
3722 nums * sizeof(hda_nid_t));
3723 memcpy(spec->private_capsrc_nids, capsrc_nids,
3724 nums * sizeof(hda_nid_t));
3725 spec->num_adc_nids = nums;
3726 }
3727
3728 if (spec->auto_mic)
3729 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3730 else if (spec->input_mux->num_items == 1)
3731 spec->num_adc_nids = 1; /* reduce to a single ADC */
3732 }
3733
3734 /*
3735 * initialize ADC paths
3736 */
3737 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3738 {
3739 struct alc_spec *spec = codec->spec;
3740 hda_nid_t nid;
3741
3742 nid = spec->adc_nids[adc_idx];
3743 /* mute ADC */
3744 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3745 snd_hda_codec_write(codec, nid, 0,
3746 AC_VERB_SET_AMP_GAIN_MUTE,
3747 AMP_IN_MUTE(0));
3748 return;
3749 }
3750 if (!spec->capsrc_nids)
3751 return;
3752 nid = spec->capsrc_nids[adc_idx];
3753 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3754 snd_hda_codec_write(codec, nid, 0,
3755 AC_VERB_SET_AMP_GAIN_MUTE,
3756 AMP_OUT_MUTE);
3757 }
3758
3759 static void alc_auto_init_input_src(struct hda_codec *codec)
3760 {
3761 struct alc_spec *spec = codec->spec;
3762 int c, nums;
3763
3764 for (c = 0; c < spec->num_adc_nids; c++)
3765 alc_auto_init_adc(codec, c);
3766 if (spec->dyn_adc_switch)
3767 nums = 1;
3768 else
3769 nums = spec->num_adc_nids;
3770 for (c = 0; c < nums; c++)
3771 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3772 }
3773
3774 /* add mic boosts if needed */
3775 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3776 {
3777 struct alc_spec *spec = codec->spec;
3778 struct auto_pin_cfg *cfg = &spec->autocfg;
3779 int i, err;
3780 int type_idx = 0;
3781 hda_nid_t nid;
3782 const char *prev_label = NULL;
3783
3784 for (i = 0; i < cfg->num_inputs; i++) {
3785 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3786 break;
3787 nid = cfg->inputs[i].pin;
3788 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3789 const char *label;
3790 char boost_label[32];
3791
3792 label = hda_get_autocfg_input_label(codec, cfg, i);
3793 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3794 label = "Headphone Mic";
3795 if (prev_label && !strcmp(label, prev_label))
3796 type_idx++;
3797 else
3798 type_idx = 0;
3799 prev_label = label;
3800
3801 snprintf(boost_label, sizeof(boost_label),
3802 "%s Boost Volume", label);
3803 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3804 boost_label, type_idx,
3805 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3806 if (err < 0)
3807 return err;
3808 }
3809 }
3810 return 0;
3811 }
3812
3813 /* select or unmute the given capsrc route */
3814 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3815 int idx)
3816 {
3817 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3818 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3819 HDA_AMP_MUTE, 0);
3820 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3821 snd_hda_codec_write_cache(codec, cap, 0,
3822 AC_VERB_SET_CONNECT_SEL, idx);
3823 }
3824 }
3825
3826 /* set the default connection to that pin */
3827 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3828 {
3829 struct alc_spec *spec = codec->spec;
3830 int i;
3831
3832 if (!pin)
3833 return 0;
3834 for (i = 0; i < spec->num_adc_nids; i++) {
3835 hda_nid_t cap = get_capsrc(spec, i);
3836 int idx;
3837
3838 idx = get_connection_index(codec, cap, pin);
3839 if (idx < 0)
3840 continue;
3841 select_or_unmute_capsrc(codec, cap, idx);
3842 return i; /* return the found index */
3843 }
3844 return -1; /* not found */
3845 }
3846
3847 /* initialize some special cases for input sources */
3848 static void alc_init_special_input_src(struct hda_codec *codec)
3849 {
3850 struct alc_spec *spec = codec->spec;
3851 int i;
3852
3853 for (i = 0; i < spec->autocfg.num_inputs; i++)
3854 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3855 }
3856
3857 /* assign appropriate capture mixers */
3858 static void set_capture_mixer(struct hda_codec *codec)
3859 {
3860 struct alc_spec *spec = codec->spec;
3861 static const struct snd_kcontrol_new *caps[2][3] = {
3862 { alc_capture_mixer_nosrc1,
3863 alc_capture_mixer_nosrc2,
3864 alc_capture_mixer_nosrc3 },
3865 { alc_capture_mixer1,
3866 alc_capture_mixer2,
3867 alc_capture_mixer3 },
3868 };
3869
3870 /* check whether either of ADC or MUX has a volume control */
3871 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3872 if (!spec->capsrc_nids)
3873 return; /* no volume */
3874 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3875 return; /* no volume in capsrc, too */
3876 spec->vol_in_capsrc = 1;
3877 }
3878
3879 if (spec->num_adc_nids > 0) {
3880 int mux = 0;
3881 int num_adcs = 0;
3882
3883 if (spec->input_mux && spec->input_mux->num_items > 1)
3884 mux = 1;
3885 if (spec->auto_mic) {
3886 num_adcs = 1;
3887 mux = 0;
3888 } else if (spec->dyn_adc_switch)
3889 num_adcs = 1;
3890 if (!num_adcs) {
3891 if (spec->num_adc_nids > 3)
3892 spec->num_adc_nids = 3;
3893 else if (!spec->num_adc_nids)
3894 return;
3895 num_adcs = spec->num_adc_nids;
3896 }
3897 spec->cap_mixer = caps[mux][num_adcs - 1];
3898 }
3899 }
3900
3901 /*
3902 * standard auto-parser initializations
3903 */
3904 static void alc_auto_init_std(struct hda_codec *codec)
3905 {
3906 struct alc_spec *spec = codec->spec;
3907 alc_auto_init_multi_out(codec);
3908 alc_auto_init_extra_out(codec);
3909 alc_auto_init_analog_input(codec);
3910 alc_auto_init_input_src(codec);
3911 alc_auto_init_digital(codec);
3912 if (spec->unsol_event)
3913 alc_inithook(codec);
3914 }
3915
3916 /*
3917 * Digital-beep handlers
3918 */
3919 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3920 #define set_beep_amp(spec, nid, idx, dir) \
3921 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3922
3923 static const struct snd_pci_quirk beep_white_list[] = {
3924 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3925 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3926 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3927 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3928 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3929 {}
3930 };
3931
3932 static inline int has_cdefine_beep(struct hda_codec *codec)
3933 {
3934 struct alc_spec *spec = codec->spec;
3935 const struct snd_pci_quirk *q;
3936 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3937 if (q)
3938 return q->value;
3939 return spec->cdefine.enable_pcbeep;
3940 }
3941 #else
3942 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3943 #define has_cdefine_beep(codec) 0
3944 #endif
3945
3946 /* parse the BIOS configuration and set up the alc_spec */
3947 /* return 1 if successful, 0 if the proper config is not found,
3948 * or a negative error code
3949 */
3950 static int alc_parse_auto_config(struct hda_codec *codec,
3951 const hda_nid_t *ignore_nids,
3952 const hda_nid_t *ssid_nids)
3953 {
3954 struct alc_spec *spec = codec->spec;
3955 struct auto_pin_cfg *cfg = &spec->autocfg;
3956 int err;
3957
3958 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3959 spec->parse_flags);
3960 if (err < 0)
3961 return err;
3962 if (!cfg->line_outs) {
3963 if (cfg->dig_outs || cfg->dig_in_pin) {
3964 spec->multiout.max_channels = 2;
3965 spec->no_analog = 1;
3966 goto dig_only;
3967 }
3968 return 0; /* can't find valid BIOS pin config */
3969 }
3970
3971 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3972 cfg->line_outs <= cfg->hp_outs) {
3973 /* use HP as primary out */
3974 cfg->speaker_outs = cfg->line_outs;
3975 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3976 sizeof(cfg->speaker_pins));
3977 cfg->line_outs = cfg->hp_outs;
3978 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3979 cfg->hp_outs = 0;
3980 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3981 cfg->line_out_type = AUTO_PIN_HP_OUT;
3982 }
3983
3984 err = alc_auto_fill_dac_nids(codec);
3985 if (err < 0)
3986 return err;
3987 err = alc_auto_add_multi_channel_mode(codec);
3988 if (err < 0)
3989 return err;
3990 err = alc_auto_create_multi_out_ctls(codec, cfg);
3991 if (err < 0)
3992 return err;
3993 err = alc_auto_create_hp_out(codec);
3994 if (err < 0)
3995 return err;
3996 err = alc_auto_create_speaker_out(codec);
3997 if (err < 0)
3998 return err;
3999 err = alc_auto_create_shared_input(codec);
4000 if (err < 0)
4001 return err;
4002 err = alc_auto_create_input_ctls(codec);
4003 if (err < 0)
4004 return err;
4005
4006 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4007
4008 dig_only:
4009 alc_auto_parse_digital(codec);
4010
4011 if (!spec->no_analog)
4012 alc_remove_invalid_adc_nids(codec);
4013
4014 if (ssid_nids)
4015 alc_ssid_check(codec, ssid_nids);
4016
4017 if (!spec->no_analog) {
4018 alc_auto_check_switches(codec);
4019 err = alc_auto_add_mic_boost(codec);
4020 if (err < 0)
4021 return err;
4022 }
4023
4024 if (spec->kctls.list)
4025 add_mixer(spec, spec->kctls.list);
4026
4027 return 1;
4028 }
4029
4030 static int alc880_parse_auto_config(struct hda_codec *codec)
4031 {
4032 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4033 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4034 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4035 }
4036
4037 #ifdef CONFIG_SND_HDA_POWER_SAVE
4038 static const struct hda_amp_list alc880_loopbacks[] = {
4039 { 0x0b, HDA_INPUT, 0 },
4040 { 0x0b, HDA_INPUT, 1 },
4041 { 0x0b, HDA_INPUT, 2 },
4042 { 0x0b, HDA_INPUT, 3 },
4043 { 0x0b, HDA_INPUT, 4 },
4044 { } /* end */
4045 };
4046 #endif
4047
4048 /*
4049 * ALC880 fix-ups
4050 */
4051 enum {
4052 ALC880_FIXUP_GPIO2,
4053 ALC880_FIXUP_MEDION_RIM,
4054 };
4055
4056 static const struct alc_fixup alc880_fixups[] = {
4057 [ALC880_FIXUP_GPIO2] = {
4058 .type = ALC_FIXUP_VERBS,
4059 .v.verbs = alc_gpio2_init_verbs,
4060 },
4061 [ALC880_FIXUP_MEDION_RIM] = {
4062 .type = ALC_FIXUP_VERBS,
4063 .v.verbs = (const struct hda_verb[]) {
4064 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4065 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4066 { }
4067 },
4068 .chained = true,
4069 .chain_id = ALC880_FIXUP_GPIO2,
4070 },
4071 };
4072
4073 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4074 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4075 {}
4076 };
4077
4078
4079 /*
4080 * board setups
4081 */
4082 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4083 #define alc_board_config \
4084 snd_hda_check_board_config
4085 #define alc_board_codec_sid_config \
4086 snd_hda_check_board_codec_sid_config
4087 #include "alc_quirks.c"
4088 #else
4089 #define alc_board_config(codec, nums, models, tbl) -1
4090 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4091 #define setup_preset(codec, x) /* NOP */
4092 #endif
4093
4094 /*
4095 * OK, here we have finally the patch for ALC880
4096 */
4097 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4098 #include "alc880_quirks.c"
4099 #endif
4100
4101 static int patch_alc880(struct hda_codec *codec)
4102 {
4103 struct alc_spec *spec;
4104 int board_config;
4105 int err;
4106
4107 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4108 if (spec == NULL)
4109 return -ENOMEM;
4110
4111 codec->spec = spec;
4112
4113 spec->mixer_nid = 0x0b;
4114 spec->need_dac_fix = 1;
4115
4116 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4117 alc880_models, alc880_cfg_tbl);
4118 if (board_config < 0) {
4119 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4120 codec->chip_name);
4121 board_config = ALC_MODEL_AUTO;
4122 }
4123
4124 if (board_config == ALC_MODEL_AUTO) {
4125 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4126 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4127 }
4128
4129 if (board_config == ALC_MODEL_AUTO) {
4130 /* automatic parse from the BIOS config */
4131 err = alc880_parse_auto_config(codec);
4132 if (err < 0)
4133 goto error;
4134 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4135 else if (!err) {
4136 printk(KERN_INFO
4137 "hda_codec: Cannot set up configuration "
4138 "from BIOS. Using 3-stack mode...\n");
4139 board_config = ALC880_3ST;
4140 }
4141 #endif
4142 }
4143
4144 if (board_config != ALC_MODEL_AUTO) {
4145 spec->vmaster_nid = 0x0c;
4146 setup_preset(codec, &alc880_presets[board_config]);
4147 }
4148
4149 if (!spec->no_analog && !spec->adc_nids) {
4150 alc_auto_fill_adc_caps(codec);
4151 alc_rebuild_imux_for_auto_mic(codec);
4152 alc_remove_invalid_adc_nids(codec);
4153 }
4154
4155 if (!spec->no_analog && !spec->cap_mixer)
4156 set_capture_mixer(codec);
4157
4158 if (!spec->no_analog) {
4159 err = snd_hda_attach_beep_device(codec, 0x1);
4160 if (err < 0)
4161 goto error;
4162 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4163 }
4164
4165 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4166
4167 codec->patch_ops = alc_patch_ops;
4168 if (board_config == ALC_MODEL_AUTO)
4169 spec->init_hook = alc_auto_init_std;
4170 else
4171 codec->patch_ops.build_controls = __alc_build_controls;
4172 #ifdef CONFIG_SND_HDA_POWER_SAVE
4173 if (!spec->loopback.amplist)
4174 spec->loopback.amplist = alc880_loopbacks;
4175 #endif
4176
4177 return 0;
4178
4179 error:
4180 alc_free(codec);
4181 return err;
4182 }
4183
4184
4185 /*
4186 * ALC260 support
4187 */
4188 static int alc260_parse_auto_config(struct hda_codec *codec)
4189 {
4190 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4191 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4192 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4193 }
4194
4195 #ifdef CONFIG_SND_HDA_POWER_SAVE
4196 static const struct hda_amp_list alc260_loopbacks[] = {
4197 { 0x07, HDA_INPUT, 0 },
4198 { 0x07, HDA_INPUT, 1 },
4199 { 0x07, HDA_INPUT, 2 },
4200 { 0x07, HDA_INPUT, 3 },
4201 { 0x07, HDA_INPUT, 4 },
4202 { } /* end */
4203 };
4204 #endif
4205
4206 /*
4207 * Pin config fixes
4208 */
4209 enum {
4210 ALC260_FIXUP_HP_DC5750,
4211 ALC260_FIXUP_HP_PIN_0F,
4212 ALC260_FIXUP_COEF,
4213 ALC260_FIXUP_GPIO1,
4214 };
4215
4216 static const struct alc_fixup alc260_fixups[] = {
4217 [ALC260_FIXUP_HP_DC5750] = {
4218 .type = ALC_FIXUP_PINS,
4219 .v.pins = (const struct alc_pincfg[]) {
4220 { 0x11, 0x90130110 }, /* speaker */
4221 { }
4222 }
4223 },
4224 [ALC260_FIXUP_HP_PIN_0F] = {
4225 .type = ALC_FIXUP_PINS,
4226 .v.pins = (const struct alc_pincfg[]) {
4227 { 0x0f, 0x01214000 }, /* HP */
4228 { }
4229 }
4230 },
4231 [ALC260_FIXUP_COEF] = {
4232 .type = ALC_FIXUP_VERBS,
4233 .v.verbs = (const struct hda_verb[]) {
4234 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4235 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4236 { }
4237 },
4238 .chained = true,
4239 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4240 },
4241 [ALC260_FIXUP_GPIO1] = {
4242 .type = ALC_FIXUP_VERBS,
4243 .v.verbs = alc_gpio1_init_verbs,
4244 },
4245 };
4246
4247 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4248 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
4249 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
4250 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4251 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4252 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
4253 {}
4254 };
4255
4256 /*
4257 */
4258 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4259 #include "alc260_quirks.c"
4260 #endif
4261
4262 static int patch_alc260(struct hda_codec *codec)
4263 {
4264 struct alc_spec *spec;
4265 int err, board_config;
4266
4267 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4268 if (spec == NULL)
4269 return -ENOMEM;
4270
4271 codec->spec = spec;
4272
4273 spec->mixer_nid = 0x07;
4274
4275 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4276 alc260_models, alc260_cfg_tbl);
4277 if (board_config < 0) {
4278 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4279 codec->chip_name);
4280 board_config = ALC_MODEL_AUTO;
4281 }
4282
4283 if (board_config == ALC_MODEL_AUTO) {
4284 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4285 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4286 }
4287
4288 if (board_config == ALC_MODEL_AUTO) {
4289 /* automatic parse from the BIOS config */
4290 err = alc260_parse_auto_config(codec);
4291 if (err < 0)
4292 goto error;
4293 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4294 else if (!err) {
4295 printk(KERN_INFO
4296 "hda_codec: Cannot set up configuration "
4297 "from BIOS. Using base mode...\n");
4298 board_config = ALC260_BASIC;
4299 }
4300 #endif
4301 }
4302
4303 if (board_config != ALC_MODEL_AUTO) {
4304 setup_preset(codec, &alc260_presets[board_config]);
4305 spec->vmaster_nid = 0x08;
4306 }
4307
4308 if (!spec->no_analog && !spec->adc_nids) {
4309 alc_auto_fill_adc_caps(codec);
4310 alc_rebuild_imux_for_auto_mic(codec);
4311 alc_remove_invalid_adc_nids(codec);
4312 }
4313
4314 if (!spec->no_analog && !spec->cap_mixer)
4315 set_capture_mixer(codec);
4316
4317 if (!spec->no_analog) {
4318 err = snd_hda_attach_beep_device(codec, 0x1);
4319 if (err < 0)
4320 goto error;
4321 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4322 }
4323
4324 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4325
4326 codec->patch_ops = alc_patch_ops;
4327 if (board_config == ALC_MODEL_AUTO)
4328 spec->init_hook = alc_auto_init_std;
4329 else
4330 codec->patch_ops.build_controls = __alc_build_controls;
4331 spec->shutup = alc_eapd_shutup;
4332 #ifdef CONFIG_SND_HDA_POWER_SAVE
4333 if (!spec->loopback.amplist)
4334 spec->loopback.amplist = alc260_loopbacks;
4335 #endif
4336
4337 return 0;
4338
4339 error:
4340 alc_free(codec);
4341 return err;
4342 }
4343
4344
4345 /*
4346 * ALC882/883/885/888/889 support
4347 *
4348 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4349 * configuration. Each pin widget can choose any input DACs and a mixer.
4350 * Each ADC is connected from a mixer of all inputs. This makes possible
4351 * 6-channel independent captures.
4352 *
4353 * In addition, an independent DAC for the multi-playback (not used in this
4354 * driver yet).
4355 */
4356 #ifdef CONFIG_SND_HDA_POWER_SAVE
4357 #define alc882_loopbacks alc880_loopbacks
4358 #endif
4359
4360 /*
4361 * Pin config fixes
4362 */
4363 enum {
4364 ALC882_FIXUP_ABIT_AW9D_MAX,
4365 ALC882_FIXUP_LENOVO_Y530,
4366 ALC882_FIXUP_PB_M5210,
4367 ALC882_FIXUP_ACER_ASPIRE_7736,
4368 ALC882_FIXUP_ASUS_W90V,
4369 ALC889_FIXUP_VAIO_TT,
4370 ALC888_FIXUP_EEE1601,
4371 ALC882_FIXUP_EAPD,
4372 ALC883_FIXUP_EAPD,
4373 ALC883_FIXUP_ACER_EAPD,
4374 ALC882_FIXUP_GPIO3,
4375 ALC889_FIXUP_COEF,
4376 ALC882_FIXUP_ASUS_W2JC,
4377 ALC882_FIXUP_ACER_ASPIRE_4930G,
4378 ALC882_FIXUP_ACER_ASPIRE_8930G,
4379 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4380 ALC885_FIXUP_MACPRO_GPIO,
4381 };
4382
4383 static void alc889_fixup_coef(struct hda_codec *codec,
4384 const struct alc_fixup *fix, int action)
4385 {
4386 if (action != ALC_FIXUP_ACT_INIT)
4387 return;
4388 alc889_coef_init(codec);
4389 }
4390
4391 /* toggle speaker-output according to the hp-jack state */
4392 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4393 {
4394 unsigned int gpiostate, gpiomask, gpiodir;
4395
4396 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4397 AC_VERB_GET_GPIO_DATA, 0);
4398
4399 if (!muted)
4400 gpiostate |= (1 << pin);
4401 else
4402 gpiostate &= ~(1 << pin);
4403
4404 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4405 AC_VERB_GET_GPIO_MASK, 0);
4406 gpiomask |= (1 << pin);
4407
4408 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4409 AC_VERB_GET_GPIO_DIRECTION, 0);
4410 gpiodir |= (1 << pin);
4411
4412
4413 snd_hda_codec_write(codec, codec->afg, 0,
4414 AC_VERB_SET_GPIO_MASK, gpiomask);
4415 snd_hda_codec_write(codec, codec->afg, 0,
4416 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4417
4418 msleep(1);
4419
4420 snd_hda_codec_write(codec, codec->afg, 0,
4421 AC_VERB_SET_GPIO_DATA, gpiostate);
4422 }
4423
4424 /* set up GPIO at initialization */
4425 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4426 const struct alc_fixup *fix, int action)
4427 {
4428 if (action != ALC_FIXUP_ACT_INIT)
4429 return;
4430 alc882_gpio_mute(codec, 0, 0);
4431 alc882_gpio_mute(codec, 1, 0);
4432 }
4433
4434 static const struct alc_fixup alc882_fixups[] = {
4435 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4436 .type = ALC_FIXUP_PINS,
4437 .v.pins = (const struct alc_pincfg[]) {
4438 { 0x15, 0x01080104 }, /* side */
4439 { 0x16, 0x01011012 }, /* rear */
4440 { 0x17, 0x01016011 }, /* clfe */
4441 { }
4442 }
4443 },
4444 [ALC882_FIXUP_LENOVO_Y530] = {
4445 .type = ALC_FIXUP_PINS,
4446 .v.pins = (const struct alc_pincfg[]) {
4447 { 0x15, 0x99130112 }, /* rear int speakers */
4448 { 0x16, 0x99130111 }, /* subwoofer */
4449 { }
4450 }
4451 },
4452 [ALC882_FIXUP_PB_M5210] = {
4453 .type = ALC_FIXUP_VERBS,
4454 .v.verbs = (const struct hda_verb[]) {
4455 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4456 {}
4457 }
4458 },
4459 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4460 .type = ALC_FIXUP_SKU,
4461 .v.sku = ALC_FIXUP_SKU_IGNORE,
4462 },
4463 [ALC882_FIXUP_ASUS_W90V] = {
4464 .type = ALC_FIXUP_PINS,
4465 .v.pins = (const struct alc_pincfg[]) {
4466 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4467 { }
4468 }
4469 },
4470 [ALC889_FIXUP_VAIO_TT] = {
4471 .type = ALC_FIXUP_PINS,
4472 .v.pins = (const struct alc_pincfg[]) {
4473 { 0x17, 0x90170111 }, /* hidden surround speaker */
4474 { }
4475 }
4476 },
4477 [ALC888_FIXUP_EEE1601] = {
4478 .type = ALC_FIXUP_VERBS,
4479 .v.verbs = (const struct hda_verb[]) {
4480 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4481 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4482 { }
4483 }
4484 },
4485 [ALC882_FIXUP_EAPD] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = (const struct hda_verb[]) {
4488 /* change to EAPD mode */
4489 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4490 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4491 { }
4492 }
4493 },
4494 [ALC883_FIXUP_EAPD] = {
4495 .type = ALC_FIXUP_VERBS,
4496 .v.verbs = (const struct hda_verb[]) {
4497 /* change to EAPD mode */
4498 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4499 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4500 { }
4501 }
4502 },
4503 [ALC883_FIXUP_ACER_EAPD] = {
4504 .type = ALC_FIXUP_VERBS,
4505 .v.verbs = (const struct hda_verb[]) {
4506 /* eanable EAPD on Acer laptops */
4507 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4508 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4509 { }
4510 }
4511 },
4512 [ALC882_FIXUP_GPIO3] = {
4513 .type = ALC_FIXUP_VERBS,
4514 .v.verbs = alc_gpio3_init_verbs,
4515 },
4516 [ALC882_FIXUP_ASUS_W2JC] = {
4517 .type = ALC_FIXUP_VERBS,
4518 .v.verbs = alc_gpio1_init_verbs,
4519 .chained = true,
4520 .chain_id = ALC882_FIXUP_EAPD,
4521 },
4522 [ALC889_FIXUP_COEF] = {
4523 .type = ALC_FIXUP_FUNC,
4524 .v.func = alc889_fixup_coef,
4525 },
4526 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4527 .type = ALC_FIXUP_PINS,
4528 .v.pins = (const struct alc_pincfg[]) {
4529 { 0x16, 0x99130111 }, /* CLFE speaker */
4530 { 0x17, 0x99130112 }, /* surround speaker */
4531 { }
4532 }
4533 },
4534 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4535 .type = ALC_FIXUP_PINS,
4536 .v.pins = (const struct alc_pincfg[]) {
4537 { 0x16, 0x99130111 }, /* CLFE speaker */
4538 { 0x1b, 0x99130112 }, /* surround speaker */
4539 { }
4540 },
4541 .chained = true,
4542 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4543 },
4544 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4545 /* additional init verbs for Acer Aspire 8930G */
4546 .type = ALC_FIXUP_VERBS,
4547 .v.verbs = (const struct hda_verb[]) {
4548 /* Enable all DACs */
4549 /* DAC DISABLE/MUTE 1? */
4550 /* setting bits 1-5 disables DAC nids 0x02-0x06
4551 * apparently. Init=0x38 */
4552 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4553 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4554 /* DAC DISABLE/MUTE 2? */
4555 /* some bit here disables the other DACs.
4556 * Init=0x4900 */
4557 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4558 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4559 /* DMIC fix
4560 * This laptop has a stereo digital microphone.
4561 * The mics are only 1cm apart which makes the stereo
4562 * useless. However, either the mic or the ALC889
4563 * makes the signal become a difference/sum signal
4564 * instead of standard stereo, which is annoying.
4565 * So instead we flip this bit which makes the
4566 * codec replicate the sum signal to both channels,
4567 * turning it into a normal mono mic.
4568 */
4569 /* DMIC_CONTROL? Init value = 0x0001 */
4570 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4571 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4572 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4573 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4574 { }
4575 }
4576 },
4577 [ALC885_FIXUP_MACPRO_GPIO] = {
4578 .type = ALC_FIXUP_FUNC,
4579 .v.func = alc885_fixup_macpro_gpio,
4580 },
4581 };
4582
4583 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4584 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4585 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4586 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4587 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4588 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4589 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
4590 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4591 ALC882_FIXUP_ACER_ASPIRE_4930G),
4592 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4593 ALC882_FIXUP_ACER_ASPIRE_4930G),
4594 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4595 ALC882_FIXUP_ACER_ASPIRE_8930G),
4596 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4597 ALC882_FIXUP_ACER_ASPIRE_8930G),
4598 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4599 ALC882_FIXUP_ACER_ASPIRE_4930G),
4600 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4601 ALC882_FIXUP_ACER_ASPIRE_4930G),
4602 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4603 ALC882_FIXUP_ACER_ASPIRE_4930G),
4604 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
4605 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
4606 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
4607 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
4608 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
4609 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
4610 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4611
4612 /* All Apple entries are in codec SSIDs */
4613 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4614 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4615 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4616 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4617 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4618
4619 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
4620 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4621 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4622 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4623 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
4624 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
4625 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
4626 {}
4627 };
4628
4629 /*
4630 * BIOS auto configuration
4631 */
4632 /* almost identical with ALC880 parser... */
4633 static int alc882_parse_auto_config(struct hda_codec *codec)
4634 {
4635 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4636 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4637 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4638 }
4639
4640 /*
4641 */
4642 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4643 #include "alc882_quirks.c"
4644 #endif
4645
4646 static int patch_alc882(struct hda_codec *codec)
4647 {
4648 struct alc_spec *spec;
4649 int err, board_config;
4650
4651 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4652 if (spec == NULL)
4653 return -ENOMEM;
4654
4655 codec->spec = spec;
4656
4657 spec->mixer_nid = 0x0b;
4658
4659 switch (codec->vendor_id) {
4660 case 0x10ec0882:
4661 case 0x10ec0885:
4662 break;
4663 default:
4664 /* ALC883 and variants */
4665 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4666 break;
4667 }
4668
4669 err = alc_codec_rename_from_preset(codec);
4670 if (err < 0)
4671 goto error;
4672
4673 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4674 alc882_models, NULL);
4675 if (board_config < 0)
4676 board_config = alc_board_codec_sid_config(codec,
4677 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4678
4679 if (board_config < 0) {
4680 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4681 codec->chip_name);
4682 board_config = ALC_MODEL_AUTO;
4683 }
4684
4685 if (board_config == ALC_MODEL_AUTO) {
4686 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4687 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4688 }
4689
4690 alc_auto_parse_customize_define(codec);
4691
4692 if (board_config == ALC_MODEL_AUTO) {
4693 /* automatic parse from the BIOS config */
4694 err = alc882_parse_auto_config(codec);
4695 if (err < 0)
4696 goto error;
4697 }
4698
4699 if (board_config != ALC_MODEL_AUTO) {
4700 setup_preset(codec, &alc882_presets[board_config]);
4701 spec->vmaster_nid = 0x0c;
4702 }
4703
4704 if (!spec->no_analog && !spec->adc_nids) {
4705 alc_auto_fill_adc_caps(codec);
4706 alc_rebuild_imux_for_auto_mic(codec);
4707 alc_remove_invalid_adc_nids(codec);
4708 }
4709
4710 if (!spec->no_analog && !spec->cap_mixer)
4711 set_capture_mixer(codec);
4712
4713 if (!spec->no_analog && has_cdefine_beep(codec)) {
4714 err = snd_hda_attach_beep_device(codec, 0x1);
4715 if (err < 0)
4716 goto error;
4717 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4718 }
4719
4720 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4721
4722 codec->patch_ops = alc_patch_ops;
4723 if (board_config == ALC_MODEL_AUTO)
4724 spec->init_hook = alc_auto_init_std;
4725 else
4726 codec->patch_ops.build_controls = __alc_build_controls;
4727
4728 #ifdef CONFIG_SND_HDA_POWER_SAVE
4729 if (!spec->loopback.amplist)
4730 spec->loopback.amplist = alc882_loopbacks;
4731 #endif
4732
4733 return 0;
4734
4735 error:
4736 alc_free(codec);
4737 return err;
4738 }
4739
4740
4741 /*
4742 * ALC262 support
4743 */
4744 static int alc262_parse_auto_config(struct hda_codec *codec)
4745 {
4746 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4747 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4748 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4749 }
4750
4751 /*
4752 * Pin config fixes
4753 */
4754 enum {
4755 ALC262_FIXUP_FSC_H270,
4756 ALC262_FIXUP_HP_Z200,
4757 ALC262_FIXUP_TYAN,
4758 ALC262_FIXUP_LENOVO_3000,
4759 ALC262_FIXUP_BENQ,
4760 ALC262_FIXUP_BENQ_T31,
4761 };
4762
4763 static const struct alc_fixup alc262_fixups[] = {
4764 [ALC262_FIXUP_FSC_H270] = {
4765 .type = ALC_FIXUP_PINS,
4766 .v.pins = (const struct alc_pincfg[]) {
4767 { 0x14, 0x99130110 }, /* speaker */
4768 { 0x15, 0x0221142f }, /* front HP */
4769 { 0x1b, 0x0121141f }, /* rear HP */
4770 { }
4771 }
4772 },
4773 [ALC262_FIXUP_HP_Z200] = {
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x16, 0x99130120 }, /* internal speaker */
4777 { }
4778 }
4779 },
4780 [ALC262_FIXUP_TYAN] = {
4781 .type = ALC_FIXUP_PINS,
4782 .v.pins = (const struct alc_pincfg[]) {
4783 { 0x14, 0x1993e1f0 }, /* int AUX */
4784 { }
4785 }
4786 },
4787 [ALC262_FIXUP_LENOVO_3000] = {
4788 .type = ALC_FIXUP_VERBS,
4789 .v.verbs = (const struct hda_verb[]) {
4790 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4791 {}
4792 },
4793 .chained = true,
4794 .chain_id = ALC262_FIXUP_BENQ,
4795 },
4796 [ALC262_FIXUP_BENQ] = {
4797 .type = ALC_FIXUP_VERBS,
4798 .v.verbs = (const struct hda_verb[]) {
4799 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4800 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4801 {}
4802 }
4803 },
4804 [ALC262_FIXUP_BENQ_T31] = {
4805 .type = ALC_FIXUP_VERBS,
4806 .v.verbs = (const struct hda_verb[]) {
4807 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4808 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4809 {}
4810 }
4811 },
4812 };
4813
4814 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4815 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
4816 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4817 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
4818 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4819 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
4820 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
4821 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4822 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
4823 {}
4824 };
4825
4826
4827 #ifdef CONFIG_SND_HDA_POWER_SAVE
4828 #define alc262_loopbacks alc880_loopbacks
4829 #endif
4830
4831 /*
4832 */
4833 static int patch_alc262(struct hda_codec *codec)
4834 {
4835 struct alc_spec *spec;
4836 int err;
4837
4838 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4839 if (spec == NULL)
4840 return -ENOMEM;
4841
4842 codec->spec = spec;
4843
4844 spec->mixer_nid = 0x0b;
4845
4846 #if 0
4847 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4848 * under-run
4849 */
4850 {
4851 int tmp;
4852 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4853 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4854 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4855 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4856 }
4857 #endif
4858 alc_auto_parse_customize_define(codec);
4859
4860 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4861
4862 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4863 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4864
4865 /* automatic parse from the BIOS config */
4866 err = alc262_parse_auto_config(codec);
4867 if (err < 0)
4868 goto error;
4869
4870 if (!spec->no_analog && !spec->adc_nids) {
4871 alc_auto_fill_adc_caps(codec);
4872 alc_rebuild_imux_for_auto_mic(codec);
4873 alc_remove_invalid_adc_nids(codec);
4874 }
4875
4876 if (!spec->no_analog && !spec->cap_mixer)
4877 set_capture_mixer(codec);
4878
4879 if (!spec->no_analog && has_cdefine_beep(codec)) {
4880 err = snd_hda_attach_beep_device(codec, 0x1);
4881 if (err < 0)
4882 goto error;
4883 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4884 }
4885
4886 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4887
4888 codec->patch_ops = alc_patch_ops;
4889 spec->init_hook = alc_auto_init_std;
4890 spec->shutup = alc_eapd_shutup;
4891
4892 #ifdef CONFIG_SND_HDA_POWER_SAVE
4893 if (!spec->loopback.amplist)
4894 spec->loopback.amplist = alc262_loopbacks;
4895 #endif
4896
4897 return 0;
4898
4899 error:
4900 alc_free(codec);
4901 return err;
4902 }
4903
4904 /*
4905 * ALC268
4906 */
4907 /* bind Beep switches of both NID 0x0f and 0x10 */
4908 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4909 .ops = &snd_hda_bind_sw,
4910 .values = {
4911 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4912 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4913 0
4914 },
4915 };
4916
4917 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4918 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4919 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4920 { }
4921 };
4922
4923 /* set PCBEEP vol = 0, mute connections */
4924 static const struct hda_verb alc268_beep_init_verbs[] = {
4925 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4926 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4927 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4928 { }
4929 };
4930
4931 /*
4932 * BIOS auto configuration
4933 */
4934 static int alc268_parse_auto_config(struct hda_codec *codec)
4935 {
4936 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4937 struct alc_spec *spec = codec->spec;
4938 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4939 if (err > 0) {
4940 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4941 add_mixer(spec, alc268_beep_mixer);
4942 add_verb(spec, alc268_beep_init_verbs);
4943 }
4944 }
4945 return err;
4946 }
4947
4948 /*
4949 */
4950 static int patch_alc268(struct hda_codec *codec)
4951 {
4952 struct alc_spec *spec;
4953 int i, has_beep, err;
4954
4955 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4956 if (spec == NULL)
4957 return -ENOMEM;
4958
4959 codec->spec = spec;
4960
4961 /* ALC268 has no aa-loopback mixer */
4962
4963 /* automatic parse from the BIOS config */
4964 err = alc268_parse_auto_config(codec);
4965 if (err < 0)
4966 goto error;
4967
4968 has_beep = 0;
4969 for (i = 0; i < spec->num_mixers; i++) {
4970 if (spec->mixers[i] == alc268_beep_mixer) {
4971 has_beep = 1;
4972 break;
4973 }
4974 }
4975
4976 if (has_beep) {
4977 err = snd_hda_attach_beep_device(codec, 0x1);
4978 if (err < 0)
4979 goto error;
4980 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4981 /* override the amp caps for beep generator */
4982 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4983 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4984 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4985 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4986 (0 << AC_AMPCAP_MUTE_SHIFT));
4987 }
4988
4989 if (!spec->no_analog && !spec->adc_nids) {
4990 alc_auto_fill_adc_caps(codec);
4991 alc_rebuild_imux_for_auto_mic(codec);
4992 alc_remove_invalid_adc_nids(codec);
4993 }
4994
4995 if (!spec->no_analog && !spec->cap_mixer)
4996 set_capture_mixer(codec);
4997
4998 codec->patch_ops = alc_patch_ops;
4999 spec->init_hook = alc_auto_init_std;
5000 spec->shutup = alc_eapd_shutup;
5001
5002 return 0;
5003
5004 error:
5005 alc_free(codec);
5006 return err;
5007 }
5008
5009 /*
5010 * ALC269
5011 */
5012 #ifdef CONFIG_SND_HDA_POWER_SAVE
5013 #define alc269_loopbacks alc880_loopbacks
5014 #endif
5015
5016 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5017 .substreams = 1,
5018 .channels_min = 2,
5019 .channels_max = 8,
5020 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5021 /* NID is set in alc_build_pcms */
5022 .ops = {
5023 .open = alc_playback_pcm_open,
5024 .prepare = alc_playback_pcm_prepare,
5025 .cleanup = alc_playback_pcm_cleanup
5026 },
5027 };
5028
5029 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5030 .substreams = 1,
5031 .channels_min = 2,
5032 .channels_max = 2,
5033 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5034 /* NID is set in alc_build_pcms */
5035 };
5036
5037 #ifdef CONFIG_SND_HDA_POWER_SAVE
5038 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5039 {
5040 switch (codec->subsystem_id) {
5041 case 0x103c1586:
5042 return 1;
5043 }
5044 return 0;
5045 }
5046
5047 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5048 {
5049 /* update mute-LED according to the speaker mute state */
5050 if (nid == 0x01 || nid == 0x14) {
5051 int pinval;
5052 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5053 HDA_AMP_MUTE)
5054 pinval = 0x24;
5055 else
5056 pinval = 0x20;
5057 /* mic2 vref pin is used for mute LED control */
5058 snd_hda_codec_update_cache(codec, 0x19, 0,
5059 AC_VERB_SET_PIN_WIDGET_CONTROL,
5060 pinval);
5061 }
5062 return alc_check_power_status(codec, nid);
5063 }
5064 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5065
5066 /* different alc269-variants */
5067 enum {
5068 ALC269_TYPE_ALC269VA,
5069 ALC269_TYPE_ALC269VB,
5070 ALC269_TYPE_ALC269VC,
5071 };
5072
5073 /*
5074 * BIOS auto configuration
5075 */
5076 static int alc269_parse_auto_config(struct hda_codec *codec)
5077 {
5078 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5079 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5080 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5081 struct alc_spec *spec = codec->spec;
5082 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5083 alc269va_ssids : alc269_ssids;
5084
5085 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5086 }
5087
5088 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5089 {
5090 int val = alc_read_coef_idx(codec, 0x04);
5091 if (power_up)
5092 val |= 1 << 11;
5093 else
5094 val &= ~(1 << 11);
5095 alc_write_coef_idx(codec, 0x04, val);
5096 }
5097
5098 static void alc269_shutup(struct hda_codec *codec)
5099 {
5100 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5101 alc269_toggle_power_output(codec, 0);
5102 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5103 alc269_toggle_power_output(codec, 0);
5104 msleep(150);
5105 }
5106 }
5107
5108 #ifdef CONFIG_PM
5109 static int alc269_resume(struct hda_codec *codec)
5110 {
5111 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5112 alc269_toggle_power_output(codec, 0);
5113 msleep(150);
5114 }
5115
5116 codec->patch_ops.init(codec);
5117
5118 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5119 alc269_toggle_power_output(codec, 1);
5120 msleep(200);
5121 }
5122
5123 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5124 alc269_toggle_power_output(codec, 1);
5125
5126 snd_hda_codec_resume_amp(codec);
5127 snd_hda_codec_resume_cache(codec);
5128 hda_call_check_power_status(codec, 0x01);
5129 return 0;
5130 }
5131 #endif /* CONFIG_PM */
5132
5133 static void alc269_fixup_hweq(struct hda_codec *codec,
5134 const struct alc_fixup *fix, int action)
5135 {
5136 int coef;
5137
5138 if (action != ALC_FIXUP_ACT_INIT)
5139 return;
5140 coef = alc_read_coef_idx(codec, 0x1e);
5141 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5142 }
5143
5144 static void alc271_fixup_dmic(struct hda_codec *codec,
5145 const struct alc_fixup *fix, int action)
5146 {
5147 static const struct hda_verb verbs[] = {
5148 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5149 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5150 {}
5151 };
5152 unsigned int cfg;
5153
5154 if (strcmp(codec->chip_name, "ALC271X"))
5155 return;
5156 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5157 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5158 snd_hda_sequence_write(codec, verbs);
5159 }
5160
5161 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5162 const struct alc_fixup *fix, int action)
5163 {
5164 struct alc_spec *spec = codec->spec;
5165
5166 if (action != ALC_FIXUP_ACT_PROBE)
5167 return;
5168
5169 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5170 * fix the sample rate of analog I/O to 44.1kHz
5171 */
5172 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5173 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5174 }
5175
5176 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5177 const struct alc_fixup *fix, int action)
5178 {
5179 int coef;
5180
5181 if (action != ALC_FIXUP_ACT_INIT)
5182 return;
5183 /* The digital-mic unit sends PDM (differential signal) instead of
5184 * the standard PCM, thus you can't record a valid mono stream as is.
5185 * Below is a workaround specific to ALC269 to control the dmic
5186 * signal source as mono.
5187 */
5188 coef = alc_read_coef_idx(codec, 0x07);
5189 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5190 }
5191
5192 static void alc269_quanta_automute(struct hda_codec *codec)
5193 {
5194 update_outputs(codec);
5195
5196 snd_hda_codec_write(codec, 0x20, 0,
5197 AC_VERB_SET_COEF_INDEX, 0x0c);
5198 snd_hda_codec_write(codec, 0x20, 0,
5199 AC_VERB_SET_PROC_COEF, 0x680);
5200
5201 snd_hda_codec_write(codec, 0x20, 0,
5202 AC_VERB_SET_COEF_INDEX, 0x0c);
5203 snd_hda_codec_write(codec, 0x20, 0,
5204 AC_VERB_SET_PROC_COEF, 0x480);
5205 }
5206
5207 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5208 const struct alc_fixup *fix, int action)
5209 {
5210 struct alc_spec *spec = codec->spec;
5211 if (action != ALC_FIXUP_ACT_PROBE)
5212 return;
5213 spec->automute_hook = alc269_quanta_automute;
5214 }
5215
5216 enum {
5217 ALC269_FIXUP_SONY_VAIO,
5218 ALC275_FIXUP_SONY_VAIO_GPIO2,
5219 ALC269_FIXUP_DELL_M101Z,
5220 ALC269_FIXUP_SKU_IGNORE,
5221 ALC269_FIXUP_ASUS_G73JW,
5222 ALC269_FIXUP_LENOVO_EAPD,
5223 ALC275_FIXUP_SONY_HWEQ,
5224 ALC271_FIXUP_DMIC,
5225 ALC269_FIXUP_PCM_44K,
5226 ALC269_FIXUP_STEREO_DMIC,
5227 ALC269_FIXUP_QUANTA_MUTE,
5228 ALC269_FIXUP_LIFEBOOK,
5229 ALC269_FIXUP_AMIC,
5230 ALC269_FIXUP_DMIC,
5231 ALC269VB_FIXUP_AMIC,
5232 ALC269VB_FIXUP_DMIC,
5233 };
5234
5235 static const struct alc_fixup alc269_fixups[] = {
5236 [ALC269_FIXUP_SONY_VAIO] = {
5237 .type = ALC_FIXUP_VERBS,
5238 .v.verbs = (const struct hda_verb[]) {
5239 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5240 {}
5241 }
5242 },
5243 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5244 .type = ALC_FIXUP_VERBS,
5245 .v.verbs = (const struct hda_verb[]) {
5246 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5247 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5248 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5249 { }
5250 },
5251 .chained = true,
5252 .chain_id = ALC269_FIXUP_SONY_VAIO
5253 },
5254 [ALC269_FIXUP_DELL_M101Z] = {
5255 .type = ALC_FIXUP_VERBS,
5256 .v.verbs = (const struct hda_verb[]) {
5257 /* Enables internal speaker */
5258 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5259 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5260 {}
5261 }
5262 },
5263 [ALC269_FIXUP_SKU_IGNORE] = {
5264 .type = ALC_FIXUP_SKU,
5265 .v.sku = ALC_FIXUP_SKU_IGNORE,
5266 },
5267 [ALC269_FIXUP_ASUS_G73JW] = {
5268 .type = ALC_FIXUP_PINS,
5269 .v.pins = (const struct alc_pincfg[]) {
5270 { 0x17, 0x99130111 }, /* subwoofer */
5271 { }
5272 }
5273 },
5274 [ALC269_FIXUP_LENOVO_EAPD] = {
5275 .type = ALC_FIXUP_VERBS,
5276 .v.verbs = (const struct hda_verb[]) {
5277 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5278 {}
5279 }
5280 },
5281 [ALC275_FIXUP_SONY_HWEQ] = {
5282 .type = ALC_FIXUP_FUNC,
5283 .v.func = alc269_fixup_hweq,
5284 .chained = true,
5285 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5286 },
5287 [ALC271_FIXUP_DMIC] = {
5288 .type = ALC_FIXUP_FUNC,
5289 .v.func = alc271_fixup_dmic,
5290 },
5291 [ALC269_FIXUP_PCM_44K] = {
5292 .type = ALC_FIXUP_FUNC,
5293 .v.func = alc269_fixup_pcm_44k,
5294 },
5295 [ALC269_FIXUP_STEREO_DMIC] = {
5296 .type = ALC_FIXUP_FUNC,
5297 .v.func = alc269_fixup_stereo_dmic,
5298 },
5299 [ALC269_FIXUP_QUANTA_MUTE] = {
5300 .type = ALC_FIXUP_FUNC,
5301 .v.func = alc269_fixup_quanta_mute,
5302 },
5303 [ALC269_FIXUP_LIFEBOOK] = {
5304 .type = ALC_FIXUP_PINS,
5305 .v.pins = (const struct alc_pincfg[]) {
5306 { 0x1a, 0x2101103f }, /* dock line-out */
5307 { 0x1b, 0x23a11040 }, /* dock mic-in */
5308 { }
5309 },
5310 .chained = true,
5311 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5312 },
5313 [ALC269_FIXUP_AMIC] = {
5314 .type = ALC_FIXUP_PINS,
5315 .v.pins = (const struct alc_pincfg[]) {
5316 { 0x14, 0x99130110 }, /* speaker */
5317 { 0x15, 0x0121401f }, /* HP out */
5318 { 0x18, 0x01a19c20 }, /* mic */
5319 { 0x19, 0x99a3092f }, /* int-mic */
5320 { }
5321 },
5322 },
5323 [ALC269_FIXUP_DMIC] = {
5324 .type = ALC_FIXUP_PINS,
5325 .v.pins = (const struct alc_pincfg[]) {
5326 { 0x12, 0x99a3092f }, /* int-mic */
5327 { 0x14, 0x99130110 }, /* speaker */
5328 { 0x15, 0x0121401f }, /* HP out */
5329 { 0x18, 0x01a19c20 }, /* mic */
5330 { }
5331 },
5332 },
5333 [ALC269VB_FIXUP_AMIC] = {
5334 .type = ALC_FIXUP_PINS,
5335 .v.pins = (const struct alc_pincfg[]) {
5336 { 0x14, 0x99130110 }, /* speaker */
5337 { 0x18, 0x01a19c20 }, /* mic */
5338 { 0x19, 0x99a3092f }, /* int-mic */
5339 { 0x21, 0x0121401f }, /* HP out */
5340 { }
5341 },
5342 },
5343 [ALC269VB_FIXUP_DMIC] = {
5344 .type = ALC_FIXUP_PINS,
5345 .v.pins = (const struct alc_pincfg[]) {
5346 { 0x12, 0x99a3092f }, /* int-mic */
5347 { 0x14, 0x99130110 }, /* speaker */
5348 { 0x18, 0x01a19c20 }, /* mic */
5349 { 0x21, 0x0121401f }, /* HP out */
5350 { }
5351 },
5352 },
5353 };
5354
5355 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5356 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5357 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5358 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5359 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5360 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5361 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5362 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5363 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5364 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5365 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5366 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5367 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5368 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5369 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5370 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5371 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5372 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5373 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5374 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5375 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5376 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5377
5378 #if 1
5379 /* Below is a quirk table taken from the old code.
5380 * Basically the device should work as is without the fixup table.
5381 * If BIOS doesn't give a proper info, enable the corresponding
5382 * fixup entry.
5383 */
5384 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5385 ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5419 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5421 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5422 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5423 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5424 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5425 #endif
5426 {}
5427 };
5428
5429 static const struct alc_model_fixup alc269_fixup_models[] = {
5430 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5431 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5432 {}
5433 };
5434
5435
5436 static int alc269_fill_coef(struct hda_codec *codec)
5437 {
5438 int val;
5439
5440 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5441 alc_write_coef_idx(codec, 0xf, 0x960b);
5442 alc_write_coef_idx(codec, 0xe, 0x8817);
5443 }
5444
5445 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5446 alc_write_coef_idx(codec, 0xf, 0x960b);
5447 alc_write_coef_idx(codec, 0xe, 0x8814);
5448 }
5449
5450 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5451 val = alc_read_coef_idx(codec, 0x04);
5452 /* Power up output pin */
5453 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5454 }
5455
5456 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5457 val = alc_read_coef_idx(codec, 0xd);
5458 if ((val & 0x0c00) >> 10 != 0x1) {
5459 /* Capless ramp up clock control */
5460 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5461 }
5462 val = alc_read_coef_idx(codec, 0x17);
5463 if ((val & 0x01c0) >> 6 != 0x4) {
5464 /* Class D power on reset */
5465 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5466 }
5467 }
5468
5469 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5470 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5471
5472 val = alc_read_coef_idx(codec, 0x4); /* HP */
5473 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5474
5475 return 0;
5476 }
5477
5478 /*
5479 */
5480 static int patch_alc269(struct hda_codec *codec)
5481 {
5482 struct alc_spec *spec;
5483 int err = 0;
5484
5485 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5486 if (spec == NULL)
5487 return -ENOMEM;
5488
5489 codec->spec = spec;
5490
5491 spec->mixer_nid = 0x0b;
5492
5493 alc_auto_parse_customize_define(codec);
5494
5495 err = alc_codec_rename_from_preset(codec);
5496 if (err < 0)
5497 goto error;
5498
5499 if (codec->vendor_id == 0x10ec0269) {
5500 spec->codec_variant = ALC269_TYPE_ALC269VA;
5501 switch (alc_get_coef0(codec) & 0x00f0) {
5502 case 0x0010:
5503 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5504 spec->cdefine.platform_type == 1)
5505 err = alc_codec_rename(codec, "ALC271X");
5506 spec->codec_variant = ALC269_TYPE_ALC269VB;
5507 break;
5508 case 0x0020:
5509 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5510 codec->bus->pci->subsystem_device == 0x21f3)
5511 err = alc_codec_rename(codec, "ALC3202");
5512 spec->codec_variant = ALC269_TYPE_ALC269VC;
5513 break;
5514 default:
5515 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5516 }
5517 if (err < 0)
5518 goto error;
5519 alc269_fill_coef(codec);
5520 }
5521
5522 alc_pick_fixup(codec, alc269_fixup_models,
5523 alc269_fixup_tbl, alc269_fixups);
5524 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5525
5526 /* automatic parse from the BIOS config */
5527 err = alc269_parse_auto_config(codec);
5528 if (err < 0)
5529 goto error;
5530
5531 if (!spec->no_analog && !spec->adc_nids) {
5532 alc_auto_fill_adc_caps(codec);
5533 alc_rebuild_imux_for_auto_mic(codec);
5534 alc_remove_invalid_adc_nids(codec);
5535 }
5536
5537 if (!spec->no_analog && !spec->cap_mixer)
5538 set_capture_mixer(codec);
5539
5540 if (!spec->no_analog && has_cdefine_beep(codec)) {
5541 err = snd_hda_attach_beep_device(codec, 0x1);
5542 if (err < 0)
5543 goto error;
5544 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5545 }
5546
5547 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5548
5549 codec->patch_ops = alc_patch_ops;
5550 #ifdef CONFIG_PM
5551 codec->patch_ops.resume = alc269_resume;
5552 #endif
5553 spec->init_hook = alc_auto_init_std;
5554 spec->shutup = alc269_shutup;
5555
5556 #ifdef CONFIG_SND_HDA_POWER_SAVE
5557 if (!spec->loopback.amplist)
5558 spec->loopback.amplist = alc269_loopbacks;
5559 if (alc269_mic2_for_mute_led(codec))
5560 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5561 #endif
5562
5563 return 0;
5564
5565 error:
5566 alc_free(codec);
5567 return err;
5568 }
5569
5570 /*
5571 * ALC861
5572 */
5573
5574 static int alc861_parse_auto_config(struct hda_codec *codec)
5575 {
5576 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5577 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5578 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5579 }
5580
5581 #ifdef CONFIG_SND_HDA_POWER_SAVE
5582 static const struct hda_amp_list alc861_loopbacks[] = {
5583 { 0x15, HDA_INPUT, 0 },
5584 { 0x15, HDA_INPUT, 1 },
5585 { 0x15, HDA_INPUT, 2 },
5586 { 0x15, HDA_INPUT, 3 },
5587 { } /* end */
5588 };
5589 #endif
5590
5591
5592 /* Pin config fixes */
5593 enum {
5594 ALC861_FIXUP_FSC_AMILO_PI1505,
5595 ALC861_FIXUP_AMP_VREF_0F,
5596 ALC861_FIXUP_NO_JACK_DETECT,
5597 ALC861_FIXUP_ASUS_A6RP,
5598 };
5599
5600 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5601 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5602 const struct alc_fixup *fix, int action)
5603 {
5604 struct alc_spec *spec = codec->spec;
5605 unsigned int val;
5606
5607 if (action != ALC_FIXUP_ACT_INIT)
5608 return;
5609 val = snd_hda_codec_read(codec, 0x0f, 0,
5610 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5611 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5612 val |= AC_PINCTL_IN_EN;
5613 val |= AC_PINCTL_VREF_50;
5614 snd_hda_codec_write(codec, 0x0f, 0,
5615 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5616 spec->keep_vref_in_automute = 1;
5617 }
5618
5619 /* suppress the jack-detection */
5620 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
5621 const struct alc_fixup *fix, int action)
5622 {
5623 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5624 codec->no_jack_detect = 1;
5625 }
5626
5627 static const struct alc_fixup alc861_fixups[] = {
5628 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
5629 .type = ALC_FIXUP_PINS,
5630 .v.pins = (const struct alc_pincfg[]) {
5631 { 0x0b, 0x0221101f }, /* HP */
5632 { 0x0f, 0x90170310 }, /* speaker */
5633 { }
5634 }
5635 },
5636 [ALC861_FIXUP_AMP_VREF_0F] = {
5637 .type = ALC_FIXUP_FUNC,
5638 .v.func = alc861_fixup_asus_amp_vref_0f,
5639 },
5640 [ALC861_FIXUP_NO_JACK_DETECT] = {
5641 .type = ALC_FIXUP_FUNC,
5642 .v.func = alc_fixup_no_jack_detect,
5643 },
5644 [ALC861_FIXUP_ASUS_A6RP] = {
5645 .type = ALC_FIXUP_FUNC,
5646 .v.func = alc861_fixup_asus_amp_vref_0f,
5647 .chained = true,
5648 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
5649 }
5650 };
5651
5652 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5653 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
5654 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
5655 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
5656 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
5657 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
5658 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
5659 {}
5660 };
5661
5662 /*
5663 */
5664 static int patch_alc861(struct hda_codec *codec)
5665 {
5666 struct alc_spec *spec;
5667 int err;
5668
5669 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5670 if (spec == NULL)
5671 return -ENOMEM;
5672
5673 codec->spec = spec;
5674
5675 spec->mixer_nid = 0x15;
5676
5677 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5678 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5679
5680 /* automatic parse from the BIOS config */
5681 err = alc861_parse_auto_config(codec);
5682 if (err < 0)
5683 goto error;
5684
5685 if (!spec->no_analog && !spec->adc_nids) {
5686 alc_auto_fill_adc_caps(codec);
5687 alc_rebuild_imux_for_auto_mic(codec);
5688 alc_remove_invalid_adc_nids(codec);
5689 }
5690
5691 if (!spec->no_analog && !spec->cap_mixer)
5692 set_capture_mixer(codec);
5693
5694 if (!spec->no_analog) {
5695 err = snd_hda_attach_beep_device(codec, 0x23);
5696 if (err < 0)
5697 goto error;
5698 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5699 }
5700
5701 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5702
5703 codec->patch_ops = alc_patch_ops;
5704 spec->init_hook = alc_auto_init_std;
5705 #ifdef CONFIG_SND_HDA_POWER_SAVE
5706 spec->power_hook = alc_power_eapd;
5707 if (!spec->loopback.amplist)
5708 spec->loopback.amplist = alc861_loopbacks;
5709 #endif
5710
5711 return 0;
5712
5713 error:
5714 alc_free(codec);
5715 return err;
5716 }
5717
5718 /*
5719 * ALC861-VD support
5720 *
5721 * Based on ALC882
5722 *
5723 * In addition, an independent DAC
5724 */
5725 #ifdef CONFIG_SND_HDA_POWER_SAVE
5726 #define alc861vd_loopbacks alc880_loopbacks
5727 #endif
5728
5729 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5730 {
5731 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5732 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5733 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5734 }
5735
5736 enum {
5737 ALC660VD_FIX_ASUS_GPIO1,
5738 ALC861VD_FIX_DALLAS,
5739 };
5740
5741 /* exclude VREF80 */
5742 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5743 const struct alc_fixup *fix, int action)
5744 {
5745 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5746 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5747 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5748 }
5749 }
5750
5751 static const struct alc_fixup alc861vd_fixups[] = {
5752 [ALC660VD_FIX_ASUS_GPIO1] = {
5753 .type = ALC_FIXUP_VERBS,
5754 .v.verbs = (const struct hda_verb[]) {
5755 /* reset GPIO1 */
5756 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5757 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5758 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5759 { }
5760 }
5761 },
5762 [ALC861VD_FIX_DALLAS] = {
5763 .type = ALC_FIXUP_FUNC,
5764 .v.func = alc861vd_fixup_dallas,
5765 },
5766 };
5767
5768 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5769 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5770 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5771 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5772 {}
5773 };
5774
5775 static const struct hda_verb alc660vd_eapd_verbs[] = {
5776 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5777 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5778 { }
5779 };
5780
5781 /*
5782 */
5783 static int patch_alc861vd(struct hda_codec *codec)
5784 {
5785 struct alc_spec *spec;
5786 int err;
5787
5788 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5789 if (spec == NULL)
5790 return -ENOMEM;
5791
5792 codec->spec = spec;
5793
5794 spec->mixer_nid = 0x0b;
5795
5796 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5797 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5798
5799 /* automatic parse from the BIOS config */
5800 err = alc861vd_parse_auto_config(codec);
5801 if (err < 0)
5802 goto error;
5803
5804 if (codec->vendor_id == 0x10ec0660) {
5805 /* always turn on EAPD */
5806 add_verb(spec, alc660vd_eapd_verbs);
5807 }
5808
5809 if (!spec->no_analog && !spec->adc_nids) {
5810 alc_auto_fill_adc_caps(codec);
5811 alc_rebuild_imux_for_auto_mic(codec);
5812 alc_remove_invalid_adc_nids(codec);
5813 }
5814
5815 if (!spec->no_analog && !spec->cap_mixer)
5816 set_capture_mixer(codec);
5817
5818 if (!spec->no_analog) {
5819 err = snd_hda_attach_beep_device(codec, 0x23);
5820 if (err < 0)
5821 goto error;
5822 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5823 }
5824
5825 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5826
5827 codec->patch_ops = alc_patch_ops;
5828
5829 spec->init_hook = alc_auto_init_std;
5830 spec->shutup = alc_eapd_shutup;
5831 #ifdef CONFIG_SND_HDA_POWER_SAVE
5832 if (!spec->loopback.amplist)
5833 spec->loopback.amplist = alc861vd_loopbacks;
5834 #endif
5835
5836 return 0;
5837
5838 error:
5839 alc_free(codec);
5840 return err;
5841 }
5842
5843 /*
5844 * ALC662 support
5845 *
5846 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5847 * configuration. Each pin widget can choose any input DACs and a mixer.
5848 * Each ADC is connected from a mixer of all inputs. This makes possible
5849 * 6-channel independent captures.
5850 *
5851 * In addition, an independent DAC for the multi-playback (not used in this
5852 * driver yet).
5853 */
5854 #ifdef CONFIG_SND_HDA_POWER_SAVE
5855 #define alc662_loopbacks alc880_loopbacks
5856 #endif
5857
5858 /*
5859 * BIOS auto configuration
5860 */
5861
5862 static int alc662_parse_auto_config(struct hda_codec *codec)
5863 {
5864 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5865 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5866 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5867 const hda_nid_t *ssids;
5868
5869 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5870 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5871 ssids = alc663_ssids;
5872 else
5873 ssids = alc662_ssids;
5874 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5875 }
5876
5877 static void alc272_fixup_mario(struct hda_codec *codec,
5878 const struct alc_fixup *fix, int action)
5879 {
5880 if (action != ALC_FIXUP_ACT_PROBE)
5881 return;
5882 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5883 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5884 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5885 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5886 (0 << AC_AMPCAP_MUTE_SHIFT)))
5887 printk(KERN_WARNING
5888 "hda_codec: failed to override amp caps for NID 0x2\n");
5889 }
5890
5891 enum {
5892 ALC662_FIXUP_ASPIRE,
5893 ALC662_FIXUP_IDEAPAD,
5894 ALC272_FIXUP_MARIO,
5895 ALC662_FIXUP_CZC_P10T,
5896 ALC662_FIXUP_SKU_IGNORE,
5897 ALC662_FIXUP_HP_RP5800,
5898 ALC662_FIXUP_ASUS_MODE1,
5899 ALC662_FIXUP_ASUS_MODE2,
5900 ALC662_FIXUP_ASUS_MODE3,
5901 ALC662_FIXUP_ASUS_MODE4,
5902 ALC662_FIXUP_ASUS_MODE5,
5903 ALC662_FIXUP_ASUS_MODE6,
5904 ALC662_FIXUP_ASUS_MODE7,
5905 ALC662_FIXUP_ASUS_MODE8,
5906 ALC662_FIXUP_NO_JACK_DETECT,
5907 };
5908
5909 static const struct alc_fixup alc662_fixups[] = {
5910 [ALC662_FIXUP_ASPIRE] = {
5911 .type = ALC_FIXUP_PINS,
5912 .v.pins = (const struct alc_pincfg[]) {
5913 { 0x15, 0x99130112 }, /* subwoofer */
5914 { }
5915 }
5916 },
5917 [ALC662_FIXUP_IDEAPAD] = {
5918 .type = ALC_FIXUP_PINS,
5919 .v.pins = (const struct alc_pincfg[]) {
5920 { 0x17, 0x99130112 }, /* subwoofer */
5921 { }
5922 }
5923 },
5924 [ALC272_FIXUP_MARIO] = {
5925 .type = ALC_FIXUP_FUNC,
5926 .v.func = alc272_fixup_mario,
5927 },
5928 [ALC662_FIXUP_CZC_P10T] = {
5929 .type = ALC_FIXUP_VERBS,
5930 .v.verbs = (const struct hda_verb[]) {
5931 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5932 {}
5933 }
5934 },
5935 [ALC662_FIXUP_SKU_IGNORE] = {
5936 .type = ALC_FIXUP_SKU,
5937 .v.sku = ALC_FIXUP_SKU_IGNORE,
5938 },
5939 [ALC662_FIXUP_HP_RP5800] = {
5940 .type = ALC_FIXUP_PINS,
5941 .v.pins = (const struct alc_pincfg[]) {
5942 { 0x14, 0x0221201f }, /* HP out */
5943 { }
5944 },
5945 .chained = true,
5946 .chain_id = ALC662_FIXUP_SKU_IGNORE
5947 },
5948 [ALC662_FIXUP_ASUS_MODE1] = {
5949 .type = ALC_FIXUP_PINS,
5950 .v.pins = (const struct alc_pincfg[]) {
5951 { 0x14, 0x99130110 }, /* speaker */
5952 { 0x18, 0x01a19c20 }, /* mic */
5953 { 0x19, 0x99a3092f }, /* int-mic */
5954 { 0x21, 0x0121401f }, /* HP out */
5955 { }
5956 },
5957 .chained = true,
5958 .chain_id = ALC662_FIXUP_SKU_IGNORE
5959 },
5960 [ALC662_FIXUP_ASUS_MODE2] = {
5961 .type = ALC_FIXUP_PINS,
5962 .v.pins = (const struct alc_pincfg[]) {
5963 { 0x14, 0x99130110 }, /* speaker */
5964 { 0x18, 0x01a19820 }, /* mic */
5965 { 0x19, 0x99a3092f }, /* int-mic */
5966 { 0x1b, 0x0121401f }, /* HP out */
5967 { }
5968 },
5969 .chained = true,
5970 .chain_id = ALC662_FIXUP_SKU_IGNORE
5971 },
5972 [ALC662_FIXUP_ASUS_MODE3] = {
5973 .type = ALC_FIXUP_PINS,
5974 .v.pins = (const struct alc_pincfg[]) {
5975 { 0x14, 0x99130110 }, /* speaker */
5976 { 0x15, 0x0121441f }, /* HP */
5977 { 0x18, 0x01a19840 }, /* mic */
5978 { 0x19, 0x99a3094f }, /* int-mic */
5979 { 0x21, 0x01211420 }, /* HP2 */
5980 { }
5981 },
5982 .chained = true,
5983 .chain_id = ALC662_FIXUP_SKU_IGNORE
5984 },
5985 [ALC662_FIXUP_ASUS_MODE4] = {
5986 .type = ALC_FIXUP_PINS,
5987 .v.pins = (const struct alc_pincfg[]) {
5988 { 0x14, 0x99130110 }, /* speaker */
5989 { 0x16, 0x99130111 }, /* speaker */
5990 { 0x18, 0x01a19840 }, /* mic */
5991 { 0x19, 0x99a3094f }, /* int-mic */
5992 { 0x21, 0x0121441f }, /* HP */
5993 { }
5994 },
5995 .chained = true,
5996 .chain_id = ALC662_FIXUP_SKU_IGNORE
5997 },
5998 [ALC662_FIXUP_ASUS_MODE5] = {
5999 .type = ALC_FIXUP_PINS,
6000 .v.pins = (const struct alc_pincfg[]) {
6001 { 0x14, 0x99130110 }, /* speaker */
6002 { 0x15, 0x0121441f }, /* HP */
6003 { 0x16, 0x99130111 }, /* speaker */
6004 { 0x18, 0x01a19840 }, /* mic */
6005 { 0x19, 0x99a3094f }, /* int-mic */
6006 { }
6007 },
6008 .chained = true,
6009 .chain_id = ALC662_FIXUP_SKU_IGNORE
6010 },
6011 [ALC662_FIXUP_ASUS_MODE6] = {
6012 .type = ALC_FIXUP_PINS,
6013 .v.pins = (const struct alc_pincfg[]) {
6014 { 0x14, 0x99130110 }, /* speaker */
6015 { 0x15, 0x01211420 }, /* HP2 */
6016 { 0x18, 0x01a19840 }, /* mic */
6017 { 0x19, 0x99a3094f }, /* int-mic */
6018 { 0x1b, 0x0121441f }, /* HP */
6019 { }
6020 },
6021 .chained = true,
6022 .chain_id = ALC662_FIXUP_SKU_IGNORE
6023 },
6024 [ALC662_FIXUP_ASUS_MODE7] = {
6025 .type = ALC_FIXUP_PINS,
6026 .v.pins = (const struct alc_pincfg[]) {
6027 { 0x14, 0x99130110 }, /* speaker */
6028 { 0x17, 0x99130111 }, /* speaker */
6029 { 0x18, 0x01a19840 }, /* mic */
6030 { 0x19, 0x99a3094f }, /* int-mic */
6031 { 0x1b, 0x01214020 }, /* HP */
6032 { 0x21, 0x0121401f }, /* HP */
6033 { }
6034 },
6035 .chained = true,
6036 .chain_id = ALC662_FIXUP_SKU_IGNORE
6037 },
6038 [ALC662_FIXUP_ASUS_MODE8] = {
6039 .type = ALC_FIXUP_PINS,
6040 .v.pins = (const struct alc_pincfg[]) {
6041 { 0x14, 0x99130110 }, /* speaker */
6042 { 0x12, 0x99a30970 }, /* int-mic */
6043 { 0x15, 0x01214020 }, /* HP */
6044 { 0x17, 0x99130111 }, /* speaker */
6045 { 0x18, 0x01a19840 }, /* mic */
6046 { 0x21, 0x0121401f }, /* HP */
6047 { }
6048 },
6049 .chained = true,
6050 .chain_id = ALC662_FIXUP_SKU_IGNORE
6051 },
6052 [ALC662_FIXUP_NO_JACK_DETECT] = {
6053 .type = ALC_FIXUP_FUNC,
6054 .v.func = alc_fixup_no_jack_detect,
6055 },
6056 };
6057
6058 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6059 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6060 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6061 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6062 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6063 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6064 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
6065 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6066 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6067 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6068 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6069 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6070
6071 #if 0
6072 /* Below is a quirk table taken from the old code.
6073 * Basically the device should work as is without the fixup table.
6074 * If BIOS doesn't give a proper info, enable the corresponding
6075 * fixup entry.
6076 */
6077 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6078 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6079 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6080 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6081 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6082 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6083 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6084 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6085 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6086 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6087 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6088 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6089 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6090 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6091 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6092 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6093 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6094 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6095 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6096 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6097 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6098 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6099 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6100 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6101 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6102 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6103 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6104 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6105 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6106 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6107 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6108 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6109 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6110 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6111 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6112 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6113 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6114 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6115 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6116 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6117 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6118 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6119 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6120 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6121 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6122 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6123 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6124 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6125 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6126 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6127 #endif
6128 {}
6129 };
6130
6131 static const struct alc_model_fixup alc662_fixup_models[] = {
6132 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6133 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6134 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6135 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6136 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6137 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6138 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6139 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6140 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6141 {}
6142 };
6143
6144
6145 /*
6146 */
6147 static int patch_alc662(struct hda_codec *codec)
6148 {
6149 struct alc_spec *spec;
6150 int err = 0;
6151
6152 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6153 if (!spec)
6154 return -ENOMEM;
6155
6156 codec->spec = spec;
6157
6158 spec->mixer_nid = 0x0b;
6159
6160 /* handle multiple HPs as is */
6161 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6162
6163 alc_auto_parse_customize_define(codec);
6164
6165 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6166
6167 err = alc_codec_rename_from_preset(codec);
6168 if (err < 0)
6169 goto error;
6170
6171 if ((alc_get_coef0(codec) & (1 << 14)) &&
6172 codec->bus->pci->subsystem_vendor == 0x1025 &&
6173 spec->cdefine.platform_type == 1) {
6174 if (alc_codec_rename(codec, "ALC272X") < 0)
6175 goto error;
6176 }
6177
6178 alc_pick_fixup(codec, alc662_fixup_models,
6179 alc662_fixup_tbl, alc662_fixups);
6180 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6181 /* automatic parse from the BIOS config */
6182 err = alc662_parse_auto_config(codec);
6183 if (err < 0)
6184 goto error;
6185
6186 if (!spec->no_analog && !spec->adc_nids) {
6187 alc_auto_fill_adc_caps(codec);
6188 alc_rebuild_imux_for_auto_mic(codec);
6189 alc_remove_invalid_adc_nids(codec);
6190 }
6191
6192 if (!spec->no_analog && !spec->cap_mixer)
6193 set_capture_mixer(codec);
6194
6195 if (!spec->no_analog && has_cdefine_beep(codec)) {
6196 err = snd_hda_attach_beep_device(codec, 0x1);
6197 if (err < 0)
6198 goto error;
6199 switch (codec->vendor_id) {
6200 case 0x10ec0662:
6201 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6202 break;
6203 case 0x10ec0272:
6204 case 0x10ec0663:
6205 case 0x10ec0665:
6206 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6207 break;
6208 case 0x10ec0273:
6209 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6210 break;
6211 }
6212 }
6213
6214 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6215
6216 codec->patch_ops = alc_patch_ops;
6217 spec->init_hook = alc_auto_init_std;
6218 spec->shutup = alc_eapd_shutup;
6219
6220 #ifdef CONFIG_SND_HDA_POWER_SAVE
6221 if (!spec->loopback.amplist)
6222 spec->loopback.amplist = alc662_loopbacks;
6223 #endif
6224
6225 return 0;
6226
6227 error:
6228 alc_free(codec);
6229 return err;
6230 }
6231
6232 /*
6233 * ALC680 support
6234 */
6235
6236 static int alc680_parse_auto_config(struct hda_codec *codec)
6237 {
6238 return alc_parse_auto_config(codec, NULL, NULL);
6239 }
6240
6241 /*
6242 */
6243 static int patch_alc680(struct hda_codec *codec)
6244 {
6245 struct alc_spec *spec;
6246 int err;
6247
6248 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6249 if (spec == NULL)
6250 return -ENOMEM;
6251
6252 codec->spec = spec;
6253
6254 /* ALC680 has no aa-loopback mixer */
6255
6256 /* automatic parse from the BIOS config */
6257 err = alc680_parse_auto_config(codec);
6258 if (err < 0) {
6259 alc_free(codec);
6260 return err;
6261 }
6262
6263 if (!spec->no_analog && !spec->cap_mixer)
6264 set_capture_mixer(codec);
6265
6266 codec->patch_ops = alc_patch_ops;
6267 spec->init_hook = alc_auto_init_std;
6268
6269 return 0;
6270 }
6271
6272 /*
6273 * patch entries
6274 */
6275 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6276 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6277 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6278 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6279 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6280 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6281 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6282 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6283 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6284 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6285 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6286 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6287 .patch = patch_alc861 },
6288 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6289 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6290 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6291 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6292 .patch = patch_alc882 },
6293 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6294 .patch = patch_alc662 },
6295 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6296 .patch = patch_alc662 },
6297 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6298 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6299 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6300 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6301 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6302 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6303 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6304 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6305 .patch = patch_alc882 },
6306 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6307 .patch = patch_alc882 },
6308 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6309 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6310 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6311 .patch = patch_alc882 },
6312 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6313 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6314 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6315 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6316 {} /* terminator */
6317 };
6318
6319 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6320
6321 MODULE_LICENSE("GPL");
6322 MODULE_DESCRIPTION("Realtek HD-audio codec");
6323
6324 static struct hda_codec_preset_list realtek_list = {
6325 .preset = snd_hda_preset_realtek,
6326 .owner = THIS_MODULE,
6327 };
6328
6329 static int __init patch_realtek_init(void)
6330 {
6331 return snd_hda_add_codec_preset(&realtek_list);
6332 }
6333
6334 static void __exit patch_realtek_exit(void)
6335 {
6336 snd_hda_delete_codec_preset(&realtek_list);
6337 }
6338
6339 module_init(patch_realtek_init)
6340 module_exit(patch_realtek_exit)